From 7a31039d3cfcde6005e3c059017db884d8e90a67 Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Thu, 23 Nov 2023 15:03:15 +0800 Subject: [PATCH] feat: update latest rspack version --- .github/actions/clone-crates/action.yml | 2 +- Cargo.lock | 648 ++++++++++++++---- Cargo.toml | 81 +-- crates/binding_options/Cargo.toml | 5 +- .../binding_options/src/options/js_loader.rs | 28 +- crates/binding_options/src/options/mod.rs | 30 +- .../src/options/raw_features.rs | 9 +- .../binding_options/src/options/raw_module.rs | 6 - .../src/options/raw_optimization.rs | 82 +++ crates/node_binding/Cargo.toml | 1 + crates/node_binding/index.d.ts | 8 + crates/node_binding/src/js_values/asset.rs | 106 --- .../node_binding/src/js_values/chunk_group.rs | 27 - .../node_binding/src/js_values/compilation.rs | 434 ------------ crates/node_binding/src/js_values/hooks.rs | 42 -- crates/node_binding/src/js_values/mod.rs | 25 - crates/node_binding/src/js_values/module.rs | 37 - .../src/js_values/normal_module_factory.rs | 105 --- .../node_binding/src/js_values/path_data.rs | 42 -- crates/node_binding/src/js_values/source.rs | 198 ------ crates/node_binding/src/js_values/stats.rs | 561 --------------- crates/node_binding/src/lib.rs | 18 +- crates/node_binding/src/loader.rs | 3 +- crates/node_binding/src/plugins/mod.rs | 17 +- crates/node_binding/src/utils.rs | 203 ------ rust-toolchain.toml | 4 +- 26 files changed, 721 insertions(+), 2001 deletions(-) create mode 100644 crates/binding_options/src/options/raw_optimization.rs delete mode 100644 crates/node_binding/src/js_values/asset.rs delete mode 100644 crates/node_binding/src/js_values/chunk_group.rs delete mode 100644 crates/node_binding/src/js_values/compilation.rs delete mode 100644 crates/node_binding/src/js_values/hooks.rs delete mode 100644 crates/node_binding/src/js_values/mod.rs delete mode 100644 crates/node_binding/src/js_values/module.rs delete mode 100644 crates/node_binding/src/js_values/normal_module_factory.rs delete mode 100644 crates/node_binding/src/js_values/path_data.rs delete mode 100644 crates/node_binding/src/js_values/source.rs delete mode 100644 crates/node_binding/src/js_values/stats.rs delete mode 100644 crates/node_binding/src/utils.rs diff --git a/.github/actions/clone-crates/action.yml b/.github/actions/clone-crates/action.yml index b8e89dc..c9dc12d 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.3.6' + default: 'v0.4.0' required: false type: string temp: diff --git a/Cargo.lock b/Cargo.lock index cfb8e97..e00f98a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -137,7 +137,7 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "ast_node" version = "0.9.5" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "pmutil", "proc-macro2", @@ -265,7 +265,7 @@ dependencies = [ [[package]] name = "better_scoped_tls" version = "0.1.1" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "scoped-tls", ] @@ -286,12 +286,12 @@ dependencies = [ "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", @@ -310,6 +310,7 @@ dependencies = [ "rspack_plugin_javascript", "rspack_plugin_json", "rspack_plugin_library", + "rspack_plugin_limit_chunk_count", "rspack_plugin_progress", "rspack_plugin_real_content_hash", "rspack_plugin_remove_empty_chunks", @@ -319,7 +320,9 @@ dependencies = [ "rspack_plugin_split_chunks_new", "rspack_plugin_swc_css_minimizer", "rspack_plugin_swc_js_minimizer", + "rspack_plugin_warn_sensitive_module", "rspack_plugin_wasm", + "rspack_plugin_web_worker_template", "rspack_plugin_worker", "rspack_regex", "rspack_swc_visitors", @@ -906,7 +909,7 @@ dependencies = [ [[package]] name = "from_variant" version = "0.1.6" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "pmutil", "proc-macro2", @@ -1337,6 +1340,15 @@ dependencies = [ "serde_json", ] +[[package]] +name = "jsonc-parser" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "538702ed54bac04d391352d4c9ad0ec2a9225e3c477ffa23fc44d0f04fa83c54" +dependencies = [ + "serde_json", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -1698,6 +1710,7 @@ dependencies = [ "once_cell", "rspack_binding_macros", "rspack_binding_options", + "rspack_binding_values", "rspack_core", "rspack_error", "rspack_fs_node", @@ -1720,7 +1733,7 @@ dependencies = [ "dashmap", "dunce", "indexmap 1.9.3", - "jsonc-parser", + "jsonc-parser 0.21.1", "once_cell", "path-absolutize", "rustc-hash", @@ -1847,9 +1860,9 @@ checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" [[package]] name = "oxc_resolver" -version = "0.2.0" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9657cba6ac0894a8acf3aca5b9a4b7668ce8486042588cf2bf0f34eb5f37ebc6" +checksum = "1d10d078b6ba0b8cfa0eb634ef749698aa82ef4a86c7ba1446453644ccf13fd2" dependencies = [ "dashmap", "dunce", @@ -1860,7 +1873,6 @@ dependencies = [ "serde_json", "thiserror", "tracing", - "tracing-subscriber", ] [[package]] @@ -1932,6 +1944,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ecba01bf2678719532c5e3059e0b5f0811273d94b397088b82e3bd0a78c78fdd" +[[package]] +name = "path-clean" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17359afc20d7ab31fdb42bb844c8b3bb1dabd7dcf7e68428492da7f16966fcef" + [[package]] name = "path-dedot" version = "3.1.1" @@ -2119,9 +2137,12 @@ name = "plugin_manifest" version = "0.1.0" dependencies = [ "async-trait", + "regex", "rspack_core", "rspack_error", "rspack_testing", + "serde", + "serde_json", "tracing", ] @@ -2173,8 +2194,8 @@ checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" [[package]] name = "preset_env_base" -version = "0.4.5" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.4.6" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "ahash 0.8.6", "anyhow", @@ -2515,6 +2536,18 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "rspack_ast" +version = "0.1.0" +dependencies = [ + "anyhow", + "rspack_error", + "swc_core", + "swc_error_reporters", + "swc_node_comments", + "tokio", +] + [[package]] name = "rspack_ast_viewer" version = "0.1.0" @@ -2551,6 +2584,70 @@ dependencies = [ "napi", "napi-derive", "rspack_binding_macros", + "rspack_binding_values", + "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_limit_chunk_count", + "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_warn_sensitive_module", + "rspack_plugin_wasm", + "rspack_plugin_web_worker_template", + "rspack_plugin_worker", + "rspack_regex", + "rspack_swc_visitors", + "rustc-hash", + "serde", + "serde_json", + "swc_config", + "swc_core", + "tokio", + "tracing", +] + +[[package]] +name = "rspack_binding_values" +version = "0.1.0" +dependencies = [ + "anyhow", + "async-trait", + "better_scoped_tls 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "dashmap", + "derivative", + "futures", + "glob", + "napi", + "napi-derive", + "napi-sys", + "rspack_binding_macros", "rspack_core", "rspack_error", "rspack_identifier", @@ -2607,6 +2704,7 @@ dependencies = [ "dashmap", "derivative", "dyn-clone", + "either", "futures", "glob-match", "hashlink", @@ -2621,6 +2719,7 @@ dependencies = [ "rayon", "regex", "rkyv", + "rspack_ast", "rspack_database", "rspack_error", "rspack_fs", @@ -2669,9 +2768,11 @@ dependencies = [ "rspack_binding_options", "rspack_core", "rspack_fs", + "rspack_sources", "rspack_testing", "rspack_tracing", "rspack_util", + "serde_json", "sugar_path", "swc_core", "termcolor", @@ -2754,6 +2855,7 @@ dependencies = [ name = "rspack_loader_runner" version = "0.1.0" dependencies = [ + "anymap", "async-recursion", "async-trait", "bitflags 1.3.2", @@ -2794,11 +2896,16 @@ version = "0.1.0" dependencies = [ "anyhow", "async-trait", + "dashmap", "either", "indexmap 1.9.3", + "jsonc-parser 0.22.1", + "once_cell", + "rspack_ast", "rspack_core", "rspack_error", "rspack_loader_runner", + "rspack_plugin_javascript", "rspack_swc_visitors", "rspack_testing", "serde", @@ -2835,6 +2942,7 @@ dependencies = [ "once_cell", "rspack_binding_macros", "rspack_binding_options", + "rspack_binding_values", "rspack_core", "rspack_error", "rspack_fs_node", @@ -2895,6 +3003,7 @@ dependencies = [ "rspack_futures", "rspack_hash", "rspack_testing", + "rustc-hash", "sugar_path", "testing_macros", "tokio", @@ -3010,6 +3119,7 @@ dependencies = [ "async-trait", "dojang", "itertools", + "path-clean 1.0.1", "rayon", "regex", "rspack_base64", @@ -3040,6 +3150,7 @@ dependencies = [ "preset_env_base", "rayon", "regex", + "rspack_ast", "rspack_core", "rspack_error", "rspack_hash", @@ -3082,6 +3193,16 @@ dependencies = [ "serde_json", ] +[[package]] +name = "rspack_plugin_limit_chunk_count" +version = "0.1.0" +dependencies = [ + "async-trait", + "rspack_core", + "rspack_database", + "rspack_util", +] + [[package]] name = "rspack_plugin_progress" version = "0.1.0" @@ -3122,6 +3243,7 @@ dependencies = [ "anyhow", "async-trait", "itertools", + "once_cell", "rayon", "rspack_core", "rspack_error", @@ -3168,6 +3290,7 @@ dependencies = [ "dashmap", "derivative", "futures-util", + "num-bigint", "rayon", "rspack_core", "rspack_identifier", @@ -3194,6 +3317,7 @@ version = "0.1.0" dependencies = [ "async-recursion", "async-trait", + "once_cell", "rayon", "regex", "rspack_core", @@ -3201,11 +3325,21 @@ dependencies = [ "rspack_plugin_javascript", "rspack_regex", "rspack_util", + "serde_json", "swc_config", "swc_core", "swc_ecma_minifier", ] +[[package]] +name = "rspack_plugin_warn_sensitive_module" +version = "0.1.0" +dependencies = [ + "dashmap", + "rspack_core", + "rspack_error", +] + [[package]] name = "rspack_plugin_wasm" version = "0.1.0" @@ -3224,6 +3358,15 @@ dependencies = [ "wasmparser", ] +[[package]] +name = "rspack_plugin_web_worker_template" +version = "0.1.0" +dependencies = [ + "async-trait", + "rspack_core", + "rspack_plugin_runtime", +] + [[package]] name = "rspack_plugin_worker" version = "0.1.0" @@ -3270,6 +3413,7 @@ dependencies = [ "once_cell", "regex", "serde", + "styled_components", "swc_core", "swc_emotion", "swc_plugin_import", @@ -3304,6 +3448,7 @@ dependencies = [ "rspack_plugin_library", "rspack_plugin_remove_empty_chunks", "rspack_plugin_runtime", + "rspack_plugin_warn_sensitive_module", "rspack_plugin_wasm", "rspack_regex", "rspack_tracing", @@ -3382,9 +3527,9 @@ checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" [[package]] name = "ryu-js" -version = "0.2.2" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6518fc26bced4d53678a22d6e423e9d8716377def84545fe328236e3af070e7f" +checksum = "4950d85bc52415f8432144c97c4791bd0c4f7954de32a7270ee9cccd3c22b12b" [[package]] name = "same-file" @@ -3746,7 +3891,7 @@ dependencies = [ [[package]] name = "string_enum" version = "0.4.1" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "pmutil", "proc-macro2", @@ -3761,6 +3906,24 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "styled_components" +version = "0.77.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2efe2ad3cd5fe8868b2fa9d7b2619110313c19c3c304733651cd90d11b6e201a" +dependencies = [ + "Inflector", + "once_cell", + "regex", + "serde", + "swc_atoms", + "swc_common", + "swc_ecma_ast", + "swc_ecma_utils", + "swc_ecma_visit", + "tracing", +] + [[package]] name = "substring" version = "1.4.5" @@ -3809,15 +3972,15 @@ dependencies = [ [[package]] name = "swc" -version = "0.266.0" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.269.31" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "anyhow", "base64", "dashmap", "either", "indexmap 1.9.3", - "jsonc-parser", + "jsonc-parser 0.21.1", "lru", "once_cell", "parking_lot 0.12.1", @@ -3830,6 +3993,7 @@ dependencies = [ "swc_atoms", "swc_cached", "swc_common", + "swc_compiler_base", "swc_config", "swc_ecma_ast", "swc_ecma_codegen", @@ -3855,8 +4019,8 @@ dependencies = [ [[package]] name = "swc_atoms" -version = "0.5.9" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.6.0" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "once_cell", "rustc-hash", @@ -3868,8 +4032,8 @@ dependencies = [ [[package]] name = "swc_cached" -version = "0.3.17" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.3.18" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "ahash 0.8.6", "anyhow", @@ -3881,13 +4045,13 @@ dependencies = [ [[package]] name = "swc_common" -version = "0.32.1" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.33.2" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "ahash 0.8.6", "ast_node", "atty", - "better_scoped_tls 0.1.1 (git+https://github.com/swc-project/swc.git?rev=5c00525)", + "better_scoped_tls 0.1.1 (git+https://github.com/swc-project/swc.git?rev=1095bff)", "cfg-if", "either", "from_variant", @@ -3909,10 +4073,31 @@ dependencies = [ "url", ] +[[package]] +name = "swc_compiler_base" +version = "0.3.30" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +dependencies = [ + "anyhow", + "base64", + "pathdiff", + "serde", + "sourcemap", + "swc_atoms", + "swc_common", + "swc_config", + "swc_ecma_ast", + "swc_ecma_codegen", + "swc_ecma_minifier", + "swc_ecma_parser", + "swc_ecma_visit", + "swc_timer", +] + [[package]] name = "swc_config" version = "0.1.7" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "indexmap 1.9.3", "serde", @@ -3923,7 +4108,7 @@ dependencies = [ [[package]] name = "swc_config_macro" version = "0.1.2" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "pmutil", "proc-macro2", @@ -3934,8 +4119,8 @@ dependencies = [ [[package]] name = "swc_core" -version = "0.83.1" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.86.33" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "swc", "swc_atoms", @@ -3963,14 +4148,13 @@ dependencies = [ "swc_ecma_transforms_typescript", "swc_ecma_utils", "swc_ecma_visit", - "swc_trace_macro", "vergen", ] [[package]] name = "swc_css_ast" -version = "0.139.1" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.140.3" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "is-macro", "string_enum", @@ -3980,8 +4164,8 @@ dependencies = [ [[package]] name = "swc_css_codegen" -version = "0.149.1" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.151.5" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "auto_impl", "bitflags 2.4.1", @@ -3997,7 +4181,7 @@ dependencies = [ [[package]] name = "swc_css_codegen_macros" version = "0.2.2" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "pmutil", "proc-macro2", @@ -4008,8 +4192,8 @@ dependencies = [ [[package]] name = "swc_css_compat" -version = "0.25.1" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.27.5" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "bitflags 2.4.1", "once_cell", @@ -4024,8 +4208,8 @@ dependencies = [ [[package]] name = "swc_css_minifier" -version = "0.114.1" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.116.5" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "serde", "swc_atoms", @@ -4037,8 +4221,8 @@ dependencies = [ [[package]] name = "swc_css_modules" -version = "0.27.2" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.29.5" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "rustc-hash", "serde", @@ -4052,8 +4236,8 @@ dependencies = [ [[package]] name = "swc_css_parser" -version = "0.148.1" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.150.5" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "lexical", "serde", @@ -4064,8 +4248,8 @@ dependencies = [ [[package]] name = "swc_css_prefixer" -version = "0.151.1" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.153.6" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "once_cell", "preset_env_base", @@ -4080,8 +4264,8 @@ dependencies = [ [[package]] name = "swc_css_utils" -version = "0.136.1" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.137.3" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "once_cell", "serde", @@ -4094,8 +4278,8 @@ dependencies = [ [[package]] name = "swc_css_visit" -version = "0.138.1" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.139.3" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "serde", "swc_atoms", @@ -4106,8 +4290,8 @@ dependencies = [ [[package]] name = "swc_ecma_ast" -version = "0.109.1" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.110.2" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "bitflags 2.4.1", "is-macro", @@ -4122,8 +4306,8 @@ dependencies = [ [[package]] name = "swc_ecma_codegen" -version = "0.145.0" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.146.9" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "memchr", "num-bigint", @@ -4141,7 +4325,7 @@ dependencies = [ [[package]] name = "swc_ecma_codegen_macros" version = "0.7.3" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "pmutil", "proc-macro2", @@ -4150,10 +4334,193 @@ dependencies = [ "syn 2.0.39", ] +[[package]] +name = "swc_ecma_compat_bugfixes" +version = "0.1.17" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +dependencies = [ + "swc_atoms", + "swc_common", + "swc_ecma_ast", + "swc_ecma_compat_es2015", + "swc_ecma_transforms_base", + "swc_ecma_utils", + "swc_ecma_visit", + "swc_trace_macro 0.1.3 (git+https://github.com/swc-project/swc.git?rev=1095bff)", + "tracing", +] + +[[package]] +name = "swc_ecma_compat_common" +version = "0.1.11" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +dependencies = [ + "swc_common", + "swc_ecma_ast", + "swc_ecma_utils", + "swc_ecma_visit", + "swc_trace_macro 0.1.3 (git+https://github.com/swc-project/swc.git?rev=1095bff)", +] + +[[package]] +name = "swc_ecma_compat_es2015" +version = "0.1.17" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +dependencies = [ + "arrayvec", + "indexmap 1.9.3", + "is-macro", + "serde", + "serde_derive", + "smallvec", + "swc_atoms", + "swc_common", + "swc_config", + "swc_ecma_ast", + "swc_ecma_compat_common", + "swc_ecma_transforms_base", + "swc_ecma_transforms_classes", + "swc_ecma_transforms_macros", + "swc_ecma_utils", + "swc_ecma_visit", + "swc_trace_macro 0.1.3 (git+https://github.com/swc-project/swc.git?rev=1095bff)", + "tracing", +] + +[[package]] +name = "swc_ecma_compat_es2016" +version = "0.1.15" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +dependencies = [ + "swc_atoms", + "swc_common", + "swc_ecma_ast", + "swc_ecma_transforms_base", + "swc_ecma_transforms_macros", + "swc_ecma_utils", + "swc_ecma_visit", + "swc_trace_macro 0.1.3 (git+https://github.com/swc-project/swc.git?rev=1095bff)", + "tracing", +] + +[[package]] +name = "swc_ecma_compat_es2017" +version = "0.1.15" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +dependencies = [ + "serde", + "swc_atoms", + "swc_common", + "swc_ecma_ast", + "swc_ecma_transforms_base", + "swc_ecma_transforms_macros", + "swc_ecma_utils", + "swc_ecma_visit", + "swc_trace_macro 0.1.3 (git+https://github.com/swc-project/swc.git?rev=1095bff)", + "tracing", +] + +[[package]] +name = "swc_ecma_compat_es2018" +version = "0.1.15" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +dependencies = [ + "serde", + "swc_atoms", + "swc_common", + "swc_ecma_ast", + "swc_ecma_compat_common", + "swc_ecma_transforms_base", + "swc_ecma_transforms_macros", + "swc_ecma_utils", + "swc_ecma_visit", + "swc_trace_macro 0.1.3 (git+https://github.com/swc-project/swc.git?rev=1095bff)", + "tracing", +] + +[[package]] +name = "swc_ecma_compat_es2019" +version = "0.1.15" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +dependencies = [ + "swc_atoms", + "swc_common", + "swc_ecma_ast", + "swc_ecma_transforms_base", + "swc_ecma_utils", + "swc_ecma_visit", + "swc_trace_macro 0.1.3 (git+https://github.com/swc-project/swc.git?rev=1095bff)", + "tracing", +] + +[[package]] +name = "swc_ecma_compat_es2020" +version = "0.1.15" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +dependencies = [ + "serde", + "swc_atoms", + "swc_common", + "swc_ecma_ast", + "swc_ecma_compat_es2022", + "swc_ecma_transforms_base", + "swc_ecma_utils", + "swc_ecma_visit", + "swc_trace_macro 0.1.3 (git+https://github.com/swc-project/swc.git?rev=1095bff)", + "tracing", +] + +[[package]] +name = "swc_ecma_compat_es2021" +version = "0.1.14" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +dependencies = [ + "swc_atoms", + "swc_common", + "swc_ecma_ast", + "swc_ecma_transforms_base", + "swc_ecma_utils", + "swc_ecma_visit", + "swc_trace_macro 0.1.3 (git+https://github.com/swc-project/swc.git?rev=1095bff)", + "tracing", +] + +[[package]] +name = "swc_ecma_compat_es2022" +version = "0.1.15" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +dependencies = [ + "swc_atoms", + "swc_common", + "swc_ecma_ast", + "swc_ecma_compat_common", + "swc_ecma_transforms_base", + "swc_ecma_transforms_classes", + "swc_ecma_transforms_macros", + "swc_ecma_utils", + "swc_ecma_visit", + "swc_trace_macro 0.1.3 (git+https://github.com/swc-project/swc.git?rev=1095bff)", + "tracing", +] + +[[package]] +name = "swc_ecma_compat_es3" +version = "0.1.15" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +dependencies = [ + "swc_common", + "swc_ecma_ast", + "swc_ecma_transforms_base", + "swc_ecma_utils", + "swc_ecma_visit", + "swc_trace_macro 0.1.3 (git+https://github.com/swc-project/swc.git?rev=1095bff)", + "tracing", +] + [[package]] name = "swc_ecma_ext_transforms" -version = "0.109.0" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.110.13" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "phf", "swc_atoms", @@ -4165,8 +4532,8 @@ dependencies = [ [[package]] name = "swc_ecma_lints" -version = "0.88.0" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.89.16" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "auto_impl", "dashmap", @@ -4184,8 +4551,8 @@ dependencies = [ [[package]] name = "swc_ecma_loader" -version = "0.44.3" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.45.3" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "anyhow", "dashmap", @@ -4193,7 +4560,7 @@ dependencies = [ "normpath", "once_cell", "parking_lot 0.12.1", - "path-clean", + "path-clean 0.1.0", "pathdiff", "serde", "serde_json", @@ -4204,8 +4571,8 @@ dependencies = [ [[package]] name = "swc_ecma_minifier" -version = "0.187.0" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.189.28" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "arrayvec", "indexmap 1.9.3", @@ -4238,8 +4605,8 @@ dependencies = [ [[package]] name = "swc_ecma_parser" -version = "0.140.0" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.141.8" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "either", "num-bigint", @@ -4257,8 +4624,8 @@ dependencies = [ [[package]] name = "swc_ecma_preset_env" -version = "0.201.0" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.203.23" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "anyhow", "dashmap", @@ -4281,8 +4648,8 @@ dependencies = [ [[package]] name = "swc_ecma_quote_macros" -version = "0.51.0" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.52.8" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "anyhow", "pmutil", @@ -4298,8 +4665,8 @@ dependencies = [ [[package]] name = "swc_ecma_transforms" -version = "0.224.0" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.226.22" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "swc_atoms", "swc_common", @@ -4317,10 +4684,10 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_base" -version = "0.133.0" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.134.16" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ - "better_scoped_tls 0.1.1 (git+https://github.com/swc-project/swc.git?rev=5c00525)", + "better_scoped_tls 0.1.1 (git+https://github.com/swc-project/swc.git?rev=1095bff)", "bitflags 2.4.1", "indexmap 1.9.3", "once_cell", @@ -4340,8 +4707,8 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_classes" -version = "0.122.0" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.123.16" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "swc_atoms", "swc_common", @@ -4353,8 +4720,8 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_compat" -version = "0.159.0" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.160.21" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "arrayvec", "indexmap 1.9.3", @@ -4366,19 +4733,30 @@ dependencies = [ "swc_common", "swc_config", "swc_ecma_ast", + "swc_ecma_compat_bugfixes", + "swc_ecma_compat_common", + "swc_ecma_compat_es2015", + "swc_ecma_compat_es2016", + "swc_ecma_compat_es2017", + "swc_ecma_compat_es2018", + "swc_ecma_compat_es2019", + "swc_ecma_compat_es2020", + "swc_ecma_compat_es2021", + "swc_ecma_compat_es2022", + "swc_ecma_compat_es3", "swc_ecma_transforms_base", "swc_ecma_transforms_classes", "swc_ecma_transforms_macros", "swc_ecma_utils", "swc_ecma_visit", - "swc_trace_macro", + "swc_trace_macro 0.1.3 (git+https://github.com/swc-project/swc.git?rev=1095bff)", "tracing", ] [[package]] name = "swc_ecma_transforms_macros" version = "0.5.3" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "pmutil", "proc-macro2", @@ -4389,15 +4767,15 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_module" -version = "0.176.0" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.177.23" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "Inflector", "anyhow", "bitflags 2.4.1", "indexmap 1.9.3", "is-macro", - "path-clean", + "path-clean 0.1.0", "pathdiff", "regex", "serde", @@ -4415,8 +4793,8 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_optimization" -version = "0.193.0" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.195.23" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "dashmap", "indexmap 1.9.3", @@ -4439,8 +4817,8 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_proposal" -version = "0.167.0" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.168.24" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "either", "rustc-hash", @@ -4458,8 +4836,8 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_react" -version = "0.179.0" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.180.24" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "base64", "dashmap", @@ -4481,9 +4859,10 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_typescript" -version = "0.183.0" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.185.22" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ + "ryu-js", "serde", "swc_atoms", "swc_common", @@ -4496,8 +4875,8 @@ dependencies = [ [[package]] name = "swc_ecma_usage_analyzer" -version = "0.19.0" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.20.14" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "indexmap 1.9.3", "rustc-hash", @@ -4512,8 +4891,8 @@ dependencies = [ [[package]] name = "swc_ecma_utils" -version = "0.123.0" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.124.13" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "indexmap 1.9.3", "num_cpus", @@ -4530,8 +4909,8 @@ dependencies = [ [[package]] name = "swc_ecma_visit" -version = "0.95.1" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.96.2" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "num-bigint", "swc_atoms", @@ -4543,9 +4922,9 @@ dependencies = [ [[package]] name = "swc_emotion" -version = "0.42.0" +version = "0.58.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13abda43ddbc94149aca923fb331f13b90e70f7cc2fb54662ee4a2c51cb59b22" +checksum = "d123bc6ff6aff8724f43542964ee726801fc205137bbf0de7f822a2f8b15f204" dependencies = [ "base64", "byteorder", @@ -4555,14 +4934,20 @@ dependencies = [ "regex", "serde", "sourcemap", - "swc_core", + "swc_atoms", + "swc_common", + "swc_ecma_ast", + "swc_ecma_codegen", + "swc_ecma_utils", + "swc_ecma_visit", + "swc_trace_macro 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "tracing", ] [[package]] name = "swc_eq_ignore_macros" version = "0.1.2" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "pmutil", "proc-macro2", @@ -4572,8 +4957,8 @@ dependencies = [ [[package]] name = "swc_error_reporters" -version = "0.16.1" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.17.2" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "anyhow", "miette", @@ -4584,8 +4969,8 @@ dependencies = [ [[package]] name = "swc_fast_graph" -version = "0.20.1" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.21.2" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "indexmap 1.9.3", "petgraph", @@ -4595,8 +4980,8 @@ dependencies = [ [[package]] name = "swc_html" -version = "0.131.0" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.134.29" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "swc_html_ast", "swc_html_codegen", @@ -4606,8 +4991,8 @@ dependencies = [ [[package]] name = "swc_html_ast" -version = "0.32.1" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.33.2" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "is-macro", "string_enum", @@ -4617,8 +5002,8 @@ dependencies = [ [[package]] name = "swc_html_codegen" -version = "0.41.1" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.42.4" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "auto_impl", "bitflags 2.4.1", @@ -4633,7 +5018,7 @@ dependencies = [ [[package]] name = "swc_html_codegen_macros" version = "0.2.2" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "pmutil", "proc-macro2", @@ -4644,8 +5029,8 @@ dependencies = [ [[package]] name = "swc_html_minifier" -version = "0.128.0" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.131.29" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "once_cell", "serde", @@ -4672,8 +5057,8 @@ dependencies = [ [[package]] name = "swc_html_parser" -version = "0.38.1" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.39.4" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "swc_atoms", "swc_common", @@ -4683,8 +5068,8 @@ dependencies = [ [[package]] name = "swc_html_utils" -version = "0.17.1" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.18.2" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "once_cell", "serde", @@ -4695,8 +5080,8 @@ dependencies = [ [[package]] name = "swc_html_visit" -version = "0.32.1" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.33.2" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "serde", "swc_atoms", @@ -4708,7 +5093,7 @@ dependencies = [ [[package]] name = "swc_macros_common" version = "0.3.8" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "pmutil", "proc-macro2", @@ -4718,8 +5103,8 @@ dependencies = [ [[package]] name = "swc_node_comments" -version = "0.19.1" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.20.2" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "dashmap", "swc_atoms", @@ -4738,8 +5123,8 @@ dependencies = [ [[package]] name = "swc_timer" -version = "0.20.1" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +version = "0.21.4" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "tracing", ] @@ -4747,7 +5132,18 @@ dependencies = [ [[package]] name = "swc_trace_macro" version = "0.1.3" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff9719b6085dd2824fd61938a881937be14b08f95e2d27c64c825a9f65e052ba" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "swc_trace_macro" +version = "0.1.3" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "proc-macro2", "quote", @@ -4757,7 +5153,7 @@ dependencies = [ [[package]] name = "swc_visit" version = "0.5.7" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "either", "swc_visit_macros", @@ -4766,7 +5162,7 @@ dependencies = [ [[package]] name = "swc_visit_macros" version = "0.5.8" -source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d6402705ec5de12603d8e13dccd18ee5" +source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" dependencies = [ "Inflector", "pmutil", diff --git a/Cargo.toml b/Cargo.toml index e6f98eb..8aec9ce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,30 +10,21 @@ members = [ resolver = "2" [workspace.dependencies] -anyhow = { version = "1.0.75" } -async-trait = { version = "0.1.71" } -better_scoped_tls = { version = "0.1.1" } -derivative = { version = "2.2.0" } -glob = { version = "0.3.1" } -# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix -napi = "2.12.2" -napi-derive = "2.12.2" -napi-build = "2.0.1" -rustc-hash = { version = "1.1.0" } -serde = { version = "1.0.171" } -serde_json = { version = "1.0.100" } -tokio = { version = "1.29.1" } -tracing = { version = "0.1.37" } +anyhow = { version = "1.0.71", features = ["backtrace"] } async-recursion = { version = "1.0.4" } async-scoped = { version = "0.7.1" } +async-trait = { version = "0.1.71" } backtrace = "0.3" +better_scoped_tls = { version = "0.1.1" } bitflags = { version = "1.3.2" } colored = { version = "2.0.4" } concat-string = "1.0.1" dashmap = { version = "5.5.0" } +derivative = { version = "2.2.0" } derive_builder = { version = "0.11.2" } 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" } insta = { version = "1.30.0" } @@ -44,53 +35,65 @@ mimalloc-rust = { version = "0.2" } mime_guess = { version = "2.0.4" } once_cell = { version = "1.18.0" } paste = { version = "1.0" } +path-clean = { version = "1.0.1" } pathdiff = { version = "0.2.1" } -preset_env_base = { version = "0.4.5" } +preset_env_base = { version = "0.4.6" } 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_json = { version = "1.0.100" } similar = { version = "2.2.1" } sugar_path = { version = "0.0.12" } testing_macros = { version = "0.2.11" } +tokio = { version = "1.29.1" } +tracing = { version = "0.1.37" } tracing-subscriber = { version = "0.3.17" } url = { version = "2.4.0" } urlencoding = { version = "2.1.2" } ustr = { version = "0.9.0" } xxhash-rust = { version = "0.8.6" } +# Pinned +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.72.0" } +styled_components = { version = "0.77.0" } swc_config = { version = "=0.1.7" } -swc_core = { version = "=0.83.1", default-features = false } -swc_css = { version = "=0.155.2" } -swc_ecma_minifier = { version = "=0.187.0", default-features = false } -swc_emotion = { version = "=0.42.0" } -swc_error_reporters = { version = "=0.16.1" } -swc_html = { version = "=0.131.0" } -swc_html_minifier = { version = "=0.128.0" } -swc_node_comments = { version = "=0.19.1" } +swc_core = { version = "0.86.33", default-features = false } +swc_css = { version = "0.157.6" } +swc_ecma_minifier = { version = "0.189.28", default-features = false } +swc_emotion = { version = "=0.58.0" } +swc_error_reporters = { version = "=0.17.2" } +swc_html = { version = "=0.134.29" } +swc_html_minifier = { version = "=0.131.29" } +swc_node_comments = { version = "=0.20.2" } tikv-jemallocator = { version = "=0.5.4", features = ["disable_initial_exec_tls"] } [patch.crates-io] -swc_config = { git = "https://github.com/swc-project/swc.git", rev = "5c00525" } -swc_core = { git = "https://github.com/swc-project/swc.git", rev = "5c00525" } -swc_ecma_minifier = { git = "https://github.com/swc-project/swc.git", rev = "5c00525" } -swc_error_reporters = { git = "https://github.com/swc-project/swc.git", rev = "5c00525" } -swc_html = { git = "https://github.com/swc-project/swc.git", rev = "5c00525" } -swc_html_minifier = { git = "https://github.com/swc-project/swc.git", rev = "5c00525" } -swc_node_comments = { git = "https://github.com/swc-project/swc.git", rev = "5c00525" } -swc_common = { git = "https://github.com/swc-project/swc.git", rev = "5c00525" } -swc_ecma_utils = { git = "https://github.com/swc-project/swc.git", rev = "5c00525" } -swc_ecma_ast = { git = "https://github.com/swc-project/swc.git", rev = "5c00525" } -swc_ecma_visit = { git = "https://github.com/swc-project/swc.git", rev = "5c00525" } -swc_atoms = { git = "https://github.com/swc-project/swc.git", rev = "5c00525" } -preset_env_base = { git = "https://github.com/swc-project/swc.git", rev = "5c00525" } +swc_config = { git = "https://github.com/swc-project/swc.git", rev = "1095bff" } +swc_core = { git = "https://github.com/swc-project/swc.git", rev = "1095bff" } +swc_ecma_minifier = { git = "https://github.com/swc-project/swc.git", rev = "1095bff" } +swc_error_reporters = { git = "https://github.com/swc-project/swc.git", rev = "1095bff" } +swc_html = { git = "https://github.com/swc-project/swc.git", rev = "1095bff" } +swc_html_minifier = { git = "https://github.com/swc-project/swc.git", rev = "1095bff" } +swc_node_comments = { git = "https://github.com/swc-project/swc.git", rev = "1095bff" } +swc_common = { git = "https://github.com/swc-project/swc.git", rev = "1095bff" } +swc_ecma_utils = { git = "https://github.com/swc-project/swc.git", rev = "1095bff" } +swc_ecma_ast = { git = "https://github.com/swc-project/swc.git", rev = "1095bff" } +swc_ecma_visit = { git = "https://github.com/swc-project/swc.git", rev = "1095bff" } +swc_atoms = { git = "https://github.com/swc-project/swc.git", rev = "1095bff" } +preset_env_base = { git = "https://github.com/swc-project/swc.git", rev = "1095bff" } +swc_ecma_codegen = { git = "https://github.com/swc-project/swc.git", rev = "1095bff" } [profile.dev] -debug = 2 -incremental = true +codegen-units = 16 # debug build will cause runtime panic if codegen-unints is default +debug = 2 +incremental = true [profile.release] codegen-units = 1 diff --git a/crates/binding_options/Cargo.toml b/crates/binding_options/Cargo.toml index 2a21109..a0a45e8 100644 --- a/crates/binding_options/Cargo.toml +++ b/crates/binding_options/Cargo.toml @@ -6,11 +6,11 @@ edition = "2021" [dependencies] rspack_binding_macros = { path = "../.rspack_crates/rspack_binding_macros" } rspack_binding_options = { path = "../.rspack_crates/rspack_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_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_sass = { path = "../.rspack_crates/rspack_loader_sass" } rspack_loader_swc = { path = "../.rspack_crates/rspack_loader_swc" } @@ -29,6 +29,7 @@ rspack_plugin_html = { path = "../.rspack_crates/rspack_plu 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" } @@ -38,7 +39,9 @@ rspack_plugin_split_chunks = { path = "../.rspack_crates/rspack_plu 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_hash = { path = "../.rspack_crates/rspack_hash" } diff --git a/crates/binding_options/src/options/js_loader.rs b/crates/binding_options/src/options/js_loader.rs index 98ee634..ae36171 100644 --- a/crates/binding_options/src/options/js_loader.rs +++ b/crates/binding_options/src/options/js_loader.rs @@ -21,6 +21,16 @@ pub async fn run_builtin_loader( let loader = get_builtin_loader(&builtin, options); let loader_item = loader.clone().into(); let list = &[loader_item]; + let additional_data = { + let mut additional_data = loader_context.additional_data_external.clone(); + if let Some(data) = loader_context + .additional_data + .map(|b| String::from_utf8_lossy(b.as_ref()).to_string()) + { + additional_data.insert(data); + } + additional_data + }; let mut cx = LoaderContext { content: loader_context @@ -30,15 +40,13 @@ pub async fn run_builtin_loader( resource_path: Path::new(&loader_context.resource_path), resource_query: loader_context.resource_query.as_deref(), resource_fragment: loader_context.resource_fragment.as_deref(), - context: loader_context.context.clone(), + context: loader_context.context_external.clone(), source_map: loader_context .source_map .map(|s| SourceMap::from_slice(s.as_ref())) .transpose() .map_err(|e| Error::from_reason(e.to_string()))?, - additional_data: loader_context - .additional_data - .map(|b| String::from_utf8_lossy(b.as_ref()).to_string()), + additional_data, cacheable: loader_context.cacheable, file_dependencies: HashSet::from_iter( loader_context @@ -69,21 +77,21 @@ pub async fn run_builtin_loader( __diagnostics: vec![], __resource_data: &ResourceData::new(Default::default(), Default::default()), __loader_items: LoaderItemList(list), - __loader_index: 0, + // This is used an hack to `builtin:swc-loader` in order to determine whether to return AST or source. + __loader_index: loader_context.loader_index_from_js.unwrap_or(0) as usize, __plugins: &[], }; if loader_context.is_pitching { - // Run pitching loader - loader - .pitch(&mut cx) - .await - .map_err(|e| Error::from_reason(e.to_string()))?; + // Builtin loaders dispatched using JS loader-runner does not support pitching. + // This phase is ignored. } else { // Run normal loader loader .run(&mut cx) .await .map_err(|e| Error::from_reason(e.to_string()))?; + // restore the hack + cx.__loader_index = 0; } JsLoaderContext::try_from(&cx).map_err(|e| Error::from_reason(e.to_string())) diff --git a/crates/binding_options/src/options/mod.rs b/crates/binding_options/src/options/mod.rs index b5db707..9fe4d0e 100644 --- a/crates/binding_options/src/options/mod.rs +++ b/crates/binding_options/src/options/mod.rs @@ -1,26 +1,28 @@ use napi_derive::napi; -use better_scoped_tls::scoped_tls; use rspack_core::{ BoxPlugin, CompilerOptions, Context, DevServerOptions, Devtool, Experiments, IncrementalRebuild, - IncrementalRebuildMakeState, ModuleOptions, ModuleType, OutputOptions, PluginExt, + IncrementalRebuildMakeState, ModuleOptions, ModuleType, OutputOptions, PluginExt, Optimization, }; +use rspack_plugin_javascript::{ + FlagDependencyExportsPlugin, FlagDependencyUsagePlugin, SideEffectsFlagPlugin, +}; +use serde::Deserialize; + use rspack_binding_options::{ RawBuiltins, RawCacheOptions, RawContext, RawDevServer, RawDevtool, RawExperiments, - RawMode, RawNodeOption, RawOptimizationOptions, RawOutputOptions, RawResolveOptions, - RawSnapshotOptions, RawStatsOptions, RawTarget, RawOptionsApply, RawModuleOptions, + RawMode, RawNodeOption, RawOutputOptions, RawResolveOptions, RawOptimizationOptions, + RawSnapshotOptions, RawStatsOptions, RawTarget, RawModuleOptions, RawOptionsApply, }; -use rspack_plugin_javascript::{FlagDependencyExportsPlugin, FlagDependencyUsagePlugin}; -use serde::Deserialize; mod raw_module; mod raw_features; mod js_loader; +mod raw_optimization; pub use raw_module::*; pub use raw_features::*; pub use js_loader::*; - -scoped_tls!(pub(crate) static IS_ENABLE_NEW_SPLIT_CHUNKS: bool); +pub use raw_optimization::*; #[derive(Deserialize, Debug)] #[serde(rename_all = "camelCase")] @@ -38,7 +40,7 @@ pub struct RSPackRawOptions { pub module: RawModuleOptions, #[napi(ts_type = "string")] pub devtool: RawDevtool, - pub optimization: RawOptimizationOptions, + pub optimization: RspackRawOptimizationOptions, pub stats: RawStatsOptions, pub dev_server: RawDevServer, pub snapshot: RawSnapshotOptions, @@ -75,9 +77,10 @@ impl RawOptionsApply for RSPackRawOptions { }, async_web_assembly: self.experiments.async_web_assembly, new_split_chunks: self.experiments.new_split_chunks, + top_level_await: self.experiments.top_level_await, rspack_future: self.experiments.rspack_future.into(), }; - let optimization; + let optimization: Optimization; if self.features.split_chunks_strategy.is_some() { let split_chunk_strategy = SplitChunksStrategy::new( self.features.split_chunks_strategy.unwrap(), @@ -89,7 +92,7 @@ impl RawOptionsApply for RSPackRawOptions { self.optimization.apply(plugins) })?; } - + let stats = self.stats.into(); let snapshot = self.snapshot.into(); let node = self.node.map(|n| n.into()); @@ -141,6 +144,9 @@ impl RawOptionsApply for RSPackRawOptions { plugins.push(rspack_ids::NamedChunkIdsPlugin::new(None, None).boxed()); if experiments.rspack_future.new_treeshaking { + if optimization.side_effects.is_enable() { + plugins.push(SideEffectsFlagPlugin::default().boxed()); + } if optimization.provided_exports { plugins.push(FlagDependencyExportsPlugin::default().boxed()); } @@ -156,7 +162,7 @@ impl RawOptionsApply for RSPackRawOptions { plugins.push(rspack_plugin_ensure_chunk_conditions::EnsureChunkConditionsPlugin.boxed()); - plugins.push(plugin_manifest::ManifestPlugin::new().boxed()); + plugins.push(rspack_plugin_warn_sensitive_module::WarnCaseSensitiveModulesPlugin.boxed()); Ok(Self::Options { context, diff --git a/crates/binding_options/src/options/raw_features.rs b/crates/binding_options/src/options/raw_features.rs index ceec742..f3b8fb3 100644 --- a/crates/binding_options/src/options/raw_features.rs +++ b/crates/binding_options/src/options/raw_features.rs @@ -11,7 +11,7 @@ use rspack_ids::{ DeterministicChunkIdsPlugin, DeterministicModuleIdsPlugin, NamedChunkIdsPlugin, NamedModuleIdsPlugin, }; -use rspack_binding_options::RawOptimizationOptions; +use crate::RspackRawOptimizationOptions; use rspack_plugin_split_chunks_new::{PluginOptions, CacheGroup}; use rspack_regex::RspackRegex; use rspack_hash::{RspackHash, HashFunction, HashDigest}; @@ -27,6 +27,7 @@ pub struct SplitChunksStrategy { real_content_hash: bool, remove_empty_chunks: bool, remove_available_modules: bool, + inner_graph: bool, } fn get_modules_size(module: &dyn Module) -> f64 { @@ -126,7 +127,7 @@ pub trait FeatureApply { } impl SplitChunksStrategy { - pub fn new(strategy: RawStrategyOptions, option: RawOptimizationOptions) -> Self { + pub fn new(strategy: RawStrategyOptions, option: RspackRawOptimizationOptions) -> Self { Self { strategy, chunk_ids: option.chunk_ids, @@ -137,6 +138,7 @@ impl SplitChunksStrategy { used_exports: option.used_exports, provided_exports: option.provided_exports, real_content_hash: option.real_content_hash, + inner_graph: option.inner_graph, } } } @@ -173,12 +175,13 @@ impl FeatureApply for SplitChunksStrategy { if self.real_content_hash { plugins.push(rspack_plugin_real_content_hash::RealContentHashPlugin.boxed()); } - Ok(Self::Options { + Ok(Optimization { remove_available_modules: self.remove_available_modules, remove_empty_chunks: self.remove_empty_chunks, side_effects: SideEffectOption::from(self.side_effects.as_str()), provided_exports: self.provided_exports, used_exports: UsedExportsOption::from(self.used_exports.as_str()), + inner_graph: self.inner_graph, }) } } diff --git a/crates/binding_options/src/options/raw_module.rs b/crates/binding_options/src/options/raw_module.rs index 4cc8e18..77b6c21 100644 --- a/crates/binding_options/src/options/raw_module.rs +++ b/crates/binding_options/src/options/raw_module.rs @@ -1,6 +1,5 @@ use std::sync::Arc; 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; use loader_compilation::COMPILATION_LOADER_IDENTIFIER; @@ -24,11 +23,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()), - ); - } if builtin.starts_with(COMPILATION_LOADER_IDENTIFIER) { return Arc::new( diff --git a/crates/binding_options/src/options/raw_optimization.rs b/crates/binding_options/src/options/raw_optimization.rs new file mode 100644 index 0000000..2090002 --- /dev/null +++ b/crates/binding_options/src/options/raw_optimization.rs @@ -0,0 +1,82 @@ +use better_scoped_tls::scoped_tls; +use napi_derive::napi; +use rspack_core::{Optimization, PluginExt, SideEffectOption, UsedExportsOption}; +use rspack_error::internal_error; +use rspack_ids::{ + DeterministicChunkIdsPlugin, DeterministicModuleIdsPlugin, NamedChunkIdsPlugin, + NamedModuleIdsPlugin, +}; +use rspack_plugin_split_chunks::SplitChunksPlugin; +use serde::Deserialize; + +use rspack_binding_options::{RawOptionsApply, RawSplitChunksOptions}; + +scoped_tls!(pub(crate) static IS_ENABLE_NEW_SPLIT_CHUNKS: bool); + +#[derive(Deserialize, Debug, Default)] +#[serde(rename_all = "camelCase")] +#[napi(object)] +pub struct RspackRawOptimizationOptions { + pub split_chunks: Option, + pub module_ids: String, + pub chunk_ids: String, + pub remove_available_modules: bool, + pub remove_empty_chunks: bool, + pub side_effects: String, + pub used_exports: String, + pub provided_exports: bool, + pub inner_graph: bool, + pub real_content_hash: bool, +} + +impl RawOptionsApply for RspackRawOptimizationOptions { + type Options = Optimization; + + fn apply( + self, + plugins: &mut Vec>, + ) -> Result { + if let Some(options) = self.split_chunks { + let split_chunks_plugin = IS_ENABLE_NEW_SPLIT_CHUNKS.with(|is_enable_new_split_chunks| { + if *is_enable_new_split_chunks { + rspack_plugin_split_chunks_new::SplitChunksPlugin::new(options.into()).boxed() + } else { + SplitChunksPlugin::new(options.into()).boxed() + } + }); + + plugins.push(split_chunks_plugin); + } + let chunk_ids_plugin = match self.chunk_ids.as_ref() { + "named" => NamedChunkIdsPlugin::new(None, None).boxed(), + "deterministic" => DeterministicChunkIdsPlugin::default().boxed(), + _ => { + return Err(internal_error!( + "'chunk_ids' should be 'named' or 'deterministic'." + )) + } + }; + plugins.push(chunk_ids_plugin); + let module_ids_plugin = match self.module_ids.as_ref() { + "named" => NamedModuleIdsPlugin::default().boxed(), + "deterministic" => DeterministicModuleIdsPlugin::default().boxed(), + _ => { + return Err(internal_error!( + "'module_ids' should be 'named' or 'deterministic'." + )) + } + }; + plugins.push(module_ids_plugin); + if self.real_content_hash { + plugins.push(rspack_plugin_real_content_hash::RealContentHashPlugin.boxed()); + } + Ok(Optimization { + remove_available_modules: self.remove_available_modules, + remove_empty_chunks: self.remove_empty_chunks, + side_effects: SideEffectOption::from(self.side_effects.as_str()), + provided_exports: self.provided_exports, + used_exports: UsedExportsOption::from(self.used_exports.as_str()), + inner_graph: self.inner_graph, + }) + } +} diff --git a/crates/node_binding/Cargo.toml b/crates/node_binding/Cargo.toml index f41687a..c3edc02 100644 --- a/crates/node_binding/Cargo.toml +++ b/crates/node_binding/Cargo.toml @@ -8,6 +8,7 @@ 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" } rspack_core = { path = "../.rspack_crates/rspack_core" } diff --git a/crates/node_binding/index.d.ts b/crates/node_binding/index.d.ts index 591c15f..d9d6acf 100644 --- a/crates/node_binding/index.d.ts +++ b/crates/node_binding/index.d.ts @@ -620,6 +620,13 @@ export interface RawOptions { profile: boolean builtins: RawBuiltins } +export interface RawStrategyOptions { + name: string + topLevelFrameworks: Array +} +export interface RawFeatures { + splitChunksStrategy?: RawStrategyOptions +} export interface RsPackRawOptions { mode?: undefined | 'production' | 'development' | 'none' target: Array @@ -638,6 +645,7 @@ export interface RsPackRawOptions { node?: RawNodeOption profile: boolean builtins: RawBuiltins + features: RawFeatures } export interface JsAssetInfoRelated { sourceMap?: string diff --git a/crates/node_binding/src/js_values/asset.rs b/crates/node_binding/src/js_values/asset.rs deleted file mode 100644 index 1c27142..0000000 --- a/crates/node_binding/src/js_values/asset.rs +++ /dev/null @@ -1,106 +0,0 @@ -use super::JsCompatSource; - -#[napi(object)] -pub struct JsAssetInfoRelated { - pub source_map: Option, -} - -impl From for rspack_core::AssetInfoRelated { - fn from(i: JsAssetInfoRelated) -> Self { - Self { - source_map: i.source_map, - } - } -} -#[napi(object)] -pub struct JsAssetInfo { - /// if the asset can be long term cached forever (contains a hash) - pub immutable: bool, - /// whether the asset is minimized - pub minimized: bool, - /// the value(s) of the full hash used for this asset - // pub full_hash: - /// the value(s) of the chunk hash used for this asset - pub chunk_hash: Vec, - /// the value(s) of the module hash used for this asset - // pub module_hash: - /// the value(s) of the content hash used for this asset - pub content_hash: Vec, - /// when asset was created from a source file (potentially transformed), the original filename relative to compilation context - // pub source_filename: - /// size in bytes, only set after asset has been emitted - // pub size: f64, - /// when asset is only used for development and doesn't count towards user-facing assets - pub development: bool, - /// when asset ships data for updating an existing application (HMR) - pub hot_module_replacement: bool, - /// when asset is javascript and an ESM - // pub javascript_module: - /// related object to other assets, keyed by type of relation (only points from parent to child) - pub related: JsAssetInfoRelated, - /// the asset version, emit can be skipped when both filename and version are the same - /// An empty string means no version, it will always emit - pub version: String, -} - -impl From for rspack_core::AssetInfo { - fn from(i: JsAssetInfo) -> Self { - Self { - immutable: i.immutable, - minimized: i.minimized, - development: i.development, - hot_module_replacement: i.hot_module_replacement, - chunk_hash: i.chunk_hash.into_iter().collect(), - related: i.related.into(), - content_hash: i.content_hash.into_iter().collect(), - version: i.version, - } - } -} - -#[napi(object)] -pub struct JsAsset { - pub name: String, - pub source: Option, - pub info: JsAssetInfo, -} - -impl From for JsAssetInfoRelated { - fn from(related: rspack_core::AssetInfoRelated) -> Self { - Self { - source_map: related.source_map, - } - } -} - -impl From for JsAssetInfo { - fn from(info: rspack_core::AssetInfo) -> Self { - Self { - immutable: info.immutable, - minimized: info.minimized, - development: info.development, - hot_module_replacement: info.hot_module_replacement, - related: info.related.into(), - chunk_hash: info.chunk_hash.into_iter().collect(), - content_hash: info.content_hash.into_iter().collect(), - version: info.version, - } - } -} - -#[napi(object)] -pub struct JsAssetEmittedArgs { - pub filename: String, - pub output_path: String, - pub target_path: String, -} - -impl From<&rspack_core::AssetEmittedArgs<'_>> for JsAssetEmittedArgs { - fn from(args: &rspack_core::AssetEmittedArgs) -> Self { - Self { - filename: args.filename.to_string(), - output_path: args.output_path.to_string_lossy().to_string(), - target_path: args.target_path.to_string_lossy().to_string(), - } - } -} diff --git a/crates/node_binding/src/js_values/chunk_group.rs b/crates/node_binding/src/js_values/chunk_group.rs deleted file mode 100644 index 557e72c..0000000 --- a/crates/node_binding/src/js_values/chunk_group.rs +++ /dev/null @@ -1,27 +0,0 @@ -use crate::js_values::JsChunk; - -#[napi(object)] -pub struct JsChunkGroup { - pub chunks: Vec, -} - -impl JsChunkGroup { - pub fn from_chunk_group( - cg: &rspack_core::ChunkGroup, - compilation: &rspack_core::Compilation, - ) -> Self { - Self { - chunks: cg - .chunks - .iter() - .map(|k| { - JsChunk::from( - compilation.chunk_by_ukey.get(k).unwrap_or_else(|| { - panic!("Could not find Chunk({k:?}) belong to ChunkGroup: {cg:?}",) - }), - ) - }) - .collect(), - } - } -} diff --git a/crates/node_binding/src/js_values/compilation.rs b/crates/node_binding/src/js_values/compilation.rs deleted file mode 100644 index a1203c8..0000000 --- a/crates/node_binding/src/js_values/compilation.rs +++ /dev/null @@ -1,434 +0,0 @@ -use std::collections::HashMap; -use std::path::PathBuf; - -use napi::bindgen_prelude::*; -use napi::NapiRaw; -use rspack_core::rspack_sources::BoxSource; -use rspack_core::AssetInfo; -use rspack_core::ModuleIdentifier; -use rspack_core::{rspack_sources::SourceExt, NormalModuleSource}; -use rspack_error::Diagnostic; -use rspack_identifier::Identifier; -use rspack_napi_shared::NapiResultExt; - -use super::module::ToJsModule; -use super::PathWithInfo; -use crate::utils::callbackify; -use crate::{ - js_values::{chunk::JsChunk, module::JsModule, PathData}, - CompatSource, JsAsset, JsAssetInfo, JsChunkGroup, JsCompatSource, JsStats, ToJsCompatSource, -}; - -#[napi] -pub struct JsCompilation { - inner: &'static mut rspack_core::Compilation, -} - -#[napi] -impl JsCompilation { - #[napi( - ts_args_type = r#"filename: string, newSourceOrFunction: JsCompatSource | ((source: JsCompatSource) => JsCompatSource), assetInfoUpdateOrFunction?: JsAssetInfo | ((assetInfo: JsAssetInfo) => JsAssetInfo)"# - )] - pub fn update_asset( - &mut self, - env: Env, - filename: String, - new_source_or_function: Either, - asset_info_update_or_function: Option>, - ) -> Result<()> { - self - .inner - .update_asset(&filename, |original_source, original_info| { - let new_source: napi::Result = try { - let new_source = match new_source_or_function { - Either::A(new_source) => Into::::into(new_source).boxed(), - Either::B(new_source_fn) => { - let js_source = unsafe { - call_js_function_with_napi_objects!( - env, - new_source_fn, - original_source.to_js_compat_source() - ) - }?; - - let compat_source: CompatSource = unsafe { - convert_raw_napi_value_to_napi_value!(env, JsCompatSource, js_source.raw()) - }? - .into(); - - compat_source.boxed() - } - }; - new_source - }; - let new_source = new_source.into_rspack_result()?; - - let new_info: napi::Result> = asset_info_update_or_function - .map( - |asset_info_update_or_function| match asset_info_update_or_function { - Either::A(asset_info) => Ok(asset_info.into()), - Either::B(asset_info_fn) => { - let asset_info = unsafe { - call_js_function_with_napi_objects!( - env, - asset_info_fn, - Into::::into(original_info.clone()) - ) - }?; - - let js_asset_info = unsafe { - convert_raw_napi_value_to_napi_value!(env, JsAssetInfo, asset_info.raw()) - }?; - Ok(js_asset_info.into()) - } - }, - ) - .transpose(); - let new_info = new_info.into_rspack_result()?; - Ok((new_source, new_info.unwrap_or(original_info))) - }) - .map_err(|err| napi::Error::from_reason(err.to_string())) - } - - #[napi(ts_return_type = "Readonly[]")] - pub fn get_assets(&self) -> Result> { - let mut assets = Vec::::with_capacity(self.inner.assets().len()); - - for (filename, asset) in self.inner.assets() { - assets.push(JsAsset { - name: filename.clone(), - source: asset - .source - .as_ref() - .map(|s| s.to_js_compat_source()) - .transpose()?, - info: asset.info.clone().into(), - }); - } - - Ok(assets) - } - - #[napi] - pub fn get_asset(&self, name: String) -> Result> { - match self.inner.assets().get(&name) { - Some(asset) => Ok(Some(JsAsset { - name, - source: asset - .source - .as_ref() - .map(|s| s.to_js_compat_source()) - .transpose()?, - info: asset.info.clone().into(), - })), - None => Ok(None), - } - } - - #[napi] - pub fn get_asset_source(&self, name: String) -> Result> { - self - .inner - .assets() - .get(&name) - .and_then(|v| v.source.as_ref().map(|s| s.to_js_compat_source())) - .transpose() - } - - #[napi] - pub fn get_modules(&self) -> Vec { - self - .inner - .module_graph - .modules() - .values() - .filter_map(|module| module.to_js_module().ok()) - .collect::>() - } - - #[napi] - pub fn get_chunks(&self) -> Vec { - self - .inner - .chunk_by_ukey - .values() - .map(JsChunk::from) - .collect::>() - } - - #[napi] - pub fn get_named_chunk(&self, name: String) -> Option { - self - .inner - .named_chunks - .get(&name) - .and_then(|c| self.inner.chunk_by_ukey.get(c).map(JsChunk::from)) - } - - #[napi] - /// Only available for those none Js and Css source, - /// return true if set module source successfully, false if failed. - pub fn set_none_ast_module_source( - &mut self, - module_identifier: String, - source: JsCompatSource, - ) -> bool { - match self - .inner - .module_graph - .module_by_identifier_mut(&Identifier::from(module_identifier.as_str())) - { - Some(module) => match module.as_normal_module_mut() { - Some(module) => { - let compat_source = CompatSource::from(source).boxed(); - *module.source_mut() = NormalModuleSource::new_built(compat_source, &[]); - true - } - None => false, - }, - None => false, - } - } - - #[napi] - pub fn set_asset_source(&mut self, name: String, source: JsCompatSource) { - let source = CompatSource::from(source).boxed(); - match self.inner.assets_mut().entry(name) { - std::collections::hash_map::Entry::Occupied(mut e) => e.get_mut().set_source(Some(source)), - std::collections::hash_map::Entry::Vacant(e) => { - e.insert(rspack_core::CompilationAsset::from(source)); - } - }; - } - - #[napi] - pub fn delete_asset_source(&mut self, name: String) { - self - .inner - .assets_mut() - .entry(name) - .and_modify(|a| a.set_source(None)); - } - - #[napi] - pub fn get_asset_filenames(&self) -> Result> { - let filenames = self - .inner - .assets() - .iter() - .filter(|(_, asset)| asset.get_source().is_some()) - .map(|(filename, _)| filename) - .cloned() - .collect(); - Ok(filenames) - } - - #[napi] - pub fn has_asset(&self, name: String) -> Result { - Ok(self.inner.assets().contains_key(&name)) - } - - #[napi] - pub fn emit_asset( - &mut self, - filename: String, - source: JsCompatSource, - asset_info: JsAssetInfo, - ) -> Result<()> { - let compat_source: CompatSource = source.into(); - - self.inner.emit_asset( - filename, - rspack_core::CompilationAsset::new(Some(compat_source.boxed()), asset_info.into()), - ); - - Ok(()) - } - - #[napi] - pub fn delete_asset(&mut self, filename: String) { - self.inner.delete_asset(&filename); - } - - #[napi(getter)] - pub fn entrypoints(&self) -> HashMap { - let entrypoints = self.inner.entrypoints(); - entrypoints - .iter() - .map(|(n, _)| { - ( - n.clone(), - JsChunkGroup::from_chunk_group(self.inner.entrypoint_by_name(n), self.inner), - ) - }) - .collect() - } - - #[napi(getter)] - pub fn hash(&self) -> Option { - self.inner.get_hash().map(|hash| hash.to_owned()) - } - - #[napi] - pub fn get_file_dependencies(&self) -> Vec { - self - .inner - .file_dependencies - .iter() - .map(|i| i.to_string_lossy().to_string()) - .collect() - } - - #[napi] - pub fn get_context_dependencies(&self) -> Vec { - self - .inner - .context_dependencies - .iter() - .map(|i| i.to_string_lossy().to_string()) - .collect() - } - - #[napi] - pub fn get_missing_dependencies(&self) -> Vec { - self - .inner - .missing_dependencies - .iter() - .map(|i| i.to_string_lossy().to_string()) - .collect() - } - - #[napi] - pub fn get_build_dependencies(&self) -> Vec { - self - .inner - .build_dependencies - .iter() - .map(|i| i.to_string_lossy().to_string()) - .collect() - } - - #[napi(ts_args_type = r#"severity: "error" | "warning", title: string, message: string"#)] - pub fn push_diagnostic(&mut self, severity: String, title: String, message: String) { - let diagnostic = match severity.as_str() { - "warning" => rspack_error::Diagnostic::warn(title, message, 0, 0), - _ => rspack_error::Diagnostic::error(title, message, 0, 0), - }; - self.inner.push_diagnostic(diagnostic); - } - - #[napi] - pub fn push_native_diagnostics(&mut self, mut diagnostics: External>) { - while let Some(diagnostic) = diagnostics.pop() { - self.inner.push_diagnostic(diagnostic); - } - } - - #[napi] - pub fn get_stats(&self, reference: Reference, env: Env) -> Result { - Ok(JsStats::new(reference.share_with(env, |compilation| { - Ok(compilation.inner.get_stats()) - })?)) - } - - #[napi] - pub fn get_asset_path(&self, filename: String, data: PathData) -> String { - self.inner.get_asset_path( - &rspack_core::Filename::from(filename), - data.as_core_path_data(), - ) - } - - #[napi] - pub fn get_asset_path_with_info(&self, filename: String, data: PathData) -> PathWithInfo { - self - .inner - .get_asset_path_with_info( - &rspack_core::Filename::from(filename), - data.as_core_path_data(), - ) - .into() - } - - #[napi] - pub fn get_path(&self, filename: String, data: PathData) -> String { - self.inner.get_path( - &rspack_core::Filename::from(filename), - data.as_core_path_data(), - ) - } - - #[napi] - pub fn get_path_with_info(&self, filename: String, data: PathData) -> PathWithInfo { - self - .inner - .get_path_with_info( - &rspack_core::Filename::from(filename), - data.as_core_path_data(), - ) - .into() - } - - #[napi] - pub fn add_file_dependencies(&mut self, deps: Vec) { - self - .inner - .file_dependencies - .extend(deps.into_iter().map(PathBuf::from)) - } - - #[napi] - pub fn add_context_dependencies(&mut self, deps: Vec) { - self - .inner - .context_dependencies - .extend(deps.into_iter().map(PathBuf::from)) - } - - #[napi] - pub fn add_missing_dependencies(&mut self, deps: Vec) { - self - .inner - .missing_dependencies - .extend(deps.into_iter().map(PathBuf::from)) - } - - #[napi] - pub fn add_build_dependencies(&mut self, deps: Vec) { - self - .inner - .build_dependencies - .extend(deps.into_iter().map(PathBuf::from)) - } - - #[napi] - pub fn rebuild_module( - &'static mut self, - env: Env, - module_identifiers: Vec, - f: JsFunction, - ) -> Result<()> { - callbackify(env, f, async { - let modules = self - .inner - .rebuild_module(rustc_hash::FxHashSet::from_iter( - module_identifiers.into_iter().map(ModuleIdentifier::from), - )) - .await - .map_err(|e| Error::new(napi::Status::GenericFailure, format!("{e}")))?; - Ok( - modules - .into_iter() - .filter_map(|item| item.to_js_module().ok()) - .collect::>(), - ) - }) - } -} - -impl JsCompilation { - pub fn from_compilation(inner: &'static mut rspack_core::Compilation) -> Self { - Self { inner } - } -} diff --git a/crates/node_binding/src/js_values/hooks.rs b/crates/node_binding/src/js_values/hooks.rs deleted file mode 100644 index 3a401a5..0000000 --- a/crates/node_binding/src/js_values/hooks.rs +++ /dev/null @@ -1,42 +0,0 @@ -use napi::bindgen_prelude::*; - -#[napi(object)] -pub struct JsHooks { - pub process_assets_stage_additional: JsFunction, - pub process_assets_stage_pre_process: JsFunction, - pub process_assets_stage_derived: JsFunction, - pub process_assets_stage_additions: JsFunction, - pub process_assets_stage_none: JsFunction, - pub process_assets_stage_optimize: JsFunction, - pub process_assets_stage_optimize_count: JsFunction, - pub process_assets_stage_optimize_compatibility: JsFunction, - pub process_assets_stage_optimize_size: JsFunction, - pub process_assets_stage_dev_tooling: JsFunction, - pub process_assets_stage_optimize_inline: JsFunction, - pub process_assets_stage_summarize: JsFunction, - pub process_assets_stage_optimize_hash: JsFunction, - pub process_assets_stage_optimize_transfer: JsFunction, - pub process_assets_stage_analyse: JsFunction, - pub process_assets_stage_report: JsFunction, - pub compilation: JsFunction, - pub this_compilation: JsFunction, - pub emit: JsFunction, - pub asset_emitted: JsFunction, - pub after_emit: JsFunction, - pub make: JsFunction, - pub optimize_modules: JsFunction, - pub optimize_tree: JsFunction, - pub optimize_chunk_module: JsFunction, - pub before_compile: JsFunction, - pub after_compile: JsFunction, - pub finish_modules: JsFunction, - pub finish_make: JsFunction, - pub build_module: JsFunction, - pub before_resolve: JsFunction, - pub after_resolve: JsFunction, - pub context_module_before_resolve: JsFunction, - pub normal_module_factory_resolve_for_scheme: JsFunction, - pub chunk_asset: JsFunction, - pub succeed_module: JsFunction, - pub still_valid_module: JsFunction, -} diff --git a/crates/node_binding/src/js_values/mod.rs b/crates/node_binding/src/js_values/mod.rs deleted file mode 100644 index c2959a4..0000000 --- a/crates/node_binding/src/js_values/mod.rs +++ /dev/null @@ -1,25 +0,0 @@ -mod chunk { - // TODO: should we merge rspack_binding_options and node_binding? - pub use rspack_binding_options::chunk::*; -} - -mod asset; -mod chunk_group; -mod compilation; -mod hooks; -mod module; -mod normal_module_factory; -mod path_data; -mod source; -mod stats; - -pub use asset::*; -pub use chunk::*; -pub use chunk_group::*; -pub use compilation::*; -pub use hooks::*; -pub use module::*; -pub use normal_module_factory::*; -pub use path_data::*; -pub use source::*; -pub use stats::*; diff --git a/crates/node_binding/src/js_values/module.rs b/crates/node_binding/src/js_values/module.rs deleted file mode 100644 index 8ddf315..0000000 --- a/crates/node_binding/src/js_values/module.rs +++ /dev/null @@ -1,37 +0,0 @@ -use napi::bindgen_prelude::*; -use rspack_core::Module; -use rspack_identifier::Identifiable; - -use super::{JsCompatSource, ToJsCompatSource}; - -#[napi(object)] -pub struct JsModule { - pub original_source: Option, - pub resource: String, - pub module_identifier: String, -} - -pub trait ToJsModule { - fn to_js_module(&self) -> Result; -} - -impl ToJsModule for dyn Module + '_ { - fn to_js_module(&self) -> Result { - let original_source = self - .original_source() - .and_then(|source| source.to_js_compat_source().ok()); - self - .try_as_normal_module() - .map(|normal_module| JsModule { - original_source, - - resource: normal_module - .resource_resolved_data() - .resource_path - .to_string_lossy() - .to_string(), - module_identifier: normal_module.identifier().to_string(), - }) - .map_err(|_| napi::Error::from_reason("Failed to convert module to JsModule")) - } -} diff --git a/crates/node_binding/src/js_values/normal_module_factory.rs b/crates/node_binding/src/js_values/normal_module_factory.rs deleted file mode 100644 index feb0296..0000000 --- a/crates/node_binding/src/js_values/normal_module_factory.rs +++ /dev/null @@ -1,105 +0,0 @@ -use rspack_core::{NormalModuleAfterResolveArgs, NormalModuleBeforeResolveArgs, ResourceData}; - -#[napi(object)] -pub struct JsResolveForSchemeInput { - pub resource_data: JsResourceData, - pub scheme: String, -} - -#[napi(object)] -pub struct JsResolveForSchemeResult { - pub resource_data: JsResourceData, - pub stop: bool, -} - -#[napi(object)] -pub struct BeforeResolveData { - pub request: String, - pub context: String, -} - -#[napi(object)] -pub struct AfterResolveData { - pub request: String, - pub context: String, - pub file_dependencies: Vec, - pub context_dependencies: Vec, - pub missing_dependencies: Vec, - pub factory_meta: FactoryMeta, -} - -#[napi(object)] -pub struct FactoryMeta { - pub side_effect_free: Option, -} - -#[napi(object)] -pub struct JsResourceData { - /// Resource with absolute path, query and fragment - pub resource: String, - /// Absolute resource path only - pub path: String, - /// Resource query with `?` prefix - pub query: Option, - /// Resource fragment with `#` prefix - pub fragment: Option, -} - -impl From for JsResourceData { - fn from(value: ResourceData) -> Self { - Self { - resource: value.resource, - path: value.resource_path.to_string_lossy().to_string(), - query: value.resource_query, - fragment: value.resource_fragment, - } - } -} - -impl From for JsResolveForSchemeInput { - fn from(value: ResourceData) -> Self { - Self { - scheme: value.get_scheme().to_string(), - resource_data: value.into(), - } - } -} - -impl From for BeforeResolveData { - fn from(value: NormalModuleBeforeResolveArgs) -> Self { - Self { - context: value.context, - request: value.request, - } - } -} - -impl From> for AfterResolveData { - fn from(value: NormalModuleAfterResolveArgs) -> Self { - Self { - context: value.context.to_owned(), - request: value.request.to_string(), - file_dependencies: value - .file_dependencies - .clone() - .into_iter() - .map(|item| item.to_string_lossy().to_string()) - .collect::>(), - context_dependencies: value - .context_dependencies - .clone() - .into_iter() - .map(|item| item.to_string_lossy().to_string()) - .collect::>(), - missing_dependencies: value - .context_dependencies - .clone() - .into_iter() - .map(|item| item.to_string_lossy().to_string()) - .collect::>(), - factory_meta: FactoryMeta { - side_effect_free: value.factory_meta.side_effect_free, - }, - } - } -} diff --git a/crates/node_binding/src/js_values/path_data.rs b/crates/node_binding/src/js_values/path_data.rs deleted file mode 100644 index 68d5afc..0000000 --- a/crates/node_binding/src/js_values/path_data.rs +++ /dev/null @@ -1,42 +0,0 @@ -use super::JsAssetInfo; - -#[napi(object)] -pub struct PathData { - pub filename: Option, - pub hash: Option, - pub content_hash: Option, - pub runtime: Option, - pub url: Option, - pub id: Option, -} - -impl PathData { - pub fn as_core_path_data(&self) -> rspack_core::PathData { - rspack_core::PathData { - filename: self.filename.as_deref(), - chunk: None, - module: None, - hash: self.hash.as_deref(), - content_hash: self.content_hash.as_deref(), - chunk_graph: None, - runtime: self.runtime.as_deref(), - url: self.url.as_deref(), - id: self.id.as_deref(), - } - } -} - -#[napi(object)] -pub struct PathWithInfo { - pub path: String, - pub info: JsAssetInfo, -} - -impl From<(String, rspack_core::AssetInfo)> for PathWithInfo { - fn from(value: (String, rspack_core::AssetInfo)) -> Self { - Self { - path: value.0, - info: value.1.into(), - } - } -} diff --git a/crates/node_binding/src/js_values/source.rs b/crates/node_binding/src/js_values/source.rs deleted file mode 100644 index 22d972b..0000000 --- a/crates/node_binding/src/js_values/source.rs +++ /dev/null @@ -1,198 +0,0 @@ -use std::{borrow::Cow, hash::Hash, sync::Arc}; - -use napi::bindgen_prelude::*; -use rspack_core::rspack_sources::{ - stream_chunks::{stream_chunks_default, GeneratedInfo, OnChunk, OnName, OnSource, StreamChunks}, - CachedSource, ConcatSource, MapOptions, OriginalSource, RawSource, ReplaceSource, Source, - SourceMap, SourceMapSource, -}; - -#[napi(object)] -pub struct JsCompatSource { - /// Whether the underlying data structure is a `RawSource` - pub is_raw: bool, - /// Whether the underlying value is a buffer or string - pub is_buffer: bool, - pub source: Buffer, - pub map: Option, -} - -#[derive(Debug, Clone, Eq)] -pub struct CompatSource { - pub is_raw: bool, - pub is_buffer: bool, - pub source: Vec, - pub map: Option>, -} - -impl std::hash::Hash for CompatSource { - fn hash(&self, state: &mut H) { - "__CompatSource".hash(state); - self.is_raw.hash(state); - self.is_buffer.hash(state); - self.source.hash(state); - self.map.hash(state); - } -} - -impl PartialEq for CompatSource { - fn eq(&self, other: &Self) -> bool { - self.is_raw == other.is_raw - && self.is_buffer == other.is_buffer - && self.source == other.source - && self.map == other.map - } -} - -impl From for CompatSource { - fn from(source: JsCompatSource) -> Self { - Self { - is_raw: source.is_raw, - is_buffer: source.is_buffer, - source: source.source.into(), - map: source.map.map(Into::into), - } - } -} - -impl StreamChunks for CompatSource { - fn stream_chunks( - &self, - options: &MapOptions, - on_chunk: OnChunk, - on_source: OnSource, - on_name: OnName, - ) -> GeneratedInfo { - stream_chunks_default(self, options, on_chunk, on_source, on_name) - } -} - -impl Source for CompatSource { - fn source(&self) -> Cow { - // Use UTF-8 lossy for any sources, including `RawSource` as a workaround for not supporting either `Buffer` or `String` in `Source`. - String::from_utf8_lossy(&self.source) - } - - fn buffer(&self) -> Cow<[u8]> { - Cow::Borrowed(self.source.as_ref()) - } - - fn size(&self) -> usize { - self.source.len() - } - - fn map(&self, _options: &MapOptions) -> Option { - self - .map - .as_ref() - .and_then(|m| SourceMap::from_slice(m).ok()) - } - - fn to_writer(&self, writer: &mut dyn std::io::Write) -> std::io::Result<()> { - writer.write_all(&self.source) - } -} - -pub trait ToJsCompatSource { - fn to_js_compat_source(&self) -> Result; -} - -impl ToJsCompatSource for RawSource { - fn to_js_compat_source(&self) -> Result { - Ok(JsCompatSource { - is_raw: true, - is_buffer: self.is_buffer(), - source: self.buffer().to_vec().into(), - map: to_webpack_map(self)?, - }) - } -} - -impl ToJsCompatSource for ReplaceSource { - fn to_js_compat_source(&self) -> Result { - Ok(JsCompatSource { - is_raw: false, - is_buffer: false, - source: self.buffer().to_vec().into(), - map: to_webpack_map(self)?, - }) - } -} - -impl ToJsCompatSource for CachedSource { - fn to_js_compat_source(&self) -> Result { - self.original().to_js_compat_source() - } -} - -impl ToJsCompatSource for Arc { - fn to_js_compat_source(&self) -> Result { - (**self).to_js_compat_source() - } -} - -impl ToJsCompatSource for Box { - fn to_js_compat_source(&self) -> Result { - (**self).to_js_compat_source() - } -} - -macro_rules! impl_default_to_compat_source { - ($ident:ident) => { - impl ToJsCompatSource for $ident { - fn to_js_compat_source(&self) -> Result { - Ok(JsCompatSource { - is_raw: false, - is_buffer: false, - source: self.buffer().to_vec().into(), - map: to_webpack_map(self)?, - }) - } - } - }; -} - -impl_default_to_compat_source!(SourceMapSource); -impl_default_to_compat_source!(ConcatSource); -impl_default_to_compat_source!(OriginalSource); - -fn to_webpack_map(source: &dyn Source) -> Result> { - let map = source.map(&MapOptions::default()); - - map - .map(|m| m.to_json().map(|inner| inner.into_bytes().into())) - .transpose() - .map_err(|err| napi::Error::from_reason(err.to_string())) -} - -impl ToJsCompatSource for dyn Source + '_ { - fn to_js_compat_source(&self) -> Result { - if let Some(raw_source) = self.as_any().downcast_ref::() { - raw_source.to_js_compat_source() - } else if let Some(cached_source) = self.as_any().downcast_ref::>() { - cached_source.to_js_compat_source() - } else if let Some(cached_source) = self - .as_any() - .downcast_ref::>>() - { - cached_source.to_js_compat_source() - } else if let Some(cached_source) = self - .as_any() - .downcast_ref::>>() - { - cached_source.to_js_compat_source() - } else if let Some(source) = self.as_any().downcast_ref::>() { - source.to_js_compat_source() - } else if let Some(source) = self.as_any().downcast_ref::>() { - source.to_js_compat_source() - } else { - // If it's not a `RawSource` related type, then we regards it as a `Source` type. - Ok(JsCompatSource { - is_raw: false, - is_buffer: false, - source: self.buffer().to_vec().into(), - map: to_webpack_map(self)?, - }) - } - } -} diff --git a/crates/node_binding/src/js_values/stats.rs b/crates/node_binding/src/js_values/stats.rs deleted file mode 100644 index 26d97f1..0000000 --- a/crates/node_binding/src/js_values/stats.rs +++ /dev/null @@ -1,561 +0,0 @@ -use napi::bindgen_prelude::Buffer; -use napi::{ - bindgen_prelude::{Result, SharedReference}, - Either, -}; -use rspack_core::Stats; - -use super::{JsCompilation, ToJsCompatSource}; - -#[napi(object)] -#[derive(Debug)] -pub struct JsStatsError { - pub message: String, - pub formatted: String, - pub title: String, -} - -impl From for JsStatsError { - fn from(stats: rspack_core::StatsError) -> Self { - Self { - message: stats.message, - formatted: stats.formatted, - title: stats.title, - } - } -} - -#[napi(object)] -pub struct JsStatsWarning { - pub message: String, - pub formatted: String, -} - -impl From for JsStatsWarning { - fn from(stats: rspack_core::StatsWarning) -> Self { - Self { - message: stats.message, - formatted: stats.formatted, - } - } -} - -#[napi(object)] -pub struct JsStatsLogging { - pub name: String, - pub r#type: String, - pub args: Option>, - pub trace: Option>, -} - -impl From<(String, rspack_core::LogType)> for JsStatsLogging { - fn from(value: (String, rspack_core::LogType)) -> Self { - match value.1 { - rspack_core::LogType::Error { message, trace } => Self { - name: value.0, - r#type: "error".to_string(), - args: Some(vec![message]), - trace: Some(trace), - }, - rspack_core::LogType::Warn { message, trace } => Self { - name: value.0, - r#type: "warn".to_string(), - args: Some(vec![message]), - trace: Some(trace), - }, - rspack_core::LogType::Info { message } => Self { - name: value.0, - r#type: "info".to_string(), - args: Some(vec![message]), - trace: None, - }, - rspack_core::LogType::Log { message } => Self { - name: value.0, - r#type: "log".to_string(), - args: Some(vec![message]), - trace: None, - }, - rspack_core::LogType::Debug { message } => Self { - name: value.0, - r#type: "debug".to_string(), - args: Some(vec![message]), - trace: None, - }, - rspack_core::LogType::Trace { message, trace } => Self { - name: value.0, - r#type: "trace".to_string(), - args: Some(vec![message]), - trace: Some(trace), - }, - rspack_core::LogType::Group { message } => Self { - name: value.0, - r#type: "group".to_string(), - args: Some(vec![message]), - trace: None, - }, - rspack_core::LogType::GroupCollapsed { message } => Self { - name: value.0, - r#type: "groupCollapsed".to_string(), - args: Some(vec![message]), - trace: None, - }, - rspack_core::LogType::GroupEnd => Self { - name: value.0, - r#type: "groupEnd".to_string(), - args: None, - trace: None, - }, - rspack_core::LogType::Profile { label } => Self { - name: value.0, - r#type: "profile".to_string(), - args: Some(vec![label.to_string()]), - trace: None, - }, - rspack_core::LogType::ProfileEnd { label } => Self { - name: value.0, - r#type: "profileEnd".to_string(), - args: Some(vec![label.to_string()]), - trace: None, - }, - rspack_core::LogType::Time { - label, - secs, - subsec_nanos, - } => Self { - name: value.0, - r#type: "time".to_string(), - args: Some(vec![format!( - "{}: {} ms", - label, - secs * 1000 + subsec_nanos as u64 / 1000000 - )]), - trace: None, - }, - rspack_core::LogType::Clear => Self { - name: value.0, - r#type: "clear".to_string(), - args: None, - trace: None, - }, - rspack_core::LogType::Status { message } => Self { - name: value.0, - r#type: "status".to_string(), - args: Some(vec![message]), - trace: None, - }, - rspack_core::LogType::Cache { label, hit, total } => Self { - name: value.0, - r#type: "cache".to_string(), - args: Some(vec![format!( - "{}: {:.1}% ({}/{})", - label, - if total == 0 { - 0 as f32 - } else { - hit as f32 / total as f32 * 100_f32 - }, - hit, - total, - )]), - trace: None, - }, - } - } -} - -#[napi(object)] -pub struct JsStatsAsset { - pub r#type: &'static str, - pub name: String, - pub size: f64, - pub chunks: Vec, - pub chunk_names: Vec, - pub info: JsStatsAssetInfo, - pub emitted: bool, -} - -impl From for JsStatsAsset { - fn from(stats: rspack_core::StatsAsset) -> Self { - Self { - r#type: stats.r#type, - name: stats.name, - size: stats.size, - chunks: stats.chunks, - chunk_names: stats.chunk_names, - info: stats.info.into(), - emitted: stats.emitted, - } - } -} - -#[napi(object)] -pub struct JsStatsAssetInfo { - pub development: bool, - pub hot_module_replacement: bool, -} - -impl From for JsStatsAssetInfo { - fn from(stats: rspack_core::StatsAssetInfo) -> Self { - Self { - development: stats.development, - hot_module_replacement: stats.hot_module_replacement, - } - } -} - -type JsStatsModuleSource = Either; -#[napi(object)] -pub struct JsStatsModule { - pub r#type: &'static str, - pub module_type: String, - pub identifier: String, - pub name: String, - pub id: Option, - pub chunks: Vec, - pub size: f64, - pub issuer: Option, - pub issuer_name: Option, - pub issuer_id: Option, - pub issuer_path: Vec, - pub name_for_condition: Option, - pub reasons: Option>, - pub assets: Option>, - pub source: Option>, - pub profile: Option, -} - -impl TryFrom> for JsStatsModule { - type Error = napi::Error; - fn try_from(stats: rspack_core::StatsModule) -> Result { - let source = stats - .source - .map(|source| { - source.to_js_compat_source().map(|js_compat_source| { - if js_compat_source.is_raw && js_compat_source.is_buffer { - JsStatsModuleSource::B(js_compat_source.source) - } else { - let s = String::from_utf8_lossy(js_compat_source.source.as_ref()).to_string(); - JsStatsModuleSource::A(s) - } - }) - }) - .transpose() - .map_err(|e| napi::Error::from_reason(e.to_string()))?; - - Ok(Self { - r#type: stats.r#type, - name: stats.name, - size: stats.size, - chunks: stats.chunks, - module_type: stats.module_type.as_str().to_string(), - identifier: stats.identifier.to_string(), - id: stats.id, - issuer: stats.issuer, - issuer_name: stats.issuer_name, - issuer_id: stats.issuer_id, - name_for_condition: stats.name_for_condition, - issuer_path: stats.issuer_path.into_iter().map(Into::into).collect(), - reasons: stats - .reasons - .map(|i| i.into_iter().map(Into::into).collect()), - assets: stats.assets, - source, - profile: stats.profile.map(|p| p.into()), - }) - } -} - -#[napi(object)] -pub struct JsStatsModuleProfile { - pub factory: JsStatsMillisecond, - pub integration: JsStatsMillisecond, - pub building: JsStatsMillisecond, -} - -impl From for JsStatsModuleProfile { - fn from(value: rspack_core::StatsModuleProfile) -> Self { - Self { - factory: value.factory.into(), - integration: value.integration.into(), - building: value.building.into(), - } - } -} - -#[napi(object)] -pub struct JsStatsMillisecond { - pub secs: u32, - pub subsec_millis: u32, -} - -impl From for JsStatsMillisecond { - fn from(value: rspack_core::StatsMillisecond) -> Self { - Self { - secs: value.secs as u32, - subsec_millis: value.subsec_millis, - } - } -} - -#[napi(object)] -pub struct JsStatsModuleIssuer { - pub identifier: String, - pub name: String, - pub id: Option, -} - -impl From for JsStatsModuleIssuer { - fn from(stats: rspack_core::StatsModuleIssuer) -> Self { - Self { - identifier: stats.identifier, - name: stats.name, - id: stats.id, - } - } -} - -#[napi(object)] -pub struct JsStatsModuleReason { - pub module_identifier: Option, - pub module_name: Option, - pub module_id: Option, - pub r#type: Option, - pub user_request: Option, -} - -impl From for JsStatsModuleReason { - fn from(stats: rspack_core::StatsModuleReason) -> Self { - Self { - module_identifier: stats.module_identifier, - module_name: stats.module_name, - module_id: stats.module_id, - r#type: stats.r#type, - user_request: stats.user_request, - } - } -} - -#[napi(object)] -pub struct JsStatsChunk { - pub r#type: &'static str, - pub files: Vec, - pub auxiliary_files: Vec, - pub id: String, - pub entry: bool, - pub initial: bool, - pub names: Vec, - pub size: f64, - pub modules: Option>, - pub parents: Option>, - pub children: Option>, - pub siblings: Option>, -} - -impl TryFrom> for JsStatsChunk { - type Error = napi::Error; - fn try_from(stats: rspack_core::StatsChunk) -> Result { - Ok(Self { - r#type: stats.r#type, - files: stats.files, - auxiliary_files: stats.auxiliary_files, - id: stats.id, - entry: stats.entry, - initial: stats.initial, - names: stats.names, - size: stats.size, - modules: stats - .modules - .map(|i| i.into_iter().map(|m| m.try_into()).collect::>()) - .transpose()?, - parents: stats.parents, - children: stats.children, - siblings: stats.siblings, - }) - } -} - -#[napi(object)] -pub struct JsStatsChunkGroupAsset { - pub name: String, - pub size: f64, -} - -impl From for JsStatsChunkGroupAsset { - fn from(stats: rspack_core::StatsChunkGroupAsset) -> Self { - Self { - name: stats.name, - size: stats.size, - } - } -} - -#[napi(object)] -pub struct JsStatsChunkGroup { - pub name: String, - pub assets: Vec, - pub chunks: Vec, - pub assets_size: f64, -} - -impl From for JsStatsChunkGroup { - fn from(stats: rspack_core::StatsChunkGroup) -> Self { - Self { - name: stats.name, - assets: stats.assets.into_iter().map(Into::into).collect(), - chunks: stats.chunks, - assets_size: stats.assets_size, - } - } -} - -#[napi(object)] -pub struct JsStatsAssetsByChunkName { - pub name: String, - pub files: Vec, -} - -impl From for JsStatsAssetsByChunkName { - fn from(stats: rspack_core::StatsAssetsByChunkName) -> Self { - Self { - name: stats.name, - files: stats.files, - } - } -} - -#[napi] -pub struct JsStats { - inner: SharedReference>, -} - -impl JsStats { - pub fn new(inner: SharedReference>) -> Self { - Self { inner } - } -} - -#[napi(object)] -pub struct JsStatsGetAssets { - pub assets: Vec, - pub assets_by_chunk_name: Vec, -} - -#[napi] -impl JsStats { - #[napi] - pub fn get_assets(&self) -> JsStatsGetAssets { - let (assets, assets_by_chunk_name) = self.inner.get_assets(); - let assets = assets.into_iter().map(Into::into).collect(); - let assets_by_chunk_name = assets_by_chunk_name.into_iter().map(Into::into).collect(); - JsStatsGetAssets { - assets, - assets_by_chunk_name, - } - } - - #[napi] - pub fn get_modules( - &self, - reasons: bool, - module_assets: bool, - nested_modules: bool, - source: bool, - ) -> Result> { - self - .inner - .get_modules(reasons, module_assets, nested_modules, source) - .map_err(|e| napi::Error::from_reason(e.to_string()))? - .into_iter() - .map(TryInto::try_into) - .collect() - } - - #[napi] - pub fn get_chunks( - &self, - chunk_modules: bool, - chunks_relations: bool, - reasons: bool, - module_assets: bool, - nested_modules: bool, - source: bool, - ) -> Result> { - self - .inner - .get_chunks( - chunk_modules, - chunks_relations, - reasons, - module_assets, - nested_modules, - source, - ) - .map_err(|e| napi::Error::from_reason(e.to_string()))? - .into_iter() - .map(TryInto::try_into) - .collect() - } - - #[napi] - pub fn get_entrypoints(&self) -> Vec { - self - .inner - .get_entrypoints() - .into_iter() - .map(Into::into) - .collect() - } - - #[napi] - pub fn get_named_chunk_groups(&self) -> Vec { - self - .inner - .get_named_chunk_groups() - .into_iter() - .map(Into::into) - .collect() - } - - #[napi] - pub fn get_errors(&self) -> Vec { - self - .inner - .get_errors() - .into_iter() - .map(Into::into) - .collect() - } - - #[napi] - pub fn get_warnings(&self) -> Vec { - self - .inner - .get_warnings() - .into_iter() - .map(Into::into) - .collect() - } - - #[napi] - pub fn get_logging(&self, accepted_types: u32) -> Vec { - self - .inner - .get_logging() - .into_iter() - .filter(|log| { - let bit = log.1.to_bit_flag(); - accepted_types & bit == bit - }) - .map(Into::into) - .collect() - } - - #[napi(catch_unwind)] - pub fn get_hash(&self) -> String { - self - .inner - .get_hash() - .expect("should have hash in stats::get_hash") - .to_string() - } -} diff --git a/crates/node_binding/src/lib.rs b/crates/node_binding/src/lib.rs index b3c9180..c6be2e5 100644 --- a/crates/node_binding/src/lib.rs +++ b/crates/node_binding/src/lib.rs @@ -4,9 +4,6 @@ #[macro_use] extern crate napi_derive; -#[macro_use] -extern crate rspack_binding_macros; - use std::collections::HashSet; use std::pin::Pin; use std::sync::atomic::{AtomicU32, Ordering}; @@ -14,28 +11,25 @@ use std::sync::Mutex; use napi::bindgen_prelude::*; use once_cell::sync::Lazy; +use rspack_binding_options::BuiltinPlugin; use binding_options::RSPackRawOptions; +use rspack_binding_values::SingleThreadedHashMap; use rspack_core::PluginExt; use rspack_fs_node::{AsyncNodeWritableFileSystem, ThreadsafeNodeFS}; use rspack_napi_shared::NAPI_ENV; mod hook; -mod js_values; mod loader; mod plugins; -mod utils; use hook::*; -use js_values::*; - // Napi macro registered this successfully #[allow(unused)] -use loader::*; +use loader::run_builtin_loader; use plugins::*; use rspack_binding_options::*; +use rspack_binding_values::*; use rspack_tracing::chrome::FlushGuard; -use utils::*; - #[cfg(not(target_os = "linux"))] #[global_allocator] static GLOBAL: mimalloc_rust::GlobalMiMalloc = mimalloc_rust::GlobalMiMalloc; @@ -280,7 +274,9 @@ pub fn cleanup_global_trace() { let mut state = GLOBAL_TRACE_STATE .lock() .expect("Failed to lock GLOBAL_TRACE_STATE"); - if let TraceState::On(guard) = &mut *state && let Some(g) = guard.take() { + if let TraceState::On(guard) = &mut *state + && let Some(g) = guard.take() + { g.flush(); drop(g); let new_state = TraceState::Off; diff --git a/crates/node_binding/src/loader.rs b/crates/node_binding/src/loader.rs index 03eb3b9..cc28833 100644 --- a/crates/node_binding/src/loader.rs +++ b/crates/node_binding/src/loader.rs @@ -1,6 +1,5 @@ use napi::Result; use rspack_binding_options::JsLoaderContext; -use binding_options::run_builtin_loader as run_builtin; /// Builtin loader runner #[napi(catch_unwind)] @@ -10,5 +9,5 @@ pub async fn run_builtin_loader( options: Option, loader_context: JsLoaderContext, ) -> Result { - run_builtin(builtin, options.as_deref(), loader_context).await + binding_options::run_builtin_loader(builtin, options.as_deref(), loader_context).await } diff --git a/crates/node_binding/src/plugins/mod.rs b/crates/node_binding/src/plugins/mod.rs index 619404e..0086057 100644 --- a/crates/node_binding/src/plugins/mod.rs +++ b/crates/node_binding/src/plugins/mod.rs @@ -6,6 +6,10 @@ use async_trait::async_trait; pub use loader::JsLoaderResolver; use napi::{Env, Result}; use rspack_binding_macros::js_fn_into_threadsafe_fn; +use rspack_binding_values::{ + AfterResolveData, BeforeResolveData, JsAssetEmittedArgs, JsChunkAssetArgs, JsModule, + JsResolveForSchemeInput, JsResolveForSchemeResult, ToJsModule, +}; use rspack_core::{ ChunkAssetArgs, NormalModuleAfterResolveArgs, NormalModuleBeforeResolveArgs, PluginNormalModuleFactoryAfterResolveOutput, PluginNormalModuleFactoryBeforeResolveOutput, @@ -15,10 +19,6 @@ use rspack_error::internal_error; use rspack_napi_shared::threadsafe_function::{ThreadsafeFunction, ThreadsafeFunctionCallMode}; use rspack_napi_shared::NapiResultExt; -use crate::js_values::{ - AfterResolveData, BeforeResolveData, JsAssetEmittedArgs, JsChunkAssetArgs, JsModule, - JsResolveForSchemeInput, JsResolveForSchemeResult, ToJsModule, -}; use crate::{DisabledHooks, Hook, JsCompilation, JsHooks}; pub struct JsHooksAdapter { @@ -714,13 +714,12 @@ impl rspack_core::Plugin for JsHooksAdapter { if self.is_hook_disabled(&Hook::SucceedModule) { return Ok(()); } - + let js_module = args + .to_js_module() + .expect("Failed to convert module to JsModule"); self .succeed_module_tsfn - .call( - args.to_js_module().expect("Convert to js_module failed."), - ThreadsafeFunctionCallMode::NonBlocking, - ) + .call(js_module, ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await .map_err(|err| internal_error!("Failed to call succeed_module hook: {err}"))? diff --git a/crates/node_binding/src/utils.rs b/crates/node_binding/src/utils.rs deleted file mode 100644 index 4e1104a..0000000 --- a/crates/node_binding/src/utils.rs +++ /dev/null @@ -1,203 +0,0 @@ -use std::ffi::CStr; -use std::io::Write; -use std::ptr; - -use dashmap::DashMap; -use futures::Future; -use napi::bindgen_prelude::*; -use napi::{check_status, Env, Error, JsFunction, JsUnknown, NapiRaw, Result}; -use rspack_error::CatchUnwindFuture; -use rspack_napi_shared::threadsafe_function::{ - ThreadSafeContext, ThreadsafeFunction, ThreadsafeFunctionCallMode, -}; - -/// Try to resolve the string value of a given named property -#[allow(unused)] -pub(crate) fn get_named_property_value_string( - env: Env, - object: T, - property_name: &str, -) -> Result { - let mut bytes_with_nul: Vec = Vec::with_capacity(property_name.len() + 1); - - write!(&mut bytes_with_nul, "{property_name}")?; - write!(&mut bytes_with_nul, "\0")?; - - let mut value_ptr = ptr::null_mut(); - - check_status!( - unsafe { - napi_sys::napi_get_named_property( - env.raw(), - object.raw(), - CStr::from_bytes_with_nul_unchecked(&bytes_with_nul).as_ptr(), - &mut value_ptr, - ) - }, - "failed to get the value" - )?; - - let mut str_len = 0; - check_status!( - unsafe { - napi_sys::napi_get_value_string_utf8(env.raw(), value_ptr, ptr::null_mut(), 0, &mut str_len) - }, - "failed to get the value" - )?; - - str_len += 1; - let mut buf = Vec::with_capacity(str_len); - let mut copied_len = 0; - - check_status!( - unsafe { - napi_sys::napi_get_value_string_utf8( - env.raw(), - value_ptr, - buf.as_mut_ptr(), - str_len, - &mut copied_len, - ) - }, - "failed to get the value" - )?; - - // Vec -> Vec See: https://stackoverflow.com/questions/59707349/cast-vector-of-i8-to-vector-of-u8-in-rust - let mut buf = std::mem::ManuallyDrop::new(buf); - - let buf = unsafe { Vec::from_raw_parts(buf.as_mut_ptr() as *mut u8, copied_len, copied_len) }; - - String::from_utf8(buf).map_err(|_| Error::from_reason("failed to get property")) -} - -pub fn callbackify(env: Env, f: JsFunction, fut: F) -> Result<()> -where - R: 'static + ToNapiValue, - F: 'static + Send + Future>, -{ - let ptr = unsafe { f.raw() }; - - let tsfn = ThreadsafeFunction::, ()>::create(env.raw(), ptr, 0, |ctx| { - let ThreadSafeContext { - value, - env, - callback, - .. - } = ctx; - - let argv = match value { - Ok(value) => { - let val = unsafe { R::to_napi_value(env.raw(), value)? }; - let js_value = unsafe { JsUnknown::from_napi_value(env.raw(), val)? }; - vec![env.get_null()?.into_unknown(), js_value] - } - Err(err) => { - vec![JsError::from(err).into_unknown(env)] - } - }; - - callback.call(None, &argv)?; - - Ok(()) - })?; - - napi::bindgen_prelude::spawn(async move { - let fut = CatchUnwindFuture::create(fut); - let res = fut.await; - match res { - Ok(result) => { - tsfn - .call(result, ThreadsafeFunctionCallMode::NonBlocking) - .expect("Failed to call JS callback"); - } - Err(e) => { - tsfn - .call( - Err(Error::from_reason(format!("{e}"))), - ThreadsafeFunctionCallMode::NonBlocking, - ) - .expect("Failed to send panic info"); - } - } - }); - - Ok(()) -} - -// **Note** that Node's main thread and the worker thread share the same binding context. Using `Mutex` would cause deadlocks if multiple compilers exist. -pub(crate) struct SingleThreadedHashMap(DashMap); - -impl SingleThreadedHashMap -where - K: Eq + std::hash::Hash + std::fmt::Display, -{ - /// Acquire a mutable reference to the inner hashmap. - /// - /// Safety: Mutable reference can almost let you do anything you want, this is intended to be used from the thread where the map was created. - pub(crate) unsafe fn borrow_mut(&self, key: &K, f: F) -> Result - where - F: FnOnce(&mut V) -> Result, - { - let mut inner = self.0.get_mut(key).ok_or_else(|| { - napi::Error::from_reason(format!( - "Failed to find key {key} for single-threaded hashmap", - )) - })?; - - f(&mut inner) - } - - /// Acquire a shared reference to the inner hashmap. - /// - /// Safety: It's not thread-safe if a value is not safe to modify cross thread boundary, so this is intended to be used from the thread where the map was created. - #[allow(unused)] - pub(crate) unsafe fn borrow(&self, key: &K, f: F) -> Result - where - F: FnOnce(&V) -> Result, - { - let inner = self.0.get(key).ok_or_else(|| { - napi::Error::from_reason(format!( - "Failed to find key {key} for single-threaded hashmap", - )) - })?; - - f(&*inner) - } - - /// Insert a value into the map. - /// - /// Safety: It's not thread-safe if a value has thread affinity, so this is intended to be used from the thread where the map was created. - pub(crate) unsafe fn insert_if_vacant(&self, key: K, value: V) -> Result<()> { - if let dashmap::mapref::entry::Entry::Vacant(vacant) = self.0.entry(key) { - vacant.insert(value); - Ok(()) - } else { - Err(napi::Error::from_reason( - "Failed to insert on single-threaded hashmap as it's not vacant", - )) - } - } - - /// Remove a value from the map. - /// - /// See: [DashMap::remove] for more details. https://docs.rs/dashmap/latest/dashmap/struct.DashMap.html#method.remove - /// - /// Safety: It's not thread-safe if a value has thread affinity, so this is intended to be used from the thread where the map was created. - #[allow(unused)] - pub(crate) unsafe fn remove(&self, key: &K) -> Option { - self.0.remove(key).map(|(_, v)| v) - } -} - -impl Default for SingleThreadedHashMap -where - K: Eq + std::hash::Hash, -{ - fn default() -> Self { - Self(Default::default()) - } -} - -// Safety: Methods are already marked as unsafe. -unsafe impl Send for SingleThreadedHashMap {} -unsafe impl Sync for SingleThreadedHashMap {} diff --git a/rust-toolchain.toml b/rust-toolchain.toml index bf354c4..51177fb 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,5 @@ [toolchain] profile = "default" -channel = "nightly-2023-06-02" +# Use nightly for better access to the latest Rust features. +# This date is aligned to stable release dates. +channel = "nightly-2023-10-24"