From 0dd215fb10e69e2abf6ecc53813b7dffb93e6e56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=B2=E5=B0=98?= Date: Mon, 30 Oct 2023 16:34:33 +0800 Subject: [PATCH 01/32] feat: support built-in loader of compilation --- crates/loader_compilation/src/lib.rs | 57 ++++++++++++++++-- crates/loader_compilation/src/options.rs | 0 .../loader_compilation/src/transform/mod.rs | 60 +++++++++++++++++++ 3 files changed, 111 insertions(+), 6 deletions(-) create mode 100644 crates/loader_compilation/src/options.rs create mode 100644 crates/loader_compilation/src/transform/mod.rs diff --git a/crates/loader_compilation/src/lib.rs b/crates/loader_compilation/src/lib.rs index 34570bc..4f61f07 100644 --- a/crates/loader_compilation/src/lib.rs +++ b/crates/loader_compilation/src/lib.rs @@ -1,10 +1,21 @@ +use std::sync::Arc; use rspack_core::{rspack_sources::SourceMap, LoaderRunnerContext, Mode}; use rspack_loader_runner::{Identifiable, Identifier, Loader, LoaderContext}; use rspack_error::{ internal_error, Diagnostic, DiagnosticKind, Error, InternalError, Result, Severity, TraceableError, }; - +use swc_core::{ + base::{ + Compiler, + config::{InputSourceMap, Options}, + try_with_handler + }, + common::{FilePathMapping,GLOBALS, FileName, comments::SingleThreadedComments}, + ecma::transforms::base::pass::noop +}; +mod transform; +use transform::*; pub struct CompilationLoader { identifier: Identifier, } @@ -28,14 +39,48 @@ impl CompilationLoader { #[async_trait::async_trait] impl Loader for CompilationLoader { async fn run(&self, loader_context: &mut LoaderContext<'_, LoaderRunnerContext>) -> Result<()> { + let resource_path = loader_context.resource_path.to_path_buf(); let Some(content) = std::mem::take(&mut loader_context.content) else { return Err(internal_error!("No content found")); }; - let mut source = content.try_into_string()?; - source += r#" -window.__custom_code__ = true; -"#; - loader_context.content = Some(source.into()); + + let compiler = Compiler::new(Arc::from(swc_core::common::SourceMap::new(FilePathMapping::empty()))); + // TODO: init loader with custom options. + let mut swc_options = Options::default(); + + // TODO: merge config with built-in config. + + if let Some(pre_source_map) = std::mem::take(&mut loader_context.source_map) { + if let Ok(source_map) = pre_source_map.to_json() { + swc_options.config.input_source_map = Some(InputSourceMap:: Str(source_map)) + } + } + + GLOBALS.set(&Default::default(), || { + try_with_handler(compiler.cm.clone(), Default::default(), |handler| { + compiler.run(|| { + let content = content.try_into_string()?; + let fm = compiler.cm.new_source_file(FileName::Real(resource_path.clone()), content.clone()); + let comments = SingleThreadedComments::default(); + let transform_options = SwcPluginOptions { + keep_export: None, + remove_export: None, + }; + let out = compiler.process_js_with_custom_pass( + fm, + None, + handler, + &swc_options, + comments, |_| { + transform(transform_options) + }, + |_| noop(), + )?; + Ok(()) + }) + }) + })?; + Ok(()) } } diff --git a/crates/loader_compilation/src/options.rs b/crates/loader_compilation/src/options.rs new file mode 100644 index 0000000..e69de29 diff --git a/crates/loader_compilation/src/transform/mod.rs b/crates/loader_compilation/src/transform/mod.rs new file mode 100644 index 0000000..e0e15f8 --- /dev/null +++ b/crates/loader_compilation/src/transform/mod.rs @@ -0,0 +1,60 @@ +use either::Either; +use swc_core::common::chain; +use swc_core::ecma::{ + transforms::base::pass::noop, + visit::{as_folder, Fold, VisitMut}, + ast::Module, +}; + +macro_rules! either { + ($config:expr, $f:expr) => { + if let Some(config) = &$config { + Either::Left($f(config)) + } else { + Either::Right(noop()) + } + }; + ($config:expr, $f:expr, $enabled:expr) => { + if $enabled { + either!($config, $f) + } else { + Either::Right(noop()) + } + }; +} + +pub struct KeepExportOptions { + export_names: Vec, +} + +pub struct RemoveExport { + remove_names: Vec, +} + +pub struct SwcPluginOptions { + pub keep_export: Option, + pub remove_export: Option, +} + +pub(crate) fn transform<'a>(plugin_options: SwcPluginOptions) -> impl Fold + 'a { + chain!( + either!(plugin_options.keep_export, |_| { + keep_export() + }), + either!(plugin_options.remove_export, |_| { + keep_export() + }), + ) +} + +struct KeepExport; + +impl VisitMut for KeepExport { + fn visit_mut_module(&mut self, module: &mut Module) { + + } +} + +fn keep_export() -> impl Fold { + as_folder(KeepExport) +} \ No newline at end of file From 1cf0af4fc76a4c08d0f6f12d493761c36c2b8b7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=B2=E5=B0=98?= Date: Mon, 30 Oct 2023 17:47:07 +0800 Subject: [PATCH 02/32] fix: bump rspack_core version --- Cargo.toml | 73 +- .../binding_options/src/options/js_loader.rs | 28 +- crates/binding_options/src/options/mod.rs | 6 +- crates/node_binding/src/lib.rs | 1 - crates/node_binding/src/loader.rs | 3 +- pnpm-lock.yaml | 1071 +++-------------- scripts/clone-rspack.mjs | 2 +- 7 files changed, 229 insertions(+), 955 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e8df955..3930002 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,30 +9,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" } @@ -43,49 +34,59 @@ 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" } 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.9", default-features = false } +swc_css = { version = "0.157.1" } +swc_ecma_minifier = { version = "0.189.9", default-features = false } +swc_emotion = { version = "=0.53.0" } +swc_error_reporters = { version = "=0.17.0" } +swc_html = { version = "=0.134.10" } +swc_html_minifier = { version = "=0.131.9" } +swc_node_comments = { version = "=0.20.0" } 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 = "4a1a233" } +swc_core = { git = "https://github.com/swc-project/swc.git", rev = "4a1a233" } +swc_ecma_minifier = { git = "https://github.com/swc-project/swc.git", rev = "4a1a233" } +swc_error_reporters = { git = "https://github.com/swc-project/swc.git", rev = "4a1a233" } +swc_html = { git = "https://github.com/swc-project/swc.git", rev = "4a1a233" } +swc_html_minifier = { git = "https://github.com/swc-project/swc.git", rev = "4a1a233" } +swc_node_comments = { git = "https://github.com/swc-project/swc.git", rev = "4a1a233" } +swc_common = { git = "https://github.com/swc-project/swc.git", rev = "4a1a233" } +swc_ecma_utils = { git = "https://github.com/swc-project/swc.git", rev = "4a1a233" } +swc_ecma_ast = { git = "https://github.com/swc-project/swc.git", rev = "4a1a233" } +swc_ecma_visit = { git = "https://github.com/swc-project/swc.git", rev = "4a1a233" } +swc_atoms = { git = "https://github.com/swc-project/swc.git", rev = "4a1a233" } +preset_env_base = { git = "https://github.com/swc-project/swc.git", rev = "4a1a233" } [profile.dev] debug = 2 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 786396a..414bb5a 100644 --- a/crates/binding_options/src/options/mod.rs +++ b/crates/binding_options/src/options/mod.rs @@ -9,7 +9,7 @@ use rspack_binding_options::{ RawMode, RawNodeOption, RawOptimizationOptions, RawOutputOptions, RawResolveOptions, RawSnapshotOptions, RawStatsOptions, RawTarget, RawOptionsApply, RawModuleOptions, }; -use rspack_plugin_javascript::{FlagDependencyExportsPlugin, FlagDependencyUsagePlugin}; +use rspack_plugin_javascript::{FlagDependencyExportsPlugin, FlagDependencyUsagePlugin, SideEffectsFlagPlugin}; use serde::Deserialize; mod raw_module; @@ -72,6 +72,7 @@ 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 = IS_ENABLE_NEW_SPLIT_CHUNKS.set(&experiments.new_split_chunks, || { @@ -128,6 +129,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()); } diff --git a/crates/node_binding/src/lib.rs b/crates/node_binding/src/lib.rs index b3c9180..262a360 100644 --- a/crates/node_binding/src/lib.rs +++ b/crates/node_binding/src/lib.rs @@ -27,7 +27,6 @@ mod utils; use hook::*; use js_values::*; - // Napi macro registered this successfully #[allow(unused)] use loader::*; 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/pnpm-lock.yaml b/pnpm-lock.yaml index 2786b92..eccca0c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,55 +1,61 @@ -lockfileVersion: 5.4 +lockfileVersion: '6.0' + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false importers: .: - specifiers: - fs-extra: ^11.1.1 - git-clone: 0.2.0 - ora: ^7.0.1 - rimraf: ^5.0.5 devDependencies: - fs-extra: 11.1.1 - git-clone: 0.2.0 - ora: 7.0.1 - rimraf: 5.0.5 + fs-extra: + specifier: ^11.1.1 + version: 11.1.1 + git-clone: + specifier: 0.2.0 + version: 0.2.0 + ora: + specifier: ^7.0.1 + version: 7.0.1 + rimraf: + specifier: ^5.0.5 + version: 5.0.5 crates/node_binding: - specifiers: - '@napi-rs/cli': 3.0.0-alpha.3 - ava: ^5.1.1 - call-bind: 1.0.2 devDependencies: - '@napi-rs/cli': 3.0.0-alpha.3 - ava: 5.3.1 - call-bind: 1.0.2 + '@napi-rs/cli': + specifier: 3.0.0-alpha.3 + version: 3.0.0-alpha.3 + call-bind: + specifier: 1.0.2 + version: 1.0.2 packages: - /@isaacs/cliui/8.0.2: + /@isaacs/cliui@8.0.2: resolution: {integrity: sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==} engines: {node: '>=12'} dependencies: string-width: 5.1.2 - string-width-cjs: /string-width/4.2.3 + string-width-cjs: /string-width@4.2.3 strip-ansi: 7.1.0 - strip-ansi-cjs: /strip-ansi/6.0.1 + strip-ansi-cjs: /strip-ansi@6.0.1 wrap-ansi: 8.1.0 - wrap-ansi-cjs: /wrap-ansi/7.0.0 + wrap-ansi-cjs: /wrap-ansi@7.0.0 dev: true - /@ljharb/through/2.3.10: + /@ljharb/through@2.3.10: resolution: {integrity: sha512-NwkQ4+jf4tMpDSlRc1wlttHnC7KfII+SjdqDEwEuQ7W0IaTK5Ab1jxCJrH6pYsLbLXiQgRn+nFQsGmKowbAKkA==} engines: {node: '>= 0.4'} dev: true - /@napi-rs/cli/3.0.0-alpha.3: + /@napi-rs/cli@3.0.0-alpha.3: resolution: {integrity: sha512-s5RHKqbqUVVfwgr/wO7S/vdqQ9shQzvIETgdz57r1Gg4bRv8kqy2Q1LfJAQJ09Y9Ddao9jKErvz4+11gHZZrWA==} engines: {node: '>= 16'} hasBin: true dependencies: '@octokit/rest': 19.0.13 - clipanion: 3.2.1 + clipanion: 3.2.1(typanion@3.14.0) colorette: 2.0.20 debug: 4.3.4 inquirer: 9.2.11 @@ -61,33 +67,12 @@ packages: - supports-color dev: true - /@nodelib/fs.scandir/2.1.5: - resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==} - engines: {node: '>= 8'} - dependencies: - '@nodelib/fs.stat': 2.0.5 - run-parallel: 1.2.0 - dev: true - - /@nodelib/fs.stat/2.0.5: - resolution: {integrity: sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==} - engines: {node: '>= 8'} - dev: true - - /@nodelib/fs.walk/1.2.8: - resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==} - engines: {node: '>= 8'} - dependencies: - '@nodelib/fs.scandir': 2.1.5 - fastq: 1.15.0 - dev: true - - /@octokit/auth-token/3.0.4: + /@octokit/auth-token@3.0.4: resolution: {integrity: sha512-TWFX7cZF2LXoCvdmJWY7XVPi74aSY0+FfBZNSXEXFkMpjcqsQwDSYVv5FhRFaI0V1ECnwbz4j59T/G+rXNWaIQ==} engines: {node: '>= 14'} dev: true - /@octokit/core/4.2.4: + /@octokit/core@4.2.4: resolution: {integrity: sha512-rYKilwgzQ7/imScn3M9/pFfUf4I1AZEH3KhyJmtPdE2zfaXAn2mFfUy4FbKewzc2We5y/LlKLj36fWJLKC2SIQ==} engines: {node: '>= 14'} dependencies: @@ -102,7 +87,7 @@ packages: - encoding dev: true - /@octokit/endpoint/7.0.6: + /@octokit/endpoint@7.0.6: resolution: {integrity: sha512-5L4fseVRUsDFGR00tMWD/Trdeeihn999rTMGRMC1G/Ldi1uWlWJzI98H4Iak5DB/RVvQuyMYKqSK/R6mbSOQyg==} engines: {node: '>= 14'} dependencies: @@ -111,7 +96,7 @@ packages: universal-user-agent: 6.0.0 dev: true - /@octokit/graphql/5.0.6: + /@octokit/graphql@5.0.6: resolution: {integrity: sha512-Fxyxdy/JH0MnIB5h+UQ3yCoh1FG4kWXfFKkpWqjZHw/p+Kc8Y44Hu/kCgNBT6nU1shNumEchmW/sUO1JuQnPcw==} engines: {node: '>= 14'} dependencies: @@ -122,11 +107,11 @@ packages: - encoding dev: true - /@octokit/openapi-types/18.1.1: + /@octokit/openapi-types@18.1.1: resolution: {integrity: sha512-VRaeH8nCDtF5aXWnjPuEMIYf1itK/s3JYyJcWFJT8X9pSNnBtriDf7wlEWsGuhPLl4QIH4xM8fqTXDwJ3Mu6sw==} dev: true - /@octokit/plugin-paginate-rest/6.1.2_@octokit+core@4.2.4: + /@octokit/plugin-paginate-rest@6.1.2(@octokit/core@4.2.4): resolution: {integrity: sha512-qhrmtQeHU/IivxucOV1bbI/xZyC/iOBhclokv7Sut5vnejAIAEXVcGQeRpQlU39E0WwK9lNvJHphHri/DB6lbQ==} engines: {node: '>= 14'} peerDependencies: @@ -137,7 +122,7 @@ packages: '@octokit/types': 9.3.2 dev: true - /@octokit/plugin-request-log/1.0.4_@octokit+core@4.2.4: + /@octokit/plugin-request-log@1.0.4(@octokit/core@4.2.4): resolution: {integrity: sha512-mLUsMkgP7K/cnFEw07kWqXGF5LKrOkD+lhCrKvPHXWDywAwuDUeDwWBpc69XK3pNX0uKiVt8g5z96PJ6z9xCFA==} peerDependencies: '@octokit/core': '>=3' @@ -145,7 +130,7 @@ packages: '@octokit/core': 4.2.4 dev: true - /@octokit/plugin-rest-endpoint-methods/7.2.3_@octokit+core@4.2.4: + /@octokit/plugin-rest-endpoint-methods@7.2.3(@octokit/core@4.2.4): resolution: {integrity: sha512-I5Gml6kTAkzVlN7KCtjOM+Ruwe/rQppp0QU372K1GP7kNOYEKe8Xn5BW4sE62JAHdwpq95OQK/qGNyKQMUzVgA==} engines: {node: '>= 14'} peerDependencies: @@ -155,7 +140,7 @@ packages: '@octokit/types': 10.0.0 dev: true - /@octokit/request-error/3.0.3: + /@octokit/request-error@3.0.3: resolution: {integrity: sha512-crqw3V5Iy2uOU5Np+8M/YexTlT8zxCfI+qu+LxUB7SZpje4Qmx3mub5DfEKSO8Ylyk0aogi6TYdf6kxzh2BguQ==} engines: {node: '>= 14'} dependencies: @@ -164,7 +149,7 @@ packages: once: 1.4.0 dev: true - /@octokit/request/6.2.8: + /@octokit/request@6.2.8: resolution: {integrity: sha512-ow4+pkVQ+6XVVsekSYBzJC0VTVvh/FCTUUgTsboGq+DTeWdyIFV8WSCdo0RIxk6wSkBTHqIK1mYuY7nOBXOchw==} engines: {node: '>= 14'} dependencies: @@ -178,197 +163,87 @@ packages: - encoding dev: true - /@octokit/rest/19.0.13: + /@octokit/rest@19.0.13: resolution: {integrity: sha512-/EzVox5V9gYGdbAI+ovYj3nXQT1TtTHRT+0eZPcuC05UFSWO3mdO9UY1C0i2eLF9Un1ONJkAk+IEtYGAC+TahA==} engines: {node: '>= 14'} dependencies: '@octokit/core': 4.2.4 - '@octokit/plugin-paginate-rest': 6.1.2_@octokit+core@4.2.4 - '@octokit/plugin-request-log': 1.0.4_@octokit+core@4.2.4 - '@octokit/plugin-rest-endpoint-methods': 7.2.3_@octokit+core@4.2.4 + '@octokit/plugin-paginate-rest': 6.1.2(@octokit/core@4.2.4) + '@octokit/plugin-request-log': 1.0.4(@octokit/core@4.2.4) + '@octokit/plugin-rest-endpoint-methods': 7.2.3(@octokit/core@4.2.4) transitivePeerDependencies: - encoding dev: true - /@octokit/tsconfig/1.0.2: + /@octokit/tsconfig@1.0.2: resolution: {integrity: sha512-I0vDR0rdtP8p2lGMzvsJzbhdOWy405HcGovrspJ8RRibHnyRgggUSNO5AIox5LmqiwmatHKYsvj6VGFHkqS7lA==} dev: true - /@octokit/types/10.0.0: + /@octokit/types@10.0.0: resolution: {integrity: sha512-Vm8IddVmhCgU1fxC1eyinpwqzXPEYu0NrYzD3YZjlGjyftdLBTeqNblRC0jmJmgxbJIsQlyogVeGnrNaaMVzIg==} dependencies: '@octokit/openapi-types': 18.1.1 dev: true - /@octokit/types/9.3.2: + /@octokit/types@9.3.2: resolution: {integrity: sha512-D4iHGTdAnEEVsB8fl95m1hiz7D5YiRdQ9b/OEb3BYRVwbLsGHcRVPz+u+BgRLNk0Q0/4iZCBqDN96j2XNxfXrA==} dependencies: '@octokit/openapi-types': 18.1.1 dev: true - /@pkgjs/parseargs/0.11.0: + /@pkgjs/parseargs@0.11.0: resolution: {integrity: sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==} engines: {node: '>=14'} requiresBuild: true dev: true optional: true - /acorn-walk/8.2.0: - resolution: {integrity: sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==} - engines: {node: '>=0.4.0'} - dev: true - - /acorn/8.10.0: - resolution: {integrity: sha512-F0SAmZ8iUtS//m8DmCTA0jlh6TDKkHQyK6xc6V4KDTyZKA9dnvX9/3sRTVQrWm79glUAZbnmmNcdYwUIHWVybw==} - engines: {node: '>=0.4.0'} - hasBin: true - dev: true - - /aggregate-error/4.0.1: - resolution: {integrity: sha512-0poP0T7el6Vq3rstR8Mn4V/IQrpBLO6POkUSrN7RhyY+GF/InCFShQzsQ39T25gkHhLgSLByyAz+Kjb+c2L98w==} - engines: {node: '>=12'} - dependencies: - clean-stack: 4.2.0 - indent-string: 5.0.0 - dev: true - - /ansi-escapes/4.3.2: + /ansi-escapes@4.3.2: resolution: {integrity: sha512-gKXj5ALrKWQLsYG9jlTRmR/xKluxHV+Z9QEwNIgCfM1/uwPMCuzVVnh5mwTd+OuBZcwSIMbqssNWRm1lE51QaQ==} engines: {node: '>=8'} dependencies: type-fest: 0.21.3 dev: true - /ansi-regex/5.0.1: + /ansi-regex@5.0.1: resolution: {integrity: sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==} engines: {node: '>=8'} dev: true - /ansi-regex/6.0.1: + /ansi-regex@6.0.1: resolution: {integrity: sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==} engines: {node: '>=12'} dev: true - /ansi-styles/4.3.0: + /ansi-styles@4.3.0: resolution: {integrity: sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==} engines: {node: '>=8'} dependencies: color-convert: 2.0.1 dev: true - /ansi-styles/6.2.1: + /ansi-styles@6.2.1: resolution: {integrity: sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==} engines: {node: '>=12'} dev: true - /anymatch/3.1.3: - resolution: {integrity: sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==} - engines: {node: '>= 8'} - dependencies: - normalize-path: 3.0.0 - picomatch: 2.3.1 - dev: true - - /argparse/1.0.10: - resolution: {integrity: sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==} - dependencies: - sprintf-js: 1.0.3 - dev: true - - /argparse/2.0.1: + /argparse@2.0.1: resolution: {integrity: sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==} dev: true - /array-find-index/1.0.2: - resolution: {integrity: sha512-M1HQyIXcBGtVywBt8WVdim+lrNaK7VHp99Qt5pSNziXznKHViIBbXWtfRTpEFpF/c4FdfxNAsCCwPp5phBYJtw==} - engines: {node: '>=0.10.0'} - dev: true - - /arrgv/1.0.2: - resolution: {integrity: sha512-a4eg4yhp7mmruZDQFqVMlxNRFGi/i1r87pt8SDHy0/I8PqSXoUTlWZRdAZo0VXgvEARcujbtTk8kiZRi1uDGRw==} - engines: {node: '>=8.0.0'} - dev: true - - /arrify/3.0.0: - resolution: {integrity: sha512-tLkvA81vQG/XqE2mjDkGQHoOINtMHtysSnemrmoGe6PydDPMRbVugqyk4A6V/WDWEfm3l+0d8anA9r8cv/5Jaw==} - engines: {node: '>=12'} - dev: true - - /ava/5.3.1: - resolution: {integrity: sha512-Scv9a4gMOXB6+ni4toLuhAm9KYWEjsgBglJl+kMGI5+IVDt120CCDZyB5HNU9DjmLI2t4I0GbnxGLmmRfGTJGg==} - engines: {node: '>=14.19 <15 || >=16.15 <17 || >=18'} - hasBin: true - peerDependencies: - '@ava/typescript': '*' - peerDependenciesMeta: - '@ava/typescript': - optional: true - dependencies: - acorn: 8.10.0 - acorn-walk: 8.2.0 - ansi-styles: 6.2.1 - arrgv: 1.0.2 - arrify: 3.0.0 - callsites: 4.1.0 - cbor: 8.1.0 - chalk: 5.3.0 - chokidar: 3.5.3 - chunkd: 2.0.1 - ci-info: 3.9.0 - ci-parallel-vars: 1.0.1 - clean-yaml-object: 0.1.0 - cli-truncate: 3.1.0 - code-excerpt: 4.0.0 - common-path-prefix: 3.0.0 - concordance: 5.0.4 - currently-unhandled: 0.4.1 - debug: 4.3.4 - emittery: 1.0.1 - figures: 5.0.0 - globby: 13.2.2 - ignore-by-default: 2.1.0 - indent-string: 5.0.0 - is-error: 2.2.2 - is-plain-object: 5.0.0 - is-promise: 4.0.0 - matcher: 5.0.0 - mem: 9.0.2 - ms: 2.1.3 - p-event: 5.0.1 - p-map: 5.5.0 - picomatch: 2.3.1 - pkg-conf: 4.0.0 - plur: 5.1.0 - pretty-ms: 8.0.0 - resolve-cwd: 3.0.0 - stack-utils: 2.0.6 - strip-ansi: 7.1.0 - supertap: 3.0.1 - temp-dir: 3.0.0 - write-file-atomic: 5.0.1 - yargs: 17.7.2 - transitivePeerDependencies: - - supports-color - dev: true - - /balanced-match/1.0.2: + /balanced-match@1.0.2: resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} dev: true - /base64-js/1.5.1: + /base64-js@1.5.1: resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==} dev: true - /before-after-hook/2.2.3: + /before-after-hook@2.2.3: resolution: {integrity: sha512-NzUnlZexiaH/46WDhANlyR2bXRopNg4F/zuSA3OpZnllCUgRaOF2znDioDWrmbNVsuZk6l9pMquQB38cfBZwkQ==} dev: true - /binary-extensions/2.2.0: - resolution: {integrity: sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==} - engines: {node: '>=8'} - dev: true - - /bl/4.1.0: + /bl@4.1.0: resolution: {integrity: sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==} dependencies: buffer: 5.7.1 @@ -376,7 +251,7 @@ packages: readable-stream: 3.6.2 dev: true - /bl/5.1.0: + /bl@5.1.0: resolution: {integrity: sha512-tv1ZJHLfTDnXE6tMHv73YgSJaWR2AFuPwMntBe7XL/GBFHnT0CLnsHMogfk5+GzCDC5ZWarSCYaIGATZt9dNsQ==} dependencies: buffer: 6.0.3 @@ -384,57 +259,34 @@ packages: readable-stream: 3.6.2 dev: true - /blueimp-md5/2.19.0: - resolution: {integrity: sha512-DRQrD6gJyy8FbiE4s+bDoXS9hiW3Vbx5uCdwvcCf3zLHL+Iv7LtGHLpr+GZV8rHG8tK766FGYBwRbu8pELTt+w==} - dev: true - - /brace-expansion/2.0.1: + /brace-expansion@2.0.1: resolution: {integrity: sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==} dependencies: balanced-match: 1.0.2 dev: true - /braces/3.0.2: - resolution: {integrity: sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==} - engines: {node: '>=8'} - dependencies: - fill-range: 7.0.1 - dev: true - - /buffer/5.7.1: + /buffer@5.7.1: resolution: {integrity: sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==} dependencies: base64-js: 1.5.1 ieee754: 1.2.1 dev: true - /buffer/6.0.3: + /buffer@6.0.3: resolution: {integrity: sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==} dependencies: base64-js: 1.5.1 ieee754: 1.2.1 dev: true - /call-bind/1.0.2: + /call-bind@1.0.2: resolution: {integrity: sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==} dependencies: function-bind: 1.1.1 get-intrinsic: 1.2.1 dev: true - /callsites/4.1.0: - resolution: {integrity: sha512-aBMbD1Xxay75ViYezwT40aQONfr+pSXTHwNKvIXhXD6+LY3F1dLIcceoC5OZKBVHbXcysz1hL9D2w0JJIMXpUw==} - engines: {node: '>=12.20'} - dev: true - - /cbor/8.1.0: - resolution: {integrity: sha512-DwGjNW9omn6EwP70aXsn7FQJx5kO12tX0bZkaTjzdVFM6/7nhA4t0EENocKGx6D2Bch9PE2KzCUf5SceBdeijg==} - engines: {node: '>=12.19'} - dependencies: - nofilter: 3.1.0 - dev: true - - /chalk/4.1.2: + /chalk@4.1.2: resolution: {integrity: sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==} engines: {node: '>=10'} dependencies: @@ -442,153 +294,68 @@ packages: supports-color: 7.2.0 dev: true - /chalk/5.3.0: + /chalk@5.3.0: resolution: {integrity: sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==} engines: {node: ^12.17.0 || ^14.13 || >=16.0.0} dev: true - /chardet/0.7.0: + /chardet@0.7.0: resolution: {integrity: sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==} dev: true - /chokidar/3.5.3: - resolution: {integrity: sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==} - engines: {node: '>= 8.10.0'} - dependencies: - anymatch: 3.1.3 - braces: 3.0.2 - glob-parent: 5.1.2 - is-binary-path: 2.1.0 - is-glob: 4.0.3 - normalize-path: 3.0.0 - readdirp: 3.6.0 - optionalDependencies: - fsevents: 2.3.3 - dev: true - - /chunkd/2.0.1: - resolution: {integrity: sha512-7d58XsFmOq0j6el67Ug9mHf9ELUXsQXYJBkyxhH/k+6Ke0qXRnv0kbemx+Twc6fRJ07C49lcbdgm9FL1Ei/6SQ==} - dev: true - - /ci-info/3.9.0: - resolution: {integrity: sha512-NIxF55hv4nSqQswkAeiOi1r83xy8JldOFDTWiug55KBu9Jnblncd2U6ViHmYgHf01TPZS77NJBhBMKdWj9HQMQ==} - engines: {node: '>=8'} - dev: true - - /ci-parallel-vars/1.0.1: - resolution: {integrity: sha512-uvzpYrpmidaoxvIQHM+rKSrigjOe9feHYbw4uOI2gdfe1C3xIlxO+kVXq83WQWNniTf8bAxVpy+cQeFQsMERKg==} - dev: true - - /clean-stack/4.2.0: - resolution: {integrity: sha512-LYv6XPxoyODi36Dp976riBtSY27VmFo+MKqEU9QCCWyTrdEPDog+RWA7xQWHi6Vbp61j5c4cdzzX1NidnwtUWg==} - engines: {node: '>=12'} - dependencies: - escape-string-regexp: 5.0.0 - dev: true - - /clean-yaml-object/0.1.0: - resolution: {integrity: sha512-3yONmlN9CSAkzNwnRCiJQ7Q2xK5mWuEfL3PuTZcAUzhObbXsfsnMptJzXwz93nc5zn9V9TwCVMmV7w4xsm43dw==} - engines: {node: '>=0.10.0'} - dev: true - - /cli-cursor/3.1.0: + /cli-cursor@3.1.0: resolution: {integrity: sha512-I/zHAwsKf9FqGoXM4WWRACob9+SNukZTd94DWF57E4toouRulbCxcUh6RKUEOQlYTHJnzkPMySvPNaaSLNfLZw==} engines: {node: '>=8'} dependencies: restore-cursor: 3.1.0 dev: true - /cli-cursor/4.0.0: + /cli-cursor@4.0.0: resolution: {integrity: sha512-VGtlMu3x/4DOtIUwEkRezxUZ2lBacNJCHash0N0WeZDBS+7Ux1dm3XWAgWYxLJFMMdOeXMHXorshEFhbMSGelg==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} dependencies: restore-cursor: 4.0.0 dev: true - /cli-spinners/2.9.1: + /cli-spinners@2.9.1: resolution: {integrity: sha512-jHgecW0pxkonBJdrKsqxgRX9AcG+u/5k0Q7WPDfi8AogLAdwxEkyYYNWwZ5GvVFoFx2uiY1eNcSK00fh+1+FyQ==} engines: {node: '>=6'} dev: true - /cli-truncate/3.1.0: - resolution: {integrity: sha512-wfOBkjXteqSnI59oPcJkcPl/ZmwvMMOj340qUIY1SKZCv0B9Cf4D4fAucRkIKQmsIuYK3x1rrgU7MeGRruiuiA==} - engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - dependencies: - slice-ansi: 5.0.0 - string-width: 5.1.2 - dev: true - - /cli-width/4.1.0: + /cli-width@4.1.0: resolution: {integrity: sha512-ouuZd4/dm2Sw5Gmqy6bGyNNNe1qt9RpmxveLSO7KcgsTnU7RXfsw+/bukWGo1abgBiMAic068rclZsO4IWmmxQ==} engines: {node: '>= 12'} dev: true - /clipanion/3.2.1: + /clipanion@3.2.1(typanion@3.14.0): resolution: {integrity: sha512-dYFdjLb7y1ajfxQopN05mylEpK9ZX0sO1/RfMXdfmwjlIsPkbh4p7A682x++zFPLDCo1x3p82dtljHf5cW2LKA==} + peerDependencies: + typanion: '*' dependencies: typanion: 3.14.0 dev: true - /cliui/8.0.1: - resolution: {integrity: sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==} - engines: {node: '>=12'} - dependencies: - string-width: 4.2.3 - strip-ansi: 6.0.1 - wrap-ansi: 7.0.0 - dev: true - - /clone/1.0.4: + /clone@1.0.4: resolution: {integrity: sha512-JQHZ2QMW6l3aH/j6xCqQThY/9OH4D/9ls34cgkUBiEeocRTU04tHfKPBsUK1PqZCUQM7GiA0IIXJSuXHI64Kbg==} engines: {node: '>=0.8'} dev: true - /code-excerpt/4.0.0: - resolution: {integrity: sha512-xxodCmBen3iy2i0WtAK8FlFNrRzjUqjRsMfho58xT/wvZU1YTM3fCnRjcy1gJPMepaRlgm/0e6w8SpWHpn3/cA==} - engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - dependencies: - convert-to-spaces: 2.0.1 - dev: true - - /color-convert/2.0.1: + /color-convert@2.0.1: resolution: {integrity: sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==} engines: {node: '>=7.0.0'} dependencies: color-name: 1.1.4 dev: true - /color-name/1.1.4: + /color-name@1.1.4: resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==} dev: true - /colorette/2.0.20: + /colorette@2.0.20: resolution: {integrity: sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w==} dev: true - /common-path-prefix/3.0.0: - resolution: {integrity: sha512-QE33hToZseCH3jS0qN96O/bSh3kaw/h+Tq7ngyY9eWDUnTlTNUyqfqvCXioLe5Na5jFsL78ra/wuBU4iuEgd4w==} - dev: true - - /concordance/5.0.4: - resolution: {integrity: sha512-OAcsnTEYu1ARJqWVGwf4zh4JDfHZEaSNlNccFmt8YjB2l/n19/PF2viLINHc57vO4FKIAFl2FWASIGZZWZ2Kxw==} - engines: {node: '>=10.18.0 <11 || >=12.14.0 <13 || >=14'} - dependencies: - date-time: 3.1.0 - esutils: 2.0.3 - fast-diff: 1.3.0 - js-string-escape: 1.0.1 - lodash: 4.17.21 - md5-hex: 3.0.1 - semver: 7.5.4 - well-known-symbols: 2.0.0 - dev: true - - /convert-to-spaces/2.0.1: - resolution: {integrity: sha512-rcQ1bsQO9799wq24uE5AM2tAILy4gXGIK/njFWcVQkGNZ96edlpY+A7bjwvzjYvLDyzmG1MmMLZhpcsb+klNMQ==} - engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - dev: true - - /cross-spawn/7.0.3: + /cross-spawn@7.0.3: resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==} engines: {node: '>= 8'} dependencies: @@ -597,21 +364,7 @@ packages: which: 2.0.2 dev: true - /currently-unhandled/0.4.1: - resolution: {integrity: sha512-/fITjgjGU50vjQ4FH6eUoYu+iUoUKIXws2hL15JJpIR+BbTxaXQsMuuyjtNh2WqsSBS5nsaZHFsFecyw5CCAng==} - engines: {node: '>=0.10.0'} - dependencies: - array-find-index: 1.0.2 - dev: true - - /date-time/3.1.0: - resolution: {integrity: sha512-uqCUKXE5q1PNBXjPqvwhwJf9SwMoAHBgWJ6DcrnS5o+W2JOiIILl0JEdVD8SGujrNS02GGxgwAg2PN2zONgtjg==} - engines: {node: '>=6'} - dependencies: - time-zone: 1.0.0 - dev: true - - /debug/4.3.4: + /debug@4.3.4: resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==} engines: {node: '>=6.0'} peerDependencies: @@ -623,71 +376,38 @@ packages: ms: 2.1.2 dev: true - /defaults/1.0.4: + /defaults@1.0.4: resolution: {integrity: sha512-eFuaLoy/Rxalv2kr+lqMlUnrDWV+3j4pljOIJgLIhI058IQfWJ7vXhyEIHu+HtC738klGALYxOKDO0bQP3tg8A==} dependencies: clone: 1.0.4 dev: true - /deprecation/2.3.1: + /deprecation@2.3.1: resolution: {integrity: sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ==} dev: true - /dir-glob/3.0.1: - resolution: {integrity: sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==} - engines: {node: '>=8'} - dependencies: - path-type: 4.0.0 - dev: true - - /eastasianwidth/0.2.0: + /eastasianwidth@0.2.0: resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==} dev: true - /emittery/1.0.1: - resolution: {integrity: sha512-2ID6FdrMD9KDLldGesP6317G78K7km/kMcwItRtVFva7I/cSEOIaLpewaUb+YLXVwdAp3Ctfxh/V5zIl1sj7dQ==} - engines: {node: '>=14.16'} - dev: true - - /emoji-regex/10.2.1: + /emoji-regex@10.2.1: resolution: {integrity: sha512-97g6QgOk8zlDRdgq1WxwgTMgEWGVAQvB5Fdpgc1MkNy56la5SKP9GsMXKDOdqwn90/41a8yPwIGk1Y6WVbeMQA==} dev: true - /emoji-regex/8.0.0: + /emoji-regex@8.0.0: resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==} dev: true - /emoji-regex/9.2.2: + /emoji-regex@9.2.2: resolution: {integrity: sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==} dev: true - /escalade/3.1.1: - resolution: {integrity: sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==} - engines: {node: '>=6'} - dev: true - - /escape-string-regexp/2.0.0: - resolution: {integrity: sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==} - engines: {node: '>=8'} - dev: true - - /escape-string-regexp/5.0.0: + /escape-string-regexp@5.0.0: resolution: {integrity: sha512-/veY75JbMK4j1yjvuUxuVsiS/hr/4iHs9FTT6cgTexxdE0Ly/glccBAkloH/DofkjRbZU3bnoj38mOmhkZ0lHw==} engines: {node: '>=12'} dev: true - /esprima/4.0.1: - resolution: {integrity: sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==} - engines: {node: '>=4'} - hasBin: true - dev: true - - /esutils/2.0.3: - resolution: {integrity: sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==} - engines: {node: '>=0.10.0'} - dev: true - - /external-editor/3.1.0: + /external-editor@3.1.0: resolution: {integrity: sha512-hMQ4CX1p1izmuLYyZqLMO/qGNw10wSv9QDCPfzXfyFrOaCSSoRfqE1Kf1s5an66J5JZC62NewG+mK49jOCtQew==} engines: {node: '>=4'} dependencies: @@ -696,28 +416,7 @@ packages: tmp: 0.0.33 dev: true - /fast-diff/1.3.0: - resolution: {integrity: sha512-VxPP4NqbUjj6MaAOafWeUn2cXWLcCtljklUtZf0Ind4XQ+QPtmA0b18zZy0jIQx+ExRVCR/ZQpBmik5lXshNsw==} - dev: true - - /fast-glob/3.3.1: - resolution: {integrity: sha512-kNFPyjhh5cKjrUltxs+wFx+ZkbRaxxmZ+X0ZU31SOsxCEtP9VPgtq2teZw1DebupL5GmDaNQ6yKMMVcM41iqDg==} - engines: {node: '>=8.6.0'} - dependencies: - '@nodelib/fs.stat': 2.0.5 - '@nodelib/fs.walk': 1.2.8 - glob-parent: 5.1.2 - merge2: 1.4.1 - micromatch: 4.0.5 - dev: true - - /fastq/1.15.0: - resolution: {integrity: sha512-wBrocU2LCXXa+lWBt8RoIRD89Fi8OdABODa/kEnyeyjS5aZO5/GNvI5sEINADqP/h8M29UHTHUb53sUu5Ihqdw==} - dependencies: - reusify: 1.0.4 - dev: true - - /figures/5.0.0: + /figures@5.0.0: resolution: {integrity: sha512-ej8ksPF4x6e5wvK9yevct0UCXh8TTFlWGVLlgjZuoBH1HwjIfKE/IdL5mq89sFA7zELi1VhKpmtDnrs7zWyeyg==} engines: {node: '>=14'} dependencies: @@ -725,22 +424,7 @@ packages: is-unicode-supported: 1.3.0 dev: true - /fill-range/7.0.1: - resolution: {integrity: sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==} - engines: {node: '>=8'} - dependencies: - to-regex-range: 5.0.1 - dev: true - - /find-up/6.3.0: - resolution: {integrity: sha512-v2ZsoEuVHYy8ZIlYqwPe/39Cy+cFDzp4dXPaxNvkEuouymu+2Jbz0PxpKarJHYJTmv2HWT3O382qY8l4jMWthw==} - engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - dependencies: - locate-path: 7.2.0 - path-exists: 5.0.0 - dev: true - - /foreground-child/3.1.1: + /foreground-child@3.1.1: resolution: {integrity: sha512-TMKDUnIte6bfb5nWv7V/caI169OHgvwjb7V4WkeUvbQQdjr5rWKqHFiKWb/fcOwB+CzBT+qbWjvj+DVwRskpIg==} engines: {node: '>=14'} dependencies: @@ -748,7 +432,7 @@ packages: signal-exit: 4.1.0 dev: true - /fs-extra/11.1.1: + /fs-extra@11.1.1: resolution: {integrity: sha512-MGIE4HOvQCeUCzmlHs0vXpih4ysz4wg9qiSAu6cd42lVwPbTM1TjV7RusoyQqMmk/95gdQZX72u+YW+c3eEpFQ==} engines: {node: '>=14.14'} dependencies: @@ -757,24 +441,11 @@ packages: universalify: 2.0.0 dev: true - /fsevents/2.3.3: - resolution: {integrity: sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==} - engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} - os: [darwin] - requiresBuild: true - dev: true - optional: true - - /function-bind/1.1.1: + /function-bind@1.1.1: resolution: {integrity: sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==} dev: true - /get-caller-file/2.0.5: - resolution: {integrity: sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==} - engines: {node: 6.* || 8.* || >= 10.*} - dev: true - - /get-intrinsic/1.2.1: + /get-intrinsic@1.2.1: resolution: {integrity: sha512-2DcsyfABl+gVHEfCOaTrWgyt+tb6MSEGmKq+kI5HwLbIYgjgmMcV8KQ41uaKz1xxUcn9tJtgFbQUEVcEbd0FYw==} dependencies: function-bind: 1.1.1 @@ -783,18 +454,11 @@ packages: has-symbols: 1.0.3 dev: true - /git-clone/0.2.0: + /git-clone@0.2.0: resolution: {integrity: sha512-1UAkEPIFbyjHaddljUKvPhhLRnrKaImT71T7rdvSvWLXw95nLdhdi6Qmlx0KOWoV1qqvHGLq5lMLJEZM0JXk8A==} dev: true - /glob-parent/5.1.2: - resolution: {integrity: sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==} - engines: {node: '>= 6'} - dependencies: - is-glob: 4.0.3 - dev: true - - /glob/10.3.10: + /glob@10.3.10: resolution: {integrity: sha512-fa46+tv1Ak0UPK1TOy/pZrIybNNt4HCv7SDzwyfiOZkvZLEbjsZkJBPtDHVshZjbecAoAGSC20MjLDG/qr679g==} engines: {node: '>=16 || 14 >=14.17'} hasBin: true @@ -806,77 +470,46 @@ packages: path-scurry: 1.10.1 dev: true - /globby/13.2.2: - resolution: {integrity: sha512-Y1zNGV+pzQdh7H39l9zgB4PJqjRNqydvdYCDG4HFXM4XuvSaQQlEc91IU1yALL8gUTDomgBAfz3XJdmUS+oo0w==} - engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - dependencies: - dir-glob: 3.0.1 - fast-glob: 3.3.1 - ignore: 5.2.4 - merge2: 1.4.1 - slash: 4.0.0 - dev: true - - /graceful-fs/4.2.11: + /graceful-fs@4.2.11: resolution: {integrity: sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==} dev: true - /has-flag/4.0.0: + /has-flag@4.0.0: resolution: {integrity: sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==} engines: {node: '>=8'} dev: true - /has-proto/1.0.1: + /has-proto@1.0.1: resolution: {integrity: sha512-7qE+iP+O+bgF9clE5+UoBFzE65mlBiVj3tKCrlNQ0Ogwm0BjpT/gK4SlLYDMybDh5I3TCTKnPPa0oMG7JDYrhg==} engines: {node: '>= 0.4'} dev: true - /has-symbols/1.0.3: + /has-symbols@1.0.3: resolution: {integrity: sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==} engines: {node: '>= 0.4'} dev: true - /has/1.0.4: + /has@1.0.4: resolution: {integrity: sha512-qdSAmqLF6209RFj4VVItywPMbm3vWylknmB3nvNiUIs72xAimcM8nVYxYr7ncvZq5qzk9MKIZR8ijqD/1QuYjQ==} engines: {node: '>= 0.4.0'} dev: true - /iconv-lite/0.4.24: + /iconv-lite@0.4.24: resolution: {integrity: sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==} engines: {node: '>=0.10.0'} dependencies: safer-buffer: 2.1.2 dev: true - /ieee754/1.2.1: + /ieee754@1.2.1: resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==} dev: true - /ignore-by-default/2.1.0: - resolution: {integrity: sha512-yiWd4GVmJp0Q6ghmM2B/V3oZGRmjrKLXvHR3TE1nfoXsmoggllfZUQe74EN0fJdPFZu2NIvNdrMMLm3OsV7Ohw==} - engines: {node: '>=10 <11 || >=12 <13 || >=14'} - dev: true - - /ignore/5.2.4: - resolution: {integrity: sha512-MAb38BcSbH0eHNBxn7ql2NH/kX33OkB3lZ1BNdh7ENeRChHTYsTvWrMubiIAMNS2llXEEgZ1MUOBtXChP3kaFQ==} - engines: {node: '>= 4'} - dev: true - - /imurmurhash/0.1.4: - resolution: {integrity: sha512-JmXMZ6wuvDmLiHEml9ykzqO6lwFbof0GG4IkcGaENdCRDDmMVnny7s5HsIgHCbaq0w2MyPhDqkhTUgS2LU2PHA==} - engines: {node: '>=0.8.19'} - dev: true - - /indent-string/5.0.0: - resolution: {integrity: sha512-m6FAo/spmsW2Ab2fU35JTYwtOKa2yAwXSwgjSv1TJzh4Mh7mC3lzAOVLBprb72XsTrgkEIsl7YrFNAiDiRhIGg==} - engines: {node: '>=12'} - dev: true - - /inherits/2.0.4: + /inherits@2.0.4: resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==} dev: true - /inquirer/9.2.11: + /inquirer@9.2.11: resolution: {integrity: sha512-B2LafrnnhbRzCWfAdOXisUzL89Kg8cVJlYmhqoi3flSiV/TveO+nsXwgKr9h9PIo+J1hz7nBSk6gegRIMBBf7g==} engines: {node: '>=14.18.0'} dependencies: @@ -897,83 +530,41 @@ packages: wrap-ansi: 6.2.0 dev: true - /irregular-plurals/3.5.0: - resolution: {integrity: sha512-1ANGLZ+Nkv1ptFb2pa8oG8Lem4krflKuX/gINiHJHjJUKaJHk/SXk5x6K3J+39/p0h1RQ2saROclJJ+QLvETCQ==} - engines: {node: '>=8'} - dev: true - - /is-binary-path/2.1.0: - resolution: {integrity: sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==} - engines: {node: '>=8'} - dependencies: - binary-extensions: 2.2.0 - dev: true - - /is-error/2.2.2: - resolution: {integrity: sha512-IOQqts/aHWbiisY5DuPJQ0gcbvaLFCa7fBa9xoLfxBZvQ+ZI/Zh9xoI7Gk+G64N0FdK4AbibytHht2tWgpJWLg==} - dev: true - - /is-extglob/2.1.1: - resolution: {integrity: sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==} - engines: {node: '>=0.10.0'} - dev: true - - /is-fullwidth-code-point/3.0.0: + /is-fullwidth-code-point@3.0.0: resolution: {integrity: sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==} engines: {node: '>=8'} dev: true - /is-fullwidth-code-point/4.0.0: - resolution: {integrity: sha512-O4L094N2/dZ7xqVdrXhh9r1KODPJpFms8B5sGdJLPy664AgvXsreZUyCQQNItZRDlYug4xStLjNp/sz3HvBowQ==} - engines: {node: '>=12'} - dev: true - - /is-glob/4.0.3: - resolution: {integrity: sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==} - engines: {node: '>=0.10.0'} - dependencies: - is-extglob: 2.1.1 - dev: true - - /is-interactive/1.0.0: + /is-interactive@1.0.0: resolution: {integrity: sha512-2HvIEKRoqS62guEC+qBjpvRubdX910WCMuJTZ+I9yvqKU2/12eSL549HMwtabb4oupdj2sMP50k+XJfB/8JE6w==} engines: {node: '>=8'} dev: true - /is-interactive/2.0.0: + /is-interactive@2.0.0: resolution: {integrity: sha512-qP1vozQRI+BMOPcjFzrjXuQvdak2pHNUMZoeG2eRbiSqyvbEf/wQtEOTOX1guk6E3t36RkaqiSt8A/6YElNxLQ==} engines: {node: '>=12'} dev: true - /is-number/7.0.0: - resolution: {integrity: sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==} - engines: {node: '>=0.12.0'} - dev: true - - /is-plain-object/5.0.0: + /is-plain-object@5.0.0: resolution: {integrity: sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q==} engines: {node: '>=0.10.0'} dev: true - /is-promise/4.0.0: - resolution: {integrity: sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==} - dev: true - - /is-unicode-supported/0.1.0: + /is-unicode-supported@0.1.0: resolution: {integrity: sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==} engines: {node: '>=10'} dev: true - /is-unicode-supported/1.3.0: + /is-unicode-supported@1.3.0: resolution: {integrity: sha512-43r2mRvz+8JRIKnWJ+3j8JtjRKZ6GmjzfaE/qiBJnikNnYv/6bagRJ1kUhNk8R5EX/GkobD+r+sfxCPJsiKBLQ==} engines: {node: '>=12'} dev: true - /isexe/2.0.0: + /isexe@2.0.0: resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==} dev: true - /jackspeak/2.3.6: + /jackspeak@2.3.6: resolution: {integrity: sha512-N3yCS/NegsOBokc8GAdM8UcmfsKiSS8cipheD/nivzr700H+nsMOxJjQnvwOcRYVuFkdH0wGUvW2WbXGmrZGbQ==} engines: {node: '>=14'} dependencies: @@ -982,27 +573,14 @@ packages: '@pkgjs/parseargs': 0.11.0 dev: true - /js-string-escape/1.0.1: - resolution: {integrity: sha512-Smw4xcfIQ5LVjAOuJCvN/zIodzA/BBSsluuoSykP+lUvScIi4U6RJLfwHet5cxFnCswUjISV8oAXaqaJDY3chg==} - engines: {node: '>= 0.8'} - dev: true - - /js-yaml/3.14.1: - resolution: {integrity: sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==} - hasBin: true - dependencies: - argparse: 1.0.10 - esprima: 4.0.1 - dev: true - - /js-yaml/4.1.0: + /js-yaml@4.1.0: resolution: {integrity: sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==} hasBin: true dependencies: argparse: 2.0.1 dev: true - /jsonfile/6.1.0: + /jsonfile@6.1.0: resolution: {integrity: sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==} dependencies: universalify: 2.0.0 @@ -1010,27 +588,15 @@ packages: graceful-fs: 4.2.11 dev: true - /load-json-file/7.0.1: - resolution: {integrity: sha512-Gnxj3ev3mB5TkVBGad0JM6dmLiQL+o0t23JPBZ9sd+yvSLk05mFoqKBw5N8gbbkU4TNXyqCgIrl/VM17OgUIgQ==} - engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - dev: true - - /locate-path/7.2.0: - resolution: {integrity: sha512-gvVijfZvn7R+2qyPX8mAuKcFGDf6Nc61GdvGafQsHL0sBIxfKzA+usWn4GFC/bk+QdwPUD4kWFJLhElipq+0VA==} - engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - dependencies: - p-locate: 6.0.0 - dev: true - - /lodash-es/4.17.21: + /lodash-es@4.17.21: resolution: {integrity: sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==} dev: true - /lodash/4.17.21: + /lodash@4.17.21: resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==} dev: true - /log-symbols/4.1.0: + /log-symbols@4.1.0: resolution: {integrity: sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==} engines: {node: '>=10'} dependencies: @@ -1038,7 +604,7 @@ packages: is-unicode-supported: 0.1.0 dev: true - /log-symbols/5.1.0: + /log-symbols@5.1.0: resolution: {integrity: sha512-l0x2DvrW294C9uDCoQe1VSU4gf529FkSZ6leBl4TiqZH/e+0R7hSfHQBNut2mNygDgHwvYHfFLn6Oxb3VWj2rA==} engines: {node: '>=12'} dependencies: @@ -1046,96 +612,38 @@ packages: is-unicode-supported: 1.3.0 dev: true - /lru-cache/10.0.1: + /lru-cache@10.0.1: resolution: {integrity: sha512-IJ4uwUTi2qCccrioU6g9g/5rvvVl13bsdczUUcqbciD9iLr095yj8DQKdObriEvuNSx325N1rV1O0sJFszx75g==} engines: {node: 14 || >=16.14} dev: true - /lru-cache/6.0.0: - resolution: {integrity: sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==} - engines: {node: '>=10'} - dependencies: - yallist: 4.0.0 - dev: true - - /map-age-cleaner/0.1.3: - resolution: {integrity: sha512-bJzx6nMoP6PDLPBFmg7+xRKeFZvFboMrGlxmNj9ClvX53KrmvM5bXFXEWjbz4cz1AFn+jWJ9z/DJSz7hrs0w3w==} - engines: {node: '>=6'} - dependencies: - p-defer: 1.0.0 - dev: true - - /matcher/5.0.0: - resolution: {integrity: sha512-s2EMBOWtXFc8dgqvoAzKJXxNHibcdJMV0gwqKUaw9E2JBJuGUK7DrNKrA6g/i+v72TT16+6sVm5mS3thaMLQUw==} - engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - dependencies: - escape-string-regexp: 5.0.0 - dev: true - - /md5-hex/3.0.1: - resolution: {integrity: sha512-BUiRtTtV39LIJwinWBjqVsU9xhdnz7/i889V859IBFpuqGAj6LuOvHv5XLbgZ2R7ptJoJaEcxkv88/h25T7Ciw==} - engines: {node: '>=8'} - dependencies: - blueimp-md5: 2.19.0 - dev: true - - /mem/9.0.2: - resolution: {integrity: sha512-F2t4YIv9XQUBHt6AOJ0y7lSmP1+cY7Fm1DRh9GClTGzKST7UWLMx6ly9WZdLH/G/ppM5RL4MlQfRT71ri9t19A==} - engines: {node: '>=12.20'} - dependencies: - map-age-cleaner: 0.1.3 - mimic-fn: 4.0.0 - dev: true - - /merge2/1.4.1: - resolution: {integrity: sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==} - engines: {node: '>= 8'} - dev: true - - /micromatch/4.0.5: - resolution: {integrity: sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==} - engines: {node: '>=8.6'} - dependencies: - braces: 3.0.2 - picomatch: 2.3.1 - dev: true - - /mimic-fn/2.1.0: + /mimic-fn@2.1.0: resolution: {integrity: sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==} engines: {node: '>=6'} dev: true - /mimic-fn/4.0.0: - resolution: {integrity: sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==} - engines: {node: '>=12'} - dev: true - - /minimatch/9.0.3: + /minimatch@9.0.3: resolution: {integrity: sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==} engines: {node: '>=16 || 14 >=14.17'} dependencies: brace-expansion: 2.0.1 dev: true - /minipass/7.0.4: + /minipass@7.0.4: resolution: {integrity: sha512-jYofLM5Dam9279rdkWzqHozUo4ybjdZmCsDHePy5V/PbBcVMiSZR97gmAy45aqi8CK1lG2ECd356FU86avfwUQ==} engines: {node: '>=16 || 14 >=14.17'} dev: true - /ms/2.1.2: + /ms@2.1.2: resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==} dev: true - /ms/2.1.3: - resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==} - dev: true - - /mute-stream/1.0.0: + /mute-stream@1.0.0: resolution: {integrity: sha512-avsJQhyd+680gKXyG/sQc0nXaC6rBkPOfyHYcFb9+hdkqQkR9bdnkJ0AMZhke0oesPqIO+mFFJ+IdBc7mst4IA==} engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} dev: true - /node-fetch/2.7.0: + /node-fetch@2.7.0: resolution: {integrity: sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==} engines: {node: 4.x || >=6.0.0} peerDependencies: @@ -1147,30 +655,20 @@ packages: whatwg-url: 5.0.0 dev: true - /nofilter/3.1.0: - resolution: {integrity: sha512-l2NNj07e9afPnhAhvgVrCD/oy2Ai1yfLpuo3EpiO1jFTsB4sFz6oIfAfSZyQzVpkZQ9xS8ZS5g1jCBgq4Hwo0g==} - engines: {node: '>=12.19'} - dev: true - - /normalize-path/3.0.0: - resolution: {integrity: sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==} - engines: {node: '>=0.10.0'} - dev: true - - /once/1.4.0: + /once@1.4.0: resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==} dependencies: wrappy: 1.0.2 dev: true - /onetime/5.1.2: + /onetime@5.1.2: resolution: {integrity: sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==} engines: {node: '>=6'} dependencies: mimic-fn: 2.1.0 dev: true - /ora/5.4.1: + /ora@5.4.1: resolution: {integrity: sha512-5b6Y85tPxZZ7QytO+BQzysW31HJku27cRIlkbAXaNx+BdcVi+LlRFmVXzeF6a7JCwJpyw5c4b+YSVImQIrBpuQ==} engines: {node: '>=10'} dependencies: @@ -1185,7 +683,7 @@ packages: wcwidth: 1.0.1 dev: true - /ora/7.0.1: + /ora@7.0.1: resolution: {integrity: sha512-0TUxTiFJWv+JnjWm4o9yvuskpEJLXTcng8MJuKd+SzAzp2o+OP3HWqNhB4OdJRt1Vsd9/mR0oyaEYlOnL7XIRw==} engines: {node: '>=16'} dependencies: @@ -1200,65 +698,17 @@ packages: strip-ansi: 7.1.0 dev: true - /os-tmpdir/1.0.2: + /os-tmpdir@1.0.2: resolution: {integrity: sha512-D2FR03Vir7FIu45XBY20mTb+/ZSWB00sjU9jdQXt83gDrI4Ztz5Fs7/yy74g2N5SVQY4xY1qDr4rNddwYRVX0g==} engines: {node: '>=0.10.0'} dev: true - /p-defer/1.0.0: - resolution: {integrity: sha512-wB3wfAxZpk2AzOfUMJNL+d36xothRSyj8EXOa4f6GMqYDN9BJaaSISbsk+wS9abmnebVw95C2Kb5t85UmpCxuw==} - engines: {node: '>=4'} - dev: true - - /p-event/5.0.1: - resolution: {integrity: sha512-dd589iCQ7m1L0bmC5NLlVYfy3TbBEsMUfWx9PyAgPeIcFZ/E2yaTZ4Rz4MiBmmJShviiftHVXOqfnfzJ6kyMrQ==} - engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - dependencies: - p-timeout: 5.1.0 - dev: true - - /p-limit/4.0.0: - resolution: {integrity: sha512-5b0R4txpzjPWVw/cXXUResoD4hb6U/x9BH08L7nw+GN1sezDzPdxeRvpc9c433fZhBan/wusjbCsqwqm4EIBIQ==} - engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - dependencies: - yocto-queue: 1.0.0 - dev: true - - /p-locate/6.0.0: - resolution: {integrity: sha512-wPrq66Llhl7/4AGC6I+cqxT07LhXvWL08LNXz1fENOw0Ap4sRZZ/gZpTTJ5jpurzzzfS2W/Ge9BY3LgLjCShcw==} - engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - dependencies: - p-limit: 4.0.0 - dev: true - - /p-map/5.5.0: - resolution: {integrity: sha512-VFqfGDHlx87K66yZrNdI4YGtD70IRyd+zSvgks6mzHPRNkoKy+9EKP4SFC77/vTTQYmRmti7dvqC+m5jBrBAcg==} - engines: {node: '>=12'} - dependencies: - aggregate-error: 4.0.1 - dev: true - - /p-timeout/5.1.0: - resolution: {integrity: sha512-auFDyzzzGZZZdHz3BtET9VEz0SE/uMEAx7uWfGPucfzEwwe/xH0iVeZibQmANYE/hp9T2+UUZT5m+BKyrDp3Ew==} - engines: {node: '>=12'} - dev: true - - /parse-ms/3.0.0: - resolution: {integrity: sha512-Tpb8Z7r7XbbtBTrM9UhpkzzaMrqA2VXMT3YChzYltwV3P3pM6t8wl7TvpMnSTosz1aQAdVib7kdoys7vYOPerw==} - engines: {node: '>=12'} - dev: true - - /path-exists/5.0.0: - resolution: {integrity: sha512-RjhtfwJOxzcFmNOi6ltcbcu4Iu+FL3zEj83dk4kAS+fVpTxXLO1b38RvJgT/0QwvV/L3aY9TAnyv0EOqW4GoMQ==} - engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - dev: true - - /path-key/3.1.1: + /path-key@3.1.1: resolution: {integrity: sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==} engines: {node: '>=8'} dev: true - /path-scurry/1.10.1: + /path-scurry@1.10.1: resolution: {integrity: sha512-MkhCqzzBEpPvxxQ71Md0b1Kk51W01lrYvlMzSUaIzNsODdd7mqhiimSZlr+VegAz5Z6Vzt9Xg2ttE//XBhH3EQ==} engines: {node: '>=16 || 14 >=14.17'} dependencies: @@ -1266,43 +716,7 @@ packages: minipass: 7.0.4 dev: true - /path-type/4.0.0: - resolution: {integrity: sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==} - engines: {node: '>=8'} - dev: true - - /picomatch/2.3.1: - resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==} - engines: {node: '>=8.6'} - dev: true - - /pkg-conf/4.0.0: - resolution: {integrity: sha512-7dmgi4UY4qk+4mj5Cd8v/GExPo0K+SlY+hulOSdfZ/T6jVH6//y7NtzZo5WrfhDBxuQ0jCa7fLZmNaNh7EWL/w==} - engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - dependencies: - find-up: 6.3.0 - load-json-file: 7.0.1 - dev: true - - /plur/5.1.0: - resolution: {integrity: sha512-VP/72JeXqak2KiOzjgKtQen5y3IZHn+9GOuLDafPv0eXa47xq0At93XahYBs26MsifCQ4enGKwbjBTKgb9QJXg==} - engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - dependencies: - irregular-plurals: 3.5.0 - dev: true - - /pretty-ms/8.0.0: - resolution: {integrity: sha512-ASJqOugUF1bbzI35STMBUpZqdfYKlJugy6JBziGi2EE+AL5JPJGSzvpeVXojxrr0ViUYoToUjb5kjSEGf7Y83Q==} - engines: {node: '>=14.16'} - dependencies: - parse-ms: 3.0.0 - dev: true - - /queue-microtask/1.2.3: - resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==} - dev: true - - /readable-stream/3.6.2: + /readable-stream@3.6.2: resolution: {integrity: sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==} engines: {node: '>= 6'} dependencies: @@ -1311,31 +725,7 @@ packages: util-deprecate: 1.0.2 dev: true - /readdirp/3.6.0: - resolution: {integrity: sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==} - engines: {node: '>=8.10.0'} - dependencies: - picomatch: 2.3.1 - dev: true - - /require-directory/2.1.1: - resolution: {integrity: sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==} - engines: {node: '>=0.10.0'} - dev: true - - /resolve-cwd/3.0.0: - resolution: {integrity: sha512-OrZaX2Mb+rJCpH/6CpSqt9xFVpN++x01XnN2ie9g6P5/3xelLAkXWVADpdz1IHD/KFfEXyE6V0U01OQ3UO2rEg==} - engines: {node: '>=8'} - dependencies: - resolve-from: 5.0.0 - dev: true - - /resolve-from/5.0.0: - resolution: {integrity: sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==} - engines: {node: '>=8'} - dev: true - - /restore-cursor/3.1.0: + /restore-cursor@3.1.0: resolution: {integrity: sha512-l+sSefzHpj5qimhFSE5a8nufZYAM3sBSVMAPtYkmC+4EH2anSGaEMXSD0izRQbu9nfyQ9y5JrVmp7E8oZrUjvA==} engines: {node: '>=8'} dependencies: @@ -1343,7 +733,7 @@ packages: signal-exit: 3.0.7 dev: true - /restore-cursor/4.0.0: + /restore-cursor@4.0.0: resolution: {integrity: sha512-I9fPXU9geO9bHOt9pHHOhOkYerIMsmVaWB0rA2AI9ERh/+x/i7MV5HKBNrg+ljO5eoPVgCcnFuRjJ9uH6I/3eg==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} dependencies: @@ -1351,12 +741,7 @@ packages: signal-exit: 3.0.7 dev: true - /reusify/1.0.4: - resolution: {integrity: sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==} - engines: {iojs: '>=1.0.0', node: '>=0.10.0'} - dev: true - - /rimraf/5.0.5: + /rimraf@5.0.5: resolution: {integrity: sha512-CqDakW+hMe/Bz202FPEymy68P+G50RfMQK+Qo5YUqc9SPipvbGjCGKd0RSKEelbsfQuw3g5NZDSrlZZAJurH1A==} engines: {node: '>=14'} hasBin: true @@ -1364,99 +749,54 @@ packages: glob: 10.3.10 dev: true - /run-async/3.0.0: + /run-async@3.0.0: resolution: {integrity: sha512-540WwVDOMxA6dN6We19EcT9sc3hkXPw5mzRNGM3FkdN/vtE9NFvj5lFAPNwUDmJjXidm3v7TC1cTE7t17Ulm1Q==} engines: {node: '>=0.12.0'} dev: true - /run-parallel/1.2.0: - resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==} - dependencies: - queue-microtask: 1.2.3 - dev: true - - /rxjs/7.8.1: + /rxjs@7.8.1: resolution: {integrity: sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg==} dependencies: tslib: 2.6.2 dev: true - /safe-buffer/5.2.1: + /safe-buffer@5.2.1: resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==} dev: true - /safer-buffer/2.1.2: + /safer-buffer@2.1.2: resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==} dev: true - /semver/7.5.4: - resolution: {integrity: sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==} - engines: {node: '>=10'} - hasBin: true - dependencies: - lru-cache: 6.0.0 - dev: true - - /serialize-error/7.0.1: - resolution: {integrity: sha512-8I8TjW5KMOKsZQTvoxjuSIa7foAwPWGOts+6o7sgjz41/qMD9VQHEDxi6PBvK2l0MXUmqZyNpUK+T2tQaaElvw==} - engines: {node: '>=10'} - dependencies: - type-fest: 0.13.1 - dev: true - - /shebang-command/2.0.0: + /shebang-command@2.0.0: resolution: {integrity: sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==} engines: {node: '>=8'} dependencies: shebang-regex: 3.0.0 dev: true - /shebang-regex/3.0.0: + /shebang-regex@3.0.0: resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==} engines: {node: '>=8'} dev: true - /signal-exit/3.0.7: + /signal-exit@3.0.7: resolution: {integrity: sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==} dev: true - /signal-exit/4.1.0: + /signal-exit@4.1.0: resolution: {integrity: sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==} engines: {node: '>=14'} dev: true - /slash/4.0.0: - resolution: {integrity: sha512-3dOsAHXXUkQTpOYcoAxLIorMTp4gIQr5IW3iVb7A7lFIp0VHhnynm9izx6TssdrIcVIESAlVjtnO2K8bg+Coew==} - engines: {node: '>=12'} - dev: true - - /slice-ansi/5.0.0: - resolution: {integrity: sha512-FC+lgizVPfie0kkhqUScwRu1O/lF6NOgJmlCgK+/LYxDCTk8sGelYaHDhFcDN+Sn3Cv+3VSa4Byeo+IMCzpMgQ==} - engines: {node: '>=12'} - dependencies: - ansi-styles: 6.2.1 - is-fullwidth-code-point: 4.0.0 - dev: true - - /sprintf-js/1.0.3: - resolution: {integrity: sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==} - dev: true - - /stack-utils/2.0.6: - resolution: {integrity: sha512-XlkWvfIm6RmsWtNJx+uqtKLS8eqFbxUg0ZzLXqY0caEy9l7hruX8IpiDnjsLavoBgqCCR71TqWO8MaXYheJ3RQ==} - engines: {node: '>=10'} - dependencies: - escape-string-regexp: 2.0.0 - dev: true - - /stdin-discarder/0.1.0: + /stdin-discarder@0.1.0: resolution: {integrity: sha512-xhV7w8S+bUwlPTb4bAOUQhv8/cSS5offJuX8GQGq32ONF0ZtDWKfkdomM3HMRA+LhX6um/FZ0COqlwsjD53LeQ==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} dependencies: bl: 5.1.0 dev: true - /string-width/4.2.3: + /string-width@4.2.3: resolution: {integrity: sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==} engines: {node: '>=8'} dependencies: @@ -1465,7 +805,7 @@ packages: strip-ansi: 6.0.1 dev: true - /string-width/5.1.2: + /string-width@5.1.2: resolution: {integrity: sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==} engines: {node: '>=12'} dependencies: @@ -1474,7 +814,7 @@ packages: strip-ansi: 7.1.0 dev: true - /string-width/6.1.0: + /string-width@6.1.0: resolution: {integrity: sha512-k01swCJAgQmuADB0YIc+7TuatfNvTBVOoaUWJjTB9R4VJzR5vNWzf5t42ESVZFPS8xTySF7CAdV4t/aaIm3UnQ==} engines: {node: '>=16'} dependencies: @@ -1483,125 +823,88 @@ packages: strip-ansi: 7.1.0 dev: true - /string_decoder/1.3.0: + /string_decoder@1.3.0: resolution: {integrity: sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==} dependencies: safe-buffer: 5.2.1 dev: true - /strip-ansi/6.0.1: + /strip-ansi@6.0.1: resolution: {integrity: sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==} engines: {node: '>=8'} dependencies: ansi-regex: 5.0.1 dev: true - /strip-ansi/7.1.0: + /strip-ansi@7.1.0: resolution: {integrity: sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==} engines: {node: '>=12'} dependencies: ansi-regex: 6.0.1 dev: true - /supertap/3.0.1: - resolution: {integrity: sha512-u1ZpIBCawJnO+0QePsEiOknOfCRq0yERxiAchT0i4li0WHNUJbf0evXXSXOcCAR4M8iMDoajXYmstm/qO81Isw==} - engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - dependencies: - indent-string: 5.0.0 - js-yaml: 3.14.1 - serialize-error: 7.0.1 - strip-ansi: 7.1.0 - dev: true - - /supports-color/7.2.0: + /supports-color@7.2.0: resolution: {integrity: sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==} engines: {node: '>=8'} dependencies: has-flag: 4.0.0 dev: true - /temp-dir/3.0.0: - resolution: {integrity: sha512-nHc6S/bwIilKHNRgK/3jlhDoIHcp45YgyiwcAk46Tr0LfEqGBVpmiAyuiuxeVE44m3mXnEeVhaipLOEWmH+Njw==} - engines: {node: '>=14.16'} - dev: true - - /time-zone/1.0.0: - resolution: {integrity: sha512-TIsDdtKo6+XrPtiTm1ssmMngN1sAhyKnTO2kunQWqNPWIVvCm15Wmw4SWInwTVgJ5u/Tr04+8Ei9TNcw4x4ONA==} - engines: {node: '>=4'} - dev: true - - /tmp/0.0.33: + /tmp@0.0.33: resolution: {integrity: sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==} engines: {node: '>=0.6.0'} dependencies: os-tmpdir: 1.0.2 dev: true - /to-regex-range/5.0.1: - resolution: {integrity: sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==} - engines: {node: '>=8.0'} - dependencies: - is-number: 7.0.0 - dev: true - - /tr46/0.0.3: + /tr46@0.0.3: resolution: {integrity: sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==} dev: true - /tslib/2.6.2: + /tslib@2.6.2: resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==} dev: true - /typanion/3.14.0: + /typanion@3.14.0: resolution: {integrity: sha512-ZW/lVMRabETuYCd9O9ZvMhAh8GslSqaUjxmK/JLPCh6l73CvLBiuXswj/+7LdnWOgYsQ130FqLzFz5aGT4I3Ug==} dev: true - /type-fest/0.13.1: - resolution: {integrity: sha512-34R7HTnG0XIJcBSn5XhDd7nNFPRcXYRZrBB2O2jdKqYODldSzBAqzsWoZYYvduky73toYS/ESqxPvkDf/F0XMg==} - engines: {node: '>=10'} - dev: true - - /type-fest/0.21.3: + /type-fest@0.21.3: resolution: {integrity: sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==} engines: {node: '>=10'} dev: true - /universal-user-agent/6.0.0: + /universal-user-agent@6.0.0: resolution: {integrity: sha512-isyNax3wXoKaulPDZWHQqbmIx1k2tb9fb3GGDBRxCscfYV2Ch7WxPArBsFEG8s/safwXTT7H4QGhaIkTp9447w==} dev: true - /universalify/2.0.0: + /universalify@2.0.0: resolution: {integrity: sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==} engines: {node: '>= 10.0.0'} dev: true - /util-deprecate/1.0.2: + /util-deprecate@1.0.2: resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==} dev: true - /wcwidth/1.0.1: + /wcwidth@1.0.1: resolution: {integrity: sha512-XHPEwS0q6TaxcvG85+8EYkbiCux2XtWG2mkc47Ng2A77BQu9+DqIOJldST4HgPkuea7dvKSj5VgX3P1d4rW8Tg==} dependencies: defaults: 1.0.4 dev: true - /webidl-conversions/3.0.1: + /webidl-conversions@3.0.1: resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==} dev: true - /well-known-symbols/2.0.0: - resolution: {integrity: sha512-ZMjC3ho+KXo0BfJb7JgtQ5IBuvnShdlACNkKkdsqBmYw3bPAaJfPeYUo6tLUaT5tG/Gkh7xkpBhKRQ9e7pyg9Q==} - engines: {node: '>=6'} - dev: true - - /whatwg-url/5.0.0: + /whatwg-url@5.0.0: resolution: {integrity: sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==} dependencies: tr46: 0.0.3 webidl-conversions: 3.0.1 dev: true - /which/2.0.2: + /which@2.0.2: resolution: {integrity: sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==} engines: {node: '>= 8'} hasBin: true @@ -1609,7 +912,7 @@ packages: isexe: 2.0.0 dev: true - /wrap-ansi/6.2.0: + /wrap-ansi@6.2.0: resolution: {integrity: sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==} engines: {node: '>=8'} dependencies: @@ -1618,7 +921,7 @@ packages: strip-ansi: 6.0.1 dev: true - /wrap-ansi/7.0.0: + /wrap-ansi@7.0.0: resolution: {integrity: sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==} engines: {node: '>=10'} dependencies: @@ -1627,7 +930,7 @@ packages: strip-ansi: 6.0.1 dev: true - /wrap-ansi/8.1.0: + /wrap-ansi@8.1.0: resolution: {integrity: sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==} engines: {node: '>=12'} dependencies: @@ -1636,46 +939,6 @@ packages: strip-ansi: 7.1.0 dev: true - /wrappy/1.0.2: + /wrappy@1.0.2: resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==} dev: true - - /write-file-atomic/5.0.1: - resolution: {integrity: sha512-+QU2zd6OTD8XWIJCbffaiQeH9U73qIqafo1x6V1snCWYGJf6cVE0cDR4D8xRzcEnfI21IFrUPzPGtcPf8AC+Rw==} - engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} - dependencies: - imurmurhash: 0.1.4 - signal-exit: 4.1.0 - dev: true - - /y18n/5.0.8: - resolution: {integrity: sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==} - engines: {node: '>=10'} - dev: true - - /yallist/4.0.0: - resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==} - dev: true - - /yargs-parser/21.1.1: - resolution: {integrity: sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==} - engines: {node: '>=12'} - dev: true - - /yargs/17.7.2: - resolution: {integrity: sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==} - engines: {node: '>=12'} - dependencies: - cliui: 8.0.1 - escalade: 3.1.1 - get-caller-file: 2.0.5 - require-directory: 2.1.1 - string-width: 4.2.3 - y18n: 5.0.8 - yargs-parser: 21.1.1 - dev: true - - /yocto-queue/1.0.0: - resolution: {integrity: sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==} - engines: {node: '>=12.20'} - dev: true diff --git a/scripts/clone-rspack.mjs b/scripts/clone-rspack.mjs index cdd4d34..f4c5d9d 100644 --- a/scripts/clone-rspack.mjs +++ b/scripts/clone-rspack.mjs @@ -5,7 +5,7 @@ import fse from 'fs-extra'; const REPO = 'git@github.com:web-infra-dev/rspack.git'; const DEST = 'crates/.rspack_crates/'; -const CEHECKOUT = 'v0.3.6'; +const CEHECKOUT = 'main'; function createSpinner( text, From 0650d4da1c54e1f3ceb4ba33393515e0ea5b8f74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=B2=E5=B0=98?= Date: Mon, 30 Oct 2023 18:00:50 +0800 Subject: [PATCH 03/32] chore: deprecate built in react refresh --- crates/binding_options/Cargo.toml | 1 - crates/binding_options/src/options/raw_module.rs | 5 ----- 2 files changed, 6 deletions(-) diff --git a/crates/binding_options/Cargo.toml b/crates/binding_options/Cargo.toml index 6f13b5a..d3464bc 100644 --- a/crates/binding_options/Cargo.toml +++ b/crates/binding_options/Cargo.toml @@ -10,7 +10,6 @@ rspack_core = { path = "../.rspack_crates/rspack_cor 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" } diff --git a/crates/binding_options/src/options/raw_module.rs b/crates/binding_options/src/options/raw_module.rs index 4cc8e18..74ae56b 100644 --- a/crates/binding_options/src/options/raw_module.rs +++ b/crates/binding_options/src/options/raw_module.rs @@ -24,11 +24,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( From e0f374d4ca10f480849c0b093b070382b78cab98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=B2=E5=B0=98?= Date: Tue, 31 Oct 2023 17:27:28 +0800 Subject: [PATCH 04/32] feat: loader structure --- crates/loader_compilation/Cargo.toml | 3 + crates/loader_compilation/src/compiler.rs | 262 ++++++++++++++++++ crates/loader_compilation/src/lib.rs | 98 ++++--- .../src/transform/keep_export.rs | 0 .../src/transform/remove_export.rs | 0 5 files changed, 325 insertions(+), 38 deletions(-) create mode 100644 crates/loader_compilation/src/compiler.rs create mode 100644 crates/loader_compilation/src/transform/keep_export.rs create mode 100644 crates/loader_compilation/src/transform/remove_export.rs diff --git a/crates/loader_compilation/Cargo.toml b/crates/loader_compilation/Cargo.toml index 94e1198..7a825a6 100644 --- a/crates/loader_compilation/Cargo.toml +++ b/crates/loader_compilation/Cargo.toml @@ -8,11 +8,14 @@ edition = "2021" [dependencies] anyhow = { workspace = true } async-trait = { workspace = true } +dashmap = { workspace = true } either = "1" once_cell = { workspace = true } +rspack_ast = { path = "../.rspack_crates/rspack_ast" } rspack_core = { path = "../.rspack_crates/rspack_core" } rspack_error = { path = "../.rspack_crates/rspack_error" } rspack_loader_runner = { path = "../.rspack_crates/rspack_loader_runner" } +rspack_plugin_javascript = { path = "../.rspack_crates/rspack_plugin_javascript" } serde = { workspace = true, features = ["derive"] } serde_json = "1.0.100" swc_config = { workspace = true } diff --git a/crates/loader_compilation/src/compiler.rs b/crates/loader_compilation/src/compiler.rs new file mode 100644 index 0000000..f8a91a3 --- /dev/null +++ b/crates/loader_compilation/src/compiler.rs @@ -0,0 +1,262 @@ +use std::env; +use std::{path::PathBuf, sync::Arc}; +use anyhow::{Context, Error}; +use dashmap::DashMap; +use rspack_ast::javascript::{Ast as JsAst, Context as JsAstContext, Program as JsProgram}; +use swc_core:: { + base::{ + config::{Options, JsMinifyCommentOption, BuiltInput, IsModule}, + try_with_handler, SwcComments + }, + common::{ + Globals, SourceFile, SourceMap, GLOBALS, Mark, FileName, FilePathMapping, BytePos, + comments::{SingleThreadedComments, Comments, Comment, CommentKind}, + errors::{Handler, HANDLER}, + }, + ecma::{transforms::base::helpers::{self, Helpers}, ast::{Program, EsVersion}, visit::{Fold, FoldWith}, + parser::{parse_file_as_module, Syntax, parse_file_as_script, parse_file_as_program}}, +}; +use swc_config::config_types::BoolOr; + +fn minify_file_comments( + comments: &SingleThreadedComments, + preserve_comments: BoolOr, +) { + match preserve_comments { + BoolOr::Bool(true) | BoolOr::Data(JsMinifyCommentOption::PreserveAllComments) => {} + + BoolOr::Data(JsMinifyCommentOption::PreserveSomeComments) => { + let preserve_excl = |_: &BytePos, vc: &mut Vec| -> bool { + // Preserve license comments. + // + // See https://github.com/terser/terser/blob/798135e04baddd94fea403cfaab4ba8b22b1b524/lib/output.js#L175-L181 + vc.retain(|c: &Comment| { + c.text.contains("@lic") + || c.text.contains("@preserve") + || c.text.contains("@copyright") + || c.text.contains("@cc_on") + || (c.kind == CommentKind::Block && c.text.starts_with('!')) + }); + !vc.is_empty() + }; + let (mut l, mut t) = comments.borrow_all_mut(); + + l.retain(preserve_excl); + t.retain(preserve_excl); + } + + BoolOr::Bool(false) => { + let (mut l, mut t) = comments.borrow_all_mut(); + l.clear(); + t.clear(); + } + } +} + +pub(crate) struct SwcCompiler { + cm: Arc, + fm: Arc, + comments: SingleThreadedComments, + options: Options, + globals: Globals, + helpers: Helpers, +} + +impl SwcCompiler { + pub fn new(resource_path: PathBuf, source: String, mut options: Options) -> Result { + let cm = Arc::new(SourceMap::new(FilePathMapping::empty())); + let globals = Globals::default(); + GLOBALS.set(&globals, || { + let top_level_mark = Mark::new(); + let unresolved_mark = Mark::new(); + options.top_level_mark = Some(top_level_mark); + options.unresolved_mark = Some(unresolved_mark); + }); + // TODO: support read config of .swcrc. + let fm = cm.new_source_file(FileName::Real(resource_path), source); + let comments = SingleThreadedComments::default(); + let helpers = GLOBALS.set(&globals, || { + let external_helpers = options.config.jsc.external_helpers; + Helpers::new(external_helpers.into()) + }); + + Ok(Self { + cm, + fm, + comments, + options, + globals, + helpers, + }) + } + + pub fn run(&self, op: impl FnOnce() -> R) -> R { + GLOBALS.set(&self.globals, op) + } + + fn parse_js( + &self, + fm: Arc, + handler: &Handler, + target: EsVersion, + syntax: Syntax, + is_module: IsModule, + comments: Option<&dyn Comments>, + ) -> Result { + let mut error = false; + let mut errors = vec![]; + + let program_result = match is_module { + IsModule::Bool(true) => { + parse_file_as_module(&fm, syntax, target, comments, &mut errors).map(Program::Module) + } + IsModule::Bool(false) => { + parse_file_as_script(&fm, syntax, target, comments, &mut errors).map(Program::Script) + } + IsModule::Unknown => parse_file_as_program(&fm, syntax, target, comments, &mut errors), + }; + + for e in errors { + e.into_diagnostic(handler).emit(); + error = true; + } + + let mut res = program_result.map_err(|e| { + e.into_diagnostic(handler).emit(); + Error::msg("Syntax Error") + }); + + if error { + return Err(anyhow::anyhow!("Syntax Error")); + } + + if env::var("SWC_DEBUG").unwrap_or_default() == "1" { + res = res.with_context(|| format!("Parser config: {:?}", syntax)); + } + + res + + } + + pub fn parse<'a, P>( + &'a self, + program: Option, + before_pass: impl FnOnce(&Program) -> P + 'a, + ) -> Result, Error> + where + P: Fold + 'a, + { + let built = self.run(|| { + try_with_handler(self.cm.clone(), Default::default(), |handler| { + let built = self.options.build_as_input( + &self.cm, + &self.fm.name, + move |syntax, target, is_module| match program { + Some(v) => Ok(v), + _ => self.parse_js( + self.fm.clone(), + handler, + target, + syntax, + is_module, + Some(&self.comments), + ), + }, + self.options.output_path.as_deref(), + self.options.source_file_name.clone(), + handler, + // TODO: support config file. + Some(self.options.config.clone()), + Some(&self.comments), + before_pass, + )?; + + Ok(Some(built)) + }) + })?; + + match built { + Some(v) => Ok(v), + None => { + anyhow::bail!("cannot process file because it's ignored by .swcrc") + } + } + } + + pub fn transform(&self, config: BuiltInput) -> Result { + let program = config.program; + let mut pass = config.pass; + + let program = self.run(|| { + helpers::HELPERS.set(&self.helpers, || { + try_with_handler(self.cm.clone(), Default::default(), |handler| { + HANDLER.set(handler, || { + // Fold module + Ok(program.fold_with(&mut pass)) + }) + }) + }) + }); + if let Some(comments) = &config.comments { + minify_file_comments(comments, config.preserve_comments); + }; + + program + } + + pub fn comments(&self) -> &SingleThreadedComments { + &self.comments + } + + pub fn options(&self) -> &Options { + &self.options + } + + pub fn cm(&self) -> &Arc { + &self.cm + } +} + +pub(crate) trait IntoJsAst { + fn into_js_ast(self, program: Program) -> JsAst; +} + +impl IntoJsAst for SwcCompiler { + fn into_js_ast(self, program: Program) -> JsAst { + JsAst::default() + .with_program(JsProgram::new( + program, + Some(self.comments.into_swc_comments()), + )) + .with_context(JsAstContext { + globals: self.globals, + helpers: self.helpers, + source_map: self.cm, + top_level_mark: self + .options + .top_level_mark + .expect("`top_level_mark` should be initialized"), + unresolved_mark: self + .options + .unresolved_mark + .expect("`unresolved_mark` should be initialized"), + }) + } +} + +trait IntoSwcComments { + fn into_swc_comments(self) -> SwcComments; +} + +impl IntoSwcComments for SingleThreadedComments { + fn into_swc_comments(self) -> SwcComments { + let (l, t) = { + let (l, t) = self.take_all(); + (l.take(), t.take()) + }; + SwcComments { + leading: Arc::new(DashMap::from_iter(l.into_iter())), + trailing: Arc::new(DashMap::from_iter(t.into_iter())), + } + } +} \ No newline at end of file diff --git a/crates/loader_compilation/src/lib.rs b/crates/loader_compilation/src/lib.rs index 4f61f07..ad1f6f1 100644 --- a/crates/loader_compilation/src/lib.rs +++ b/crates/loader_compilation/src/lib.rs @@ -1,21 +1,19 @@ -use std::sync::Arc; -use rspack_core::{rspack_sources::SourceMap, LoaderRunnerContext, Mode}; +use rspack_ast::RspackAst; +use rspack_core::{rspack_sources::SourceMap, LoaderRunnerContext}; use rspack_loader_runner::{Identifiable, Identifier, Loader, LoaderContext}; use rspack_error::{ - internal_error, Diagnostic, DiagnosticKind, Error, InternalError, Result, Severity, - TraceableError, + internal_error, Result, }; -use swc_core::{ - base::{ - Compiler, - config::{InputSourceMap, Options}, - try_with_handler - }, - common::{FilePathMapping,GLOBALS, FileName, comments::SingleThreadedComments}, - ecma::transforms::base::pass::noop +use swc_core::base::config::{InputSourceMap, Options, OutputCharset}; +use rspack_plugin_javascript::{ + ast::{self, SourceMapConfig}, + TransformOutput, }; +mod compiler; mod transform; + use transform::*; +use compiler::{SwcCompiler, IntoJsAst}; pub struct CompilationLoader { identifier: Identifier, } @@ -43,8 +41,6 @@ impl Loader for CompilationLoader { let Some(content) = std::mem::take(&mut loader_context.content) else { return Err(internal_error!("No content found")); }; - - let compiler = Compiler::new(Arc::from(swc_core::common::SourceMap::new(FilePathMapping::empty()))); // TODO: init loader with custom options. let mut swc_options = Options::default(); @@ -56,31 +52,57 @@ impl Loader for CompilationLoader { } } - GLOBALS.set(&Default::default(), || { - try_with_handler(compiler.cm.clone(), Default::default(), |handler| { - compiler.run(|| { - let content = content.try_into_string()?; - let fm = compiler.cm.new_source_file(FileName::Real(resource_path.clone()), content.clone()); - let comments = SingleThreadedComments::default(); - let transform_options = SwcPluginOptions { - keep_export: None, - remove_export: None, - }; - let out = compiler.process_js_with_custom_pass( - fm, - None, - handler, - &swc_options, - comments, |_| { - transform(transform_options) - }, - |_| noop(), - )?; - Ok(()) - }) - }) + let devtool = &loader_context.context.options.devtool; + let source = content.try_into_string()?; + let compiler = SwcCompiler::new(resource_path.clone(), source.clone(), swc_options)?; + + let transform_options = SwcPluginOptions { + keep_export: None, + remove_export: None, + }; + let built = compiler.parse(None, |_| { + transform(transform_options) })?; - + + let codegen_options = ast::CodegenOptions { + target: Some(built.target), + minify: Some(built.minify), + ascii_only: built + .output + .charset + .as_ref() + .map(|v| matches!(v, OutputCharset::Ascii)), + source_map_config: SourceMapConfig { + enable: devtool.source_map(), + inline_sources_content: true, + emit_columns: !devtool.cheap(), + names: Default::default(), + }, + keep_comments: Some(true), + }; + let program = compiler.transform(built)?; + let ast = compiler.into_js_ast(program); + + // If swc-loader is the latest loader available, + // then loader produces AST, which could be used as an optimization. + if loader_context.loader_index() == 0 + && (loader_context + .current_loader() + .composed_index_by_identifier(&self.identifier) + .map(|idx| idx == 0) + .unwrap_or(true)) + { + loader_context + .additional_data + .insert(RspackAst::JavaScript(ast)); + loader_context.additional_data.insert(codegen_options); + loader_context.content = Some("".to_owned().into()) + } else { + let TransformOutput { code, map } = ast::stringify(&ast, codegen_options)?; + loader_context.content = Some(code.into()); + loader_context.source_map = map.map(|m| SourceMap::from_json(&m)).transpose()?; + } + Ok(()) } } diff --git a/crates/loader_compilation/src/transform/keep_export.rs b/crates/loader_compilation/src/transform/keep_export.rs new file mode 100644 index 0000000..e69de29 diff --git a/crates/loader_compilation/src/transform/remove_export.rs b/crates/loader_compilation/src/transform/remove_export.rs new file mode 100644 index 0000000..e69de29 From f75281009d10b012442a2bb38f4fe2f5cef882ca Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Tue, 31 Oct 2023 17:34:21 +0800 Subject: [PATCH 05/32] fix: update loader test case --- crates/loader_compilation/tests/fixtures.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/crates/loader_compilation/tests/fixtures.rs b/crates/loader_compilation/tests/fixtures.rs index d99f90b..b6c9d18 100644 --- a/crates/loader_compilation/tests/fixtures.rs +++ b/crates/loader_compilation/tests/fixtures.rs @@ -1,14 +1,23 @@ use std::{str::FromStr,env, fs,path::{Path, PathBuf}, sync::Arc}; use loader_compilation::CompilationLoader; -use rspack_core::{run_loaders, CompilerContext, CompilerOptions, SideEffectOption}; -use rspack_loader_runner::ResourceData; +use rspack_core::{ + run_loaders, CompilerContext, CompilerOptions, Loader, LoaderRunnerContext, ResourceData, SideEffectOption, +}; +use serde_json::json; +use swc_core::base::config::{PluginConfig, Config}; async fn loader_test(actual: impl AsRef, expected: impl AsRef) { let tests_path = PathBuf::from(concat!(env!("CARGO_MANIFEST_DIR"))).join("tests"); - let actual_path = tests_path.join(actual); let expected_path = tests_path.join(expected); + let actual_path = tests_path.join(actual); + let plugin_path = tests_path.join("my_first_plugin.wasm"); + let mut options = Config::default(); + options.jsc.experimental.plugins = Some(vec![PluginConfig( + plugin_path.to_string_lossy().to_string(), + json!(null), + )]); let (result, _) = run_loaders( - &[Arc::new(CompilationLoader::default())], + &[Arc::new(CompilationLoader::new(options)) as Arc>], &ResourceData::new(actual_path.to_string_lossy().to_string(), actual_path), &[], CompilerContext { @@ -71,11 +80,12 @@ async fn loader_test(actual: impl AsRef, expected: impl AsRef) { side_effects: SideEffectOption::False, provided_exports: Default::default(), used_exports: Default::default(), + inner_graph: Default::default(), }, profile: false, }), resolver_factory: Default::default(), - } + }, ) .await .expect("TODO:") From 408a4dae194b5ab009f5e80ad161c97cd5bdaa41 Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Tue, 31 Oct 2023 17:55:03 +0800 Subject: [PATCH 06/32] fix: impl new --- crates/binding_options/src/options/raw_module.rs | 2 +- crates/loader_compilation/src/lib.rs | 6 ++---- crates/loader_compilation/tests/fixtures.rs | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/crates/binding_options/src/options/raw_module.rs b/crates/binding_options/src/options/raw_module.rs index 74ae56b..9b909d5 100644 --- a/crates/binding_options/src/options/raw_module.rs +++ b/crates/binding_options/src/options/raw_module.rs @@ -27,7 +27,7 @@ pub fn get_builtin_loader(builtin: &str, options: Option<&str>) -> BoxLoader { if builtin.starts_with(COMPILATION_LOADER_IDENTIFIER) { return Arc::new( - loader_compilation::CompilationLoader::default().with_identifier(builtin.into()), + loader_compilation::CompilationLoader::new().with_identifier(builtin.into()), ); } diff --git a/crates/loader_compilation/src/lib.rs b/crates/loader_compilation/src/lib.rs index ad1f6f1..617b2b4 100644 --- a/crates/loader_compilation/src/lib.rs +++ b/crates/loader_compilation/src/lib.rs @@ -18,15 +18,13 @@ pub struct CompilationLoader { identifier: Identifier, } -impl Default for CompilationLoader { - fn default() -> Self { +impl CompilationLoader { + pub fn new() -> Self { Self { identifier: COMPILATION_LOADER_IDENTIFIER.into(), } } -} -impl CompilationLoader { pub fn with_identifier(mut self, identifier: Identifier) -> Self { assert!(identifier.starts_with(COMPILATION_LOADER_IDENTIFIER)); self.identifier = identifier; diff --git a/crates/loader_compilation/tests/fixtures.rs b/crates/loader_compilation/tests/fixtures.rs index b6c9d18..efb3880 100644 --- a/crates/loader_compilation/tests/fixtures.rs +++ b/crates/loader_compilation/tests/fixtures.rs @@ -17,7 +17,7 @@ async fn loader_test(actual: impl AsRef, expected: impl AsRef) { json!(null), )]); let (result, _) = run_loaders( - &[Arc::new(CompilationLoader::new(options)) as Arc>], + &[Arc::new(CompilationLoader::new()) as Arc>], &ResourceData::new(actual_path.to_string_lossy().to_string(), actual_path), &[], CompilerContext { From 6fe41befa86241637559850c30b18eb3c84a7672 Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Thu, 2 Nov 2023 15:40:45 +0800 Subject: [PATCH 07/32] feat: add tranform chain of remove exports and keep exports --- crates/loader_compilation/Cargo.toml | 1 + crates/loader_compilation/src/lib.rs | 8 +- .../src/transform/keep_export.rs | 589 ++++++++++++++++++ .../loader_compilation/src/transform/mod.rs | 38 +- .../src/transform/remove_export.rs | 586 +++++++++++++++++ crates/loader_compilation/tests/fixtures.rs | 6 +- .../tests/fixtures/basic/input.js | 7 + 7 files changed, 1206 insertions(+), 29 deletions(-) diff --git a/crates/loader_compilation/Cargo.toml b/crates/loader_compilation/Cargo.toml index 7a825a6..4e519ce 100644 --- a/crates/loader_compilation/Cargo.toml +++ b/crates/loader_compilation/Cargo.toml @@ -10,6 +10,7 @@ anyhow = { workspace = true } async-trait = { workspace = true } dashmap = { workspace = true } either = "1" +fxhash= "0.2.1" once_cell = { workspace = true } rspack_ast = { path = "../.rspack_crates/rspack_ast" } rspack_core = { path = "../.rspack_crates/rspack_core" } diff --git a/crates/loader_compilation/src/lib.rs b/crates/loader_compilation/src/lib.rs index 617b2b4..fde47b2 100644 --- a/crates/loader_compilation/src/lib.rs +++ b/crates/loader_compilation/src/lib.rs @@ -55,8 +55,12 @@ impl Loader for CompilationLoader { let compiler = SwcCompiler::new(resource_path.clone(), source.clone(), swc_options)?; let transform_options = SwcPluginOptions { - keep_export: None, - remove_export: None, + keep_export: Some(KeepExportOptions { + export_names: vec!["default".to_string()], + }), + remove_export: Some(RemoveExportOptions { + remove_names: vec!["default".to_string()], + }), }; let built = compiler.parse(None, |_| { transform(transform_options) diff --git a/crates/loader_compilation/src/transform/keep_export.rs b/crates/loader_compilation/src/transform/keep_export.rs index e69de29..1d23124 100644 --- a/crates/loader_compilation/src/transform/keep_export.rs +++ b/crates/loader_compilation/src/transform/keep_export.rs @@ -0,0 +1,589 @@ +// transform code is modified based on swc plugin of keep_export: +// https://github.com/ice-lab/swc-plugins/tree/main/packages/keep-export +use fxhash::FxHashSet; +use std::mem::take; +use swc_core::ecma::{ + ast::*, + visit::{Fold, FoldWith, noop_fold_type}, +}; +use swc_core::common::{ + DUMMY_SP, pass::{Repeat, Repeated} +}; + +/// State of the transforms. Shared by the analyzer and the transform. +#[derive(Debug, Default)] +struct State { + /// Identifiers referenced by other functions. + /// + /// Cleared before running each pass, because we drop ast nodes between the + /// passes. + refs_from_other: FxHashSet, + + /// Identifiers referenced by kept functions or derivatives. + /// + /// Preserved between runs, because we should remember derivatives of data + /// functions as the data function itself is already removed. + refs_used: FxHashSet, + + should_run_again: bool, + keep_exports: Vec, +} + +impl State { + fn should_keep_identifier(&mut self, i: &Ident) -> bool { + self.keep_exports.contains(&String::from(&*i.sym)) + } + + fn should_keep_default(&mut self) -> bool { + self.keep_exports.contains(&String::from("default")) + } +} + +struct KeepExport { + pub state: State, + in_lhs_of_var: bool, +} + +impl KeepExport { + fn should_remove(&self, id: Id) -> bool { + !self.state.refs_used.contains(&id) && !self.state.refs_from_other.contains(&id) + } + + /// Mark identifiers in `n` as a candidate for removal. + fn mark_as_candidate(&mut self, n: N) -> N + where + N: for<'a> FoldWith>, + { + // Analyzer never change `in_kept_fn` to false, so all identifiers in `n` will + // be marked as referenced from a data function. + let mut v = Analyzer { + state: &mut self.state, + in_lhs_of_var: false, + in_kept_fn: false, + }; + + let n = n.fold_with(&mut v); + self.state.should_run_again = true; + n + } +} + +impl Repeated for KeepExport { + fn changed(&self) -> bool { + self.state.should_run_again + } + + fn reset(&mut self) { + self.state.refs_from_other.clear(); + self.state.should_run_again = false; + } +} + +impl Fold for KeepExport { + // This is important for reducing binary sizes. + noop_fold_type!(); + + // Remove import expression + fn fold_import_decl(&mut self, mut i: ImportDecl) -> ImportDecl { + // Imports for side effects. + if i.specifiers.is_empty() { + return i; + } + + i.specifiers.retain(|s| match s { + ImportSpecifier::Named(ImportNamedSpecifier { local, .. }) + | ImportSpecifier::Default(ImportDefaultSpecifier { local, .. }) + | ImportSpecifier::Namespace(ImportStarAsSpecifier { local, .. }) => { + if self.should_remove(local.to_id()) { + self.state.should_run_again = true; + false + } else { + true + } + } + }); + + i + } + + fn fold_module(&mut self, mut m: Module) -> Module { + { + // Fill the state. + let mut v = Analyzer { + state: &mut self.state, + in_lhs_of_var: false, + in_kept_fn: false, + }; + m = m.fold_with(&mut v); + } + + m.fold_children_with(self) + } + + fn fold_module_items(&mut self, mut items: Vec) -> Vec { + items = items.fold_children_with(self); + + // Drop nodes. + items.retain(|s| !matches!(s, ModuleItem::Stmt(Stmt::Empty(..)))); + + // If all exports are deleted, return the empty named export. + if items.len() == 0 { + items.push(ModuleItem::ModuleDecl(ModuleDecl::ExportNamed(NamedExport{ + span: DUMMY_SP, + specifiers: Vec::new(), + src: None, + type_only: false, + with: Default::default(), + }))); + } + + items + } + + fn fold_module_item(&mut self, i: ModuleItem) -> ModuleItem { + if let ModuleItem::ModuleDecl(ModuleDecl::Import(i)) = i { + let i = i.fold_with(self); + + if i.specifiers.is_empty() { + return ModuleItem::Stmt(Stmt::Empty(EmptyStmt { span: DUMMY_SP })); + } + + return ModuleItem::ModuleDecl(ModuleDecl::Import(i)); + } + + let i = i.fold_children_with(self); + + match &i { + ModuleItem::ModuleDecl(ModuleDecl::ExportNamed(e)) if e.specifiers.is_empty() => { + return ModuleItem::Stmt(Stmt::Empty(EmptyStmt { span: DUMMY_SP })) + } + _ => {} + } + + i + } + + fn fold_named_export(&mut self, mut n: NamedExport) -> NamedExport { + n.specifiers = n.specifiers.fold_with(self); + + n.specifiers.retain(|s| { + let preserve = match s { + ExportSpecifier::Namespace(ExportNamespaceSpecifier { + name: ModuleExportName::Ident(exported), + .. + }) + | ExportSpecifier::Default(ExportDefaultSpecifier { exported, .. }) + | ExportSpecifier::Named(ExportNamedSpecifier { + exported: Some(ModuleExportName::Ident(exported)), + .. + }) => self + .state + .should_keep_identifier(exported), + ExportSpecifier::Named(ExportNamedSpecifier { + orig: ModuleExportName::Ident(orig), + .. + }) => self + .state + .should_keep_identifier(orig), + _ => false, + }; + + match preserve { + false => { + if let ExportSpecifier::Named(ExportNamedSpecifier { + orig: ModuleExportName::Ident(_orig), + .. + }) = s + { + self.state.should_run_again = true; + } + + false + } + true => true, + } + }); + + n + } + + /// This methods returns [Pat::Invalid] if the pattern should be removed. + fn fold_pat(&mut self, mut p: Pat) -> Pat { + p = p.fold_children_with(self); + + if self.in_lhs_of_var { + match &mut p { + Pat::Ident(name) => { + if self.should_remove(name.id.to_id()) { + self.state.should_run_again = true; + return Pat::Invalid(Invalid { span: DUMMY_SP }); + } + } + Pat::Array(arr) => { + if !arr.elems.is_empty() { + arr.elems.retain(|e| !matches!(e, Some(Pat::Invalid(..)))); + + if arr.elems.is_empty() { + return Pat::Invalid(Invalid { span: DUMMY_SP }); + } + } + } + Pat::Object(obj) => { + if !obj.props.is_empty() { + obj.props = take(&mut obj.props) + .into_iter() + .filter_map(|prop| match prop { + ObjectPatProp::KeyValue(prop) => { + if prop.value.is_invalid() { + None + } else { + Some(ObjectPatProp::KeyValue(prop)) + } + } + ObjectPatProp::Assign(prop) => { + if self.should_remove(prop.key.to_id()) { + self.mark_as_candidate(prop.value); + + None + } else { + Some(ObjectPatProp::Assign(prop)) + } + } + ObjectPatProp::Rest(prop) => { + if prop.arg.is_invalid() { + None + } else { + Some(ObjectPatProp::Rest(prop)) + } + } + }) + .collect(); + + if obj.props.is_empty() { + return Pat::Invalid(Invalid { span: DUMMY_SP }); + } + } + } + Pat::Rest(rest) => { + if rest.arg.is_invalid() { + return Pat::Invalid(Invalid { span: DUMMY_SP }); + } + } + _ => {} + } + } + + p + } + + #[allow(clippy::single_match)] + fn fold_stmt(&mut self, mut s: Stmt) -> Stmt { + match s { + Stmt::Decl(Decl::Fn(f)) => { + if self.should_remove(f.ident.to_id()) { + self.mark_as_candidate(f.function); + return Stmt::Empty(EmptyStmt { span: DUMMY_SP }); + } + + s = Stmt::Decl(Decl::Fn(f)); + } + Stmt::Decl(Decl::Class(c)) => { + if self.should_remove(c.ident.to_id()) { + self.mark_as_candidate(c.class); + return Stmt::Empty(EmptyStmt { span: DUMMY_SP }); + } + + s = Stmt::Decl(Decl::Class(c)); + } + _ => {} + } + + let s = s.fold_children_with(self); + match s { + Stmt::Decl(Decl::Var(v)) if v.decls.is_empty() => { + return Stmt::Empty(EmptyStmt { span: DUMMY_SP }); + } + _ => {} + } + + s + } + + /// This method make `name` of [VarDeclarator] to [Pat::Invalid] if it + /// should be removed. + fn fold_var_declarator(&mut self, mut d: VarDeclarator) -> VarDeclarator { + let old = self.in_lhs_of_var; + self.in_lhs_of_var = true; + let name = d.name.fold_with(self); + + self.in_lhs_of_var = false; + if name.is_invalid() { + d.init = self.mark_as_candidate(d.init); + } + let init = d.init.fold_with(self); + self.in_lhs_of_var = old; + + VarDeclarator { name, init, ..d } + } + + fn fold_var_declarators(&mut self, mut decls: Vec) -> Vec { + decls = decls.fold_children_with(self); + decls.retain(|d| !d.name.is_invalid()); + + decls + } +} + +struct Analyzer<'a> { + state: &'a mut State, + in_lhs_of_var: bool, + in_kept_fn: bool, +} + +impl Analyzer<'_> { + fn add_ref(&mut self, id: Id) { + if self.in_kept_fn { + self.state.refs_used.insert(id); + } else { + self.state.refs_from_other.insert(id); + } + } + + fn check_default>(&mut self, e: T) -> T { + if self.state.should_keep_default() { + let old_in_kept = self.in_kept_fn; + self.in_kept_fn = true; + let e = e.fold_children_with(self); + self.in_kept_fn = old_in_kept; + return e + } + + return e; + } +} + +impl Fold for Analyzer<'_> { + // This is important for reducing binary sizes. + noop_fold_type!(); + + fn fold_binding_ident(&mut self, i: BindingIdent) -> BindingIdent { + if !self.in_lhs_of_var || self.in_kept_fn { + self.add_ref(i.id.to_id()); + } + i + } + + fn fold_export_named_specifier(&mut self, s: ExportNamedSpecifier) -> ExportNamedSpecifier { + if let ModuleExportName::Ident(i) = &s.orig { + match &s.exported { + Some(exported) => { + if let ModuleExportName::Ident(e) = exported { + if self.state.should_keep_identifier(e) { + self.add_ref(i.to_id()); + } + } + } + None => { + if self.state.should_keep_identifier(i) { + self.add_ref(i.to_id()); + } + } + } + } + s + } + + fn fold_export_decl(&mut self, s: ExportDecl) -> ExportDecl { + let old_in_kept = self.in_kept_fn; + + match &s.decl { + Decl::Fn(f) => { + if self.state.should_keep_identifier(&f.ident) { + self.in_kept_fn = true; + self.add_ref(f.ident.to_id()); + } + } + + Decl::Var(d) => { + if d.decls.is_empty() { + return s; + } + if let Pat::Ident(id) = &d.decls[0].name { + if self.state.should_keep_identifier(&id.id) { + self.in_kept_fn = true; + self.add_ref(id.to_id()); + } + } + } + _ => {} + } + let e = s.fold_children_with(self); + self.in_kept_fn = old_in_kept; + e + } + + fn fold_expr(&mut self, e: Expr) -> Expr { + let e = e.fold_children_with(self); + + if let Expr::Ident(i) = &e { + self.add_ref(i.to_id()); + } + e + } + + fn fold_jsx_element(&mut self, jsx: JSXElement) -> JSXElement { + fn get_leftmost_id_member_expr(e: &JSXMemberExpr) -> Id { + match &e.obj { + JSXObject::Ident(i) => i.to_id(), + JSXObject::JSXMemberExpr(e) => get_leftmost_id_member_expr(e), + } + } + + match &jsx.opening.name { + JSXElementName::Ident(i) => { + self.add_ref(i.to_id()); + } + JSXElementName::JSXMemberExpr(e) => { + self.add_ref(get_leftmost_id_member_expr(e)); + } + _ => {} + } + + jsx.fold_children_with(self) + } + + fn fold_fn_decl(&mut self, f: FnDecl) -> FnDecl { + let f = f.fold_children_with(self); + if self.in_kept_fn { + self.add_ref(f.ident.to_id()); + } + f + } + + fn fold_fn_expr(&mut self, f: FnExpr) -> FnExpr { + let f = f.fold_children_with(self); + if let Some(id) = &f.ident { + self.add_ref(id.to_id()); + } + f + } + + /// Drops [ExportDecl] if all specifiers are removed. + fn fold_module_item(&mut self, s: ModuleItem) -> ModuleItem { + match s { + ModuleItem::ModuleDecl(ModuleDecl::ExportNamed(e)) if !e.specifiers.is_empty() => { + let e = e.fold_with(self); + + if e.specifiers.is_empty() { + return ModuleItem::Stmt(Stmt::Empty(EmptyStmt { span: DUMMY_SP })); + } + + return ModuleItem::ModuleDecl(ModuleDecl::ExportNamed(e)); + } + + ModuleItem::Stmt(Stmt::Expr(_e)) => { + // remove top expression + return ModuleItem::Stmt(Stmt::Empty(EmptyStmt { span: DUMMY_SP })) + } + + ModuleItem::Stmt(Stmt::If(_e)) => { + return ModuleItem::Stmt(Stmt::Empty(EmptyStmt { span: DUMMY_SP })) + } + + ModuleItem::Stmt(Stmt::DoWhile(_e)) => { + return ModuleItem::Stmt(Stmt::Empty(EmptyStmt { span: DUMMY_SP })) + } + + ModuleItem::Stmt(Stmt::Try(_e)) => { + return ModuleItem::Stmt(Stmt::Empty(EmptyStmt { span: DUMMY_SP })) + } + _ => {} + }; + + if let ModuleItem::ModuleDecl(ModuleDecl::ExportDecl(e)) = &s { + match &e.decl { + Decl::Fn(f) => { + if self.state.should_keep_identifier(&f.ident) { + let s = s.fold_children_with(self); + return s; + } else { + return ModuleItem::Stmt(Stmt::Empty(EmptyStmt { span: DUMMY_SP })); + } + } + + Decl::Var(d) => { + if d.decls.is_empty() { + return ModuleItem::Stmt(Stmt::Empty(EmptyStmt { span: DUMMY_SP })); + } + + if let Pat::Ident(id) = &d.decls[0].name { + if self.state.should_keep_identifier(&id.id) { + let s = s.fold_children_with(self); + return s; + } else { + return ModuleItem::Stmt(Stmt::Empty(EmptyStmt { span: DUMMY_SP })); + } + } + } + _ => {} + } + } + + if let ModuleItem::ModuleDecl(ModuleDecl::ExportDefaultExpr(_e)) = &s { + if !self.state.should_keep_default() { + return ModuleItem::Stmt(Stmt::Empty(EmptyStmt { span: DUMMY_SP })); + } + } + + if let ModuleItem::ModuleDecl(ModuleDecl::ExportDefaultDecl(_e)) = &s { + if !self.state.should_keep_default() { + return ModuleItem::Stmt(Stmt::Empty(EmptyStmt { span: DUMMY_SP })); + } + } + + // Visit children to ensure that all references is added to the scope. + let s = s.fold_children_with(self); + s + } + + fn fold_default_decl(&mut self, d: DefaultDecl) -> DefaultDecl { + return self.check_default(d); + } + + fn fold_export_default_expr(&mut self, e: ExportDefaultExpr) -> ExportDefaultExpr { + return self.check_default(e); + } + + fn fold_prop(&mut self, p: Prop) -> Prop { + let p = p.fold_children_with(self); + + if let Prop::Shorthand(i) = &p { + self.add_ref(i.to_id()); + } + + p + } + + fn fold_var_declarator(&mut self, mut v: VarDeclarator) -> VarDeclarator { + let old_in_lhs_of_var = self.in_lhs_of_var; + + self.in_lhs_of_var = true; + v.name = v.name.fold_with(self); + + self.in_lhs_of_var = false; + v.init = v.init.fold_with(self); + + self.in_lhs_of_var = old_in_lhs_of_var; + v + } +} + +pub fn keep_export(exports: Vec) -> impl Fold { + Repeat::new(KeepExport { + state: State { + keep_exports: exports, + ..Default::default() + }, + in_lhs_of_var: false, + }) +} \ No newline at end of file diff --git a/crates/loader_compilation/src/transform/mod.rs b/crates/loader_compilation/src/transform/mod.rs index e0e15f8..9e08e7e 100644 --- a/crates/loader_compilation/src/transform/mod.rs +++ b/crates/loader_compilation/src/transform/mod.rs @@ -2,13 +2,19 @@ use either::Either; use swc_core::common::chain; use swc_core::ecma::{ transforms::base::pass::noop, - visit::{as_folder, Fold, VisitMut}, + visit::{as_folder, Fold, VisitMut, Visit}, ast::Module, }; +mod keep_export; +mod remove_export; + +use keep_export::keep_export; +use remove_export::remove_export; + macro_rules! either { ($config:expr, $f:expr) => { - if let Some(config) = &$config { + if let Some(config) = $config { Either::Left($f(config)) } else { Either::Right(noop()) @@ -24,37 +30,25 @@ macro_rules! either { } pub struct KeepExportOptions { - export_names: Vec, + pub export_names: Vec, } -pub struct RemoveExport { - remove_names: Vec, +pub struct RemoveExportOptions { + pub remove_names: Vec, } pub struct SwcPluginOptions { pub keep_export: Option, - pub remove_export: Option, + pub remove_export: Option, } pub(crate) fn transform<'a>(plugin_options: SwcPluginOptions) -> impl Fold + 'a { chain!( - either!(plugin_options.keep_export, |_| { - keep_export() + either!(plugin_options.keep_export, |options: KeepExportOptions| { + keep_export(options.export_names) }), - either!(plugin_options.remove_export, |_| { - keep_export() + either!(plugin_options.remove_export, |options: RemoveExportOptions| { + remove_export(options.remove_names) }), ) -} - -struct KeepExport; - -impl VisitMut for KeepExport { - fn visit_mut_module(&mut self, module: &mut Module) { - - } -} - -fn keep_export() -> impl Fold { - as_folder(KeepExport) } \ No newline at end of file diff --git a/crates/loader_compilation/src/transform/remove_export.rs b/crates/loader_compilation/src/transform/remove_export.rs index e69de29..f58b3c1 100644 --- a/crates/loader_compilation/src/transform/remove_export.rs +++ b/crates/loader_compilation/src/transform/remove_export.rs @@ -0,0 +1,586 @@ +// transform code is modified based on swc plugin of remove_export: +// https://github.com/ice-lab/swc-plugins/tree/main/packages/remove-export +use fxhash::FxHashSet; +use std::mem::take; +use swc_core::ecma::{ + ast::*, + visit::{Fold, FoldWith, noop_fold_type}, +}; +use rspack_error::Error; +use swc_core::common::{ + DUMMY_SP, pass::{Repeat, Repeated} +}; + +/// State of the transforms. Shared by the analyzer and the transform. +#[derive(Debug, Default)] +struct State { + /// Identifiers referenced by non-data function codes. + /// + /// Cleared before running each pass, because we drop ast nodes between the + /// passes. + refs_from_other: FxHashSet, + + /// Identifiers referenced by data functions or derivatives. + /// + /// Preserved between runs, because we should remember derivatives of data + /// functions as the data function itself is already removed. + refs_from_data_fn: FxHashSet, + + cur_declaring: FxHashSet, + + should_run_again: bool, + remove_exports: Vec, +} + +impl State { + fn should_remove_identifier(&mut self, i: &Ident) -> Result { + Ok(self.remove_exports.contains(&String::from(&*i.sym))) + } + fn should_remove_default(&mut self) -> bool { + self.remove_exports.contains(&String::from("default")) + } +} + +struct Analyzer<'a> { + state: &'a mut State, + in_lhs_of_var: bool, + in_data_fn: bool, +} + +impl Analyzer<'_> { + fn add_ref(&mut self, id: Id) { + if self.in_data_fn { + self.state.refs_from_data_fn.insert(id); + } else { + if self.state.cur_declaring.contains(&id) { + return; + } + + self.state.refs_from_other.insert(id); + } + } + + fn check_default>(&mut self, e: T) -> T { + if self.state.should_remove_default() { + let old_in_data = self.in_data_fn; + self.in_data_fn = true; + let e = e.fold_children_with(self); + self.in_data_fn = old_in_data; + return e + } + + return e.fold_children_with(self); + } +} + +impl Fold for Analyzer<'_> { + // This is important for reducing binary sizes. + noop_fold_type!(); + + fn fold_binding_ident(&mut self, i: BindingIdent) -> BindingIdent { + if !self.in_lhs_of_var || self.in_data_fn { + self.add_ref(i.id.to_id()); + } + + i + } + + fn fold_export_named_specifier(&mut self, s: ExportNamedSpecifier) -> ExportNamedSpecifier { + if let ModuleExportName::Ident(id) = &s.orig { + if !self.state.remove_exports.contains(&String::from(&*id.sym)) { + self.add_ref(id.to_id()); + } + } + + s + } + + fn fold_export_decl(&mut self, s: ExportDecl) -> ExportDecl { + let old_in_data = self.in_data_fn; + + match &s.decl { + Decl::Fn(f) => { + if let Ok(should_remove_identifier) = self.state.should_remove_identifier(&f.ident) { + if should_remove_identifier { + self.in_data_fn = true; + self.add_ref(f.ident.to_id()); + } + } + } + + Decl::Var(d) => { + if d.decls.is_empty() { + return s; + } + if let Pat::Ident(id) = &d.decls[0].name { + if self.state.remove_exports.contains(&String::from(&*id.id.sym)) { + self.in_data_fn = true; + self.add_ref(id.to_id()); + } + } + } + _ => {} + } + + let e = s.fold_children_with(self); + + self.in_data_fn = old_in_data; + + return e; + } + + fn fold_expr(&mut self, e: Expr) -> Expr { + let e = e.fold_children_with(self); + + if let Expr::Ident(i) = &e { + self.add_ref(i.to_id()); + } + + e + } + + fn fold_jsx_element(&mut self, jsx: JSXElement) -> JSXElement { + fn get_leftmost_id_member_expr(e: &JSXMemberExpr) -> Id { + match &e.obj { + JSXObject::Ident(i) => i.to_id(), + JSXObject::JSXMemberExpr(e) => get_leftmost_id_member_expr(e), + } + } + + match &jsx.opening.name { + JSXElementName::Ident(i) => { + self.add_ref(i.to_id()); + } + JSXElementName::JSXMemberExpr(e) => { + self.add_ref(get_leftmost_id_member_expr(e)); + } + _ => {} + } + + jsx.fold_children_with(self) + } + + fn fold_fn_decl(&mut self, f: FnDecl) -> FnDecl { + let f = f.fold_children_with(self); + if self.in_data_fn { + self.add_ref(f.ident.to_id()); + } + + f + } + + fn fold_fn_expr(&mut self, f: FnExpr) -> FnExpr { + let f = f.fold_children_with(self); + if let Some(id) = &f.ident { + self.add_ref(id.to_id()); + } + + f + } + + /// Drops [ExportDecl] if all specifiers are removed. + fn fold_module_item(&mut self, s: ModuleItem) -> ModuleItem { + match s { + ModuleItem::ModuleDecl(ModuleDecl::ExportNamed(e)) if !e.specifiers.is_empty() => { + let e = e.fold_with(self); + + if e.specifiers.is_empty() { + return ModuleItem::Stmt(Stmt::Empty(EmptyStmt { span: DUMMY_SP })); + } + + return ModuleItem::ModuleDecl(ModuleDecl::ExportNamed(e)); + } + _ => {} + }; + + // Visit children to ensure that all references is added to the scope. + let s = s.fold_children_with(self); + + if let ModuleItem::ModuleDecl(ModuleDecl::ExportDecl(e)) = &s { + match &e.decl { + Decl::Fn(f) => { + if let Ok(should_remove_identifier) = self.state.should_remove_identifier(&f.ident) { + if should_remove_identifier { + return ModuleItem::Stmt(Stmt::Empty(EmptyStmt { span: DUMMY_SP })); + } + } else { + return s; + } + } + + Decl::Var(d) => { + if d.decls.is_empty() { + return ModuleItem::Stmt(Stmt::Empty(EmptyStmt { span: DUMMY_SP })); + } + } + _ => {} + } + } + + s + } + + fn fold_named_export(&mut self, mut n: NamedExport) -> NamedExport { + if n.src.is_some() { + n.specifiers = n.specifiers.fold_with(self); + } + + n + } + + fn fold_default_decl(&mut self, d: DefaultDecl) -> DefaultDecl { + return self.check_default(d); + } + + fn fold_export_default_expr(&mut self, e: ExportDefaultExpr) -> ExportDefaultExpr { + return self.check_default(e); + } + + fn fold_prop(&mut self, p: Prop) -> Prop { + let p = p.fold_children_with(self); + if let Prop::Shorthand(i) = &p { + self.add_ref(i.to_id()); + } + p + } + + fn fold_var_declarator(&mut self, mut v: VarDeclarator) -> VarDeclarator { + let old_in_lhs_of_var = self.in_lhs_of_var; + + self.in_lhs_of_var = true; + v.name = v.name.fold_with(self); + + self.in_lhs_of_var = false; + v.init = v.init.fold_with(self); + + self.in_lhs_of_var = old_in_lhs_of_var; + v + } +} + +struct RemoveExport { + pub state: State, + in_lhs_of_var: bool, +} + +impl RemoveExport { + fn should_remove(&self, id: Id) -> bool { + self.state.refs_from_data_fn.contains(&id) && !self.state.refs_from_other.contains(&id) + } + + /// Mark identifiers in `n` as a candidate for removal. + fn mark_as_candidate(&mut self, n: N) -> N + where + N: for<'a> FoldWith>, + { + // Analyzer never change `in_data_fn` to false, so all identifiers in `n` will + // be marked as referenced from a data function. + let mut v = Analyzer { + state: &mut self.state, + in_lhs_of_var: false, + in_data_fn: true, + }; + + let n = n.fold_with(&mut v); + self.state.should_run_again = true; + n + } + + fn create_empty_fn(&mut self) -> FnExpr { + return FnExpr { + ident: None, + function: Box::new(Function { + params: vec![], + body: Some(BlockStmt { + span: DUMMY_SP, + stmts: vec![] + }), + span: DUMMY_SP, + is_generator: false, + is_async: false, + decorators: vec![], + return_type: None, + type_params: None, + }) + }; + } +} + +impl Repeated for RemoveExport { + fn changed(&self) -> bool { + self.state.should_run_again + } + + fn reset(&mut self) { + self.state.refs_from_other.clear(); + self.state.cur_declaring.clear(); + self.state.should_run_again = false; + } +} + +impl Fold for RemoveExport { + // This is important for reducing binary sizes. + noop_fold_type!(); + + // Remove import expression + fn fold_import_decl(&mut self, mut i: ImportDecl) -> ImportDecl { + // Imports for side effects. + if i.specifiers.is_empty() { + return i; + } + + i.specifiers.retain(|s| match s { + ImportSpecifier::Named(ImportNamedSpecifier { local, .. }) + | ImportSpecifier::Default(ImportDefaultSpecifier { local, .. }) + | ImportSpecifier::Namespace(ImportStarAsSpecifier { local, .. }) => { + if self.should_remove(local.to_id()) { + self.state.should_run_again = true; + false + } else { + true + } + } + }); + + i + } + + fn fold_module(&mut self, mut m: Module) -> Module { + { + // Fill the state. + let mut v = Analyzer { + state: &mut self.state, + in_lhs_of_var: false, + in_data_fn: false, + }; + m = m.fold_with(&mut v); + } + + m.fold_children_with(self) + } + + fn fold_module_items(&mut self, mut items: Vec) -> Vec { + items = items.fold_children_with(self); + // Drop nodes. + items.retain(|s| !matches!(s, ModuleItem::Stmt(Stmt::Empty(..)))); + items + } + + fn fold_module_item(&mut self, i: ModuleItem) -> ModuleItem { + if let ModuleItem::ModuleDecl(ModuleDecl::Import(i)) = i { + let is_for_side_effect = i.specifiers.is_empty(); + let i = i.fold_with(self); + + if !is_for_side_effect && i.specifiers.is_empty() { + return ModuleItem::Stmt(Stmt::Empty(EmptyStmt { span: DUMMY_SP })); + } + return ModuleItem::ModuleDecl(ModuleDecl::Import(i)); + } + + let i = i.fold_children_with(self); + + match &i { + ModuleItem::ModuleDecl(ModuleDecl::ExportNamed(e)) if e.specifiers.is_empty() => { + return ModuleItem::Stmt(Stmt::Empty(EmptyStmt { span: DUMMY_SP })) + } + _ => {} + } + + i + } + + fn fold_named_export(&mut self, mut n: NamedExport) -> NamedExport { + n.specifiers = n.specifiers.fold_with(self); + + n.specifiers.retain(|s| { + let preserve = match s { + ExportSpecifier::Namespace(ExportNamespaceSpecifier { + name: ModuleExportName::Ident(exported), + .. + }) + | ExportSpecifier::Default(ExportDefaultSpecifier { exported, .. }) + | ExportSpecifier::Named(ExportNamedSpecifier { + exported: Some(ModuleExportName::Ident(exported)), + .. + }) => self + .state + .should_remove_identifier(exported) + .map(|should_remove_identifier| !should_remove_identifier), + ExportSpecifier::Named(ExportNamedSpecifier { + orig: ModuleExportName::Ident(orig), + .. + }) => self + .state + .should_remove_identifier(orig) + .map(|should_remove_identifier| !should_remove_identifier), + _ => Ok(true), + }; + + match preserve { + Ok(false) => { + if let ExportSpecifier::Named(ExportNamedSpecifier { + orig: ModuleExportName::Ident(orig), + .. + }) = s + { + self.state.should_run_again = true; + self.state.refs_from_data_fn.insert(orig.to_id()); + } + + false + } + Ok(true) => true, + Err(_) => false, + } + }); + + n + } + + fn fold_default_decl(&mut self, d: DefaultDecl) -> DefaultDecl { + if self.state.should_remove_default() { + // Replace with an empty function + return DefaultDecl::Fn(self.create_empty_fn()) + } + d + } + + fn fold_export_default_expr(&mut self, n: ExportDefaultExpr) -> ExportDefaultExpr { + if self.state.should_remove_default() { + // Replace with an empty function + return ExportDefaultExpr { + span: DUMMY_SP, + expr: Box::new(Expr::Fn(self.create_empty_fn())) + }; + } + n + } + + /// This methods returns [Pat::Invalid] if the pattern should be removed. + fn fold_pat(&mut self, mut p: Pat) -> Pat { + p = p.fold_children_with(self); + + if self.in_lhs_of_var { + match &mut p { + Pat::Ident(name) => { + if self.should_remove(name.id.to_id()) { + self.state.should_run_again = true; + return Pat::Invalid(Invalid { span: DUMMY_SP }); + } + } + Pat::Array(arr) => { + if !arr.elems.is_empty() { + arr.elems.retain(|e| !matches!(e, Some(Pat::Invalid(..)))); + + if arr.elems.is_empty() { + return Pat::Invalid(Invalid { span: DUMMY_SP }); + } + } + } + Pat::Object(obj) => { + if !obj.props.is_empty() { + obj.props = take(&mut obj.props) + .into_iter() + .filter_map(|prop| match prop { + ObjectPatProp::KeyValue(prop) => { + if prop.value.is_invalid() { + None + } else { + Some(ObjectPatProp::KeyValue(prop)) + } + } + ObjectPatProp::Assign(prop) => { + if self.should_remove(prop.key.to_id()) { + self.mark_as_candidate(prop.value); + + None + } else { + Some(ObjectPatProp::Assign(prop)) + } + } + ObjectPatProp::Rest(prop) => { + if prop.arg.is_invalid() { + None + } else { + Some(ObjectPatProp::Rest(prop)) + } + } + }) + .collect(); + + if obj.props.is_empty() { + return Pat::Invalid(Invalid { span: DUMMY_SP }); + } + } + } + Pat::Rest(rest) => { + if rest.arg.is_invalid() { + return Pat::Invalid(Invalid { span: DUMMY_SP }); + } + } + _ => {} + } + } + + p + } + + #[allow(clippy::single_match)] + fn fold_stmt(&mut self, mut s: Stmt) -> Stmt { + match s { + Stmt::Decl(Decl::Fn(f)) => { + if self.should_remove(f.ident.to_id()) { + self.mark_as_candidate(f.function); + return Stmt::Empty(EmptyStmt { span: DUMMY_SP }); + } + + s = Stmt::Decl(Decl::Fn(f)); + } + _ => {} + } + + let s = s.fold_children_with(self); + match s { + Stmt::Decl(Decl::Var(v)) if v.decls.is_empty() => { + return Stmt::Empty(EmptyStmt { span: DUMMY_SP }); + } + _ => {} + } + + s + } + + /// This method make `name` of [VarDeclarator] to [Pat::Invalid] if it + /// should be removed. + fn fold_var_declarator(&mut self, mut d: VarDeclarator) -> VarDeclarator { + let old = self.in_lhs_of_var; + self.in_lhs_of_var = true; + let name = d.name.fold_with(self); + + self.in_lhs_of_var = false; + if name.is_invalid() { + d.init = self.mark_as_candidate(d.init); + } + let init = d.init.fold_with(self); + self.in_lhs_of_var = old; + + VarDeclarator { name, init, ..d } + } + + fn fold_var_declarators(&mut self, mut decls: Vec) -> Vec { + decls = decls.fold_children_with(self); + decls.retain(|d| !d.name.is_invalid()); + + decls + } +} + +pub fn remove_export(exports: Vec) -> impl Fold { + Repeat::new(RemoveExport { + state: State { + remove_exports: exports, + ..Default::default() + }, + in_lhs_of_var: false, + }) +} \ No newline at end of file diff --git a/crates/loader_compilation/tests/fixtures.rs b/crates/loader_compilation/tests/fixtures.rs index efb3880..3b78fdb 100644 --- a/crates/loader_compilation/tests/fixtures.rs +++ b/crates/loader_compilation/tests/fixtures.rs @@ -10,12 +10,8 @@ async fn loader_test(actual: impl AsRef, expected: impl AsRef) { let tests_path = PathBuf::from(concat!(env!("CARGO_MANIFEST_DIR"))).join("tests"); let expected_path = tests_path.join(expected); let actual_path = tests_path.join(actual); - let plugin_path = tests_path.join("my_first_plugin.wasm"); + let mut options = Config::default(); - options.jsc.experimental.plugins = Some(vec![PluginConfig( - plugin_path.to_string_lossy().to_string(), - json!(null), - )]); let (result, _) = run_loaders( &[Arc::new(CompilationLoader::new()) as Arc>], &ResourceData::new(actual_path.to_string_lossy().to_string(), actual_path), diff --git a/crates/loader_compilation/tests/fixtures/basic/input.js b/crates/loader_compilation/tests/fixtures/basic/input.js index 54b82a0..f11cfe5 100644 --- a/crates/loader_compilation/tests/fixtures/basic/input.js +++ b/crates/loader_compilation/tests/fixtures/basic/input.js @@ -1 +1,8 @@ const a = 1; +const b = 2; + +export const dataLoader = { + b, +}; + +export default a; \ No newline at end of file From 45583987530e76b91c651a97659622d1a3189f2e Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Tue, 21 Nov 2023 14:23:19 +0800 Subject: [PATCH 08/32] feat: custom split chunk rules (#11) * fix: add cargo lock * feat: custom split chunks rule * feat: support split chunk strategy of chunks --- Cargo.lock | 163 +++++++------- crates/binding_options/Cargo.toml | 4 +- crates/binding_options/src/options/mod.rs | 19 +- .../src/options/raw_features.rs | 199 ++++++++++++++++++ 4 files changed, 306 insertions(+), 79 deletions(-) create mode 100644 crates/binding_options/src/options/raw_features.rs diff --git a/Cargo.lock b/Cargo.lock index 45049d5..cfb8e97 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -116,7 +116,7 @@ dependencies = [ "argh_shared", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -143,7 +143,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -154,7 +154,7 @@ checksum = "5fd55a5ba1179988837d24ab4c7cc8ed6efdeff578ede0416b4225a5fca35bd0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -177,7 +177,7 @@ checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -278,6 +278,7 @@ dependencies = [ "async-trait", "better_scoped_tls 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "derivative", + "futures-util", "glob", "loader_compilation", "napi", @@ -287,6 +288,7 @@ dependencies = [ "rspack_binding_options", "rspack_core", "rspack_error", + "rspack_hash", "rspack_identifier", "rspack_ids", "rspack_loader_react_refresh", @@ -670,7 +672,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37e366bff8cd32dd8754b0991fb66b279dc48f598c3a18914852a6673deef583" dependencies = [ "quote", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -828,9 +830,9 @@ checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b" [[package]] name = "dyn-clone" -version = "1.0.14" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23d2f3407d9a573d666de4b5bdf10569d73ca9478087346697dcbae6244bfbcd" +checksum = "545b22097d44f8a9581187cdf93de7a71e4722bf51200cfaba810865b49a495d" [[package]] name = "either" @@ -861,7 +863,7 @@ checksum = "eecf8589574ce9b895052fa12d69af7a233f99e6107f5cb8dd1044f2a17bfdcb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -872,9 +874,9 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.5" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3e13f66a2f95e32a39eaa81f6b95d42878ca0e1db0c7543723dfe12557e860" +checksum = "7c18ee0ed65a5f1f81cac6b1d213b69c35fa47d4252ad41f1486dbd8226fe36e" dependencies = [ "libc", "windows-sys 0.48.0", @@ -909,7 +911,7 @@ dependencies = [ "pmutil", "proc-macro2", "swc_macros_common", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -974,7 +976,7 @@ checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -1028,9 +1030,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" dependencies = [ "cfg-if", "js-sys", @@ -1221,9 +1223,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.0.2" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" +checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" dependencies = [ "equivalent", "hashbrown 0.14.2", @@ -1276,7 +1278,7 @@ dependencies = [ "pmutil", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -1313,9 +1315,9 @@ checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" [[package]] name = "js-sys" -version = "0.3.64" +version = "0.3.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" +checksum = "54c0c35952f67de54bb584e9fd912b3023117cbafc0a77d8f3dee1fb5f572fe8" dependencies = [ "wasm-bindgen", ] @@ -1416,9 +1418,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.149" +version = "0.2.150" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" +checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" [[package]] name = "libloading" @@ -1447,9 +1449,9 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.4.10" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f" +checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829" [[package]] name = "loader_compilation" @@ -1851,7 +1853,7 @@ checksum = "9657cba6ac0894a8acf3aca5b9a4b7668ce8486042588cf2bf0f34eb5f37ebc6" dependencies = [ "dashmap", "dunce", - "indexmap 2.0.2", + "indexmap 2.1.0", "once_cell", "rustc-hash", "serde", @@ -1982,7 +1984,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -2003,7 +2005,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" dependencies = [ "fixedbitset", - "indexmap 2.0.2", + "indexmap 2.1.0", "serde", "serde_derive", ] @@ -2069,7 +2071,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -2123,6 +2125,17 @@ dependencies = [ "tracing", ] +[[package]] +name = "plugin_specilize_module_name" +version = "0.1.0" +dependencies = [ + "async-trait", + "rspack_core", + "rspack_error", + "rspack_testing", + "tracing", +] + [[package]] name = "pmutil" version = "0.6.1" @@ -2131,7 +2144,7 @@ checksum = "52a40bc70c2c58040d2d8b167ba9a5ff59fc9dab7ad44771cfde3dcfde7a09c6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -3469,9 +3482,9 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.190" +version = "1.0.192" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91d3c334ca1ee894a2c6f6ad698fe8c435b76d504b13d436f0685d648d6d96f7" +checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001" dependencies = [ "serde_derive", ] @@ -3499,13 +3512,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.190" +version = "1.0.192" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67c5609f394e5c2bd7fc51efda478004ea80ef42fee983d5c67a65e34f32c0e3" +checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -3521,11 +3534,11 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.107" +version = "1.0.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" +checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" dependencies = [ - "indexmap 2.0.2", + "indexmap 2.1.0", "itoa", "ryu", "serde", @@ -3689,7 +3702,7 @@ dependencies = [ "pmutil", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -3700,9 +3713,9 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "str_indices" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8eeaedde8e50d8a331578c9fa9a288df146ce5e16173ad26ce82f6e263e2be4" +checksum = "e9557cb6521e8d009c51a8666f09356f4b817ba9ba0981a305bd86aee47bd35c" [[package]] name = "string_cache" @@ -3739,7 +3752,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -3916,7 +3929,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -3990,7 +4003,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -4134,7 +4147,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -4280,7 +4293,7 @@ dependencies = [ "swc_ecma_ast", "swc_ecma_parser", "swc_macros_common", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -4371,7 +4384,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -4554,7 +4567,7 @@ dependencies = [ "pmutil", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -4626,7 +4639,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -4700,7 +4713,7 @@ dependencies = [ "pmutil", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -4738,7 +4751,7 @@ source = "git+https://github.com/swc-project/swc.git?rev=5c00525#5c005256d640270 dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -4760,7 +4773,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -4776,9 +4789,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.38" +version = "2.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" +checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" dependencies = [ "proc-macro2", "quote", @@ -4824,7 +4837,7 @@ dependencies = [ "quote", "regex", "relative-path", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -4864,7 +4877,7 @@ checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -4972,7 +4985,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -4994,7 +5007,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", ] [[package]] @@ -5223,9 +5236,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.87" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" +checksum = "7daec296f25a1bae309c0cd5c29c4b260e510e6d813c286b19eaadf409d40fce" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -5233,24 +5246,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.87" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" +checksum = "e397f4664c0e4e428e8313a469aaa58310d302159845980fd23b0f22a847f217" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.87" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" +checksum = "5961017b3b08ad5f3fe39f1e79877f8ee7c23c5e5fd5eb80de95abc41f1f16b2" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -5258,22 +5271,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.87" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" +checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.87" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" +checksum = "0d046c5d029ba91a1ed14da14dca44b68bf2f124cfbaf741c54151fdb3e0750b" [[package]] name = "wasmparser" @@ -5287,9 +5300,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.64" +version = "0.3.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" +checksum = "5db499c5f66323272151db0e666cd34f78617522fb0c1604d31a27c50c206a85" dependencies = [ "js-sys", "wasm-bindgen", @@ -5508,20 +5521,20 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.7.20" +version = "0.7.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd66a62464e3ffd4e37bd09950c2b9dd6c4f8767380fabba0d523f9a775bc85a" +checksum = "8cd369a67c0edfef15010f980c3cbe45d7f651deac2cd67ce097cd801de16557" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.20" +version = "0.7.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "255c4596d41e6916ced49cfafea18727b24d67878fa180ddfd69b9df34fd1726" +checksum = "c2f140bda219a26ccc0cdb03dba58af72590c53b22642577d88a927bc5c87d6b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.39", ] diff --git a/crates/binding_options/Cargo.toml b/crates/binding_options/Cargo.toml index 6f13b5a..2a21109 100644 --- a/crates/binding_options/Cargo.toml +++ b/crates/binding_options/Cargo.toml @@ -41,10 +41,12 @@ rspack_plugin_swc_js_minimizer = { path = "../.rspack_crates/rspack_plu rspack_plugin_wasm = { path = "../.rspack_crates/rspack_plugin_wasm" } rspack_plugin_worker = { path = "../.rspack_crates/rspack_plugin_worker" } rspack_regex = { path = "../.rspack_crates/rspack_regex" } +rspack_hash = { path = "../.rspack_crates/rspack_hash" } rspack_swc_visitors = { path = "../.rspack_crates/rspack_swc_visitors" } loader_compilation = { path = "../loader_compilation" } -plugin_manifest = { path = "../plugin_manifest" } +plugin_manifest = { path = "../plugin_manifest" } +futures-util = { workspace = true } anyhow = { workspace = true, features = ["backtrace"] } async-trait = { workspace = true } better_scoped_tls = { workspace = true } diff --git a/crates/binding_options/src/options/mod.rs b/crates/binding_options/src/options/mod.rs index 786396a..b5db707 100644 --- a/crates/binding_options/src/options/mod.rs +++ b/crates/binding_options/src/options/mod.rs @@ -13,9 +13,11 @@ use rspack_plugin_javascript::{FlagDependencyExportsPlugin, FlagDependencyUsageP use serde::Deserialize; mod raw_module; +mod raw_features; mod js_loader; pub use raw_module::*; +pub use raw_features::*; pub use js_loader::*; scoped_tls!(pub(crate) static IS_ENABLE_NEW_SPLIT_CHUNKS: bool); @@ -45,6 +47,7 @@ pub struct RSPackRawOptions { pub node: Option, pub profile: bool, pub builtins: RawBuiltins, + pub features: RawFeatures, } impl RawOptionsApply for RSPackRawOptions { @@ -74,9 +77,19 @@ impl RawOptionsApply for RSPackRawOptions { new_split_chunks: self.experiments.new_split_chunks, rspack_future: self.experiments.rspack_future.into(), }; - let optimization = IS_ENABLE_NEW_SPLIT_CHUNKS.set(&experiments.new_split_chunks, || { - self.optimization.apply(plugins) - })?; + let optimization; + if self.features.split_chunks_strategy.is_some() { + let split_chunk_strategy = SplitChunksStrategy::new( + self.features.split_chunks_strategy.unwrap(), + self.optimization, + ); + optimization = split_chunk_strategy.apply(plugins, context.to_string())?; + } else { + optimization = IS_ENABLE_NEW_SPLIT_CHUNKS.set(&experiments.new_split_chunks, || { + self.optimization.apply(plugins) + })?; + } + let stats = self.stats.into(); let snapshot = self.snapshot.into(); let node = self.node.map(|n| n.into()); diff --git a/crates/binding_options/src/options/raw_features.rs b/crates/binding_options/src/options/raw_features.rs new file mode 100644 index 0000000..ceec742 --- /dev/null +++ b/crates/binding_options/src/options/raw_features.rs @@ -0,0 +1,199 @@ +use std::{sync::Arc, hash::Hasher}; +use futures_util::{FutureExt, future}; +use napi_derive::napi; +use serde::Deserialize; +use rspack_core::{ + Optimization, PluginExt, SideEffectOption, UsedExportsOption, SourceType, + BoxPlugin, Module, ModuleType, +}; +use rspack_error::internal_error; +use rspack_ids::{ + DeterministicChunkIdsPlugin, DeterministicModuleIdsPlugin, NamedChunkIdsPlugin, + NamedModuleIdsPlugin, +}; +use rspack_binding_options::RawOptimizationOptions; +use rspack_plugin_split_chunks_new::{PluginOptions, CacheGroup}; +use rspack_regex::RspackRegex; +use rspack_hash::{RspackHash, HashFunction, HashDigest}; + +pub struct SplitChunksStrategy { + strategy: RawStrategyOptions, + // Get the neccessary options from RawOptimizationOptions. + chunk_ids: String, + module_ids: String, + side_effects: String, + used_exports: String, + provided_exports: bool, + real_content_hash: bool, + remove_empty_chunks: bool, + remove_available_modules: bool, +} + +fn get_modules_size(module: &dyn Module) -> f64 { + let mut size = 0f64; + for source_type in module.source_types() { + size += module.size(source_type); + } + size +} + +fn get_plugin_options(strategy: RawStrategyOptions, context: String) -> rspack_plugin_split_chunks_new::PluginOptions { + use rspack_plugin_split_chunks_new::SplitChunkSizes; + let default_size_types = [SourceType::JavaScript, SourceType::Unknown]; + let create_sizes = |size: Option| { + size + .map(|size| SplitChunkSizes::with_initial_value(&default_size_types, size)) + .unwrap_or_else(SplitChunkSizes::default) + }; + + let re_node_modules = RspackRegex::new("node_modules").unwrap(); + + let cache_groups = vec![ + CacheGroup { + key: String::from("framework"), + name: rspack_plugin_split_chunks_new::create_chunk_name_getter_by_const_name("framework".to_string()), + chunk_filter: rspack_plugin_split_chunks_new::create_all_chunk_filter(), + priority: 40.0, + test: Arc::new(move |module: &dyn Module| -> bool { + module + .name_for_condition() + .map_or(false, |name| { + strategy.top_level_frameworks.iter().any(|framework| name.starts_with(framework)) + }) + }), + max_initial_requests: 25, + max_async_requests: 25, + reuse_existing_chunk: true, + min_chunks: 1, + // When enfoce is true, all size should be set to SplitChunkSizes::empty(). + min_size: SplitChunkSizes::empty(), + max_async_size: SplitChunkSizes::empty(), + max_initial_size: SplitChunkSizes::empty(), + id_hint: String::from("framework"), + r#type: rspack_plugin_split_chunks_new::create_default_module_type_filter(), + }, + CacheGroup { + key: String::from("lib"), + name: Arc::new(move |module| { + let mut hash = RspackHash::new(&HashFunction::Xxhash64); + match module.module_type() { + ModuleType::Css | ModuleType::CssModule | ModuleType::CssAuto => { + module.update_hash(&mut hash); + }, + _ => { + let options = rspack_core::LibIdentOptions { context: &context }; + let lib_ident = module.lib_ident(options); + hash.write(lib_ident.unwrap().as_bytes()); + }, + } + future::ready(Some(hash.digest(&HashDigest::Hex).rendered(8).to_string())).boxed() + }), + chunk_filter: rspack_plugin_split_chunks_new::create_all_chunk_filter(), + test: Arc::new(move |module: &dyn Module| -> bool { + module + .name_for_condition() + .map_or(false, |name| re_node_modules.test(&name)) + && get_modules_size(module) > 160000.0 + }), + priority: 30.0, + min_chunks: 1, + reuse_existing_chunk: true, + max_initial_requests: 25, + max_async_requests: 25, + min_size: create_sizes(Some(20000.0)), + max_async_size: SplitChunkSizes::default(), + max_initial_size: SplitChunkSizes::default(), + id_hint: String::from("lib"), + r#type: rspack_plugin_split_chunks_new::create_default_module_type_filter(), + }, + ]; + + PluginOptions { + cache_groups, + fallback_cache_group: rspack_plugin_split_chunks_new::FallbackCacheGroup { + chunks_filter: rspack_plugin_split_chunks_new::create_all_chunk_filter(), + min_size: SplitChunkSizes::default(), + max_async_size: SplitChunkSizes::default(), + max_initial_size: SplitChunkSizes::default(), + }, + } +} + + +pub trait FeatureApply { + type Options; + fn apply(self, plugins: &mut Vec, context: String) -> Result; +} + +impl SplitChunksStrategy { + pub fn new(strategy: RawStrategyOptions, option: RawOptimizationOptions) -> Self { + Self { + strategy, + chunk_ids: option.chunk_ids, + module_ids: option.module_ids, + remove_available_modules: option.remove_available_modules, + remove_empty_chunks: option.remove_empty_chunks, + side_effects: option.side_effects, + used_exports: option.used_exports, + provided_exports: option.provided_exports, + real_content_hash: option.real_content_hash, + } + } +} + +impl FeatureApply for SplitChunksStrategy { + type Options = Optimization; + + fn apply(self, plugins: &mut Vec>, context: String) -> Result { + let split_chunks_plugin = rspack_plugin_split_chunks_new::SplitChunksPlugin::new( + get_plugin_options(self.strategy, context), + ).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(Self::Options { + 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()), + }) + } +} + +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +#[napi(object)] +pub struct RawStrategyOptions { + pub name: String, + pub top_level_frameworks: Vec, +} + +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +#[napi(object)] +pub struct RawFeatures { + pub split_chunks_strategy: Option, +} From c2c267222cb67da9b4e190efdedcff5f40fddfb4 Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Thu, 23 Nov 2023 10:13:31 +0800 Subject: [PATCH 09/32] feat: plugin for generate assets manifest (#5) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: plugin for generate assets manifest * fix: camel case --------- Co-authored-by: 鲲尘 --- crates/plugin_manifest/Cargo.toml | 3 + crates/plugin_manifest/src/plugin.rs | 87 ++++++++++++++----- crates/plugin_manifest/tests/fixtures.rs | 2 +- .../tests/fixtures/with-assets/a.js | 1 + .../tests/fixtures/with-assets/b.js | 1 + .../tests/fixtures/with-assets/img.png | 0 .../tests/fixtures/with-assets/index.js | 5 ++ .../fixtures/with-assets/snapshot/output.snap | 4 + .../fixtures/with-assets/test.config.json | 13 +++ 9 files changed, 95 insertions(+), 21 deletions(-) create mode 100644 crates/plugin_manifest/tests/fixtures/with-assets/a.js create mode 100644 crates/plugin_manifest/tests/fixtures/with-assets/b.js create mode 100644 crates/plugin_manifest/tests/fixtures/with-assets/img.png create mode 100644 crates/plugin_manifest/tests/fixtures/with-assets/index.js create mode 100644 crates/plugin_manifest/tests/fixtures/with-assets/snapshot/output.snap create mode 100644 crates/plugin_manifest/tests/fixtures/with-assets/test.config.json diff --git a/crates/plugin_manifest/Cargo.toml b/crates/plugin_manifest/Cargo.toml index f9525ff..9ad22a5 100644 --- a/crates/plugin_manifest/Cargo.toml +++ b/crates/plugin_manifest/Cargo.toml @@ -8,6 +8,9 @@ edition = "2021" [dependencies] async-trait = { workspace = true } tracing = { workspace = true } +regex = { workspace = true } +serde = { workspace = true, features = ["derive"] } +serde_json = { workspace = true } rspack_core = { path = "../.rspack_crates/rspack_core" } rspack_error = { path = "../.rspack_crates/rspack_error" } diff --git a/crates/plugin_manifest/src/plugin.rs b/crates/plugin_manifest/src/plugin.rs index e89bfac..8bbde27 100644 --- a/crates/plugin_manifest/src/plugin.rs +++ b/crates/plugin_manifest/src/plugin.rs @@ -1,6 +1,9 @@ +use std::collections::HashMap; +use serde::{Serialize, Deserialize}; + use rspack_core::{ Plugin,PluginContext, PluginProcessAssetsOutput,ProcessAssetsArgs, - CompilationAsset, + CompilationAsset, PublicPath, rspack_sources::{RawSource, SourceExt}, }; // use rspack_error::Result; @@ -8,16 +11,23 @@ use rspack_core::{ #[derive(Debug)] pub struct ManifestPlugin; + +#[derive(Debug, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct AssetsManifest { + pub pages: HashMap>, + pub entries: HashMap>, + pub public_path: String, +} + +const AUTO_PUBLIC_PATH_PLACEHOLDER: &str = "__RSPACK_PLUGIN_CSS_AUTO_PUBLIC_PATH__"; + impl ManifestPlugin { pub fn new() -> Self { Self {} } } -fn default_cotent() -> &'static str { - r#"{"assets": []}"# -} - #[async_trait::async_trait] impl Plugin for ManifestPlugin { fn name(&self) -> &'static str { @@ -30,29 +40,66 @@ impl Plugin for ManifestPlugin { args: ProcessAssetsArgs<'_>, )-> PluginProcessAssetsOutput { let compilation = args.compilation; + let public_path = match &compilation.options.output.public_path { + PublicPath::String(p) => p, + PublicPath::Auto => AUTO_PUBLIC_PATH_PLACEHOLDER, + }; + let mut assets_mainfest = AssetsManifest { + pages: HashMap::new(), + entries: HashMap::new(), + public_path: public_path.to_string(), + }; let entry_points = &compilation.entrypoints; - println!("entry_points: {:?}", entry_points); - Ok(()) - } - - async fn process_assets_stage_optimize_inline( - &self, - _ctx: PluginContext, - args: ProcessAssetsArgs<'_>, - ) -> PluginProcessAssetsOutput { - let compilation = args.compilation; - + let assets = &compilation.assets(); + + entry_points.iter().for_each(|(name, _entry)| { + let mut files: Vec = Vec::new(); + compilation.entrypoint_by_name(name).chunks.iter().for_each(|chunk| { + + if let Some(chunk) = compilation.chunk_by_ukey.get(chunk) { + chunk.files.iter().for_each(|file| { + if let Some(asset) = assets.get(file) { + if !asset.info.hot_module_replacement && !asset.info.development { + files.push(file.to_string()); + } + } else { + files.push(file.to_string()); + } + }); + }; + }); + assets_mainfest.entries.insert(name.to_string(), files); + }); + let page_chunk_name_regex = regex::Regex::new(r"^p_").unwrap(); + compilation + .chunk_by_ukey + .values() + .for_each(|c| { + if let Some(name) = &c.id { + if !c.has_entry_module(&compilation.chunk_graph) && !c.can_be_initial(&compilation.chunk_group_by_ukey) { + assets_mainfest.pages.insert( + page_chunk_name_regex.replace(name, "").to_string(), + Vec::from_iter( + c.files + .iter() + // Only collect js and css files. + .filter(|f| f.ends_with(".js") || f.ends_with(".css")) + .cloned() + ), + ); + } + } + }); + let json_string = serde_json::to_string(&assets_mainfest).unwrap(); let output_path = compilation .options .output .path - .join("manifest.json".to_string()).to_string_lossy().to_string(); - println!("output_path: {}", output_path); + .join("assets-manifest.json".to_string()).to_string_lossy().to_string(); compilation.emit_asset( output_path, - CompilationAsset::from(RawSource::from(default_cotent().to_owned()).boxed()), + CompilationAsset::from(RawSource::from(json_string).boxed()), ); - Ok(()) } } diff --git a/crates/plugin_manifest/tests/fixtures.rs b/crates/plugin_manifest/tests/fixtures.rs index d28f36b..c415eb3 100644 --- a/crates/plugin_manifest/tests/fixtures.rs +++ b/crates/plugin_manifest/tests/fixtures.rs @@ -3,7 +3,7 @@ use rspack_core::PluginExt; use rspack_testing::{fixture,test_fixture_insta}; use plugin_manifest::ManifestPlugin; -#[fixture("tests/fixtures/*")] +#[fixture("tests/fixtures/with-assets")] fn manifest(fixture_path: PathBuf) { test_fixture_insta( &fixture_path, diff --git a/crates/plugin_manifest/tests/fixtures/with-assets/a.js b/crates/plugin_manifest/tests/fixtures/with-assets/a.js new file mode 100644 index 0000000..0d4c247 --- /dev/null +++ b/crates/plugin_manifest/tests/fixtures/with-assets/a.js @@ -0,0 +1 @@ +console.log('a.js'); \ No newline at end of file diff --git a/crates/plugin_manifest/tests/fixtures/with-assets/b.js b/crates/plugin_manifest/tests/fixtures/with-assets/b.js new file mode 100644 index 0000000..50715a5 --- /dev/null +++ b/crates/plugin_manifest/tests/fixtures/with-assets/b.js @@ -0,0 +1 @@ +console.log('b.js'); \ No newline at end of file diff --git a/crates/plugin_manifest/tests/fixtures/with-assets/img.png b/crates/plugin_manifest/tests/fixtures/with-assets/img.png new file mode 100644 index 0000000..e69de29 diff --git a/crates/plugin_manifest/tests/fixtures/with-assets/index.js b/crates/plugin_manifest/tests/fixtures/with-assets/index.js new file mode 100644 index 0000000..336f6d0 --- /dev/null +++ b/crates/plugin_manifest/tests/fixtures/with-assets/index.js @@ -0,0 +1,5 @@ +import url from './img.png'; + +import('./a.js'); +import('./b.js'); +console.log('url', url); diff --git a/crates/plugin_manifest/tests/fixtures/with-assets/snapshot/output.snap b/crates/plugin_manifest/tests/fixtures/with-assets/snapshot/output.snap new file mode 100644 index 0000000..775c9ee --- /dev/null +++ b/crates/plugin_manifest/tests/fixtures/with-assets/snapshot/output.snap @@ -0,0 +1,4 @@ +--- +source: crates/.rspack_crates/rspack_testing/src/run_fixture.rs +--- + diff --git a/crates/plugin_manifest/tests/fixtures/with-assets/test.config.json b/crates/plugin_manifest/tests/fixtures/with-assets/test.config.json new file mode 100644 index 0000000..50bee5b --- /dev/null +++ b/crates/plugin_manifest/tests/fixtures/with-assets/test.config.json @@ -0,0 +1,13 @@ +{ + "module": { + "rules": [ + { + "test": { + "type": "regexp", + "matcher": "\\.png$" + }, + "type": "asset/resource" + } + ] + } +} \ No newline at end of file From 8a3631bc0b4a737529d7d14c1b2bd4c761e8e6ca Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Thu, 23 Nov 2023 15:06:04 +0800 Subject: [PATCH 10/32] feat: support loader options (#8) * feat: support swc options * feat: support transform rule of remove export and keep export * fix: optimize code * chore: remove comments --- .../binding_options/src/options/raw_module.rs | 6 +- crates/loader_compilation/Cargo.toml | 4 +- crates/loader_compilation/src/compiler.rs | 12 -- crates/loader_compilation/src/lib.rs | 116 ++++++++++++++---- crates/loader_compilation/src/options.rs | 0 .../loader_compilation/src/transform/mod.rs | 91 ++++++++++++-- crates/loader_compilation/tests/fixtures.rs | 11 +- .../fixtures/basic/.ice/route-manifest.json | 22 ++++ 8 files changed, 210 insertions(+), 52 deletions(-) delete mode 100644 crates/loader_compilation/src/options.rs create mode 100644 crates/loader_compilation/tests/fixtures/basic/.ice/route-manifest.json diff --git a/crates/binding_options/src/options/raw_module.rs b/crates/binding_options/src/options/raw_module.rs index 9b909d5..2b550d5 100644 --- a/crates/binding_options/src/options/raw_module.rs +++ b/crates/binding_options/src/options/raw_module.rs @@ -27,7 +27,11 @@ pub fn get_builtin_loader(builtin: &str, options: Option<&str>) -> BoxLoader { if builtin.starts_with(COMPILATION_LOADER_IDENTIFIER) { return Arc::new( - loader_compilation::CompilationLoader::new().with_identifier(builtin.into()), + loader_compilation::CompilationLoader::new( + serde_json::from_str(options.unwrap_or("{}")).unwrap_or_else(|e| { + panic!("Could not parse builtin:compilation-loader options:{options:?},error: {e:?}") + }), + ).with_identifier(builtin.into()), ); } diff --git a/crates/loader_compilation/Cargo.toml b/crates/loader_compilation/Cargo.toml index 4e519ce..c252936 100644 --- a/crates/loader_compilation/Cargo.toml +++ b/crates/loader_compilation/Cargo.toml @@ -10,13 +10,15 @@ anyhow = { workspace = true } async-trait = { workspace = true } dashmap = { workspace = true } either = "1" -fxhash= "0.2.1" +fxhash = "0.2.1" +lazy_static = "1.4.0" once_cell = { workspace = true } rspack_ast = { path = "../.rspack_crates/rspack_ast" } rspack_core = { path = "../.rspack_crates/rspack_core" } rspack_error = { path = "../.rspack_crates/rspack_error" } rspack_loader_runner = { path = "../.rspack_crates/rspack_loader_runner" } rspack_plugin_javascript = { path = "../.rspack_crates/rspack_plugin_javascript" } +regex = { workspace = true } serde = { workspace = true, features = ["derive"] } serde_json = "1.0.100" swc_config = { workspace = true } diff --git a/crates/loader_compilation/src/compiler.rs b/crates/loader_compilation/src/compiler.rs index f8a91a3..040d40a 100644 --- a/crates/loader_compilation/src/compiler.rs +++ b/crates/loader_compilation/src/compiler.rs @@ -203,18 +203,6 @@ impl SwcCompiler { program } - - pub fn comments(&self) -> &SingleThreadedComments { - &self.comments - } - - pub fn options(&self) -> &Options { - &self.options - } - - pub fn cm(&self) -> &Arc { - &self.cm - } } pub(crate) trait IntoJsAst { diff --git a/crates/loader_compilation/src/lib.rs b/crates/loader_compilation/src/lib.rs index fde47b2..29729c9 100644 --- a/crates/loader_compilation/src/lib.rs +++ b/crates/loader_compilation/src/lib.rs @@ -1,10 +1,12 @@ +use std::{path::Path, collections::HashMap, sync::Mutex}; +use lazy_static::lazy_static; use rspack_ast::RspackAst; -use rspack_core::{rspack_sources::SourceMap, LoaderRunnerContext}; +use rspack_core::{rspack_sources::SourceMap, LoaderRunnerContext, Mode}; use rspack_loader_runner::{Identifiable, Identifier, Loader, LoaderContext}; use rspack_error::{ - internal_error, Result, + internal_error, Result, Diagnostic, }; -use swc_core::base::config::{InputSourceMap, Options, OutputCharset}; +use swc_core::{base::config::{InputSourceMap, Options, OutputCharset, Config, TransformConfig}, ecma::transforms::react::Runtime}; use rspack_plugin_javascript::{ ast::{self, SourceMapConfig}, TransformOutput, @@ -14,14 +16,41 @@ mod transform; use transform::*; use compiler::{SwcCompiler, IntoJsAst}; + +pub struct LoaderOptions { + pub swc_options: Config, + pub transform_features: TransformFeatureOptions, +} + +pub struct CompilationOptions { + swc_options: Options, + transform_features: TransformFeatureOptions, +} pub struct CompilationLoader { identifier: Identifier, + loader_options: CompilationOptions, +} + +pub const COMPILATION_LOADER_IDENTIFIER: &str = "builtin:compilation-loader"; + +impl From for CompilationOptions { + fn from(value: LoaderOptions) -> Self { + let transform_features = TransformFeatureOptions::default(); + CompilationOptions { + swc_options: Options { + config: value.swc_options, + ..Default::default() + }, + transform_features, + } + } } impl CompilationLoader { - pub fn new() -> Self { + pub fn new(options: LoaderOptions) -> Self { Self { identifier: COMPILATION_LOADER_IDENTIFIER.into(), + loader_options: options.into(), } } @@ -32,6 +61,11 @@ impl CompilationLoader { } } +lazy_static! { + static ref GLOBAL_FILE_ACCESS: Mutex> = Mutex::new(HashMap::new()); + static ref GLOBAL_ROUTES_CONFIG: Mutex>> = Mutex::new(None); +} + #[async_trait::async_trait] impl Loader for CompilationLoader { async fn run(&self, loader_context: &mut LoaderContext<'_, LoaderRunnerContext>) -> Result<()> { @@ -39,31 +73,69 @@ impl Loader for CompilationLoader { let Some(content) = std::mem::take(&mut loader_context.content) else { return Err(internal_error!("No content found")); }; - // TODO: init loader with custom options. - let mut swc_options = Options::default(); - // TODO: merge config with built-in config. + let swc_options = { + let mut swc_options = self.loader_options.swc_options.clone(); + if swc_options.config.jsc.transform.as_ref().is_some() { + let mut transform = TransformConfig::default(); + let default_development = matches!(loader_context.context.options.mode, Mode::Development); + transform.react.development = Some(default_development); + transform.react.runtime = Some(Runtime::Automatic); + } - if let Some(pre_source_map) = std::mem::take(&mut loader_context.source_map) { - if let Ok(source_map) = pre_source_map.to_json() { - swc_options.config.input_source_map = Some(InputSourceMap:: Str(source_map)) + if let Some(pre_source_map) = std::mem::take(&mut loader_context.source_map) { + if let Ok(source_map) = pre_source_map.to_json() { + swc_options.config.input_source_map = Some(InputSourceMap:: Str(source_map)) + } + } + + if swc_options.config.jsc.experimental.plugins.is_some() { + loader_context.emit_diagnostic(Diagnostic::warn( + COMPILATION_LOADER_IDENTIFIER.to_string(), + "Experimental plugins are not currently supported.".to_string(), + 0, + 0, + )); } - } + if swc_options.config.jsc.target.is_some() && swc_options.config.env.is_some() { + loader_context.emit_diagnostic(Diagnostic::warn( + COMPILATION_LOADER_IDENTIFIER.to_string(), + "`env` and `jsc.target` cannot be used together".to_string(), + 0, + 0, + )); + } + swc_options + }; let devtool = &loader_context.context.options.devtool; let source = content.try_into_string()?; let compiler = SwcCompiler::new(resource_path.clone(), source.clone(), swc_options)?; - let transform_options = SwcPluginOptions { - keep_export: Some(KeepExportOptions { - export_names: vec!["default".to_string()], - }), - remove_export: Some(RemoveExportOptions { - remove_names: vec!["default".to_string()], - }), - }; + let transform_options = &self.loader_options.transform_features; + let compiler_context:&str = loader_context.context.options.context.as_ref(); + let mut file_access = GLOBAL_FILE_ACCESS.lock().unwrap(); + let mut routes_config = GLOBAL_ROUTES_CONFIG.lock().unwrap(); + let file_accessed = file_access.contains_key(&resource_path.to_string_lossy().to_string()); + + if routes_config.is_none() || file_accessed { + // Load routes config for transform. + let routes_config_path: std::path::PathBuf = Path::new(compiler_context).join(".ice/route-manifest.json"); + *routes_config = Some(load_routes_config(&routes_config_path).unwrap()); + + if file_accessed { + // If file accessed, then we need to clear the map for the current compilation. + file_access.clear(); + } + } + file_access.insert(resource_path.to_string_lossy().to_string(), true); + let built = compiler.parse(None, |_| { - transform(transform_options) + transform( + &resource_path, + routes_config.as_ref().unwrap(), + transform_options + ) })?; let codegen_options = ast::CodegenOptions { @@ -87,7 +159,7 @@ impl Loader for CompilationLoader { // If swc-loader is the latest loader available, // then loader produces AST, which could be used as an optimization. - if loader_context.loader_index() == 0 + if loader_context.loader_index() == 1 && (loader_context .current_loader() .composed_index_by_identifier(&self.identifier) @@ -109,8 +181,6 @@ impl Loader for CompilationLoader { } } -pub const COMPILATION_LOADER_IDENTIFIER: &str = "builtin:compilation-loader"; - impl Identifiable for CompilationLoader { fn identifier(&self) -> Identifier { self.identifier diff --git a/crates/loader_compilation/src/options.rs b/crates/loader_compilation/src/options.rs deleted file mode 100644 index e69de29..0000000 diff --git a/crates/loader_compilation/src/transform/mod.rs b/crates/loader_compilation/src/transform/mod.rs index 9e08e7e..589a9d4 100644 --- a/crates/loader_compilation/src/transform/mod.rs +++ b/crates/loader_compilation/src/transform/mod.rs @@ -1,9 +1,10 @@ +use std::path::Path; +use anyhow::{Error, Context}; use either::Either; +use serde::Deserialize; use swc_core::common::chain; use swc_core::ecma::{ - transforms::base::pass::noop, - visit::{as_folder, Fold, VisitMut, Visit}, - ast::Module, + transforms::base::pass::noop, visit::Fold, }; mod keep_export; @@ -14,14 +15,14 @@ use remove_export::remove_export; macro_rules! either { ($config:expr, $f:expr) => { - if let Some(config) = $config { + if let Some(config) = &$config { Either::Left($f(config)) } else { Either::Right(noop()) } }; ($config:expr, $f:expr, $enabled:expr) => { - if $enabled { + if $enabled() { either!($config, $f) } else { Either::Right(noop()) @@ -29,26 +30,94 @@ macro_rules! either { }; } +// Only define the stuct which is used in the following function. +#[derive(Deserialize, Debug)] +struct NestedRoutesManifest { + file: String, + children: Option>, +} + +fn get_routes_file(routes: Vec) -> Vec { + let mut result: Vec = vec![]; + for route in routes { + // Add default prefix of src/pages/ to the route file. + let mut path_str = String::from("src/pages/"); + path_str.push_str(&route.file); + + result.push(path_str.to_string()); + + if let Some(children) = route.children { + result.append(&mut get_routes_file(children)); + } + } + result +} + +fn parse_routes_config(c: String) -> Result, Error> { + let routes = serde_json::from_str(&c)?; + Ok(get_routes_file(routes)) +} + +pub(crate) fn load_routes_config(path: &Path) -> Result, Error> { + let content = std::fs::read_to_string(path).context("failed to read routes config")?; + parse_routes_config(content) +} + +fn match_route_entry(resource_path: &Path, routes: &Vec) -> bool { + let resource_path_str = resource_path.to_str().unwrap(); + for route in routes { + if resource_path_str.ends_with(&route.to_string()) { + return true; + } + } + false +} + +fn match_app_entry(resource_path: &Path) -> bool { + let resource_path_str = resource_path.to_str().unwrap(); + // File path ends with src/app.(ts|tsx|js|jsx) + let regex_for_app = regex::Regex::new(r"src/app\.(ts|tsx|js|jsx)$").unwrap(); + regex_for_app.is_match(resource_path_str) +} + +#[derive(Default, Debug, Clone)] pub struct KeepExportOptions { pub export_names: Vec, } +#[derive(Default, Debug, Clone)] pub struct RemoveExportOptions { pub remove_names: Vec, } -pub struct SwcPluginOptions { +#[derive(Default, Debug)] +pub struct TransformFeatureOptions { pub keep_export: Option, pub remove_export: Option, } -pub(crate) fn transform<'a>(plugin_options: SwcPluginOptions) -> impl Fold + 'a { +pub(crate) fn transform<'a>( + resource_path: &'a Path, + routes_config: &Vec, + feature_options: &TransformFeatureOptions, +) -> impl Fold + 'a { chain!( - either!(plugin_options.keep_export, |options: KeepExportOptions| { - keep_export(options.export_names) + either!(feature_options.keep_export, |options: &KeepExportOptions| { + let mut exports_name = options.export_names.clone(); + // Special case for app entry. + // When keep pageConfig, we should also keep the default export of app entry. + if match_app_entry(resource_path) && exports_name.contains(&String::from("pageConfig")) { + exports_name.push(String::from("default")); + } + keep_export(exports_name) + }, || { + match_app_entry(resource_path) || match_route_entry(resource_path, routes_config) }), - either!(plugin_options.remove_export, |options: RemoveExportOptions| { - remove_export(options.remove_names) + either!(feature_options.remove_export, |options: &RemoveExportOptions| { + remove_export(options.remove_names.clone()) + }, || { + // Remove export only work for app entry and route entry. + match_app_entry(resource_path) || match_route_entry(resource_path, routes_config) }), ) } \ No newline at end of file diff --git a/crates/loader_compilation/tests/fixtures.rs b/crates/loader_compilation/tests/fixtures.rs index 3b78fdb..2a4597a 100644 --- a/crates/loader_compilation/tests/fixtures.rs +++ b/crates/loader_compilation/tests/fixtures.rs @@ -1,24 +1,27 @@ use std::{str::FromStr,env, fs,path::{Path, PathBuf}, sync::Arc}; -use loader_compilation::CompilationLoader; +use loader_compilation::{CompilationLoader, LoaderOptions}; use rspack_core::{ run_loaders, CompilerContext, CompilerOptions, Loader, LoaderRunnerContext, ResourceData, SideEffectOption, }; -use serde_json::json; use swc_core::base::config::{PluginConfig, Config}; async fn loader_test(actual: impl AsRef, expected: impl AsRef) { let tests_path = PathBuf::from(concat!(env!("CARGO_MANIFEST_DIR"))).join("tests"); let expected_path = tests_path.join(expected); let actual_path = tests_path.join(actual); + let parent_path = actual_path.parent().unwrap().to_path_buf(); let mut options = Config::default(); let (result, _) = run_loaders( - &[Arc::new(CompilationLoader::new()) as Arc>], + &[Arc::new(CompilationLoader::new(LoaderOptions { + swc_options: options, + transform_features: Default::default(), + })) as Arc>], &ResourceData::new(actual_path.to_string_lossy().to_string(), actual_path), &[], CompilerContext { options: std::sync::Arc::new(CompilerOptions { - context: rspack_core::Context::default(), + context: rspack_core::Context::new(parent_path.to_string_lossy().to_string()), dev_server: rspack_core::DevServerOptions::default(), devtool: rspack_core::Devtool::from("source-map".to_string()), mode: rspack_core::Mode::None, diff --git a/crates/loader_compilation/tests/fixtures/basic/.ice/route-manifest.json b/crates/loader_compilation/tests/fixtures/basic/.ice/route-manifest.json new file mode 100644 index 0000000..cfcf422 --- /dev/null +++ b/crates/loader_compilation/tests/fixtures/basic/.ice/route-manifest.json @@ -0,0 +1,22 @@ +[ + { + "path": "error", + "id": "error", + "file": "error.tsx", + "componentName": "error", + "layout": false, + "exports": [ + "default" + ] + }, + { + "index": true, + "id": "/", + "file": "index.tsx", + "componentName": "index", + "layout": false, + "exports": [ + "default" + ] + } +] \ No newline at end of file From aa7918db1b440b1f9b9da9bc77d358bd483eb85e Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Fri, 24 Nov 2023 16:34:21 +0800 Subject: [PATCH 11/32] feat: update latest rspack version (#14) * feat: update latest rspack version * chore: update node_binding --- .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 | 679 +++++++++--------- crates/node_binding/index.js | 7 +- 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 +- 27 files changed, 1074 insertions(+), 2326 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..f6e6922 100644 --- a/crates/node_binding/index.d.ts +++ b/crates/node_binding/index.d.ts @@ -22,43 +22,289 @@ export interface ThreadsafeNodeFS { mkdirp: (...args: any[]) => any removeDirAll: (...args: any[]) => any } +export interface JsAssetInfoRelated { + sourceMap?: string +} +export interface JsAssetInfo { + /** if the asset can be long term cached forever (contains a hash) */ + immutable: boolean + /** whether the asset is minimized */ + minimized: boolean + /** + * the value(s) of the full hash used for this asset + * the value(s) of the chunk hash used for this asset + */ + chunkHash: Array + /** + * the value(s) of the module hash used for this asset + * the value(s) of the content hash used for this asset + */ + contentHash: Array + sourceFilename?: string + /** + * size in bytes, only set after asset has been emitted + * when asset is only used for development and doesn't count towards user-facing assets + */ + development: boolean + /** when asset ships data for updating an existing application (HMR) */ + hotModuleReplacement: boolean + /** + * when asset is javascript and an ESM + * related object to other assets, keyed by type of relation (only points from parent to child) + */ + 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 + */ + version: string +} +export interface JsAsset { + name: string + source?: JsCompatSource + info: JsAssetInfo +} +export interface JsAssetEmittedArgs { + filename: string + outputPath: string + targetPath: string +} export interface JsChunk { + __inner_ukey: number name?: string + id?: string + ids: Array + idNameHints: Array + filenameTemplate?: string + cssFilenameTemplate?: string files: Array + runtime: Array + hash?: string + contentHash: Record + renderedHash?: string + chunkReasons: Array + auxiliaryFiles: Array } +export function __chunk_inner_is_only_initial(jsChunk: JsChunk, compilation: JsCompilation): boolean +export function __chunk_inner_can_be_initial(jsChunk: JsChunk, compilation: JsCompilation): boolean +export function __chunk_inner_has_runtime(jsChunk: JsChunk, compilation: JsCompilation): boolean export interface JsChunkAssetArgs { chunk: JsChunk filename: string } -export interface RawBannerRule { - type: "string" | "regexp" - stringMatcher?: string - regexpMatcher?: string +export interface JsChunkGroup { + chunks: Array } -export interface RawBannerRules { - type: "string" | "regexp" | "array" - stringMatcher?: string - regexpMatcher?: string - arrayMatcher?: Array +export interface JsHooks { + processAssetsStageAdditional: (...args: any[]) => any + processAssetsStagePreProcess: (...args: any[]) => any + processAssetsStageDerived: (...args: any[]) => any + processAssetsStageAdditions: (...args: any[]) => any + processAssetsStageNone: (...args: any[]) => any + processAssetsStageOptimize: (...args: any[]) => any + processAssetsStageOptimizeCount: (...args: any[]) => any + processAssetsStageOptimizeCompatibility: (...args: any[]) => any + processAssetsStageOptimizeSize: (...args: any[]) => any + processAssetsStageDevTooling: (...args: any[]) => any + processAssetsStageOptimizeInline: (...args: any[]) => any + processAssetsStageSummarize: (...args: any[]) => any + processAssetsStageOptimizeHash: (...args: any[]) => any + processAssetsStageOptimizeTransfer: (...args: any[]) => any + processAssetsStageAnalyse: (...args: any[]) => any + processAssetsStageReport: (...args: any[]) => any + compilation: (...args: any[]) => any + thisCompilation: (...args: any[]) => any + emit: (...args: any[]) => any + assetEmitted: (...args: any[]) => any + afterEmit: (...args: any[]) => any + make: (...args: any[]) => any + optimizeModules: (...args: any[]) => any + optimizeTree: (...args: any[]) => any + optimizeChunkModule: (...args: any[]) => any + beforeCompile: (...args: any[]) => any + afterCompile: (...args: any[]) => any + finishModules: (...args: any[]) => any + finishMake: (...args: any[]) => any + buildModule: (...args: any[]) => any + beforeResolve: (...args: any[]) => any + afterResolve: (...args: any[]) => any + contextModuleBeforeResolve: (...args: any[]) => any + normalModuleFactoryResolveForScheme: (...args: any[]) => any + chunkAsset: (...args: any[]) => any + succeedModule: (...args: any[]) => any + stillValidModule: (...args: any[]) => any +} +export interface JsModule { + originalSource?: JsCompatSource + resource?: string + moduleIdentifier: string +} +export interface JsResolveForSchemeInput { + resourceData: JsResourceData + scheme: string +} +export interface JsResolveForSchemeResult { + resourceData: JsResourceData + stop: boolean +} +export interface BeforeResolveData { + request: string + context: string +} +export interface AfterResolveData { + request: string + context: string + fileDependencies: Array + contextDependencies: Array + missingDependencies: Array + factoryMeta: FactoryMeta +} +export interface FactoryMeta { + sideEffectFree?: boolean +} +export interface JsResourceData { + /** Resource with absolute path, query and fragment */ + resource: string + /** Absolute resource path only */ + path: string + /** Resource query with `?` prefix */ + query?: string + /** Resource fragment with `#` prefix */ + fragment?: string +} +export interface PathData { + filename?: string + hash?: string + contentHash?: string + runtime?: string + url?: string + id?: string +} +export interface PathWithInfo { + path: string + info: JsAssetInfo +} +export interface JsCompatSource { + /** Whether the underlying data structure is a `RawSource` */ + isRaw: boolean + /** Whether the underlying value is a buffer or string */ + isBuffer: boolean + source: Buffer + map?: Buffer +} +export interface JsStatsError { + message: string + formatted: string + title: string +} +export interface JsStatsWarning { + message: string + formatted: string +} +export interface JsStatsLogging { + name: string + type: string + args?: Array + trace?: Array +} +export interface JsStatsAsset { + type: string + name: string + size: number + chunks: Array + chunkNames: Array + info: JsStatsAssetInfo + emitted: boolean +} +export interface JsStatsAssetInfo { + development: boolean + hotModuleReplacement: boolean + sourceFilename?: string +} +export interface JsStatsModule { + type: string + moduleType: string + identifier: string + name: string + id?: string + chunks: Array + size: number + issuer?: string + issuerName?: string + issuerId?: string + issuerPath: Array + nameForCondition?: string + reasons?: Array + assets?: Array + source?: string | Buffer + profile?: JsStatsModuleProfile +} +export interface JsStatsModuleProfile { + factory: JsStatsMillisecond + integration: JsStatsMillisecond + building: JsStatsMillisecond +} +export interface JsStatsMillisecond { + secs: number + subsecMillis: number +} +export interface JsStatsModuleIssuer { + identifier: string + name: string + id?: string +} +export interface JsStatsModuleReason { + moduleIdentifier?: string + moduleName?: string + moduleId?: string + type?: string + userRequest?: string +} +export interface JsStatsChunk { + type: string + files: Array + auxiliaryFiles: Array + id?: string + entry: boolean + initial: boolean + names: Array + size: number + modules?: Array + parents?: Array + children?: Array + siblings?: Array +} +export interface JsStatsChunkGroupAsset { + name: string + size: number +} +export interface JsStatsChunkGroup { + name: string + assets: Array + chunks: Array + assetsSize: number +} +export interface JsStatsAssetsByChunkName { + name: string + files: Array +} +export interface JsStatsGetAssets { + assets: Array + assetsByChunkName: Array } export interface RawBannerContentFnCtx { hash: string chunk: JsChunk filename: string } -export interface RawBannerContent { - type: "string" | "function" - stringPayload?: string - fnPayload?: (...args: any[]) => any -} export interface RawBannerPluginOptions { - banner: RawBannerContent + banner: string | ((...args: any[]) => any) entryOnly?: boolean footer?: boolean raw?: boolean - test?: RawBannerRules - include?: RawBannerRules - exclude?: RawBannerRules + test?: string | RegExp | (string | RegExp)[] + include?: string | RegExp | (string | RegExp)[] + exclude?: string | RegExp | (string | RegExp)[] } export interface RawCopyPattern { from: string @@ -69,6 +315,20 @@ export interface RawCopyPattern { force: boolean priority: number globOptions: RawCopyGlobOptions + info?: RawInfo +} +export interface RawInfo { + immutable?: boolean + minimized?: boolean + chunkHash?: Array + contentHash?: Array + development?: boolean + hotModuleReplacement?: boolean + related?: RawRelated + version?: string +} +export interface RawRelated { + sourceMap?: string } export interface RawCopyGlobOptions { caseSensitiveMatch?: boolean @@ -100,32 +360,23 @@ export interface RawHtmlRspackPluginOptions { favicon?: string meta?: Record> } -export interface RawProgressPluginOptions { - prefix?: string -} -export interface RawSwcJsMinimizerRule { - type: "string" | "regexp" - stringMatcher?: string - regexpMatcher?: string +export interface RawLimitChunkCountPluginOptions { + chunkOverhead?: number + entryChunkMultiplicator?: number + maxChunks: number } -export interface RawSwcJsMinimizerRules { - type: "string" | "regexp" | "array" - stringMatcher?: string - regexpMatcher?: string - arrayMatcher?: Array +export interface RawProgressPluginOptions { + prefix: string + profile: boolean } export interface RawSwcJsMinimizerRspackPluginOptions { - passes: number - dropConsole: boolean - keepClassNames: boolean - keepFnNames: boolean - comments: "all" | "some" | "false" - asciiOnly: boolean - pureFuncs: Array extractComments?: string - test?: RawSwcJsMinimizerRules - include?: RawSwcJsMinimizerRules - exclude?: RawSwcJsMinimizerRules + compress: boolean | string + mangle: boolean | string + format: string + test?: string | RegExp | (string | RegExp)[] + include?: string | RegExp | (string | RegExp)[] + exclude?: string | RegExp | (string | RegExp)[] } export interface RawDecoratorOptions { legacy: boolean @@ -204,6 +455,8 @@ export const enum BuiltinPluginName { ArrayPushCallbackChunkFormatPlugin = 'ArrayPushCallbackChunkFormatPlugin', ModuleChunkFormatPlugin = 'ModuleChunkFormatPlugin', HotModuleReplacementPlugin = 'HotModuleReplacementPlugin', + LimitChunkCountPlugin = 'LimitChunkCountPlugin', + WebWorkerTemplatePlugin = 'WebWorkerTemplatePlugin', HttpExternalsRspackPlugin = 'HttpExternalsRspackPlugin', CopyRspackPlugin = 'CopyRspackPlugin', HtmlRspackPlugin = 'HtmlRspackPlugin', @@ -241,6 +494,7 @@ export interface RawEntryOptions { publicPath?: string baseUri?: string filename?: string + library?: RawLibraryOptions } export interface RawIncrementalRebuild { make: boolean @@ -256,6 +510,7 @@ export interface RawExperiments { incrementalRebuild: RawIncrementalRebuild asyncWebAssembly: boolean newSplitChunks: boolean + topLevelAwait: boolean css: boolean rspackFuture: RawRspackFuture } @@ -265,25 +520,11 @@ export interface RawHttpExternalsRspackPluginOptions { } export interface RawExternalsPluginOptions { type: string - externals: Array -} -export interface RawExternalItem { - type: "string" | "regexp" | "object" | "function" - stringPayload?: string - regexpPayload?: string - objectPayload?: Record - fnPayload?: (value: any) => any -} -export interface RawExternalItemValue { - type: "string" | "bool" | "array" | "object" - stringPayload?: string - boolPayload?: boolean - arrayPayload?: Array - objectPayload?: Record> + externals: (string | RegExp | Record> | ((...args: any[]) => any))[] } export interface RawExternalItemFnResult { externalType?: string - result?: RawExternalItemValue + result?: string | boolean | string[] | Record } export interface RawExternalItemFnCtx { request: string @@ -315,29 +556,29 @@ export interface JsLoaderContext { assetFilenames: Array currentLoader: string isPitching: boolean + /** + * Loader index from JS. + * If loaders are dispatched by JS loader runner, + * then, this field is correspondence with loader index in JS side. + * It is useful when loader dispatched on JS side has an builtin loader, for example: builtin:swc-loader, + * Then this field will be used as an hack to test whether it should return an AST or string. + */ + loaderIndexFromJs?: number + /** + * Internal additional data, contains more than `String` + * @internal + */ + additionalDataExternal: ExternalObject<'AdditionalData'> /** * Internal loader context * @internal */ - context: ExternalObject + contextExternal: ExternalObject<'LoaderRunnerContext'> /** * Internal loader diagnostic * @internal */ - diagnostics: ExternalObject> -} -export interface JsLoaderResult { - /** Content in pitching stage can be empty */ - content?: Buffer - fileDependencies: Array - contextDependencies: Array - missingDependencies: Array - buildDependencies: Array - sourceMap?: Buffer - additionalData?: Buffer - cacheable: boolean - /** Used to instruct how rust loaders should execute */ - isPitching: boolean + diagnosticsExternal: ExternalObject<'Diagnostic[]'> } /** * `loader` is for both JS and Rust loaders. @@ -404,8 +645,12 @@ export interface RawModuleRule { enforce?: 'pre' | 'post' } export interface RawParserOptions { - type: "asset" | "unknown" + type: "asset" | "javascript" | "unknown" asset?: RawAssetParserOptions + javascript?: RawJavascriptParserOptions +} +export interface RawJavascriptParserOptions { + dynamicImportMode: string } export interface RawAssetParserOptions { dataUrlCondition?: RawAssetParserDataUrl @@ -468,12 +713,19 @@ export interface RawOptimizationOptions { sideEffects: string usedExports: string providedExports: boolean + innerGraph: boolean realContentHash: boolean } export interface RawTrustedTypes { policyName?: string } export interface RawLibraryName { + type: "string" | "array" | "umdObject" + stringPayload?: string + arrayPayload?: Array + umdObjectPayload?: RawLibraryCustomUmdObject +} +export interface RawLibraryCustomUmdObject { amd?: string commonjs?: string root?: Array @@ -490,6 +742,7 @@ export interface RawLibraryOptions { libraryType: string umdNamedDefine?: boolean auxiliaryComment?: RawLibraryAuxiliaryComment + amdContainer?: string } export interface RawCrossOriginLoading { type: "bool" | "string" @@ -534,6 +787,11 @@ export interface RawOutputOptions { workerWasmLoading: string workerPublicPath: string } +export interface RawResolveTsconfigOptions { + configFile: string + referencesType: "auto" | "manual" | "disabled" + references?: Array +} export interface RawResolveOptions { preferRelative?: boolean extensions?: Array @@ -544,7 +802,7 @@ export interface RawResolveOptions { alias?: Record> fallback?: Record> symlinks?: boolean - tsConfigPath?: string + tsconfig?: RawResolveTsconfigOptions modules?: Array byDependency?: Record fullySpecified?: boolean @@ -562,7 +820,7 @@ export interface RawSnapshotOptions { export interface RawSplitChunksOptions { fallbackCacheGroup?: RawFallbackCacheGroupOptions name?: string - cacheGroups?: Record + cacheGroups?: Array /** What kind of chunks should be selected. */ chunks?: RegExp | 'async' | 'initial' | 'all' maxAsyncRequests?: number @@ -576,6 +834,7 @@ export interface RawSplitChunksOptions { maxInitialSize?: number } export interface RawCacheGroupOptions { + key: string priority?: number test?: RegExp | string idHint?: string @@ -620,6 +879,25 @@ export interface RawOptions { profile: boolean builtins: RawBuiltins } +export interface RawStrategyOptions { + name: string + topLevelFrameworks: Array +} +export interface RawFeatures { + splitChunksStrategy?: RawStrategyOptions +} +export interface RspackRawOptimizationOptions { + splitChunks?: RawSplitChunksOptions + moduleIds: string + chunkIds: string + removeAvailableModules: boolean + removeEmptyChunks: boolean + sideEffects: string + usedExports: string + providedExports: boolean + innerGraph: boolean + realContentHash: boolean +} export interface RsPackRawOptions { mode?: undefined | 'production' | 'development' | 'none' target: Array @@ -629,7 +907,7 @@ export interface RsPackRawOptions { resolveLoader: RawResolveOptions module: RawModuleOptions devtool: string - optimization: RawOptimizationOptions + optimization: RspackRawOptimizationOptions stats: RawStatsOptions devServer: RawDevServer snapshot: RawSnapshotOptions @@ -638,252 +916,7 @@ export interface RsPackRawOptions { node?: RawNodeOption profile: boolean builtins: RawBuiltins -} -export interface JsAssetInfoRelated { - sourceMap?: string -} -export interface JsAssetInfo { - /** if the asset can be long term cached forever (contains a hash) */ - immutable: boolean - /** whether the asset is minimized */ - minimized: boolean - /** - * the value(s) of the full hash used for this asset - * the value(s) of the chunk hash used for this asset - */ - chunkHash: Array - /** - * the value(s) of the module hash used for this asset - * the value(s) of the content hash used for this asset - */ - contentHash: Array - /** - * when asset was created from a source file (potentially transformed), the original filename relative to compilation context - * size in bytes, only set after asset has been emitted - * when asset is only used for development and doesn't count towards user-facing assets - */ - development: boolean - /** when asset ships data for updating an existing application (HMR) */ - hotModuleReplacement: boolean - /** - * when asset is javascript and an ESM - * related object to other assets, keyed by type of relation (only points from parent to child) - */ - 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 - */ - version: string -} -export interface JsAsset { - name: string - source?: JsCompatSource - info: JsAssetInfo -} -export interface JsAssetEmittedArgs { - filename: string - outputPath: string - targetPath: string -} -export interface JsChunkGroup { - chunks: Array -} -export interface JsHooks { - processAssetsStageAdditional: (...args: any[]) => any - processAssetsStagePreProcess: (...args: any[]) => any - processAssetsStageDerived: (...args: any[]) => any - processAssetsStageAdditions: (...args: any[]) => any - processAssetsStageNone: (...args: any[]) => any - processAssetsStageOptimize: (...args: any[]) => any - processAssetsStageOptimizeCount: (...args: any[]) => any - processAssetsStageOptimizeCompatibility: (...args: any[]) => any - processAssetsStageOptimizeSize: (...args: any[]) => any - processAssetsStageDevTooling: (...args: any[]) => any - processAssetsStageOptimizeInline: (...args: any[]) => any - processAssetsStageSummarize: (...args: any[]) => any - processAssetsStageOptimizeHash: (...args: any[]) => any - processAssetsStageOptimizeTransfer: (...args: any[]) => any - processAssetsStageAnalyse: (...args: any[]) => any - processAssetsStageReport: (...args: any[]) => any - compilation: (...args: any[]) => any - thisCompilation: (...args: any[]) => any - emit: (...args: any[]) => any - assetEmitted: (...args: any[]) => any - afterEmit: (...args: any[]) => any - make: (...args: any[]) => any - optimizeModules: (...args: any[]) => any - optimizeTree: (...args: any[]) => any - optimizeChunkModule: (...args: any[]) => any - beforeCompile: (...args: any[]) => any - afterCompile: (...args: any[]) => any - finishModules: (...args: any[]) => any - finishMake: (...args: any[]) => any - buildModule: (...args: any[]) => any - beforeResolve: (...args: any[]) => any - afterResolve: (...args: any[]) => any - contextModuleBeforeResolve: (...args: any[]) => any - normalModuleFactoryResolveForScheme: (...args: any[]) => any - chunkAsset: (...args: any[]) => any - succeedModule: (...args: any[]) => any - stillValidModule: (...args: any[]) => any -} -export interface JsModule { - originalSource?: JsCompatSource - resource: string - moduleIdentifier: string -} -export interface JsResolveForSchemeInput { - resourceData: JsResourceData - scheme: string -} -export interface JsResolveForSchemeResult { - resourceData: JsResourceData - stop: boolean -} -export interface BeforeResolveData { - request: string - context: string -} -export interface AfterResolveData { - request: string - context: string - fileDependencies: Array - contextDependencies: Array - missingDependencies: Array - factoryMeta: FactoryMeta -} -export interface FactoryMeta { - sideEffectFree?: boolean -} -export interface JsResourceData { - /** Resource with absolute path, query and fragment */ - resource: string - /** Absolute resource path only */ - path: string - /** Resource query with `?` prefix */ - query?: string - /** Resource fragment with `#` prefix */ - fragment?: string -} -export interface PathData { - filename?: string - hash?: string - contentHash?: string - runtime?: string - url?: string - id?: string -} -export interface PathWithInfo { - path: string - info: JsAssetInfo -} -export interface JsCompatSource { - /** Whether the underlying data structure is a `RawSource` */ - isRaw: boolean - /** Whether the underlying value is a buffer or string */ - isBuffer: boolean - source: Buffer - map?: Buffer -} -export interface JsStatsError { - message: string - formatted: string - title: string -} -export interface JsStatsWarning { - message: string - formatted: string -} -export interface JsStatsLogging { - name: string - type: string - args?: Array - trace?: Array -} -export interface JsStatsAsset { - type: string - name: string - size: number - chunks: Array - chunkNames: Array - info: JsStatsAssetInfo - emitted: boolean -} -export interface JsStatsAssetInfo { - development: boolean - hotModuleReplacement: boolean -} -export interface JsStatsModule { - type: string - moduleType: string - identifier: string - name: string - id?: string - chunks: Array - size: number - issuer?: string - issuerName?: string - issuerId?: string - issuerPath: Array - nameForCondition?: string - reasons?: Array - assets?: Array - source?: string | Buffer - profile?: JsStatsModuleProfile -} -export interface JsStatsModuleProfile { - factory: JsStatsMillisecond - integration: JsStatsMillisecond - building: JsStatsMillisecond -} -export interface JsStatsMillisecond { - secs: number - subsecMillis: number -} -export interface JsStatsModuleIssuer { - identifier: string - name: string - id?: string -} -export interface JsStatsModuleReason { - moduleIdentifier?: string - moduleName?: string - moduleId?: string - type?: string - userRequest?: string -} -export interface JsStatsChunk { - type: string - files: Array - auxiliaryFiles: Array - id: string - entry: boolean - initial: boolean - names: Array - size: number - modules?: Array - parents?: Array - children?: Array - siblings?: Array -} -export interface JsStatsChunkGroupAsset { - name: string - size: number -} -export interface JsStatsChunkGroup { - name: string - assets: Array - chunks: Array - assetsSize: number -} -export interface JsStatsAssetsByChunkName { - name: string - files: Array -} -export interface JsStatsGetAssets { - assets: Array - assetsByChunkName: Array + features: RawFeatures } /** Builtin loader runner */ export function runBuiltinLoader(builtin: string, options: string | undefined | null, loaderContext: JsLoaderContext): Promise @@ -922,7 +955,7 @@ export class JsCompilation { getMissingDependencies(): Array getBuildDependencies(): Array pushDiagnostic(severity: "error" | "warning", title: string, message: string): void - pushNativeDiagnostics(diagnostics: ExternalObject>): void + pushNativeDiagnostics(diagnostics: ExternalObject<'Diagnostic[]'>): void getStats(): JsStats getAssetPath(filename: string, data: PathData): string getAssetPathWithInfo(filename: string, data: PathData): PathWithInfo @@ -943,7 +976,7 @@ export class JsStats { getErrors(): Array getWarnings(): Array getLogging(acceptedTypes: number): Array - getHash(): string + getHash(): string | null } export class Rspack { constructor(options: RSPackRawOptions, builtinPlugins: Array, jsHooks: JsHooks | undefined | null, outputFilesystem: ThreadsafeNodeFS, jsLoaderRunner: (...args: any[]) => any) diff --git a/crates/node_binding/index.js b/crates/node_binding/index.js index d7beef2..a5eee77 100644 --- a/crates/node_binding/index.js +++ b/crates/node_binding/index.js @@ -252,11 +252,14 @@ if (!nativeBinding) { throw new Error(`Failed to load native binding`) } -const { BuiltinPluginName, JsCompilation, JsStats, runBuiltinLoader, Rspack, registerGlobalTrace, cleanupGlobalTrace } = nativeBinding +const { __chunk_inner_is_only_initial, __chunk_inner_can_be_initial, __chunk_inner_has_runtime, JsCompilation, JsStats, BuiltinPluginName, runBuiltinLoader, Rspack, registerGlobalTrace, cleanupGlobalTrace } = nativeBinding -module.exports.BuiltinPluginName = BuiltinPluginName +module.exports.__chunk_inner_is_only_initial = __chunk_inner_is_only_initial +module.exports.__chunk_inner_can_be_initial = __chunk_inner_can_be_initial +module.exports.__chunk_inner_has_runtime = __chunk_inner_has_runtime module.exports.JsCompilation = JsCompilation module.exports.JsStats = JsStats +module.exports.BuiltinPluginName = BuiltinPluginName module.exports.runBuiltinLoader = runBuiltinLoader module.exports.Rspack = Rspack module.exports.registerGlobalTrace = registerGlobalTrace 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" From 78e8b832aea7ae46fc0b32e8d742258e710efe3c Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Tue, 28 Nov 2023 13:59:16 +0800 Subject: [PATCH 12/32] fix: loader index --- crates/loader_compilation/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/loader_compilation/src/lib.rs b/crates/loader_compilation/src/lib.rs index 2ad1e23..ff2e4ce 100644 --- a/crates/loader_compilation/src/lib.rs +++ b/crates/loader_compilation/src/lib.rs @@ -163,7 +163,7 @@ impl Loader for CompilationLoader { // If swc-loader is the latest loader available, // then loader produces AST, which could be used as an optimization. - if loader_context.loader_index() == 1 + if loader_context.loader_index() == 0 && (loader_context .current_loader() .composed_index_by_identifier(&self.identifier) From 746b8d2efd57b3a554f82d3f0a96f59d84d7f9b5 Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Wed, 29 Nov 2023 15:30:55 +0800 Subject: [PATCH 13/32] fix: simplify loader config (#15) * fix: simplify loader config * chore: fix test case * fix: built-in options --- Cargo.lock | 1 + crates/loader_compilation/Cargo.toml | 1 + crates/loader_compilation/src/lib.rs | 46 +++++++++++++++++-- .../loader_compilation/src/transform/mod.rs | 25 +++------- crates/loader_compilation/tests/fixtures.rs | 5 +- 5 files changed, 54 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6133446..ba40dc5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1483,6 +1483,7 @@ dependencies = [ "rspack_error", "rspack_loader_runner", "rspack_plugin_javascript", + "rspack_regex", "rspack_testing", "serde", "serde_json", diff --git a/crates/loader_compilation/Cargo.toml b/crates/loader_compilation/Cargo.toml index c252936..46e8ced 100644 --- a/crates/loader_compilation/Cargo.toml +++ b/crates/loader_compilation/Cargo.toml @@ -18,6 +18,7 @@ rspack_core = { path = "../.rspack_crates/rspack_core" } rspack_error = { path = "../.rspack_crates/rspack_error" } rspack_loader_runner = { path = "../.rspack_crates/rspack_loader_runner" } rspack_plugin_javascript = { path = "../.rspack_crates/rspack_plugin_javascript" } +rspack_regex = { path = "../.rspack_crates/rspack_regex" } regex = { workspace = true } serde = { workspace = true, features = ["derive"] } serde_json = "1.0.100" diff --git a/crates/loader_compilation/src/lib.rs b/crates/loader_compilation/src/lib.rs index ff2e4ce..5bcb3c9 100644 --- a/crates/loader_compilation/src/lib.rs +++ b/crates/loader_compilation/src/lib.rs @@ -6,12 +6,18 @@ use rspack_loader_runner::{Identifiable, Identifier, Loader, LoaderContext}; use rspack_error::{ internal_error, Result, Diagnostic, }; -use swc_core::{base::config::{InputSourceMap, Options, OutputCharset, Config, TransformConfig}, ecma::transforms::react::Runtime}; +use swc_core::{ + base::config::{InputSourceMap, Options, OutputCharset, Config, TransformConfig}, + ecma::parser::{Syntax, TsConfig}, +}; + +use swc_config::{config_types::MergingOption, merge::Merge}; use rspack_plugin_javascript::{ ast::{self, SourceMapConfig}, TransformOutput, }; use serde::Deserialize; +use rspack_regex::RspackRegex; mod compiler; mod transform; @@ -19,16 +25,25 @@ mod transform; use transform::*; use compiler::{SwcCompiler, IntoJsAst}; +#[derive(Debug, Default, Deserialize)] +#[serde(rename_all = "camelCase", default)] +pub struct CompileRules { + // Built-in rules to exclude files from compilation, such as react, react-dom, etc. + exclude: Option>, +} + #[derive(Debug, Default, Deserialize)] #[serde(rename_all = "camelCase", default)] pub struct LoaderOptions { pub swc_options: Config, pub transform_features: TransformFeatureOptions, + pub compile_rules: CompileRules, } pub struct CompilationOptions { swc_options: Options, transform_features: TransformFeatureOptions, + compile_rules: CompileRules, } pub struct CompilationLoader { identifier: Identifier, @@ -39,13 +54,15 @@ pub const COMPILATION_LOADER_IDENTIFIER: &str = "builtin:compilation-loader"; impl From for CompilationOptions { fn from(value: LoaderOptions) -> Self { - let transform_features = TransformFeatureOptions::default(); + let transform_features = value.transform_features; + let compile_rules = value.compile_rules; CompilationOptions { swc_options: Options { config: value.swc_options, ..Default::default() }, transform_features, + compile_rules, } } } @@ -74,6 +91,17 @@ lazy_static! { impl Loader for CompilationLoader { async fn run(&self, loader_context: &mut LoaderContext<'_, LoaderRunnerContext>) -> Result<()> { let resource_path = loader_context.resource_path.to_path_buf(); + + if self.loader_options.compile_rules.exclude.is_some() { + let exclude = self.loader_options.compile_rules.exclude.as_ref().unwrap(); + for pattern in exclude { + let pattern = RspackRegex::new(pattern).unwrap(); + if pattern.test(&resource_path.to_string_lossy()) { + return Ok(()); + } + } + } + let Some(content) = std::mem::take(&mut loader_context.content) else { return Err(internal_error!("No content found")); }; @@ -84,7 +112,17 @@ impl Loader for CompilationLoader { let mut transform = TransformConfig::default(); let default_development = matches!(loader_context.context.options.mode, Mode::Development); transform.react.development = Some(default_development); - transform.react.runtime = Some(Runtime::Automatic); + swc_options + .config + .jsc + .transform + .merge(MergingOption::from(Some(transform))); + } + + let file_extension = resource_path.extension().unwrap(); + let ts_extensions = vec!["tsx", "ts", "mts"]; + if ts_extensions.iter().any(|ext| ext == &file_extension) { + swc_options.config.jsc.syntax = Some(Syntax::Typescript(TsConfig { tsx: true, decorators: true, ..Default::default() })); } if let Some(pre_source_map) = std::mem::take(&mut loader_context.source_map) { @@ -133,7 +171,7 @@ impl Loader for CompilationLoader { } } file_access.insert(resource_path.to_string_lossy().to_string(), true); - + let built = compiler.parse(None, |_| { transform( &resource_path, diff --git a/crates/loader_compilation/src/transform/mod.rs b/crates/loader_compilation/src/transform/mod.rs index ff2a10b..9bc09dd 100644 --- a/crates/loader_compilation/src/transform/mod.rs +++ b/crates/loader_compilation/src/transform/mod.rs @@ -80,24 +80,11 @@ fn match_app_entry(resource_path: &Path) -> bool { regex_for_app.is_match(resource_path_str) } -#[derive(Default, Debug, Clone, Deserialize)] -#[serde(rename_all = "camelCase", default)] -pub struct KeepExportOptions { - pub export_names: Vec, -} - -#[derive(Default, Debug, Clone, Deserialize)] -#[serde(rename_all = "camelCase", default)] -pub struct RemoveExportOptions { - pub remove_names: Vec, -} - - #[derive(Debug, Default, Deserialize)] #[serde(rename_all = "camelCase", default)] pub struct TransformFeatureOptions { - pub keep_export: Option, - pub remove_export: Option, + pub keep_export: Option>, + pub remove_export: Option>, } pub(crate) fn transform<'a>( @@ -106,8 +93,8 @@ pub(crate) fn transform<'a>( feature_options: &TransformFeatureOptions, ) -> impl Fold + 'a { chain!( - either!(feature_options.keep_export, |options: &KeepExportOptions| { - let mut exports_name = options.export_names.clone(); + either!(feature_options.keep_export, |options: &Vec| { + let mut exports_name = options.clone(); // Special case for app entry. // When keep pageConfig, we should also keep the default export of app entry. if match_app_entry(resource_path) && exports_name.contains(&String::from("pageConfig")) { @@ -117,8 +104,8 @@ pub(crate) fn transform<'a>( }, || { match_app_entry(resource_path) || match_route_entry(resource_path, routes_config) }), - either!(feature_options.remove_export, |options: &RemoveExportOptions| { - remove_export(options.remove_names.clone()) + either!(feature_options.remove_export, |options: &Vec| { + remove_export(options.clone()) }, || { // Remove export only work for app entry and route entry. match_app_entry(resource_path) || match_route_entry(resource_path, routes_config) diff --git a/crates/loader_compilation/tests/fixtures.rs b/crates/loader_compilation/tests/fixtures.rs index 2a4597a..ae7386a 100644 --- a/crates/loader_compilation/tests/fixtures.rs +++ b/crates/loader_compilation/tests/fixtures.rs @@ -3,7 +3,7 @@ use loader_compilation::{CompilationLoader, LoaderOptions}; use rspack_core::{ run_loaders, CompilerContext, CompilerOptions, Loader, LoaderRunnerContext, ResourceData, SideEffectOption, }; -use swc_core::base::config::{PluginConfig, Config}; +use swc_core::base::config::Config; async fn loader_test(actual: impl AsRef, expected: impl AsRef) { let tests_path = PathBuf::from(concat!(env!("CARGO_MANIFEST_DIR"))).join("tests"); @@ -16,10 +16,13 @@ async fn loader_test(actual: impl AsRef, expected: impl AsRef) { &[Arc::new(CompilationLoader::new(LoaderOptions { swc_options: options, transform_features: Default::default(), + compile_rules: Default::default(), })) as Arc>], &ResourceData::new(actual_path.to_string_lossy().to_string(), actual_path), &[], CompilerContext { + module: None, + module_context: None, options: std::sync::Arc::new(CompilerOptions { context: rspack_core::Context::new(parent_path.to_string_lossy().to_string()), dev_server: rspack_core::DevServerOptions::default(), From 3ef40f2cc23eff73738263c4015fbd82d3c27de4 Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Thu, 30 Nov 2023 14:16:59 +0800 Subject: [PATCH 14/32] chore: push built-in plugins (#16) * chore: push built-in plugins * chore: add default plugin --- crates/binding_options/Cargo.toml | 1 + crates/binding_options/src/options/mod.rs | 3 +++ crates/plugin_manifest/src/plugin.rs | 7 +------ 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/crates/binding_options/Cargo.toml b/crates/binding_options/Cargo.toml index a0a45e8..5163393 100644 --- a/crates/binding_options/Cargo.toml +++ b/crates/binding_options/Cargo.toml @@ -48,6 +48,7 @@ rspack_hash = { path = "../.rspack_crates/rspack_has rspack_swc_visitors = { path = "../.rspack_crates/rspack_swc_visitors" } loader_compilation = { path = "../loader_compilation" } plugin_manifest = { path = "../plugin_manifest" } +## plugin_specilize_module_name = { path = "../plugin_specilize_module_name" } futures-util = { workspace = true } anyhow = { workspace = true, features = ["backtrace"] } diff --git a/crates/binding_options/src/options/mod.rs b/crates/binding_options/src/options/mod.rs index 2d8a912..b7b24d4 100644 --- a/crates/binding_options/src/options/mod.rs +++ b/crates/binding_options/src/options/mod.rs @@ -164,6 +164,9 @@ impl RawOptionsApply for RSPackRawOptions { plugins.push(rspack_plugin_warn_sensitive_module::WarnCaseSensitiveModulesPlugin.boxed()); + // Add custom plugins. + plugins.push(plugin_manifest::ManifestPlugin::new().boxed()); + Ok(Self::Options { context, mode, diff --git a/crates/plugin_manifest/src/plugin.rs b/crates/plugin_manifest/src/plugin.rs index 8bbde27..c2e6cab 100644 --- a/crates/plugin_manifest/src/plugin.rs +++ b/crates/plugin_manifest/src/plugin.rs @@ -91,13 +91,8 @@ impl Plugin for ManifestPlugin { } }); let json_string = serde_json::to_string(&assets_mainfest).unwrap(); - let output_path = compilation - .options - .output - .path - .join("assets-manifest.json".to_string()).to_string_lossy().to_string(); compilation.emit_asset( - output_path, + "assets-manifest.json".to_string(), CompilationAsset::from(RawSource::from(json_string).boxed()), ); Ok(()) From 555c734234e828f955de689e455884da0a0f5228 Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Thu, 30 Nov 2023 15:33:36 +0800 Subject: [PATCH 15/32] fix: update toolchain in ci workflow (#17) * fix: update toolchain in ci workflow * fix: cache target * chore: test publish * fix: remove universal build * fix: ci --- .github/workflows/ci.yml | 2 +- .github/workflows/release.yml | 31 ++----------------------------- crates/node_binding/package.json | 1 - 3 files changed, 3 insertions(+), 31 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d5f8002..4c21e39 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -89,7 +89,7 @@ jobs: - name: Install Rust Toolchain uses: ./.github/actions/rustup with: - save-cache: ${{ github.ref_name == 'main' }} + save-cache: ${{ github.ref_name == 'master' }} shared-key: check # Compile test without debug info for reducing the CI cache size diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 14074c0..a21c1b0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -70,7 +70,7 @@ jobs: uses: dtolnay/rust-toolchain@stable if: ${{ !matrix.settings.docker }} with: - toolchain: nightly-2023-06-02 + toolchain: nightly-2023-10-24 targets: ${{ matrix.settings.target }} - name: Cache cargo @@ -105,38 +105,11 @@ jobs: name: bindings-${{ matrix.settings.target }} path: crates/node_binding/${{ env.APP_NAME }}.*.node if-no-files-found: error - universal-macOS: - name: Build universal macOS binary - needs: - - build - runs-on: macos-latest - steps: - - uses: actions/checkout@v4 - - name: Pnpm Cache # Required by some tests - uses: ./.github/actions/pnpm-cache - - name: Download macOS x64 artifact - uses: actions/download-artifact@v3 - with: - name: bindings-x86_64-apple-darwin - path: crates/node_binding/ - - name: Download macOS arm64 artifact - uses: actions/download-artifact@v3 - with: - name: bindings-aarch64-apple-darwin - path: crates/node_binding/ - - name: Combine binaries - run: cd crates/node_binding && pnpm universal - - name: Upload artifact - uses: actions/upload-artifact@v3 - with: - name: bindings-universal-apple-darwin - path: crates/node_binding/${{ env.APP_NAME }}.*.node - if-no-files-found: error publish: name: Publish runs-on: ubuntu-latest needs: - - universal-macOS + - build steps: - uses: actions/checkout@v4 - name: Pnpm Cache # Required by some tests diff --git a/crates/node_binding/package.json b/crates/node_binding/package.json index 70ddf23..0f12da4 100644 --- a/crates/node_binding/package.json +++ b/crates/node_binding/package.json @@ -27,7 +27,6 @@ "build:debug": "napi build --platform", "build:debug:aarch64": "napi build --platform --target aarch64-apple-darwin", "prepublishOnly": "napi prepublish -t npm", - "universal": "napi universal", "version": "napi version" } } \ No newline at end of file From 9f1ca9aa7898d7130eb15644e528fac792e4091b Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Fri, 1 Dec 2023 11:26:15 +0800 Subject: [PATCH 16/32] fix: universal ci (#18) * fix: ci * fix: ci * fix: ci * fix: ci * fix: ci * fix: ci * fix: ci * fix: ci * fix: ci * fix: ci * fix: optimize ci --- .github/workflows/release.yml | 39 +++++++++++++++++-- .../npm/darwin-arm64/package.json | 2 +- .../npm/darwin-universal/README.md | 3 ++ .../npm/darwin-universal/package.json | 18 +++++++++ .../node_binding/npm/darwin-x64/package.json | 2 +- .../npm/linux-x64-gnu/package.json | 2 +- .../node_binding/npm/linux-x64-musl/README.md | 3 ++ .../npm/linux-x64-musl/package.json | 24 ++++++++++++ .../npm/win32-arm64-msvc/README.md | 3 ++ .../npm/win32-arm64-msvc/package.json | 21 ++++++++++ crates/node_binding/package.json | 8 +++- pnpm-lock.yaml | 8 ++-- 12 files changed, 121 insertions(+), 12 deletions(-) create mode 100644 crates/node_binding/npm/darwin-universal/README.md create mode 100644 crates/node_binding/npm/darwin-universal/package.json create mode 100644 crates/node_binding/npm/linux-x64-musl/README.md create mode 100644 crates/node_binding/npm/linux-x64-musl/package.json create mode 100644 crates/node_binding/npm/win32-arm64-msvc/README.md create mode 100644 crates/node_binding/npm/win32-arm64-msvc/package.json diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a21c1b0..b38677f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -25,6 +25,7 @@ jobs: matrix: settings: - host: macos-latest + name: darwin-x64 target: x86_64-apple-darwin build: | cd crates/node_binding @@ -32,9 +33,11 @@ jobs: strip -x *.node - host: windows-latest build: cd crates/node_binding && pnpm build + name: win32-x64-msvc target: x86_64-pc-windows-msvc - host: ubuntu-latest target: x86_64-unknown-linux-gnu + name: linux-x64-gnu docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian build: |- set -e && @@ -43,10 +46,12 @@ jobs: pnpm build --target x86_64-unknown-linux-gnu && strip *.node - host: ubuntu-latest + name: linux-x64-musl target: x86_64-unknown-linux-musl docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine build: cd crates/node_binding && set -e && pnpm build && strip *.node - host: macos-latest + name: darwin-arm64 target: aarch64-apple-darwin build: | cd crates/node_binding @@ -54,6 +59,7 @@ jobs: strip -x *.node - host: windows-latest target: aarch64-pc-windows-msvc + name: win32-arm64-msvc build: cd crates/node_binding && pnpm build --target aarch64-pc-windows-msvc name: stable - ${{ matrix.settings.target }} - node@18 runs-on: ${{ matrix.settings.host }} @@ -102,14 +108,41 @@ jobs: - name: Upload artifact uses: actions/upload-artifact@v3 with: - name: bindings-${{ matrix.settings.target }} + name: ${{ env.APP_NAME }}.${{ matrix.settings.name }}.node + path: crates/node_binding/${{ env.APP_NAME }}.*.node + if-no-files-found: error + universal-macOS: + name: Build universal macOS binary + needs: + - build + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + - name: Pnpm Cache # Required by some tests + uses: ./.github/actions/pnpm-cache + - name: Download macOS x64 artifact + uses: actions/download-artifact@v3 + with: + name: ${{ env.APP_NAME }}.darwin-x64.node + path: crates/node_binding/artifacts + - name: Download macOS arm64 artifact + uses: actions/download-artifact@v3 + with: + name: ${{ env.APP_NAME }}.darwin-arm64.node + path: crates/node_binding/artifacts + - name: Combine binaries + run: cd crates/node_binding && pnpm universal + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: ${{ env.APP_NAME }}.darwin-universal.node path: crates/node_binding/${{ env.APP_NAME }}.*.node if-no-files-found: error publish: name: Publish runs-on: ubuntu-latest needs: - - build + - universal-macOS steps: - uses: actions/checkout@v4 - name: Pnpm Cache # Required by some tests @@ -117,7 +150,7 @@ jobs: - name: Download all artifacts uses: actions/download-artifact@v3 with: - path: crates/node_binding + path: crates/node_binding/artifacts - name: Move artifacts run: cd crates/node_binding && pnpm artifacts - name: List packages diff --git a/crates/node_binding/npm/darwin-arm64/package.json b/crates/node_binding/npm/darwin-arm64/package.json index 272a590..e53a1a4 100644 --- a/crates/node_binding/npm/darwin-arm64/package.json +++ b/crates/node_binding/npm/darwin-arm64/package.json @@ -1,6 +1,6 @@ { "name": "@ice/pack-binding-darwin-arm64", - "version": "0.0.0", + "version": "0.0.1", "os": [ "darwin" ], diff --git a/crates/node_binding/npm/darwin-universal/README.md b/crates/node_binding/npm/darwin-universal/README.md new file mode 100644 index 0000000..6935816 --- /dev/null +++ b/crates/node_binding/npm/darwin-universal/README.md @@ -0,0 +1,3 @@ +# `@ice/pack-binding-darwin-universal` + +This is the **universal-apple-darwin** binary for `@ice/pack-binding` \ No newline at end of file diff --git a/crates/node_binding/npm/darwin-universal/package.json b/crates/node_binding/npm/darwin-universal/package.json new file mode 100644 index 0000000..45d2b15 --- /dev/null +++ b/crates/node_binding/npm/darwin-universal/package.json @@ -0,0 +1,18 @@ +{ + "name": "@ice/pack-binding-darwin-universal", + "version": "0.0.1", + "os": [ + "darwin" + ], + "main": "pack-binding.darwin-universal.node", + "files": [ + "pack-binding.darwin-universal.node" + ], + "license": "MIT", + "engines": { + "node": ">= 10" + }, + "repository": { + "url": "https://github.com/ice-lab/awesome-ice" + } +} \ No newline at end of file diff --git a/crates/node_binding/npm/darwin-x64/package.json b/crates/node_binding/npm/darwin-x64/package.json index 866c8a6..e0bc47c 100644 --- a/crates/node_binding/npm/darwin-x64/package.json +++ b/crates/node_binding/npm/darwin-x64/package.json @@ -1,6 +1,6 @@ { "name": "@ice/pack-binding-darwin-x64", - "version": "0.0.0", + "version": "0.0.1", "os": [ "darwin" ], diff --git a/crates/node_binding/npm/linux-x64-gnu/package.json b/crates/node_binding/npm/linux-x64-gnu/package.json index 23d2266..c649831 100644 --- a/crates/node_binding/npm/linux-x64-gnu/package.json +++ b/crates/node_binding/npm/linux-x64-gnu/package.json @@ -1,6 +1,6 @@ { "name": "@ice/pack-binding-linux-x64-gnu", - "version": "0.0.0", + "version": "0.0.1", "os": [ "linux" ], diff --git a/crates/node_binding/npm/linux-x64-musl/README.md b/crates/node_binding/npm/linux-x64-musl/README.md new file mode 100644 index 0000000..6cee88e --- /dev/null +++ b/crates/node_binding/npm/linux-x64-musl/README.md @@ -0,0 +1,3 @@ +# `@ice/pack-binding-linux-x64-musl` + +This is the **x86_64-unknown-linux-musl** binary for `@ice/pack-binding` diff --git a/crates/node_binding/npm/linux-x64-musl/package.json b/crates/node_binding/npm/linux-x64-musl/package.json new file mode 100644 index 0000000..78b14b7 --- /dev/null +++ b/crates/node_binding/npm/linux-x64-musl/package.json @@ -0,0 +1,24 @@ +{ + "name": "@ice/pack-binding-linux-x64-musl", + "version": "0.0.1", + "os": [ + "linux" + ], + "cpu": [ + "x64" + ], + "main": "pack-binding.linux-x64-musl.node", + "files": [ + "pack-binding.linux-x64-musl.node" + ], + "license": "MIT", + "engines": { + "node": ">= 10" + }, + "libc": [ + "musl" + ], + "repository": { + "url": "https://github.com/ice-lab/awesome-ice" + } +} \ No newline at end of file diff --git a/crates/node_binding/npm/win32-arm64-msvc/README.md b/crates/node_binding/npm/win32-arm64-msvc/README.md new file mode 100644 index 0000000..74961fc --- /dev/null +++ b/crates/node_binding/npm/win32-arm64-msvc/README.md @@ -0,0 +1,3 @@ +# `@ice/pack-binding-win32-arm64-msvc` + +This is the **aarch64-pc-windows-msvc** binary for `@ice/pack-binding` diff --git a/crates/node_binding/npm/win32-arm64-msvc/package.json b/crates/node_binding/npm/win32-arm64-msvc/package.json new file mode 100644 index 0000000..1eb8b21 --- /dev/null +++ b/crates/node_binding/npm/win32-arm64-msvc/package.json @@ -0,0 +1,21 @@ +{ + "name": "@ice/pack-binding-win32-arm64-msvc", + "version": "0.0.1", + "os": [ + "win32" + ], + "cpu": [ + "arm64" + ], + "main": "pack-binding.win32-arm64-msvc.node", + "files": [ + "pack-binding.win32-arm64-msvc.node" + ], + "license": "MIT", + "engines": { + "node": ">= 10" + }, + "repository": { + "url": "https://github.com/ice-lab/awesome-ice" + } +} \ No newline at end of file diff --git a/crates/node_binding/package.json b/crates/node_binding/package.json index 0f12da4..305ceab 100644 --- a/crates/node_binding/package.json +++ b/crates/node_binding/package.json @@ -7,13 +7,16 @@ "name": "pack-binding", "triples": { "additional": [ - "aarch64-apple-darwin" + "aarch64-apple-darwin", + "aarch64-pc-windows-msvc", + "x86_64-unknown-linux-musl", + "universal-apple-darwin" ] } }, "license": "MIT", "devDependencies": { - "@napi-rs/cli": "^2.16.3" + "@napi-rs/cli": "^2.16.4" }, "ava": { "timeout": "3m" @@ -27,6 +30,7 @@ "build:debug": "napi build --platform", "build:debug:aarch64": "napi build --platform --target aarch64-apple-darwin", "prepublishOnly": "napi prepublish -t npm", + "universal": "napi universal", "version": "napi version" } } \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2899f6d..01139e0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -27,8 +27,8 @@ importers: crates/node_binding: devDependencies: '@napi-rs/cli': - specifier: ^2.16.3 - version: 2.16.3 + specifier: ^2.16.4 + version: 2.16.5 packages: @@ -44,8 +44,8 @@ packages: wrap-ansi-cjs: /wrap-ansi@7.0.0 dev: true - /@napi-rs/cli@2.16.3: - resolution: {integrity: sha512-3mLNPlbbOhpbIUKicLrJtIearlHXUuXL3UeueYyRRplpVMNkdn8xCyzY6PcYZi3JXR8bmCOiWgkVmLnrSL7DKw==} + /@napi-rs/cli@2.16.5: + resolution: {integrity: sha512-mFEzwrg4IOLngGd2/P6yeqIWgwQNn59Z08n1rndu6kLDq1gg954NH9cM1O9Da0RJuybt46p43lqgSsnAY2mxqA==} engines: {node: '>= 10'} hasBin: true dev: true From 2c394c8be567f4651765375ac1e33b52236d5f45 Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Fri, 1 Dec 2023 13:49:43 +0800 Subject: [PATCH 17/32] 0.0.1 --- crates/node_binding/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/node_binding/package.json b/crates/node_binding/package.json index 305ceab..3ea2ef9 100644 --- a/crates/node_binding/package.json +++ b/crates/node_binding/package.json @@ -1,6 +1,6 @@ { "name": "@ice/pack-binding", - "version": "0.0.0", + "version": "0.0.1", "main": "index.js", "types": "index.d.ts", "napi": { From e76bc3e6240c7da2db29ad1829b7d6adeb72357d Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Fri, 1 Dec 2023 14:19:27 +0800 Subject: [PATCH 18/32] 0.0.1 --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b38677f..93c30d9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -158,7 +158,7 @@ jobs: shell: bash - name: Publish run: | - npm config set provenance true + cd crates/node_binding && npm config set provenance true if git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$"; then echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc From e6a808359413a0089bc44d0b6620524397b92814 Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Mon, 4 Dec 2023 10:40:01 +0800 Subject: [PATCH 19/32] chore: fix repository config (#20) --- crates/node_binding/npm/darwin-arm64/package.json | 3 +++ crates/node_binding/npm/darwin-universal/package.json | 2 +- crates/node_binding/npm/darwin-x64/package.json | 3 +++ crates/node_binding/npm/linux-x64-gnu/package.json | 5 ++++- crates/node_binding/npm/linux-x64-musl/package.json | 2 +- crates/node_binding/npm/win32-arm64-msvc/package.json | 2 +- crates/node_binding/npm/win32-x64-msvc/package.json | 3 +++ crates/node_binding/package.json | 3 +++ 8 files changed, 19 insertions(+), 4 deletions(-) diff --git a/crates/node_binding/npm/darwin-arm64/package.json b/crates/node_binding/npm/darwin-arm64/package.json index e53a1a4..f72cc22 100644 --- a/crates/node_binding/npm/darwin-arm64/package.json +++ b/crates/node_binding/npm/darwin-arm64/package.json @@ -14,5 +14,8 @@ "license": "MIT", "engines": { "node": ">= 10" + }, + "repository": { + "url": "https://github.com/ice-lab/icepack" } } \ No newline at end of file diff --git a/crates/node_binding/npm/darwin-universal/package.json b/crates/node_binding/npm/darwin-universal/package.json index 45d2b15..94c55bf 100644 --- a/crates/node_binding/npm/darwin-universal/package.json +++ b/crates/node_binding/npm/darwin-universal/package.json @@ -13,6 +13,6 @@ "node": ">= 10" }, "repository": { - "url": "https://github.com/ice-lab/awesome-ice" + "url": "https://github.com/ice-lab/icepack" } } \ No newline at end of file diff --git a/crates/node_binding/npm/darwin-x64/package.json b/crates/node_binding/npm/darwin-x64/package.json index e0bc47c..94184df 100644 --- a/crates/node_binding/npm/darwin-x64/package.json +++ b/crates/node_binding/npm/darwin-x64/package.json @@ -14,5 +14,8 @@ "license": "MIT", "engines": { "node": ">= 10" + }, + "repository": { + "url": "https://github.com/ice-lab/icepack" } } \ No newline at end of file diff --git a/crates/node_binding/npm/linux-x64-gnu/package.json b/crates/node_binding/npm/linux-x64-gnu/package.json index c649831..2895526 100644 --- a/crates/node_binding/npm/linux-x64-gnu/package.json +++ b/crates/node_binding/npm/linux-x64-gnu/package.json @@ -17,5 +17,8 @@ }, "libc": [ "glibc" - ] + ], + "repository": { + "url": "https://github.com/ice-lab/icepack" + } } \ No newline at end of file diff --git a/crates/node_binding/npm/linux-x64-musl/package.json b/crates/node_binding/npm/linux-x64-musl/package.json index 78b14b7..182b5ef 100644 --- a/crates/node_binding/npm/linux-x64-musl/package.json +++ b/crates/node_binding/npm/linux-x64-musl/package.json @@ -19,6 +19,6 @@ "musl" ], "repository": { - "url": "https://github.com/ice-lab/awesome-ice" + "url": "https://github.com/ice-lab/icepack" } } \ No newline at end of file diff --git a/crates/node_binding/npm/win32-arm64-msvc/package.json b/crates/node_binding/npm/win32-arm64-msvc/package.json index 1eb8b21..1b65188 100644 --- a/crates/node_binding/npm/win32-arm64-msvc/package.json +++ b/crates/node_binding/npm/win32-arm64-msvc/package.json @@ -16,6 +16,6 @@ "node": ">= 10" }, "repository": { - "url": "https://github.com/ice-lab/awesome-ice" + "url": "https://github.com/ice-lab/icepack" } } \ No newline at end of file diff --git a/crates/node_binding/npm/win32-x64-msvc/package.json b/crates/node_binding/npm/win32-x64-msvc/package.json index bdaad45..ee3e398 100644 --- a/crates/node_binding/npm/win32-x64-msvc/package.json +++ b/crates/node_binding/npm/win32-x64-msvc/package.json @@ -14,5 +14,8 @@ "license": "MIT", "engines": { "node": ">= 10" + }, + "repository": { + "url": "https://github.com/ice-lab/icepack" } } \ No newline at end of file diff --git a/crates/node_binding/package.json b/crates/node_binding/package.json index 3ea2ef9..dc696ea 100644 --- a/crates/node_binding/package.json +++ b/crates/node_binding/package.json @@ -32,5 +32,8 @@ "prepublishOnly": "napi prepublish -t npm", "universal": "napi universal", "version": "napi version" + }, + "repository": { + "url": "https://github.com/ice-lab/icepack" } } \ No newline at end of file From cf3e939060f500892256e28952c497aeb69133b2 Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Mon, 4 Dec 2023 10:42:38 +0800 Subject: [PATCH 20/32] 0.0.1 --- crates/node_binding/npm/win32-x64-msvc/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/node_binding/npm/win32-x64-msvc/package.json b/crates/node_binding/npm/win32-x64-msvc/package.json index ee3e398..1b162bf 100644 --- a/crates/node_binding/npm/win32-x64-msvc/package.json +++ b/crates/node_binding/npm/win32-x64-msvc/package.json @@ -1,6 +1,6 @@ { "name": "@ice/pack-binding-win32-x64-msvc", - "version": "0.0.0", + "version": "0.0.1", "os": [ "win32" ], From 76862688e92a9e22b439da146d2087bd26a266ea Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Tue, 5 Dec 2023 13:44:46 +0800 Subject: [PATCH 21/32] feat: support env replacement --- crates/loader_compilation/src/lib.rs | 10 +- .../src/transform/env_replacement.rs | 384 ++++++++++++++++++ .../loader_compilation/src/transform/mod.rs | 17 +- crates/loader_compilation/tests/fixtures.rs | 51 ++- .../fixtures/basic/.ice/route-manifest.json | 22 - .../tests/fixtures/basic/input.js | 11 +- .../tests/fixtures/basic/output.js | 7 +- .../tests/fixtures/default/input.js | 5 + .../tests/fixtures/default/output.js | 19 + .../tests/fixtures/multiple/input.js | 5 + .../tests/fixtures/multiple/output.js | 5 + .../tests/fixtures/named/input.js | 5 + .../tests/fixtures/named/output.js | 4 + .../tests/fixtures/require_basic/input.js | 5 + .../tests/fixtures/require_basic/output.js | 4 + .../tests/fixtures/require_default/input.js | 5 + .../tests/fixtures/require_default/output.js | 19 + .../tests/fixtures/require_named/input.js | 5 + .../tests/fixtures/require_named/output.js | 4 + .../tests/fixtures/require_rest/input.js | 5 + .../tests/fixtures/require_rest/output.js | 20 + .../tests/fixtures/require_scoped/input.js | 8 + .../tests/fixtures/require_scoped/output.js | 9 + 23 files changed, 586 insertions(+), 43 deletions(-) create mode 100644 crates/loader_compilation/src/transform/env_replacement.rs delete mode 100644 crates/loader_compilation/tests/fixtures/basic/.ice/route-manifest.json create mode 100644 crates/loader_compilation/tests/fixtures/default/input.js create mode 100644 crates/loader_compilation/tests/fixtures/default/output.js create mode 100644 crates/loader_compilation/tests/fixtures/multiple/input.js create mode 100644 crates/loader_compilation/tests/fixtures/multiple/output.js create mode 100644 crates/loader_compilation/tests/fixtures/named/input.js create mode 100644 crates/loader_compilation/tests/fixtures/named/output.js create mode 100644 crates/loader_compilation/tests/fixtures/require_basic/input.js create mode 100644 crates/loader_compilation/tests/fixtures/require_basic/output.js create mode 100644 crates/loader_compilation/tests/fixtures/require_default/input.js create mode 100644 crates/loader_compilation/tests/fixtures/require_default/output.js create mode 100644 crates/loader_compilation/tests/fixtures/require_named/input.js create mode 100644 crates/loader_compilation/tests/fixtures/require_named/output.js create mode 100644 crates/loader_compilation/tests/fixtures/require_rest/input.js create mode 100644 crates/loader_compilation/tests/fixtures/require_rest/output.js create mode 100644 crates/loader_compilation/tests/fixtures/require_scoped/input.js create mode 100644 crates/loader_compilation/tests/fixtures/require_scoped/output.js diff --git a/crates/loader_compilation/src/lib.rs b/crates/loader_compilation/src/lib.rs index 5bcb3c9..197808d 100644 --- a/crates/loader_compilation/src/lib.rs +++ b/crates/loader_compilation/src/lib.rs @@ -1,3 +1,4 @@ +#![feature(box_patterns)] use std::{path::Path, collections::HashMap, sync::Mutex}; use lazy_static::lazy_static; use rspack_ast::RspackAst; @@ -163,8 +164,11 @@ impl Loader for CompilationLoader { if routes_config.is_none() || file_accessed { // Load routes config for transform. let routes_config_path: std::path::PathBuf = Path::new(compiler_context).join(".ice/route-manifest.json"); - *routes_config = Some(load_routes_config(&routes_config_path).unwrap()); - + let routes_content = load_routes_config(&routes_config_path); + if routes_content.is_ok() { + *routes_config = Some(routes_content?); + } + if file_accessed { // If file accessed, then we need to clear the map for the current compilation. file_access.clear(); @@ -175,7 +179,7 @@ impl Loader for CompilationLoader { let built = compiler.parse(None, |_| { transform( &resource_path, - routes_config.as_ref().unwrap(), + routes_config.as_ref(), transform_options ) })?; diff --git a/crates/loader_compilation/src/transform/env_replacement.rs b/crates/loader_compilation/src/transform/env_replacement.rs new file mode 100644 index 0000000..ef9e597 --- /dev/null +++ b/crates/loader_compilation/src/transform/env_replacement.rs @@ -0,0 +1,384 @@ +use swc_core::{ + ecma::{ + ast::*, + visit::{Fold, FoldWith}, + }, + common::DUMMY_SP, +}; +struct EnvReplacement { + sources: Vec, +} + +fn create_check_expr(meta_value: &str, renderer: &str) -> Expr { + Expr::Bin(BinExpr { + span: DUMMY_SP, + op: BinaryOp::EqEqEq, + left: Box::new(Expr::Member(MemberExpr { + span: DUMMY_SP, + obj: Box::new(Expr::MetaProp(MetaPropExpr { span: DUMMY_SP, kind: MetaPropKind::ImportMeta })), + prop: Ident::new(meta_value.into(), DUMMY_SP).into(), + })), + right: Box::new(Expr::Lit(Lit::Str(Str { + value: renderer.into(), + span: DUMMY_SP, + raw: None, + }))), + }) +} + +fn create_typeof_check(expr: Expr, check_value: &str, op: BinaryOp) -> Expr { + // Create `typeof pha` unary expression + let typeof_expr = Expr::Unary(UnaryExpr { + op: UnaryOp::TypeOf, + arg: Box::new(expr), + span: DUMMY_SP, + }); + + // Create `typeof pha === 'object'` binary expression + Expr::Bin(BinExpr { + left: Box::new(typeof_expr), + op, + right: Box::new(Expr::Lit(Lit::Str(Str { + value: check_value.into(), + span: DUMMY_SP, + raw: None, + }))), + span: DUMMY_SP, + }) +} + +fn combine_check_exprs(exprs: Vec, op: BinaryOp) -> Expr { + let mut result = exprs[0].clone(); + for expr in exprs[1..].iter() { + result = Expr::Bin(BinExpr { + span: DUMMY_SP, + op, + left: Box::new(result), + right: Box::new(expr.clone()), + }); + } + result +} + +fn build_regex_test_expression() -> Expr { + // Create the regex literal + let regex_pattern = Expr::Lit(Lit::Regex(Regex { + exp: ".+AliApp\\((\\w+)\\/((?:\\d+\\.)+\\d+)\\).* .*(WindVane)(?:\\/((?:\\d+\\.)+\\d+))?.*".into(), + flags: "".into(), + span: DUMMY_SP, + })); + + // Create the typeof expression for `navigator` + let typeof_navigator = Expr::Unary(UnaryExpr { + op: UnaryOp::TypeOf, + arg: Box::new(Expr::Ident(Ident::new("navigator".into(), DUMMY_SP))), + span: DUMMY_SP, + }); + + // Create the conditional expression + let conditional = Expr::Cond(CondExpr { + test: Box::new(typeof_navigator), + cons: Box::new(Expr::Bin(BinExpr { + left: Box::new(Expr::Member(MemberExpr { + obj: Box::new(Expr::Ident(Ident::new("navigator".into(), DUMMY_SP))), + prop: MemberProp::Ident(Ident::new("userAgent".into(), DUMMY_SP)), + span: DUMMY_SP, + })), + op: BinaryOp::LogicalOr, + right: Box::new(Expr::Member(MemberExpr { + obj: Box::new(Expr::Ident(Ident::new("navigator".into(), DUMMY_SP))), + prop: MemberProp::Ident(Ident::new("swuserAgent".into(), DUMMY_SP)), + span: DUMMY_SP, + })), + span: DUMMY_SP, + })), + alt: Box::new(Expr::Lit(Lit::Str(Str { + value: "".into(), + span: DUMMY_SP, + raw: None, + }))), + span: DUMMY_SP, + }); + + // Create the 'test' method call on the regex pattern + let test_call = Expr::Call(CallExpr { + callee: Callee::Expr(Box::new(Expr::Member(MemberExpr { + obj: Box::new(regex_pattern), + prop: MemberProp::Ident(Ident::new("test".into(), DUMMY_SP)), + span: DUMMY_SP, + }))), + args: vec![ExprOrSpread { + spread: None, + expr: Box::new(conditional), + }], + span: DUMMY_SP, + type_args: None, + }); + + test_call +} + +fn get_env_expr(specifier: &Ident) -> Expr { + match specifier.sym.as_ref() { + "isClient" => { + create_check_expr("renderer", "client") + }, + "isServer" => { + create_check_expr("renderer", "server") + }, + "isWeb" => { + combine_check_exprs(vec![ + create_check_expr("renderer", "client"), + create_check_expr("target", "web"), + ], BinaryOp::LogicalAnd) + }, + "isNode" => { + create_check_expr("renderer", "server") + }, + "isWeex" => { + combine_check_exprs(vec![ + create_check_expr("renderer", "client"), + create_check_expr("target", "weex"), + ], BinaryOp::LogicalAnd) + }, + "isKraken" => { + combine_check_exprs(vec![ + create_check_expr("renderer", "client"), + create_check_expr("target", "kraken"), + ], BinaryOp::LogicalAnd) + }, + "isPHA" => { + combine_check_exprs(vec![ + create_check_expr("renderer", "client"), + create_check_expr("target", "web"), + create_typeof_check( + Expr::Ident(Ident::new("pha".into(), DUMMY_SP)), + "object", + BinaryOp::EqEqEq, + ), + ], BinaryOp::LogicalAnd) + }, + "isWindVane" => { + combine_check_exprs(vec![ + create_check_expr("renderer", "client"), + build_regex_test_expression(), + create_typeof_check( + Expr::Ident(Ident::new("WindVane".into(), DUMMY_SP)), + "undefined", + BinaryOp::NotEqEq, + ), + create_typeof_check( + Expr::Member(MemberExpr { + span: DUMMY_SP, + obj: Box::new(Expr::Ident(Ident::new("WindVane".into(), DUMMY_SP))), + prop: Ident::new("call".into(), DUMMY_SP).into(), + }), + "undefined", + BinaryOp::NotEqEq, + ), + ], BinaryOp::LogicalAnd) + }, + _ => { + // Do not support miniapp env. + Expr::Lit(Lit::Bool(Bool { + span: DUMMY_SP, + value: false, + })) + } + } +} + +fn create_env_declare(specifier: &Ident, imported: &Ident) -> Stmt { + let expr = get_env_expr(&specifier); + + return Stmt::Decl(Decl::Var(Box::new(VarDecl { + span: DUMMY_SP, + kind: VarDeclKind::Var, + declare: false, + decls: vec![VarDeclarator { + span: DUMMY_SP, + name: Pat::Ident(BindingIdent { + id: imported.clone(), + type_ann: Default::default(), + }), + init: Some(Box::new(expr)), + definite: false, + }], + }))); +} + +fn create_env_default_export(export_name: Ident) -> Stmt { + Stmt::Decl(Decl::Var(Box::new(VarDecl { + span: DUMMY_SP, + kind: VarDeclKind::Const, + declare: false, + decls: vec![VarDeclarator { + span: DUMMY_SP, + name: Pat::Ident(BindingIdent { + id: export_name.clone(), + type_ann: Default::default(), + }), + init: Some(Box::new(Expr::Object(ObjectLit { + span: DUMMY_SP, + props: vec![ + "isWeb", + "isClient", + "isNode", + "isWeex", + "isKraken", + "isMiniApp", + "isByteDanceMicroApp", + "isBaiduSmartProgram", + "isKuaiShouMiniProgram", + "isWeChatMiniProgram", + "isQuickApp", + "isPHA", + "isWindVane", + "isFRM", + ].into_iter().map(|target| PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp { + key: PropName::Ident(Ident::new(target.into(), DUMMY_SP)), + value: Box::new(get_env_expr(&Ident::new(target.into(), DUMMY_SP))), + })))).collect(), + }))), + definite: false, + }], + }))) +} + +fn get_env_stmt(sources: &Vec, decls: Vec) -> Vec { + let mut stmts = vec![]; + for decl in decls { + if let Some(init) = decl.init { + if let Expr::Call(CallExpr { + args: ref call_args, + callee: Callee::Expr(box Expr::Ident(Ident { ref sym, .. })), + .. + }) = *init { + if sym == "require" && call_args.len() == 1 { + // Case const env = require('env'); + if let ExprOrSpread { expr: box Expr::Lit(Lit::Str(Str { ref value, .. })), .. } = call_args[0] { + if sources.iter().any(|s| value == s) { + match &decl.name { + Pat::Ident(BindingIdent { id, .. }) => { + stmts.push(create_env_default_export(id.clone())); + } + Pat::Object(ObjectPat { props, .. }) => { + props.iter().for_each(|prop| { + match prop { + ObjectPatProp::Assign(AssignPatProp { key, value, .. }) => { + if value.is_some() { + if let box Expr::Ident(ident) = &value.as_ref().unwrap() { + stmts.push(create_env_declare(key, &ident)); + } + } else { + stmts.push(create_env_declare(key, key)); + } + } + ObjectPatProp::KeyValue(KeyValuePatProp { key, value, .. }) => { + if let box Pat::Ident(BindingIdent { id , ..}) = &value { + if let PropName::Ident(i) = key { + stmts.push(create_env_declare(i, &id)); + } + } + } + ObjectPatProp::Rest(RestPat {arg, ..}) => { + if let box Pat::Ident(BindingIdent { id , ..}) = arg { + stmts.push(create_env_default_export(id.clone())); + } + } + } + }); + } + _ => {} + } + continue; + } + } + } + } + } + } + stmts +} + +impl Fold for EnvReplacement { + fn fold_module_items(&mut self, items: Vec) -> Vec { + let mut new_module_items: Vec = vec![]; + for item in items.iter() { + match &item { + // Import declaration. + ModuleItem::ModuleDecl(ModuleDecl::Import(import_decl)) => { + let src = &import_decl.src.value; + if self.sources.iter().any(|s| src == s) { + // Collect all specifiers. + import_decl.specifiers.iter().for_each(|specifier| { + match specifier { + ImportSpecifier::Named(named_specifier) => { + let imported = match &named_specifier.imported { + Some(ModuleExportName::Ident(ident)) => Some(ident), + _ => None, + }; + let s = if imported.is_some() { + imported.unwrap() + } else { + &named_specifier.local + }; + new_module_items.push(ModuleItem::Stmt(create_env_declare(s, &named_specifier.local))); + } + ImportSpecifier::Default(default_specifier) => { + new_module_items.push(ModuleItem::Stmt(create_env_default_export(default_specifier.local.clone()))); + } + ImportSpecifier::Namespace(namespace_specifier) => { + new_module_items.push(ModuleItem::Stmt(create_env_default_export(namespace_specifier.local.clone()))); + } + } + }); + + } else { + new_module_items.push(item.clone()); + } + } + ModuleItem::Stmt(Stmt::Decl(Decl::Var(var_decl))) => { + let stmt = get_env_stmt(&self.sources, var_decl.decls.clone()); + if stmt.len() > 0 { + let module_stmts = stmt.into_iter().map(|s| ModuleItem::Stmt(s)).collect::>(); + new_module_items.extend_from_slice(&module_stmts); + } else { + new_module_items.push(item.clone()); + } + } + _ => { + new_module_items.push(item.clone().fold_children_with(self)); + } + } + } + new_module_items + } + + fn fold_block_stmt(&mut self, block: BlockStmt) -> BlockStmt { + let mut new_stmts: Vec = vec![]; + block.stmts.clone().into_iter().for_each(|stmt| { + match &stmt { + Stmt::Decl(Decl::Var(var_decl)) => { + let env_stmts = get_env_stmt(&self.sources, var_decl.decls.clone()); + if env_stmts.len() > 0 { + new_stmts.extend_from_slice(&env_stmts); + } else { + new_stmts.push(stmt); + } + } + _ => { + new_stmts.push(stmt.fold_children_with(self)); + } + } + }); + BlockStmt { + stmts: new_stmts, + ..block + } + } +} + +pub fn env_replacement(sources: Vec) -> impl Fold { + EnvReplacement { sources } +} \ No newline at end of file diff --git a/crates/loader_compilation/src/transform/mod.rs b/crates/loader_compilation/src/transform/mod.rs index 9bc09dd..34a69d4 100644 --- a/crates/loader_compilation/src/transform/mod.rs +++ b/crates/loader_compilation/src/transform/mod.rs @@ -9,9 +9,11 @@ use swc_core::ecma::{ mod keep_export; mod remove_export; +mod env_replacement; use keep_export::keep_export; use remove_export::remove_export; +use env_replacement::env_replacement; macro_rules! either { ($config:expr, $f:expr) => { @@ -63,11 +65,13 @@ pub(crate) fn load_routes_config(path: &Path) -> Result, Error> { parse_routes_config(content) } -fn match_route_entry(resource_path: &Path, routes: &Vec) -> bool { +fn match_route_entry(resource_path: &Path, routes: Option<&Vec>) -> bool { let resource_path_str = resource_path.to_str().unwrap(); - for route in routes { - if resource_path_str.ends_with(&route.to_string()) { - return true; + if let Some(routes) = routes { + for route in routes { + if resource_path_str.ends_with(&route.to_string()) { + return true; + } } } false @@ -89,10 +93,13 @@ pub struct TransformFeatureOptions { pub(crate) fn transform<'a>( resource_path: &'a Path, - routes_config: &Vec, + routes_config: Option<&Vec>, feature_options: &TransformFeatureOptions, ) -> impl Fold + 'a { chain!( + either!(Some(&vec!["@uni/env".to_string(), "universal-env".to_string()]), |options: &Vec| { + env_replacement(options.clone()) + }), either!(feature_options.keep_export, |options: &Vec| { let mut exports_name = options.clone(); // Special case for app entry. diff --git a/crates/loader_compilation/tests/fixtures.rs b/crates/loader_compilation/tests/fixtures.rs index ae7386a..23ea4b3 100644 --- a/crates/loader_compilation/tests/fixtures.rs +++ b/crates/loader_compilation/tests/fixtures.rs @@ -3,8 +3,12 @@ use loader_compilation::{CompilationLoader, LoaderOptions}; use rspack_core::{ run_loaders, CompilerContext, CompilerOptions, Loader, LoaderRunnerContext, ResourceData, SideEffectOption, }; +use swc_core::ecma::ast::EsVersion; use swc_core::base::config::Config; +use rspack_ast::RspackAst; +use rspack_plugin_javascript::ast; + async fn loader_test(actual: impl AsRef, expected: impl AsRef) { let tests_path = PathBuf::from(concat!(env!("CARGO_MANIFEST_DIR"))).join("tests"); let expected_path = tests_path.join(expected); @@ -12,6 +16,7 @@ async fn loader_test(actual: impl AsRef, expected: impl AsRef) { let parent_path = actual_path.parent().unwrap().to_path_buf(); let mut options = Config::default(); + options.jsc.target = Some(EsVersion::Es2020); let (result, _) = run_loaders( &[Arc::new(CompilationLoader::new(LoaderOptions { swc_options: options, @@ -92,17 +97,57 @@ async fn loader_test(actual: impl AsRef, expected: impl AsRef) { .await .expect("TODO:") .split_into_parts(); - - let result = result.content.try_into_string().expect("TODO:"); + let code: String; + let code_ast = result.additional_data.get::().unwrap(); + let code_gen_options = result.additional_data.get::().unwrap(); + if let RspackAst::JavaScript(code_ast) = code_ast { + code = ast::stringify(code_ast, code_gen_options.clone()).unwrap().code; + } else { + panic!("TODO:"); + } + if env::var("UPDATE").is_ok() { + let result = code.into_bytes(); fs::write(expected_path, result).expect("TODO:"); } else { let expected = fs::read_to_string(expected_path).expect("TODO:"); - assert_eq!(result, expected); + assert_eq!(code, expected); } } #[tokio::test] async fn basic() { loader_test("fixtures/basic/input.js", "fixtures/basic/output.js").await; +} +#[tokio::test] +async fn named() { + loader_test("fixtures/named/input.js", "fixtures/named/output.js").await; +} +#[tokio::test] +async fn multiple() { + loader_test("fixtures/multiple/input.js", "fixtures/multiple/output.js").await; +} +#[tokio::test] +async fn default() { + loader_test("fixtures/default/input.js", "fixtures/default/output.js").await; +} +#[tokio::test] +async fn require_basic() { + loader_test("fixtures/require_basic/input.js", "fixtures/require_basic/output.js").await; +} +#[tokio::test] +async fn require_named() { + loader_test("fixtures/require_named/input.js", "fixtures/require_named/output.js").await; +} +#[tokio::test] +async fn require_default() { + loader_test("fixtures/require_default/input.js", "fixtures/require_default/output.js").await; +} +#[tokio::test] +async fn require_rest() { + loader_test("fixtures/require_rest/input.js", "fixtures/require_rest/output.js").await; +} +#[tokio::test] +async fn require_scoped() { + loader_test("fixtures/require_scoped/input.js", "fixtures/require_scoped/output.js").await; } \ No newline at end of file diff --git a/crates/loader_compilation/tests/fixtures/basic/.ice/route-manifest.json b/crates/loader_compilation/tests/fixtures/basic/.ice/route-manifest.json deleted file mode 100644 index cfcf422..0000000 --- a/crates/loader_compilation/tests/fixtures/basic/.ice/route-manifest.json +++ /dev/null @@ -1,22 +0,0 @@ -[ - { - "path": "error", - "id": "error", - "file": "error.tsx", - "componentName": "error", - "layout": false, - "exports": [ - "default" - ] - }, - { - "index": true, - "id": "/", - "file": "index.tsx", - "componentName": "index", - "layout": false, - "exports": [ - "default" - ] - } -] \ No newline at end of file diff --git a/crates/loader_compilation/tests/fixtures/basic/input.js b/crates/loader_compilation/tests/fixtures/basic/input.js index f11cfe5..a5f980a 100644 --- a/crates/loader_compilation/tests/fixtures/basic/input.js +++ b/crates/loader_compilation/tests/fixtures/basic/input.js @@ -1,8 +1,5 @@ -const a = 1; -const b = 2; +import { isWeb } from "@uni/env"; -export const dataLoader = { - b, -}; - -export default a; \ No newline at end of file +if (isWeb) { + console.log("test"); +} \ No newline at end of file diff --git a/crates/loader_compilation/tests/fixtures/basic/output.js b/crates/loader_compilation/tests/fixtures/basic/output.js index 5442d74..71a9e11 100644 --- a/crates/loader_compilation/tests/fixtures/basic/output.js +++ b/crates/loader_compilation/tests/fixtures/basic/output.js @@ -1,3 +1,4 @@ -const a = 1; - -window.__custom_code__ = true; +var isWeb = import.meta.renderer === "client" && import.meta.target === "web"; +if (isWeb) { + console.log("test"); +} diff --git a/crates/loader_compilation/tests/fixtures/default/input.js b/crates/loader_compilation/tests/fixtures/default/input.js new file mode 100644 index 0000000..353670a --- /dev/null +++ b/crates/loader_compilation/tests/fixtures/default/input.js @@ -0,0 +1,5 @@ +import env from "@uni/env"; + +if (env.isWeb) { + console.log("test"); +} \ No newline at end of file diff --git a/crates/loader_compilation/tests/fixtures/default/output.js b/crates/loader_compilation/tests/fixtures/default/output.js new file mode 100644 index 0000000..849bffa --- /dev/null +++ b/crates/loader_compilation/tests/fixtures/default/output.js @@ -0,0 +1,19 @@ +const env = { + isWeb: import.meta.renderer === "client" && import.meta.target === "web", + isClient: import.meta.renderer === "client", + isNode: import.meta.renderer === "server", + isWeex: import.meta.renderer === "client" && import.meta.target === "weex", + isKraken: import.meta.renderer === "client" && import.meta.target === "kraken", + isMiniApp: false, + isByteDanceMicroApp: false, + isBaiduSmartProgram: false, + isKuaiShouMiniProgram: false, + isWeChatMiniProgram: false, + isQuickApp: false, + isPHA: import.meta.renderer === "client" && import.meta.target === "web" && typeof pha === "object", + isWindVane: import.meta.renderer === "client" && /.+AliApp\((\w+)\/((?:\d+\.)+\d+)\).* .*(WindVane)(?:\/((?:\d+\.)+\d+))?.*/.test(typeof navigator ? navigator.userAgent || navigator.swuserAgent : "") && typeof WindVane !== "undefined" && typeof WindVane.call !== "undefined", + isFRM: false +}; +if (env.isWeb) { + console.log("test"); +} diff --git a/crates/loader_compilation/tests/fixtures/multiple/input.js b/crates/loader_compilation/tests/fixtures/multiple/input.js new file mode 100644 index 0000000..e740f1e --- /dev/null +++ b/crates/loader_compilation/tests/fixtures/multiple/input.js @@ -0,0 +1,5 @@ +import { isWeb, isPHA } from "@uni/env"; + +if (isWeb && isPHA) { + console.log("test"); +} \ No newline at end of file diff --git a/crates/loader_compilation/tests/fixtures/multiple/output.js b/crates/loader_compilation/tests/fixtures/multiple/output.js new file mode 100644 index 0000000..bd9c688 --- /dev/null +++ b/crates/loader_compilation/tests/fixtures/multiple/output.js @@ -0,0 +1,5 @@ +var isWeb = import.meta.renderer === "client" && import.meta.target === "web"; +var isPHA = import.meta.renderer === "client" && import.meta.target === "web" && typeof pha === "object"; +if (isWeb && isPHA) { + console.log("test"); +} diff --git a/crates/loader_compilation/tests/fixtures/named/input.js b/crates/loader_compilation/tests/fixtures/named/input.js new file mode 100644 index 0000000..2b6908e --- /dev/null +++ b/crates/loader_compilation/tests/fixtures/named/input.js @@ -0,0 +1,5 @@ +import { isWeb as web } from "@uni/env"; + +if (web) { + console.log("test"); +} \ No newline at end of file diff --git a/crates/loader_compilation/tests/fixtures/named/output.js b/crates/loader_compilation/tests/fixtures/named/output.js new file mode 100644 index 0000000..1ac586d --- /dev/null +++ b/crates/loader_compilation/tests/fixtures/named/output.js @@ -0,0 +1,4 @@ +var web = import.meta.renderer === "client" && import.meta.target === "web"; +if (web) { + console.log("test"); +} diff --git a/crates/loader_compilation/tests/fixtures/require_basic/input.js b/crates/loader_compilation/tests/fixtures/require_basic/input.js new file mode 100644 index 0000000..cdd4e60 --- /dev/null +++ b/crates/loader_compilation/tests/fixtures/require_basic/input.js @@ -0,0 +1,5 @@ +const { isWeb } = require("@uni/env"); + +if (isWeb) { + console.log("test"); +} \ No newline at end of file diff --git a/crates/loader_compilation/tests/fixtures/require_basic/output.js b/crates/loader_compilation/tests/fixtures/require_basic/output.js new file mode 100644 index 0000000..71a9e11 --- /dev/null +++ b/crates/loader_compilation/tests/fixtures/require_basic/output.js @@ -0,0 +1,4 @@ +var isWeb = import.meta.renderer === "client" && import.meta.target === "web"; +if (isWeb) { + console.log("test"); +} diff --git a/crates/loader_compilation/tests/fixtures/require_default/input.js b/crates/loader_compilation/tests/fixtures/require_default/input.js new file mode 100644 index 0000000..02f68f4 --- /dev/null +++ b/crates/loader_compilation/tests/fixtures/require_default/input.js @@ -0,0 +1,5 @@ +const env = require("@uni/env"); + +if (env.isWeb) { + console.log("test"); +} \ No newline at end of file diff --git a/crates/loader_compilation/tests/fixtures/require_default/output.js b/crates/loader_compilation/tests/fixtures/require_default/output.js new file mode 100644 index 0000000..849bffa --- /dev/null +++ b/crates/loader_compilation/tests/fixtures/require_default/output.js @@ -0,0 +1,19 @@ +const env = { + isWeb: import.meta.renderer === "client" && import.meta.target === "web", + isClient: import.meta.renderer === "client", + isNode: import.meta.renderer === "server", + isWeex: import.meta.renderer === "client" && import.meta.target === "weex", + isKraken: import.meta.renderer === "client" && import.meta.target === "kraken", + isMiniApp: false, + isByteDanceMicroApp: false, + isBaiduSmartProgram: false, + isKuaiShouMiniProgram: false, + isWeChatMiniProgram: false, + isQuickApp: false, + isPHA: import.meta.renderer === "client" && import.meta.target === "web" && typeof pha === "object", + isWindVane: import.meta.renderer === "client" && /.+AliApp\((\w+)\/((?:\d+\.)+\d+)\).* .*(WindVane)(?:\/((?:\d+\.)+\d+))?.*/.test(typeof navigator ? navigator.userAgent || navigator.swuserAgent : "") && typeof WindVane !== "undefined" && typeof WindVane.call !== "undefined", + isFRM: false +}; +if (env.isWeb) { + console.log("test"); +} diff --git a/crates/loader_compilation/tests/fixtures/require_named/input.js b/crates/loader_compilation/tests/fixtures/require_named/input.js new file mode 100644 index 0000000..9368250 --- /dev/null +++ b/crates/loader_compilation/tests/fixtures/require_named/input.js @@ -0,0 +1,5 @@ +const { isWeb: web } = require("@uni/env"); + +if (web) { + console.log("test"); +} \ No newline at end of file diff --git a/crates/loader_compilation/tests/fixtures/require_named/output.js b/crates/loader_compilation/tests/fixtures/require_named/output.js new file mode 100644 index 0000000..1ac586d --- /dev/null +++ b/crates/loader_compilation/tests/fixtures/require_named/output.js @@ -0,0 +1,4 @@ +var web = import.meta.renderer === "client" && import.meta.target === "web"; +if (web) { + console.log("test"); +} diff --git a/crates/loader_compilation/tests/fixtures/require_rest/input.js b/crates/loader_compilation/tests/fixtures/require_rest/input.js new file mode 100644 index 0000000..3c9be22 --- /dev/null +++ b/crates/loader_compilation/tests/fixtures/require_rest/input.js @@ -0,0 +1,5 @@ +const { isNode, ...rest } = require("@uni/env"); + +if (rest.isWeb || isNode) { + console.log("test"); +} \ No newline at end of file diff --git a/crates/loader_compilation/tests/fixtures/require_rest/output.js b/crates/loader_compilation/tests/fixtures/require_rest/output.js new file mode 100644 index 0000000..262d928 --- /dev/null +++ b/crates/loader_compilation/tests/fixtures/require_rest/output.js @@ -0,0 +1,20 @@ +var isNode = import.meta.renderer === "server"; +const rest = { + isWeb: import.meta.renderer === "client" && import.meta.target === "web", + isClient: import.meta.renderer === "client", + isNode: import.meta.renderer === "server", + isWeex: import.meta.renderer === "client" && import.meta.target === "weex", + isKraken: import.meta.renderer === "client" && import.meta.target === "kraken", + isMiniApp: false, + isByteDanceMicroApp: false, + isBaiduSmartProgram: false, + isKuaiShouMiniProgram: false, + isWeChatMiniProgram: false, + isQuickApp: false, + isPHA: import.meta.renderer === "client" && import.meta.target === "web" && typeof pha === "object", + isWindVane: import.meta.renderer === "client" && /.+AliApp\((\w+)\/((?:\d+\.)+\d+)\).* .*(WindVane)(?:\/((?:\d+\.)+\d+))?.*/.test(typeof navigator ? navigator.userAgent || navigator.swuserAgent : "") && typeof WindVane !== "undefined" && typeof WindVane.call !== "undefined", + isFRM: false +}; +if (rest.isWeb || isNode) { + console.log("test"); +} diff --git a/crates/loader_compilation/tests/fixtures/require_scoped/input.js b/crates/loader_compilation/tests/fixtures/require_scoped/input.js new file mode 100644 index 0000000..369dd9c --- /dev/null +++ b/crates/loader_compilation/tests/fixtures/require_scoped/input.js @@ -0,0 +1,8 @@ +const { isNode } = require("@uni/env"); +function check() { + const { isWeb } = require("@uni/env"); + if (isWeb) { + const { isServer, isClient } = require("@uni/env"); + console.log("test"); + } +} \ No newline at end of file diff --git a/crates/loader_compilation/tests/fixtures/require_scoped/output.js b/crates/loader_compilation/tests/fixtures/require_scoped/output.js new file mode 100644 index 0000000..84f6294 --- /dev/null +++ b/crates/loader_compilation/tests/fixtures/require_scoped/output.js @@ -0,0 +1,9 @@ +var isNode = import.meta.renderer === "server"; +function check() { + var isWeb = import.meta.renderer === "client" && import.meta.target === "web"; + if (isWeb) { + var isServer = import.meta.renderer === "server"; + var isClient = import.meta.renderer === "client"; + console.log("test"); + } +} From b6147aff73be0ad4fd4dc21eca712a84fbb18b32 Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Tue, 5 Dec 2023 13:47:13 +0800 Subject: [PATCH 22/32] 0.0.1 --- crates/loader_compilation/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/loader_compilation/src/lib.rs b/crates/loader_compilation/src/lib.rs index 197808d..5bfb2dc 100644 --- a/crates/loader_compilation/src/lib.rs +++ b/crates/loader_compilation/src/lib.rs @@ -168,7 +168,6 @@ impl Loader for CompilationLoader { if routes_content.is_ok() { *routes_config = Some(routes_content?); } - if file_accessed { // If file accessed, then we need to clear the map for the current compilation. file_access.clear(); From 39b423dd06650dee35cbf50f700f7db0fe834d17 Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Tue, 5 Dec 2023 14:59:46 +0800 Subject: [PATCH 23/32] 0.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 07d88ed..1178313 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ice-monorepo", - "version": "0.0.0", + "version": "0.0.1", "type": "module", "homepage": "https://ice.work", "bugs": "https://github.com/alibaba/ice/issues", From 00ca196e98d508f1027a2d43573fe6a9722b75d3 Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Tue, 5 Dec 2023 15:55:42 +0800 Subject: [PATCH 24/32] 0.0.1 --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 93c30d9..d6f6e23 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -43,7 +43,7 @@ jobs: set -e && cd crates/node_binding && unset CC_x86_64_unknown_linux_gnu && unset CC && - pnpm build --target x86_64-unknown-linux-gnu && + npm run build -- --target x86_64-unknown-linux-gnu && strip *.node - host: ubuntu-latest name: linux-x64-musl From 397d0cf529d9cd905418898aa0f43dd1043581e8 Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Tue, 5 Dec 2023 16:30:05 +0800 Subject: [PATCH 25/32] 0.0.2 --- crates/node_binding/package.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/node_binding/package.json b/crates/node_binding/package.json index dc696ea..8b03518 100644 --- a/crates/node_binding/package.json +++ b/crates/node_binding/package.json @@ -1,6 +1,6 @@ { "name": "@ice/pack-binding", - "version": "0.0.1", + "version": "0.0.2", "main": "index.js", "types": "index.d.ts", "napi": { @@ -14,6 +14,10 @@ ] } }, + "files": [ + "index.js", + "index.d.ts" + ], "license": "MIT", "devDependencies": { "@napi-rs/cli": "^2.16.4" From c199a56249fabbe0a3c7b44d5f5acba5fbc0ee36 Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Fri, 8 Dec 2023 18:07:01 +0800 Subject: [PATCH 26/32] chore: add readme --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..abeb95b --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +

A bundler based on Rspack

+ +This project is under active development. It is based on Rspack, and it will add more built-in features required by ice framework. + +## Credits + +Thanks to the [rspack](https://github.com/web-infra-dev/rspack) project which provides the ability to customize plugins and loaders implemented by Rust. From d87e3e2cd0e3f4f4b92f61a37f3ac59bca45fef1 Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Mon, 11 Dec 2023 14:09:04 +0800 Subject: [PATCH 27/32] fix: add built loader of react refresh (#23) --- Cargo.lock | 5 +---- crates/binding_options/Cargo.toml | 6 +----- crates/binding_options/src/options/raw_module.rs | 7 +++++++ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ba40dc5..4201b56 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -284,18 +284,15 @@ dependencies = [ "napi", "napi-derive", "plugin_manifest", - "rspack_binding_macros", "rspack_binding_options", - "rspack_binding_values", "rspack_core", "rspack_error", "rspack_hash", - "rspack_identifier", "rspack_ids", + "rspack_loader_react_refresh", "rspack_loader_runner", "rspack_loader_sass", "rspack_loader_swc", - "rspack_napi_shared", "rspack_plugin_asset", "rspack_plugin_banner", "rspack_plugin_copy", diff --git a/crates/binding_options/Cargo.toml b/crates/binding_options/Cargo.toml index 5163393..d6e3f65 100644 --- a/crates/binding_options/Cargo.toml +++ b/crates/binding_options/Cargo.toml @@ -4,17 +4,13 @@ version = "0.1.0" 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_runner = { path = "../.rspack_crates/rspack_loader_runner" } rspack_loader_sass = { path = "../.rspack_crates/rspack_loader_sass" } rspack_loader_swc = { path = "../.rspack_crates/rspack_loader_swc" } -rspack_napi_shared = { path = "../.rspack_crates/rspack_napi_shared" } rspack_plugin_asset = { path = "../.rspack_crates/rspack_plugin_asset" } rspack_plugin_banner = { path = "../.rspack_crates/rspack_plugin_banner" } rspack_plugin_copy = { path = "../.rspack_crates/rspack_plugin_copy" } @@ -43,12 +39,12 @@ rspack_plugin_warn_sensitive_module = { path = "../.rspack_crates/rspack_plu rspack_plugin_wasm = { path = "../.rspack_crates/rspack_plugin_wasm" } rspack_plugin_web_worker_template = { path = "../.rspack_crates/rspack_plugin_web_worker_template" } rspack_plugin_worker = { path = "../.rspack_crates/rspack_plugin_worker" } +rspack_loader_react_refresh = { path = "../.rspack_crates/rspack_loader_react_refresh" } rspack_regex = { path = "../.rspack_crates/rspack_regex" } rspack_hash = { path = "../.rspack_crates/rspack_hash" } rspack_swc_visitors = { path = "../.rspack_crates/rspack_swc_visitors" } loader_compilation = { path = "../loader_compilation" } plugin_manifest = { path = "../plugin_manifest" } -## plugin_specilize_module_name = { path = "../plugin_specilize_module_name" } futures-util = { workspace = true } anyhow = { workspace = true, features = ["backtrace"] } diff --git a/crates/binding_options/src/options/raw_module.rs b/crates/binding_options/src/options/raw_module.rs index b8010cd..a917bf6 100644 --- a/crates/binding_options/src/options/raw_module.rs +++ b/crates/binding_options/src/options/raw_module.rs @@ -2,6 +2,7 @@ use std::sync::Arc; use rspack_core::BoxLoader; use rspack_loader_sass::SASS_LOADER_IDENTIFIER; use rspack_loader_swc::SWC_LOADER_IDENTIFIER; +use rspack_loader_react_refresh::REACT_REFRESH_LOADER_IDENTIFIER; use loader_compilation::COMPILATION_LOADER_IDENTIFIER; pub fn get_builtin_loader(builtin: &str, options: Option<&str>) -> BoxLoader { @@ -24,6 +25,12 @@ pub fn get_builtin_loader(builtin: &str, options: Option<&str>) -> BoxLoader { ); } + 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( loader_compilation::CompilationLoader::new( From 13ef2f292629f589e94b536d6785f2787badf729 Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Mon, 11 Dec 2023 14:09:19 +0800 Subject: [PATCH 28/32] fix: add assets info (#22) --- crates/plugin_manifest/src/plugin.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/crates/plugin_manifest/src/plugin.rs b/crates/plugin_manifest/src/plugin.rs index c2e6cab..99d79b9 100644 --- a/crates/plugin_manifest/src/plugin.rs +++ b/crates/plugin_manifest/src/plugin.rs @@ -17,6 +17,7 @@ pub struct ManifestPlugin; pub struct AssetsManifest { pub pages: HashMap>, pub entries: HashMap>, + pub assets: HashMap, pub public_path: String, } @@ -47,11 +48,20 @@ impl Plugin for ManifestPlugin { let mut assets_mainfest = AssetsManifest { pages: HashMap::new(), entries: HashMap::new(), + assets: HashMap::new(), public_path: public_path.to_string(), }; let entry_points = &compilation.entrypoints; let assets = &compilation.assets(); + assets.into_iter().for_each(|(_, asset)| { + let version = &asset.info.version; + let source_file = &asset.info.source_filename; + if let Some(name) = source_file { + assets_mainfest.assets.insert(name.to_string(), version.to_string()); + } + }); + entry_points.iter().for_each(|(name, _entry)| { let mut files: Vec = Vec::new(); compilation.entrypoint_by_name(name).chunks.iter().for_each(|chunk| { From d8a1c3e44b7c9beeb7d7dd2d36975694aaf562df Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Mon, 11 Dec 2023 14:09:33 +0800 Subject: [PATCH 29/32] refactor: swc transformers (#24) --- Cargo.lock | 29 ++++++++++++++++++- Cargo.toml | 3 ++ crates/loader_compilation/Cargo.toml | 4 ++- crates/loader_compilation/src/lib.rs | 1 - .../src/{transform/mod.rs => transform.rs} | 11 ++----- crates/swc_env_replacement/Cargo.toml | 11 +++++++ crates/swc_env_replacement/src/lib.rs | 3 ++ .../src/transform.rs} | 0 crates/swc_keep_export/Cargo.toml | 13 +++++++++ crates/swc_keep_export/src/lib.rs | 2 ++ .../src/transform.rs} | 15 +++++----- crates/swc_remove_export/Cargo.toml | 13 +++++++++ crates/swc_remove_export/src/lib.rs | 2 ++ .../src/transform.rs} | 0 14 files changed, 89 insertions(+), 18 deletions(-) rename crates/loader_compilation/src/{transform/mod.rs => transform.rs} (95%) create mode 100644 crates/swc_env_replacement/Cargo.toml create mode 100644 crates/swc_env_replacement/src/lib.rs rename crates/{loader_compilation/src/transform/env_replacement.rs => swc_env_replacement/src/transform.rs} (100%) create mode 100644 crates/swc_keep_export/Cargo.toml create mode 100644 crates/swc_keep_export/src/lib.rs rename crates/{loader_compilation/src/transform/keep_export.rs => swc_keep_export/src/transform.rs} (99%) create mode 100644 crates/swc_remove_export/Cargo.toml create mode 100644 crates/swc_remove_export/src/lib.rs rename crates/{loader_compilation/src/transform/remove_export.rs => swc_remove_export/src/transform.rs} (100%) diff --git a/Cargo.lock b/Cargo.lock index 4201b56..4d8b8cf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1470,7 +1470,6 @@ dependencies = [ "async-trait", "dashmap", "either", - "fxhash", "indexmap 1.9.3", "lazy_static", "once_cell", @@ -1487,6 +1486,9 @@ dependencies = [ "swc_config", "swc_core", "swc_emotion", + "swc_env_replacement", + "swc_keep_export", + "swc_remove_export", "tokio", "xxhash-rust", ] @@ -4948,6 +4950,13 @@ dependencies = [ "tracing", ] +[[package]] +name = "swc_env_replacement" +version = "0.1.0" +dependencies = [ + "swc_core", +] + [[package]] name = "swc_eq_ignore_macros" version = "0.1.2" @@ -5094,6 +5103,15 @@ dependencies = [ "swc_visit", ] +[[package]] +name = "swc_keep_export" +version = "0.1.0" +dependencies = [ + "fxhash", + "rspack_error", + "swc_core", +] + [[package]] name = "swc_macros_common" version = "0.3.8" @@ -5125,6 +5143,15 @@ dependencies = [ "swc_core", ] +[[package]] +name = "swc_remove_export" +version = "0.1.0" +dependencies = [ + "fxhash", + "rspack_error", + "swc_core", +] + [[package]] name = "swc_timer" version = "0.21.4" diff --git a/Cargo.toml b/Cargo.toml index 8aec9ce..254e03c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,9 @@ members = [ "crates/node_binding", "crates/loader_compilation", "crates/plugin_manifest", + "crates/swc_env_replacement", + "crates/swc_keep_export", + "crates/swc_remove_export", "crates/plugin_specilize_module_name" ] resolver = "2" diff --git a/crates/loader_compilation/Cargo.toml b/crates/loader_compilation/Cargo.toml index 46e8ced..a992597 100644 --- a/crates/loader_compilation/Cargo.toml +++ b/crates/loader_compilation/Cargo.toml @@ -10,7 +10,6 @@ anyhow = { workspace = true } async-trait = { workspace = true } dashmap = { workspace = true } either = "1" -fxhash = "0.2.1" lazy_static = "1.4.0" once_cell = { workspace = true } rspack_ast = { path = "../.rspack_crates/rspack_ast" } @@ -30,6 +29,9 @@ swc_core = { workspace = true, features = [ ] } swc_emotion = { workspace = true } xxhash-rust = { workspace = true, features = ["xxh32"] } +swc_env_replacement = { path = "../swc_env_replacement" } +swc_keep_export = { path = "../swc_keep_export" } +swc_remove_export = { path = "../swc_remove_export" } [dev-dependencies] indexmap = { workspace = true } diff --git a/crates/loader_compilation/src/lib.rs b/crates/loader_compilation/src/lib.rs index 5bfb2dc..ebf46bd 100644 --- a/crates/loader_compilation/src/lib.rs +++ b/crates/loader_compilation/src/lib.rs @@ -1,4 +1,3 @@ -#![feature(box_patterns)] use std::{path::Path, collections::HashMap, sync::Mutex}; use lazy_static::lazy_static; use rspack_ast::RspackAst; diff --git a/crates/loader_compilation/src/transform/mod.rs b/crates/loader_compilation/src/transform.rs similarity index 95% rename from crates/loader_compilation/src/transform/mod.rs rename to crates/loader_compilation/src/transform.rs index 34a69d4..384802d 100644 --- a/crates/loader_compilation/src/transform/mod.rs +++ b/crates/loader_compilation/src/transform.rs @@ -6,14 +6,9 @@ use swc_core::common::chain; use swc_core::ecma::{ transforms::base::pass::noop, visit::Fold, }; - -mod keep_export; -mod remove_export; -mod env_replacement; - -use keep_export::keep_export; -use remove_export::remove_export; -use env_replacement::env_replacement; +use swc_keep_export::keep_export; +use swc_remove_export::remove_export; +use swc_env_replacement::env_replacement; macro_rules! either { ($config:expr, $f:expr) => { diff --git a/crates/swc_env_replacement/Cargo.toml b/crates/swc_env_replacement/Cargo.toml new file mode 100644 index 0000000..f74b1c9 --- /dev/null +++ b/crates/swc_env_replacement/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "swc_env_replacement" +version = "0.1.0" +edition = "2021" + +[dependencies] +swc_core = { workspace = true, features = [ + "base", + "ecma_ast", + "common" +] } \ No newline at end of file diff --git a/crates/swc_env_replacement/src/lib.rs b/crates/swc_env_replacement/src/lib.rs new file mode 100644 index 0000000..9ed8f3c --- /dev/null +++ b/crates/swc_env_replacement/src/lib.rs @@ -0,0 +1,3 @@ +#![feature(box_patterns)] +mod transform; +pub use transform::*; diff --git a/crates/loader_compilation/src/transform/env_replacement.rs b/crates/swc_env_replacement/src/transform.rs similarity index 100% rename from crates/loader_compilation/src/transform/env_replacement.rs rename to crates/swc_env_replacement/src/transform.rs diff --git a/crates/swc_keep_export/Cargo.toml b/crates/swc_keep_export/Cargo.toml new file mode 100644 index 0000000..132c42d --- /dev/null +++ b/crates/swc_keep_export/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "swc_keep_export" +version = "0.1.0" +edition = "2021" + +[dependencies] +fxhash = "0.2.1" +swc_core = { workspace = true, features = [ + "base", + "ecma_ast", + "common" +] } +rspack_error = { path = "../.rspack_crates/rspack_error" } \ No newline at end of file diff --git a/crates/swc_keep_export/src/lib.rs b/crates/swc_keep_export/src/lib.rs new file mode 100644 index 0000000..73c6e1d --- /dev/null +++ b/crates/swc_keep_export/src/lib.rs @@ -0,0 +1,2 @@ +mod transform; +pub use transform::*; diff --git a/crates/loader_compilation/src/transform/keep_export.rs b/crates/swc_keep_export/src/transform.rs similarity index 99% rename from crates/loader_compilation/src/transform/keep_export.rs rename to crates/swc_keep_export/src/transform.rs index 1d23124..671f34d 100644 --- a/crates/loader_compilation/src/transform/keep_export.rs +++ b/crates/swc_keep_export/src/transform.rs @@ -2,14 +2,15 @@ // https://github.com/ice-lab/swc-plugins/tree/main/packages/keep-export use fxhash::FxHashSet; use std::mem::take; -use swc_core::ecma::{ - ast::*, - visit::{Fold, FoldWith, noop_fold_type}, -}; -use swc_core::common::{ - DUMMY_SP, pass::{Repeat, Repeated} +use swc_core::{ + common::{ + DUMMY_SP, pass::{Repeat, Repeated} + }, + ecma::{ + ast::*, + visit::{Fold, FoldWith, noop_fold_type} + } }; - /// State of the transforms. Shared by the analyzer and the transform. #[derive(Debug, Default)] struct State { diff --git a/crates/swc_remove_export/Cargo.toml b/crates/swc_remove_export/Cargo.toml new file mode 100644 index 0000000..760535f --- /dev/null +++ b/crates/swc_remove_export/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "swc_remove_export" +version = "0.1.0" +edition = "2021" + +[dependencies] +fxhash = "0.2.1" +swc_core = { workspace = true, features = [ + "base", + "ecma_ast", + "common" +] } +rspack_error = { path = "../.rspack_crates/rspack_error" } \ No newline at end of file diff --git a/crates/swc_remove_export/src/lib.rs b/crates/swc_remove_export/src/lib.rs new file mode 100644 index 0000000..73c6e1d --- /dev/null +++ b/crates/swc_remove_export/src/lib.rs @@ -0,0 +1,2 @@ +mod transform; +pub use transform::*; diff --git a/crates/loader_compilation/src/transform/remove_export.rs b/crates/swc_remove_export/src/transform.rs similarity index 100% rename from crates/loader_compilation/src/transform/remove_export.rs rename to crates/swc_remove_export/src/transform.rs From 9d159c31e06c8e551b69a024ac186108643e7f15 Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Mon, 11 Dec 2023 16:28:01 +0800 Subject: [PATCH 30/32] 0.0.3 --- crates/node_binding/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/node_binding/package.json b/crates/node_binding/package.json index 8b03518..5dfe0e5 100644 --- a/crates/node_binding/package.json +++ b/crates/node_binding/package.json @@ -1,6 +1,6 @@ { "name": "@ice/pack-binding", - "version": "0.0.2", + "version": "0.0.3", "main": "index.js", "types": "index.d.ts", "napi": { From d6efae10fd266a624e1321747f83384ed464a6b3 Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Mon, 25 Dec 2023 11:19:36 +0800 Subject: [PATCH 31/32] Feat: Update to the latest rspack version (#26) * fix: update rspack core version * fix: test case * fix: filename * fix: update js binding --- .github/actions/clone-crates/action.yml | 2 +- Cargo.lock | 840 ++++++++++-------- Cargo.toml | 26 +- .../binding_options/src/options/js_loader.rs | 2 +- crates/binding_options/src/options/mod.rs | 30 +- .../src/options/raw_features.rs | 64 +- .../src/options/raw_optimization.rs | 18 +- crates/loader_compilation/src/compiler.rs | 55 +- crates/loader_compilation/src/lib.rs | 22 +- crates/loader_compilation/tests/fixtures.rs | 2 + crates/node_binding/Cargo.toml | 2 + crates/node_binding/index.d.ts | 126 ++- crates/node_binding/index.js | 10 +- crates/node_binding/src/hook.rs | 4 + crates/node_binding/src/lib.rs | 25 +- crates/node_binding/src/loader.rs | 2 +- crates/node_binding/src/panic.rs | 64 ++ crates/node_binding/src/plugins/mod.rs | 172 ++-- .../tests/fixtures/basic/snapshot/output.snap | 54 +- 19 files changed, 915 insertions(+), 605 deletions(-) create mode 100644 crates/node_binding/src/panic.rs diff --git a/.github/actions/clone-crates/action.yml b/.github/actions/clone-crates/action.yml index c9dc12d..1eba130 100644 --- a/.github/actions/clone-crates/action.yml +++ b/.github/actions/clone-crates/action.yml @@ -12,7 +12,7 @@ inputs: required: false type: string ref: - default: 'v0.4.0' + default: 'v0.4.3' required: false type: string temp: diff --git a/Cargo.lock b/Cargo.lock index 4d8b8cf..1d95c25 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -136,10 +136,10 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "ast_node" -version = "0.9.5" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3e3e06ec6ac7d893a0db7127d91063ad7d9da8988f8a1a256f03729e6eec026" dependencies = [ - "pmutil", "proc-macro2", "quote", "swc_macros_common", @@ -224,12 +224,27 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "backtrace-ext" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "537beee3be4a18fb023b570f80e3ae28003db9167a751266b259926e25539d50" +dependencies = [ + "backtrace", +] + [[package]] name = "base64" version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +[[package]] +name = "base64" +version = "0.21.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" + [[package]] name = "base64-simd" version = "0.8.0" @@ -262,21 +277,13 @@ dependencies = [ "scoped-tls", ] -[[package]] -name = "better_scoped_tls" -version = "0.1.1" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" -dependencies = [ - "scoped-tls", -] - [[package]] name = "binding_options" version = "0.1.0" dependencies = [ "anyhow", "async-trait", - "better_scoped_tls 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "better_scoped_tls", "derivative", "futures-util", "glob", @@ -365,27 +372,23 @@ dependencies = [ [[package]] name = "browserslist-rs" -version = "0.12.4" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9bda9b4595376bf255f68dafb5dcc5b0e2842b38dc2a7b52c4e0bfe9fd1c651" +checksum = "e33066f72a558361eeb1077b0aff0f1dce1ac75bdc20b38a642f155f767b2824" dependencies = [ "ahash 0.8.6", "anyhow", "chrono", "either", - "getrandom", "itertools", - "js-sys", "nom", "once_cell", "quote", "serde", - "serde-wasm-bindgen", "serde_json", "string_cache", "string_cache_codegen", "thiserror", - "wasm-bindgen", ] [[package]] @@ -482,9 +485,7 @@ checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" dependencies = [ "android-tzdata", "iana-time-zone", - "js-sys", "num-traits", - "wasm-bindgen", "windows-targets 0.48.5", ] @@ -499,6 +500,16 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "color-backtrace" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "150fd80a270c0671379f388c8204deb6a746bb4eac8a6c03fe2460b2c0127ea0" +dependencies = [ + "backtrace", + "termcolor", +] + [[package]] name = "colored" version = "2.0.4" @@ -751,15 +762,6 @@ dependencies = [ "uuid", ] -[[package]] -name = "deranged" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f32d04922c60427da6f9fef14d042d9edddef64cb9d4ce0d64d0685fbeb1fd3" -dependencies = [ - "powerfmt", -] - [[package]] name = "derivative" version = "2.2.0" @@ -846,26 +848,6 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" -[[package]] -name = "enum-iterator" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7add3873b5dd076766ee79c8e406ad1a472c385476b9e38849f8eec24f1be689" -dependencies = [ - "enum-iterator-derive", -] - -[[package]] -name = "enum-iterator-derive" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eecf8589574ce9b895052fa12d69af7a233f99e6107f5cb8dd1044f2a17bfdcb" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.39", -] - [[package]] name = "equivalent" version = "1.0.1" @@ -905,10 +887,10 @@ dependencies = [ [[package]] name = "from_variant" -version = "0.1.6" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a0b11eeb173ce52f84ebd943d42e58813a2ebb78a6a3ff0a243b71c5199cd7b" dependencies = [ - "pmutil", "proc-macro2", "swc_macros_common", "syn 2.0.39", @@ -1035,22 +1017,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" dependencies = [ "cfg-if", - "js-sys", "libc", "wasi", - "wasm-bindgen", -] - -[[package]] -name = "getset" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e45727250e75cc04ff2846a66397da8ef2b3db8e40e0cef4df67950a07621eb9" -dependencies = [ - "proc-macro-error", - "proc-macro2", - "quote", - "syn 1.0.109", ] [[package]] @@ -1155,6 +1123,19 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb741d1d6fce95c065abb032a5f302299520a23928a95e96ab64799b5fd97f3a" +[[package]] +name = "hstr" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de90d3db62411eb62eddabe402d706ac4970f7ac8d088c05f11069cad9be9857" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "phf", + "rustc-hash", + "smallvec", +] + [[package]] name = "html-escape" version = "0.2.13" @@ -1217,7 +1198,6 @@ checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", "hashbrown 0.12.3", - "rayon", "serde", ] @@ -1229,6 +1209,7 @@ checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" dependencies = [ "equivalent", "hashbrown 0.14.2", + "rayon", "serde", ] @@ -1559,12 +1540,33 @@ checksum = "1c90329e44f9208b55f45711f9558cec15d7ef8295cc65ecd6d4188ae8edc58c" dependencies = [ "atty", "backtrace", - "miette-derive", + "miette-derive 4.7.1", "once_cell", "owo-colors", - "supports-color", - "supports-hyperlinks", - "supports-unicode", + "supports-color 1.3.1", + "supports-hyperlinks 1.2.0", + "supports-unicode 1.0.2", + "terminal_size", + "textwrap 0.15.2", + "thiserror", + "unicode-width", +] + +[[package]] +name = "miette" +version = "5.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59bb584eaeeab6bd0226ccf3509a69d7936d148cf3d036ad350abe35e8c6856e" +dependencies = [ + "backtrace", + "backtrace-ext", + "is-terminal", + "miette-derive 5.10.0", + "once_cell", + "owo-colors", + "supports-color 2.1.0", + "supports-hyperlinks 2.1.0", + "supports-unicode 2.0.0", "terminal_size", "textwrap 0.15.2", "thiserror", @@ -1582,6 +1584,17 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "miette-derive" +version = "5.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49e7bc1560b95a3c4a25d03de42fe76ca718ab92d1a22a55b9b4cf67b3ae635c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + [[package]] name = "mimalloc-rust" version = "0.2.1" @@ -1706,6 +1719,7 @@ version = "0.0.0" dependencies = [ "async-trait", "binding_options", + "color-backtrace", "dashmap", "futures", "mimalloc-rust", @@ -1731,15 +1745,15 @@ dependencies = [ [[package]] name = "nodejs-resolver" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfd06bcc5adab8de32fbbc8e975b364b537fd91e7ae5dfb9ae88fd15980c334b" +checksum = "517c9a4e74fdd7a26d38b1dca0cfff40af33ee3b1d5f379f7c9d711ba5a5d10d" dependencies = [ "daachorse", "dashmap", "dunce", - "indexmap 1.9.3", - "jsonc-parser 0.21.1", + "indexmap 2.1.0", + "jsonc-parser 0.22.1", "once_cell", "path-absolutize", "rustc-hash", @@ -1836,9 +1850,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.18.0" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "oorandom" @@ -1866,9 +1880,9 @@ checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" [[package]] name = "oxc_resolver" -version = "0.5.4" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d10d078b6ba0b8cfa0eb634ef749698aa82ef4a86c7ba1446453644ccf13fd2" +checksum = "7ac76a705bf7db9d1e43904ed4704039de8fa654b0f613cc729c09bb67fd89f6" dependencies = [ "dashmap", "dunce", @@ -2036,13 +2050,12 @@ dependencies = [ [[package]] name = "phf" -version = "0.10.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" dependencies = [ "phf_macros", - "phf_shared", - "proc-macro-hack", + "phf_shared 0.11.2", ] [[package]] @@ -2051,22 +2064,31 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" dependencies = [ - "phf_shared", + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", "rand", ] [[package]] name = "phf_macros" -version = "0.10.0" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58fdf3184dd560f160dd73922bea2d5cd6e8f064bf4b13110abd81b03697b4e0" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" dependencies = [ - "phf_generator", - "phf_shared", - "proc-macro-hack", + "phf_generator 0.11.2", + "phf_shared 0.11.2", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.39", ] [[package]] @@ -2078,6 +2100,15 @@ dependencies = [ "siphasher", ] +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + [[package]] name = "pin-project" version = "1.1.3" @@ -2180,12 +2211,6 @@ version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3bccab0e7fd7cc19f820a1c8c91720af652d0c88dc9664dd72aef2614f04af3b" -[[package]] -name = "powerfmt" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -2200,8 +2225,9 @@ checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" [[package]] name = "preset_env_base" -version = "0.4.6" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff96707a8ddcf6230b2249554d5dc78bbe93cfe28af5ef880174a0f2e63d0d53" dependencies = [ "ahash 0.8.6", "anyhow", @@ -2239,12 +2265,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "proc-macro-hack" -version = "0.5.20+deprecated" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" - [[package]] name = "proc-macro2" version = "1.0.69" @@ -2532,16 +2552,6 @@ dependencies = [ "xshell", ] -[[package]] -name = "rspack-codespan-reporting" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc53b3a0e58f509a8b55bde278d44c05879f27a66819346e0fef193c6348e9f8" -dependencies = [ - "termcolor", - "unicode-width", -] - [[package]] name = "rspack_ast" version = "0.1.0" @@ -2584,7 +2594,7 @@ version = "0.1.0" dependencies = [ "anyhow", "async-trait", - "better_scoped_tls 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "better_scoped_tls", "derivative", "glob", "napi", @@ -2615,6 +2625,8 @@ dependencies = [ "rspack_plugin_json", "rspack_plugin_library", "rspack_plugin_limit_chunk_count", + "rspack_plugin_merge_duplicate_chunks", + "rspack_plugin_mf", "rspack_plugin_progress", "rspack_plugin_real_content_hash", "rspack_plugin_remove_empty_chunks", @@ -2645,7 +2657,7 @@ version = "0.1.0" dependencies = [ "anyhow", "async-trait", - "better_scoped_tls 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "better_scoped_tls", "dashmap", "derivative", "futures", @@ -2690,6 +2702,7 @@ dependencies = [ "rspack_plugin_worker", "rspack_regex", "rspack_swc_visitors", + "rspack_util", "rustc-hash", "serde", "serde_json", @@ -2770,7 +2783,7 @@ dependencies = [ "anyhow", "futures", "insta", - "rspack-codespan-reporting", + "miette 5.10.0", "rspack_binding_options", "rspack_core", "rspack_fs", @@ -2782,6 +2795,7 @@ dependencies = [ "sugar_path", "swc_core", "termcolor", + "thiserror", "tokio", ] @@ -2938,6 +2952,7 @@ name = "rspack_node" version = "0.1.0" dependencies = [ "async-trait", + "color-backtrace", "dashmap", "futures", "mimalloc-rust", @@ -3112,7 +3127,6 @@ dependencies = [ "rspack_error", "rspack_hash", "rspack_identifier", - "rspack_plugin_runtime", "rustc-hash", "serde_json", ] @@ -3149,9 +3163,11 @@ dependencies = [ "anyhow", "async-recursion", "async-trait", + "bitflags 1.3.2", "either", "indexmap 1.9.3", "linked_hash_set", + "num-bigint", "once_cell", "preset_env_base", "rayon", @@ -3161,6 +3177,7 @@ dependencies = [ "rspack_error", "rspack_hash", "rspack_identifier", + "rspack_ids", "rspack_regex", "rspack_swc_visitors", "rspack_testing", @@ -3191,6 +3208,7 @@ dependencies = [ name = "rspack_plugin_library" version = "0.1.0" dependencies = [ + "async-trait", "once_cell", "regex", "rspack_core", @@ -3209,6 +3227,37 @@ dependencies = [ "rspack_util", ] +[[package]] +name = "rspack_plugin_merge_duplicate_chunks" +version = "0.1.0" +dependencies = [ + "async-trait", + "rspack_core", + "rspack_database", + "rspack_util", + "rustc-hash", +] + +[[package]] +name = "rspack_plugin_mf" +version = "0.1.0" +dependencies = [ + "async-trait", + "hashlink", + "itertools", + "once_cell", + "regex", + "rspack_core", + "rspack_error", + "rspack_hash", + "rspack_identifier", + "rspack_loader_runner", + "rustc-hash", + "serde", + "serde_json", + "tokio", +] + [[package]] name = "rspack_plugin_progress" version = "0.1.0" @@ -3248,9 +3297,11 @@ version = "0.1.0" dependencies = [ "anyhow", "async-trait", + "indexmap 1.9.3", "itertools", "once_cell", "rayon", + "regex", "rspack_core", "rspack_error", "rspack_hash", @@ -3295,10 +3346,13 @@ dependencies = [ "async-trait", "dashmap", "derivative", + "futures", "futures-util", - "num-bigint", + "once_cell", "rayon", + "regex", "rspack_core", + "rspack_hash", "rspack_identifier", "rspack_regex", "rspack_util", @@ -3357,7 +3411,6 @@ dependencies = [ "rspack_core", "rspack_error", "rspack_identifier", - "rspack_plugin_runtime", "rspack_testing", "serde_json", "swc_core", @@ -3377,6 +3430,7 @@ dependencies = [ name = "rspack_plugin_worker" version = "0.1.0" dependencies = [ + "async-trait", "rspack_core", "rspack_plugin_runtime", "rspack_plugin_wasm", @@ -3452,6 +3506,7 @@ dependencies = [ "rspack_plugin_javascript", "rspack_plugin_json", "rspack_plugin_library", + "rspack_plugin_merge_duplicate_chunks", "rspack_plugin_remove_empty_chunks", "rspack_plugin_runtime", "rspack_plugin_warn_sensitive_module", @@ -3633,24 +3688,13 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.192" +version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001" +checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" dependencies = [ "serde_derive", ] -[[package]] -name = "serde-wasm-bindgen" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3b4c031cd0d9014307d82b8abf653c0290fbdaeb4c02d00c63cf52f728628bf" -dependencies = [ - "js-sys", - "serde", - "wasm-bindgen", -] - [[package]] name = "serde_cbor" version = "0.11.2" @@ -3663,9 +3707,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.192" +version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1" +checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" dependencies = [ "proc-macro2", "quote", @@ -3825,12 +3869,6 @@ dependencies = [ "static-map-macro", ] -[[package]] -name = "stable_deref_trait" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" - [[package]] name = "stacker" version = "0.1.15" @@ -3877,7 +3915,7 @@ dependencies = [ "new_debug_unreachable", "once_cell", "parking_lot 0.12.1", - "phf_shared", + "phf_shared 0.10.0", "precomputed-hash", "serde", ] @@ -3888,18 +3926,18 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" dependencies = [ - "phf_generator", - "phf_shared", + "phf_generator 0.10.0", + "phf_shared 0.10.0", "proc-macro2", "quote", ] [[package]] name = "string_enum" -version = "0.4.1" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b650ea2087d32854a0f20b837fc56ec987a1cb4f758c9757e1171ee9812da63" dependencies = [ - "pmutil", "proc-macro2", "quote", "swc_macros_common", @@ -3914,9 +3952,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "styled_components" -version = "0.77.0" +version = "0.90.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2efe2ad3cd5fe8868b2fa9d7b2619110313c19c3c304733651cd90d11b6e201a" +checksum = "ddb45c257489ad9439cd5c9ecc4b17b1b43dde147ec0c857393b10226948364b" dependencies = [ "Inflector", "once_cell", @@ -3958,6 +3996,16 @@ dependencies = [ "is_ci", ] +[[package]] +name = "supports-color" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6398cde53adc3c4557306a96ce67b302968513830a77a95b2b17305d9719a89" +dependencies = [ + "is-terminal", + "is_ci", +] + [[package]] name = "supports-hyperlinks" version = "1.2.0" @@ -3967,6 +4015,15 @@ dependencies = [ "atty", ] +[[package]] +name = "supports-hyperlinks" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f84231692eb0d4d41e4cdd0cabfdd2e6cd9e255e65f80c9aa7c98dd502b4233d" +dependencies = [ + "is-terminal", +] + [[package]] name = "supports-unicode" version = "1.0.2" @@ -3976,13 +4033,23 @@ dependencies = [ "atty", ] +[[package]] +name = "supports-unicode" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b6c2cb240ab5dd21ed4906895ee23fe5a48acdbd15a3ce388e7b62a9b66baf7" +dependencies = [ + "is-terminal", +] + [[package]] name = "swc" -version = "0.269.31" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.269.75" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "603ad8da1ec4affc1564bc88173f8356f8686f84a3975121d662ee1a6d877e9d" dependencies = [ "anyhow", - "base64", + "base64 0.13.1", "dashmap", "either", "indexmap 1.9.3", @@ -4025,21 +4092,21 @@ dependencies = [ [[package]] name = "swc_atoms" -version = "0.6.0" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d538eaaa6f085161d088a04cf0a3a5a52c5a7f2b3bd9b83f73f058b0ed357c0" dependencies = [ + "hstr", "once_cell", "rustc-hash", "serde", - "string_cache", - "string_cache_codegen", - "triomphe", ] [[package]] name = "swc_cached" version = "0.3.18" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b357b80879f6c4f4f34879d02eeae63aafc7730293e6eda3686f990d160486" dependencies = [ "ahash 0.8.6", "anyhow", @@ -4051,13 +4118,14 @@ dependencies = [ [[package]] name = "swc_common" -version = "0.33.2" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.33.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b3ae36feceded27f0178dc9dabb49399830847ffb7f866af01798844de8f973" dependencies = [ "ahash 0.8.6", "ast_node", "atty", - "better_scoped_tls 0.1.1 (git+https://github.com/swc-project/swc.git?rev=1095bff)", + "better_scoped_tls", "cfg-if", "either", "from_variant", @@ -4069,7 +4137,6 @@ dependencies = [ "serde", "siphasher", "sourcemap", - "string_cache", "swc_atoms", "swc_eq_ignore_macros", "swc_visit", @@ -4081,11 +4148,12 @@ dependencies = [ [[package]] name = "swc_compiler_base" -version = "0.3.30" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.3.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2aaeaafb2670ebaf64414e4bccccad495ff0b80f2b47763a7d96fec48bb8773" dependencies = [ "anyhow", - "base64", + "base64 0.21.5", "pathdiff", "serde", "sourcemap", @@ -4103,7 +4171,8 @@ dependencies = [ [[package]] name = "swc_config" version = "0.1.7" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ba1c7a40d38f9dd4e9a046975d3faf95af42937b34b2b963be4d8f01239584b" dependencies = [ "indexmap 1.9.3", "serde", @@ -4113,10 +4182,10 @@ dependencies = [ [[package]] name = "swc_config_macro" -version = "0.1.2" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b2574f75082322a27d990116cd2a24de52945fc94172b24ca0b3e9e2a6ceb6b" dependencies = [ - "pmutil", "proc-macro2", "quote", "swc_macros_common", @@ -4125,8 +4194,9 @@ dependencies = [ [[package]] name = "swc_core" -version = "0.86.33" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.86.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05d7801335fb8d1dcb48009f3e0fd0b7a472760a06931af5b03dca96c3ead3fe" dependencies = [ "swc", "swc_atoms", @@ -4159,8 +4229,9 @@ dependencies = [ [[package]] name = "swc_css_ast" -version = "0.140.3" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.140.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec1b459dc890410ea18225d2879786247f1dbc2ddb95eb92cae9dd83c6193ed5" dependencies = [ "is-macro", "string_enum", @@ -4170,8 +4241,9 @@ dependencies = [ [[package]] name = "swc_css_codegen" -version = "0.151.5" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.151.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e61d619e672f2dc4923593c19fd0545a47c8311008ff5fb60c55134e29e68df" dependencies = [ "auto_impl", "bitflags 2.4.1", @@ -4186,10 +4258,10 @@ dependencies = [ [[package]] name = "swc_css_codegen_macros" -version = "0.2.2" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0db1d634bcd2df2b694e2bf9320b8f808db3451e35d70e36252966b551a11ef4" dependencies = [ - "pmutil", "proc-macro2", "quote", "swc_macros_common", @@ -4198,8 +4270,9 @@ dependencies = [ [[package]] name = "swc_css_compat" -version = "0.27.5" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.27.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "969293b76f5385daca38a08a99ac915de93330717c16ae45163866b8955e0613" dependencies = [ "bitflags 2.4.1", "once_cell", @@ -4214,8 +4287,9 @@ dependencies = [ [[package]] name = "swc_css_minifier" -version = "0.116.5" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.116.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2a8a5b334be14e66a4ccdf98de4cac7065f901390cf5b761a873673ad251898" dependencies = [ "serde", "swc_atoms", @@ -4227,8 +4301,9 @@ dependencies = [ [[package]] name = "swc_css_modules" -version = "0.29.5" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.29.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "430f6bc9fab0dd0e03da05bb338d803664927ae5e5e4775710160f19f1f5566b" dependencies = [ "rustc-hash", "serde", @@ -4242,8 +4317,9 @@ dependencies = [ [[package]] name = "swc_css_parser" -version = "0.150.5" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.150.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c16cff0015ce0c3a8eade2d379b336c1e7205377f40a34f5f38758469c78fd9" dependencies = [ "lexical", "serde", @@ -4254,8 +4330,9 @@ dependencies = [ [[package]] name = "swc_css_prefixer" -version = "0.153.6" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.153.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c34762ca85e7136bfb83036467b91a296818471660da2955e5df0d1de14d3f4" dependencies = [ "once_cell", "preset_env_base", @@ -4270,8 +4347,9 @@ dependencies = [ [[package]] name = "swc_css_utils" -version = "0.137.3" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.137.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6b4b604827b202bcf644ced07ad897ae5cbb5fae62a8a3d154ebca73da06b0f" dependencies = [ "once_cell", "serde", @@ -4284,8 +4362,9 @@ dependencies = [ [[package]] name = "swc_css_visit" -version = "0.139.3" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.139.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "761dc5b0b95b7c950083519dda1f82246566f6682b3b21a009b1e0e20a6d693c" dependencies = [ "serde", "swc_atoms", @@ -4296,12 +4375,14 @@ dependencies = [ [[package]] name = "swc_ecma_ast" -version = "0.110.2" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.110.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2aa3e4c43a071a747bf3e18a5423d47aab54048fdedab550d7f3c662127ba4d8" dependencies = [ "bitflags 2.4.1", "is-macro", "num-bigint", + "phf", "scoped-tls", "serde", "string_enum", @@ -4312,8 +4393,9 @@ dependencies = [ [[package]] name = "swc_ecma_codegen" -version = "0.146.9" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.146.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be75490c5a5cad616587cb8600ce387bb5925c8a9a3e44de674b67bf962fb439" dependencies = [ "memchr", "num-bigint", @@ -4330,10 +4412,10 @@ dependencies = [ [[package]] name = "swc_ecma_codegen_macros" -version = "0.7.3" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "394b8239424b339a12012ceb18726ed0244fce6bf6345053cb9320b2791dcaa5" dependencies = [ - "pmutil", "proc-macro2", "quote", "swc_macros_common", @@ -4342,8 +4424,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_bugfixes" -version = "0.1.17" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.1.53" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b57a4636b9159609557c0e3f23f393a76bcffc21ae0d4926ec9b7188d3cc9f4" dependencies = [ "swc_atoms", "swc_common", @@ -4352,29 +4435,31 @@ dependencies = [ "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)", + "swc_trace_macro", "tracing", ] [[package]] name = "swc_ecma_compat_common" -version = "0.1.11" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904a87fbec2b00a6a9aae8797dcf84bc1400f560d5a55e37e2f6728d7bebf9c3" 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)", + "swc_trace_macro", ] [[package]] name = "swc_ecma_compat_es2015" -version = "0.1.17" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.1.53" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "950a1234f6655b408d0efa6905f1e9beba5ff6835cca8a95c6d2a50714dbf50c" dependencies = [ "arrayvec", - "indexmap 1.9.3", + "indexmap 2.1.0", "is-macro", "serde", "serde_derive", @@ -4389,14 +4474,15 @@ dependencies = [ "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)", + "swc_trace_macro", "tracing", ] [[package]] name = "swc_ecma_compat_es2016" -version = "0.1.15" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40606d660400c9e4e1db343930c0d80601e5dd6c23f90f59879fa5e54ea5dc31" dependencies = [ "swc_atoms", "swc_common", @@ -4405,14 +4491,15 @@ dependencies = [ "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)", + "swc_trace_macro", "tracing", ] [[package]] name = "swc_ecma_compat_es2017" -version = "0.1.15" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.1.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d431aa66fe3d219e141f3103fdc7a3b7503a74cde1091cb42bb402934be6962e" dependencies = [ "serde", "swc_atoms", @@ -4422,14 +4509,15 @@ dependencies = [ "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)", + "swc_trace_macro", "tracing", ] [[package]] name = "swc_ecma_compat_es2018" -version = "0.1.15" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.1.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d22d2edbb19c8b27c0697e049da3102fff58b9f70355f68bbefadd988d7e648b" dependencies = [ "serde", "swc_atoms", @@ -4440,14 +4528,15 @@ dependencies = [ "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)", + "swc_trace_macro", "tracing", ] [[package]] name = "swc_ecma_compat_es2019" -version = "0.1.15" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.1.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879726051286646d4f01851827959c5de8c36fac4dfd3b02d34fdd1911bb0485" dependencies = [ "swc_atoms", "swc_common", @@ -4455,14 +4544,15 @@ dependencies = [ "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)", + "swc_trace_macro", "tracing", ] [[package]] name = "swc_ecma_compat_es2020" -version = "0.1.15" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.1.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4000344bcb4cabe6385b33cf4fa6404e7c4b754d034b172db8c55549d10829e" dependencies = [ "serde", "swc_atoms", @@ -4472,14 +4562,15 @@ dependencies = [ "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)", + "swc_trace_macro", "tracing", ] [[package]] name = "swc_ecma_compat_es2021" -version = "0.1.14" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.1.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "122dd55b3db93601353e0310f1d5018e22d2a3b62bebded5e2d368bcde21178b" dependencies = [ "swc_atoms", "swc_common", @@ -4487,14 +4578,15 @@ dependencies = [ "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)", + "swc_trace_macro", "tracing", ] [[package]] name = "swc_ecma_compat_es2022" -version = "0.1.15" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "569f093b567046d0b51eb7c84b6c3ad4e4572a61d6b3b33d02e286eccffbd8de" dependencies = [ "swc_atoms", "swc_common", @@ -4505,28 +4597,30 @@ dependencies = [ "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)", + "swc_trace_macro", "tracing", ] [[package]] name = "swc_ecma_compat_es3" -version = "0.1.15" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4530662a138b8773fd0234a083eb047eb3760d998efd15d6f46ad1102f4980ac" 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)", + "swc_trace_macro", "tracing", ] [[package]] name = "swc_ecma_ext_transforms" -version = "0.110.13" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.110.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4947357e009d54161e8dbfe77c6360c10c28b8406ece3ba65071eaa33af5f7e6" dependencies = [ "phf", "swc_atoms", @@ -4538,8 +4632,9 @@ dependencies = [ [[package]] name = "swc_ecma_lints" -version = "0.89.16" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.89.51" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b04cba6fbd1f8982fdcf50143efd22a5e49a0f608d29c033c0232f616f3d9108" dependencies = [ "auto_impl", "dashmap", @@ -4557,8 +4652,9 @@ dependencies = [ [[package]] name = "swc_ecma_loader" -version = "0.45.3" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.45.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5713ab3429530c10bdf167170ebbde75b046c8003558459e4de5aaec62ce0f1" dependencies = [ "anyhow", "dashmap", @@ -4577,11 +4673,12 @@ dependencies = [ [[package]] name = "swc_ecma_minifier" -version = "0.189.28" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.189.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebb60ce1eaffdd0a146930b1fdae54ebc4d739b9f6ec34dc6b678a305b78458a" dependencies = [ "arrayvec", - "indexmap 1.9.3", + "indexmap 2.1.0", "num-bigint", "num_cpus", "once_cell", @@ -4611,12 +4708,15 @@ dependencies = [ [[package]] name = "swc_ecma_parser" -version = "0.141.8" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.141.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d643ce57be7c4808cd7a924201aa256188aa2ef9604248cf180c4c3e867b3fd6" dependencies = [ "either", + "new_debug_unreachable", "num-bigint", "num-traits", + "phf", "serde", "smallvec", "smartstring", @@ -4630,12 +4730,13 @@ dependencies = [ [[package]] name = "swc_ecma_preset_env" -version = "0.203.23" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.203.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "594708068d26b364b8aa0af133648f51984d7ad38a8269846dcbbc97c827be06" dependencies = [ "anyhow", "dashmap", - "indexmap 1.9.3", + "indexmap 2.1.0", "once_cell", "preset_env_base", "rustc-hash", @@ -4654,11 +4755,11 @@ dependencies = [ [[package]] name = "swc_ecma_quote_macros" -version = "0.52.8" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.52.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb353504ba4a2b157bb630aeefc49ed73ef20e2bc1bb764ed4f9a25bd9d9971a" dependencies = [ "anyhow", - "pmutil", "proc-macro2", "quote", "swc_atoms", @@ -4671,8 +4772,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms" -version = "0.226.22" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.226.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "878fa83417033ad2de7a48efa4c064e84d385afc4e36b05d0140670a827c5885" dependencies = [ "swc_atoms", "swc_common", @@ -4690,12 +4792,13 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_base" -version = "0.134.16" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.134.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "335963eada3ec4a0385ff259274c9d59ef5554541273715e64e4d69442a4ff77" dependencies = [ - "better_scoped_tls 0.1.1 (git+https://github.com/swc-project/swc.git?rev=1095bff)", + "better_scoped_tls", "bitflags 2.4.1", - "indexmap 1.9.3", + "indexmap 2.1.0", "once_cell", "phf", "rayon", @@ -4713,8 +4816,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_classes" -version = "0.123.16" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.123.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10f69a2b4203e19f28dc65bd6114f6c4bebda18aa2b7a44d04d22996264a5327" dependencies = [ "swc_atoms", "swc_common", @@ -4726,11 +4830,12 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_compat" -version = "0.160.21" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.160.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ce94656bcfe5b7aef6219cdc1ffa41f072b2f521f7d3bc79f8d615a747e3762" dependencies = [ "arrayvec", - "indexmap 1.9.3", + "indexmap 2.1.0", "is-macro", "num-bigint", "serde", @@ -4755,16 +4860,16 @@ dependencies = [ "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)", + "swc_trace_macro", "tracing", ] [[package]] name = "swc_ecma_transforms_macros" -version = "0.5.3" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17e309b88f337da54ef7fe4c5b99c2c522927071f797ee6c9fb8b6bf2d100481" dependencies = [ - "pmutil", "proc-macro2", "quote", "swc_macros_common", @@ -4773,13 +4878,14 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_module" -version = "0.177.23" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.177.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d87f3fa5b146744f9ef335147eea6a0e1ba7ff9ac5ff1ba253e8e84362e481a4" dependencies = [ "Inflector", "anyhow", "bitflags 2.4.1", - "indexmap 1.9.3", + "indexmap 2.1.0", "is-macro", "path-clean 0.1.0", "pathdiff", @@ -4799,11 +4905,12 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_optimization" -version = "0.195.23" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.195.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e33d20e20fcfe375ca464097423721c5012b0a8d3d1064839120db233d13088" dependencies = [ "dashmap", - "indexmap 1.9.3", + "indexmap 2.1.0", "once_cell", "petgraph", "rayon", @@ -4823,8 +4930,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_proposal" -version = "0.168.24" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.168.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab7cbad368d4d4ca0d17ed3a0b151d555d70856e8b794563a594f1a430e3517f" dependencies = [ "either", "rustc-hash", @@ -4842,12 +4950,13 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_react" -version = "0.180.24" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.180.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5cadeb3d6c9c50385df98297177ff62d93e99653a5cf4a7848db34a619df61d" dependencies = [ - "base64", + "base64 0.21.5", "dashmap", - "indexmap 1.9.3", + "indexmap 2.1.0", "once_cell", "serde", "sha-1", @@ -4865,8 +4974,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_typescript" -version = "0.185.22" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.185.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "556067f2ea488c05198c2ad3514664e5b292ad568d50b2c5dd0dcd7a53c4abb8" dependencies = [ "ryu-js", "serde", @@ -4881,10 +4991,11 @@ dependencies = [ [[package]] name = "swc_ecma_usage_analyzer" -version = "0.20.14" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.20.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d26fcd5d3ce1571f695187362a5d92adbd09bb071c122660178ac0205c154ca" dependencies = [ - "indexmap 1.9.3", + "indexmap 2.1.0", "rustc-hash", "swc_atoms", "swc_common", @@ -4897,10 +5008,11 @@ dependencies = [ [[package]] name = "swc_ecma_utils" -version = "0.124.13" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.124.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a7a3f362e035688f7c48eeab4f4a8a477bfa64cf6541de1e3f40de882974feb" dependencies = [ - "indexmap 1.9.3", + "indexmap 2.1.0", "num_cpus", "once_cell", "rayon", @@ -4915,8 +5027,9 @@ dependencies = [ [[package]] name = "swc_ecma_visit" -version = "0.96.2" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.96.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a823435d7b3d909391499c1d944be52fb9c6c59d6b5020367a511dfa1b1a3ecd" dependencies = [ "num-bigint", "swc_atoms", @@ -4932,7 +5045,7 @@ version = "0.58.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d123bc6ff6aff8724f43542964ee726801fc205137bbf0de7f822a2f8b15f204" dependencies = [ - "base64", + "base64 0.13.1", "byteorder", "fxhash", "once_cell", @@ -4946,7 +5059,7 @@ dependencies = [ "swc_ecma_codegen", "swc_ecma_utils", "swc_ecma_visit", - "swc_trace_macro 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "swc_trace_macro", "tracing", ] @@ -4959,10 +5072,10 @@ dependencies = [ [[package]] name = "swc_eq_ignore_macros" -version = "0.1.2" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "695a1d8b461033d32429b5befbf0ad4d7a2c4d6ba9cd5ba4e0645c615839e8e4" dependencies = [ - "pmutil", "proc-macro2", "quote", "syn 2.0.39", @@ -4970,11 +5083,12 @@ dependencies = [ [[package]] name = "swc_error_reporters" -version = "0.17.2" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.17.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29add35412af288be50e1012bbb825a66871bb2b4d960d1c456917ec3ccea32" dependencies = [ "anyhow", - "miette", + "miette 4.7.1", "once_cell", "parking_lot 0.12.1", "swc_common", @@ -4982,10 +5096,11 @@ dependencies = [ [[package]] name = "swc_fast_graph" -version = "0.21.2" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.21.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acfc056067a0fbfe26a4763c1eb246e813fdbe6b376415d07915e96e15481b6" dependencies = [ - "indexmap 1.9.3", + "indexmap 2.1.0", "petgraph", "rustc-hash", "swc_common", @@ -4994,7 +5109,8 @@ dependencies = [ [[package]] name = "swc_html" version = "0.134.29" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e63e6d015cbf1ca3d389e012fc5760eea3c24cc447d605cd7e8c4853d7637304" dependencies = [ "swc_html_ast", "swc_html_codegen", @@ -5004,8 +5120,9 @@ dependencies = [ [[package]] name = "swc_html_ast" -version = "0.33.2" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.33.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f0686a31d5552ab7f75e7eae284c596c6f715488601989c3691f7817b8d4c8f" dependencies = [ "is-macro", "string_enum", @@ -5015,8 +5132,9 @@ dependencies = [ [[package]] name = "swc_html_codegen" -version = "0.42.4" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.42.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "308557ab26e22fe1eaa252af6924887b06dbd93111332995ffc0a6d53746473b" dependencies = [ "auto_impl", "bitflags 2.4.1", @@ -5030,10 +5148,10 @@ dependencies = [ [[package]] name = "swc_html_codegen_macros" -version = "0.2.2" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41912779c72f8381deb1420ab7dab842fde772aeae06f4f0e4a93bd509d4ecfe" dependencies = [ - "pmutil", "proc-macro2", "quote", "swc_macros_common", @@ -5043,7 +5161,8 @@ dependencies = [ [[package]] name = "swc_html_minifier" version = "0.131.29" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6bb97ae0b52f120318468f86e199b6d51dd532441d50e61077a25343f8706b7" dependencies = [ "once_cell", "serde", @@ -5070,8 +5189,9 @@ dependencies = [ [[package]] name = "swc_html_parser" -version = "0.39.4" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.39.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb27edab80474143ca6a0bfde8a13488e95fedc486cfbcee79080d59fb095dbc" dependencies = [ "swc_atoms", "swc_common", @@ -5081,8 +5201,9 @@ dependencies = [ [[package]] name = "swc_html_utils" -version = "0.18.2" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.18.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bafa26f8a17f398abb71cd7aeeb8e755f8087f276e9594b5120e38e5a596a457" dependencies = [ "once_cell", "serde", @@ -5093,8 +5214,9 @@ dependencies = [ [[package]] name = "swc_html_visit" -version = "0.33.2" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.33.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bccbddc3f97355513c881aed62d209e4f46fc455a36a1485fa41dad0132e8b5" dependencies = [ "serde", "swc_atoms", @@ -5114,10 +5236,10 @@ dependencies = [ [[package]] name = "swc_macros_common" -version = "0.3.8" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50176cfc1cbc8bb22f41c6fe9d1ec53fbe057001219b5954961b8ad0f336fce9" dependencies = [ - "pmutil", "proc-macro2", "quote", "syn 2.0.39", @@ -5125,8 +5247,9 @@ dependencies = [ [[package]] name = "swc_node_comments" -version = "0.20.2" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.20.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282ef548f602694c4eaa36a1d704282fd9713b9725b58bce7fb41630feefc4f7" dependencies = [ "dashmap", "swc_atoms", @@ -5154,8 +5277,9 @@ dependencies = [ [[package]] name = "swc_timer" -version = "0.21.4" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.21.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b37010da5874d241c9e11ef020b8e4473f3af4e5d2e19219e92d99c04f12e0c6" dependencies = [ "tracing", ] @@ -5171,20 +5295,11 @@ dependencies = [ "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", - "syn 2.0.39", -] - [[package]] name = "swc_visit" -version = "0.5.7" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b27078d8571abe23aa52ef608dd1df89096a37d867cf691cbb4f4c392322b7c9" dependencies = [ "either", "swc_visit_macros", @@ -5192,8 +5307,9 @@ dependencies = [ [[package]] name = "swc_visit_macros" -version = "0.5.8" -source = "git+https://github.com/swc-project/swc.git?rev=1095bff#1095bff35a3fe8473e9e5ab32a80461ddcb7fb72" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa8bb05975506741555ea4d10c3a3bdb0e2357cd58e1a4a4332b8ebb4b44c34d" dependencies = [ "Inflector", "pmutil", @@ -5289,18 +5405,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.50" +version = "1.0.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" +checksum = "f11c217e1416d6f036b870f14e0413d480dbf28edbee1f877abaf0206af43bb7" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.50" +version = "1.0.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" +checksum = "01742297787513b79cf8e29d1056ede1313e2420b7b3b15d0a768b4921f549df" dependencies = [ "proc-macro2", "quote", @@ -5337,35 +5453,6 @@ dependencies = [ "tikv-jemalloc-sys", ] -[[package]] -name = "time" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5" -dependencies = [ - "deranged", - "itoa", - "powerfmt", - "serde", - "time-core", - "time-macros", -] - -[[package]] -name = "time-core" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" - -[[package]] -name = "time-macros" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ad70d68dba9e1f8aceda7aa6711965dfec1cac869f311a51bd08b3a2ccbce20" -dependencies = [ - "time-core", -] - [[package]] name = "tinytemplate" version = "1.2.1" @@ -5487,16 +5574,6 @@ dependencies = [ "tracing-log", ] -[[package]] -name = "triomphe" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee8098afad3fb0c54a9007aab6804558410503ad676d4633f9c2559a00ac0f" -dependencies = [ - "serde", - "stable_deref_trait", -] - [[package]] name = "typed-arena" version = "2.0.2" @@ -5620,17 +5697,12 @@ checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" [[package]] name = "vergen" -version = "7.5.1" +version = "8.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f21b881cd6636ece9735721cf03c1fe1e774fe258683d084bb2812ab67435749" +checksum = "1290fd64cc4e7d3c9b07d7f333ce0ce0007253e32870e632624835cc80b83939" dependencies = [ "anyhow", - "cfg-if", - "enum-iterator", - "getset", "rustversion", - "thiserror", - "time", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 254e03c..1072ab8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -65,34 +65,18 @@ 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.77.0" } +styled_components = { version = "0.90.0" } swc_config = { version = "=0.1.7" } -swc_core = { version = "0.86.33", default-features = false } +swc_core = { version = "0.86.82", default-features = false } swc_css = { version = "0.157.6" } -swc_ecma_minifier = { version = "0.189.28", default-features = false } +swc_ecma_minifier = { version = "0.189.73", default-features = false } swc_emotion = { version = "=0.58.0" } -swc_error_reporters = { version = "=0.17.2" } +swc_error_reporters = { version = "=0.17.9" } swc_html = { version = "=0.134.29" } swc_html_minifier = { version = "=0.131.29" } -swc_node_comments = { version = "=0.20.2" } +swc_node_comments = { version = "=0.20.9" } 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 = "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] codegen-units = 16 # debug build will cause runtime panic if codegen-unints is default debug = 2 diff --git a/crates/binding_options/src/options/js_loader.rs b/crates/binding_options/src/options/js_loader.rs index ae36171..41079b3 100644 --- a/crates/binding_options/src/options/js_loader.rs +++ b/crates/binding_options/src/options/js_loader.rs @@ -94,5 +94,5 @@ pub async fn run_builtin_loader( cx.__loader_index = 0; } - JsLoaderContext::try_from(&cx).map_err(|e| Error::from_reason(e.to_string())) + JsLoaderContext::try_from(&mut cx).map_err(|e| Error::from_reason(e.to_string())) } \ No newline at end of file diff --git a/crates/binding_options/src/options/mod.rs b/crates/binding_options/src/options/mod.rs index b7b24d4..c4e21ad 100644 --- a/crates/binding_options/src/options/mod.rs +++ b/crates/binding_options/src/options/mod.rs @@ -1,10 +1,12 @@ use napi_derive::napi; use rspack_core::{ BoxPlugin, CompilerOptions, Context, DevServerOptions, Devtool, Experiments, IncrementalRebuild, - IncrementalRebuildMakeState, ModuleOptions, ModuleType, OutputOptions, PluginExt, Optimization, + IncrementalRebuildMakeState, MangleExportsOption, ModuleOptions, ModuleType, OutputOptions, + PluginExt, TreeShaking, Optimization, }; use rspack_plugin_javascript::{ - FlagDependencyExportsPlugin, FlagDependencyUsagePlugin, SideEffectsFlagPlugin, + FlagDependencyExportsPlugin, FlagDependencyUsagePlugin, MangleExportsPlugin, + SideEffectsFlagPlugin, }; use serde::Deserialize; @@ -119,11 +121,6 @@ impl RawOptionsApply for RSPackRawOptions { if experiments.async_web_assembly { plugins.push(rspack_plugin_wasm::AsyncWasmPlugin::new().boxed()); } - rspack_plugin_worker::worker_plugin( - output.worker_chunk_loading.clone(), - output.worker_wasm_loading.clone(), - plugins, - ); plugins.push(rspack_plugin_javascript::JsPlugin::new().boxed()); plugins.push(rspack_plugin_javascript::InferAsyncModulesPlugin {}.boxed()); @@ -141,8 +138,6 @@ 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()); @@ -154,6 +149,16 @@ impl RawOptionsApply for RSPackRawOptions { plugins.push(FlagDependencyUsagePlugin::default().boxed()); } } + if optimization.mangle_exports.is_enable() { + // We already know mangle_exports != false + plugins.push( + MangleExportsPlugin::new(!matches!( + optimization.mangle_exports, + MangleExportsOption::Size + )) + .boxed(), + ); + } // Notice the plugin need to be placed after SplitChunksPlugin if optimization.remove_empty_chunks { @@ -163,9 +168,12 @@ impl RawOptionsApply for RSPackRawOptions { plugins.push(rspack_plugin_ensure_chunk_conditions::EnsureChunkConditionsPlugin.boxed()); plugins.push(rspack_plugin_warn_sensitive_module::WarnCaseSensitiveModulesPlugin.boxed()); - // Add custom plugins. plugins.push(plugin_manifest::ManifestPlugin::new().boxed()); + let mut builtins = self.builtins.apply(plugins)?; + if experiments.rspack_future.new_treeshaking { + builtins.tree_shaking = TreeShaking::False; + } Ok(Self::Options { context, @@ -184,7 +192,7 @@ impl RawOptionsApply for RSPackRawOptions { node, dev_server, profile: self.profile, - builtins: self.builtins.apply(plugins)?, + builtins, }) } } diff --git a/crates/binding_options/src/options/raw_features.rs b/crates/binding_options/src/options/raw_features.rs index f3b8fb3..c57735d 100644 --- a/crates/binding_options/src/options/raw_features.rs +++ b/crates/binding_options/src/options/raw_features.rs @@ -1,10 +1,9 @@ use std::{sync::Arc, hash::Hasher}; -use futures_util::{FutureExt, future}; use napi_derive::napi; use serde::Deserialize; use rspack_core::{ Optimization, PluginExt, SideEffectOption, UsedExportsOption, SourceType, - BoxPlugin, Module, ModuleType, + BoxPlugin, Module, ModuleType, MangleExportsOption, Filename, }; use rspack_error::internal_error; use rspack_ids::{ @@ -12,9 +11,10 @@ use rspack_ids::{ NamedModuleIdsPlugin, }; use crate::RspackRawOptimizationOptions; -use rspack_plugin_split_chunks_new::{PluginOptions, CacheGroup}; +use rspack_plugin_split_chunks_new::{PluginOptions, CacheGroup, CacheGroupTest, CacheGroupTestFnCtx, ChunkNameGetter}; use rspack_regex::RspackRegex; use rspack_hash::{RspackHash, HashFunction, HashDigest}; +use rspack_binding_options::RawSplitChunksOptions; pub struct SplitChunksStrategy { strategy: RawStrategyOptions, @@ -28,6 +28,8 @@ pub struct SplitChunksStrategy { remove_empty_chunks: bool, remove_available_modules: bool, inner_graph: bool, + mangle_exports: String, + split_chunks: Option } fn get_modules_size(module: &dyn Module) -> f64 { @@ -38,7 +40,7 @@ fn get_modules_size(module: &dyn Module) -> f64 { size } -fn get_plugin_options(strategy: RawStrategyOptions, context: String) -> rspack_plugin_split_chunks_new::PluginOptions { +fn get_plugin_options(strategy: RawStrategyOptions, split_chunks: Option, context: String) -> rspack_plugin_split_chunks_new::PluginOptions { use rspack_plugin_split_chunks_new::SplitChunkSizes; let default_size_types = [SourceType::JavaScript, SourceType::Unknown]; let create_sizes = |size: Option| { @@ -48,20 +50,21 @@ fn get_plugin_options(strategy: RawStrategyOptions, context: String) -> rspack_p }; let re_node_modules = RspackRegex::new("node_modules").unwrap(); - let cache_groups = vec![ CacheGroup { key: String::from("framework"), - name: rspack_plugin_split_chunks_new::create_chunk_name_getter_by_const_name("framework".to_string()), + name: ChunkNameGetter::String("framework".to_string()), chunk_filter: rspack_plugin_split_chunks_new::create_all_chunk_filter(), priority: 40.0, - test: Arc::new(move |module: &dyn Module| -> bool { - module - .name_for_condition() - .map_or(false, |name| { - strategy.top_level_frameworks.iter().any(|framework| name.starts_with(framework)) - }) - }), + test: CacheGroupTest::Fn(Arc::new(move |ctx: CacheGroupTestFnCtx| -> Option { + Some( + ctx.module + .name_for_condition() + .map_or(false, |name| { + strategy.top_level_frameworks.iter().any(|framework| name.starts_with(framework)) + }) + ) + })), max_initial_requests: 25, max_async_requests: 25, reuse_existing_chunk: true, @@ -72,30 +75,34 @@ fn get_plugin_options(strategy: RawStrategyOptions, context: String) -> rspack_p max_initial_size: SplitChunkSizes::empty(), id_hint: String::from("framework"), r#type: rspack_plugin_split_chunks_new::create_default_module_type_filter(), + automatic_name_delimiter: String::from("-"), + filename: Some(Filename::from(String::from("framework.js"))), }, CacheGroup { key: String::from("lib"), - name: Arc::new(move |module| { + name: ChunkNameGetter::Fn(Arc::new(move |ctx| { let mut hash = RspackHash::new(&HashFunction::Xxhash64); - match module.module_type() { + match ctx.module.module_type() { ModuleType::Css | ModuleType::CssModule | ModuleType::CssAuto => { - module.update_hash(&mut hash); + ctx.module.update_hash(&mut hash); }, _ => { let options = rspack_core::LibIdentOptions { context: &context }; - let lib_ident = module.lib_ident(options); + let lib_ident = ctx.module.lib_ident(options); hash.write(lib_ident.unwrap().as_bytes()); }, } - future::ready(Some(hash.digest(&HashDigest::Hex).rendered(8).to_string())).boxed() - }), + Some(hash.digest(&HashDigest::Hex).rendered(8).to_string()) + })), chunk_filter: rspack_plugin_split_chunks_new::create_all_chunk_filter(), - test: Arc::new(move |module: &dyn Module| -> bool { - module - .name_for_condition() + test: CacheGroupTest::Fn(Arc::new(move |ctx| { + Some( + ctx.module + .name_for_condition() .map_or(false, |name| re_node_modules.test(&name)) - && get_modules_size(module) > 160000.0 - }), + && get_modules_size(ctx.module) > 160000.0 + ) + })), priority: 30.0, min_chunks: 1, reuse_existing_chunk: true, @@ -106,6 +113,8 @@ fn get_plugin_options(strategy: RawStrategyOptions, context: String) -> rspack_p max_initial_size: SplitChunkSizes::default(), id_hint: String::from("lib"), r#type: rspack_plugin_split_chunks_new::create_default_module_type_filter(), + automatic_name_delimiter: String::from("-"), + filename: Some(Filename::from(String::from("lib-[name].js"))), }, ]; @@ -116,7 +125,9 @@ fn get_plugin_options(strategy: RawStrategyOptions, context: String) -> rspack_p min_size: SplitChunkSizes::default(), max_async_size: SplitChunkSizes::default(), max_initial_size: SplitChunkSizes::default(), + automatic_name_delimiter: String::from("-"), }, + hide_path_info: Some(true), } } @@ -139,6 +150,8 @@ impl SplitChunksStrategy { provided_exports: option.provided_exports, real_content_hash: option.real_content_hash, inner_graph: option.inner_graph, + mangle_exports: option.mangle_exports, + split_chunks: option.split_chunks, } } } @@ -148,7 +161,7 @@ impl FeatureApply for SplitChunksStrategy { fn apply(self, plugins: &mut Vec>, context: String) -> Result { let split_chunks_plugin = rspack_plugin_split_chunks_new::SplitChunksPlugin::new( - get_plugin_options(self.strategy, context), + get_plugin_options(self.strategy, self.split_chunks, context), ).boxed(); plugins.push(split_chunks_plugin); @@ -182,6 +195,7 @@ impl FeatureApply for SplitChunksStrategy { provided_exports: self.provided_exports, used_exports: UsedExportsOption::from(self.used_exports.as_str()), inner_graph: self.inner_graph, + mangle_exports: MangleExportsOption::from(self.mangle_exports.as_str()), }) } } diff --git a/crates/binding_options/src/options/raw_optimization.rs b/crates/binding_options/src/options/raw_optimization.rs index 2090002..8943f4d 100644 --- a/crates/binding_options/src/options/raw_optimization.rs +++ b/crates/binding_options/src/options/raw_optimization.rs @@ -1,12 +1,13 @@ use better_scoped_tls::scoped_tls; use napi_derive::napi; -use rspack_core::{Optimization, PluginExt, SideEffectOption, UsedExportsOption}; +use rspack_core::{ + MangleExportsOption, 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}; @@ -27,6 +28,7 @@ pub struct RspackRawOptimizationOptions { pub provided_exports: bool, pub inner_graph: bool, pub real_content_hash: bool, + pub mangle_exports: String, } impl RawOptionsApply for RspackRawOptimizationOptions { @@ -36,17 +38,6 @@ impl RawOptionsApply for RspackRawOptimizationOptions { 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(), @@ -77,6 +68,7 @@ impl RawOptionsApply for RspackRawOptimizationOptions { provided_exports: self.provided_exports, used_exports: UsedExportsOption::from(self.used_exports.as_str()), inner_graph: self.inner_graph, + mangle_exports: MangleExportsOption::from(self.mangle_exports.as_str()), }) } } diff --git a/crates/loader_compilation/src/compiler.rs b/crates/loader_compilation/src/compiler.rs index 040d40a..4ef3d7f 100644 --- a/crates/loader_compilation/src/compiler.rs +++ b/crates/loader_compilation/src/compiler.rs @@ -1,22 +1,37 @@ +/** + * Some code is modified based on + * https://github.com/swc-project/swc/blob/5dacaa174baaf6bf40594d79d14884c8c2fc0de2/crates/swc/src/lib.rs + * Apache-2.0 licensed + * Author Donny/강동윤 + * Copyright (c) + */ use std::env; use std::{path::PathBuf, sync::Arc}; + use anyhow::{Context, Error}; use dashmap::DashMap; use rspack_ast::javascript::{Ast as JsAst, Context as JsAstContext, Program as JsProgram}; -use swc_core:: { - base::{ - config::{Options, JsMinifyCommentOption, BuiltInput, IsModule}, - try_with_handler, SwcComments - }, - common::{ - Globals, SourceFile, SourceMap, GLOBALS, Mark, FileName, FilePathMapping, BytePos, - comments::{SingleThreadedComments, Comments, Comment, CommentKind}, - errors::{Handler, HANDLER}, - }, - ecma::{transforms::base::helpers::{self, Helpers}, ast::{Program, EsVersion}, visit::{Fold, FoldWith}, - parser::{parse_file_as_module, Syntax, parse_file_as_script, parse_file_as_program}}, -}; use swc_config::config_types::BoolOr; +use swc_core::base::config::{ + BuiltInput, IsModule, JsMinifyCommentOption, +}; +use swc_core::base::SwcComments; +use swc_core::common::comments::{Comment, CommentKind, Comments}; +use swc_core::common::errors::{Handler, HANDLER}; +use swc_core::common::{ + comments::SingleThreadedComments, FileName, FilePathMapping, Mark, SourceMap, GLOBALS, +}; +use swc_core::common::{BytePos, SourceFile}; +use swc_core::ecma::ast::{EsVersion, Program}; +use swc_core::ecma::parser::{ + parse_file_as_module, parse_file_as_program, parse_file_as_script, Syntax, +}; +use swc_core::ecma::transforms::base::helpers::{self, Helpers}; +use swc_core::ecma::visit::{Fold, FoldWith}; +use swc_core::{ + base::{config::Options, try_with_handler}, + common::Globals, +}; fn minify_file_comments( comments: &SingleThreadedComments, @@ -72,14 +87,14 @@ impl SwcCompiler { options.top_level_mark = Some(top_level_mark); options.unresolved_mark = Some(unresolved_mark); }); - // TODO: support read config of .swcrc. + let fm = cm.new_source_file(FileName::Real(resource_path), source); let comments = SingleThreadedComments::default(); let helpers = GLOBALS.set(&globals, || { let external_helpers = options.config.jsc.external_helpers; Helpers::new(external_helpers.into()) }); - + Ok(Self { cm, fm, @@ -104,8 +119,8 @@ impl SwcCompiler { comments: Option<&dyn Comments>, ) -> Result { let mut error = false; - let mut errors = vec![]; + let mut errors = vec![]; let program_result = match is_module { IsModule::Bool(true) => { parse_file_as_module(&fm, syntax, target, comments, &mut errors).map(Program::Module) @@ -127,7 +142,7 @@ impl SwcCompiler { }); if error { - return Err(anyhow::anyhow!("Syntax Error")); + return Err(anyhow::anyhow!("Syntax Error")); } if env::var("SWC_DEBUG").unwrap_or_default() == "1" { @@ -243,8 +258,8 @@ impl IntoSwcComments for SingleThreadedComments { (l.take(), t.take()) }; SwcComments { - leading: Arc::new(DashMap::from_iter(l.into_iter())), - trailing: Arc::new(DashMap::from_iter(t.into_iter())), + leading: Arc::new(DashMap::from_iter(l)), + trailing: Arc::new(DashMap::from_iter(t)), } } -} \ No newline at end of file +} diff --git a/crates/loader_compilation/src/lib.rs b/crates/loader_compilation/src/lib.rs index ebf46bd..e920fe6 100644 --- a/crates/loader_compilation/src/lib.rs +++ b/crates/loader_compilation/src/lib.rs @@ -3,9 +3,7 @@ use lazy_static::lazy_static; use rspack_ast::RspackAst; use rspack_core::{rspack_sources::SourceMap, LoaderRunnerContext, Mode}; use rspack_loader_runner::{Identifiable, Identifier, Loader, LoaderContext}; -use rspack_error::{ - internal_error, Result, Diagnostic, -}; +use rspack_error::{internal_error, AnyhowError, Diagnostic, Result}; use swc_core::{ base::config::{InputSourceMap, Options, OutputCharset, Config, TransformConfig}, ecma::parser::{Syntax, TsConfig}, @@ -135,8 +133,6 @@ impl Loader for CompilationLoader { loader_context.emit_diagnostic(Diagnostic::warn( COMPILATION_LOADER_IDENTIFIER.to_string(), "Experimental plugins are not currently supported.".to_string(), - 0, - 0, )); } @@ -144,15 +140,13 @@ impl Loader for CompilationLoader { loader_context.emit_diagnostic(Diagnostic::warn( COMPILATION_LOADER_IDENTIFIER.to_string(), "`env` and `jsc.target` cannot be used together".to_string(), - 0, - 0, )); } swc_options }; let devtool = &loader_context.context.options.devtool; let source = content.try_into_string()?; - let compiler = SwcCompiler::new(resource_path.clone(), source.clone(), swc_options)?; + let compiler = SwcCompiler::new(resource_path.clone(), source.clone(), swc_options).map_err(AnyhowError::from)?; let transform_options = &self.loader_options.transform_features; let compiler_context:&str = loader_context.context.options.context.as_ref(); @@ -165,7 +159,7 @@ impl Loader for CompilationLoader { let routes_config_path: std::path::PathBuf = Path::new(compiler_context).join(".ice/route-manifest.json"); let routes_content = load_routes_config(&routes_config_path); if routes_content.is_ok() { - *routes_config = Some(routes_content?); + *routes_config = Some(routes_content.map_err(AnyhowError::from)?); } if file_accessed { // If file accessed, then we need to clear the map for the current compilation. @@ -180,7 +174,7 @@ impl Loader for CompilationLoader { routes_config.as_ref(), transform_options ) - })?; + }).map_err(AnyhowError::from)?; let codegen_options = ast::CodegenOptions { target: Some(built.target), @@ -196,9 +190,10 @@ impl Loader for CompilationLoader { emit_columns: !devtool.cheap(), names: Default::default(), }, + inline_script: Some(false), keep_comments: Some(true), }; - let program = compiler.transform(built)?; + let program = compiler.transform(built).map_err(AnyhowError::from)?; let ast = compiler.into_js_ast(program); // If swc-loader is the latest loader available, @@ -218,7 +213,10 @@ impl Loader for CompilationLoader { } else { let TransformOutput { code, map } = ast::stringify(&ast, codegen_options)?; loader_context.content = Some(code.into()); - loader_context.source_map = map.map(|m| SourceMap::from_json(&m)).transpose()?; + loader_context.source_map = map + .map(|m| SourceMap::from_json(&m)) + .transpose() + .map_err(|e| internal_error!(e.to_string()))?; } Ok(()) diff --git a/crates/loader_compilation/tests/fixtures.rs b/crates/loader_compilation/tests/fixtures.rs index 23ea4b3..adf060d 100644 --- a/crates/loader_compilation/tests/fixtures.rs +++ b/crates/loader_compilation/tests/fixtures.rs @@ -70,6 +70,7 @@ async fn loader_test(actual: impl AsRef, expected: impl AsRef) { ), worker_wasm_loading: rspack_core::WasmLoading::Disable, worker_public_path: String::new(), + script_type: String::from("false"), }, target: rspack_core::Target::new(&vec![String::from("web")]).expect("TODO:"), resolve: rspack_core::Resolve::default(), @@ -88,6 +89,7 @@ async fn loader_test(actual: impl AsRef, expected: impl AsRef) { provided_exports: Default::default(), used_exports: Default::default(), inner_graph: Default::default(), + mangle_exports: Default::default(), }, profile: false, }), diff --git a/crates/node_binding/Cargo.toml b/crates/node_binding/Cargo.toml index c3edc02..06b95bc 100644 --- a/crates/node_binding/Cargo.toml +++ b/crates/node_binding/Cargo.toml @@ -30,6 +30,8 @@ napi = { workspace = true } napi-derive = { workspace = true } napi-sys = { workspace = true } +color-backtrace = "0.6" + [target.'cfg(not(target_os = "linux"))'.dependencies] mimalloc-rust = { workspace = true } diff --git a/crates/node_binding/index.d.ts b/crates/node_binding/index.d.ts index f6e6922..8be0a79 100644 --- a/crates/node_binding/index.d.ts +++ b/crates/node_binding/index.d.ts @@ -48,16 +48,10 @@ export interface JsAssetInfo { development: boolean /** when asset ships data for updating an existing application (HMR) */ hotModuleReplacement: boolean - /** - * when asset is javascript and an ESM - * related object to other assets, keyed by type of relation (only points from parent to child) - */ + /** when asset is javascript and an ESM */ + javascriptModule?: boolean + /** related object to other assets, keyed by type of relation (only points from parent to child) */ 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 - */ - version: string } export interface JsAsset { name: string @@ -71,6 +65,7 @@ export interface JsAssetEmittedArgs { } export interface JsChunk { __inner_ukey: number + __inner_groups: Array name?: string id?: string ids: Array @@ -85,15 +80,32 @@ export interface JsChunk { chunkReasons: Array auxiliaryFiles: Array } -export function __chunk_inner_is_only_initial(jsChunk: JsChunk, compilation: JsCompilation): boolean -export function __chunk_inner_can_be_initial(jsChunk: JsChunk, compilation: JsCompilation): boolean -export function __chunk_inner_has_runtime(jsChunk: JsChunk, compilation: JsCompilation): boolean +export function __chunk_inner_is_only_initial(jsChunkUkey: number, compilation: JsCompilation): boolean +export function __chunk_inner_can_be_initial(jsChunkUkey: number, compilation: JsCompilation): boolean +export function __chunk_inner_has_runtime(jsChunkUkey: number, compilation: JsCompilation): boolean +export function __chunk_inner_get_all_async_chunks(jsChunkUkey: number, compilation: JsCompilation): Array +export function __chunk_inner_get_all_initial_chunks(jsChunkUkey: number, compilation: JsCompilation): Array +export function __chunk_inner_get_all_referenced_chunks(jsChunkUkey: number, compilation: JsCompilation): Array export interface JsChunkAssetArgs { chunk: JsChunk filename: string } +export function __chunk_graph_inner_get_chunk_modules(jsChunkUkey: number, compilation: JsCompilation): Array +export function __chunk_graph_inner_get_chunk_entry_modules(jsChunkUkey: number, compilation: JsCompilation): Array +export function __chunk_graph_inner_get_chunk_entry_dependent_chunks_iterable(jsChunkUkey: number, compilation: JsCompilation): Array +export function __chunk_graph_inner_get_chunk_modules_iterable_by_source_type(jsChunkUkey: number, sourceType: string, compilation: JsCompilation): Array export interface JsChunkGroup { + __inner_parents: Array chunks: Array + index?: number + name?: string +} +export function __chunk_group_inner_get_chunk_group(ukey: number, compilation: JsCompilation): JsChunkGroup +export interface JsCodegenerationResults { + map: Record> +} +export interface JsCodegenerationResult { + sources: Record } export interface JsHooks { processAssetsStageAdditional: (...args: any[]) => any @@ -116,11 +128,12 @@ export interface JsHooks { thisCompilation: (...args: any[]) => any emit: (...args: any[]) => any assetEmitted: (...args: any[]) => any + shouldEmit: (...args: any[]) => any afterEmit: (...args: any[]) => any make: (...args: any[]) => any optimizeModules: (...args: any[]) => any optimizeTree: (...args: any[]) => any - optimizeChunkModule: (...args: any[]) => any + optimizeChunkModules: (...args: any[]) => any beforeCompile: (...args: any[]) => any afterCompile: (...args: any[]) => any finishModules: (...args: any[]) => any @@ -133,11 +146,19 @@ export interface JsHooks { chunkAsset: (...args: any[]) => any succeedModule: (...args: any[]) => any stillValidModule: (...args: any[]) => any + executeModule: (...args: any[]) => any } export interface JsModule { + context?: string originalSource?: JsCompatSource resource?: string moduleIdentifier: string + nameForCondition?: string +} +export interface JsExecuteModuleArg { + entry: string + runtimeModules: Array + codegenResults: JsCodegenerationResults } export interface JsResolveForSchemeInput { resourceData: JsResourceData @@ -195,7 +216,6 @@ export interface JsCompatSource { export interface JsStatsError { message: string formatted: string - title: string } export interface JsStatsWarning { message: string @@ -365,6 +385,48 @@ export interface RawLimitChunkCountPluginOptions { entryChunkMultiplicator?: number maxChunks: number } +export interface RawContainerPluginOptions { + name: string + shareScope: string + library: RawLibraryOptions + runtime?: string + filename?: string + exposes: Array +} +export interface RawExposeOptions { + key: string + name?: string + import: Array +} +export interface RawContainerReferencePluginOptions { + remoteType: string + remotes: Array + shareScope?: string +} +export interface RawRemoteOptions { + key: string + external: Array + shareScope: string +} +export interface RawProvideOptions { + key: string + shareKey: string + shareScope: string + version?: string | false | undefined + eager: boolean +} +export interface RawConsumeOptions { + key: string + import?: string + importResolved?: string + shareKey: string + shareScope: string + requiredVersion?: string | false | undefined + packageName?: string + strictVersion: boolean + singleton: boolean + eager: boolean +} export interface RawProgressPluginOptions { prefix: string profile: boolean @@ -374,6 +436,7 @@ export interface RawSwcJsMinimizerRspackPluginOptions { compress: boolean | string mangle: boolean | string format: string + module?: boolean test?: string | RegExp | (string | RegExp)[] include?: string | RegExp | (string | RegExp)[] exclude?: string | RegExp | (string | RegExp)[] @@ -456,7 +519,16 @@ export const enum BuiltinPluginName { ModuleChunkFormatPlugin = 'ModuleChunkFormatPlugin', HotModuleReplacementPlugin = 'HotModuleReplacementPlugin', LimitChunkCountPlugin = 'LimitChunkCountPlugin', + WorkerPlugin = 'WorkerPlugin', WebWorkerTemplatePlugin = 'WebWorkerTemplatePlugin', + MergeDuplicateChunksPlugin = 'MergeDuplicateChunksPlugin', + SplitChunksPlugin = 'SplitChunksPlugin', + OldSplitChunksPlugin = 'OldSplitChunksPlugin', + ContainerPlugin = 'ContainerPlugin', + ContainerReferencePlugin = 'ContainerReferencePlugin', + ModuleFederationRuntimePlugin = 'ModuleFederationRuntimePlugin', + ProvideSharedPlugin = 'ProvideSharedPlugin', + ConsumeSharedPlugin = 'ConsumeSharedPlugin', HttpExternalsRspackPlugin = 'HttpExternalsRspackPlugin', CopyRspackPlugin = 'CopyRspackPlugin', HtmlRspackPlugin = 'HtmlRspackPlugin', @@ -598,10 +670,14 @@ export interface RawModuleRuleUses { arrayUse?: Array funcUse?: (...args: any[]) => any } +export interface RawRegexMatcher { + source: string + flags: string +} export interface RawRuleSetCondition { type: "string" | "regexp" | "logical" | "array" | "function" stringMatcher?: string - regexpMatcher?: string + regexpMatcher?: RawRegexMatcher logicalMatcher?: Array arrayMatcher?: Array funcMatcher?: (value: string) => boolean @@ -715,6 +791,7 @@ export interface RawOptimizationOptions { providedExports: boolean innerGraph: boolean realContentHash: boolean + mangleExports: string } export interface RawTrustedTypes { policyName?: string @@ -786,6 +863,7 @@ export interface RawOutputOptions { workerChunkLoading: string workerWasmLoading: string workerPublicPath: string + scriptType: "module" | "text/javascript" | "false" } export interface RawResolveTsconfigOptions { configFile: string @@ -817,15 +895,23 @@ export interface RawSnapshotOptions { resolve: RawSnapshotStrategy module: RawSnapshotStrategy } +export interface RawCacheGroupTestCtx { + module: JsModule +} +export interface RawChunkOptionNameCtx { + module: JsModule +} export interface RawSplitChunksOptions { fallbackCacheGroup?: RawFallbackCacheGroupOptions - name?: string + name?: string | false | Function cacheGroups?: Array /** What kind of chunks should be selected. */ chunks?: RegExp | 'async' | 'initial' | 'all' + automaticNameDelimiter?: string maxAsyncRequests?: number maxInitialRequests?: number minChunks?: number + hidePathInfo?: boolean minSize?: number enforceSizeThreshold?: number minRemainingSize?: number @@ -836,17 +922,19 @@ export interface RawSplitChunksOptions { export interface RawCacheGroupOptions { key: string priority?: number - test?: RegExp | string + test?: RegExp | string | Function + filename?: string idHint?: string /** What kind of chunks should be selected. */ chunks?: RegExp | 'async' | 'initial' | 'all' type?: RegExp | string + automaticNameDelimiter?: string minChunks?: number minSize?: number maxSize?: number maxAsyncSize?: number maxInitialSize?: number - name?: string + name?: string | false | Function reuseExistingChunk?: boolean enforce?: boolean } @@ -856,6 +944,7 @@ export interface RawFallbackCacheGroupOptions { maxSize?: number maxAsyncSize?: number maxInitialSize?: number + automaticNameDelimiter?: string } export interface RawStatsOptions { colors: boolean @@ -897,6 +986,7 @@ export interface RspackRawOptimizationOptions { providedExports: boolean innerGraph: boolean realContentHash: boolean + mangleExports: string } export interface RsPackRawOptions { mode?: undefined | 'production' | 'development' | 'none' diff --git a/crates/node_binding/index.js b/crates/node_binding/index.js index a5eee77..65024f8 100644 --- a/crates/node_binding/index.js +++ b/crates/node_binding/index.js @@ -252,11 +252,19 @@ if (!nativeBinding) { throw new Error(`Failed to load native binding`) } -const { __chunk_inner_is_only_initial, __chunk_inner_can_be_initial, __chunk_inner_has_runtime, JsCompilation, JsStats, BuiltinPluginName, runBuiltinLoader, Rspack, registerGlobalTrace, cleanupGlobalTrace } = nativeBinding +const { __chunk_inner_is_only_initial, __chunk_inner_can_be_initial, __chunk_inner_has_runtime, __chunk_inner_get_all_async_chunks, __chunk_inner_get_all_initial_chunks, __chunk_inner_get_all_referenced_chunks, __chunk_graph_inner_get_chunk_modules, __chunk_graph_inner_get_chunk_entry_modules, __chunk_graph_inner_get_chunk_entry_dependent_chunks_iterable, __chunk_graph_inner_get_chunk_modules_iterable_by_source_type, __chunk_group_inner_get_chunk_group, JsCompilation, JsStats, BuiltinPluginName, runBuiltinLoader, Rspack, registerGlobalTrace, cleanupGlobalTrace } = nativeBinding module.exports.__chunk_inner_is_only_initial = __chunk_inner_is_only_initial module.exports.__chunk_inner_can_be_initial = __chunk_inner_can_be_initial module.exports.__chunk_inner_has_runtime = __chunk_inner_has_runtime +module.exports.__chunk_inner_get_all_async_chunks = __chunk_inner_get_all_async_chunks +module.exports.__chunk_inner_get_all_initial_chunks = __chunk_inner_get_all_initial_chunks +module.exports.__chunk_inner_get_all_referenced_chunks = __chunk_inner_get_all_referenced_chunks +module.exports.__chunk_graph_inner_get_chunk_modules = __chunk_graph_inner_get_chunk_modules +module.exports.__chunk_graph_inner_get_chunk_entry_modules = __chunk_graph_inner_get_chunk_entry_modules +module.exports.__chunk_graph_inner_get_chunk_entry_dependent_chunks_iterable = __chunk_graph_inner_get_chunk_entry_dependent_chunks_iterable +module.exports.__chunk_graph_inner_get_chunk_modules_iterable_by_source_type = __chunk_graph_inner_get_chunk_modules_iterable_by_source_type +module.exports.__chunk_group_inner_get_chunk_group = __chunk_group_inner_get_chunk_group module.exports.JsCompilation = JsCompilation module.exports.JsStats = JsStats module.exports.BuiltinPluginName = BuiltinPluginName diff --git a/crates/node_binding/src/hook.rs b/crates/node_binding/src/hook.rs index 38c5649..167ee40 100644 --- a/crates/node_binding/src/hook.rs +++ b/crates/node_binding/src/hook.rs @@ -26,6 +26,7 @@ pub enum Hook { ProcessAssetsStageReport, Emit, AssetEmitted, + ShouldEmit, AfterEmit, OptimizeChunkModules, BeforeCompile, @@ -40,6 +41,7 @@ pub enum Hook { BeforeResolve, SucceedModule, StillValidModule, + ExecuteModule, } impl From for Hook { @@ -68,6 +70,7 @@ impl From for Hook { "processAssetsStageReport" => Hook::ProcessAssetsStageReport, "emit" => Hook::Emit, "assetEmitted" => Hook::AssetEmitted, + "shouldEmit" => Hook::ShouldEmit, "afterEmit" => Hook::AfterEmit, "optimizeChunkModules" => Hook::OptimizeChunkModules, "beforeCompile" => Hook::BeforeCompile, @@ -81,6 +84,7 @@ impl From for Hook { "beforeResolve" => Hook::BeforeResolve, "succeedModule" => Hook::SucceedModule, "stillValidModule" => Hook::StillValidModule, + "executeModule" => Hook::ExecuteModule, hook_name => panic!("{hook_name} is an invalid hook name"), } } diff --git a/crates/node_binding/src/lib.rs b/crates/node_binding/src/lib.rs index c6be2e5..5319ab4 100644 --- a/crates/node_binding/src/lib.rs +++ b/crates/node_binding/src/lib.rs @@ -16,10 +16,10 @@ 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 loader; +mod panic; mod plugins; use hook::*; @@ -29,7 +29,9 @@ use loader::run_builtin_loader; use plugins::*; use rspack_binding_options::*; use rspack_binding_values::*; +use rspack_napi_shared::set_napi_env; use rspack_tracing::chrome::FlushGuard; + #[cfg(not(target_os = "linux"))] #[global_allocator] static GLOBAL: mimalloc_rust::GlobalMiMalloc = mimalloc_rust::GlobalMiMalloc; @@ -104,7 +106,6 @@ impl Rspack { #[allow(clippy::unwrap_in_result, clippy::unwrap_used)] #[napi( - catch_unwind, js_name = "unsafe_set_disabled_hooks", ts_args_type = "hooks: Array" )] @@ -119,7 +120,6 @@ impl Rspack { /// Warning: /// Calling this method recursively might cause a deadlock. #[napi( - catch_unwind, js_name = "unsafe_build", ts_args_type = "callback: (err: null | Error) => void" )] @@ -146,7 +146,6 @@ impl Rspack { /// Warning: /// Calling this method recursively will cause a deadlock. #[napi( - catch_unwind, js_name = "unsafe_rebuild", ts_args_type = "changed_files: string[], removed_files: string[], callback: (err: null | Error) => void" )] @@ -188,7 +187,7 @@ impl Rspack { /// Calling this method under the build or rebuild method might cause a deadlock. /// /// **Note** that this method is not safe if you cache the _JsCompilation_ on the Node side, as it will be invalidated by the next build and accessing a dangling ptr is a UB. - #[napi(catch_unwind, js_name = "unsafe_last_compilation")] + #[napi(js_name = "unsafe_last_compilation")] pub fn unsafe_last_compilation Result<()>>(&self, f: F) -> Result<()> { let handle_last_compilation = |compiler: &mut Pin>>| { // Safety: compiler is stored in a global hashmap, and compilation is only available in the callback of this function, so it is safe to cast to a static lifetime. See more in the warning part of this method. @@ -208,7 +207,7 @@ impl Rspack { /// Warning: /// /// Anything related to this compiler will be invalidated after this method is called. - #[napi(catch_unwind, js_name = "unsafe_drop")] + #[napi(js_name = "unsafe_drop")] pub fn drop(&self) -> Result<()> { unsafe { COMPILERS.remove(&self.id) }; @@ -225,7 +224,7 @@ impl ObjectFinalize for Rspack { impl Rspack { fn prepare_environment(env: &Env) { - NAPI_ENV.with(|napi_env| *napi_env.borrow_mut() = Some(env.raw())); + set_napi_env(env.raw()); } } @@ -236,8 +235,12 @@ enum TraceState { Off, } -static GLOBAL_TRACE_STATE: Lazy> = - Lazy::new(|| Mutex::new(TraceState::default())); +#[ctor] +fn init() { + panic::install_panic_handler(); +} + +static GLOBAL_TRACE_STATE: Mutex = Mutex::new(TraceState::Off); /** * Some code is modified based on @@ -246,7 +249,7 @@ static GLOBAL_TRACE_STATE: Lazy> = * Author Donny/강동윤 * Copyright (c) */ -#[napi(catch_unwind)] +#[napi] pub fn register_global_trace( filter: String, #[napi(ts_arg_type = "\"chrome\" | \"logger\"")] layer: String, @@ -269,7 +272,7 @@ pub fn register_global_trace( } } -#[napi(catch_unwind)] +#[napi] pub fn cleanup_global_trace() { let mut state = GLOBAL_TRACE_STATE .lock() diff --git a/crates/node_binding/src/loader.rs b/crates/node_binding/src/loader.rs index cc28833..f610069 100644 --- a/crates/node_binding/src/loader.rs +++ b/crates/node_binding/src/loader.rs @@ -2,7 +2,7 @@ use napi::Result; use rspack_binding_options::JsLoaderContext; /// Builtin loader runner -#[napi(catch_unwind)] +#[napi] #[allow(unused)] pub async fn run_builtin_loader( builtin: String, diff --git a/crates/node_binding/src/panic.rs b/crates/node_binding/src/panic.rs new file mode 100644 index 0000000..f748060 --- /dev/null +++ b/crates/node_binding/src/panic.rs @@ -0,0 +1,64 @@ +use color_backtrace::{default_output_stream, BacktracePrinter}; + +pub fn install_panic_handler() { + let panic_handler = BacktracePrinter::default() + .message("Panic occurred at runtime. Please file an issue on GitHub with the backtrace below: https://github.com/web-infra-dev/rspack/issues") + .add_frame_filter(Box::new(|frames| { + static NAME_PREFIXES: &[&str] = &[ + "rust_panic", + "rayon", + "rust_begin_unwind", + "start_thread", + "__clone", + "call_once", + "catch_unwind", + "tokio", + ", pub emit_tsfn: ThreadsafeFunction<(), ()>, pub asset_emitted_tsfn: ThreadsafeFunction, + pub should_emit_tsfn: ThreadsafeFunction>, pub after_emit_tsfn: ThreadsafeFunction<(), ()>, pub optimize_modules_tsfn: ThreadsafeFunction, pub optimize_tree_tsfn: ThreadsafeFunction<(), ()>, @@ -61,6 +60,7 @@ pub struct JsHooksAdapter { ThreadsafeFunction, pub succeed_module_tsfn: ThreadsafeFunction, pub still_valid_module_tsfn: ThreadsafeFunction, + pub execute_module_tsfn: ThreadsafeFunction>, } impl Debug for JsHooksAdapter { @@ -78,6 +78,7 @@ impl rspack_core::Plugin for JsHooksAdapter { async fn compilation( &self, args: rspack_core::CompilationArgs<'_>, + _params: &rspack_core::CompilationParams, ) -> rspack_core::PluginCompilationHookOutput { if self.is_hook_disabled(&Hook::Compilation) { return Ok(()); @@ -94,12 +95,13 @@ impl rspack_core::Plugin for JsHooksAdapter { .call(compilation, ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call compilation: {err}"))? + .unwrap_or_else(|err| panic!("Failed to call compilation: {err}")) } async fn this_compilation( &self, args: rspack_core::ThisCompilationArgs<'_>, + _params: &rspack_core::CompilationParams, ) -> rspack_core::PluginThisCompilationHookOutput { if self.is_hook_disabled(&Hook::ThisCompilation) { return Ok(()); @@ -116,7 +118,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call(compilation, ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call this_compilation: {err}"))? + .unwrap_or_else(|err| panic!("Failed to call this_compilation: {err}")) } async fn chunk_asset(&self, args: &ChunkAssetArgs) -> rspack_error::Result<()> { @@ -132,7 +134,7 @@ impl rspack_core::Plugin for JsHooksAdapter { ) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to chunk asset: {err}"))? + .unwrap_or_else(|err| panic!("Failed to chunk asset: {err}")) } #[tracing::instrument(name = "js_hooks_adapter::make", skip_all)] @@ -152,7 +154,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call make: {err}",))? + .unwrap_or_else(|err| panic!("Failed to call make: {err}")) } async fn before_resolve( @@ -168,7 +170,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call(args.clone().into(), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call this_compilation: {err}"))? + .unwrap_or_else(|err| panic!("Failed to call this_compilation: {err}")) { Ok((ret, resolve_data)) => { args.request = resolve_data.request; @@ -192,7 +194,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call(args.clone().into(), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call this_compilation: {err}"))? + .unwrap_or_else(|err| panic!("Failed to call this_compilation: {err}")) } async fn context_module_before_resolve( &self, @@ -204,7 +206,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call(args.clone().into(), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call this_compilation: {err}"))? + .unwrap_or_else(|err| panic!("Failed to call this_compilation: {err}")) } async fn normal_module_factory_resolve_for_scheme( &self, @@ -219,7 +221,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call(args.into(), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call this_compilation: {err}"))?; + .unwrap_or_else(|err| panic!("Failed to call this_compilation: {err}")); res.map(|res| { let JsResolveForSchemeResult { resource_data, @@ -248,7 +250,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call process assets stage additional: {err}",))? + .unwrap_or_else(|err| panic!("Failed to call process assets stage additional: {err}")) } async fn process_assets_stage_pre_process( @@ -265,7 +267,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call process assets stage pre-process: {err}",))? + .unwrap_or_else(|err| panic!("Failed to call process assets stage pre-process: {err}")) } async fn process_assets_stage_derived( @@ -282,7 +284,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call process assets stage derived: {err}",))? + .unwrap_or_else(|err| panic!("Failed to call process assets stage derived: {err}")) } async fn process_assets_stage_additions( @@ -299,7 +301,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call process assets stage additions: {err}",))? + .unwrap_or_else(|err| panic!("Failed to call process assets stage additions: {err}")) } async fn process_assets_stage_none( @@ -316,7 +318,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call process assets: {err}",))? + .unwrap_or_else(|err| panic!("Failed to call process assets: {err}")) } async fn process_assets_stage_optimize( @@ -333,7 +335,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call process assets stage optimize: {err}",))? + .unwrap_or_else(|err| panic!("Failed to call process assets stage optimize: {err}")) } async fn process_assets_stage_optimize_count( @@ -350,9 +352,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err( - |err| internal_error!("Failed to call process assets stage optimize count: {err}",), - )? + .unwrap_or_else(|err| panic!("Failed to call process assets stage optimize count: {err}")) } async fn process_assets_stage_optimize_compatibility( @@ -369,9 +369,9 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| { - internal_error!("Failed to call process assets stage optimize compatibility: {err}",) - })? + .unwrap_or_else(|err| { + panic!("Failed to call process assets stage optimize compatibility: {err}") + }) } async fn process_assets_stage_optimize_size( @@ -388,7 +388,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call process assets stage optimize size: {err}",))? + .unwrap_or_else(|err| panic!("Failed to call process assets stage optimize size: {err}")) } async fn process_assets_stage_dev_tooling( @@ -405,7 +405,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call process assets stage dev tooling: {err}",))? + .unwrap_or_else(|err| panic!("Failed to call process assets stage dev tooling: {err}")) } async fn process_assets_stage_optimize_inline( @@ -422,9 +422,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| { - internal_error!("Failed to call process assets stage optimize inline: {err}",) - })? + .unwrap_or_else(|err| panic!("Failed to call process assets stage optimize inline: {err}")) } async fn process_assets_stage_summarize( @@ -442,7 +440,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call process assets stage summarize: {err}",))? + .unwrap_or_else(|err| panic!("Failed to call process assets stage summarize: {err}")) } async fn process_assets_stage_optimize_hash( @@ -459,7 +457,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call process assets stage summarize: {err}",))? + .unwrap_or_else(|err| panic!("Failed to call process assets stage summarize: {err}")) } async fn process_assets_stage_optimize_transfer( @@ -476,9 +474,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| { - internal_error!("Failed to call process assets stage optimize transfer: {err}",) - })? + .unwrap_or_else(|err| panic!("Failed to call process assets stage optimize transfer: {err}")) } async fn process_assets_stage_analyse( @@ -495,7 +491,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call process assets stage analyse: {err}",))? + .unwrap_or_else(|err| panic!("Failed to call process assets stage analyse: {err}")) } async fn process_assets_stage_report( @@ -512,7 +508,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call process assets stage report: {err}",))? + .unwrap_or_else(|err| panic!("Failed to call process assets stage report: {err}")) } async fn optimize_modules( @@ -532,7 +528,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call(compilation, ThreadsafeFunctionCallMode::Blocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call optimize modules: {err}"))? + .unwrap_or_else(|err| panic!("Failed to call optimize modules: {err}")) } async fn optimize_tree( @@ -547,7 +543,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call optimize tree: {err}",))? + .unwrap_or_else(|err| panic!("Failed to call optimize tree: {err}")) } async fn optimize_chunk_modules( @@ -569,12 +565,12 @@ impl rspack_core::Plugin for JsHooksAdapter { .call(compilation, ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to compilation: {err}"))? + .unwrap_or_else(|err| panic!("Failed to compilation: {err}")) } async fn before_compile( &self, - // args: &mut rspack_core::CompilationArgs<'_> + _params: &rspack_core::CompilationParams, ) -> rspack_error::Result<()> { if self.is_hook_disabled(&Hook::BeforeCompile) { return Ok(()); @@ -585,7 +581,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call({}, ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call before compile: {err}",))? + .unwrap_or_else(|err| panic!("Failed to call before compile: {err}")) } async fn after_compile( @@ -607,7 +603,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call(compilation, ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call after compile: {err}"))? + .unwrap_or_else(|err| panic!("Failed to call after compile: {err}")) } async fn finish_make( @@ -629,7 +625,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call(compilation, ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call finish make: {err}"))? + .unwrap_or_else(|err| panic!("Failed to call finish make: {err}")) } async fn build_module(&self, module: &mut dyn rspack_core::Module) -> rspack_error::Result<()> { @@ -645,7 +641,7 @@ impl rspack_core::Plugin for JsHooksAdapter { ) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call build module: {err}"))? + .unwrap_or_else(|err| panic!("Failed to call build module: {err}")) } async fn finish_modules( @@ -667,7 +663,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call(compilation, ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to finish modules: {err}"))? + .unwrap_or_else(|err| panic!("Failed to finish modules: {err}")) } async fn emit(&self, _: &mut rspack_core::Compilation) -> rspack_error::Result<()> { @@ -680,7 +676,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call emit: {err}"))? + .unwrap_or_else(|err| panic!("Failed to call emit: {err}")) } async fn asset_emitted(&self, args: &rspack_core::AssetEmittedArgs) -> rspack_error::Result<()> { @@ -694,7 +690,29 @@ impl rspack_core::Plugin for JsHooksAdapter { .call(args, ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call asset emitted: {err}"))? + .unwrap_or_else(|err| panic!("Failed to call asset emitted: {err}")) + } + + async fn should_emit( + &self, + compilation: &mut rspack_core::Compilation, + ) -> PluginShouldEmitHookOutput { + if self.is_hook_disabled(&Hook::ShouldEmit) { + return Ok(None); + } + + let compilation = JsCompilation::from_compilation(unsafe { + std::mem::transmute::<&'_ mut rspack_core::Compilation, &'static mut rspack_core::Compilation>( + compilation, + ) + }); + + let res = self + .should_emit_tsfn + .call(compilation, ThreadsafeFunctionCallMode::NonBlocking) + .into_rspack_result()? + .await; + res.unwrap_or_else(|err| panic!("Failed to call should emit: {err}")) } async fn after_emit(&self, _: &mut rspack_core::Compilation) -> rspack_error::Result<()> { @@ -707,7 +725,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call after emit: {err}",))? + .unwrap_or_else(|err| panic!("Failed to call after emit: {err}")) } async fn succeed_module(&self, args: &dyn rspack_core::Module) -> rspack_error::Result<()> { @@ -722,7 +740,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call(js_module, ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call succeed_module hook: {err}"))? + .unwrap_or_else(|err| panic!("Failed to call succeed_module hook: {err}")) } async fn still_valid_module(&self, args: &dyn rspack_core::Module) -> rspack_error::Result<()> { @@ -738,7 +756,35 @@ impl rspack_core::Plugin for JsHooksAdapter { ) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call still_valid_module hook: {err}"))? + .unwrap_or_else(|err| panic!("Failed to call still_valid_module hook: {err}")) + } + + fn execute_module( + &self, + entry: ModuleIdentifier, + runtime_modules: Vec, + codegen_results: &rspack_core::CodeGenerationResults, + ) -> rspack_error::Result> { + if self.is_hook_disabled(&Hook::ExecuteModule) { + return Ok(None); + } + + self + .execute_module_tsfn + .call( + JsExecuteModuleArg { + entry: entry.to_string(), + runtime_modules: runtime_modules + .into_iter() + .map(|id| id.to_string()) + .collect(), + codegen_results: codegen_results.clone().into(), + }, + ThreadsafeFunctionCallMode::NonBlocking, + ) + .into_rspack_result()? + .blocking_recv() + .unwrap_or_else(|recv_err| panic!("{}", recv_err.to_string())) } } @@ -764,12 +810,13 @@ impl JsHooksAdapter { process_assets_stage_report, this_compilation, compilation, + should_emit, emit, asset_emitted, after_emit, optimize_modules, optimize_tree, - optimize_chunk_module, + optimize_chunk_modules, before_resolve, after_resolve, context_module_before_resolve, @@ -782,6 +829,7 @@ impl JsHooksAdapter { chunk_asset, succeed_module, still_valid_module, + execute_module, } = js_hooks; let process_assets_stage_additional_tsfn: ThreadsafeFunction<(), ()> = @@ -817,6 +865,8 @@ impl JsHooksAdapter { let process_assets_stage_report_tsfn: ThreadsafeFunction<(), ()> = js_fn_into_threadsafe_fn!(process_assets_stage_report, env); let emit_tsfn: ThreadsafeFunction<(), ()> = js_fn_into_threadsafe_fn!(emit, env); + let should_emit_tsfn: ThreadsafeFunction> = + js_fn_into_threadsafe_fn!(should_emit, env); let asset_emitted_tsfn: ThreadsafeFunction = js_fn_into_threadsafe_fn!(asset_emitted, env); let after_emit_tsfn: ThreadsafeFunction<(), ()> = js_fn_into_threadsafe_fn!(after_emit, env); @@ -830,7 +880,7 @@ impl JsHooksAdapter { let optimize_tree_tsfn: ThreadsafeFunction<(), ()> = js_fn_into_threadsafe_fn!(optimize_tree, env); let optimize_chunk_modules_tsfn: ThreadsafeFunction = - js_fn_into_threadsafe_fn!(optimize_chunk_module, env); + js_fn_into_threadsafe_fn!(optimize_chunk_modules, env); let before_compile_tsfn: ThreadsafeFunction<(), ()> = js_fn_into_threadsafe_fn!(before_compile, env); let after_compile_tsfn: ThreadsafeFunction = @@ -857,6 +907,8 @@ impl JsHooksAdapter { js_fn_into_threadsafe_fn!(succeed_module, env); let still_valid_module_tsfn: ThreadsafeFunction = js_fn_into_threadsafe_fn!(still_valid_module, env); + let execute_module_tsfn: ThreadsafeFunction> = + js_fn_into_threadsafe_fn!(execute_module, env); Ok(JsHooksAdapter { disabled_hooks, @@ -879,6 +931,7 @@ impl JsHooksAdapter { process_assets_stage_report_tsfn, compilation_tsfn, this_compilation_tsfn, + should_emit_tsfn, emit_tsfn, asset_emitted_tsfn, after_emit_tsfn, @@ -897,6 +950,7 @@ impl JsHooksAdapter { after_resolve, succeed_module_tsfn, still_valid_module_tsfn, + execute_module_tsfn, }) } diff --git a/crates/plugin_specilize_module_name/tests/fixtures/basic/snapshot/output.snap b/crates/plugin_specilize_module_name/tests/fixtures/basic/snapshot/output.snap index f08d066..486d001 100644 --- a/crates/plugin_specilize_module_name/tests/fixtures/basic/snapshot/output.snap +++ b/crates/plugin_specilize_module_name/tests/fixtures/basic/snapshot/output.snap @@ -4,15 +4,15 @@ assertion_line: 146 --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./function.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; +"./function.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - 'cal': function() { return cal; }, - 'cal2': function() { return cal2; } + cal: function() { return cal; }, + cal2: function() { return cal2; } }); -const { add } = __webpack_require__(/* ./utils */"./utils.js?id=2"); -const { add_3 } = __webpack_require__(/* ./util_1 */"./util_1.js"); +const { add } = __webpack_require__(/*! ./utils */"./utils.js?id=2"); +const { add_3 } = __webpack_require__(/*! ./util_1 */"./util_1.js"); function cal() { const result = add(2 + 2); console.log("2 + 2 is %s, it is a %s number", result, isNumber(result)); @@ -20,55 +20,55 @@ const { add_3 } = __webpack_require__(/* ./util_1 */"./util_1.js"); function cal2() { return add_3(0); } -}, -"./index.js": function (__unused_webpack_module, exports, __webpack_require__) { +}), +"./index.js": (function (__unused_webpack_module, exports, __webpack_require__) { console.log("Hello World!"); -const { cal } = __webpack_require__(/* ./function */"./function.js"); -const { add } = __webpack_require__(/* ./utils */"./utils.js?id=1"); +const { cal } = __webpack_require__(/*! ./function */"./function.js"); +const { add } = __webpack_require__(/*! ./utils */"./utils.js?id=1"); cal(); console.log("1 + 1 is %s", add(1, 1)); console.log("The 'string' is String type is %s", isString('string')); -}, -"./util_1.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; +}), +"./util_1.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - 'add_3': function() { return add_3; } + add_3: function() { return add_3; } }); function add_3(a) { return a + 3; } -}, -"./utils.js?id=1": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; +}), +"./utils.js?id=1": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - 'add': function() { return add; }, - 'add_3_plus_1': function() { return add_3_plus_1; } + add: function() { return add; }, + add_3_plus_1: function() { return add_3_plus_1; } }); -const { add_3 } = __webpack_require__(/* ./util_1 */"./util_1.js"); +const { add_3 } = __webpack_require__(/*! ./util_1 */"./util_1.js"); function add(x, y) { return x + y; } function add_3_plus_1(x) { return add_3(x) + 1; } -}, -"./utils.js?id=2": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; +}), +"./utils.js?id=2": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - 'add': function() { return add; }, - 'add_3_plus_1': function() { return add_3_plus_1; } + add: function() { return add; }, + add_3_plus_1: function() { return add_3_plus_1; } }); -const { add_3 } = __webpack_require__(/* ./util_1 */"./util_1.js"); +const { add_3 } = __webpack_require__(/*! ./util_1 */"./util_1.js"); function add(x, y) { return x + y; } function add_3_plus_1(x) { return add_3(x) + 1; } -}, +}), },function(__webpack_require__) { var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } From 90aa9b26cd72a54c46a97f8e8897488b85e30aeb Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Mon, 25 Dec 2023 11:21:26 +0800 Subject: [PATCH 32/32] 0.0.4 --- crates/node_binding/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/node_binding/package.json b/crates/node_binding/package.json index 5dfe0e5..fa0b151 100644 --- a/crates/node_binding/package.json +++ b/crates/node_binding/package.json @@ -1,6 +1,6 @@ { "name": "@ice/pack-binding", - "version": "0.0.3", + "version": "0.0.4", "main": "index.js", "types": "index.d.ts", "napi": {