Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Publish v1.3.4 #5998

Merged
merged 17 commits into from
Sep 30, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
219 changes: 109 additions & 110 deletions bindings/Cargo.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions bindings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ members = ["binding_core_node", "binding_core_wasm", "swc_cli"]

# Strip debug symbols
strip = "symbols"


[profile.dev.package."*"]
debug-assertions = false
2 changes: 1 addition & 1 deletion bindings/binding_core_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ tracing-chrome = "0.5.0"
tracing-futures = "0.2.5"
tracing-subscriber = { version = "0.3.9", features = ["env-filter"] }

swc_core = { version = "0.26.0", features = [
swc_core = { version = "0.28.10", features = [
"ecma_ast",
"common_concurrent",
"bundler",
Expand Down
169 changes: 86 additions & 83 deletions bindings/binding_core_node/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use swc_core::{
Compiler, TransformOutput,
},
bundler::{BundleKind, Bundler, Load, ModuleRecord, Resolve},
common::{collections::AHashMap, Span},
common::{collections::AHashMap, Globals, Span, GLOBALS},
ecma::{
ast::{
Bool, Expr, Ident, KeyValueProp, Lit, MemberExpr, MemberProp, MetaPropExpr,
Expand Down Expand Up @@ -74,95 +74,98 @@ impl Task for BundleTask {
.codegen_target()
.unwrap_or_default();

let res = catch_unwind(AssertUnwindSafe(|| {
let mut bundler = Bundler::new(
self.swc.globals(),
self.swc.cm.clone(),
&self.config.loader,
&self.config.resolver,
swc_core::bundler::Config {
require: true,
external_modules: builtins
.into_iter()
.chain(
self.config
let globals = Globals::default();
GLOBALS.set(&globals, || {
let res = catch_unwind(AssertUnwindSafe(|| {
let mut bundler = Bundler::new(
&globals,
self.swc.cm.clone(),
&self.config.loader,
&self.config.resolver,
swc_core::bundler::Config {
require: true,
external_modules: builtins
.into_iter()
.chain(
self.config
.static_items
.config
.external_modules
.iter()
.cloned(),
)
.collect(),
..Default::default()
},
Box::new(Hook),
);

let result = bundler
.bundle(self.config.static_items.config.entry.clone().into())
.convert_err()?;

let result = result
.into_iter()
.map(|bundle| match bundle.kind {
BundleKind::Named { name } | BundleKind::Lib { name } => {
Ok((name, bundle.module))
}
BundleKind::Dynamic => bail!("unimplemented: dynamic code splitting"),
})
.map(|res| {
res.and_then(|(k, m)| {
// TODO: Source map
let minify = self
.config
.static_items
.config
.external_modules
.iter()
.cloned(),
)
.collect(),
..Default::default()
},
Box::new(Hook),
);

let result = bundler
.bundle(self.config.static_items.config.entry.clone().into())
.convert_err()?;

let result = result
.into_iter()
.map(|bundle| match bundle.kind {
BundleKind::Named { name } | BundleKind::Lib { name } => {
Ok((name, bundle.module))
}
BundleKind::Dynamic => bail!("unimplemented: dynamic code splitting"),
})
.map(|res| {
res.and_then(|(k, m)| {
// TODO: Source map
let minify = self
.config
.static_items
.config
.options
.as_ref()
.map(|v| v.config.minify.into_bool())
.unwrap_or(false);

let output = self.swc.print(
&m,
None,
None,
true,
codegen_target,
SourceMapsConfig::Bool(true),
// TODO
&Default::default(),
None,
minify,
None,
true,
false,
)?;

Ok((k, output))
.options
.as_ref()
.map(|v| v.config.minify.into_bool())
.unwrap_or(false);

let output = self.swc.print(
&m,
None,
None,
true,
codegen_target,
SourceMapsConfig::Bool(true),
// TODO
&Default::default(),
None,
minify,
None,
true,
false,
)?;

Ok((k, output))
})
})
})
.collect::<Result<_, _>>()
.convert_err()?;
.collect::<Result<_, _>>()
.convert_err()?;

Ok(result)
}));
Ok(result)
}));

let err = match res {
Ok(v) => return v,
Err(err) => err,
};
let err = match res {
Ok(v) => return v,
Err(err) => err,
};

if let Some(s) = err.downcast_ref::<String>() {
return Err(napi::Error::new(
Status::GenericFailure,
format!("panic detected: {}", s),
));
}
if let Some(s) = err.downcast_ref::<String>() {
return Err(napi::Error::new(
Status::GenericFailure,
format!("panic detected: {}", s),
));
}

Err(napi::Error::new(
Status::GenericFailure,
"panic detected".to_string(),
))
Err(napi::Error::new(
Status::GenericFailure,
"panic detected".to_string(),
))
})
}

fn resolve(&mut self, _env: Env, output: Self::Output) -> napi::Result<Self::JsValue> {
Expand Down
79 changes: 42 additions & 37 deletions bindings/binding_core_node/src/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use swc_core::{
config::{Options, SourceMapsConfig},
Compiler, TransformOutput,
},
common::GLOBALS,
ecma::ast::{EsVersion, Program},
node::{deserialize_json, get_deserialized, MapErr},
};
Expand All @@ -32,25 +33,27 @@ impl Task for PrintTask {
let program: Program = deserialize_json(&self.program_json)?;
let options: Options = deserialize_json(&self.options)?;

self.c
.print(
&program,
None,
options.output_path.clone(),
true,
options.config.jsc.target.unwrap_or(EsVersion::Es2020),
options
.source_maps
.clone()
.unwrap_or(SourceMapsConfig::Bool(false)),
&Default::default(),
None,
options.config.minify.into_bool(),
None,
options.config.emit_source_map_columns.into_bool(),
false,
)
.convert_err()
GLOBALS.set(&Default::default(), || {
self.c
.print(
&program,
None,
options.output_path.clone(),
true,
options.config.jsc.target.unwrap_or(EsVersion::Es2020),
options
.source_maps
.clone()
.unwrap_or(SourceMapsConfig::Bool(false)),
&Default::default(),
None,
options.config.minify.into_bool(),
None,
options.config.emit_source_map_columns.into_bool(),
false,
)
.convert_err()
})
}

fn resolve(&mut self, _env: Env, result: Self::Output) -> napi::Result<Self::JsValue> {
Expand Down Expand Up @@ -92,22 +95,24 @@ pub fn print_sync(program: String, options: Buffer) -> napi::Result<TransformOut
// Defaults to es3
let codegen_target = options.codegen_target().unwrap_or_default();

c.print(
&program,
None,
options.output_path,
true,
codegen_target,
options
.source_maps
.clone()
.unwrap_or(SourceMapsConfig::Bool(false)),
&Default::default(),
None,
options.config.minify.into_bool(),
None,
options.config.emit_source_map_columns.into_bool(),
false,
)
.convert_err()
GLOBALS.set(&Default::default(), || {
c.print(
&program,
None,
options.output_path,
true,
codegen_target,
options
.source_maps
.clone()
.unwrap_or(SourceMapsConfig::Bool(false)),
&Default::default(),
None,
options.config.minify.into_bool(),
None,
options.config.emit_source_map_columns.into_bool(),
false,
)
.convert_err()
})
}
48 changes: 25 additions & 23 deletions bindings/binding_core_node/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use swc_core::{
common::{
errors::Handler,
sync::{Lrc, OnceCell},
SourceMap,
SourceMap, GLOBALS,
},
};
use tracing::instrument;
Expand Down Expand Up @@ -67,30 +67,32 @@ pub fn try_with<F, Ret>(
where
F: FnOnce(&Handler) -> Result<Ret, Error>,
{
try_with_handler(
cm,
swc_core::base::HandlerOpts {
skip_filename,
..Default::default()
},
|handler| {
//
let result = catch_unwind(AssertUnwindSafe(|| op(handler)));
GLOBALS.set(&Default::default(), || {
try_with_handler(
cm,
swc_core::base::HandlerOpts {
skip_filename,
..Default::default()
},
|handler| {
//
let result = catch_unwind(AssertUnwindSafe(|| op(handler)));

let p = match result {
Ok(v) => return v,
Err(v) => v,
};
let p = match result {
Ok(v) => return v,
Err(v) => v,
};

if let Some(s) = p.downcast_ref::<String>() {
Err(anyhow!("failed to handle: {}", s))
} else if let Some(s) = p.downcast_ref::<&str>() {
Err(anyhow!("failed to handle: {}", s))
} else {
Err(anyhow!("failed to handle with unknown panic message"))
}
},
)
if let Some(s) = p.downcast_ref::<String>() {
Err(anyhow!("failed to handle: {}", s))
} else if let Some(s) = p.downcast_ref::<&str>() {
Err(anyhow!("failed to handle: {}", s))
} else {
Err(anyhow!("failed to handle with unknown panic message"))
}
},
)
})
}

// This was originally under swc_nodejs_common, but this is not a public
Expand Down
6 changes: 4 additions & 2 deletions bindings/binding_core_wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license = "Apache-2.0"
name = "binding_core_wasm"
publish = false
repository = "https://github.com/swc-project/swc.git"
version = "1.3.3"
version = "1.3.4"

[lib]
bench = false
Expand All @@ -20,10 +20,12 @@ swc_v2 = []
plugin = ["swc_core/plugin_transform_host_js"]

[dependencies]
swc_core = { version = "0.26.0", features = [
anyhow = "1"
swc_core = { version = "0.28.10", features = [
"common_perf",
"binding_macro_wasm",
] }
tracing = { version = "0.1.36", features = ["max_level_off"] }
wasm-bindgen = { version = "0.2.82", features = [
"serde-serialize",
"enable-interning",
Expand Down