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