From 1efb11e2199cd16a4027d022a0e6355f1045b554 Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Mon, 22 Jan 2024 19:41:53 +0800 Subject: [PATCH] Chore: update rspack version (#32) * chore: update rspack * feat: support rspack 0.5.1 * fix: format * fix: add new line for ci * fix: remove unexpected test case * fix: test case * fix: test case --- .github/actions/clone-crates/action.yml | 2 +- .github/workflows/release.yml | 2 +- Cargo.lock | 839 ++++++++---------- Cargo.toml | 37 +- crates/binding_options/Cargo.toml | 108 +-- crates/binding_options/src/options/mod.rs | 20 +- .../binding_options/src/options/raw_module.rs | 12 +- crates/loader_barrel/src/lib.rs | 33 +- crates/loader_barrel/tests/fixtures.rs | 11 +- crates/loader_compilation/src/lib.rs | 8 +- crates/loader_compilation/src/transform.rs | 15 +- crates/loader_compilation/tests/fixtures.rs | 9 +- crates/node_binding/Cargo.toml | 13 +- crates/node_binding/src/hook.rs | 6 + crates/node_binding/src/lib.rs | 24 +- crates/node_binding/src/plugins/loader.rs | 8 +- crates/node_binding/src/plugins/mod.rs | 73 +- crates/plugin_manifest/src/plugin.rs | 17 +- .../tests/fixtures/basic/snapshot/output.snap | 2 +- .../.gitignore | 0 .../Cargo.toml | 15 +- .../package.json | 0 .../src/change_package_import.rs | 212 +++++ .../swc_change_package_import/src/config.rs | 62 ++ .../src/lib.rs | 4 +- .../tests/fixture.rs | 301 +++++++ .../fixture/ice_alias_transform/input.js | 0 .../fixture/ice_alias_transform/output.js | 0 .../ice_alias_with_as_transform/input.js | 0 .../ice_alias_with_as_transform/output.js | 0 .../tests/fixture/ice_as_transform/input.js | 0 .../tests/fixture/ice_as_transform/output.js | 0 .../fixture/ice_basic_transform/input.js | 0 .../fixture/ice_basic_transform/output.js | 0 .../fixture/ice_matched_transform/input.js | 0 .../fixture/ice_matched_transform/output.js | 0 .../fixture/ice_miss_match_transform/input.js | 0 .../ice_miss_match_transform/output.js | 0 .../fixture/ice_multiple_transform/input.js | 0 .../fixture/ice_multiple_transform/output.js | 2 +- .../fixture/mix_specific_transform/input.js | 0 .../fixture/mix_specific_transform/output.js | 0 .../fixture/multi_literal_transform/input.js | 0 .../fixture/multi_literal_transform/output.js | 0 .../fixture/multi_specific_transform/input.js | 0 .../multi_specific_transform/output.js | 0 .../fixture/single_literal_transform/input.js | 0 .../single_literal_transform/output.js | 0 .../single_specific_transform/input.js | 0 .../single_specific_transform/output.js | 0 .../single_specific_transform_2/input.js | 0 .../single_specific_transform_2/output.js | 0 .../src/change_package_import.rs | 207 ----- .../src/config.rs | 62 -- .../tests/fixture.rs | 442 --------- rust-toolchain.toml | 2 +- 56 files changed, 1215 insertions(+), 1333 deletions(-) rename crates/{swc_plugin_change_package_import => swc_change_package_import}/.gitignore (100%) rename crates/{swc_plugin_change_package_import => swc_change_package_import}/Cargo.toml (59%) rename crates/{swc_plugin_change_package_import => swc_change_package_import}/package.json (100%) create mode 100644 crates/swc_change_package_import/src/change_package_import.rs create mode 100644 crates/swc_change_package_import/src/config.rs rename crates/{swc_plugin_change_package_import => swc_change_package_import}/src/lib.rs (63%) create mode 100644 crates/swc_change_package_import/tests/fixture.rs rename crates/{swc_plugin_change_package_import => swc_change_package_import}/tests/fixture/ice_alias_transform/input.js (100%) rename crates/{swc_plugin_change_package_import => swc_change_package_import}/tests/fixture/ice_alias_transform/output.js (100%) rename crates/{swc_plugin_change_package_import => swc_change_package_import}/tests/fixture/ice_alias_with_as_transform/input.js (100%) rename crates/{swc_plugin_change_package_import => swc_change_package_import}/tests/fixture/ice_alias_with_as_transform/output.js (100%) rename crates/{swc_plugin_change_package_import => swc_change_package_import}/tests/fixture/ice_as_transform/input.js (100%) rename crates/{swc_plugin_change_package_import => swc_change_package_import}/tests/fixture/ice_as_transform/output.js (100%) rename crates/{swc_plugin_change_package_import => swc_change_package_import}/tests/fixture/ice_basic_transform/input.js (100%) rename crates/{swc_plugin_change_package_import => swc_change_package_import}/tests/fixture/ice_basic_transform/output.js (100%) rename crates/{swc_plugin_change_package_import => swc_change_package_import}/tests/fixture/ice_matched_transform/input.js (100%) rename crates/{swc_plugin_change_package_import => swc_change_package_import}/tests/fixture/ice_matched_transform/output.js (100%) rename crates/{swc_plugin_change_package_import => swc_change_package_import}/tests/fixture/ice_miss_match_transform/input.js (100%) rename crates/{swc_plugin_change_package_import => swc_change_package_import}/tests/fixture/ice_miss_match_transform/output.js (100%) rename crates/{swc_plugin_change_package_import => swc_change_package_import}/tests/fixture/ice_multiple_transform/input.js (100%) rename crates/{swc_plugin_change_package_import => swc_change_package_import}/tests/fixture/ice_multiple_transform/output.js (66%) rename crates/{swc_plugin_change_package_import => swc_change_package_import}/tests/fixture/mix_specific_transform/input.js (100%) rename crates/{swc_plugin_change_package_import => swc_change_package_import}/tests/fixture/mix_specific_transform/output.js (100%) rename crates/{swc_plugin_change_package_import => swc_change_package_import}/tests/fixture/multi_literal_transform/input.js (100%) rename crates/{swc_plugin_change_package_import => swc_change_package_import}/tests/fixture/multi_literal_transform/output.js (100%) rename crates/{swc_plugin_change_package_import => swc_change_package_import}/tests/fixture/multi_specific_transform/input.js (100%) rename crates/{swc_plugin_change_package_import => swc_change_package_import}/tests/fixture/multi_specific_transform/output.js (100%) rename crates/{swc_plugin_change_package_import => swc_change_package_import}/tests/fixture/single_literal_transform/input.js (100%) rename crates/{swc_plugin_change_package_import => swc_change_package_import}/tests/fixture/single_literal_transform/output.js (100%) rename crates/{swc_plugin_change_package_import => swc_change_package_import}/tests/fixture/single_specific_transform/input.js (100%) rename crates/{swc_plugin_change_package_import => swc_change_package_import}/tests/fixture/single_specific_transform/output.js (100%) rename crates/{swc_plugin_change_package_import => swc_change_package_import}/tests/fixture/single_specific_transform_2/input.js (100%) rename crates/{swc_plugin_change_package_import => swc_change_package_import}/tests/fixture/single_specific_transform_2/output.js (100%) delete mode 100644 crates/swc_plugin_change_package_import/src/change_package_import.rs delete mode 100644 crates/swc_plugin_change_package_import/src/config.rs delete mode 100644 crates/swc_plugin_change_package_import/tests/fixture.rs diff --git a/.github/actions/clone-crates/action.yml b/.github/actions/clone-crates/action.yml index 815eaa1..e0cce14 100644 --- a/.github/actions/clone-crates/action.yml +++ b/.github/actions/clone-crates/action.yml @@ -12,7 +12,7 @@ inputs: required: false type: string ref: - default: 'v0.4.5' + default: 'v0.5.1' required: false type: string temp: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d6f6e23..9e9e5e8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -76,7 +76,7 @@ jobs: uses: dtolnay/rust-toolchain@stable if: ${{ !matrix.settings.docker }} with: - toolchain: nightly-2023-10-24 + toolchain: nightly-2023-12-28 targets: ${{ matrix.settings.target }} - name: Cache cargo diff --git a/Cargo.lock b/Cargo.lock index ee60b6e..55cb981 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -82,6 +82,15 @@ dependencies = [ "libc", ] +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi", +] + [[package]] name = "anyhow" version = "1.0.75" @@ -116,7 +125,7 @@ dependencies = [ "argh_shared", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -143,7 +152,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -154,7 +163,7 @@ checksum = "5fd55a5ba1179988837d24ab4c7cc8ed6efdeff578ede0416b4225a5fca35bd0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -177,7 +186,7 @@ checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -255,19 +264,6 @@ dependencies = [ "vsimd", ] -[[package]] -name = "bench" -version = "0.1.0" -dependencies = [ - "mimalloc-rust", - "rspack_core", - "rspack_fs", - "rspack_testing", - "rspack_tracing", - "tikv-jemallocator", - "tokio", -] - [[package]] name = "better_scoped_tls" version = "0.1.1" @@ -281,31 +277,31 @@ dependencies = [ name = "binding_options" version = "0.1.0" dependencies = [ - "anyhow", "async-trait", "better_scoped_tls", "derivative", - "futures-util", "glob", "loader_barrel", "loader_compilation", "napi", "napi-derive", "plugin_manifest", + "rspack_binding_macros", "rspack_binding_options", + "rspack_binding_values", "rspack_core", "rspack_error", "rspack_hash", + "rspack_identifier", "rspack_ids", "rspack_loader_react_refresh", "rspack_loader_runner", - "rspack_loader_sass", "rspack_loader_swc", + "rspack_napi_shared", "rspack_plugin_asset", "rspack_plugin_banner", "rspack_plugin_copy", "rspack_plugin_css", - "rspack_plugin_dev_friendly_split_chunks", "rspack_plugin_devtool", "rspack_plugin_ensure_chunk_conditions", "rspack_plugin_entry", @@ -316,12 +312,13 @@ dependencies = [ "rspack_plugin_json", "rspack_plugin_library", "rspack_plugin_limit_chunk_count", + "rspack_plugin_merge_duplicate_chunks", + "rspack_plugin_mf", "rspack_plugin_progress", "rspack_plugin_real_content_hash", "rspack_plugin_remove_empty_chunks", "rspack_plugin_runtime", "rspack_plugin_schemes", - "rspack_plugin_split_chunks", "rspack_plugin_split_chunks_new", "rspack_plugin_swc_css_minimizer", "rspack_plugin_swc_js_minimizer", @@ -334,6 +331,8 @@ dependencies = [ "rustc-hash", "serde", "serde_json", + "swc_config", + "swc_core", "tokio", "tracing", ] @@ -438,10 +437,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] -name = "bytes" -version = "1.5.0" +name = "camino" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" +checksum = "c59e92b5a388f549b863a7bea62612c09f24c8393560709a54558a9abdfb3b9c" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo-platform" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ceed8ef69d8518a5dda55c07425450b58a4e1946f4951eab6d7191ee86c2443d" +dependencies = [ + "serde", +] [[package]] name = "cargo-rst" @@ -457,6 +468,20 @@ dependencies = [ "testing_macros", ] +[[package]] +name = "cargo_metadata" +version = "0.15.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eee4243f1f26fc7a42710e7439c149e2b10b05472f88090acce52632f231a73a" +dependencies = [ + "camino", + "cargo-platform", + "semver 1.0.20", + "serde", + "serde_json", + "thiserror", +] + [[package]] name = "cast" version = "0.3.0" @@ -603,16 +628,6 @@ dependencies = [ "itertools", ] -[[package]] -name = "crossbeam-channel" -version = "0.5.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" -dependencies = [ - "cfg-if", - "crossbeam-utils", -] - [[package]] name = "crossbeam-deque" version = "0.8.3" @@ -639,12 +654,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.16" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" -dependencies = [ - "cfg-if", -] +checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" [[package]] name = "crypto-common" @@ -684,7 +696,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37e366bff8cd32dd8754b0991fb66b279dc48f598c3a18914852a6673deef583" dependencies = [ "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -693,12 +705,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" -[[package]] -name = "daachorse" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63b7ef7a4be509357f4804d0a22e830daddb48f19fd604e4ad32ddce04a94c36" - [[package]] name = "darling" version = "0.14.4" @@ -811,6 +817,12 @@ version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" +[[package]] +name = "difference" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" + [[package]] name = "digest" version = "0.10.7" @@ -863,14 +875,20 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.6" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c18ee0ed65a5f1f81cac6b1d213b69c35fa47d4252ad41f1486dbd8226fe36e" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" dependencies = [ "libc", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] +[[package]] +name = "fastrand" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" + [[package]] name = "fixedbitset" version = "0.4.2" @@ -900,7 +918,7 @@ checksum = "3a0b11eeb173ce52f84ebd943d42e58813a2ebb78a6a3ff0a243b71c5199cd7b" dependencies = [ "proc-macro2", "swc_macros_common", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -965,7 +983,7 @@ checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -1124,6 +1142,12 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + [[package]] name = "hrx-parser" version = "0.1.1" @@ -1266,7 +1290,7 @@ dependencies = [ "pmutil", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -1415,9 +1439,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.150" +version = "0.2.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" +checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" [[package]] name = "libloading" @@ -1446,9 +1470,9 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.4.11" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" [[package]] name = "loader_barrel" @@ -1623,7 +1647,7 @@ checksum = "49e7bc1560b95a3c4a25d03de42fe76ca718ab92d1a22a55b9b4cf67b3ae635c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -1751,13 +1775,10 @@ dependencies = [ "async-trait", "binding_options", "color-backtrace", - "dashmap", - "futures", "mimalloc-rust", "napi", "napi-build", "napi-derive", - "napi-sys", "once_cell", "rspack_binding_macros", "rspack_binding_options", @@ -1765,35 +1786,13 @@ dependencies = [ "rspack_core", "rspack_error", "rspack_fs_node", - "rspack_identifier", "rspack_napi_shared", "rspack_tracing", - "rustc-hash", - "serde_json", + "testing_macros", "tikv-jemallocator", "tracing", ] -[[package]] -name = "nodejs-resolver" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "517c9a4e74fdd7a26d38b1dca0cfff40af33ee3b1d5f379f7c9d711ba5a5d10d" -dependencies = [ - "daachorse", - "dashmap", - "dunce", - "indexmap 2.1.0", - "jsonc-parser 0.22.1", - "once_cell", - "path-absolutize", - "rustc-hash", - "serde", - "serde_json", - "tracing", - "tracing-subscriber", -] - [[package]] name = "nom" version = "7.1.3" @@ -1911,9 +1910,9 @@ checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" [[package]] name = "oxc_resolver" -version = "0.6.2" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ac76a705bf7db9d1e43904ed4704039de8fa654b0f613cc729c09bb67fd89f6" +checksum = "8c0eb6a40f9d03e5e4da3369c3f3f154e824c2ac46ea045cb7dfcefe6c7fa3dd" dependencies = [ "dashmap", "dunce", @@ -1980,15 +1979,6 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" -[[package]] -name = "path-absolutize" -version = "3.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4af381fe79fa195b4909485d99f73a80792331df0625188e707854f0b3383f5" -dependencies = [ - "path-dedot", -] - [[package]] name = "path-clean" version = "0.1.0" @@ -2001,15 +1991,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17359afc20d7ab31fdb42bb844c8b3bb1dabd7dcf7e68428492da7f16966fcef" -[[package]] -name = "path-dedot" -version = "3.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07ba0ad7e047712414213ff67533e6dd477af0a4e1d14fb52343e53d30ea9397" -dependencies = [ - "once_cell", -] - [[package]] name = "pathdiff" version = "0.2.1" @@ -2053,7 +2034,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -2119,7 +2100,7 @@ dependencies = [ "phf_shared 0.11.2", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -2157,7 +2138,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -2233,7 +2214,7 @@ checksum = "52a40bc70c2c58040d2d8b167ba9a5ff59fc9dab7ad44771cfde3dcfde7a09c6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -2308,36 +2289,13 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.69" +version = "1.0.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" dependencies = [ "unicode-ident", ] -[[package]] -name = "prost" -version = "0.11.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b82eaa1d779e9a4bc1c3217db8ffbeabaae1dca241bf70183242128d48681cd" -dependencies = [ - "bytes", - "prost-derive", -] - -[[package]] -name = "prost-derive" -version = "0.11.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5d2d8d10f3c6ded6da8b05b5fb3b8a5082514344d56c9f871412d29b4e075b4" -dependencies = [ - "anyhow", - "itertools", - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "psm" version = "0.1.21" @@ -2369,9 +2327,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -2598,11 +2556,9 @@ name = "rspack_ast" version = "0.1.0" dependencies = [ "anyhow", - "rspack_error", "swc_core", "swc_error_reporters", "swc_node_comments", - "tokio", ] [[package]] @@ -2633,7 +2589,6 @@ version = "0.1.0" name = "rspack_binding_options" version = "0.1.0" dependencies = [ - "anyhow", "async-trait", "better_scoped_tls", "derivative", @@ -2648,14 +2603,12 @@ dependencies = [ "rspack_ids", "rspack_loader_react_refresh", "rspack_loader_runner", - "rspack_loader_sass", "rspack_loader_swc", "rspack_napi_shared", "rspack_plugin_asset", "rspack_plugin_banner", "rspack_plugin_copy", "rspack_plugin_css", - "rspack_plugin_dev_friendly_split_chunks", "rspack_plugin_devtool", "rspack_plugin_ensure_chunk_conditions", "rspack_plugin_entry", @@ -2673,7 +2626,6 @@ dependencies = [ "rspack_plugin_remove_empty_chunks", "rspack_plugin_runtime", "rspack_plugin_schemes", - "rspack_plugin_split_chunks", "rspack_plugin_split_chunks_new", "rspack_plugin_swc_css_minimizer", "rspack_plugin_swc_js_minimizer", @@ -2696,13 +2648,8 @@ dependencies = [ name = "rspack_binding_values" version = "0.1.0" dependencies = [ - "anyhow", - "async-trait", - "better_scoped_tls", "dashmap", - "derivative", "futures", - "glob", "napi", "napi-derive", "napi-sys", @@ -2710,53 +2657,14 @@ dependencies = [ "rspack_core", "rspack_error", "rspack_identifier", - "rspack_ids", - "rspack_loader_react_refresh", - "rspack_loader_runner", - "rspack_loader_sass", - "rspack_loader_swc", "rspack_napi_shared", - "rspack_plugin_asset", - "rspack_plugin_banner", - "rspack_plugin_copy", - "rspack_plugin_css", - "rspack_plugin_dev_friendly_split_chunks", - "rspack_plugin_devtool", - "rspack_plugin_ensure_chunk_conditions", - "rspack_plugin_entry", - "rspack_plugin_externals", - "rspack_plugin_hmr", - "rspack_plugin_html", - "rspack_plugin_javascript", - "rspack_plugin_json", - "rspack_plugin_library", - "rspack_plugin_progress", - "rspack_plugin_real_content_hash", - "rspack_plugin_remove_empty_chunks", - "rspack_plugin_runtime", - "rspack_plugin_schemes", - "rspack_plugin_split_chunks", - "rspack_plugin_split_chunks_new", - "rspack_plugin_swc_css_minimizer", - "rspack_plugin_swc_js_minimizer", - "rspack_plugin_wasm", - "rspack_plugin_worker", - "rspack_regex", - "rspack_swc_visitors", - "rspack_util", "rustc-hash", - "serde", - "serde_json", - "swc_core", - "tokio", - "tracing", ] [[package]] name = "rspack_core" version = "0.1.0" dependencies = [ - "anyhow", "anymap", "async-recursion", "async-trait", @@ -2772,7 +2680,6 @@ dependencies = [ "itertools", "json", "mime_guess", - "nodejs-resolver", "once_cell", "oxc_resolver", "paste", @@ -2796,13 +2703,9 @@ dependencies = [ "rustc-hash", "serde", "serde_json", - "string_cache", "sugar_path", "swc_core", - "swc_emotion", - "swc_error_reporters", "swc_node_comments", - "swc_plugin_import", "tokio", "tracing", "url", @@ -2825,22 +2728,12 @@ version = "0.1.0" dependencies = [ "anyhow", "futures", - "insta", "miette 5.10.0", - "rspack_binding_options", - "rspack_core", - "rspack_fs", + "once_cell", "rspack_identifier", - "rspack_sources", - "rspack_testing", - "rspack_tracing", - "rspack_util", - "serde_json", - "sugar_path", "swc_core", "termcolor", "thiserror", - "tokio", ] [[package]] @@ -2935,25 +2828,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "rspack_loader_sass" -version = "0.1.0" -dependencies = [ - "async-trait", - "indexmap 1.9.3", - "itertools", - "once_cell", - "regex", - "rspack_core", - "rspack_error", - "rspack_loader_runner", - "rspack_testing", - "sass-embedded", - "serde", - "str_indices", - "tokio", -] - [[package]] name = "rspack_loader_swc" version = "0.1.0" @@ -2976,8 +2850,6 @@ dependencies = [ "serde_json", "swc_config", "swc_core", - "swc_emotion", - "swc_plugin_import", "xxhash-rust", ] @@ -2997,13 +2869,10 @@ version = "0.1.0" dependencies = [ "async-trait", "color-backtrace", - "dashmap", - "futures", "mimalloc-rust", "napi", "napi-build", "napi-derive", - "napi-sys", "once_cell", "rspack_binding_macros", "rspack_binding_options", @@ -3011,10 +2880,8 @@ dependencies = [ "rspack_core", "rspack_error", "rspack_fs_node", - "rspack_identifier", "rspack_napi_shared", "rspack_tracing", - "rustc-hash", "testing_macros", "tikv-jemallocator", "tracing", @@ -3072,14 +2939,12 @@ dependencies = [ "sugar_path", "testing_macros", "tokio", - "tracing", ] [[package]] name = "rspack_plugin_css" version = "0.1.0" dependencies = [ - "anyhow", "async-trait", "bitflags 1.3.2", "heck", @@ -3094,9 +2959,9 @@ dependencies = [ "rspack_error", "rspack_hash", "rspack_identifier", + "rspack_plugin_runtime", "rspack_testing", "rustc-hash", - "serde", "serde_json", "sugar_path", "swc_core", @@ -3104,17 +2969,6 @@ dependencies = [ "urlencoding", ] -[[package]] -name = "rspack_plugin_dev_friendly_split_chunks" -version = "0.1.0" -dependencies = [ - "async-trait", - "dashmap", - "rayon", - "rspack_core", - "rspack_identifier", -] - [[package]] name = "rspack_plugin_devtool" version = "0.1.0" @@ -3158,7 +3012,6 @@ dependencies = [ "once_cell", "regex", "rspack_core", - "rspack_error", "rspack_regex", ] @@ -3204,8 +3057,6 @@ dependencies = [ name = "rspack_plugin_javascript" version = "0.1.0" dependencies = [ - "anyhow", - "async-recursion", "async-trait", "bitflags 1.3.2", "either", @@ -3229,14 +3080,10 @@ dependencies = [ "rspack_util", "rustc-hash", "serde_json", - "sourcemap", "sugar_path", "swc_core", - "swc_emotion", "swc_node_comments", - "swc_plugin_import", "url", - "xxhash-rust", ] [[package]] @@ -3270,7 +3117,6 @@ dependencies = [ "async-trait", "rspack_core", "rspack_database", - "rspack_util", ] [[package]] @@ -3279,8 +3125,6 @@ version = "0.1.0" dependencies = [ "async-trait", "rspack_core", - "rspack_database", - "rspack_util", "rustc-hash", ] @@ -3341,7 +3185,6 @@ dependencies = [ name = "rspack_plugin_runtime" version = "0.1.0" dependencies = [ - "anyhow", "async-trait", "indexmap 1.9.3", "itertools", @@ -3371,29 +3214,13 @@ dependencies = [ "urlencoding", ] -[[package]] -name = "rspack_plugin_split_chunks" -version = "0.1.0" -dependencies = [ - "async-trait", - "derivative", - "rspack_core", - "rspack_identifier", - "rspack_util", - "rustc-hash", - "tracing", -] - [[package]] name = "rspack_plugin_split_chunks_new" version = "0.1.0" dependencies = [ - "async-scoped", "async-trait", "dashmap", "derivative", - "futures", - "futures-util", "once_cell", "rayon", "regex", @@ -3421,7 +3248,6 @@ dependencies = [ name = "rspack_plugin_swc_js_minimizer" version = "0.1.0" dependencies = [ - "async-recursion", "async-trait", "once_cell", "rayon", @@ -3441,7 +3267,6 @@ dependencies = [ name = "rspack_plugin_warn_sensitive_module" version = "0.1.0" dependencies = [ - "dashmap", "rspack_core", "rspack_error", ] @@ -3467,7 +3292,6 @@ dependencies = [ name = "rspack_plugin_web_worker_template" version = "0.1.0" dependencies = [ - "async-trait", "rspack_core", "rspack_plugin_runtime", ] @@ -3478,8 +3302,6 @@ version = "0.1.0" dependencies = [ "async-trait", "rspack_core", - "rspack_plugin_runtime", - "rspack_plugin_wasm", ] [[package]] @@ -3538,12 +3360,9 @@ dependencies = [ "rspack_error", "rspack_fs", "rspack_ids", - "rspack_loader_runner", - "rspack_loader_sass", "rspack_loader_swc", "rspack_plugin_asset", "rspack_plugin_css", - "rspack_plugin_dev_friendly_split_chunks", "rspack_plugin_devtool", "rspack_plugin_entry", "rspack_plugin_externals", @@ -3551,7 +3370,6 @@ dependencies = [ "rspack_plugin_html", "rspack_plugin_javascript", "rspack_plugin_json", - "rspack_plugin_library", "rspack_plugin_merge_duplicate_chunks", "rspack_plugin_remove_empty_chunks", "rspack_plugin_runtime", @@ -3610,15 +3428,15 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.21" +version = "0.38.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b426b0506e5d50a7d8dafcf2e81471400deb602392c7dd110815afb4eaf02a3" +checksum = "322394588aaf33c24007e8bb3238ee3e4c5c09c084ab32bc73890b99ff326bca" dependencies = [ "bitflags 2.4.1", "errno", "libc", "linux-raw-sys", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -3648,25 +3466,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "sass-embedded" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "043fea16ac00f7132b50dce6094873fee0d328bd43c0f552faeb33d989d97b77" -dependencies = [ - "atty", - "crossbeam-channel", - "dashmap", - "parking_lot 0.12.1", - "prost", - "regex", - "rustc-hash", - "serde", - "serde_json", - "url", - "urlencoding", -] - [[package]] name = "schemars" version = "0.8.15" @@ -3735,9 +3534,9 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.193" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" dependencies = [ "serde_derive", ] @@ -3754,13 +3553,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.193" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -3776,9 +3575,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.108" +version = "1.0.111" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" +checksum = "176e46fa42316f18edd598015a5166857fc835ec732f5215eac6b7bdbf0a84f4" dependencies = [ "indexmap 2.1.0", "itoa", @@ -3938,7 +3737,7 @@ dependencies = [ "pmutil", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -3988,7 +3787,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -3999,9 +3798,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "styled_components" -version = "0.90.0" +version = "0.91.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddb45c257489ad9439cd5c9ecc4b17b1b43dde147ec0c857393b10226948364b" +checksum = "70839c116ea418685475d63254fbbbfa84805a29be9643bd4c0ff853df933165" dependencies = [ "Inflector", "once_cell", @@ -4091,15 +3890,15 @@ dependencies = [ [[package]] name = "swc" -version = "0.269.75" +version = "0.270.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "603ad8da1ec4affc1564bc88173f8356f8686f84a3975121d662ee1a6d877e9d" +checksum = "df31dd9488814df8b8c2e0ed34d24c21a3622efb14f6babd29d9f7ff1e9ddf34" dependencies = [ "anyhow", - "base64 0.13.1", + "base64 0.21.5", "dashmap", "either", - "indexmap 1.9.3", + "indexmap 2.1.0", "jsonc-parser 0.21.1", "lru", "once_cell", @@ -4163,6 +3962,15 @@ dependencies = [ "serde", ] +[[package]] +name = "swc_change_package_import" +version = "0.1.0" +dependencies = [ + "serde", + "swc_core", + "testing", +] + [[package]] name = "swc_common" version = "0.33.12" @@ -4206,9 +4014,9 @@ dependencies = [ [[package]] name = "swc_compiler_base" -version = "0.3.83" +version = "0.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2aaeaafb2670ebaf64414e4bccccad495ff0b80f2b47763a7d96fec48bb8773" +checksum = "48f2ef1d6ccbeb79c4fdce7abfc12194e291bf202fa61ab02c245b9a2811fb67" dependencies = [ "anyhow", "base64 0.21.5", @@ -4228,11 +4036,11 @@ dependencies = [ [[package]] name = "swc_config" -version = "0.1.7" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ba1c7a40d38f9dd4e9a046975d3faf95af42937b34b2b963be4d8f01239584b" +checksum = "112884e66b60e614c0f416138b91b8b82b7fea6ed0ecc5e26bad4726c57a6c99" dependencies = [ - "indexmap 1.9.3", + "indexmap 2.1.0", "serde", "serde_json", "swc_config_macro", @@ -4247,14 +4055,14 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] name = "swc_core" -version = "0.86.84" +version = "0.87.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05d7801335fb8d1dcb48009f3e0fd0b7a472760a06931af5b03dca96c3ead3fe" +checksum = "f71409708fe30c531a1447cc7d339f53d76b0b7235b2b9e3cc070882a15a55b0" dependencies = [ "swc", "swc_atoms", @@ -4279,6 +4087,7 @@ dependencies = [ "swc_ecma_transforms_optimization", "swc_ecma_transforms_proposal", "swc_ecma_transforms_react", + "swc_ecma_transforms_testing", "swc_ecma_transforms_typescript", "swc_ecma_utils", "swc_ecma_visit", @@ -4287,9 +4096,9 @@ dependencies = [ [[package]] name = "swc_css_ast" -version = "0.140.13" +version = "0.140.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec1b459dc890410ea18225d2879786247f1dbc2ddb95eb92cae9dd83c6193ed5" +checksum = "85eb09e34d7a6e1869897b4aa884c739c5f5320aea00b35b589d2e4391e47868" dependencies = [ "is-macro", "string_enum", @@ -4299,9 +4108,9 @@ dependencies = [ [[package]] name = "swc_css_codegen" -version = "0.151.21" +version = "0.151.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e61d619e672f2dc4923593c19fd0545a47c8311008ff5fb60c55134e29e68df" +checksum = "5d292d3dbf611b6be21980919f8896852af40bbb0d430d6008f4283685137e64" dependencies = [ "auto_impl", "bitflags 2.4.1", @@ -4323,14 +4132,14 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] name = "swc_css_compat" -version = "0.27.22" +version = "0.27.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "969293b76f5385daca38a08a99ac915de93330717c16ae45163866b8955e0613" +checksum = "a544c80e5b481dab958e4bdd1286349b7583b1412e53993fbcf1aeb83d0e585e" dependencies = [ "bitflags 2.4.1", "once_cell", @@ -4345,9 +4154,9 @@ dependencies = [ [[package]] name = "swc_css_minifier" -version = "0.116.22" +version = "0.116.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2a8a5b334be14e66a4ccdf98de4cac7065f901390cf5b761a873673ad251898" +checksum = "e9807dea905a6c4696076ff642e507ecaf63e624ef20c55a303017d3e6f301e9" dependencies = [ "serde", "swc_atoms", @@ -4359,9 +4168,9 @@ dependencies = [ [[package]] name = "swc_css_modules" -version = "0.29.24" +version = "0.29.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "430f6bc9fab0dd0e03da05bb338d803664927ae5e5e4775710160f19f1f5566b" +checksum = "caceeba805e5123dbbe9f4210bb28644ea026bdd7a6f407046c7b3c941573332" dependencies = [ "rustc-hash", "serde", @@ -4375,9 +4184,9 @@ dependencies = [ [[package]] name = "swc_css_parser" -version = "0.150.20" +version = "0.150.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c16cff0015ce0c3a8eade2d379b336c1e7205377f40a34f5f38758469c78fd9" +checksum = "9fb8221a52f2f50cd23c6b70fa024f4ef21a3dd737a67965292fdac49f391036" dependencies = [ "lexical", "serde", @@ -4388,9 +4197,9 @@ dependencies = [ [[package]] name = "swc_css_prefixer" -version = "0.153.23" +version = "0.153.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c34762ca85e7136bfb83036467b91a296818471660da2955e5df0d1de14d3f4" +checksum = "74adc2822de64d5215ad253ce360dc39f99686dbb46840b6ae374aad69133cfa" dependencies = [ "once_cell", "preset_env_base", @@ -4405,9 +4214,9 @@ dependencies = [ [[package]] name = "swc_css_utils" -version = "0.137.13" +version = "0.137.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6b4b604827b202bcf644ced07ad897ae5cbb5fae62a8a3d154ebca73da06b0f" +checksum = "426952c65332d750820cc4cb2b8e21955d6315c57b30939e43def2c48f36c55f" dependencies = [ "once_cell", "serde", @@ -4420,9 +4229,9 @@ dependencies = [ [[package]] name = "swc_css_visit" -version = "0.139.13" +version = "0.139.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "761dc5b0b95b7c950083519dda1f82246566f6682b3b21a009b1e0e20a6d693c" +checksum = "0653b91d85ef5415bfd7b205d03d7a4772ec8e324c980873523294bc2e827717" dependencies = [ "serde", "swc_atoms", @@ -4433,9 +4242,9 @@ dependencies = [ [[package]] name = "swc_ecma_ast" -version = "0.110.15" +version = "0.110.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2aa3e4c43a071a747bf3e18a5423d47aab54048fdedab550d7f3c662127ba4d8" +checksum = "79401a45da704f4fb2552c5bf86ee2198e8636b121cb81f8036848a300edd53b" dependencies = [ "bitflags 2.4.1", "is-macro", @@ -4451,9 +4260,9 @@ dependencies = [ [[package]] name = "swc_ecma_codegen" -version = "0.146.45" +version = "0.146.54" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be75490c5a5cad616587cb8600ce387bb5925c8a9a3e44de674b67bf962fb439" +checksum = "99b61ca275e3663238b71c4b5da8e6fb745bde9989ef37d94984dfc81fc6d009" dependencies = [ "memchr", "num-bigint", @@ -4477,14 +4286,14 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] name = "swc_ecma_compat_bugfixes" -version = "0.1.53" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b57a4636b9159609557c0e3f23f393a76bcffc21ae0d4926ec9b7188d3cc9f4" +checksum = "0337067ede6103a274191a20c4de238ded32bb8b3d3e99561ca3e7811e089b21" dependencies = [ "swc_atoms", "swc_common", @@ -4499,9 +4308,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_common" -version = "0.1.36" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "904a87fbec2b00a6a9aae8797dcf84bc1400f560d5a55e37e2f6728d7bebf9c3" +checksum = "8b0a57bd134c03dd545263ee41824a8cb06af1553016dccf8ac1ad8cbbb940c3" dependencies = [ "swc_common", "swc_ecma_ast", @@ -4512,9 +4321,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_es2015" -version = "0.1.53" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "950a1234f6655b408d0efa6905f1e9beba5ff6835cca8a95c6d2a50714dbf50c" +checksum = "a6912d92bcfc313d7b05d1da0ae8d283bce24baf4e1fd09541acd52f32ab1e32" dependencies = [ "arrayvec", "indexmap 2.1.0", @@ -4538,9 +4347,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_es2016" -version = "0.1.57" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40606d660400c9e4e1db343930c0d80601e5dd6c23f90f59879fa5e54ea5dc31" +checksum = "52f4824f2bd45b02b70bc85824daa35c9c07477589f008f888748c115d4b0b97" dependencies = [ "swc_atoms", "swc_common", @@ -4555,9 +4364,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_es2017" -version = "0.1.58" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d431aa66fe3d219e141f3103fdc7a3b7503a74cde1091cb42bb402934be6962e" +checksum = "c85bcb454c2d69e38777fd739864938fbc18ed45b6ee4dd314b9fc0a463a63c1" dependencies = [ "serde", "swc_atoms", @@ -4573,9 +4382,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_es2018" -version = "0.1.58" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d22d2edbb19c8b27c0697e049da3102fff58b9f70355f68bbefadd988d7e648b" +checksum = "3d47d63860994814c49e8ad5996d182d1d7804e96d6f7bdab0bf1282716d9884" dependencies = [ "serde", "swc_atoms", @@ -4592,9 +4401,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_es2019" -version = "0.1.58" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "879726051286646d4f01851827959c5de8c36fac4dfd3b02d34fdd1911bb0485" +checksum = "f20b2d70b26e48926bba3b7629b6bc10de724a8f076fdf4eb9267fe12a1db17b" dependencies = [ "swc_atoms", "swc_common", @@ -4608,9 +4417,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_es2020" -version = "0.1.56" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4000344bcb4cabe6385b33cf4fa6404e7c4b754d034b172db8c55549d10829e" +checksum = "973a0bca6c9e85869d62b38937b80e13ee5e105df4eb18576177c4ebb41e5bb9" dependencies = [ "serde", "swc_atoms", @@ -4626,9 +4435,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_es2021" -version = "0.1.56" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "122dd55b3db93601353e0310f1d5018e22d2a3b62bebded5e2d368bcde21178b" +checksum = "9a33089b3b121acadc052ca636905c1dd465db3cc94fa456c26eacc65d5074db" dependencies = [ "swc_atoms", "swc_common", @@ -4642,9 +4451,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_es2022" -version = "0.1.57" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "569f093b567046d0b51eb7c84b6c3ad4e4572a61d6b3b33d02e286eccffbd8de" +checksum = "ebe2a334c1ed213b0a58adb09518c63c63229afad705e5ab027e2fd0f3ff20bd" dependencies = [ "swc_atoms", "swc_common", @@ -4661,9 +4470,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_es3" -version = "0.1.57" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4530662a138b8773fd0234a083eb047eb3760d998efd15d6f46ad1102f4980ac" +checksum = "ce5624a8b906965af30484a0b8e2ed9b0d68675a1b8bdba6a242882f38e3270e" dependencies = [ "swc_common", "swc_ecma_ast", @@ -4676,9 +4485,9 @@ dependencies = [ [[package]] name = "swc_ecma_ext_transforms" -version = "0.110.40" +version = "0.111.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4947357e009d54161e8dbfe77c6360c10c28b8406ece3ba65071eaa33af5f7e6" +checksum = "4e728d14119048a95e023c3c5c0ad5ddddb1f405bfef3bd55f81dc5fc3c9e95a" dependencies = [ "phf", "swc_atoms", @@ -4690,9 +4499,9 @@ dependencies = [ [[package]] name = "swc_ecma_lints" -version = "0.89.51" +version = "0.90.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b04cba6fbd1f8982fdcf50143efd22a5e49a0f608d29c033c0232f616f3d9108" +checksum = "5afe579c82fe80a24e8c815fa19e7f1126c8114db0985f211c985d5b4db4137e" dependencies = [ "auto_impl", "dashmap", @@ -4731,9 +4540,9 @@ dependencies = [ [[package]] name = "swc_ecma_minifier" -version = "0.189.77" +version = "0.190.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebb60ce1eaffdd0a146930b1fdae54ebc4d739b9f6ec34dc6b678a305b78458a" +checksum = "35dae1f624247350378a02bbbbe408844e6ebfe8b8cd4558d9544f55b5a47b2d" dependencies = [ "arrayvec", "indexmap 2.1.0", @@ -4766,9 +4575,9 @@ dependencies = [ [[package]] name = "swc_ecma_parser" -version = "0.141.33" +version = "0.141.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d643ce57be7c4808cd7a924201aa256188aa2ef9604248cf180c4c3e867b3fd6" +checksum = "c4d17401dd95048a6a62b777d533c0999dabdd531ef9d667e22f8ae2a2a0d294" dependencies = [ "either", "new_debug_unreachable", @@ -4788,9 +4597,9 @@ dependencies = [ [[package]] name = "swc_ecma_preset_env" -version = "0.203.65" +version = "0.204.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "594708068d26b364b8aa0af133648f51984d7ad38a8269846dcbbc97c827be06" +checksum = "25c04f9800e67c97938a60f3c90f9455ba1984abe169ba70b1776428dcc6ee25" dependencies = [ "anyhow", "dashmap", @@ -4813,9 +4622,9 @@ dependencies = [ [[package]] name = "swc_ecma_quote_macros" -version = "0.52.33" +version = "0.52.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb353504ba4a2b157bb630aeefc49ed73ef20e2bc1bb764ed4f9a25bd9d9971a" +checksum = "d2bd72fda3eb232e08ac6ce9766edb59791dab5f588377c151a1da6c1862b734" dependencies = [ "anyhow", "proc-macro2", @@ -4825,14 +4634,27 @@ dependencies = [ "swc_ecma_ast", "swc_ecma_parser", "swc_macros_common", - "syn 2.0.39", + "syn 2.0.48", +] + +[[package]] +name = "swc_ecma_testing" +version = "0.22.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09b02a3eafe6cecb8a63618c21edc31dda5baefa829c3e0ffb386da73a5f94d8" +dependencies = [ + "anyhow", + "hex", + "sha2", + "testing", + "tracing", ] [[package]] name = "swc_ecma_transforms" -version = "0.226.65" +version = "0.227.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "878fa83417033ad2de7a48efa4c064e84d385afc4e36b05d0140670a827c5885" +checksum = "d91e52749e37685afa9bcb3ad58c945e31b1bf51259c8438c4cc6787366ae3cd" dependencies = [ "swc_atoms", "swc_common", @@ -4850,9 +4672,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_base" -version = "0.134.58" +version = "0.135.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "335963eada3ec4a0385ff259274c9d59ef5554541273715e64e4d69442a4ff77" +checksum = "6d4ab26ec124b03e47f54d4daade8e9a9dcd66d3a4ca3cd47045f138d267a60e" dependencies = [ "better_scoped_tls", "bitflags 2.4.1", @@ -4874,9 +4696,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_classes" -version = "0.123.59" +version = "0.124.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10f69a2b4203e19f28dc65bd6114f6c4bebda18aa2b7a44d04d22996264a5327" +checksum = "9fe4376c024fa04394cafb8faecafb4623722b92dbbe46532258cc0a6b569d9c" dependencies = [ "swc_atoms", "swc_common", @@ -4888,9 +4710,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_compat" -version = "0.160.58" +version = "0.161.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ce94656bcfe5b7aef6219cdc1ffa41f072b2f521f7d3bc79f8d615a747e3762" +checksum = "f46cfe232648c0994922d136d686c0a598c73a30334d92b14ba5a61e768bb4e7" dependencies = [ "arrayvec", "indexmap 2.1.0", @@ -4931,14 +4753,14 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] name = "swc_ecma_transforms_module" -version = "0.177.70" +version = "0.178.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d87f3fa5b146744f9ef335147eea6a0e1ba7ff9ac5ff1ba253e8e84362e481a4" +checksum = "48e51136811754dcbd7400cdd62da7117deabd029c8049a6740cff75934e3f40" dependencies = [ "Inflector", "anyhow", @@ -4963,9 +4785,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_optimization" -version = "0.195.74" +version = "0.196.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e33d20e20fcfe375ca464097423721c5012b0a8d3d1064839120db233d13088" +checksum = "95b7acea7f3306e5b9c3b19abc02f85885309f154901c951c63c3bcef4b0ff82" dependencies = [ "dashmap", "indexmap 2.1.0", @@ -4988,9 +4810,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_proposal" -version = "0.168.71" +version = "0.169.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab7cbad368d4d4ca0d17ed3a0b151d555d70856e8b794563a594f1a430e3517f" +checksum = "ed89d6ff74f60de490fb56e1cc505b057905e36c13d405d7d61dd5c9f6ee8fc9" dependencies = [ "either", "rustc-hash", @@ -5008,9 +4830,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_react" -version = "0.180.63" +version = "0.181.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5cadeb3d6c9c50385df98297177ff62d93e99653a5cf4a7848db34a619df61d" +checksum = "e31a2f879fd21d18080b6c42e633e0ae8c6f3d54b83c1de876767d82b458c999" dependencies = [ "base64 0.21.5", "dashmap", @@ -5030,11 +4852,37 @@ dependencies = [ "swc_ecma_visit", ] +[[package]] +name = "swc_ecma_transforms_testing" +version = "0.138.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbff87379f76ecb3d159f6c73e140c7b95d3ee37facfdf4e539e648fe616c95c" +dependencies = [ + "ansi_term", + "anyhow", + "base64 0.21.5", + "hex", + "serde", + "serde_json", + "sha2", + "sourcemap", + "swc_common", + "swc_ecma_ast", + "swc_ecma_codegen", + "swc_ecma_parser", + "swc_ecma_testing", + "swc_ecma_transforms_base", + "swc_ecma_utils", + "swc_ecma_visit", + "tempfile", + "testing", +] + [[package]] name = "swc_ecma_transforms_typescript" -version = "0.185.63" +version = "0.186.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "556067f2ea488c05198c2ad3514664e5b292ad568d50b2c5dd0dcd7a53c4abb8" +checksum = "6460d1e6a9ffade4b89b15fa38944fa0f7da877d7e79aa69e9f9c6a83a23b031" dependencies = [ "ryu-js", "serde", @@ -5049,9 +4897,9 @@ dependencies = [ [[package]] name = "swc_ecma_usage_analyzer" -version = "0.20.40" +version = "0.21.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d26fcd5d3ce1571f695187362a5d92adbd09bb071c122660178ac0205c154ca" +checksum = "2bf6ae5dd022ac6f39034896dd94eaeb590bf1fc6ab6e4f302fc9cdd8569e9b7" dependencies = [ "indexmap 2.1.0", "rustc-hash", @@ -5066,9 +4914,9 @@ dependencies = [ [[package]] name = "swc_ecma_utils" -version = "0.124.39" +version = "0.125.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a7a3f362e035688f7c48eeab4f4a8a477bfa64cf6541de1e3f40de882974feb" +checksum = "7cead1083e46b0f072a82938f16d366014468f7510350957765bb4d013496890" dependencies = [ "indexmap 2.1.0", "num_cpus", @@ -5085,9 +4933,9 @@ dependencies = [ [[package]] name = "swc_ecma_visit" -version = "0.96.15" +version = "0.96.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a823435d7b3d909391499c1d944be52fb9c6c59d6b5020367a511dfa1b1a3ecd" +checksum = "a1d0100c383fb08b6f34911ab6f925950416a5d14404c1cd520d59fb8dfbb3bf" dependencies = [ "num-bigint", "swc_atoms", @@ -5099,9 +4947,9 @@ dependencies = [ [[package]] name = "swc_emotion" -version = "0.58.0" +version = "0.67.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d123bc6ff6aff8724f43542964ee726801fc205137bbf0de7f822a2f8b15f204" +checksum = "30e429f66f612c42bef6b202419a79ccbe7317a09da00107a56c24dbc3dbaf0d" dependencies = [ "base64 0.13.1", "byteorder", @@ -5136,14 +4984,14 @@ checksum = "695a1d8b461033d32429b5befbf0ad4d7a2c4d6ba9cd5ba4e0645c615839e8e4" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] name = "swc_error_reporters" -version = "0.17.9" +version = "0.17.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29add35412af288be50e1012bbb825a66871bb2b4d960d1c456917ec3ccea32" +checksum = "9e00fa7c3009268d8ab2ca69d22ac3c3fe777297215fa128bc0ef42dcdf230ab" dependencies = [ "anyhow", "miette 4.7.1", @@ -5166,9 +5014,9 @@ dependencies = [ [[package]] name = "swc_html" -version = "0.134.29" +version = "0.135.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e63e6d015cbf1ca3d389e012fc5760eea3c24cc447d605cd7e8c4853d7637304" +checksum = "c17e177a34d7260d8bd440fe3458eb656b68b90e14de06b50b8d2a685fd8f1f1" dependencies = [ "swc_html_ast", "swc_html_codegen", @@ -5190,9 +5038,9 @@ dependencies = [ [[package]] name = "swc_html_codegen" -version = "0.42.16" +version = "0.42.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "308557ab26e22fe1eaa252af6924887b06dbd93111332995ffc0a6d53746473b" +checksum = "27c3f2bf9a87df642f7f3df10e4d471f216d955deb28cf053f4f637db9c7d535" dependencies = [ "auto_impl", "bitflags 2.4.1", @@ -5213,14 +5061,14 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] name = "swc_html_minifier" -version = "0.131.29" +version = "0.132.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6bb97ae0b52f120318468f86e199b6d51dd532441d50e61077a25343f8706b7" +checksum = "9770f760f1c6f43abd65d25828b5881ff6ff3dc72816a3bfdeb524078a33fcdd" dependencies = [ "once_cell", "serde", @@ -5247,9 +5095,9 @@ dependencies = [ [[package]] name = "swc_html_parser" -version = "0.39.16" +version = "0.39.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb27edab80474143ca6a0bfde8a13488e95fedc486cfbcee79080d59fb095dbc" +checksum = "3366eb3d3b955f7bfeb3ddbc19184dd87caaf687c85daac4bde5acf59cfa0413" dependencies = [ "swc_atoms", "swc_common", @@ -5300,7 +5148,7 @@ checksum = "50176cfc1cbc8bb22f41c6fe9d1ec53fbe057001219b5954961b8ad0f336fce9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -5312,9 +5160,9 @@ dependencies = [ [[package]] name = "swc_node_comments" -version = "0.20.9" +version = "0.20.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282ef548f602694c4eaa36a1d704282fd9713b9725b58bce7fb41630feefc4f7" +checksum = "86a67c8fb9735b17b2cdf7b5dd539dc1625f73d05c794566b98e65be39cee5b1" dependencies = [ "dashmap", "swc_atoms", @@ -5334,6 +5182,7 @@ dependencies = [ name = "swc_plugin_import" version = "0.1.5" dependencies = [ + "Inflector", "handlebars", "rustc-hash", "serde", @@ -5366,7 +5215,7 @@ checksum = "ff9719b6085dd2824fd61938a881937be14b08f95e2d27c64c825a9f65e052ba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -5390,7 +5239,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -5406,9 +5255,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.39" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -5421,6 +5270,19 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" +[[package]] +name = "tempfile" +version = "3.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01ce4141aa927a6d1bd34a041795abd0db1cccba5d5f24b009f694bdf3a1f3fa" +dependencies = [ + "cfg-if", + "fastrand", + "redox_syscall 0.4.1", + "rustix", + "windows-sys 0.52.0", +] + [[package]] name = "termcolor" version = "1.3.0" @@ -5440,21 +5302,41 @@ dependencies = [ "winapi", ] +[[package]] +name = "testing" +version = "0.35.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "293dc0c2fc5e51a67cde205832476cf205758168f9966312ea05a97c8fb2230c" +dependencies = [ + "ansi_term", + "cargo_metadata", + "difference", + "once_cell", + "pretty_assertions", + "regex", + "serde", + "serde_json", + "swc_common", + "swc_error_reporters", + "testing_macros", + "tracing", + "tracing-subscriber", +] + [[package]] name = "testing_macros" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1c15b796025051a07f1ac695ee0cac0883f05a0d510c9d171ef8d31a992e6a5" +checksum = "f9d3864d4184569c1428645a51a304b3b6e8d3094cd61fb3cce8dfdd9f6d0f72" dependencies = [ "anyhow", "glob", "once_cell", - "pmutil", "proc-macro2", "quote", "regex", "relative-path", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -5479,22 +5361,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.51" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f11c217e1416d6f036b870f14e0413d480dbf28edbee1f877abaf0206af43bb7" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.51" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01742297787513b79cf8e29d1056ede1313e2420b7b3b15d0a768b4921f549df" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -5573,7 +5455,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -5595,7 +5477,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] [[package]] @@ -5621,9 +5503,9 @@ dependencies = [ [[package]] name = "tracing-log" -version = "0.1.4" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f751112709b4e791d8ce53e32c4ed2d353565a795ce84da2285393f41557bdf2" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" dependencies = [ "log", "once_cell", @@ -5632,9 +5514,9 @@ dependencies = [ [[package]] name = "tracing-subscriber" -version = "0.3.17" +version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" dependencies = [ "matchers", "nu-ansi-term", @@ -5729,7 +5611,6 @@ dependencies = [ "form_urlencoded", "idna", "percent-encoding", - "serde", ] [[package]] @@ -5828,7 +5709,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", "wasm-bindgen-shared", ] @@ -5850,7 +5731,7 @@ checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -5939,6 +5820,15 @@ dependencies = [ "windows-targets 0.48.5", ] +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.0", +] + [[package]] name = "windows-targets" version = "0.42.2" @@ -5969,6 +5859,21 @@ dependencies = [ "windows_x86_64_msvc 0.48.5", ] +[[package]] +name = "windows-targets" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +dependencies = [ + "windows_aarch64_gnullvm 0.52.0", + "windows_aarch64_msvc 0.52.0", + "windows_i686_gnu 0.52.0", + "windows_i686_msvc 0.52.0", + "windows_x86_64_gnu 0.52.0", + "windows_x86_64_gnullvm 0.52.0", + "windows_x86_64_msvc 0.52.0", +] + [[package]] name = "windows_aarch64_gnullvm" version = "0.42.2" @@ -5981,6 +5886,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" + [[package]] name = "windows_aarch64_msvc" version = "0.42.2" @@ -5993,6 +5904,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" + [[package]] name = "windows_i686_gnu" version = "0.42.2" @@ -6005,6 +5922,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +[[package]] +name = "windows_i686_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" + [[package]] name = "windows_i686_msvc" version = "0.42.2" @@ -6017,6 +5940,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +[[package]] +name = "windows_i686_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" + [[package]] name = "windows_x86_64_gnu" version = "0.42.2" @@ -6029,6 +5958,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" + [[package]] name = "windows_x86_64_gnullvm" version = "0.42.2" @@ -6041,6 +5976,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" + [[package]] name = "windows_x86_64_msvc" version = "0.42.2" @@ -6053,6 +5994,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" + [[package]] name = "wyz" version = "0.5.1" @@ -6115,5 +6062,5 @@ checksum = "c2f140bda219a26ccc0cdb03dba58af72590c53b22642577d88a927bc5c87d6b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.48", ] diff --git a/Cargo.toml b/Cargo.toml index 0e4c1a5..f851b8a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ members = [ "crates/swc_remove_export", "crates/swc_optimize_barrel", "crates/plugin_specilize_module_name", - "crates/swc_plugin_change_package_import", + "crates/swc_change_package_import", ] resolver = "2" @@ -33,7 +33,7 @@ futures = { version = "0.3.28" } futures-util = { version = "0.3.28" } glob = { version = "0.3.1" } hashlink = { version = "0.8.3" } -indexmap = { version = "1.9.3" } +indexmap = { version = "=1.9.3", features = ["serde-1"] } insta = { version = "1.30.0" } itertools = { version = "0.10.5" } json = { version = "0.12.4" } @@ -45,20 +45,23 @@ paste = { version = "1.0" } path-clean = { version = "1.0.1" } pathdiff = { version = "0.2.1" } preset_env_base = { version = "0.4.6" } +proc-macro2 = { version = "1.0.76" } +quote = { version = "1.0.35" } rayon = { version = "1.7.0" } regex = { version = "1.9.1" } rkyv = { version = "0.7.42" } rspack_sources = { version = "0.2.7" } rustc-hash = { version = "1.1.0" } schemars = { version = "0.8.12" } -serde = { version = "1.0.171" } +serde = { version = "1.0.194" } serde_json = { version = "1.0.100" } similar = { version = "2.2.1" } sugar_path = { version = "0.0.12" } +syn = { version = "2.0.48" } testing_macros = { version = "0.2.11" } tokio = { version = "1.29.1" } -tracing = { version = "0.1.37" } -tracing-subscriber = { version = "0.3.17" } +tracing = { version = "0.1.40" } +tracing-subscriber = { version = "0.3.18" } url = { version = "2.4.0" } urlencoding = { version = "2.1.2" } ustr = { version = "0.9.0" } @@ -69,21 +72,21 @@ napi = { version = "=2.13.3" } napi-build = { version = "=2.0.1" } napi-derive = { version = "=2.13.0" } napi-sys = { version = "=2.2.3" } -styled_components = { version = "0.90.0" } -swc_config = { version = "=0.1.7" } -swc_core = { version = "0.86.82", default-features = false } -swc_css = { version = "0.157.6" } -swc_ecma_minifier = { version = "0.189.73", default-features = false } -swc_emotion = { version = "=0.58.0" } -swc_error_reporters = { version = "=0.17.9" } -swc_html = { version = "=0.134.29" } -swc_html_minifier = { version = "=0.131.29" } -swc_node_comments = { version = "=0.20.9" } +styled_components = { version = "0.91.0" } +swc_config = { version = "=0.1.9" } +swc_core = { version = "=0.87.21", default-features = false } +swc_css = { version = "=0.157.29" } +swc_ecma_minifier = { version = "=0.190.17", default-features = false } +swc_emotion = { version = "=0.67.0" } +swc_error_reporters = { version = "=0.17.12" } +swc_html = { version = "=0.135.20" } +swc_html_minifier = { version = "=0.132.20" } +swc_node_comments = { version = "=0.20.12" } tikv-jemallocator = { version = "=0.5.4", features = ["disable_initial_exec_tls"] } -testing = { version = "0.35.13" } +testing = { version = "=0.35.14" } [profile.dev] -codegen-units = 16 # debug build will cause runtime panic if codegen-unints is default +codegen-units = 16 # debug build will cause runtime panic if codegen-unints is default debug = 2 incremental = true panic = "abort" diff --git a/crates/binding_options/Cargo.toml b/crates/binding_options/Cargo.toml index 3c14e93..09e6e8c 100644 --- a/crates/binding_options/Cargo.toml +++ b/crates/binding_options/Cargo.toml @@ -4,59 +4,61 @@ version = "0.1.0" edition = "2021" [dependencies] -rspack_binding_options = { path = "../.rspack_crates/rspack_binding_options" } -rspack_core = { path = "../.rspack_crates/rspack_core" } -rspack_error = { path = "../.rspack_crates/rspack_error" } -rspack_ids = { path = "../.rspack_crates/rspack_ids" } -rspack_loader_runner = { path = "../.rspack_crates/rspack_loader_runner" } -rspack_loader_sass = { path = "../.rspack_crates/rspack_loader_sass" } -rspack_loader_swc = { path = "../.rspack_crates/rspack_loader_swc" } -rspack_plugin_asset = { path = "../.rspack_crates/rspack_plugin_asset" } -rspack_plugin_banner = { path = "../.rspack_crates/rspack_plugin_banner" } -rspack_plugin_copy = { path = "../.rspack_crates/rspack_plugin_copy" } -rspack_plugin_css = { path = "../.rspack_crates/rspack_plugin_css" } -rspack_plugin_dev_friendly_split_chunks = { path = "../.rspack_crates/rspack_plugin_dev_friendly_split_chunks" } -rspack_plugin_devtool = { path = "../.rspack_crates/rspack_plugin_devtool" } -rspack_plugin_ensure_chunk_conditions = { path = "../.rspack_crates/rspack_plugin_ensure_chunk_conditions" } -rspack_plugin_entry = { path = "../.rspack_crates/rspack_plugin_entry" } -rspack_plugin_externals = { path = "../.rspack_crates/rspack_plugin_externals" } -rspack_plugin_hmr = { path = "../.rspack_crates/rspack_plugin_hmr" } -rspack_plugin_html = { path = "../.rspack_crates/rspack_plugin_html" } -rspack_plugin_javascript = { path = "../.rspack_crates/rspack_plugin_javascript" } -rspack_plugin_json = { path = "../.rspack_crates/rspack_plugin_json" } -rspack_plugin_library = { path = "../.rspack_crates/rspack_plugin_library" } -rspack_plugin_limit_chunk_count = { path = "../.rspack_crates/rspack_plugin_limit_chunk_count" } -rspack_plugin_progress = { path = "../.rspack_crates/rspack_plugin_progress" } -rspack_plugin_real_content_hash = { path = "../.rspack_crates/rspack_plugin_real_content_hash" } -rspack_plugin_remove_empty_chunks = { path = "../.rspack_crates/rspack_plugin_remove_empty_chunks" } -rspack_plugin_runtime = { path = "../.rspack_crates/rspack_plugin_runtime" } -rspack_plugin_schemes = { path = "../.rspack_crates/rspack_plugin_schemes" } -rspack_plugin_split_chunks = { path = "../.rspack_crates/rspack_plugin_split_chunks" } -rspack_plugin_split_chunks_new = { path = "../.rspack_crates/rspack_plugin_split_chunks_new" } -rspack_plugin_swc_css_minimizer = { path = "../.rspack_crates/rspack_plugin_swc_css_minimizer" } -rspack_plugin_swc_js_minimizer = { path = "../.rspack_crates/rspack_plugin_swc_js_minimizer" } -rspack_plugin_warn_sensitive_module = { path = "../.rspack_crates/rspack_plugin_warn_sensitive_module" } -rspack_plugin_wasm = { path = "../.rspack_crates/rspack_plugin_wasm" } -rspack_plugin_web_worker_template = { path = "../.rspack_crates/rspack_plugin_web_worker_template" } -rspack_plugin_worker = { path = "../.rspack_crates/rspack_plugin_worker" } -rspack_loader_react_refresh = { path = "../.rspack_crates/rspack_loader_react_refresh" } -rspack_regex = { path = "../.rspack_crates/rspack_regex" } -rspack_hash = { path = "../.rspack_crates/rspack_hash" } -rspack_swc_visitors = { path = "../.rspack_crates/rspack_swc_visitors" } +async-trait = { workspace = true } +better_scoped_tls = { workspace = true } +derivative = { workspace = true } +glob = { workspace = true } +napi = { workspace = true, features = ["async", "tokio_rt", "serde-json", "anyhow"] } +napi-derive = { workspace = true } +rspack_binding_options = { path = "../.rspack_crates/rspack_binding_options" } +rspack_hash = { path = "../.rspack_crates/rspack_hash" } +rspack_binding_macros = { path = "../.rspack_crates/rspack_binding_macros" } +rspack_binding_values = { path = "../.rspack_crates/rspack_binding_values" } +rspack_core = { path = "../.rspack_crates/rspack_core" } +rspack_error = { path = "../.rspack_crates/rspack_error" } +rspack_identifier = { path = "../.rspack_crates/rspack_identifier" } +rspack_ids = { path = "../.rspack_crates/rspack_ids" } +rspack_loader_react_refresh = { path = "../.rspack_crates/rspack_loader_react_refresh" } +rspack_loader_runner = { path = "../.rspack_crates/rspack_loader_runner" } +rspack_loader_swc = { path = "../.rspack_crates/rspack_loader_swc" } +rspack_napi_shared = { path = "../.rspack_crates/rspack_napi_shared" } +rspack_plugin_asset = { path = "../.rspack_crates/rspack_plugin_asset" } +rspack_plugin_banner = { path = "../.rspack_crates/rspack_plugin_banner" } +rspack_plugin_copy = { path = "../.rspack_crates/rspack_plugin_copy" } +rspack_plugin_css = { path = "../.rspack_crates/rspack_plugin_css" } +rspack_plugin_devtool = { path = "../.rspack_crates/rspack_plugin_devtool" } +rspack_plugin_ensure_chunk_conditions = { path = "../.rspack_crates/rspack_plugin_ensure_chunk_conditions" } +rspack_plugin_entry = { path = "../.rspack_crates/rspack_plugin_entry" } +rspack_plugin_externals = { path = "../.rspack_crates/rspack_plugin_externals" } +rspack_plugin_hmr = { path = "../.rspack_crates/rspack_plugin_hmr" } +rspack_plugin_html = { path = "../.rspack_crates/rspack_plugin_html" } +rspack_plugin_javascript = { path = "../.rspack_crates/rspack_plugin_javascript" } +rspack_plugin_json = { path = "../.rspack_crates/rspack_plugin_json" } +rspack_plugin_library = { path = "../.rspack_crates/rspack_plugin_library" } +rspack_plugin_limit_chunk_count = { path = "../.rspack_crates/rspack_plugin_limit_chunk_count" } +rspack_plugin_merge_duplicate_chunks = { path = "../.rspack_crates/rspack_plugin_merge_duplicate_chunks" } +rspack_plugin_mf = { path = "../.rspack_crates/rspack_plugin_mf" } +rspack_plugin_progress = { path = "../.rspack_crates/rspack_plugin_progress" } +rspack_plugin_real_content_hash = { path = "../.rspack_crates/rspack_plugin_real_content_hash" } +rspack_plugin_remove_empty_chunks = { path = "../.rspack_crates/rspack_plugin_remove_empty_chunks" } +rspack_plugin_runtime = { path = "../.rspack_crates/rspack_plugin_runtime" } +rspack_plugin_schemes = { path = "../.rspack_crates/rspack_plugin_schemes" } +rspack_plugin_split_chunks_new = { path = "../.rspack_crates/rspack_plugin_split_chunks_new" } +rspack_plugin_swc_css_minimizer = { path = "../.rspack_crates/rspack_plugin_swc_css_minimizer" } +rspack_plugin_swc_js_minimizer = { path = "../.rspack_crates/rspack_plugin_swc_js_minimizer" } +rspack_plugin_warn_sensitive_module = { path = "../.rspack_crates/rspack_plugin_warn_sensitive_module" } +rspack_plugin_wasm = { path = "../.rspack_crates/rspack_plugin_wasm" } +rspack_plugin_web_worker_template = { path = "../.rspack_crates/rspack_plugin_web_worker_template" } +rspack_plugin_worker = { path = "../.rspack_crates/rspack_plugin_worker" } +rspack_regex = { path = "../.rspack_crates/rspack_regex" } +rspack_swc_visitors = { path = "../.rspack_crates/rspack_swc_visitors" } loader_compilation = { path = "../loader_compilation" } loader_barrel = { path = "../loader_barrel" } plugin_manifest = { path = "../plugin_manifest" } - -futures-util = { workspace = true } -anyhow = { workspace = true, features = ["backtrace"] } -async-trait = { workspace = true } -better_scoped_tls = { workspace = true } -derivative = { workspace = true } -glob = { workspace = true } -napi = { workspace = true, features = ["async", "tokio_rt", "serde-json", "anyhow"] } -napi-derive = { workspace = true } -rustc-hash = { workspace = true } -serde = { workspace = true, features = ["derive"] } -serde_json = { workspace = true } -tokio = { workspace = true, features = ["rt", "rt-multi-thread", "macros", "test-util", "parking_lot"] } -tracing = { workspace = true } +rustc-hash = { workspace = true } +serde = { workspace = true, features = ["derive"] } +serde_json = { workspace = true } +swc_config = { workspace = true } +swc_core = { workspace = true, default-features = false, features = ["ecma_transforms_react"] } +tokio = { workspace = true, features = ["rt", "rt-multi-thread", "macros", "test-util", "parking_lot"] } +tracing = { workspace = true } diff --git a/crates/binding_options/src/options/mod.rs b/crates/binding_options/src/options/mod.rs index 2e99c38..db61661 100644 --- a/crates/binding_options/src/options/mod.rs +++ b/crates/binding_options/src/options/mod.rs @@ -1,11 +1,11 @@ use napi_derive::napi; use rspack_binding_options::{ - RawBuiltins, RawCacheOptions, RawDevServer, RawExperiments, RawMode, RawModuleOptions, - RawNodeOption, RawOutputOptions, RawResolveOptions, RawSnapshotOptions, RawStatsOptions, + RawBuiltins, RawCacheOptions, RawExperiments, RawMode, RawModuleOptions, RawNodeOption, + RawOutputOptions, RawResolveOptions, RawSnapshotOptions, RawStatsOptions, }; use rspack_core::{ - CompilerOptions, Context, DevServerOptions, Devtool, Experiments, IncrementalRebuild, - IncrementalRebuildMakeState, ModuleOptions, Optimization, OutputOptions, Target, TreeShaking, + CompilerOptions, Context, Devtool, Experiments, IncrementalRebuild, IncrementalRebuildMakeState, + ModuleOptions, Optimization, OutputOptions, Target, TreeShaking, }; use serde::Deserialize; @@ -34,7 +34,6 @@ pub struct RSPackRawOptions { pub devtool: String, pub optimization: RspackRawOptimizationOptions, pub stats: RawStatsOptions, - pub dev_server: RawDevServer, pub snapshot: RawSnapshotOptions, pub cache: RawCacheOptions, pub experiments: RawExperiments, @@ -61,12 +60,8 @@ impl RSPackRawOptions { let cache = self.cache.into(); let experiments = Experiments { incremental_rebuild: IncrementalRebuild { - make: self - .experiments - .incremental_rebuild - .make - .then(IncrementalRebuildMakeState::default), - emit_asset: self.experiments.incremental_rebuild.emit_asset, + make: Some(IncrementalRebuildMakeState::default()), + emit_asset: true, }, new_split_chunks: self.experiments.new_split_chunks, top_level_await: self.experiments.top_level_await, @@ -87,7 +82,6 @@ impl RSPackRawOptions { let stats = self.stats.into(); let snapshot = self.snapshot.into(); let node = self.node.map(|n| n.into()); - let dev_server: DevServerOptions = self.dev_server.into(); // Add custom plugins. plugins.push(Box::new(plugin_manifest::ManifestPlugin::new())); @@ -111,7 +105,7 @@ impl RSPackRawOptions { snapshot, optimization, node, - dev_server, + dev_server: Default::default(), profile: self.profile, bail: self.bail, builtins, diff --git a/crates/binding_options/src/options/raw_module.rs b/crates/binding_options/src/options/raw_module.rs index eb76d98..493599c 100644 --- a/crates/binding_options/src/options/raw_module.rs +++ b/crates/binding_options/src/options/raw_module.rs @@ -1,21 +1,12 @@ use std::sync::Arc; -use loader_compilation::COMPILATION_LOADER_IDENTIFIER; use loader_barrel::BARREL_LOADER_IDENTIFIER; +use loader_compilation::COMPILATION_LOADER_IDENTIFIER; use rspack_core::BoxLoader; use rspack_loader_react_refresh::REACT_REFRESH_LOADER_IDENTIFIER; -use rspack_loader_sass::SASS_LOADER_IDENTIFIER; use rspack_loader_swc::SWC_LOADER_IDENTIFIER; pub fn get_builtin_loader(builtin: &str, options: Option<&str>) -> BoxLoader { - if builtin.starts_with(SASS_LOADER_IDENTIFIER) { - return Arc::new(rspack_loader_sass::SassLoader::new( - serde_json::from_str(options.unwrap_or("{}")).unwrap_or_else(|e| { - panic!("Could not parse builtin:sass-loader options: {options:?}, error: {e:?}") - }), - )); - } - if builtin.starts_with(SWC_LOADER_IDENTIFIER) { return Arc::new( rspack_loader_swc::SwcLoader::new( @@ -26,7 +17,6 @@ pub fn get_builtin_loader(builtin: &str, options: Option<&str>) -> BoxLoader { .with_identifier(builtin.into()), ); } - if builtin.starts_with(REACT_REFRESH_LOADER_IDENTIFIER) { return Arc::new( rspack_loader_react_refresh::ReactRefreshLoader::default().with_identifier(builtin.into()), diff --git a/crates/loader_barrel/src/lib.rs b/crates/loader_barrel/src/lib.rs index 792dfb8..3e667b6 100644 --- a/crates/loader_barrel/src/lib.rs +++ b/crates/loader_barrel/src/lib.rs @@ -12,13 +12,13 @@ use rspack_core::{ DependencyCategory, LoaderRunnerContext, ResolveOptionsWithDependencyType, ResolveResult, Resolver, }; -use serde::Deserialize; -use rspack_error::{internal_error, AnyhowError, Result}; +use rspack_error::{error, AnyhowError, Result}; use rspack_loader_runner::{Content, Identifiable, Identifier, Loader, LoaderContext}; use rspack_plugin_javascript::{ ast::{self, SourceMapConfig}, TransformOutput, }; +use serde::Deserialize; use swc_compiler::{IntoJsAst, SwcCompiler}; use swc_core::{ base::config::{Options, OutputCharset}, @@ -86,7 +86,7 @@ async fn get_barrel_map( let content = if source.is_none() { let result = tokio::fs::read(file.clone()) .await - .map_err(|e| internal_error!(e.to_string()))?; + .map_err(|e| error!(e.to_string()))?; Content::from(result).try_into_string()? } else { source.unwrap() @@ -186,11 +186,17 @@ async fn get_barrel_map( let real_req = req.replace("__barrel_optimize__?names=__PLACEHOLDER__!=!", ""); let wildcard_resolve = resolver .resolve(&file.parent().unwrap().to_path_buf(), &real_req) - .map_err(|err| internal_error!("Failed to resolve {err:?}"))?; + .map_err(|err| error!("Failed to resolve {err:?}"))?; if let ResolveResult::Resource(resource) = wildcard_resolve { - let res = - get_barrel_map_boxed(visited.clone(), resolver.clone(), resource.path, cache_dir.clone(), true, None) - .await?; + let res = get_barrel_map_boxed( + visited.clone(), + resolver.clone(), + resource.path, + cache_dir.clone(), + true, + None, + ) + .await?; if let Some(TransformMapping { export_list: sub_export_list, wildcard_exports: _, @@ -221,7 +227,14 @@ fn get_barrel_map_boxed( is_wildcard: bool, source: Option, ) -> Pin>> + Send>> { - Box::pin(get_barrel_map(visited, resolver, file, cache_dir, is_wildcard, source)) + Box::pin(get_barrel_map( + visited, + resolver, + file, + cache_dir, + is_wildcard, + source, + )) } #[async_trait::async_trait] @@ -238,9 +251,7 @@ impl Loader for BarrelLoader { dependency_category: DependencyCategory::Esm, }); - let Some(content) = std::mem::take(&mut loader_context.content) else { - return Err(internal_error!("No content found")); - }; + let content = std::mem::take(&mut loader_context.content).expect("content should be available"); let source = content.try_into_string()?; let result = { diff --git a/crates/loader_barrel/tests/fixtures.rs b/crates/loader_barrel/tests/fixtures.rs index a3b8688..a4600af 100644 --- a/crates/loader_barrel/tests/fixtures.rs +++ b/crates/loader_barrel/tests/fixtures.rs @@ -2,13 +2,13 @@ use std::{ env, fs, path::{Path, PathBuf}, str::FromStr, - sync::Arc, + sync::Arc, vec, }; use loader_barrel::{BarrelLoader, LoaderOptions}; use rspack_core::{ run_loaders, CompilerContext, CompilerOptions, Loader, LoaderRunnerContext, ResourceData, - SideEffectOption, + SideEffectOption, ResolverFactory, }; use swc_core::base::config::Config; use swc_core::ecma::ast::EsVersion; @@ -96,7 +96,12 @@ async fn loader_test(actual: impl AsRef, expected: impl AsRef) { }, profile: false, }), - resolver_factory: Default::default(), + resolver_factory: Arc::new( + ResolverFactory::new( + rspack_core::Resolve { extensions: Some(vec![".js".to_string()]), + ..Default::default() + } + )), }, ) .await diff --git a/crates/loader_compilation/src/lib.rs b/crates/loader_compilation/src/lib.rs index 1fae4bc..fd1f75b 100644 --- a/crates/loader_compilation/src/lib.rs +++ b/crates/loader_compilation/src/lib.rs @@ -3,7 +3,7 @@ use std::{collections::HashMap, path::Path, sync::Mutex}; use lazy_static::lazy_static; use rspack_ast::RspackAst; use rspack_core::{rspack_sources::SourceMap, LoaderRunnerContext, Mode}; -use rspack_error::{internal_error, AnyhowError, Diagnostic, Result}; +use rspack_error::{error, AnyhowError, Diagnostic, Result}; use rspack_loader_runner::{Identifiable, Identifier, Loader, LoaderContext}; use rspack_plugin_javascript::{ ast::{self, SourceMapConfig}, @@ -99,9 +99,7 @@ impl Loader for CompilationLoader { } } - let Some(content) = std::mem::take(&mut loader_context.content) else { - return Err(internal_error!("No content found")); - }; + let content = std::mem::take(&mut loader_context.content).expect("content should be available"); let swc_options = { let mut swc_options = self.loader_options.swc_options.clone(); @@ -219,7 +217,7 @@ impl Loader for CompilationLoader { loader_context.source_map = map .map(|m| SourceMap::from_json(&m)) .transpose() - .map_err(|e| internal_error!(e.to_string()))?; + .map_err(|e| error!(e.to_string()))?; } Ok(()) diff --git a/crates/loader_compilation/src/transform.rs b/crates/loader_compilation/src/transform.rs index ba15e21..1a35f58 100644 --- a/crates/loader_compilation/src/transform.rs +++ b/crates/loader_compilation/src/transform.rs @@ -7,8 +7,8 @@ use swc_core::common::chain; use swc_core::ecma::{transforms::base::pass::noop, visit::Fold}; use swc_env_replacement::env_replacement; use swc_keep_export::keep_export; -use swc_remove_export::remove_export; use swc_named_import_transform::{named_import_transform, TransformConfig}; +use swc_remove_export::remove_export; macro_rules! either { ($config:expr, $f:expr) => { @@ -93,14 +93,11 @@ pub(crate) fn transform<'a>( feature_options: &TransformFeatureOptions, ) -> impl Fold + 'a { chain!( - either!( - feature_options.optimize_import, - |options: &Vec| { - named_import_transform(TransformConfig { - packages: options.clone(), - }) - } - ), + either!(feature_options.optimize_import, |options: &Vec| { + named_import_transform(TransformConfig { + packages: options.clone(), + }) + }), either!( Some(&vec!["@uni/env".to_string(), "universal-env".to_string()]), |options: &Vec| { env_replacement(options.clone()) } diff --git a/crates/loader_compilation/tests/fixtures.rs b/crates/loader_compilation/tests/fixtures.rs index efe4a9f..b33a2ce 100644 --- a/crates/loader_compilation/tests/fixtures.rs +++ b/crates/loader_compilation/tests/fixtures.rs @@ -9,7 +9,7 @@ use loader_compilation::{CompilationLoader, LoaderOptions}; use rspack_ast::RspackAst; use rspack_core::{ run_loaders, CompilerContext, CompilerOptions, Loader, LoaderRunnerContext, ResourceData, - SideEffectOption, + SideEffectOption, ResolverFactory, }; use rspack_plugin_javascript::ast; use swc_core::base::config::Config; @@ -99,7 +99,12 @@ async fn loader_test(actual: impl AsRef, expected: impl AsRef) { }, profile: false, }), - resolver_factory: Default::default(), + resolver_factory: Arc::new( + ResolverFactory::new( + rspack_core::Resolve { extensions: Some(vec![".js".to_string()]), + ..Default::default() + } + )), }, ) .await diff --git a/crates/node_binding/Cargo.toml b/crates/node_binding/Cargo.toml index 06b95bc..db20d3e 100644 --- a/crates/node_binding/Cargo.toml +++ b/crates/node_binding/Cargo.toml @@ -8,27 +8,21 @@ crate-type = ["cdylib"] [dependencies] rspack_binding_macros = { path = "../.rspack_crates/rspack_binding_macros" } -rspack_binding_values = { path = "../.rspack_crates/rspack_binding_values" } -binding_options = { path = "../binding_options" } rspack_binding_options = { path = "../.rspack_crates/rspack_binding_options" } +binding_options = { path = "../binding_options" } +rspack_binding_values = { path = "../.rspack_crates/rspack_binding_values" } rspack_core = { path = "../.rspack_crates/rspack_core" } rspack_error = { path = "../.rspack_crates/rspack_error" } rspack_fs_node = { path = "../.rspack_crates/rspack_fs_node" } -rspack_identifier = { path = "../.rspack_crates/rspack_identifier" } rspack_napi_shared = { path = "../.rspack_crates/rspack_napi_shared" } rspack_tracing = { path = "../.rspack_crates/rspack_tracing" } async-trait = { workspace = true } -dashmap = { workspace = true } -futures = { workspace = true } once_cell = { workspace = true } -rustc-hash = { workspace = true } tracing = { workspace = true } -serde_json = { workspace = true } napi = { workspace = true } napi-derive = { workspace = true } -napi-sys = { workspace = true } color-backtrace = "0.6" @@ -40,3 +34,6 @@ tikv-jemallocator = { workspace = true } [build-dependencies] napi-build = { workspace = true } + +[dev-dependencies] +testing_macros = { workspace = true } diff --git a/crates/node_binding/src/hook.rs b/crates/node_binding/src/hook.rs index 578482b..376b739 100644 --- a/crates/node_binding/src/hook.rs +++ b/crates/node_binding/src/hook.rs @@ -24,6 +24,7 @@ pub enum Hook { ProcessAssetsStageOptimizeTransfer, ProcessAssetsStageAnalyse, ProcessAssetsStageReport, + AfterProcessAssets, Emit, AssetEmitted, ShouldEmit, @@ -37,7 +38,9 @@ pub enum Hook { OptimizeTree, /// webpack `compilation.hooks.chunkAsset` ChunkAsset, + ContextModuleFactoryBeforeResolve, NormalModuleFactoryResolveForScheme, + NormalModuleFactoryCreateModule, AfterResolve, BeforeResolve, SucceedModule, @@ -69,6 +72,7 @@ impl From for Hook { "processAssetsStageOptimizeTransfer" => Hook::ProcessAssetsStageOptimizeTransfer, "processAssetsStageAnalyse" => Hook::ProcessAssetsStageAnalyse, "processAssetsStageReport" => Hook::ProcessAssetsStageReport, + "afterProcessAssets" => Hook::AfterProcessAssets, "emit" => Hook::Emit, "assetEmitted" => Hook::AssetEmitted, "shouldEmit" => Hook::ShouldEmit, @@ -81,6 +85,8 @@ impl From for Hook { "afterOptimizeModules" => Hook::AfterOptimizeModules, "optimizeTree" => Hook::OptimizeTree, "chunkAsset" => Hook::ChunkAsset, + "contextModuleFactoryBeforeResolve" => Hook::ContextModuleFactoryBeforeResolve, + "normalModuleFactoryCreateModule" => Hook::NormalModuleFactoryCreateModule, "normalModuleFactoryResolveForScheme" => Hook::NormalModuleFactoryResolveForScheme, "afterResolve" => Hook::AfterResolve, "beforeResolve" => Hook::BeforeResolve, diff --git a/crates/node_binding/src/lib.rs b/crates/node_binding/src/lib.rs index 5fafb16..11c1682 100644 --- a/crates/node_binding/src/lib.rs +++ b/crates/node_binding/src/lib.rs @@ -15,6 +15,7 @@ use once_cell::sync::Lazy; use rspack_binding_options::BuiltinPlugin; use rspack_binding_values::SingleThreadedHashMap; use rspack_core::PluginExt; +use rspack_error::Diagnostic; use rspack_fs_node::{AsyncNodeWritableFileSystem, ThreadsafeNodeFS}; mod hook; @@ -130,10 +131,12 @@ impl Rspack { unsafe { std::mem::transmute::<&'_ mut _, &'static mut _>(compiler) }; callbackify(env, f, async move { - compiler - .build() - .await - .map_err(|e| Error::new(napi::Status::GenericFailure, format!("{e}")))?; + compiler.build().await.map_err(|e| { + Error::new( + napi::Status::GenericFailure, + print_error_diagnostic(e, compiler.options.stats.colors), + ) + })?; tracing::info!("build ok"); Ok(()) }) @@ -171,7 +174,12 @@ impl Rspack { HashSet::from_iter(removed_files.into_iter()), ) .await - .map_err(|e| Error::new(napi::Status::GenericFailure, format!("{e:?}")))?; + .map_err(|e| { + Error::new( + napi::Status::GenericFailure, + print_error_diagnostic(e, compiler.options.stats.colors), + ) + })?; tracing::info!("rebuild ok"); Ok(()) }) @@ -240,6 +248,12 @@ fn init() { panic::install_panic_handler(); } +fn print_error_diagnostic(e: rspack_error::Error, colored: bool) -> String { + Diagnostic::from(e) + .render_report(colored) + .expect("should print diagnostics") +} + static GLOBAL_TRACE_STATE: Mutex = Mutex::new(TraceState::Off); /** diff --git a/crates/node_binding/src/plugins/loader.rs b/crates/node_binding/src/plugins/loader.rs index 2156603..bcea69f 100644 --- a/crates/node_binding/src/plugins/loader.rs +++ b/crates/node_binding/src/plugins/loader.rs @@ -5,7 +5,7 @@ use rspack_binding_options::{JsLoaderAdapter, JsLoaderRunner}; use rspack_core::{ BoxLoader, CompilerOptions, NormalModule, Plugin, ResolveResult, Resolver, BUILTIN_LOADER_PREFIX, }; -use rspack_error::{internal_error, Result}; +use rspack_error::{error, Result}; pub struct JsLoaderResolver { pub js_loader_runner: JsLoaderRunner, @@ -73,7 +73,7 @@ impl Plugin for JsLoaderResolver { .map_err(|err| { let loader_request = prev.display(); let context = context.display(); - internal_error!("Failed to resolve loader: {loader_request} in {context} {err:?}") + error!("Failed to resolve loader: {loader_request} in {context} {err:?}") })?; match resolve_result { @@ -87,9 +87,7 @@ impl Plugin for JsLoaderResolver { } ResolveResult::Ignored => { let loader_request = prev.display(); - Err(internal_error!( - "Failed to resolve loader: {loader_request}" - )) + Err(error!("Failed to resolve loader: {loader_request}")) } } } diff --git a/crates/node_binding/src/plugins/mod.rs b/crates/node_binding/src/plugins/mod.rs index 276d6f1..caeac1f 100644 --- a/crates/node_binding/src/plugins/mod.rs +++ b/crates/node_binding/src/plugins/mod.rs @@ -5,13 +5,16 @@ use std::path::PathBuf; use async_trait::async_trait; use napi::{Env, Result}; use rspack_binding_macros::js_fn_into_threadsafe_fn; -use rspack_binding_values::JsExecuteModuleArg; use rspack_binding_values::{AfterResolveData, JsChunkAssetArgs, JsModule}; use rspack_binding_values::{BeforeResolveData, JsAssetEmittedArgs, ToJsModule}; +use rspack_binding_values::{CreateModuleData, JsExecuteModuleArg}; use rspack_binding_values::{JsResolveForSchemeInput, JsResolveForSchemeResult}; use rspack_core::{ChunkAssetArgs, ModuleIdentifier, NormalModuleAfterResolveArgs}; use rspack_core::{NormalModuleBeforeResolveArgs, PluginNormalModuleFactoryAfterResolveOutput}; -use rspack_core::{PluginNormalModuleFactoryBeforeResolveOutput, ResourceData}; +use rspack_core::{ + NormalModuleCreateData, PluginNormalModuleFactoryBeforeResolveOutput, + PluginNormalModuleFactoryCreateModuleHookOutput, ResourceData, +}; use rspack_core::{PluginNormalModuleFactoryResolveForSchemeOutput, PluginShouldEmitHookOutput}; use rspack_napi_shared::threadsafe_function::{ThreadsafeFunction, ThreadsafeFunctionCallMode}; use rspack_napi_shared::NapiResultExt; @@ -40,6 +43,7 @@ pub struct JsHooksAdapter { pub process_assets_stage_optimize_transfer_tsfn: ThreadsafeFunction<(), ()>, pub process_assets_stage_analyse_tsfn: ThreadsafeFunction<(), ()>, pub process_assets_stage_report_tsfn: ThreadsafeFunction<(), ()>, + pub after_process_assets_tsfn: ThreadsafeFunction<(), ()>, pub emit_tsfn: ThreadsafeFunction<(), ()>, pub asset_emitted_tsfn: ThreadsafeFunction, pub should_emit_tsfn: ThreadsafeFunction>, @@ -56,7 +60,8 @@ pub struct JsHooksAdapter { pub chunk_asset_tsfn: ThreadsafeFunction, pub before_resolve: ThreadsafeFunction, BeforeResolveData)>, pub after_resolve: ThreadsafeFunction>, - pub context_module_before_resolve: ThreadsafeFunction>, + pub context_module_factory_before_resolve: ThreadsafeFunction>, + pub normal_module_factory_create_module: ThreadsafeFunction, pub normal_module_factory_resolve_for_scheme: ThreadsafeFunction, pub succeed_module_tsfn: ThreadsafeFunction, @@ -143,7 +148,7 @@ impl rspack_core::Plugin for JsHooksAdapter { &self, _ctx: rspack_core::PluginContext, _compilation: &mut rspack_core::Compilation, - _param: &mut rspack_core::MakeParam, + _params: &mut Vec, ) -> rspack_core::PluginMakeHookOutput { if self.is_hook_disabled(&Hook::Make) { return Ok(()); @@ -185,30 +190,52 @@ impl rspack_core::Plugin for JsHooksAdapter { async fn after_resolve( &self, _ctx: rspack_core::PluginContext, - args: &NormalModuleAfterResolveArgs, + args: &mut NormalModuleAfterResolveArgs<'_>, ) -> PluginNormalModuleFactoryAfterResolveOutput { if self.is_hook_disabled(&Hook::AfterResolve) { return Ok(None); } self .after_resolve - .call(args.clone().into(), ThreadsafeFunctionCallMode::NonBlocking) + .call((&*args).into(), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await .unwrap_or_else(|err| panic!("Failed to call this_compilation: {err}")) } + async fn context_module_before_resolve( &self, _ctx: rspack_core::PluginContext, args: &mut NormalModuleBeforeResolveArgs, ) -> PluginNormalModuleFactoryBeforeResolveOutput { + if self.is_hook_disabled(&Hook::ContextModuleFactoryBeforeResolve) { + return Ok(None); + } self - .context_module_before_resolve + .context_module_factory_before_resolve .call(args.clone().into(), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await .unwrap_or_else(|err| panic!("Failed to call this_compilation: {err}")) } + + async fn normal_module_factory_create_module( + &self, + _ctx: rspack_core::PluginContext, + args: &mut NormalModuleCreateData<'_>, + ) -> PluginNormalModuleFactoryCreateModuleHookOutput { + if self.is_hook_disabled(&Hook::NormalModuleFactoryCreateModule) { + return Ok(None); + } + self + .normal_module_factory_create_module + .call(args.into(), ThreadsafeFunctionCallMode::NonBlocking) + .into_rspack_result()? + .await + .map(|_| None) + .map_err(|err| panic!("Failed to call this_compilation: {err}")) + } + async fn normal_module_factory_resolve_for_scheme( &self, _ctx: rspack_core::PluginContext, @@ -512,6 +539,22 @@ impl rspack_core::Plugin for JsHooksAdapter { .unwrap_or_else(|err| panic!("Failed to call process assets stage report: {err}")) } + async fn after_process_assets( + &self, + _ctx: rspack_core::PluginContext, + _args: rspack_core::ProcessAssetsArgs<'_>, + ) -> rspack_core::PluginProcessAssetsHookOutput { + if self.is_hook_disabled(&Hook::AfterProcessAssets) { + return Ok(()); + } + self + .after_process_assets_tsfn + .call((), ThreadsafeFunctionCallMode::NonBlocking) + .into_rspack_result()? + .await + .unwrap_or_else(|err| panic!("Failed to call process assets stage report: {err}")) + } + async fn optimize_modules( &self, compilation: &mut rspack_core::Compilation, @@ -829,6 +872,7 @@ impl JsHooksAdapter { process_assets_stage_optimize_transfer, process_assets_stage_analyse, process_assets_stage_report, + after_process_assets, this_compilation, compilation, should_emit, @@ -841,7 +885,8 @@ impl JsHooksAdapter { optimize_chunk_modules, before_resolve, after_resolve, - context_module_before_resolve, + context_module_factory_before_resolve, + normal_module_factory_create_module, normal_module_factory_resolve_for_scheme, before_compile, after_compile, @@ -886,6 +931,8 @@ impl JsHooksAdapter { js_fn_into_threadsafe_fn!(process_assets_stage_optimize_hash, env); let process_assets_stage_report_tsfn: ThreadsafeFunction<(), ()> = js_fn_into_threadsafe_fn!(process_assets_stage_report, env); + let after_process_assets_tsfn: ThreadsafeFunction<(), ()> = + js_fn_into_threadsafe_fn!(after_process_assets, env); let emit_tsfn: ThreadsafeFunction<(), ()> = js_fn_into_threadsafe_fn!(emit, env); let should_emit_tsfn: ThreadsafeFunction> = js_fn_into_threadsafe_fn!(should_emit, env); @@ -915,12 +962,14 @@ impl JsHooksAdapter { js_fn_into_threadsafe_fn!(build_module, env); let finish_modules_tsfn: ThreadsafeFunction = js_fn_into_threadsafe_fn!(finish_modules, env); - let context_module_before_resolve: ThreadsafeFunction> = - js_fn_into_threadsafe_fn!(context_module_before_resolve, env); + let context_module_factory_before_resolve: ThreadsafeFunction> = + js_fn_into_threadsafe_fn!(context_module_factory_before_resolve, env); let before_resolve: ThreadsafeFunction, BeforeResolveData)> = js_fn_into_threadsafe_fn!(before_resolve, env); let after_resolve: ThreadsafeFunction> = js_fn_into_threadsafe_fn!(after_resolve, env); + let normal_module_factory_create_module: ThreadsafeFunction = + js_fn_into_threadsafe_fn!(normal_module_factory_create_module, env); let normal_module_factory_resolve_for_scheme: ThreadsafeFunction< JsResolveForSchemeInput, JsResolveForSchemeResult, @@ -953,6 +1002,7 @@ impl JsHooksAdapter { process_assets_stage_optimize_transfer_tsfn, process_assets_stage_analyse_tsfn, process_assets_stage_report_tsfn, + after_process_assets_tsfn, compilation_tsfn, this_compilation_tsfn, should_emit_tsfn, @@ -966,7 +1016,8 @@ impl JsHooksAdapter { before_compile_tsfn, after_compile_tsfn, before_resolve, - context_module_before_resolve, + context_module_factory_before_resolve, + normal_module_factory_create_module, normal_module_factory_resolve_for_scheme, finish_modules_tsfn, finish_make_tsfn, diff --git a/crates/plugin_manifest/src/plugin.rs b/crates/plugin_manifest/src/plugin.rs index 992c9f8..0f1f383 100644 --- a/crates/plugin_manifest/src/plugin.rs +++ b/crates/plugin_manifest/src/plugin.rs @@ -72,17 +72,16 @@ impl Plugin for ManifestPlugin { .chunks .iter() .for_each(|chunk| { - if let Some(chunk) = compilation.chunk_by_ukey.get(chunk) { - chunk.files.iter().for_each(|file| { - if let Some(asset) = assets.get(file) { - if !asset.info.hot_module_replacement && !asset.info.development { - files.push(file.to_string()); - } - } else { + let chunk = compilation.chunk_by_ukey.expect_get(chunk); + chunk.files.iter().for_each(|file| { + if let Some(asset) = assets.get(file) { + if !asset.info.hot_module_replacement && !asset.info.development { files.push(file.to_string()); } - }); - }; + } else { + files.push(file.to_string()); + } + }); }); assets_mainfest.entries.insert(name.to_string(), files); }); diff --git a/crates/plugin_specilize_module_name/tests/fixtures/basic/snapshot/output.snap b/crates/plugin_specilize_module_name/tests/fixtures/basic/snapshot/output.snap index 486d001..8fd8cae 100644 --- a/crates/plugin_specilize_module_name/tests/fixtures/basic/snapshot/output.snap +++ b/crates/plugin_specilize_module_name/tests/fixtures/basic/snapshot/output.snap @@ -21,7 +21,7 @@ const { add_3 } = __webpack_require__(/*! ./util_1 */"./util_1.js"); return add_3(0); } }), -"./index.js": (function (__unused_webpack_module, exports, __webpack_require__) { +"./index.js": (function (__unused_webpack_module, __unused_webpack_exports, __webpack_require__) { console.log("Hello World!"); const { cal } = __webpack_require__(/*! ./function */"./function.js"); const { add } = __webpack_require__(/*! ./utils */"./utils.js?id=1"); diff --git a/crates/swc_plugin_change_package_import/.gitignore b/crates/swc_change_package_import/.gitignore similarity index 100% rename from crates/swc_plugin_change_package_import/.gitignore rename to crates/swc_change_package_import/.gitignore diff --git a/crates/swc_plugin_change_package_import/Cargo.toml b/crates/swc_change_package_import/Cargo.toml similarity index 59% rename from crates/swc_plugin_change_package_import/Cargo.toml rename to crates/swc_change_package_import/Cargo.toml index 9136d6d..92deb34 100644 --- a/crates/swc_plugin_change_package_import/Cargo.toml +++ b/crates/swc_change_package_import/Cargo.toml @@ -1,22 +1,23 @@ [package] -name = "swc_plugin_change_package_import" +name = "swc_change_package_import" version = "0.1.0" edition = "2021" [lib] crate-type = ["cdylib", "rlib"] -[profile.release] -lto = true - [dependencies] serde = { workspace = true } swc_core = { workspace = true, features = [ - "ecma_plugin_transform", + "base", "ecma_ast", - "common", "ecma_utils", + "ecma_visit", + "common", ] } [dev-dependencies] -testing = "0.35.11" \ No newline at end of file +swc_core = { workspace = true, features = [ + "testing_transform", +] } +testing = { workspace = true } diff --git a/crates/swc_plugin_change_package_import/package.json b/crates/swc_change_package_import/package.json similarity index 100% rename from crates/swc_plugin_change_package_import/package.json rename to crates/swc_change_package_import/package.json diff --git a/crates/swc_change_package_import/src/change_package_import.rs b/crates/swc_change_package_import/src/change_package_import.rs new file mode 100644 index 0000000..ce79792 --- /dev/null +++ b/crates/swc_change_package_import/src/change_package_import.rs @@ -0,0 +1,212 @@ +use swc_core::{ + common::{util::take::Take, DUMMY_SP}, + ecma::{ + ast::*, + atoms::JsWord, + utils::{quote_str, swc_ecma_ast::ImportSpecifier}, + visit::{VisitMut, VisitMutWith}, + }, +}; + +use crate::config::{Config, ImportType}; + +pub struct ModuleImportVisitor { + // 用户配置 + pub options: Vec, + // 全新生成的导入声明 + new_stmts: Vec, +} + +impl ModuleImportVisitor { + pub fn new(options: Vec) -> Self { + Self { + options, + new_stmts: vec![], + } + } +} + +impl VisitMut for ModuleImportVisitor { + fn visit_mut_import_decl(&mut self, import_decl: &mut ImportDecl) { + import_decl.visit_mut_children_with(self); + + for option in &self.options { + match option { + Config::LiteralConfig(src) => { + if is_hit_rule(import_decl, option) { + for specifier in &import_decl.specifiers { + match specifier { + ImportSpecifier::Named(named_import_spec) => { + let mut import_new_src = src.clone(); + import_new_src.push_str("/"); + import_new_src.push_str(&get_import_module_name(named_import_spec)); + + self.new_stmts.push(create_default_import_decl( + import_new_src, + named_import_spec.local.clone(), + )); + } + _ => (), + } + } + // 清空当前导入声明,否则会被作为有效的声明添加至 new_stmts 中 + import_decl.take(); + break; + } + } + Config::SpecificConfig(config) => { + if is_hit_rule(import_decl, option) { + let target_fields: Vec<&String> = config.map.keys().clone().collect(); + let mut named_import_spec_copy = import_decl.clone(); + + // 获取未命中规则的导入声明 + named_import_spec_copy.specifiers = named_import_spec_copy + .specifiers + .into_iter() + .filter(|specifier| match specifier { + ImportSpecifier::Named(named_import_spec) => { + let import_object_name = get_import_module_name(named_import_spec); + !target_fields.contains(&&import_object_name) + } + _ => true, + }) + .collect::>(); + + if named_import_spec_copy.specifiers.len() != 0 { + self + .new_stmts + .push(ModuleItem::ModuleDecl(ModuleDecl::Import( + named_import_spec_copy, + ))); + } + + for (target, rules) in config.map.iter() { + for specifier in &import_decl.specifiers { + match specifier { + ImportSpecifier::Named(named_import_spec) => { + let import_object_name = get_import_module_name(named_import_spec); + if target == &import_object_name { + let new_import_decl: ModuleItem; + if rules.import_type.is_none() + || match rules.import_type.as_ref().unwrap() { + ImportType::Default => true, + _ => false, + } + { + // Default import mode + new_import_decl = create_default_import_decl( + rules.to.to_string(), + named_import_spec.local.clone(), + ); + } else { + // Named import mode + let mut named_import_spec_copy = named_import_spec.clone(); + + if rules.name.is_some() { + named_import_spec_copy.imported = Some(ModuleExportName::Str(Str { + span: named_import_spec.span, + value: rules.name.clone().unwrap().into(), + raw: Some(rules.name.clone().unwrap().clone().into()), + })) + } + + new_import_decl = create_named_import_decl( + rules.to.to_string(), + vec![ImportSpecifier::Named(named_import_spec_copy)], + ); + } + + self.new_stmts.push(new_import_decl); + } + } + _ => (), + } + } + } + import_decl.take(); + break; + } + } + } + } + + if !is_empty_decl(import_decl) { + self + .new_stmts + .push(wrap_with_moudle_item(import_decl.clone())); + } + } + + fn visit_mut_module_item(&mut self, n: &mut ModuleItem) { + n.visit_mut_children_with(self); + + if !n.is_module_decl() { + self.new_stmts.push(n.clone()); + } + } + + fn visit_mut_module_items(&mut self, stmts: &mut Vec) { + stmts.visit_mut_children_with(self); + + *stmts = self.new_stmts.clone(); + } +} + +fn is_hit_rule(cur_import: &ImportDecl, rule: &Config) -> bool { + match rule { + Config::LiteralConfig(s) => { + if cur_import.src.value == JsWord::from(s.clone()) { + return true; + } + false + } + Config::SpecificConfig(s) => { + if cur_import.src.value == JsWord::from(s.name.clone()) { + return true; + } + false + } + } +} + +fn is_empty_decl(decl: &ImportDecl) -> bool { + decl.specifiers.len() == 0 && decl.src.value == JsWord::from("".to_string()) +} + +fn get_import_module_name(named_import_spec: &ImportNamedSpecifier) -> String { + if named_import_spec.imported.is_none() { + (&named_import_spec.local.sym).to_string() + } else { + match &named_import_spec.imported.clone().unwrap() { + ModuleExportName::Ident(ident) => (&ident.sym).to_string(), + ModuleExportName::Str(str) => (&str.value).to_string(), + } + } +} + +fn create_default_import_decl(src: String, local: Ident) -> ModuleItem { + wrap_with_moudle_item(ImportDecl { + src: Box::new(quote_str!(src)), + specifiers: vec![ImportSpecifier::Default(ImportDefaultSpecifier { + span: DUMMY_SP, + local, + })], + span: DUMMY_SP, + type_only: false, + with: None, + }) +} + +fn create_named_import_decl(src: String, specifiers: Vec) -> ModuleItem { + wrap_with_moudle_item(ImportDecl { + src: Box::new(quote_str!(src)), + specifiers, + span: DUMMY_SP, + type_only: false, + with: None, + }) +} + +fn wrap_with_moudle_item(import_decl: ImportDecl) -> ModuleItem { + ModuleItem::ModuleDecl(ModuleDecl::Import(import_decl)) +} diff --git a/crates/swc_change_package_import/src/config.rs b/crates/swc_change_package_import/src/config.rs new file mode 100644 index 0000000..1f31ff3 --- /dev/null +++ b/crates/swc_change_package_import/src/config.rs @@ -0,0 +1,62 @@ +use std::collections::HashMap; + +#[derive(Debug)] +pub enum Config { + /// 配置: + /// ```rs + /// Config::LiteralConfig(String::from("antd")) + /// ``` + /// 效果: + /// ```js + /// import { Button } from "antd"; + /// // ---> + /// import Button from "antd/Button"; + /// ``` + LiteralConfig(String), + /// 配置: + /// ```rs + /// Config::SpecificConfig( + // SpecificConfigs { + // name: String::from("ice"), + // map: HashMap::from([ + // ( + // "a".to_string(), + // MapProperty { + // to: String::from("@ice/x/y"), + // import_type: None, + // name: None, + // } + // ), + // ]), + // } + // ), + /// ``` + /// 效果: + /// ```js + /// import { a } from "ice"; + /// // ---> + /// import a from "@ice/x/y"; + /// ``` + /// + /// 更多配置请参考[文档](https://alidocs.dingtalk.com/i/nodes/20eMKjyp810mMdK4Ho1LpqX7JxAZB1Gv?utm_scene=team_space) + SpecificConfig(SpecificConfigs), +} + +#[derive(Debug)] +pub struct SpecificConfigs { + pub name: String, + pub map: HashMap, +} + +#[derive(Debug)] +pub struct MapProperty { + pub to: String, + pub import_type: Option, + pub name: Option, +} + +#[derive(Debug, PartialEq)] +pub enum ImportType { + Named, + Default, +} diff --git a/crates/swc_plugin_change_package_import/src/lib.rs b/crates/swc_change_package_import/src/lib.rs similarity index 63% rename from crates/swc_plugin_change_package_import/src/lib.rs rename to crates/swc_change_package_import/src/lib.rs index ed9b552..b32122a 100644 --- a/crates/swc_plugin_change_package_import/src/lib.rs +++ b/crates/swc_change_package_import/src/lib.rs @@ -1,5 +1,5 @@ -mod config; mod change_package_import; +mod config; +pub use change_package_import::*; pub use config::*; -pub use change_package_import::*; \ No newline at end of file diff --git a/crates/swc_change_package_import/tests/fixture.rs b/crates/swc_change_package_import/tests/fixture.rs new file mode 100644 index 0000000..9623887 --- /dev/null +++ b/crates/swc_change_package_import/tests/fixture.rs @@ -0,0 +1,301 @@ +use std::collections::HashMap; +use std::path::PathBuf; + +use swc_core::ecma::{ + transforms::testing::{test_fixture, FixtureTestConfig}, + visit::as_folder, +}; +use swc_change_package_import::{ + Config, ImportType, MapProperty, ModuleImportVisitor, SpecificConfigs, +}; + +#[testing::fixture("tests/fixture/single_literal_transform/input.js")] +fn test_single_literal_transform(input: PathBuf) { + let output = input.with_file_name("output.js"); + test_fixture( + Default::default(), + &|_t| { + as_folder(ModuleImportVisitor::new(vec![Config::LiteralConfig( + String::from("y"), + )])) + }, + &input, + &output, + FixtureTestConfig { + ..Default::default() + }, + ); +} + +#[testing::fixture("tests/fixture/multi_literal_transform/input.js")] +fn test_multi_literal_transform(input: PathBuf) { + let output = input.with_file_name("output.js"); + test_fixture( + Default::default(), + &|_t| { + as_folder(ModuleImportVisitor::new(vec![ + Config::LiteralConfig(String::from("z")), + Config::LiteralConfig(String::from("o")), + ])) + }, + &input, + &output, + FixtureTestConfig { + ..Default::default() + }, + ); +} + +#[testing::fixture("tests/fixture/single_specific_transform/input.js")] + +fn test_single_specific_transform(input: PathBuf) { + let output = input.with_file_name("output.js"); + test_fixture( + Default::default(), + &|_t| { + as_folder(ModuleImportVisitor::new(vec![Config::SpecificConfig( + SpecificConfigs { + name: String::from("y"), + map: HashMap::from([( + "x".to_string(), + MapProperty { + to: String::from("m/n"), + import_type: Some(ImportType::Named), + name: Some(String::from("a")), + }, + )]), + }, + )])) + }, + &input, + &output, + FixtureTestConfig { + ..Default::default() + }, + ); +} + +#[testing::fixture("tests/fixture/single_specific_transform_2/input.js")] +fn test_single_specific_transform_2(input: PathBuf) { + let output = input.with_file_name("output.js"); + test_fixture( + Default::default(), + &|_t| { + as_folder(ModuleImportVisitor::new(vec![Config::SpecificConfig( + SpecificConfigs { + name: String::from("y"), + map: HashMap::from([( + "x".to_string(), + MapProperty { + to: String::from("m/n"), + import_type: Some(ImportType::Named), + name: Some(String::from("a")), + }, + )]), + }, + )])) + }, + &input, + &output, + FixtureTestConfig { + ..Default::default() + }, + ); +} + +#[testing::fixture("tests/fixture/mix_specific_transform/input.js")] +fn test_mix_specific_transform(input: PathBuf) { + let output = input.with_file_name("output.js"); + test_fixture( + Default::default(), + &|_t| { + as_folder(ModuleImportVisitor::new(vec![ + Config::LiteralConfig(String::from("antd")), + Config::SpecificConfig(SpecificConfigs { + name: String::from("ice"), + map: HashMap::from([( + "a".to_string(), + MapProperty { + to: String::from("@ice/x/y"), + import_type: None, + name: None, + }, + )]), + }), + ])) + }, + &input, + &output, + FixtureTestConfig { + ..Default::default() + }, + ); +} + +#[testing::fixture("tests/fixture/ice_basic_transform/input.js")] +fn test_ice_basic_transform(input: PathBuf) { + let output = input.with_file_name("output.js"); + test_fixture( + Default::default(), + &|_t| { + as_folder(ModuleImportVisitor::new(vec![Config::SpecificConfig( + SpecificConfigs { + name: String::from("ice"), + map: HashMap::from([( + "runApp".to_string(), + MapProperty { + to: String::from("@ice/runtime"), + import_type: Some(ImportType::Named), + name: None, + }, + )]), + }, + )])) + }, + &input, + &output, + FixtureTestConfig { + ..Default::default() + }, + ); +} + +#[testing::fixture("tests/fixture/ice_as_transform/input.js")] +fn test_ice_as_transform(input: PathBuf) { + let output = input.with_file_name("output.js"); + test_fixture( + Default::default(), + &|_t| { + as_folder(ModuleImportVisitor::new(vec![Config::SpecificConfig( + SpecificConfigs { + name: String::from("ice"), + map: HashMap::from([( + "runApp".to_string(), + MapProperty { + to: String::from("@ice/runtime"), + import_type: Some(ImportType::Named), + name: None, + }, + )]), + }, + )])) + }, + &input, + &output, + FixtureTestConfig { + ..Default::default() + }, + ); +} + +#[testing::fixture("tests/fixture/ice_alias_transform/input.js")] +fn test_ice_alias_transform(input: PathBuf) { + let output = input.with_file_name("output.js"); + test_fixture( + Default::default(), + &|_t| { + as_folder(ModuleImportVisitor::new(vec![Config::SpecificConfig( + SpecificConfigs { + name: String::from("ice"), + map: HashMap::from([( + "Head".to_string(), + MapProperty { + to: String::from("react-helmet"), + import_type: Some(ImportType::Default), + name: Some("Helmet".to_string()), + }, + )]), + }, + )])) + }, + &input, + &output, + FixtureTestConfig { + ..Default::default() + }, + ); +} + +#[testing::fixture("tests/fixture/ice_alias_with_as_transform/input.js")] +fn test_ice_alias_with_as_transform(input: PathBuf) { + let output = input.with_file_name("output.js"); + test_fixture( + Default::default(), + &|_t| { + as_folder(ModuleImportVisitor::new(vec![Config::SpecificConfig( + SpecificConfigs { + name: String::from("ice"), + map: HashMap::from([( + "Head".to_string(), + MapProperty { + to: String::from("react-helmet"), + import_type: Some(ImportType::Default), + name: None, + }, + )]), + }, + )])) + }, + &input, + &output, + FixtureTestConfig { + ..Default::default() + }, + ); +} + +#[testing::fixture("tests/fixture/ice_matched_transform/input.js")] +fn test_ice_matched_transform(input: PathBuf) { + let output = input.with_file_name("output.js"); + test_fixture( + Default::default(), + &|_t| { + as_folder(ModuleImportVisitor::new(vec![Config::SpecificConfig( + SpecificConfigs { + name: String::from("ice"), + map: HashMap::from([( + "runApp".to_string(), + MapProperty { + to: String::from("@ice/runtime"), + import_type: Some(ImportType::Named), + name: None, + }, + )]), + }, + )])) + }, + &input, + &output, + FixtureTestConfig { + ..Default::default() + }, + ); +} + +#[testing::fixture("tests/fixture/ice_miss_match_transform/input.js")] +fn test_ice_miss_match_transform(input: PathBuf) { + let output = input.with_file_name("output.js"); + test_fixture( + Default::default(), + &|_t| { + as_folder(ModuleImportVisitor::new(vec![Config::SpecificConfig( + SpecificConfigs { + name: String::from("ice"), + map: HashMap::from([( + "runApp".to_string(), + MapProperty { + to: String::from("@ice/runtime"), + import_type: Some(ImportType::Named), + name: None, + }, + )]), + }, + )])) + }, + &input, + &output, + FixtureTestConfig { + ..Default::default() + }, + ); +} diff --git a/crates/swc_plugin_change_package_import/tests/fixture/ice_alias_transform/input.js b/crates/swc_change_package_import/tests/fixture/ice_alias_transform/input.js similarity index 100% rename from crates/swc_plugin_change_package_import/tests/fixture/ice_alias_transform/input.js rename to crates/swc_change_package_import/tests/fixture/ice_alias_transform/input.js diff --git a/crates/swc_plugin_change_package_import/tests/fixture/ice_alias_transform/output.js b/crates/swc_change_package_import/tests/fixture/ice_alias_transform/output.js similarity index 100% rename from crates/swc_plugin_change_package_import/tests/fixture/ice_alias_transform/output.js rename to crates/swc_change_package_import/tests/fixture/ice_alias_transform/output.js diff --git a/crates/swc_plugin_change_package_import/tests/fixture/ice_alias_with_as_transform/input.js b/crates/swc_change_package_import/tests/fixture/ice_alias_with_as_transform/input.js similarity index 100% rename from crates/swc_plugin_change_package_import/tests/fixture/ice_alias_with_as_transform/input.js rename to crates/swc_change_package_import/tests/fixture/ice_alias_with_as_transform/input.js diff --git a/crates/swc_plugin_change_package_import/tests/fixture/ice_alias_with_as_transform/output.js b/crates/swc_change_package_import/tests/fixture/ice_alias_with_as_transform/output.js similarity index 100% rename from crates/swc_plugin_change_package_import/tests/fixture/ice_alias_with_as_transform/output.js rename to crates/swc_change_package_import/tests/fixture/ice_alias_with_as_transform/output.js diff --git a/crates/swc_plugin_change_package_import/tests/fixture/ice_as_transform/input.js b/crates/swc_change_package_import/tests/fixture/ice_as_transform/input.js similarity index 100% rename from crates/swc_plugin_change_package_import/tests/fixture/ice_as_transform/input.js rename to crates/swc_change_package_import/tests/fixture/ice_as_transform/input.js diff --git a/crates/swc_plugin_change_package_import/tests/fixture/ice_as_transform/output.js b/crates/swc_change_package_import/tests/fixture/ice_as_transform/output.js similarity index 100% rename from crates/swc_plugin_change_package_import/tests/fixture/ice_as_transform/output.js rename to crates/swc_change_package_import/tests/fixture/ice_as_transform/output.js diff --git a/crates/swc_plugin_change_package_import/tests/fixture/ice_basic_transform/input.js b/crates/swc_change_package_import/tests/fixture/ice_basic_transform/input.js similarity index 100% rename from crates/swc_plugin_change_package_import/tests/fixture/ice_basic_transform/input.js rename to crates/swc_change_package_import/tests/fixture/ice_basic_transform/input.js diff --git a/crates/swc_plugin_change_package_import/tests/fixture/ice_basic_transform/output.js b/crates/swc_change_package_import/tests/fixture/ice_basic_transform/output.js similarity index 100% rename from crates/swc_plugin_change_package_import/tests/fixture/ice_basic_transform/output.js rename to crates/swc_change_package_import/tests/fixture/ice_basic_transform/output.js diff --git a/crates/swc_plugin_change_package_import/tests/fixture/ice_matched_transform/input.js b/crates/swc_change_package_import/tests/fixture/ice_matched_transform/input.js similarity index 100% rename from crates/swc_plugin_change_package_import/tests/fixture/ice_matched_transform/input.js rename to crates/swc_change_package_import/tests/fixture/ice_matched_transform/input.js diff --git a/crates/swc_plugin_change_package_import/tests/fixture/ice_matched_transform/output.js b/crates/swc_change_package_import/tests/fixture/ice_matched_transform/output.js similarity index 100% rename from crates/swc_plugin_change_package_import/tests/fixture/ice_matched_transform/output.js rename to crates/swc_change_package_import/tests/fixture/ice_matched_transform/output.js diff --git a/crates/swc_plugin_change_package_import/tests/fixture/ice_miss_match_transform/input.js b/crates/swc_change_package_import/tests/fixture/ice_miss_match_transform/input.js similarity index 100% rename from crates/swc_plugin_change_package_import/tests/fixture/ice_miss_match_transform/input.js rename to crates/swc_change_package_import/tests/fixture/ice_miss_match_transform/input.js diff --git a/crates/swc_plugin_change_package_import/tests/fixture/ice_miss_match_transform/output.js b/crates/swc_change_package_import/tests/fixture/ice_miss_match_transform/output.js similarity index 100% rename from crates/swc_plugin_change_package_import/tests/fixture/ice_miss_match_transform/output.js rename to crates/swc_change_package_import/tests/fixture/ice_miss_match_transform/output.js diff --git a/crates/swc_plugin_change_package_import/tests/fixture/ice_multiple_transform/input.js b/crates/swc_change_package_import/tests/fixture/ice_multiple_transform/input.js similarity index 100% rename from crates/swc_plugin_change_package_import/tests/fixture/ice_multiple_transform/input.js rename to crates/swc_change_package_import/tests/fixture/ice_multiple_transform/input.js diff --git a/crates/swc_plugin_change_package_import/tests/fixture/ice_multiple_transform/output.js b/crates/swc_change_package_import/tests/fixture/ice_multiple_transform/output.js similarity index 66% rename from crates/swc_plugin_change_package_import/tests/fixture/ice_multiple_transform/output.js rename to crates/swc_change_package_import/tests/fixture/ice_multiple_transform/output.js index a18b3b8..d305c41 100644 --- a/crates/swc_plugin_change_package_import/tests/fixture/ice_multiple_transform/output.js +++ b/crates/swc_change_package_import/tests/fixture/ice_multiple_transform/output.js @@ -1,3 +1,3 @@ import { request } from "axios"; import { test } from "axios"; -import store from "@ice/store"; +import store from "@ice/store"; \ No newline at end of file diff --git a/crates/swc_plugin_change_package_import/tests/fixture/mix_specific_transform/input.js b/crates/swc_change_package_import/tests/fixture/mix_specific_transform/input.js similarity index 100% rename from crates/swc_plugin_change_package_import/tests/fixture/mix_specific_transform/input.js rename to crates/swc_change_package_import/tests/fixture/mix_specific_transform/input.js diff --git a/crates/swc_plugin_change_package_import/tests/fixture/mix_specific_transform/output.js b/crates/swc_change_package_import/tests/fixture/mix_specific_transform/output.js similarity index 100% rename from crates/swc_plugin_change_package_import/tests/fixture/mix_specific_transform/output.js rename to crates/swc_change_package_import/tests/fixture/mix_specific_transform/output.js diff --git a/crates/swc_plugin_change_package_import/tests/fixture/multi_literal_transform/input.js b/crates/swc_change_package_import/tests/fixture/multi_literal_transform/input.js similarity index 100% rename from crates/swc_plugin_change_package_import/tests/fixture/multi_literal_transform/input.js rename to crates/swc_change_package_import/tests/fixture/multi_literal_transform/input.js diff --git a/crates/swc_plugin_change_package_import/tests/fixture/multi_literal_transform/output.js b/crates/swc_change_package_import/tests/fixture/multi_literal_transform/output.js similarity index 100% rename from crates/swc_plugin_change_package_import/tests/fixture/multi_literal_transform/output.js rename to crates/swc_change_package_import/tests/fixture/multi_literal_transform/output.js diff --git a/crates/swc_plugin_change_package_import/tests/fixture/multi_specific_transform/input.js b/crates/swc_change_package_import/tests/fixture/multi_specific_transform/input.js similarity index 100% rename from crates/swc_plugin_change_package_import/tests/fixture/multi_specific_transform/input.js rename to crates/swc_change_package_import/tests/fixture/multi_specific_transform/input.js diff --git a/crates/swc_plugin_change_package_import/tests/fixture/multi_specific_transform/output.js b/crates/swc_change_package_import/tests/fixture/multi_specific_transform/output.js similarity index 100% rename from crates/swc_plugin_change_package_import/tests/fixture/multi_specific_transform/output.js rename to crates/swc_change_package_import/tests/fixture/multi_specific_transform/output.js diff --git a/crates/swc_plugin_change_package_import/tests/fixture/single_literal_transform/input.js b/crates/swc_change_package_import/tests/fixture/single_literal_transform/input.js similarity index 100% rename from crates/swc_plugin_change_package_import/tests/fixture/single_literal_transform/input.js rename to crates/swc_change_package_import/tests/fixture/single_literal_transform/input.js diff --git a/crates/swc_plugin_change_package_import/tests/fixture/single_literal_transform/output.js b/crates/swc_change_package_import/tests/fixture/single_literal_transform/output.js similarity index 100% rename from crates/swc_plugin_change_package_import/tests/fixture/single_literal_transform/output.js rename to crates/swc_change_package_import/tests/fixture/single_literal_transform/output.js diff --git a/crates/swc_plugin_change_package_import/tests/fixture/single_specific_transform/input.js b/crates/swc_change_package_import/tests/fixture/single_specific_transform/input.js similarity index 100% rename from crates/swc_plugin_change_package_import/tests/fixture/single_specific_transform/input.js rename to crates/swc_change_package_import/tests/fixture/single_specific_transform/input.js diff --git a/crates/swc_plugin_change_package_import/tests/fixture/single_specific_transform/output.js b/crates/swc_change_package_import/tests/fixture/single_specific_transform/output.js similarity index 100% rename from crates/swc_plugin_change_package_import/tests/fixture/single_specific_transform/output.js rename to crates/swc_change_package_import/tests/fixture/single_specific_transform/output.js diff --git a/crates/swc_plugin_change_package_import/tests/fixture/single_specific_transform_2/input.js b/crates/swc_change_package_import/tests/fixture/single_specific_transform_2/input.js similarity index 100% rename from crates/swc_plugin_change_package_import/tests/fixture/single_specific_transform_2/input.js rename to crates/swc_change_package_import/tests/fixture/single_specific_transform_2/input.js diff --git a/crates/swc_plugin_change_package_import/tests/fixture/single_specific_transform_2/output.js b/crates/swc_change_package_import/tests/fixture/single_specific_transform_2/output.js similarity index 100% rename from crates/swc_plugin_change_package_import/tests/fixture/single_specific_transform_2/output.js rename to crates/swc_change_package_import/tests/fixture/single_specific_transform_2/output.js diff --git a/crates/swc_plugin_change_package_import/src/change_package_import.rs b/crates/swc_plugin_change_package_import/src/change_package_import.rs deleted file mode 100644 index 48e0bb1..0000000 --- a/crates/swc_plugin_change_package_import/src/change_package_import.rs +++ /dev/null @@ -1,207 +0,0 @@ -use crate::config::{Config, ImportType}; -use swc_core::{ - common::{ - DUMMY_SP, - util::{ - take::Take - }, - }, - ecma::{ - ast::*, - atoms::{JsWord}, - visit::{VisitMut, VisitMutWith}, - utils::{quote_str, swc_ecma_ast::ImportSpecifier}, - }, -}; - -pub struct ModuleImportVisitor { - // 用户配置 - pub options: Vec, - // 全新生成的导入声明 - new_stmts: Vec, -} - -impl ModuleImportVisitor { - pub fn new(options: Vec) -> Self { - Self { - options, - new_stmts: vec![], - } - } -} - -impl VisitMut for ModuleImportVisitor { - fn visit_mut_import_decl(&mut self, import_decl: &mut ImportDecl) { - import_decl.visit_mut_children_with(self); - - for option in &self.options { - match option { - Config::LiteralConfig(src) => { - if is_hit_rule(import_decl, option) { - for specifier in &import_decl.specifiers { - match specifier { - ImportSpecifier::Named(named_import_spec) => { - let mut import_new_src = src.clone(); - import_new_src.push_str("/"); - import_new_src.push_str(&get_import_module_name(named_import_spec)); - - self.new_stmts.push(create_default_import_decl(import_new_src, named_import_spec.local.clone())); - } - _ => () - } - } - // 清空当前导入声明,否则会被作为有效的声明添加至 new_stmts 中 - import_decl.take(); - break; - } - } - Config::SpecificConfig(config) => { - if is_hit_rule(import_decl, option) { - let target_fields: Vec<&String> = config.map.keys().clone().collect(); - let mut named_import_spec_copy = import_decl.clone(); - - // 获取未命中规则的导入声明 - named_import_spec_copy.specifiers = named_import_spec_copy.specifiers.into_iter().filter(|specifier| { - match specifier { - ImportSpecifier::Named(named_import_spec) => { - let import_object_name = get_import_module_name(named_import_spec); - !target_fields.contains(&&import_object_name) - } - _ => true - } - }).collect::>(); - - if named_import_spec_copy.specifiers.len() != 0 { - self.new_stmts.push(ModuleItem::ModuleDecl(ModuleDecl::Import(named_import_spec_copy))); - } - - for (target, rules) in config.map.iter() { - for specifier in &import_decl.specifiers { - match specifier { - ImportSpecifier::Named(named_import_spec) => { - let import_object_name = get_import_module_name(named_import_spec); - if target == &import_object_name { - let new_import_decl: ModuleItem; - if rules.import_type.is_none() || match rules.import_type.as_ref().unwrap() { - ImportType::Default => true, - _ => false - } { - // Default import mode - new_import_decl = create_default_import_decl(rules.to.to_string(), named_import_spec.local.clone()); - } else { - // Named import mode - let mut named_import_spec_copy = named_import_spec.clone(); - - if rules.name.is_some() { - named_import_spec_copy.imported = Some(ModuleExportName::Str(Str { - span: named_import_spec.span, - value: rules.name.clone().unwrap().into(), - raw: Some(rules.name.clone().unwrap().clone().into()), - })) - } - - new_import_decl = create_named_import_decl(rules.to.to_string(), vec![ImportSpecifier::Named(named_import_spec_copy)]); - } - - self.new_stmts.push(new_import_decl); - } - } - _ => () - } - } - } - import_decl.take(); - break; - } - } - } - } - - if !is_empty_decl(import_decl) { - self.new_stmts.push(wrap_with_moudle_item(import_decl.clone())); - } - } - - fn visit_mut_module_item(&mut self, n: &mut ModuleItem) { - n.visit_mut_children_with(self); - - if !n.is_module_decl() { - self.new_stmts.push(n.clone()); - } - } - - fn visit_mut_module_items(&mut self, stmts: &mut Vec) { - stmts.visit_mut_children_with(self); - - *stmts = self.new_stmts.clone(); - } -} - -fn is_hit_rule(cur_import: &ImportDecl, rule: &Config) -> bool { - match rule { - Config::LiteralConfig(s) => { - if cur_import.src.value == JsWord::from(s.clone()) { - return true; - } - false - } - Config::SpecificConfig(s) => { - if cur_import.src.value == JsWord::from(s.name.clone()) { - return true; - } - false - } - } -} - -fn is_empty_decl(decl: &ImportDecl) -> bool { - decl.specifiers.len() == 0 && decl.src.value == JsWord::from("".to_string()) -} - -fn get_import_module_name(named_import_spec: &ImportNamedSpecifier) -> String { - if named_import_spec.imported.is_none() { - (&named_import_spec.local.sym).to_string() - } else { - match &named_import_spec.imported.clone().unwrap() { - ModuleExportName::Ident(ident) => { - (&ident.sym).to_string() - } - ModuleExportName::Str(str) => { - (&str.value).to_string() - } - } - } -} - -fn create_default_import_decl(src: String, local: Ident) -> ModuleItem { - wrap_with_moudle_item( - ImportDecl { - src: Box::new(quote_str!(src)), - specifiers: vec![ImportSpecifier::Default( - ImportDefaultSpecifier { - span: DUMMY_SP, - local, - } - )], - span: DUMMY_SP, - type_only: false, - with: None, - } - ) -} - -fn create_named_import_decl(src: String, specifiers: Vec) -> ModuleItem { - wrap_with_moudle_item( - ImportDecl { - src: Box::new(quote_str!(src)), - specifiers, - span: DUMMY_SP, - type_only: false, - with: None, - } - ) -} - -fn wrap_with_moudle_item(import_decl: ImportDecl) -> ModuleItem { - ModuleItem::ModuleDecl(ModuleDecl::Import(import_decl)) -} \ No newline at end of file diff --git a/crates/swc_plugin_change_package_import/src/config.rs b/crates/swc_plugin_change_package_import/src/config.rs deleted file mode 100644 index 3f64628..0000000 --- a/crates/swc_plugin_change_package_import/src/config.rs +++ /dev/null @@ -1,62 +0,0 @@ -use std::collections::HashMap; - -#[derive(Debug)] -pub enum Config { - /// 配置: - /// ```rs - /// Config::LiteralConfig(String::from("antd")) - /// ``` - /// 效果: - /// ```js - /// import { Button } from "antd"; - /// // ---> - /// import Button from "antd/Button"; - /// ``` - LiteralConfig(String), - /// 配置: - /// ```rs - /// Config::SpecificConfig( - // SpecificConfigs { - // name: String::from("ice"), - // map: HashMap::from([ - // ( - // "a".to_string(), - // MapProperty { - // to: String::from("@ice/x/y"), - // import_type: None, - // name: None, - // } - // ), - // ]), - // } - // ), - /// ``` - /// 效果: - /// ```js - /// import { a } from "ice"; - /// // ---> - /// import a from "@ice/x/y"; - /// ``` - /// - /// 更多配置请参考[文档](https://alidocs.dingtalk.com/i/nodes/20eMKjyp810mMdK4Ho1LpqX7JxAZB1Gv?utm_scene=team_space) - SpecificConfig(SpecificConfigs), -} - -#[derive(Debug)] -pub struct SpecificConfigs { - pub name: String, - pub map: HashMap, -} - -#[derive(Debug)] -pub struct MapProperty { - pub to: String, - pub import_type: Option, - pub name: Option, -} - -#[derive(Debug, PartialEq)] -pub enum ImportType { - Named, - Default, -} diff --git a/crates/swc_plugin_change_package_import/tests/fixture.rs b/crates/swc_plugin_change_package_import/tests/fixture.rs deleted file mode 100644 index 734a934..0000000 --- a/crates/swc_plugin_change_package_import/tests/fixture.rs +++ /dev/null @@ -1,442 +0,0 @@ -use std::path::PathBuf; -use std::collections::HashMap; -use swc_core::ecma::{ - visit::as_folder, - transforms::testing::{FixtureTestConfig, test_fixture}, -}; -use swc_plugin_change_package_import::{ - ModuleImportVisitor, - Config, - SpecificConfigs, - MapProperty, - ImportType, -}; - -#[testing::fixture("tests/fixture/single_literal_transform/input.js")] -fn test_single_literal_transform(input: PathBuf) { - let output = input.with_file_name("output.js"); - test_fixture( - Default::default(), - &|_t| { - as_folder(ModuleImportVisitor::new(vec![Config::LiteralConfig(String::from("y"))])) - }, - &input, - &output, - FixtureTestConfig { - ..Default::default() - }, - ); -} - -#[testing::fixture("tests/fixture/multi_literal_transform/input.js")] -fn test_multi_literal_transform(input: PathBuf) { - let output = input.with_file_name("output.js"); - test_fixture( - Default::default(), - &|_t| { - as_folder(ModuleImportVisitor::new(vec![ - Config::LiteralConfig(String::from("z")), - Config::LiteralConfig(String::from("o")), - ])) - }, - &input, - &output, - FixtureTestConfig { - ..Default::default() - }, - ); -} - -#[testing::fixture("tests/fixture/single_specific_transform/input.js")] - -fn test_single_specific_transform(input: PathBuf) { - let output = input.with_file_name("output.js"); - test_fixture( - Default::default(), - &|_t| { - as_folder(ModuleImportVisitor::new(vec![ - Config::SpecificConfig( - SpecificConfigs { - name: String::from("y"), - map: HashMap::from([ - ( - "x".to_string(), - MapProperty { - to: String::from("m/n"), - import_type: Some(ImportType::Named), - name: Some(String::from("a")), - } - ), - ]), - } - ), - ])) - }, - &input, - &output, - FixtureTestConfig { - ..Default::default() - }, - ); -} - -#[testing::fixture("tests/fixture/single_specific_transform_2/input.js")] -fn test_single_specific_transform_2(input: PathBuf) { - let output = input.with_file_name("output.js"); - test_fixture( - Default::default(), - &|_t| { - as_folder(ModuleImportVisitor::new(vec![ - Config::SpecificConfig( - SpecificConfigs { - name: String::from("y"), - map: HashMap::from([ - ( - "x".to_string(), - MapProperty { - to: String::from("m/n"), - import_type: Some(ImportType::Named), - name: Some(String::from("a")), - } - ), - ]), - } - ), - ])) - }, - &input, - &output, - FixtureTestConfig { - ..Default::default() - }, - ); -} - -#[testing::fixture("tests/fixture/mix_specific_transform/input.js")] -fn test_mix_specific_transform(input: PathBuf) { - let output = input.with_file_name("output.js"); - test_fixture( - Default::default(), - &|_t| { - as_folder(ModuleImportVisitor::new(vec![ - Config::LiteralConfig(String::from("antd")), - Config::SpecificConfig( - SpecificConfigs { - name: String::from("ice"), - map: HashMap::from([ - ( - "a".to_string(), - MapProperty { - to: String::from("@ice/x/y"), - import_type: None, - name: None, - } - ), - ]), - } - ), - ])) - }, - &input, - &output, - FixtureTestConfig { - ..Default::default() - }, - ); -} - - -#[testing::fixture("tests/fixture/multi_specific_transform/input.js")] -fn test_multi_specific_transform(input: PathBuf) { - let output = input.with_file_name("output.js"); - test_fixture( - Default::default(), - &|_t| { - as_folder(ModuleImportVisitor::new(vec![ - Config::SpecificConfig( - SpecificConfigs { - name: String::from("e"), - map: HashMap::from([ - ( - "a".to_string(), - MapProperty { - to: String::from("@e/x"), - import_type: Some(ImportType::Default), - name: None, - } - ), - ( - "b".to_string(), - MapProperty { - to: String::from("e"), - import_type: Some(ImportType::Named), - name: None, - } - ) - ]), - }, - ), - Config::SpecificConfig( - SpecificConfigs { - name: String::from("k"), - map: HashMap::from([ - ( - "j".to_string(), - MapProperty { - to: String::from("@e/k"), - import_type: Some(ImportType::Named), - name: Some(String::from("jj")), - } - ), - ]), - }, - ), - ])) - }, - &input, - &output, - FixtureTestConfig { - ..Default::default() - }, - ); -} - -#[testing::fixture("tests/fixture/ice_basic_transform/input.js")] -fn test_ice_basic_transform(input: PathBuf) { - let output = input.with_file_name("output.js"); - test_fixture( - Default::default(), - &|_t| { - as_folder(ModuleImportVisitor::new(vec![ - Config::SpecificConfig( - SpecificConfigs { - name: String::from("ice"), - map: HashMap::from([ - ( - "runApp".to_string(), - MapProperty { - to: String::from("@ice/runtime"), - import_type: Some(ImportType::Named), - name: None, - } - ), - ]), - } - ), - ])) - }, - &input, - &output, - FixtureTestConfig { - ..Default::default() - }, - ); -} - -#[testing::fixture("tests/fixture/ice_as_transform/input.js")] -fn test_ice_as_transform(input: PathBuf) { - let output = input.with_file_name("output.js"); - test_fixture( - Default::default(), - &|_t| { - as_folder(ModuleImportVisitor::new(vec![ - Config::SpecificConfig( - SpecificConfigs { - name: String::from("ice"), - map: HashMap::from([ - ( - "runApp".to_string(), - MapProperty { - to: String::from("@ice/runtime"), - import_type: Some(ImportType::Named), - name: None, - } - ), - ]), - } - ), - ])) - }, - &input, - &output, - FixtureTestConfig { - ..Default::default() - }, - ); -} - -#[testing::fixture("tests/fixture/ice_alias_transform/input.js")] -fn test_ice_alias_transform(input: PathBuf) { - let output = input.with_file_name("output.js"); - test_fixture( - Default::default(), - &|_t| { - as_folder(ModuleImportVisitor::new(vec![ - Config::SpecificConfig( - SpecificConfigs { - name: String::from("ice"), - map: HashMap::from([ - ( - "Head".to_string(), - MapProperty { - to: String::from("react-helmet"), - import_type: Some(ImportType::Default), - name: Some("Helmet".to_string()), - } - ), - ]), - } - ), - ])) - }, - &input, - &output, - FixtureTestConfig { - ..Default::default() - }, - ); -} - -#[testing::fixture("tests/fixture/ice_alias_with_as_transform/input.js")] -fn test_ice_alias_with_as_transform(input: PathBuf) { - let output = input.with_file_name("output.js"); - test_fixture( - Default::default(), - &|_t| { - as_folder(ModuleImportVisitor::new(vec![ - Config::SpecificConfig( - SpecificConfigs { - name: String::from("ice"), - map: HashMap::from([ - ( - "Head".to_string(), - MapProperty { - to: String::from("react-helmet"), - import_type: Some(ImportType::Default), - name: None, - } - ), - ]), - } - ), - ])) - }, - &input, - &output, - FixtureTestConfig { - ..Default::default() - }, - ); -} - -#[testing::fixture("tests/fixture/ice_multiple_transform/input.js")] -fn test_ice_multiple_transform(input: PathBuf) { - let output = input.with_file_name("output.js"); - test_fixture( - Default::default(), - &|_t| { - as_folder(ModuleImportVisitor::new(vec![ - Config::SpecificConfig( - SpecificConfigs { - name: String::from("ice"), - map: HashMap::from([ - ( - "request".to_string(), - MapProperty { - to: String::from("axios"), - import_type: Some(ImportType::Named), - name: None, - } - ), - ( - "test".to_string(), - MapProperty { - to: String::from("axios"), - import_type: Some(ImportType::Named), - name: None, - } - ), - ( - "store".to_string(), - MapProperty { - to: String::from("@ice/store"), - import_type: Some(ImportType::Default), - name: None, - } - ) - ]), - } - ), - ])) - }, - &input, - &output, - FixtureTestConfig { - ..Default::default() - }, - ); -} - -#[testing::fixture("tests/fixture/ice_matched_transform/input.js")] -fn test_ice_matched_transform(input: PathBuf) { - let output = input.with_file_name("output.js"); - test_fixture( - Default::default(), - &|_t| { - as_folder(ModuleImportVisitor::new(vec![ - Config::SpecificConfig( - SpecificConfigs { - name: String::from("ice"), - map: HashMap::from([ - ( - "runApp".to_string(), - MapProperty { - to: String::from("@ice/runtime"), - import_type: Some(ImportType::Named), - name: None, - } - ), - ]), - } - ), - ])) - }, - &input, - &output, - FixtureTestConfig { - ..Default::default() - }, - ); -} - -#[testing::fixture("tests/fixture/ice_miss_match_transform/input.js")] -fn test_ice_miss_match_transform(input: PathBuf) { - let output = input.with_file_name("output.js"); - test_fixture( - Default::default(), - &|_t| { - as_folder(ModuleImportVisitor::new(vec![ - Config::SpecificConfig( - SpecificConfigs { - name: String::from("ice"), - map: HashMap::from([ - ( - "runApp".to_string(), - MapProperty { - to: String::from("@ice/runtime"), - import_type: Some(ImportType::Named), - name: None, - } - ), - ]), - } - ), - ])) - }, - &input, - &output, - FixtureTestConfig { - ..Default::default() - }, - ); -} \ No newline at end of file diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 51177fb..8a00cf7 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -2,4 +2,4 @@ profile = "default" # Use nightly for better access to the latest Rust features. # This date is aligned to stable release dates. -channel = "nightly-2023-10-24" +channel = "nightly-2023-12-28" # v1.75.0