feat(node): Use published version of swc_core for node binding (#5481)

This commit is contained in:
OJ Kwon 2022-08-13 18:15:56 -07:00 committed by GitHub
parent 239617bccd
commit 9d04f24c26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 131 additions and 99 deletions

8
Cargo.lock generated
View File

@ -180,8 +180,6 @@ dependencies = [
"serde",
"serde_json",
"swc_core",
"swc_node_bundler",
"swc_nodejs_common",
"tracing",
"tracing-chrome",
"tracing-futures",
@ -3132,7 +3130,7 @@ dependencies = [
[[package]]
name = "swc_core"
version = "0.7.4"
version = "0.7.5"
dependencies = [
"binding_macros",
"once_cell",
@ -3149,6 +3147,8 @@ dependencies = [
"swc_ecma_utils",
"swc_ecma_visit",
"swc_node_base",
"swc_node_bundler",
"swc_nodejs_common",
"swc_plugin",
"swc_plugin_macro",
"swc_plugin_proxy",
@ -4083,7 +4083,7 @@ dependencies = [
[[package]]
name = "swc_node_bundler"
version = "0.0.0"
version = "0.0.1"
dependencies = [
"anyhow",
"dashmap",

View File

@ -15,8 +15,8 @@ crate-type = ["cdylib"]
[features]
default = ["swc_v1", "plugin"]
plugin = ["swc_core/plugin_transform_host_native"]
swc_v1 = ["swc_node_bundler/swc_v1"]
swc_v2 = ["swc_node_bundler/swc_v2"]
swc_v1 = ["swc_core/bundler_node_v1"]
swc_v2 = ["swc_core/bundler_node_v2"]
# Internal flag for testing purpose only.
__plugin_transform_vtest = [
@ -56,6 +56,3 @@ swc_core = { path = "../swc_core", features = [
"base_node",
"base_concurrent",
] }
swc_node_bundler = { path = "../swc_node_bundler" }
swc_nodejs_common = { path = "../swc_nodejs_common" }

View File

@ -23,8 +23,8 @@ use swc_core::{
bundler::{BundleKind, Bundler, Load, ModuleRecord, Resolve},
common::{collections::AHashMap, Span},
loader::{TargetEnv, NODE_BUILTINS},
node::{get_deserialized, MapErr},
};
use swc_nodejs_common::{get_deserialized, MapErr};
use crate::get_compiler;
@ -39,7 +39,7 @@ struct ConfigItem {
struct StaticConfigItem {
#[cfg(feature = "swc_v1")]
#[serde(flatten)]
config: swc_node_bundler::v1::Config,
config: swc_core::bundler::node::v1::Config,
}
pub(crate) struct BundleTask {
@ -188,13 +188,13 @@ pub(crate) fn bundle(
conf_items: Buffer,
signal: Option<AbortSignal>,
) -> napi::Result<AsyncTask<BundleTask>> {
swc_nodejs_common::init_default_trace_subscriber();
crate::util::init_default_trace_subscriber();
let c: Arc<Compiler> = get_compiler();
let static_items: StaticConfigItem = get_deserialized(&conf_items)?;
let loader = Box::new(swc_node_bundler::loaders::swc::SwcLoader::new(
let loader = Box::new(swc_core::bundler::node::loaders::swc::SwcLoader::new(
c.clone(),
static_items
.config

View File

@ -11,8 +11,8 @@ use swc_core::{
TransformOutput,
},
common::{collections::AHashMap, sync::Lrc, FileName, SourceFile, SourceMap},
node::{deserialize_json, get_deserialized, MapErr},
};
use swc_nodejs_common::{deserialize_json, get_deserialized, MapErr};
use crate::{get_compiler, util::try_with};
@ -74,7 +74,7 @@ impl Task for MinifyTask {
#[napi]
fn minify(code: Buffer, opts: Buffer, signal: Option<AbortSignal>) -> AsyncTask<MinifyTask> {
swc_nodejs_common::init_default_trace_subscriber();
crate::util::init_default_trace_subscriber();
let code = String::from_utf8_lossy(code.as_ref()).to_string();
let options = String::from_utf8_lossy(opts.as_ref()).to_string();
@ -87,7 +87,7 @@ fn minify(code: Buffer, opts: Buffer, signal: Option<AbortSignal>) -> AsyncTask<
#[napi]
pub fn minify_sync(code: Buffer, opts: Buffer) -> napi::Result<TransformOutput> {
swc_nodejs_common::init_default_trace_subscriber();
crate::util::init_default_trace_subscriber();
let code: MinifyTarget = get_deserialized(code)?;
let opts = get_deserialized(opts)?;

View File

@ -14,8 +14,8 @@ use swc_core::{
Compiler,
},
common::{comments::Comments, FileName},
node::{deserialize_json, get_deserialized, MapErr},
};
use swc_nodejs_common::{deserialize_json, get_deserialized, MapErr};
use crate::{get_compiler, util::try_with};
@ -126,7 +126,7 @@ pub fn parse(
filename: Option<String>,
signal: Option<AbortSignal>,
) -> AsyncTask<ParseTask> {
swc_nodejs_common::init_default_trace_subscriber();
crate::util::init_default_trace_subscriber();
let c = get_compiler();
let options = String::from_utf8_lossy(options.as_ref()).to_string();
@ -149,7 +149,7 @@ pub fn parse(
#[napi]
pub fn parse_sync(src: String, opts: Buffer, filename: Option<String>) -> napi::Result<String> {
swc_nodejs_common::init_default_trace_subscriber();
crate::util::init_default_trace_subscriber();
let c = get_compiler();
let options: ParseOptions = get_deserialized(&opts)?;
@ -186,7 +186,7 @@ pub fn parse_sync(src: String, opts: Buffer, filename: Option<String>) -> napi::
#[napi]
pub fn parse_file_sync(path: String, opts: Buffer) -> napi::Result<String> {
swc_nodejs_common::init_default_trace_subscriber();
crate::util::init_default_trace_subscriber();
let c = get_compiler();
let options: ParseOptions = get_deserialized(&opts)?;
@ -223,7 +223,7 @@ pub fn parse_file(
options: Buffer,
signal: Option<AbortSignal>,
) -> AsyncTask<ParseFileTask> {
swc_nodejs_common::init_default_trace_subscriber();
crate::util::init_default_trace_subscriber();
let c = get_compiler();
let path = PathBuf::from(&path);

View File

@ -10,8 +10,8 @@ use swc_core::{
config::{Options, SourceMapsConfig},
Compiler, TransformOutput,
},
node::{deserialize_json, get_deserialized, MapErr},
};
use swc_nodejs_common::{deserialize_json, get_deserialized, MapErr};
use crate::get_compiler;
@ -64,7 +64,7 @@ pub fn print(
options: Buffer,
signal: Option<AbortSignal>,
) -> napi::Result<AsyncTask<PrintTask>> {
swc_nodejs_common::init_default_trace_subscriber();
crate::util::init_default_trace_subscriber();
let c = get_compiler();
let options = String::from_utf8_lossy(&options).to_string();
@ -81,7 +81,7 @@ pub fn print(
#[napi]
pub fn print_sync(program: String, options: Buffer) -> napi::Result<TransformOutput> {
swc_nodejs_common::init_default_trace_subscriber();
crate::util::init_default_trace_subscriber();
let c = get_compiler();

View File

@ -13,8 +13,8 @@ use swc_core::{
ast::Program,
base::{config::Options, Compiler, TransformOutput},
common::FileName,
node::{deserialize_json, get_deserialized, MapErr},
};
use swc_nodejs_common::{deserialize_json, get_deserialized, MapErr};
use tracing::instrument;
use crate::{get_compiler, util::try_with};
@ -104,7 +104,7 @@ pub fn transform(
options: JsBuffer,
signal: Option<AbortSignal>,
) -> napi::Result<AsyncTask<TransformTask>> {
swc_nodejs_common::init_default_trace_subscriber();
crate::util::init_default_trace_subscriber();
let c = get_compiler();
@ -125,7 +125,7 @@ pub fn transform(
#[napi]
#[instrument(level = "trace", skip_all)]
pub fn transform_sync(s: String, is_module: bool, opts: Buffer) -> napi::Result<TransformOutput> {
swc_nodejs_common::init_default_trace_subscriber();
crate::util::init_default_trace_subscriber();
let c = get_compiler();
@ -172,7 +172,7 @@ pub fn transform_file(
options: JsBuffer,
signal: Option<AbortSignal>,
) -> napi::Result<AsyncTask<TransformTask>> {
swc_nodejs_common::init_default_trace_subscriber();
crate::util::init_default_trace_subscriber();
let c = get_compiler();
@ -191,7 +191,7 @@ pub fn transform_file_sync(
is_module: bool,
opts: Buffer,
) -> napi::Result<TransformOutput> {
swc_nodejs_common::init_default_trace_subscriber();
crate::util::init_default_trace_subscriber();
let c = get_compiler();

View File

@ -15,7 +15,7 @@ use swc_core::{
use tracing::instrument;
use tracing_chrome::ChromeLayerBuilder;
use tracing_subscriber::{
filter, prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt, Layer,
filter, prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt, EnvFilter, Layer,
};
static TARGET_TRIPLE: &str = include_str!(concat!(env!("OUT_DIR"), "/triple.txt"));
@ -92,3 +92,21 @@ where
},
)
}
// This was originally under swc_nodejs_common, but this is not a public
// interface for the custom binary - they should choose own trace initialization
// instead. Will keep as hidden for now until there's proper usecase.
/// Trying to initialize default subscriber if global dispatch is not set.
/// This can be called multiple time, however subsequent calls will be ignored
/// as tracing_subscriber only allows single global dispatch.
pub fn init_default_trace_subscriber() {
let _unused = tracing_subscriber::FmtSubscriber::builder()
.without_time()
.with_target(false)
.with_writer(std::io::stderr)
.with_ansi(true)
.with_env_filter(EnvFilter::from_env("SWC_LOG"))
.pretty()
.try_init();
}

View File

@ -6,7 +6,7 @@ edition = "2021"
license = "Apache-2.0"
name = "swc_core"
repository = "https://github.com/swc-project/swc.git"
version = "0.7.4"
version = "0.7.5"
[package.metadata.docs.rs]
features = [
"common_perf",
@ -49,7 +49,14 @@ allocator_node = ["swc_node_base"]
# it is named as 'base' instead.
base = ["__base"]
base_concurrent = ["__base", "swc/concurrent"]
base_node = ["__base", "swc/node"]
# Enables n-api related features.
base_node = [
"__base",
"swc/node",
# Assume if anyone enables n-api related codes, they may would like to use
# some utility functions as well.
"swc_nodejs_common",
]
# Enable swc_common reexports.
#
@ -82,7 +89,9 @@ utils = ["__utils", "__common"]
transforms = ["__transforms", "__testing_transform"]
# Enable swc_bundler
bundler = ["swc_bundler"]
bundler = ["__bundler"]
bundler_node_v1 = ["__bundler", "swc_node_bundler/swc_v1"]
bundler_node_v2 = ["__bundler", "swc_node_bundler/swc_v2"]
# Enable swc_ecma_loader
loader = ["swc_ecma_loader"]
@ -202,6 +211,7 @@ __plugin_transform_schema_test = [
## Common
__base = ["swc"]
__binding_macros = ["common", "__base", "__transforms", "ast", "binding_macros"]
__bundler = ["swc_bundler"]
__common = ["swc_common"]
__testing_transform = ["swc_ecma_transforms_testing"]
__transforms = ["swc_ecma_transforms"]
@ -228,6 +238,8 @@ swc_ecma_transforms_testing = { optional = true, version = "0.105.4", path = "..
swc_ecma_utils = { optional = true, version = "0.99.4", path = "../swc_ecma_utils" }
swc_ecma_visit = { optional = true, version = "0.76.5", path = "../swc_ecma_visit" }
swc_node_base = { optional = true, version = "0.5.5", path = "../swc_node_base" }
swc_node_bundler = { optional = true, version = "0.0.1", path = "../swc_node_bundler" }
swc_nodejs_common = { optional = true, version = "0.0.1", path = "../swc_nodejs_common" }
swc_plugin = { optional = true, version = "0.89.0", path = "../swc_plugin" }
swc_plugin_macro = { optional = true, version = "0.9.2", path = "../swc_plugin_macro" }
swc_plugin_proxy = { optional = true, version = "0.18.5", path = "../swc_plugin_proxy" }

View File

@ -74,10 +74,19 @@ pub mod transforms {
}
// swc_bundler
#[cfg(feature = "bundler")]
#[cfg_attr(docsrs, doc(cfg(feature = "bundler")))]
#[cfg(feature = "__bundler")]
#[cfg_attr(docsrs, doc(cfg(feature = "__bundler")))]
pub mod bundler {
pub use swc_bundler::*;
#[cfg(any(feature = "bundler_node_v1", feature = "bundler_node_v2"))]
#[cfg_attr(
docsrs,
doc(cfg(any(feature = "bundler_node_v1", feature = "bundler_node_v2")))
)]
pub mod node {
pub use swc_node_bundler::*;
}
}
// swc_ecma_loader
@ -105,6 +114,12 @@ pub mod binding_macros {
pub use binding_macros::*;
}
#[cfg(feature = "base_node")]
#[cfg_attr(docsrs, doc(cfg(feature = "base_node")))]
pub mod node {
pub use swc_nodejs_common::*;
}
#[cfg(feature = "allocator_node")]
#[cfg_attr(docsrs, doc(cfg(feature = "allocator_node")))]
extern crate swc_node_base;

View File

@ -1,22 +1,21 @@
[package]
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
build = "build.rs"
description = "Speedy web compiler"
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
build = "build.rs"
description = "Speedy web compiler"
documentation = "https://rustdoc.swc.rs/swc/"
edition = "2021"
license = "Apache-2.0"
name = "swc_node_bundler"
publish = false
repository = "https://github.com/swc-project/swc.git"
version = "0.0.0"
edition = "2021"
license = "Apache-2.0"
name = "swc_node_bundler"
repository = "https://github.com/swc-project/swc.git"
version = "0.0.1"
[lib]
bench = false
[features]
default = ["swc_v1"]
swc_v1 = []
swc_v2 = []
swc_v1 = []
swc_v2 = []
[dependencies]
anyhow = "1"
@ -24,23 +23,27 @@ dashmap = "5.1.0"
is-macro = "0.2.0"
once_cell = "1.10.0"
regex = "1"
serde = {version = "1", features = ["derive"]}
serde = { version = "1", features = ["derive"] }
serde_json = "1"
string_enum = {version = "0.3", path = "../string_enum"}
swc = {path = "../swc"}
swc_atoms = {path = "../swc_atoms"}
swc_bundler = {path = "../swc_bundler", features = ["concurrent"]}
swc_common = {path = "../swc_common", features = ["concurrent"]}
swc_ecma_ast = {path = "../swc_ecma_ast"}
swc_ecma_codegen = {path = "../swc_ecma_codegen"}
swc_ecma_loader = {path = "../swc_ecma_loader"}
swc_ecma_parser = {path = "../swc_ecma_parser"}
swc_ecma_transforms = {path = "../swc_ecma_transforms"}
swc_ecma_utils = {path = "../swc_ecma_utils"}
swc_ecma_visit = {path = "../swc_ecma_visit"}
swc_node_base = {path = "../swc_node_base"}
string_enum = { version = "0.3", path = "../string_enum" }
swc = { version = "0.214.4", path = "../swc" }
swc_atoms = { version = "0.4.5", path = "../swc_atoms" }
swc_bundler = { version = "0.177.3", path = "../swc_bundler", features = [
"concurrent",
] }
swc_common = { version = "0.27.6", path = "../swc_common", features = [
"concurrent",
] }
swc_ecma_ast = { version = "0.90.7", path = "../swc_ecma_ast" }
swc_ecma_codegen = { version = "0.121.4", path = "../swc_ecma_codegen" }
swc_ecma_loader = { version = "0.39.4", path = "../swc_ecma_loader" }
swc_ecma_parser = { version = "0.117.4", path = "../swc_ecma_parser" }
swc_ecma_transforms = { version = "0.183.3", path = "../swc_ecma_transforms" }
swc_ecma_utils = { version = "0.99.4", path = "../swc_ecma_utils" }
swc_ecma_visit = { version = "0.76.5", path = "../swc_ecma_visit" }
swc_node_base = { version = "0.5.5", path = "../swc_node_base" }
tracing = "0.1.32"
[dev-dependencies]
pretty_assertions = "1.1"
testing = {path = "../testing"}
testing = { path = "../testing" }

View File

@ -8,21 +8,6 @@ use std::any::type_name;
use anyhow::Context;
use napi::Status;
use serde::de::DeserializeOwned;
use tracing_subscriber::EnvFilter;
/// Trying to initialize default subscriber if global dispatch is not set.
/// This can be called multiple time, however subsequent calls will be ignored
/// as tracing_subscriber only allows single global dispatch.
pub fn init_default_trace_subscriber() {
let _unused = tracing_subscriber::FmtSubscriber::builder()
.without_time()
.with_target(false)
.with_writer(std::io::stderr)
.with_ansi(true)
.with_env_filter(EnvFilter::from_env("SWC_LOG"))
.pretty()
.try_init();
}
pub trait MapErr<T>: Into<Result<T, anyhow::Error>> {
fn convert_err(self) -> napi::Result<T> {

View File

@ -3,6 +3,7 @@ use swc_common::{
comments::{Comment, Comments},
BytePos,
};
#[cfg(feature = "plugin-mode")]
use swc_trace_macro::swc_trace;
#[cfg(feature = "plugin-mode")]

View File

@ -1,5 +1,6 @@
#[cfg(feature = "plugin-mode")]
use swc_common::Mark;
#[cfg(feature = "plugin-mode")]
use swc_trace_macro::swc_trace;
#[cfg(feature = "plugin-mode")]

View File

@ -1175,7 +1175,7 @@ dependencies = [
[[package]]
name = "swc_atoms"
version = "0.4.2"
version = "0.4.5"
dependencies = [
"bytecheck",
"once_cell",
@ -1188,7 +1188,7 @@ dependencies = [
[[package]]
name = "swc_common"
version = "0.27.3"
version = "0.27.6"
dependencies = [
"ahash",
"anyhow",
@ -1219,7 +1219,7 @@ dependencies = [
[[package]]
name = "swc_core"
version = "0.6.5"
version = "0.7.5"
dependencies = [
"once_cell",
"swc_atoms",
@ -1235,7 +1235,7 @@ dependencies = [
[[package]]
name = "swc_ecma_ast"
version = "0.90.4"
version = "0.90.7"
dependencies = [
"bitflags",
"bytecheck",
@ -1252,7 +1252,7 @@ dependencies = [
[[package]]
name = "swc_ecma_codegen"
version = "0.121.1"
version = "0.121.4"
dependencies = [
"memchr",
"num-bigint",
@ -1280,7 +1280,7 @@ dependencies = [
[[package]]
name = "swc_ecma_parser"
version = "0.117.1"
version = "0.117.4"
dependencies = [
"either",
"enum_kind",
@ -1297,7 +1297,7 @@ dependencies = [
[[package]]
name = "swc_ecma_quote_macros"
version = "0.28.1"
version = "0.28.4"
dependencies = [
"anyhow",
"pmutil",
@ -1313,7 +1313,7 @@ dependencies = [
[[package]]
name = "swc_ecma_testing"
version = "0.14.1"
version = "0.14.4"
dependencies = [
"anyhow",
"hex",
@ -1327,7 +1327,7 @@ dependencies = [
[[package]]
name = "swc_ecma_transforms_base"
version = "0.103.3"
version = "0.103.6"
dependencies = [
"better_scoped_tls",
"bitflags",
@ -1348,7 +1348,7 @@ dependencies = [
[[package]]
name = "swc_ecma_transforms_testing"
version = "0.105.1"
version = "0.105.4"
dependencies = [
"ansi_term",
"anyhow",
@ -1370,7 +1370,7 @@ dependencies = [
[[package]]
name = "swc_ecma_utils"
version = "0.99.1"
version = "0.99.4"
dependencies = [
"indexmap",
"once_cell",
@ -1384,7 +1384,7 @@ dependencies = [
[[package]]
name = "swc_ecma_visit"
version = "0.76.2"
version = "0.76.5"
dependencies = [
"num-bigint",
"swc_atoms",
@ -1406,7 +1406,7 @@ dependencies = [
[[package]]
name = "swc_error_reporters"
version = "0.11.1"
version = "0.11.4"
dependencies = [
"anyhow",
"miette",
@ -1442,7 +1442,7 @@ dependencies = [
[[package]]
name = "swc_plugin_macro"
version = "0.9.0"
version = "0.9.2"
dependencies = [
"proc-macro2",
"quote",
@ -1451,7 +1451,7 @@ dependencies = [
[[package]]
name = "swc_plugin_proxy"
version = "0.18.2"
version = "0.18.5"
dependencies = [
"better_scoped_tls",
"bytecheck",
@ -1464,7 +1464,7 @@ dependencies = [
[[package]]
name = "swc_trace_macro"
version = "0.1.1"
version = "0.1.2"
dependencies = [
"proc-macro2",
"quote",
@ -1537,7 +1537,7 @@ dependencies = [
[[package]]
name = "testing"
version = "0.29.1"
version = "0.29.4"
dependencies = [
"ansi_term",
"difference",

View File

@ -613,7 +613,7 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "swc_atoms"
version = "0.4.4"
version = "0.4.5"
dependencies = [
"bytecheck",
"once_cell",
@ -626,7 +626,7 @@ dependencies = [
[[package]]
name = "swc_common"
version = "0.27.5"
version = "0.27.6"
dependencies = [
"ahash",
"anyhow",
@ -654,7 +654,7 @@ dependencies = [
[[package]]
name = "swc_core"
version = "0.7.3"
version = "0.7.5"
dependencies = [
"once_cell",
"swc_atoms",
@ -668,7 +668,7 @@ dependencies = [
[[package]]
name = "swc_ecma_ast"
version = "0.90.6"
version = "0.90.7"
dependencies = [
"bitflags",
"bytecheck",
@ -685,7 +685,7 @@ dependencies = [
[[package]]
name = "swc_ecma_visit"
version = "0.76.4"
version = "0.76.5"
dependencies = [
"num-bigint",
"swc_atoms",
@ -733,7 +733,7 @@ dependencies = [
[[package]]
name = "swc_plugin_proxy"
version = "0.18.4"
version = "0.18.5"
dependencies = [
"better_scoped_tls",
"bytecheck",