Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,352 changes: 746 additions & 1,606 deletions Cargo.lock

Large diffs are not rendered by default.

27 changes: 14 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,20 @@ inventory = { version = "0.3.17", default-features = false }
rkyv = { version = "=0.8.8", default-features = false, features = ["std", "bytecheck"] }

# Must be pinned with the same swc versions
pnp = { version = "0.12.1", default-features = false }
swc = { version = "32.0.0", default-features = false }
swc_config = { version = "3.1.1", default-features = false }
swc_core = { version = "33.0.0", default-features = false, features = ["parallel_rayon"] }
swc_ecma_lexer = { version = "21.0.0", default-features = false }
swc_ecma_minifier = { version = "27.0.0", default-features = false }
swc_error_reporters = { version = "16.0.1", default-features = false }
swc_html = { version = "25.0.0", default-features = false }
swc_html_minifier = { version = "27.0.0", default-features = false }
swc_node_comments = { version = "14.0.0", default-features = false }
pnp = { version = "0.12.1", default-features = false }
swc = { version = "34.0.0", default-features = false }
swc_config = { version = "3.1.1", default-features = false }
swc_core = { version = "35.0.0", default-features = false, features = ["parallel_rayon"] }
swc_ecma_lexer = { version = "22.0.0", default-features = false }
swc_ecma_minifier = { version = "29.0.0", default-features = false }
swc_error_reporters = { version = "16.0.1", default-features = false }
swc_html = { version = "25.0.0", default-features = false }
swc_html_minifier = { version = "29.0.0", default-features = false }
swc_node_comments = { version = "14.0.0", default-features = false }
swc_plugin_runner = { version = "18.0.0", default-features = false }

wasmtime = { version = "35.0.0", default-features = false }
wasi-common = { version = "35.0.0", default-features = false }

rspack_dojang = { version = "0.1.11", default-features = false }

Expand Down Expand Up @@ -340,9 +344,6 @@ opt-level = "s"
[profile.release.package.swc_error_reporters]
opt-level = "s"

[profile.release.package.http]
opt-level = "s"

[profile.release.package.idna]
opt-level = "s"

Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_binding_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ version.workspace = true
browser = ["dep:rspack_browser", "rspack_napi/browser"]
color-backtrace = ["dep:color-backtrace"]
debug_tool = ["rspack_core/debug_tool"]
plugin = ["rspack_loader_swc/plugin"]
plugin = ["rspack_loader_swc/plugin", "rspack_util/plugin"]
sftrace-setup = ["dep:sftrace-setup", "rspack_allocator/sftrace-setup"]

[dependencies]
Expand Down
12 changes: 11 additions & 1 deletion crates/rspack_binding_api/src/swc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,19 @@ fn _to_source_map_kind(source_maps: Option<SourceMapsConfig>) -> SourceMapKind {
}

fn _transform(source: String, options: String) -> napi::Result<TransformOutput> {
let options: SwcOptions = serde_json::from_str(&options)?;
#[cfg_attr(not(feature = "plugin"), allow(unused_mut))]
let mut options: SwcOptions = serde_json::from_str(&options)?;

#[cfg(feature = "plugin")]
{
options.runtime_options = options.runtime_options.plugin_runtime(std::sync::Arc::new(
rspack_util::swc::runtime::WasmtimeRuntime,
));
}

let compiler = JavaScriptCompiler::new();
let module_source_map_kind = _to_source_map_kind(options.source_maps.clone());

compiler
.transform(
source,
Expand Down
8 changes: 6 additions & 2 deletions crates/rspack_loader_swc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ ignored = ["swc"]
[features]
default = []
plugin = [
"swc_core/plugin_transform_host_native",
"rspack_util/plugin",

# plugin_transform_host_native cannot be enabled directly to avoid wasmer dependency
"swc_core/__plugin_transform_host",
"swc_core/__plugin_transform_host_schema_v1",
"swc_core/plugin_transform_host_native_filesystem_cache",
"swc_core/plugin_transform_host_native_shared_runtime",
]

[dependencies]
Expand All @@ -36,6 +39,7 @@ swc_config = { workspace = true }
swc_core = { workspace = true, features = ["base", "ecma_ast", "common", "ecma_preset_env", "ecma_helpers_inline"] }
tokio = { workspace = true }
tracing = { workspace = true }
rspack_util = { workspace = true, optional = true }


[target.'cfg(not(target_family = "wasm"))'.dependencies]
Expand Down
11 changes: 11 additions & 0 deletions crates/rspack_loader_swc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ impl SwcLoader {
"`env` and `jsc.target` cannot be used together".to_string(),
));
}

#[cfg(feature = "plugin")]
{
swc_options.runtime_options =
swc_options
.runtime_options
.plugin_runtime(std::sync::Arc::new(
rspack_util::swc::runtime::WasmtimeRuntime,
));
}

swc_options
};

Expand Down
8 changes: 8 additions & 0 deletions crates/rspack_util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,16 @@ unicase = { workspace = true }
swc_config = { workspace = true }
swc_core = { workspace = true, features = ["base", "ecma_ast"] }

# wasm runtime
anyhow = { workspace = true, optional = true }
once_cell = { workspace = true, optional = true }
wasmtime = { workspace = true, optional = true, features = ["runtime", "cranelift", "threads"] }
wasi-common = { workspace = true, optional = true, features = ["sync", "wasmtime"] }
swc_plugin_runner = { workspace = true, optional = true }

rspack_regex = { workspace = true }
signal-hook = { workspace = true, optional = true }

[features]
debug_tool = ["signal-hook"] # only used for local debug and should not be enabled in production release
plugin = [ "anyhow", "once_cell", "wasmtime", "wasi-common", "swc_plugin_runner" ]
3 changes: 3 additions & 0 deletions crates/rspack_util/src/swc.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(feature = "plugin")]
pub mod runtime;

use rustc_hash::FxHashSet;
use swc_config::types::BoolOr;
use swc_core::{
Expand Down
Loading
Loading