From 4e0d24089588da8952c6986f1bfcc47bcd9f84a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Sat, 10 Feb 2024 12:40:55 +0900 Subject: [PATCH] build(plugin): Update `wasmer` to `v4.2.5` (#8624) **Description:** This is required to update rustc. --- Cargo.lock | 436 ++++++++---------- bindings/Cargo.lock | 16 +- bindings/Cargo.toml | 11 +- bindings/binding_core_node/Cargo.toml | 1 + bindings/binding_core_node/src/transform.rs | 165 ++++--- crates/binding_macros/Cargo.toml | 15 +- crates/swc_plugin_runner/Cargo.toml | 10 +- crates/swc_plugin_runner/src/wasix_runtime.rs | 6 +- crates/swc_plugin_runner/tests/css_rkyv.rs | 232 +++++----- .../tests/ecma_integration.rs | 349 +++++++------- crates/swc_plugin_runner/tests/ecma_rkyv.rs | 262 +++++------ crates/swc_plugin_runner/tests/issues.rs | 150 +++--- deny.toml | 1 + node-swc/e2e/plugins/plugins.compat.test.js | 39 ++ 14 files changed, 843 insertions(+), 850 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aa2e8a4feb3a..d3923365ee07 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -277,12 +277,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "base-x" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270" - [[package]] name = "base64" version = "0.21.7" @@ -683,12 +677,6 @@ dependencies = [ "tiny-keccak", ] -[[package]] -name = "const_fn" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbdcdcb6d86f71c5e97409ad45898af11cbc995b4ee8112d59095a28d376c935" - [[package]] name = "constant_time_eq" version = "0.3.0" @@ -903,6 +891,15 @@ version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7059fff8937831a9ae6f0fe4d658ffabf58f2ca96aa9dec1c889f936f705f216" +[[package]] +name = "crossbeam-channel" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "176dc175b78f56c0f321911d9c8eb2b77a78a4860b9c19db83835fea1a46649b" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "crossbeam-deque" version = "0.8.5" @@ -922,6 +919,15 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "crossbeam-queue" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df0346b5d5e76ac2fe4e327c5fd1118d6be7c51dfb18f9b7922923f287471e35" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "crossbeam-utils" version = "0.8.19" @@ -1059,7 +1065,7 @@ dependencies = [ "rayon", "serde", "serde_json", - "sha1 0.10.6", + "sha1", "swc_atoms", "swc_common", "swc_ecma_ast", @@ -1086,6 +1092,15 @@ dependencies = [ "uuid", ] +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", +] + [[package]] name = "derivative" version = "2.2.0" @@ -1179,32 +1194,6 @@ dependencies = [ "crypto-common", ] -[[package]] -name = "dirs" -version = "4.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" -dependencies = [ - "dirs-sys", -] - -[[package]] -name = "dirs-sys" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" -dependencies = [ - "libc", - "redox_users", - "winapi", -] - -[[package]] -name = "discard" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" - [[package]] name = "doc-comment" version = "0.3.3" @@ -1719,7 +1708,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2", + "socket2 0.5.5", "tokio", "tower-service", "tracing", @@ -1901,9 +1890,9 @@ checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "js-sys" -version = "0.3.61" +version = "0.3.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" +checksum = "406cda4b368d531c842222cf9d2600a9a4acce8d29423695379c6868a143a9ee" dependencies = [ "wasm-bindgen", ] @@ -2048,17 +2037,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "libredox" -version = "0.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85c833ca1e66078851dba29046874e38f08b2c883700aa29a03ddd3b23814ee8" -dependencies = [ - "bitflags 2.4.2", - "libc", - "redox_syscall", -] - [[package]] name = "linked-hash-map" version = "0.5.6" @@ -2155,9 +2133,9 @@ dependencies = [ [[package]] name = "memoffset" -version = "0.8.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" +checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" dependencies = [ "autocfg", ] @@ -2241,6 +2219,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" dependencies = [ "libc", + "log", "wasi", "windows-sys 0.48.0", ] @@ -2410,6 +2389,12 @@ dependencies = [ "serde", ] +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num-integer" version = "0.1.45" @@ -2756,6 +2741,12 @@ dependencies = [ "syn 2.0.48", ] +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -2855,17 +2846,11 @@ dependencies = [ "version_check", ] -[[package]] -name = "proc-macro-hack" -version = "0.5.20+deprecated" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" - [[package]] name = "proc-macro2" -version = "1.0.76" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] @@ -2990,17 +2975,6 @@ dependencies = [ "bitflags 1.3.2", ] -[[package]] -name = "redox_users" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a18479200779601e498ada4e8c1e1f50e3ee19deb0259c25825a98b5603b2cb4" -dependencies = [ - "getrandom", - "libredox", - "thiserror", -] - [[package]] name = "regalloc2" version = "0.5.1" @@ -3220,6 +3194,19 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" +[[package]] +name = "rusty_pool" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ed36cdb20de66d89a17ea04b8883fc7a386f2cf877aaedca5005583ce4876ff" +dependencies = [ + "crossbeam-channel", + "futures", + "futures-channel", + "futures-executor", + "num_cpus", +] + [[package]] name = "ryu" version = "1.0.16" @@ -3291,6 +3278,12 @@ dependencies = [ "libc", ] +[[package]] +name = "self_cell" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58bf37232d3bb9a2c4e641ca2a11d83b5062066f88df7fed36c28772046d65ba" + [[package]] name = "semver" version = "0.9.0" @@ -3424,15 +3417,6 @@ dependencies = [ "digest", ] -[[package]] -name = "sha1" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1da05c97445caa12d05e848c4a4fcbbea29e748ac28f7e80e9b010392063770" -dependencies = [ - "sha1_smol", -] - [[package]] name = "sha1" version = "0.10.6" @@ -3444,12 +3428,6 @@ dependencies = [ "digest", ] -[[package]] -name = "sha1_smol" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" - [[package]] name = "sha2" version = "0.10.8" @@ -3486,15 +3464,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde" -[[package]] -name = "shellexpand" -version = "2.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ccc8076840c4da029af4f87e4e8daeb0fca6b87bbb02e10cb60b791450e11e4" -dependencies = [ - "dirs", -] - [[package]] name = "simdutf8" version = "0.1.4" @@ -3545,6 +3514,16 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b7c388c1b5e93756d0c740965c41e8822f866621d41acbdf6336a6a168f8840c" +[[package]] +name = "socket2" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "socket2" version = "0.5.5" @@ -3609,15 +3588,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "standback" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e113fb6f3de07a243d434a56ec6f186dfd51cb08448239fe7bcae73f87ff28ff" -dependencies = [ - "version_check", -] - [[package]] name = "static-map-macro" version = "0.3.3" @@ -3635,55 +3605,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" -[[package]] -name = "stdweb" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5" -dependencies = [ - "discard", - "rustc_version 0.2.3", - "stdweb-derive", - "stdweb-internal-macros", - "stdweb-internal-runtime", - "wasm-bindgen", -] - -[[package]] -name = "stdweb-derive" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef" -dependencies = [ - "proc-macro2", - "quote", - "serde", - "serde_derive", - "syn 1.0.109", -] - -[[package]] -name = "stdweb-internal-macros" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11" -dependencies = [ - "base-x", - "proc-macro2", - "quote", - "serde", - "serde_derive", - "serde_json", - "sha1 0.6.1", - "syn 1.0.109", -] - -[[package]] -name = "stdweb-internal-runtime" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" - [[package]] name = "string_cache" version = "0.8.7" @@ -5654,40 +5575,33 @@ dependencies = [ [[package]] name = "time" -version = "0.2.27" +version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4752a97f8eebd6854ff91f1c1824cd6160626ac4bd44287f7f4ea2035a02a242" +checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749" dependencies = [ - "const_fn", - "libc", - "standback", - "stdweb", + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde", + "time-core", "time-macros", - "version_check", - "winapi", ] [[package]] -name = "time-macros" -version = "0.1.1" +name = "time-core" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957e9c6e26f12cb6d0dd7fc776bb67a706312e7299aed74c8dd5b17ebb27e2f1" -dependencies = [ - "proc-macro-hack", - "time-macros-impl", -] +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] -name = "time-macros-impl" -version = "0.1.2" +name = "time-macros" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd3c141a1b43194f3f56a1411225df8646c55781d5f26db825b3d98507eb482f" +checksum = "7ba3a3ef41e6672a2f0f001392bb5dcd3ff0a9992d618ca761a11c3121547774" dependencies = [ - "proc-macro-hack", - "proc-macro2", - "quote", - "standback", - "syn 1.0.109", + "num-conv", + "time-core", ] [[package]] @@ -5736,7 +5650,7 @@ dependencies = [ "mio", "num_cpus", "pin-project-lite", - "socket2", + "socket2 0.5.5", "tokio-macros", "windows-sys 0.48.0", ] @@ -6070,9 +5984,9 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "virtual-fs" -version = "0.6.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcd74701f37aea30b90a83c90b92bc3850dedb9448836dbcc0960f993bda423b" +checksum = "49a16a7893a16a31ef442ce86691e7060a19691fb7739387624f3dd07ec4c04b" dependencies = [ "anyhow", "async-trait", @@ -6087,6 +6001,7 @@ dependencies = [ "libc", "pin-project-lite", "replace_with", + "shared-buffer", "slab", "thiserror", "tokio", @@ -6095,15 +6010,40 @@ dependencies = [ ] [[package]] -name = "virtual-net" +name = "virtual-mio" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfac1d64ecfe2d8b295530da2a14af9eb9acccd91d76f3347dee96d745c83661" +checksum = "b9f38a379f14296f9fb93eda42ece4d57b568af417569102c3dcfeb88ab4800f" +dependencies = [ + "async-trait", + "bytes", + "derivative", + "futures", + "mio", + "serde", + "socket2 0.4.10", + "thiserror", + "tracing", +] + +[[package]] +name = "virtual-net" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75b66781480898ee7ee62a2bbe2955ce1bb5a90fdc8bfedbdabe3537b177fa3e" dependencies = [ + "anyhow", "async-trait", + "base64", + "bincode", "bytes", + "derivative", + "futures-util", + "pin-project-lite", + "serde", "thiserror", "tracing", + "virtual-mio", ] [[package]] @@ -6172,9 +6112,9 @@ dependencies = [ [[package]] name = "wai-bindgen-wasmer" -version = "0.9.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ffd9a8124a3e4e664cb79864fd1eaf24521e15bf8d67509af1bc45e8b510475" +checksum = "00f4a7cb5421959864b139870a7ebba26eafc9b46648feda9ac143528e9a8769" dependencies = [ "anyhow", "bitflags 1.3.2", @@ -6252,9 +6192,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.84" +version = "0.2.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" +checksum = "c1e124130aee3fb58c5bdd6b639a0509486b0338acaaae0c84a5124b0f588b7f" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -6262,47 +6202,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.84" +version = "0.2.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" +checksum = "c9e7e1900c352b609c8488ad12639a311045f40a35491fb69ba8c12f758af70b" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.48", "wasm-bindgen-shared", ] -[[package]] -name = "wasm-bindgen-downcast" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dac026d43bcca6e7ce1c0956ba68f59edf6403e8e930a5d891be72c31a44340" -dependencies = [ - "js-sys", - "once_cell", - "wasm-bindgen", - "wasm-bindgen-downcast-macros", -] - -[[package]] -name = "wasm-bindgen-downcast-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5020cfa87c7cecefef118055d44e3c1fc122c7ec25701d528ee458a0b45f38f" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "wasm-bindgen-futures" -version = "0.4.34" +version = "0.4.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f219e0d211ba40266969f6dbdd90636da12f75bee4fc9d6c23d1260dadb51454" +checksum = "877b9c3f61ceea0e56331985743b13f3d25c406a7098d45180fb5f09bc19ed97" dependencies = [ "cfg-if", "js-sys", @@ -6312,9 +6229,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.84" +version = "0.2.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" +checksum = "b30af9e2d358182b5c7449424f017eba305ed32a7010509ede96cdc4696c46ed" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -6322,37 +6239,37 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.84" +version = "0.2.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" +checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.48", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.84" +version = "0.2.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" +checksum = "4f186bd2dcf04330886ce82d6f33dd75a7bfcf69ecf5763b89fcde53b6ac9838" [[package]] name = "wasm-encoder" -version = "0.39.0" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "111495d6204760238512f57a9af162f45086504da332af210f2f75dd80b34f1d" +checksum = "1ba64e81215916eaeb48fee292f29401d69235d62d8b8fd92a7b2844ec5ae5f7" dependencies = [ "leb128", ] [[package]] name = "wasmer" -version = "4.0.0" +version = "4.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea790bcdfb4e6e9d1e5ddf75b4699aac62b078fcc9f27f44e1748165ceea67bf" +checksum = "5467c7a23f9be04d5691590bea509dbea27e5ba5810d0020bef908456a495f33" dependencies = [ "bytes", "cfg-if", @@ -6363,10 +6280,10 @@ dependencies = [ "rustc-demangle", "serde", "serde-wasm-bindgen", + "shared-buffer", "target-lexicon", "thiserror", "wasm-bindgen", - "wasm-bindgen-downcast", "wasmer-compiler", "wasmer-compiler-cranelift", "wasmer-derive", @@ -6380,9 +6297,9 @@ dependencies = [ [[package]] name = "wasmer-cache" -version = "4.0.0" +version = "4.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36c968d5f47c4eef4597a7315aa9c6b633c285b5c52070722bac58fab75b298f" +checksum = "c1613ff5e7db7645eab2f003411b1e7a12dcf0ff4677f6e7712ba74ebf40b276" dependencies = [ "blake3", "hex", @@ -6392,11 +6309,12 @@ dependencies = [ [[package]] name = "wasmer-compiler" -version = "4.0.0" +version = "4.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f093937725e242e5529fed27e08ff836c011a9ecc22e6819fb818c2ac6ff5f88" +checksum = "510ad01a668d774f3a103a7c219bbc0970be93e8f1b27e2fdb48d1f4ccd1deff" dependencies = [ "backtrace", + "bytes", "cfg-if", "enum-iterator", "enumset", @@ -6405,6 +6323,9 @@ dependencies = [ "memmap2 0.5.10", "more-asserts", "region", + "rkyv", + "self_cell", + "shared-buffer", "smallvec", "thiserror", "wasmer-types", @@ -6415,9 +6336,9 @@ dependencies = [ [[package]] name = "wasmer-compiler-cranelift" -version = "4.0.0" +version = "4.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b27b1670d27158789ebe14e4da3902c72132174884a1c6a3533ce4fd9dd83db" +checksum = "54bf93078990d83960d798de3c5935bddaba771fc2fefb9ed6bab9c0bbdea5c1" dependencies = [ "cranelift-codegen", "cranelift-entity", @@ -6434,9 +6355,9 @@ dependencies = [ [[package]] name = "wasmer-derive" -version = "4.0.0" +version = "4.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13ae8286cba2acb10065a4dac129c7c7f7bcd24acd6538555d96616eea16bc27" +checksum = "1b374fd34d97b1c091d8675f9bc472df52dc6787d139d3762d42c7dc84813a9b" dependencies = [ "proc-macro-error", "proc-macro2", @@ -6464,9 +6385,9 @@ dependencies = [ [[package]] name = "wasmer-types" -version = "4.0.0" +version = "4.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "918d2f0bb5eaa95a80c06be33f21dee92f40f12cd0982da34490d121a99d244b" +checksum = "0caf1c87937b52aba8e9f920a278e1beda282f7439612c0b48f51a58e7a87bab" dependencies = [ "bytecheck", "enum-iterator", @@ -6481,14 +6402,15 @@ dependencies = [ [[package]] name = "wasmer-vm" -version = "4.0.0" +version = "4.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1e000c2cbd4f9805427af5f3b3446574caf89ab3a1e66c2f3579fbde22b072b" +checksum = "58315c25492bc72a33f47a7d7fb0869a0106fc0164ec051e349a9e1eddba9a01" dependencies = [ "backtrace", "cc", "cfg-if", "corosensei", + "crossbeam-queue", "dashmap", "derivative", "enum-iterator", @@ -6508,9 +6430,9 @@ dependencies = [ [[package]] name = "wasmer-wasix" -version = "0.9.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dcd089dcd440141b2edf300ddd61c2d67d052baac8d29256c901f607d44d459" +checksum = "a9697b8ffc3a37c193648919018848171de0d75e6e955377893d258431b19d7a" dependencies = [ "anyhow", "async-trait", @@ -6526,6 +6448,7 @@ dependencies = [ "heapless", "hex", "http", + "js-sys", "lazy_static", "libc", "linked_hash_set", @@ -6533,6 +6456,7 @@ dependencies = [ "petgraph", "pin-project", "rand", + "rusty_pool", "semver 1.0.21", "serde", "serde_cbor", @@ -6540,7 +6464,6 @@ dependencies = [ "serde_json", "serde_yaml 0.8.26", "sha2", - "shellexpand", "tempfile", "term_size", "termios", @@ -6550,23 +6473,27 @@ dependencies = [ "url", "urlencoding", "virtual-fs", + "virtual-mio", "virtual-net", "wai-bindgen-wasmer", "waker-fn", "wasm-bindgen", + "wasm-bindgen-futures", "wasmer", "wasmer-types", "wasmer-wasix-types", + "web-sys", "webc", "weezl", "winapi", + "xxhash-rust", ] [[package]] name = "wasmer-wasix-types" -version = "0.9.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a4a519e8f0b878bb4cd2b1bc733235aa6c331b7b4857dd6e0ac3c9a36d942ae" +checksum = "65ca293eae6e3af6e4fd9fe1c8e096151d4f06cbb405ce5dd65edb779aba42d9" dependencies = [ "anyhow", "bitflags 1.3.2", @@ -6575,6 +6502,7 @@ dependencies = [ "num_enum", "serde", "time", + "tracing", "wai-bindgen-gen-core", "wai-bindgen-gen-rust", "wai-bindgen-gen-rust-wasm", @@ -6603,9 +6531,9 @@ dependencies = [ [[package]] name = "wast" -version = "70.0.0" +version = "64.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ee4bc54bbe1c6924160b9f75e374a1d07532e7580eb632c0ee6cdd109bb217e" +checksum = "a259b226fd6910225aa7baeba82f9d9933b6d00f2ce1b49b80fa4214328237cc" dependencies = [ "leb128", "memchr", @@ -6615,18 +6543,18 @@ dependencies = [ [[package]] name = "wat" -version = "1.0.83" +version = "1.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f0dce8cdc288c717cf01e461a1e451a7b8445d53451123536ba576e423a101a" +checksum = "53253d920ab413fca1c7dc2161d601c79b4fdf631d0ba51dd4343bf9b556c3f6" dependencies = [ "wast", ] [[package]] name = "web-sys" -version = "0.3.61" +version = "0.3.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e33b99f4b23ba3eec1a53ac264e35a755f00e966e0065077d6027c0f575b0b97" +checksum = "96565907687f7aceb35bc5fc03770a8a0471d82e479f25832f54a0e3f4b28446" dependencies = [ "js-sys", "wasm-bindgen", @@ -6940,6 +6868,12 @@ dependencies = [ "walkdir", ] +[[package]] +name = "xxhash-rust" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53be06678ed9e83edb1745eb72efc0bbcd7b5c3c35711a860906aed827a13d61" + [[package]] name = "yaml-rust" version = "0.4.5" diff --git a/bindings/Cargo.lock b/bindings/Cargo.lock index fb0ee51b675c..b4b6b0cb5a76 100644 --- a/bindings/Cargo.lock +++ b/bindings/Cargo.lock @@ -221,6 +221,7 @@ dependencies = [ "serde_json", "swc_core", "swc_malloc", + "tokio", "tracing", "tracing-chrome", "tracing-futures", @@ -2008,9 +2009,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.9" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" [[package]] name = "pin-utils" @@ -4196,23 +4197,22 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.27.0" +version = "1.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0de47a4eecbe11f498978a9b29d792f0d2692d1dd003650c24c76510e3bc001" +checksum = "61285f6515fa018fb2d1e46eb21223fff441ee8db5d0f1435e8ab4f5cdb80931" dependencies = [ - "autocfg", + "backtrace", "bytes", "num_cpus", "pin-project-lite", "tokio-macros", - "windows-sys 0.45.0", ] [[package]] name = "tokio-macros" -version = "2.0.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61a573bdc87985e9d6ddeed1b3d864e8a302c847e40d647746df2f1de209d1ce" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", diff --git a/bindings/Cargo.toml b/bindings/Cargo.toml index fceedbd7b668..d9ae05ef04cf 100644 --- a/bindings/Cargo.toml +++ b/bindings/Cargo.toml @@ -1,11 +1,12 @@ [workspace] members = [ - "binding_core_node", - "binding_core_wasm", - "binding_minifier_node", - "binding_minifier_wasm", - "swc_cli", + "binding_core_node", + "binding_core_wasm", + "binding_minifier_node", + "binding_minifier_wasm", + "swc_cli", ] +resolver = "2" [profile.release] # lto = true diff --git a/bindings/binding_core_node/Cargo.toml b/bindings/binding_core_node/Cargo.toml index 4069aa268c33..10d873549aca 100644 --- a/bindings/binding_core_node/Cargo.toml +++ b/bindings/binding_core_node/Cargo.toml @@ -65,3 +65,4 @@ swc_core = { version = "0.90.6", features = [ "base_concurrent", ] } swc_malloc = "0.5.10" +tokio = { version = "1.36.0", features = ["rt", "rt-multi-thread"] } diff --git a/bindings/binding_core_node/src/transform.rs b/bindings/binding_core_node/src/transform.rs index 86a8bd34cbc3..00b8d19e2b45 100644 --- a/bindings/binding_core_node/src/transform.rs +++ b/bindings/binding_core_node/src/transform.rs @@ -50,40 +50,45 @@ impl Task for TransformTask { let error_format = options.experimental.error_format.unwrap_or_default(); - try_with( - self.c.cm.clone(), - !options.config.error.filename.into_bool(), - error_format, - |handler| { - self.c.run(|| match &self.input { - Input::Program(ref s) => { - let program: Program = - deserialize_json(s).expect("failed to deserialize Program"); - // TODO: Source map - self.c.process_js(handler, program, &options) - } - - Input::File(ref path) => { - let fm = self.c.cm.load_file(path).context("failed to load file")?; - self.c.process_js_file(fm, handler, &options) - } - - Input::Source { src } => { - let fm = self.c.cm.new_source_file( - if options.filename.is_empty() { - FileName::Anon - } else { - FileName::Real(options.filename.clone().into()) - }, - src.to_string(), - ); - - self.c.process_js_file(fm, handler, &options) - } - }) - }, - ) - .convert_err() + tokio::runtime::Runtime::new() + .unwrap() + .block_on(async move { + try_with( + self.c.cm.clone(), + !options.config.error.filename.into_bool(), + error_format, + |handler| { + self.c.run(|| match &self.input { + Input::Program(ref s) => { + let program: Program = + deserialize_json(s).expect("failed to deserialize Program"); + // TODO: Source map + self.c.process_js(handler, program, &options) + } + + Input::File(ref path) => { + let fm = + self.c.cm.load_file(path).context("failed to load file")?; + self.c.process_js_file(fm, handler, &options) + } + + Input::Source { src } => { + let fm = self.c.cm.new_source_file( + if options.filename.is_empty() { + FileName::Anon + } else { + FileName::Real(options.filename.clone().into()) + }, + src.to_string(), + ); + + self.c.process_js_file(fm, handler, &options) + } + }) + }, + ) + }) + .convert_err() } fn resolve(&mut self, _env: Env, result: Self::Output) -> napi::Result { @@ -137,31 +142,35 @@ pub fn transform_sync(s: String, is_module: bool, opts: Buffer) -> napi::Result< let error_format = options.experimental.error_format.unwrap_or_default(); - try_with( - c.cm.clone(), - !options.config.error.filename.into_bool(), - error_format, - |handler| { - c.run(|| { - if is_module { - let program: Program = - deserialize_json(s.as_str()).context("failed to deserialize Program")?; - c.process_js(handler, program, &options) - } else { - let fm = c.cm.new_source_file( - if options.filename.is_empty() { - FileName::Anon + tokio::runtime::Runtime::new() + .unwrap() + .block_on(async move { + try_with( + c.cm.clone(), + !options.config.error.filename.into_bool(), + error_format, + |handler| { + c.run(|| { + if is_module { + let program: Program = deserialize_json(s.as_str()) + .context("failed to deserialize Program")?; + c.process_js(handler, program, &options) } else { - FileName::Real(options.filename.clone().into()) - }, - s, - ); - c.process_js_file(fm, handler, &options) - } - }) - }, - ) - .convert_err() + let fm = c.cm.new_source_file( + if options.filename.is_empty() { + FileName::Anon + } else { + FileName::Real(options.filename.clone().into()) + }, + s, + ); + c.process_js_file(fm, handler, &options) + } + }) + }, + ) + }) + .convert_err() } #[napi] @@ -203,22 +212,26 @@ pub fn transform_file_sync( let error_format = options.experimental.error_format.unwrap_or_default(); - try_with( - c.cm.clone(), - !options.config.error.filename.into_bool(), - error_format, - |handler| { - c.run(|| { - if is_module { - let program: Program = - deserialize_json(s.as_str()).context("failed to deserialize Program")?; - c.process_js(handler, program, &options) - } else { - let fm = c.cm.load_file(Path::new(&s)).expect("failed to load file"); - c.process_js_file(fm, handler, &options) - } - }) - }, - ) - .convert_err() + tokio::runtime::Runtime::new() + .unwrap() + .block_on(async move { + try_with( + c.cm.clone(), + !options.config.error.filename.into_bool(), + error_format, + |handler| { + c.run(|| { + if is_module { + let program: Program = deserialize_json(s.as_str()) + .context("failed to deserialize Program")?; + c.process_js(handler, program, &options) + } else { + let fm = c.cm.load_file(Path::new(&s)).expect("failed to load file"); + c.process_js_file(fm, handler, &options) + } + }) + }, + ) + }) + .convert_err() } diff --git a/crates/binding_macros/Cargo.toml b/crates/binding_macros/Cargo.toml index ded1591099a9..3a97d507c073 100644 --- a/crates/binding_macros/Cargo.toml +++ b/crates/binding_macros/Cargo.toml @@ -40,14 +40,13 @@ swc_ecma_transforms = { optional = true, version = "0.229.3", path = "../swc_ecm swc_ecma_visit = { optional = true, version = "0.98.2", path = "../swc_ecma_visit" } # Optional deps for the wasm binding macro -anyhow = { optional = true, version = "1.0.71" } +anyhow = { optional = true, version = "1.0.71" } console_error_panic_hook = { optional = true, version = "0.1.7" } -js-sys = { optional = true, version = "0.3.59" } -once_cell = { optional = true, version = "1.18.0" } -serde = { optional = true, version = "1", features = ["derive"] } -serde-wasm-bindgen = { optional = true, version = "0.4.5" } -# https://github.com/wasmerio/wasmer/blob/77898a7767eb7057834fdc1a80b239e6b68cf44e/lib/wasix/Cargo.toml#L92 -wasm-bindgen = { optional = true, version = "=0.2.84", features = [ +js-sys = { optional = true, version = "0.3.59" } +once_cell = { optional = true, version = "1.18.0" } +serde = { optional = true, version = "1", features = ["derive"] } +serde-wasm-bindgen = { optional = true, version = "0.4.5" } +wasm-bindgen = { optional = true, version = "0.2.91", features = [ "enable-interning", ] } -wasm-bindgen-futures = { optional = true, version = "=0.4.34" } +wasm-bindgen-futures = { optional = true, version = "0.4.41" } diff --git a/crates/swc_plugin_runner/Cargo.toml b/crates/swc_plugin_runner/Cargo.toml index 13ddf211739e..c6850f05ecb7 100644 --- a/crates/swc_plugin_runner/Cargo.toml +++ b/crates/swc_plugin_runner/Cargo.toml @@ -29,10 +29,7 @@ plugin_transform_host_native = [ "wasmer-wasix/host-threads", "wasmer-compiler-cranelift/default", ] -plugin_transform_host_native_shared_runtime = [ - "tokio", - "wasmer-wasix/webc_runner", -] +plugin_transform_host_native_shared_runtime = ["tokio"] # Supports a cache allow to store compiled bytecode into filesystem location. # This feature implies in-memory cache support. This is not supported on wasm32 target. @@ -58,8 +55,8 @@ serde = { version = "1.0.126", features = ["derive"] } serde_json = "1.0.64" tokio = { version = "1", default-features = false, optional = true } tracing = "0.1.37" -wasmer = { version = "4.0.0", default-features = false } -wasmer-wasix = { version = "0.9.0", default-features = false } +wasmer = { version = "4.2.5", default-features = false } +wasmer-wasix = { version = "0.18.0", default-features = false } swc_common = { version = "0.33.17", path = "../swc_common", features = [ "concurrent", @@ -88,6 +85,7 @@ swc_ecma_parser = { version = "0.143.3", path = "../swc_ecma_parser" } swc_ecma_visit = { version = "0.98.2", path = "../swc_ecma_visit" } swc_malloc = { version = "0.5.10", path = "../swc_malloc" } testing = { version = "0.35.18", path = "../testing" } +tokio = { version = "1", features = ["rt"] } [[bench]] harness = false diff --git a/crates/swc_plugin_runner/src/wasix_runtime.rs b/crates/swc_plugin_runner/src/wasix_runtime.rs index 1fa2fb936ac1..eca00d91a0a1 100644 --- a/crates/swc_plugin_runner/src/wasix_runtime.rs +++ b/crates/swc_plugin_runner/src/wasix_runtime.rs @@ -58,7 +58,7 @@ pub fn build_wasi_runtime( use wasmer_wasix::{ runtime::{ module_cache::{ModuleCache, SharedCache}, - package_loader::BuiltinPackageLoader, + package_loader::UnsupportedPackageLoader, resolver::MultiSource, task_manager::tokio::TokioTaskManager, }, @@ -68,9 +68,9 @@ pub fn build_wasi_runtime( let cache = SharedCache::default().with_fallback(wasmer_wasix::runtime::module_cache::in_memory()); - let dummy_loader = BuiltinPackageLoader::new_with_client(".", Arc::new(StubHttpClient)); + let dummy_loader = UnsupportedPackageLoader; let rt = PluggableRuntime { - rt: Arc::new(TokioTaskManager::shared()), + rt: Arc::new(TokioTaskManager::default()), networking: Arc::new(virtual_net::UnsupportedVirtualNetworking::default()), engine: Some(ENGINE.lock().clone()), tty: None, diff --git a/crates/swc_plugin_runner/tests/css_rkyv.rs b/crates/swc_plugin_runner/tests/css_rkyv.rs index 2b128a090e51..dd25a7b53cd2 100644 --- a/crates/swc_plugin_runner/tests/css_rkyv.rs +++ b/crates/swc_plugin_runner/tests/css_rkyv.rs @@ -76,127 +76,127 @@ static PLUGIN_BYTES: Lazy Result<(), Error> { +fn invoke(input: PathBuf) { use swc_css_ast::Stylesheet; - // run single plugin - testing::run_test(false, |cm, _handler| { - let fm = cm.new_source_file(FileName::Anon, "console.log(foo)".into()); - - let parsed: Stylesheet = - swc_css_parser::parse_file(&fm, None, Default::default(), &mut vec![]).unwrap(); - - let program = PluginSerializedBytes::try_serialize( - &swc_common::plugin::serialized::VersionedSerializable::new(parsed.clone()), - ) - .expect("Should serializable"); - let experimental_metadata: AHashMap = [ - ( - "TestExperimental".to_string(), - "ExperimentalValue".to_string(), - ), - ("OtherTest".to_string(), "OtherVal".to_string()), - ] - .into_iter() - .collect(); - - let mut plugin_transform_executor = swc_plugin_runner::create_plugin_transform_executor( - &cm, - &Mark::new(), - &Arc::new(TransformPluginMetadataContext::new( + tokio::runtime::Runtime::new().unwrap().block_on(async { + // run single plugin + testing::run_test(false, |cm, _handler| { + let fm = cm.new_source_file(FileName::Anon, "console.log(foo)".into()); + + let parsed: Stylesheet = + swc_css_parser::parse_file(&fm, None, Default::default(), &mut vec![]).unwrap(); + + let program = PluginSerializedBytes::try_serialize( + &swc_common::plugin::serialized::VersionedSerializable::new(parsed.clone()), + ) + .expect("Should serializable"); + let experimental_metadata: AHashMap = [ + ( + "TestExperimental".to_string(), + "ExperimentalValue".to_string(), + ), + ("OtherTest".to_string(), "OtherVal".to_string()), + ] + .into_iter() + .collect(); + + let mut plugin_transform_executor = swc_plugin_runner::create_plugin_transform_executor( + &cm, + &Mark::new(), + &Arc::new(TransformPluginMetadataContext::new( + None, + "development".to_string(), + Some(experimental_metadata), + )), + Box::new(PLUGIN_BYTES.clone()), + Some(json!({ "pluginConfig": "testValue" })), None, - "development".to_string(), - Some(experimental_metadata), - )), - Box::new(PLUGIN_BYTES.clone()), - Some(json!({ "pluginConfig": "testValue" })), - None, - ); - - info!("Created transform executor"); - - let program_bytes = plugin_transform_executor - .transform(&program, Some(false)) - .expect("Plugin should apply transform"); - - let program: Stylesheet = program_bytes - .deserialize() - .expect("Should able to deserialize") - .into_inner(); - - assert_eq!(parsed, program); + ); + + info!("Created transform executor"); + + let program_bytes = plugin_transform_executor + .transform(&program, Some(false)) + .expect("Plugin should apply transform"); + + let program: Stylesheet = program_bytes + .deserialize() + .expect("Should able to deserialize") + .into_inner(); + + assert_eq!(parsed, program); + + Ok(()) + }) + .expect("Should able to run single plugin transform"); + + // Run multiple plugins. + testing::run_test(false, |cm, _handler| { + let fm = cm.new_source_file(FileName::Anon, "console.log(foo)".into()); + + let parsed: Stylesheet = + swc_css_parser::parse_file(&fm, None, Default::default(), &mut vec![]).unwrap(); + + let mut serialized_program = PluginSerializedBytes::try_serialize( + &swc_common::plugin::serialized::VersionedSerializable::new(parsed.clone()), + ) + .expect("Should serializable"); + + let experimental_metadata: AHashMap = [ + ( + "TestExperimental".to_string(), + "ExperimentalValue".to_string(), + ), + ("OtherTest".to_string(), "OtherVal".to_string()), + ] + .into_iter() + .collect(); + + let mut plugin_transform_executor = swc_plugin_runner::create_plugin_transform_executor( + &cm, + &Mark::new(), + &Arc::new(TransformPluginMetadataContext::new( + None, + "development".to_string(), + Some(experimental_metadata.clone()), + )), + Box::new(PLUGIN_BYTES.clone()), + Some(json!({ "pluginConfig": "testValue" })), + None, + ); + + serialized_program = plugin_transform_executor + .transform(&serialized_program, Some(false)) + .expect("Plugin should apply transform"); + + // TODO: we'll need to apply 2 different plugins + let mut plugin_transform_executor = swc_plugin_runner::create_plugin_transform_executor( + &cm, + &Mark::new(), + &Arc::new(TransformPluginMetadataContext::new( + None, + "development".to_string(), + Some(experimental_metadata), + )), + Box::new(PLUGIN_BYTES.clone()), + Some(json!({ "pluginConfig": "testValue" })), + None, + ); - Ok(()) - }) - .expect("Should able to run single plugin transform"); + serialized_program = plugin_transform_executor + .transform(&serialized_program, Some(false)) + .expect("Plugin should apply transform"); - // Run multiple plugins. - testing::run_test(false, |cm, _handler| { - let fm = cm.new_source_file(FileName::Anon, "console.log(foo)".into()); + let program: Stylesheet = serialized_program + .deserialize() + .expect("Should able to deserialize") + .into_inner(); - let parsed: Stylesheet = - swc_css_parser::parse_file(&fm, None, Default::default(), &mut vec![]).unwrap(); + assert_eq!(parsed, program); - let mut serialized_program = PluginSerializedBytes::try_serialize( - &swc_common::plugin::serialized::VersionedSerializable::new(parsed.clone()), - ) - .expect("Should serializable"); - - let experimental_metadata: AHashMap = [ - ( - "TestExperimental".to_string(), - "ExperimentalValue".to_string(), - ), - ("OtherTest".to_string(), "OtherVal".to_string()), - ] - .into_iter() - .collect(); - - let mut plugin_transform_executor = swc_plugin_runner::create_plugin_transform_executor( - &cm, - &Mark::new(), - &Arc::new(TransformPluginMetadataContext::new( - None, - "development".to_string(), - Some(experimental_metadata.clone()), - )), - Box::new(PLUGIN_BYTES.clone()), - Some(json!({ "pluginConfig": "testValue" })), - None, - ); - - serialized_program = plugin_transform_executor - .transform(&serialized_program, Some(false)) - .expect("Plugin should apply transform"); - - // TODO: we'll need to apply 2 different plugins - let mut plugin_transform_executor = swc_plugin_runner::create_plugin_transform_executor( - &cm, - &Mark::new(), - &Arc::new(TransformPluginMetadataContext::new( - None, - "development".to_string(), - Some(experimental_metadata), - )), - Box::new(PLUGIN_BYTES.clone()), - Some(json!({ "pluginConfig": "testValue" })), - None, - ); - - serialized_program = plugin_transform_executor - .transform(&serialized_program, Some(false)) - .expect("Plugin should apply transform"); - - let program: Stylesheet = serialized_program - .deserialize() - .expect("Should able to deserialize") - .into_inner(); - - assert_eq!(parsed, program); - - Ok(()) - }) - .expect("Should able to run multiple plugins transform"); - - Ok(()) + Ok(()) + }) + .expect("Should able to run multiple plugins transform"); + }); } diff --git a/crates/swc_plugin_runner/tests/ecma_integration.rs b/crates/swc_plugin_runner/tests/ecma_integration.rs index 3cad77696ba4..0683c32535cf 100644 --- a/crates/swc_plugin_runner/tests/ecma_integration.rs +++ b/crates/swc_plugin_runner/tests/ecma_integration.rs @@ -99,100 +99,36 @@ static PLUGIN_BYTES: Lazy Result<(), Error> { +fn internal() { use swc_common::plugin::serialized::VersionedSerializable; - // run single plugin - testing::run_test(false, |cm, _handler| { - let fm = cm.new_source_file(FileName::Anon, "console.log(foo)".into()); + tokio::runtime::Runtime::new().unwrap().block_on(async { + // run single plugin + testing::run_test(false, |cm, _handler| { + let fm = cm.new_source_file(FileName::Anon, "console.log(foo)".into()); - let program = parse_file_as_program( - &fm, - Syntax::Es(Default::default()), - EsVersion::latest(), - None, - &mut vec![], - ) - .unwrap(); - - let program = PluginSerializedBytes::try_serialize(&VersionedSerializable::new(program)) - .expect("Should serializable"); - let experimental_metadata: AHashMap = [ - ( - "TestExperimental".to_string(), - "ExperimentalValue".to_string(), - ), - ("OtherTest".to_string(), "OtherVal".to_string()), - ] - .into_iter() - .collect(); - - let mut plugin_transform_executor = swc_plugin_runner::create_plugin_transform_executor( - &cm, - &Mark::new(), - &Arc::new(TransformPluginMetadataContext::new( + let program = parse_file_as_program( + &fm, + Syntax::Es(Default::default()), + EsVersion::latest(), None, - "development".to_string(), - Some(experimental_metadata), - )), - Box::new(PLUGIN_BYTES.clone()), - Some(json!({ "pluginConfig": "testValue" })), - None, - ); - - /* [TODO]: reenable this later - assert!(!plugin_transform_executor - .plugin_core_diag - .pkg_version - .is_empty()); - */ - - let program_bytes = plugin_transform_executor - .transform(&program, Some(false)) - .expect("Plugin should apply transform"); - - let program: Program = program_bytes - .deserialize() - .expect("Should able to deserialize") - .into_inner(); - let mut visitor = TestVisitor { - plugin_transform_found: false, - }; - program.visit_with(&mut visitor); - - visitor - .plugin_transform_found - .then(|| visitor.plugin_transform_found) - .ok_or(()) - }) - .expect("Should able to run single plugin transform"); - - // run single plugin with handler - testing::run_test2(false, |cm, handler| { - let fm = cm.new_source_file(FileName::Anon, "console.log(foo)".into()); - - let program = parse_file_as_program( - &fm, - Syntax::Es(Default::default()), - EsVersion::latest(), - None, - &mut vec![], - ) - .unwrap(); + &mut vec![], + ) + .unwrap(); + + let program = + PluginSerializedBytes::try_serialize(&VersionedSerializable::new(program)) + .expect("Should serializable"); + let experimental_metadata: AHashMap = [ + ( + "TestExperimental".to_string(), + "ExperimentalValue".to_string(), + ), + ("OtherTest".to_string(), "OtherVal".to_string()), + ] + .into_iter() + .collect(); - let program = PluginSerializedBytes::try_serialize(&VersionedSerializable::new(program)) - .expect("Should serializable"); - let experimental_metadata: AHashMap = [ - ( - "TestExperimental".to_string(), - "ExperimentalValue".to_string(), - ), - ("OtherTest".to_string(), "OtherVal".to_string()), - ] - .into_iter() - .collect(); - - let _res = HANDLER.set(&handler, || { let mut plugin_transform_executor = swc_plugin_runner::create_plugin_transform_executor( &cm, &Mark::new(), @@ -206,92 +142,159 @@ fn internal() -> Result<(), Error> { None, ); - plugin_transform_executor + /* [TODO]: reenable this later + assert!(!plugin_transform_executor + .plugin_core_diag + .pkg_version + .is_empty()); + */ + + let program_bytes = plugin_transform_executor .transform(&program, Some(false)) - .expect("Plugin should apply transform") - }); - - Ok(()) - }) - .expect("Should able to run single plugin transform with handler"); - - // Run multiple plugins. - testing::run_test(false, |cm, _handler| { - let fm = cm.new_source_file(FileName::Anon, "console.log(foo)".into()); - - let program = parse_file_as_program( - &fm, - Syntax::Es(Default::default()), - EsVersion::latest(), - None, - &mut vec![], - ) - .unwrap(); + .expect("Plugin should apply transform"); + + let program: Program = program_bytes + .deserialize() + .expect("Should able to deserialize") + .into_inner(); + let mut visitor = TestVisitor { + plugin_transform_found: false, + }; + program.visit_with(&mut visitor); + + visitor + .plugin_transform_found + .then(|| visitor.plugin_transform_found) + .ok_or(()) + }) + .expect("Should able to run single plugin transform"); + + // run single plugin with handler + testing::run_test2(false, |cm, handler| { + let fm = cm.new_source_file(FileName::Anon, "console.log(foo)".into()); + + let program = parse_file_as_program( + &fm, + Syntax::Es(Default::default()), + EsVersion::latest(), + None, + &mut vec![], + ) + .unwrap(); + + let program = + PluginSerializedBytes::try_serialize(&VersionedSerializable::new(program)) + .expect("Should serializable"); + let experimental_metadata: AHashMap = [ + ( + "TestExperimental".to_string(), + "ExperimentalValue".to_string(), + ), + ("OtherTest".to_string(), "OtherVal".to_string()), + ] + .into_iter() + .collect(); + + let _res = HANDLER.set(&handler, || { + let mut plugin_transform_executor = + swc_plugin_runner::create_plugin_transform_executor( + &cm, + &Mark::new(), + &Arc::new(TransformPluginMetadataContext::new( + None, + "development".to_string(), + Some(experimental_metadata), + )), + Box::new(PLUGIN_BYTES.clone()), + Some(json!({ "pluginConfig": "testValue" })), + None, + ); + + plugin_transform_executor + .transform(&program, Some(false)) + .expect("Plugin should apply transform") + }); + + Ok(()) + }) + .expect("Should able to run single plugin transform with handler"); + + // Run multiple plugins. + testing::run_test(false, |cm, _handler| { + let fm = cm.new_source_file(FileName::Anon, "console.log(foo)".into()); + + let program = parse_file_as_program( + &fm, + Syntax::Es(Default::default()), + EsVersion::latest(), + None, + &mut vec![], + ) + .unwrap(); + + let mut serialized_program = + PluginSerializedBytes::try_serialize(&VersionedSerializable::new(program)) + .expect("Should serializable"); + + let experimental_metadata: AHashMap = [ + ( + "TestExperimental".to_string(), + "ExperimentalValue".to_string(), + ), + ("OtherTest".to_string(), "OtherVal".to_string()), + ] + .into_iter() + .collect(); - let mut serialized_program = - PluginSerializedBytes::try_serialize(&VersionedSerializable::new(program)) - .expect("Should serializable"); - - let experimental_metadata: AHashMap = [ - ( - "TestExperimental".to_string(), - "ExperimentalValue".to_string(), - ), - ("OtherTest".to_string(), "OtherVal".to_string()), - ] - .into_iter() - .collect(); - - let mut plugin_transform_executor = swc_plugin_runner::create_plugin_transform_executor( - &cm, - &Mark::new(), - &Arc::new(TransformPluginMetadataContext::new( + let mut plugin_transform_executor = swc_plugin_runner::create_plugin_transform_executor( + &cm, + &Mark::new(), + &Arc::new(TransformPluginMetadataContext::new( + None, + "development".to_string(), + Some(experimental_metadata.clone()), + )), + Box::new(PLUGIN_BYTES.clone()), + Some(json!({ "pluginConfig": "testValue" })), None, - "development".to_string(), - Some(experimental_metadata.clone()), - )), - Box::new(PLUGIN_BYTES.clone()), - Some(json!({ "pluginConfig": "testValue" })), - None, - ); - - serialized_program = plugin_transform_executor - .transform(&serialized_program, Some(false)) - .expect("Plugin should apply transform"); - - // TODO: we'll need to apply 2 different plugins - let mut plugin_transform_executor = swc_plugin_runner::create_plugin_transform_executor( - &cm, - &Mark::new(), - &Arc::new(TransformPluginMetadataContext::new( + ); + + serialized_program = plugin_transform_executor + .transform(&serialized_program, Some(false)) + .expect("Plugin should apply transform"); + + // TODO: we'll need to apply 2 different plugins + let mut plugin_transform_executor = swc_plugin_runner::create_plugin_transform_executor( + &cm, + &Mark::new(), + &Arc::new(TransformPluginMetadataContext::new( + None, + "development".to_string(), + Some(experimental_metadata), + )), + Box::new(PLUGIN_BYTES.clone()), + Some(json!({ "pluginConfig": "testValue" })), None, - "development".to_string(), - Some(experimental_metadata), - )), - Box::new(PLUGIN_BYTES.clone()), - Some(json!({ "pluginConfig": "testValue" })), - None, - ); - - serialized_program = plugin_transform_executor - .transform(&serialized_program, Some(false)) - .expect("Plugin should apply transform"); - - let program: Program = serialized_program - .deserialize() - .expect("Should able to deserialize") - .into_inner(); - let mut visitor = TestVisitor { - plugin_transform_found: false, - }; - program.visit_with(&mut visitor); - - visitor - .plugin_transform_found - .then(|| visitor.plugin_transform_found) - .ok_or(()) - }) - .expect("Should able to run multiple plugins transform"); - - Ok(()) + ); + + serialized_program = plugin_transform_executor + .transform(&serialized_program, Some(false)) + .expect("Plugin should apply transform"); + + let program: Program = serialized_program + .deserialize() + .expect("Should able to deserialize") + .into_inner(); + let mut visitor = TestVisitor { + plugin_transform_found: false, + }; + program.visit_with(&mut visitor); + + visitor + .plugin_transform_found + .then(|| visitor.plugin_transform_found) + .ok_or(()) + }) + .expect("Should able to run multiple plugins transform"); + }); } diff --git a/crates/swc_plugin_runner/tests/ecma_rkyv.rs b/crates/swc_plugin_runner/tests/ecma_rkyv.rs index e775f83bc020..ef029f35dbc7 100644 --- a/crates/swc_plugin_runner/tests/ecma_rkyv.rs +++ b/crates/swc_plugin_runner/tests/ecma_rkyv.rs @@ -78,140 +78,140 @@ static PLUGIN_BYTES: Lazy Result<(), Error> { +fn internal(input: PathBuf) { // run single plugin - testing::run_test(false, |cm, _handler| { - let fm = cm.new_source_file(FileName::Anon, "console.log(foo)".into()); - - let parsed = parse_file_as_program( - &fm, - Syntax::Typescript(TsConfig { - tsx: input.to_string_lossy().ends_with(".tsx"), - ..Default::default() - }), - EsVersion::latest(), - None, - &mut vec![], - ) - .unwrap(); - - let program = PluginSerializedBytes::try_serialize( - &swc_common::plugin::serialized::VersionedSerializable::new(parsed.clone()), - ) - .expect("Should serializable"); - let experimental_metadata: AHashMap = [ - ( - "TestExperimental".to_string(), - "ExperimentalValue".to_string(), - ), - ("OtherTest".to_string(), "OtherVal".to_string()), - ] - .into_iter() - .collect(); - - let mut plugin_transform_executor = swc_plugin_runner::create_plugin_transform_executor( - &cm, - &Mark::new(), - &Arc::new(TransformPluginMetadataContext::new( + tokio::runtime::Runtime::new().unwrap().block_on(async { + testing::run_test(false, |cm, _handler| { + let fm = cm.new_source_file(FileName::Anon, "console.log(foo)".into()); + + let parsed = parse_file_as_program( + &fm, + Syntax::Typescript(TsConfig { + tsx: input.to_string_lossy().ends_with(".tsx"), + ..Default::default() + }), + EsVersion::latest(), None, - "development".to_string(), - Some(experimental_metadata), - )), - Box::new(PLUGIN_BYTES.clone()), - Some(json!({ "pluginConfig": "testValue" })), - None, - ); - - info!("Created transform executor"); - - let program_bytes = plugin_transform_executor - .transform(&program, Some(false)) - .expect("Plugin should apply transform"); - - let program: Program = program_bytes - .deserialize() - .expect("Should able to deserialize") - .into_inner(); - - assert_eq!(parsed, program); - - Ok(()) - }) - .expect("Should able to run single plugin transform"); - - // Run multiple plugins. - testing::run_test(false, |cm, _handler| { - let fm = cm.new_source_file(FileName::Anon, "console.log(foo)".into()); - - let parsed = parse_file_as_program( - &fm, - Syntax::Es(Default::default()), - EsVersion::latest(), - None, - &mut vec![], - ) - .unwrap(); + &mut vec![], + ) + .unwrap(); + + let program = PluginSerializedBytes::try_serialize( + &swc_common::plugin::serialized::VersionedSerializable::new(parsed.clone()), + ) + .expect("Should serializable"); + let experimental_metadata: AHashMap = [ + ( + "TestExperimental".to_string(), + "ExperimentalValue".to_string(), + ), + ("OtherTest".to_string(), "OtherVal".to_string()), + ] + .into_iter() + .collect(); + + let mut plugin_transform_executor = swc_plugin_runner::create_plugin_transform_executor( + &cm, + &Mark::new(), + &Arc::new(TransformPluginMetadataContext::new( + None, + "development".to_string(), + Some(experimental_metadata), + )), + Box::new(PLUGIN_BYTES.clone()), + Some(json!({ "pluginConfig": "testValue" })), + None, + ); - let mut serialized_program = PluginSerializedBytes::try_serialize( - &swc_common::plugin::serialized::VersionedSerializable::new(parsed.clone()), - ) - .expect("Should serializable"); - - let experimental_metadata: AHashMap = [ - ( - "TestExperimental".to_string(), - "ExperimentalValue".to_string(), - ), - ("OtherTest".to_string(), "OtherVal".to_string()), - ] - .into_iter() - .collect(); - - let mut plugin_transform_executor = swc_plugin_runner::create_plugin_transform_executor( - &cm, - &Mark::new(), - &Arc::new(TransformPluginMetadataContext::new( + info!("Created transform executor"); + + let program_bytes = plugin_transform_executor + .transform(&program, Some(false)) + .expect("Plugin should apply transform"); + + let program: Program = program_bytes + .deserialize() + .expect("Should able to deserialize") + .into_inner(); + + assert_eq!(parsed, program); + + Ok(()) + }) + .expect("Should able to run single plugin transform"); + + // Run multiple plugins. + testing::run_test(false, |cm, _handler| { + let fm = cm.new_source_file(FileName::Anon, "console.log(foo)".into()); + + let parsed = parse_file_as_program( + &fm, + Syntax::Es(Default::default()), + EsVersion::latest(), + None, + &mut vec![], + ) + .unwrap(); + + let mut serialized_program = PluginSerializedBytes::try_serialize( + &swc_common::plugin::serialized::VersionedSerializable::new(parsed.clone()), + ) + .expect("Should serializable"); + + let experimental_metadata: AHashMap = [ + ( + "TestExperimental".to_string(), + "ExperimentalValue".to_string(), + ), + ("OtherTest".to_string(), "OtherVal".to_string()), + ] + .into_iter() + .collect(); + + let mut plugin_transform_executor = swc_plugin_runner::create_plugin_transform_executor( + &cm, + &Mark::new(), + &Arc::new(TransformPluginMetadataContext::new( + None, + "development".to_string(), + Some(experimental_metadata.clone()), + )), + Box::new(PLUGIN_BYTES.clone()), + Some(json!({ "pluginConfig": "testValue" })), None, - "development".to_string(), - Some(experimental_metadata.clone()), - )), - Box::new(PLUGIN_BYTES.clone()), - Some(json!({ "pluginConfig": "testValue" })), - None, - ); - - serialized_program = plugin_transform_executor - .transform(&serialized_program, Some(false)) - .expect("Plugin should apply transform"); - - // TODO: we'll need to apply 2 different plugins - let mut plugin_transform_executor = swc_plugin_runner::create_plugin_transform_executor( - &cm, - &Mark::new(), - &Arc::new(TransformPluginMetadataContext::new( + ); + + serialized_program = plugin_transform_executor + .transform(&serialized_program, Some(false)) + .expect("Plugin should apply transform"); + + // TODO: we'll need to apply 2 different plugins + let mut plugin_transform_executor = swc_plugin_runner::create_plugin_transform_executor( + &cm, + &Mark::new(), + &Arc::new(TransformPluginMetadataContext::new( + None, + "development".to_string(), + Some(experimental_metadata), + )), + Box::new(PLUGIN_BYTES.clone()), + Some(json!({ "pluginConfig": "testValue" })), None, - "development".to_string(), - Some(experimental_metadata), - )), - Box::new(PLUGIN_BYTES.clone()), - Some(json!({ "pluginConfig": "testValue" })), - None, - ); - - serialized_program = plugin_transform_executor - .transform(&serialized_program, Some(false)) - .expect("Plugin should apply transform"); - - let program: Program = serialized_program - .deserialize() - .expect("Should able to deserialize") - .into_inner(); - - assert_eq!(parsed, program); - - Ok(()) - }) - .expect("Should able to run multiple plugins transform"); - - Ok(()) + ); + + serialized_program = plugin_transform_executor + .transform(&serialized_program, Some(false)) + .expect("Plugin should apply transform"); + + let program: Program = serialized_program + .deserialize() + .expect("Should able to deserialize") + .into_inner(); + + assert_eq!(parsed, program); + + Ok(()) + }) + .expect("Should able to run multiple plugins transform"); + }); } diff --git a/crates/swc_plugin_runner/tests/issues.rs b/crates/swc_plugin_runner/tests/issues.rs index 5fc9eedc4796..754f9e8ec8f7 100644 --- a/crates/swc_plugin_runner/tests/issues.rs +++ b/crates/swc_plugin_runner/tests/issues.rs @@ -82,82 +82,86 @@ fn issue_6404() -> Result<(), Error> { "swc_issue_6404", )?; - dbg!("Built!"); - - // run single plugin - testing::run_test(false, |cm, _handler| { - let fm = cm - .load_file("../swc_ecma_minifier/benches/full/typescript.js".as_ref()) + tokio::runtime::Runtime::new().unwrap().block_on(async { + dbg!("Built!"); + + // run single plugin + testing::run_test(false, |cm, _handler| { + let fm = cm + .load_file("../swc_ecma_minifier/benches/full/typescript.js".as_ref()) + .unwrap(); + + let program = parse_file_as_program( + &fm, + Syntax::Es(Default::default()), + EsVersion::latest(), + None, + &mut vec![], + ) .unwrap(); - let program = parse_file_as_program( - &fm, - Syntax::Es(Default::default()), - EsVersion::latest(), - None, - &mut vec![], - ) - .unwrap(); - - let program = PluginSerializedBytes::try_serialize(&VersionedSerializable::new(program)) - .expect("Should serializable"); - let experimental_metadata: AHashMap = [ - ( - "TestExperimental".to_string(), - "ExperimentalValue".to_string(), - ), - ("OtherTest".to_string(), "OtherVal".to_string()), - ] - .into_iter() - .collect(); - - let raw_module_bytes = - std::fs::read(&plugin_path).expect("Should able to read plugin bytes"); - let store = wasmer::Store::default(); - let module = wasmer::Module::new(&store, raw_module_bytes).unwrap(); - - let plugin_module = swc_plugin_runner::plugin_module_bytes::CompiledPluginModuleBytes::new( - plugin_path - .as_os_str() - .to_str() - .expect("Should able to get path") - .to_string(), - module, - store, - ); - - let mut plugin_transform_executor = swc_plugin_runner::create_plugin_transform_executor( - &cm, - &Mark::new(), - &Arc::new(TransformPluginMetadataContext::new( + let program = + PluginSerializedBytes::try_serialize(&VersionedSerializable::new(program)) + .expect("Should serializable"); + let experimental_metadata: AHashMap = [ + ( + "TestExperimental".to_string(), + "ExperimentalValue".to_string(), + ), + ("OtherTest".to_string(), "OtherVal".to_string()), + ] + .into_iter() + .collect(); + + let raw_module_bytes = + std::fs::read(&plugin_path).expect("Should able to read plugin bytes"); + let store = wasmer::Store::default(); + let module = wasmer::Module::new(&store, raw_module_bytes).unwrap(); + + let plugin_module = + swc_plugin_runner::plugin_module_bytes::CompiledPluginModuleBytes::new( + plugin_path + .as_os_str() + .to_str() + .expect("Should able to get path") + .to_string(), + module, + store, + ); + + let mut plugin_transform_executor = swc_plugin_runner::create_plugin_transform_executor( + &cm, + &Mark::new(), + &Arc::new(TransformPluginMetadataContext::new( + None, + "development".to_string(), + Some(experimental_metadata), + )), + Box::new(plugin_module), + Some(json!({ "pluginConfig": "testValue" })), None, - "development".to_string(), - Some(experimental_metadata), - )), - Box::new(plugin_module), - Some(json!({ "pluginConfig": "testValue" })), - None, - ); - - /* [TODO]: reenable this test - assert!(!plugin_transform_executor - .plugin_core_diag - .pkg_version - .is_empty()); - */ - - let program_bytes = plugin_transform_executor - .transform(&program, Some(false)) - .expect("Plugin should apply transform"); - - let _: Program = program_bytes - .deserialize() - .expect("Should able to deserialize") - .into_inner(); - - Ok(()) - }) - .expect("Should able to run single plugin transform"); + ); + + /* [TODO]: reenable this test + assert!(!plugin_transform_executor + .plugin_core_diag + .pkg_version + .is_empty()); + */ + + let program_bytes = plugin_transform_executor + .transform(&program, Some(false)) + .expect("Plugin should apply transform"); + + let _: Program = program_bytes + .deserialize() + .expect("Should able to deserialize") + .into_inner(); + + Ok(()) + }) + .expect("Should able to run single plugin transform"); + }); Ok(()) } diff --git a/deny.toml b/deny.toml index 20c37ae37575..8465f9426284 100644 --- a/deny.toml +++ b/deny.toml @@ -77,6 +77,7 @@ allow = [ "0BSD", "LicenseRef-ring", #ring "Unicode-DFS-2016", #unicode-ident + "BSL-1.0", #xxhash-rust ] # List of explictly disallowed licenses # See https://spdx.org/licenses/ for list of possible licenses diff --git a/node-swc/e2e/plugins/plugins.compat.test.js b/node-swc/e2e/plugins/plugins.compat.test.js index c21a45a1d40b..804ec1919664 100644 --- a/node-swc/e2e/plugins/plugins.compat.test.js +++ b/node-swc/e2e/plugins/plugins.compat.test.js @@ -103,5 +103,44 @@ describe("Published plugins", () => { " `); }); + + it("should compile without seg fault (async)", async () => { + const { transform } = require(path.resolve( + getPkgRoot(), + packageName + )); + console.log(`Package name: ${packageName}`); + + const options = { + jsc: { + target: "es5", + parser: { + syntax: "typescript", + }, + experimental: { + plugins: [ + ["@swc/plugin-jest", {}], + // Disabled because this plugin is broken + // ["swc-plugin-coverage-instrument", {}], + ], + }, + }, + }; + + console.log("Before transform"); + + const { code } = await transform( + 'console.log("hello world")', + false, + Buffer.from(JSON.stringify(options)) + ); + + console.log("After transform"); + + expect(code).toMatchInlineSnapshot(` + "console.log("hello world"); + " + `); + }); } });