feat(swc_core): Expand features to support node bindings (#5387)

This commit is contained in:
OJ Kwon 2022-08-04 22:11:40 -07:00 committed by GitHub
parent c50b4f08aa
commit 038a543be9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 363 additions and 232 deletions

22
Cargo.lock generated
View File

@ -179,23 +179,13 @@ dependencies = [
"path-clean",
"serde",
"serde_json",
"swc",
"swc_atoms",
"swc_bundler",
"swc_common",
"swc_ecma_ast",
"swc_ecma_lints",
"swc_ecma_loader",
"swc_ecma_parser",
"swc_core",
"swc_node_bundler",
"swc_nodejs_common",
"swc_plugin_runner",
"tracing",
"tracing-chrome",
"tracing-futures",
"tracing-subscriber",
"wasmer",
"wasmer-wasi",
]
[[package]]
@ -210,7 +200,6 @@ dependencies = [
"path-clean",
"serde",
"serde_json",
"swc",
"swc_core",
"tracing",
"wasm-bindgen",
@ -2973,7 +2962,6 @@ dependencies = [
"swc_ecma_transforms_optimization",
"swc_ecma_utils",
"swc_ecma_visit",
"swc_ecmascript",
"swc_error_reporters",
"swc_node_base",
"swc_node_comments",
@ -3070,7 +3058,6 @@ dependencies = [
"relative-path",
"serde",
"serde_json",
"swc",
"swc_core",
"tracing",
"tracing-chrome",
@ -3142,11 +3129,18 @@ name = "swc_core"
version = "0.2.0"
dependencies = [
"once_cell",
"swc",
"swc_atoms",
"swc_bundler",
"swc_common",
"swc_ecma_ast",
"swc_ecma_loader",
"swc_ecma_parser",
"swc_ecma_quote",
"swc_ecma_transforms",
"swc_ecma_utils",
"swc_ecma_visit",
"swc_node_base",
"swc_plugin",
"swc_plugin_macro",
"swc_plugin_proxy",

View File

@ -1,37 +1,30 @@
[package]
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
build = "build.rs"
build = "build.rs"
edition = "2021"
exclude = ["artifacts.json", "index.node"]
license = "Apache-2.0"
name = "binding_core_node"
name = "binding_core_node"
publish = false
version = "0.1.0"
[lib]
bench = false
bench = false
crate-type = ["cdylib"]
[features]
default = ["swc_v1", "plugin", "plugin_transform_schema_v1"]
plugin = [
"swc/plugin",
"swc_plugin_runner/default",
"wasmer/default",
"wasmer-wasi/default",
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"]
# Internal flag for testing purpose only.
__plugin_transform_vtest = [
# We know what we're doing - enable internal features for testing fixture setup.
"swc_core/__plugin_transform_host",
"swc_core/__plugin_transform_host_schema_vtest",
"swc_core/__plugin_transform_env_native",
]
plugin_transform_schema_v1 = [
"swc/plugin_transform_schema_v1",
"swc_common/plugin_transform_schema_v1",
"swc_plugin_runner/plugin_transform_schema_v1",
]
plugin_transform_schema_vtest = [
"swc/plugin_transform_schema_vtest",
"swc_common/plugin_transform_schema_vtest",
"swc_plugin_runner/plugin_transform_schema_vtest",
]
swc_v1 = ["swc_node_bundler/swc_v1"]
swc_v2 = ["swc_node_bundler/swc_v2"]
[build-dependencies]
napi-build = { version = "2" }
@ -50,22 +43,19 @@ node_macro_deps = { path = "../node_macro_deps" }
path-clean = "0.1"
serde = { version = "1", features = ["derive"] }
serde_json = { version = "1", features = ["unbounded_depth"] }
swc = { path = "../swc", features = ["node", "concurrent"] }
swc_atoms = { path = "../swc_atoms" }
swc_bundler = { path = "../swc_bundler" }
swc_common = { path = "../swc_common", features = ["sourcemap", "perf"] }
swc_ecma_ast = { path = "../swc_ecma_ast" }
swc_ecma_lints = { path = "../swc_ecma_lints", features = [
"non_critical_lints",
] }
swc_ecma_loader = { path = "../swc_ecma_loader" }
swc_ecma_parser = { path = "../swc_ecma_parser" }
swc_node_bundler = { path = "../swc_node_bundler" }
swc_nodejs_common = { path = "../swc_nodejs_common" }
swc_plugin_runner = { path = "../swc_plugin_runner", optional = true, default-features = false }
tracing = { version = "0.1.32", features = ["release_max_level_info"] }
tracing-chrome = "0.5.0"
tracing-futures = "0.2.5"
tracing-subscriber = { version = "0.3.9", features = ["env-filter"] }
wasmer = { version = "2.3.0", optional = true, default-features = false }
wasmer-wasi = { version = "2.3.0", optional = true, default-features = false }
swc_core = { path = "../swc_core", features = [
"ast",
"common_concurrent",
"bundler",
"loader",
"base_node",
"base_concurrent",
] }
swc_node_bundler = { path = "../swc_node_bundler" }
swc_nodejs_common = { path = "../swc_nodejs_common" }

View File

@ -9,19 +9,21 @@ use napi::{
Env, Status, Task,
};
use serde::Deserialize;
use swc::{
config::SourceMapsConfig,
resolver::{environment_resolver, paths_resolver},
Compiler, TransformOutput,
use swc_core::{
ast::{
Bool, Expr, Ident, KeyValueProp, Lit, MemberExpr, MemberProp, MetaPropExpr, MetaPropKind,
PropName, Str,
},
atoms::{js_word, JsWord},
base::{
config::SourceMapsConfig,
resolver::{environment_resolver, paths_resolver},
Compiler, TransformOutput,
},
bundler::{BundleKind, Bundler, Load, ModuleRecord, Resolve},
common::{collections::AHashMap, Span},
loader::{TargetEnv, NODE_BUILTINS},
};
use swc_atoms::{js_word, JsWord};
use swc_bundler::{BundleKind, Bundler, Load, ModuleRecord, Resolve};
use swc_common::{collections::AHashMap, Span};
use swc_ecma_ast::{
Bool, Expr, Ident, KeyValueProp, Lit, MemberExpr, MemberProp, MetaPropExpr, MetaPropKind,
PropName, Str,
};
use swc_ecma_loader::{TargetEnv, NODE_BUILTINS};
use swc_nodejs_common::{get_deserialized, MapErr};
use crate::get_compiler;
@ -41,7 +43,7 @@ struct StaticConfigItem {
}
pub(crate) struct BundleTask {
swc: Arc<swc::Compiler>,
swc: Arc<swc_core::base::Compiler>,
config: ConfigItem,
}
@ -76,7 +78,7 @@ impl Task for BundleTask {
self.swc.cm.clone(),
&self.config.loader,
&self.config.resolver,
swc_bundler::Config {
swc_core::bundler::Config {
require: true,
external_modules: builtins
.into_iter()
@ -261,7 +263,7 @@ pub(crate) fn bundle() -> napi::Result<AsyncTask<BundleTask>> {
struct Hook;
impl swc_bundler::Hook for Hook {
impl swc_core::bundler::Hook for Hook {
fn get_import_meta_props(
&self,
span: Span,

View File

@ -7,8 +7,10 @@ extern crate napi_derive;
use std::{env, panic::set_hook, sync::Arc};
use backtrace::Backtrace;
use swc::Compiler;
use swc_common::{self, sync::Lazy, FilePathMapping, SourceMap};
use swc_core::{
base::Compiler,
common::{sync::Lazy, FilePathMapping, SourceMap},
};
mod bundle;
mod minify;

View File

@ -5,17 +5,19 @@ use napi::{
Task,
};
use serde::Deserialize;
use swc::{
config::{ErrorFormat, JsMinifyOptions},
TransformOutput,
use swc_core::{
base::{
config::{ErrorFormat, JsMinifyOptions},
TransformOutput,
},
common::{collections::AHashMap, sync::Lrc, FileName, SourceFile, SourceMap},
};
use swc_common::{collections::AHashMap, sync::Lrc, FileName, SourceFile, SourceMap};
use swc_nodejs_common::{deserialize_json, get_deserialized, MapErr};
use crate::{get_compiler, util::try_with};
struct MinifyTask {
c: Arc<swc::Compiler>,
c: Arc<swc_core::base::Compiler>,
code: String,
options: String,
}

View File

@ -8,11 +8,13 @@ use napi::{
bindgen_prelude::{AbortSignal, AsyncTask, Buffer},
Env, Task,
};
use swc::{
config::{ErrorFormat, ParseOptions},
Compiler,
use swc_core::{
base::{
config::{ErrorFormat, ParseOptions},
Compiler,
},
common::{comments::Comments, FileName},
};
use swc_common::{comments::Comments, FileName};
use swc_nodejs_common::{deserialize_json, get_deserialized, MapErr};
use crate::{get_compiler, util::try_with};

View File

@ -4,11 +4,13 @@ use napi::{
bindgen_prelude::{AbortSignal, AsyncTask, Buffer},
Env, Task,
};
use swc::{
config::{Options, SourceMapsConfig},
Compiler, TransformOutput,
use swc_core::{
ast::{EsVersion, Program},
base::{
config::{Options, SourceMapsConfig},
Compiler, TransformOutput,
},
};
use swc_ecma_ast::{EsVersion, Program};
use swc_nodejs_common::{deserialize_json, get_deserialized, MapErr};
use crate::get_compiler;

View File

@ -9,9 +9,11 @@ use napi::{
Env, JsBuffer, JsBufferValue, Ref, Task,
};
use path_clean::clean;
use swc::{config::Options, Compiler, TransformOutput};
use swc_common::FileName;
use swc_ecma_ast::Program;
use swc_core::{
ast::Program,
base::{config::Options, Compiler, TransformOutput},
common::FileName,
};
use swc_nodejs_common::{deserialize_json, get_deserialized, MapErr};
use tracing::instrument;

View File

@ -4,11 +4,13 @@ use std::panic::{catch_unwind, AssertUnwindSafe};
use anyhow::{anyhow, Error};
use napi::Env;
use swc::{config::ErrorFormat, try_with_handler};
use swc_common::{
errors::Handler,
sync::{Lrc, OnceCell},
SourceMap,
use swc_core::{
base::{config::ErrorFormat, try_with_handler},
common::{
errors::Handler,
sync::{Lrc, OnceCell},
SourceMap,
},
};
use tracing::instrument;
use tracing_chrome::ChromeLayerBuilder;
@ -67,7 +69,7 @@ where
{
try_with_handler(
cm,
swc::HandlerOpts {
swc_core::base::HandlerOpts {
skip_filename,
..Default::default()
},

View File

@ -17,7 +17,7 @@ default = ["swc_v1"]
swc_v1 = []
swc_v2 = []
# This feature exists to allow cargo operations
plugin = ["swc/plugin", "swc_core/plugin_transform_host_js"]
plugin = ["swc_core/plugin_transform_host_js"]
[dependencies]
anyhow = "1.0.58"
@ -28,8 +28,12 @@ parking_lot_core = "0.9.3"
path-clean = "0.1.0"
serde = { version = "1.0.140", features = ["derive"] }
serde_json = "1.0.82"
swc = { path = "../swc" }
swc_core = { path = "../swc_core", features = ["ast", "common", "perf"] }
swc_core = { path = "../swc_core", features = [
"ast",
"common",
"common_perf",
"base",
] }
tracing = { version = "0.1.35", features = ["release_max_level_off"] }
wasm-bindgen = { version = "0.2.82", features = [
"serde-serialize",

View File

@ -7,12 +7,12 @@ use std::sync::Arc;
use anyhow::{Context, Error};
use js_sys::{JsString, JSON};
use once_cell::sync::Lazy;
use swc::{
config::{ErrorFormat, JsMinifyOptions, Options, ParseOptions, SourceMapsConfig},
try_with_handler, Compiler,
};
use swc_core::{
ast::{EsVersion, Program},
base::{
config::{ErrorFormat, JsMinifyOptions, Options, ParseOptions, SourceMapsConfig},
try_with_handler, Compiler,
},
common::{comments::Comments, FileName, FilePathMapping, SourceMap},
};
use wasm_bindgen::{prelude::*, JsCast};
@ -75,7 +75,7 @@ pub fn minify_sync(s: JsString, opts: JsValue) -> Result<JsValue, JsValue> {
try_with_handler(
c.cm.clone(),
swc::HandlerOpts {
swc_core::base::HandlerOpts {
..Default::default()
},
|handler| {
@ -113,7 +113,7 @@ pub fn parse_sync(s: JsString, opts: JsValue) -> Result<JsValue, JsValue> {
try_with_handler(
c.cm.clone(),
swc::HandlerOpts {
swc_core::base::HandlerOpts {
..Default::default()
},
|handler| {
@ -166,7 +166,7 @@ pub fn print_sync(s: JsValue, opts: JsValue) -> Result<JsValue, JsValue> {
try_with_handler(
c.cm.clone(),
swc::HandlerOpts {
swc_core::base::HandlerOpts {
..Default::default()
},
|_handler| {
@ -284,7 +284,7 @@ pub fn transform_sync(
try_with_handler(
c.cm.clone(),
swc::HandlerOpts {
swc_core::base::HandlerOpts {
..Default::default()
},
|handler| {

View File

@ -1,22 +1,29 @@
[package]
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
description = "Speedy web compiler"
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
description = "Speedy web compiler"
documentation = "https://rustdoc.swc.rs/swc/"
edition = "2021"
include = ["Cargo.toml", "src/**/*.rs"]
license = "Apache-2.0"
name = "swc"
repository = "https://github.com/swc-project/swc.git"
version = "0.212.3"
edition = "2021"
include = ["Cargo.toml", "src/**/*.rs"]
license = "Apache-2.0"
name = "swc"
repository = "https://github.com/swc-project/swc.git"
version = "0.212.3"
[lib]
bench = false
name = "swc"
name = "swc"
[features]
concurrent = ["swc_ecma_transforms/concurrent", "swc_common/concurrent", "swc_ecma_minifier/concurrent", "swc_ecmascript/concurrent"]
# TODO: This may need reorganization with swc_core - swc_core allows to optionally enable
# each features (minifier, transforms..) but swc includes all of them.
concurrent = [
"swc_ecma_transforms/concurrent",
"swc_common/concurrent",
"swc_ecma_minifier/concurrent",
]
debug = ["swc_ecma_visit/debug"]
default = ["es3"]
es3 = []
@ -24,11 +31,11 @@ node = ["napi", "napi-derive"]
plugin = ["swc_plugin_runner", "swc_plugin_proxy/plugin-rt"]
plugin_transform_schema_v1 = [
"swc_common/plugin_transform_schema_v1",
"swc_plugin_runner/plugin_transform_schema_v1"
"swc_plugin_runner/plugin_transform_schema_v1",
]
plugin_transform_schema_vtest = [
"swc_common/plugin_transform_schema_vtest",
"swc_plugin_runner/plugin_transform_schema_vtest"
"swc_plugin_runner/plugin_transform_schema_vtest",
]
[dependencies]
@ -37,7 +44,7 @@ anyhow = "1"
base64 = "0.13.0"
dashmap = "5.1.0"
either = "1"
indexmap = {version = "1", features = ["serde"]}
indexmap = { version = "1", features = ["serde"] }
json_comments = "0.2.0"
lru = "0.7.1"
once_cell = "1.10.0"
@ -45,72 +52,71 @@ parking_lot = "0.12.0"
pathdiff = "0.2.0"
regex = "1"
rustc-hash = "1.1.0"
serde = {version = "1", features = ["derive"]}
serde = { version = "1", features = ["derive"] }
serde_json = "1"
sourcemap = "6"
swc_atoms = {version = "0.3.1", path = "../swc_atoms"}
swc_cached = {version = "0.2.0", path = "../swc_cached"}
swc_common = {version = "0.26.0", path = "../swc_common", features = [
swc_atoms = { version = "0.3.1", path = "../swc_atoms" }
swc_cached = { version = "0.2.0", path = "../swc_cached" }
swc_common = { version = "0.26.0", path = "../swc_common", features = [
"sourcemap",
"parking_lot",
]}
swc_config = {version = "0.1.1", path = "../swc_config"}
swc_ecma_ast = {version = "0.89.0", path = "../swc_ecma_ast"}
swc_ecma_codegen = {version = "0.120.0", path = "../swc_ecma_codegen"}
swc_ecma_ext_transforms = {version = "0.84.0", path = "../swc_ecma_ext_transforms"}
swc_ecma_lints = {version = "0.57.0", path = "../swc_ecma_lints"}
swc_ecma_loader = {version = "0.38.0", path = "../swc_ecma_loader", features = [
] }
swc_config = { version = "0.1.1", path = "../swc_config" }
swc_ecma_ast = { version = "0.89.0", path = "../swc_ecma_ast" }
swc_ecma_codegen = { version = "0.120.0", path = "../swc_ecma_codegen" }
swc_ecma_ext_transforms = { version = "0.84.0", path = "../swc_ecma_ext_transforms" }
swc_ecma_lints = { version = "0.57.0", path = "../swc_ecma_lints" }
swc_ecma_loader = { version = "0.38.0", path = "../swc_ecma_loader", features = [
"cache",
"node",
"tsc",
]}
swc_ecma_minifier = {version = "0.142.0", path = "../swc_ecma_minifier"}
swc_ecma_parser = {version = "0.116.0", path = "../swc_ecma_parser"}
swc_ecma_preset_env = {version = "0.156.0", path = "../swc_ecma_preset_env"}
swc_ecma_transforms = {version = "0.181.0", path = "../swc_ecma_transforms", features = [
] }
swc_ecma_minifier = { version = "0.142.0", path = "../swc_ecma_minifier" }
swc_ecma_parser = { version = "0.116.0", path = "../swc_ecma_parser" }
swc_ecma_preset_env = { version = "0.156.0", path = "../swc_ecma_preset_env" }
swc_ecma_transforms = { version = "0.181.0", path = "../swc_ecma_transforms", features = [
"compat",
"module",
"optimization",
"proposal",
"react",
"typescript",
]}
swc_ecma_transforms_base = {version = "0.102.0", path = "../swc_ecma_transforms_base"}
swc_ecma_transforms_compat = {version = "0.120.0", path = "../swc_ecma_transforms_compat"}
swc_ecma_transforms_optimization = {version = "0.150.0", path = "../swc_ecma_transforms_optimization"}
swc_ecma_utils = {version = "0.98.0", path = "../swc_ecma_utils"}
swc_ecma_visit = {version = "0.75.0", path = "../swc_ecma_visit"}
swc_ecmascript = {version = "0.186.0", path = "../swc_ecmascript"}
swc_error_reporters = {version = "0.10.0", path = "../swc_error_reporters"}
swc_node_comments = {version = "0.13.0", path = "../swc_node_comments"}
swc_plugin_proxy = {version = "0.17.0", path = "../swc_plugin_proxy", optional = true}
swc_plugin_runner = {version = "0.70.0", path = "../swc_plugin_runner", optional = true, default-features = false}
swc_timer = {version = "0.14.0", path = "../swc_timer"}
swc_visit = {version = "0.5.1", path = "../swc_visit"}
] }
swc_ecma_transforms_base = { version = "0.102.0", path = "../swc_ecma_transforms_base" }
swc_ecma_transforms_compat = { version = "0.120.0", path = "../swc_ecma_transforms_compat" }
swc_ecma_transforms_optimization = { version = "0.150.0", path = "../swc_ecma_transforms_optimization" }
swc_ecma_utils = { version = "0.98.0", path = "../swc_ecma_utils" }
swc_ecma_visit = { version = "0.75.0", path = "../swc_ecma_visit" }
swc_error_reporters = { version = "0.10.0", path = "../swc_error_reporters" }
swc_node_comments = { version = "0.13.0", path = "../swc_node_comments" }
swc_plugin_proxy = { version = "0.17.0", path = "../swc_plugin_proxy", optional = true }
swc_plugin_runner = { version = "0.70.0", path = "../swc_plugin_runner", optional = true, default-features = false }
swc_timer = { version = "0.14.0", path = "../swc_timer" }
swc_visit = { version = "0.5.1", path = "../swc_visit" }
tracing = "0.1.32"
[dependencies.napi-derive]
default-features = false
features = ["type-def"]
optional = true
version = "2.0.0"
[dependencies.napi-derive]
default-features = false
features = ["type-def"]
optional = true
version = "2.0.0"
[dependencies.napi]
default-features = false
features = ["napi3"]
optional = true
version = "2.0.0"
[dependencies.napi]
default-features = false
features = ["napi3"]
optional = true
version = "2.0.0"
[dev-dependencies]
ansi_term = "0.12"
criterion = "0.3"
rayon = "1.5.1"
swc_ecma_lints = {version = "0.57.0", path = "../swc_ecma_lints", features = [
swc_ecma_lints = { version = "0.57.0", path = "../swc_ecma_lints", features = [
"non_critical_lints",
]}
swc_ecma_testing = {version = "0.13.0", path = "../swc_ecma_testing"}
swc_node_base = {version = "0.5.0", path = "../swc_node_base"}
testing = {version = "0.28.0", path = "../testing"}
] }
swc_ecma_testing = { version = "0.13.0", path = "../swc_ecma_testing" }
swc_node_base = { version = "0.5.0", path = "../swc_node_base" }
testing = { version = "0.28.0", path = "../testing" }
walkdir = "2"
[[example]]
@ -118,12 +124,12 @@ name = "transform"
[[bench]]
harness = false
name = "bugs"
name = "bugs"
[[bench]]
harness = false
name = "minify"
name = "minify"
[[bench]]
harness = false
name = "typescript"
name = "typescript"

View File

@ -19,8 +19,8 @@ use serde::{
};
use swc_atoms::JsWord;
use swc_cached::regex::CachedRegex;
pub use swc_common::chain;
use swc_common::{
chain,
collections::{AHashMap, AHashSet},
comments::SingleThreadedComments,
errors::Handler,

View File

@ -9,7 +9,7 @@
//!
//! ## Dependency version management
//!
//! `swc` has [swc_ecmascript](https://docs.rs/swc_ecmascript) and [swc_css](https://docs.rs/swc_css), which re-exports required modules.
//! `swc` has [swc_css](https://docs.rs/swc_css), which re-exports required modules.
//!
//! ## Testing
//!
@ -109,8 +109,7 @@
#![cfg_attr(docsrs, feature(doc_cfg))]
pub extern crate swc_atoms as atoms;
pub extern crate swc_common as common;
pub extern crate swc_ecmascript as ecmascript;
extern crate swc_common as common;
use std::{
env,

View File

@ -1,21 +1,21 @@
[package]
authors = ["강동윤 <kdy1997.dev@gmail.com>", "OJ Kwon <kwon.ohjoong@gmail.com>"]
authors = ["강동윤 <kdy1997.dev@gmail.com>", "OJ Kwon <kwon.ohjoong@gmail.com>"]
description = "Commandline for SWC"
edition = "2021"
include = ["Cargo.toml", "src/**/*.rs"]
license = "Apache-2.0"
name = "swc_cli"
repository = "https://github.com/swc-project/swc.git"
version = "0.86.0"
edition = "2021"
include = ["Cargo.toml", "src/**/*.rs"]
license = "Apache-2.0"
name = "swc_cli"
repository = "https://github.com/swc-project/swc.git"
version = "0.86.0"
[[bin]]
bench = false
name = "swc"
path = "./src/main.rs"
name = "swc"
path = "./src/main.rs"
[features]
default = []
plugin = ["swc/plugin", "swc_core/plugin_transform_host_native"]
plugin = ["swc_core/plugin_transform_host_native"]
[dependencies]
anyhow = "1.0.53"
@ -26,14 +26,17 @@ rayon = "1"
relative-path = "1.6.1"
serde = { version = "1", features = ["derive"] }
serde_json = { version = "1", features = ["unbounded_depth"] }
swc = { version = "0.212.0", path = "../swc" }
swc_core = { path = "../swc_core", features = ["trace_macro", "common"] }
swc_core = { version = "0.2.0", path = "../swc_core", features = [
"trace_macro",
"common_concurrent",
"base",
] }
tracing = "0.1.32"
tracing-chrome = "0.5.0"
tracing-futures = "0.2.5"
tracing-subscriber = { version = "0.3.9", features = ["env-filter"] }
walkdir = "2"
[dependencies.path-absolutize]
features = ["once_cell_cache"]
version = "3.0.11"
[dependencies.path-absolutize]
features = ["once_cell_cache"]
version = "3.0.11"

View File

@ -11,11 +11,11 @@ use glob::glob;
use path_absolutize::Absolutize;
use rayon::prelude::*;
use relative_path::RelativePath;
use swc::{
config::{Config, ConfigFile, Options},
try_with_handler, Compiler, HandlerOpts, TransformOutput,
};
use swc_core::{
base::{
config::{Config, ConfigFile, Options},
try_with_handler, Compiler, HandlerOpts, TransformOutput,
},
common::{errors::ColorConfig, sync::Lazy, FileName, FilePathMapping, SourceFile, SourceMap},
trace_macro::swc_trace,
};

View File

@ -1,15 +1,33 @@
[package]
authors = ["강동윤 <kdy1997.dev@gmail.com>", "OJ Kwon <kwon.ohjoong@gmail.com>"]
authors = ["강동윤 <kdy1997.dev@gmail.com>", "OJ Kwon <kwon.ohjoong@gmail.com>"]
description = "TBD"
edition = "2021"
license = "Apache-2.0"
name = "swc_core"
repository = "https://github.com/swc-project/swc.git"
version = "0.2.0"
edition = "2021"
license = "Apache-2.0"
name = "swc_core"
repository = "https://github.com/swc-project/swc.git"
version = "0.2.0"
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
[package.metadata.docs.rs]
features = [
"common_perf",
"allocator_node",
"base",
"base_node",
"common",
"common_concurrent",
"visit",
"quote",
"utils",
"transforms",
"bundler",
"loader",
"ast",
"trace_macro",
"plugin_transform",
"plugin_transform_host_js",
"plugin_transform_host_native",
]
rustdoc-args = ["--cfg", "docsrs"]
[features]
@ -19,9 +37,21 @@ rustdoc-args = ["--cfg", "docsrs"]
## Flags to opt into certain optimizations. In most cases this won't expose new interfaces,
## but changes internal logics to perform differently. These flag should be turned on in combination with
## actual features. Refer build.rs for more details.
perf = ["swc_common/perf"]
# swc_common/perf
common_perf = ["swc_common/perf"]
# configures specific memory allocator.
# node.js binding should depend on this.
allocator_node = ["swc_node_base"]
## General
# Enable swc reexports. To avoid confusion between swc_core namespace,
# it is named as 'base' instead.
base = ["__base"]
base_concurrent = ["__base", "swc/concurrent"]
base_node = ["__base", "swc/node"]
# Enable swc_common reexports.
#
# In most cases, top-level features (i.e plugin, or plugin_host) will include this, so no need to
@ -30,11 +60,29 @@ perf = ["swc_common/perf"]
# refer binding_core_wasm for example: it has plugin_transform_host feature, but
# it has to be a feature to be enabled by compile time flag to avoid cargo's feature collision,
# while it also need to access 'common' exports by default for cargo check / or clippy.
common = ["swc_common"]
common = ["__common"]
# TODO: internally concurrent / perf refers to the same feature (`parking_lot`)
# - can we consolidate them?
common_concurrent = ["__common", "swc_common/concurrent"]
# Enable swc_ecma_visit
visit = ["swc_ecma_visit"]
# Enable `quote!` macro support.
quote = ["swc_ecma_quote"]
# Enable swc_ecma_utils
utils = ["__utils"]
# Enable swc_ecma_transforms base features
transforms = ["__transforms"]
# Enable swc_bundler
bundler = ["swc_bundler"]
# Enable swc_ecma_loader
loader = ["swc_ecma_loader"]
# Enable swc_ecma_ast / swc_atoms support.
# TODO: currently both are enabled at once, we may want to separate them.
ast = ["swc_ecma_ast", "swc_atoms"]
@ -52,23 +100,17 @@ plugin_transform = ["__plugin_transform", "__plugin_transform_schema_v1"]
# native feature is for the host environment does not have, or cannot access
# to the wasm runtime (i.e cli, or @swc/core node bindings).
# js feature is for the environment can access wasm runtime (i.e @swc/wasm)
plugin_transform_host_native = [
# Dependent features
"__plugin_transform_host",
"__plugin_transform_host_schema_v1",
# Enable optional packages
"swc_plugin_runner/filesystem_cache",
"wasmer/default",
"wasmer-wasi/default",
]
plugin_transform_host_js = [
# Dependent features
"__plugin_transform_host",
"__plugin_transform_host_schema_v1",
# Enable optional packages
"swc_plugin_runner/memory_cache",
"wasmer/js-default",
"wasmer-wasi/js-default",
"__plugin_transform_env_js",
]
plugin_transform_host_native = [
# Dependent features
"__plugin_transform_host",
"__plugin_transform_host_schema_v1",
"__plugin_transform_env_native",
]
### Internal features that public features are relying on.
@ -79,26 +121,32 @@ plugin_transform_host_js = [
# This'll be automatically selected via transform_plugin features,
# SWC upstream decides which version to be used for specific version of
# swc_core.
__plugin_transform_schema_v1 = ["swc_common/plugin_transform_schema_v1"]
__plugin_transform_host_schema_v1 = [
# Dependent features
"__plugin_transform_schema_v1",
# Enable optional features
"swc/plugin_transform_schema_v1",
"swc_plugin_runner/plugin_transform_schema_v1",
]
__plugin_transform_schema_v1 = ["swc_common/plugin_transform_schema_v1"]
# Do not use: testing purpose only
__plugin_transform_schema_vtest = ["swc_common/plugin_transform_schema_vtest"]
__plugin_transform_host_schema_vtest = [
# Dependent features
"__plugin_transform_schema_vtest",
# Enable optional features
"swc/plugin_transform_schema_vtest",
"swc_plugin_runner/plugin_transform_schema_vtest",
]
__plugin_transform_schema_vtest = ["swc_common/plugin_transform_schema_vtest"]
## Plugins
# Internal flags for any transform plugin feature
__plugin_transform = [
# Dependent features
"__visit",
"common",
"visit",
"__common",
"ast",
# Enable optional packages
"swc_ecma_ast/rkyv-impl",
@ -110,7 +158,26 @@ __plugin_transform = [
]
# Internal flags for any transform plugin host feature
__plugin_transform_host = ["common"]
__plugin_transform_host = [
# Dependent features
"__common",
# Enable optional packages
# TODO: we may simply flag around downlevel plugin feature
"swc_plugin_proxy/plugin-rt",
"swc/plugin",
]
# Internal flags to control plugin environment
__plugin_transform_env_native = [
"swc_plugin_runner/filesystem_cache",
"wasmer/default",
"wasmer-wasi/default",
]
__plugin_transform_env_js = [
"swc_plugin_runner/memory_cache",
"wasmer/js-default",
"wasmer-wasi/js-default",
]
# Do not use: testing purpose only
# Force enable different version of AST schema
@ -120,23 +187,33 @@ __plugin_transform_schema_test = [
]
## Common
__visit = ["swc_ecma_visit"]
__base = ["swc"]
__common = ["swc_common"]
__transforms = ["swc_ecma_transforms"]
__utils = ["swc_ecma_utils"]
[dependencies]
# 3rd party dependencies
once_cell = { optional = true, version = "1.13.0" }
wasmer = { optional = true, version = "2.3.0", default-features = false }
once_cell = { optional = true, version = "1.13.0" }
wasmer = { optional = true, version = "2.3.0", default-features = false }
wasmer-wasi = { optional = true, version = "2.3.0", default-features = false }
# swc_* dependencies
swc_atoms = { optional = true, version = "0.3.1", path = "../swc_atoms" }
swc_common = { optional = true, version = "0.26.0", path = "../swc_common" }
swc_ecma_ast = { optional = true, version = "0.89.1", path = "../swc_ecma_ast" }
swc_ecma_quote = { optional = true, version = "0.30.0", path = "../swc_ecma_quote" }
swc_ecma_visit = { optional = true, version = "0.75.0", path = "../swc_ecma_visit" }
swc_plugin = { optional = true, version = "0.89.0", path = "../swc_plugin" }
swc_plugin_macro = { optional = true, version = "0.9.0", path = "../swc_plugin_macro" }
swc_plugin_proxy = { optional = true, version = "0.17.0", path = "../swc_plugin_proxy" }
swc_trace_macro = { optional = true, version = "0.1.0", path = "../swc_trace_macro" }
swc = { optional = true, version = "0.212.3", path = "../swc" }
swc_atoms = { optional = true, version = "0.3.1", path = "../swc_atoms" }
swc_bundler = { optional = true, version = "0.175.0", path = "../swc_bundler" }
swc_common = { optional = true, version = "0.26.0", path = "../swc_common" }
swc_ecma_ast = { optional = true, version = "0.89.1", path = "../swc_ecma_ast" }
swc_ecma_loader = { optional = true, version = "0.38.0", path = "../swc_ecma_loader" }
swc_ecma_parser = { optional = true, version = "0.116.0", path = "../swc_ecma_parser" }
swc_ecma_quote = { optional = true, version = "0.30.0", path = "../swc_ecma_quote" }
swc_ecma_transforms = { optional = true, version = "0.181.0", path = "../swc_ecma_transforms" }
swc_ecma_utils = { optional = true, version = "0.98.0", path = "../swc_ecma_utils" }
swc_ecma_visit = { optional = true, version = "0.75.0", path = "../swc_ecma_visit" }
swc_node_base = { optional = true, version = "0.5.5", path = "../swc_node_base" }
swc_plugin = { optional = true, version = "0.89.0", path = "../swc_plugin" }
swc_plugin_macro = { optional = true, version = "0.9.0", path = "../swc_plugin_macro" }
swc_plugin_proxy = { optional = true, version = "0.17.0", path = "../swc_plugin_proxy" }
swc_trace_macro = { optional = true, version = "0.1.0", path = "../swc_trace_macro" }
# TODO: eventually swc_plugin_runner needs to remove default features
swc_plugin_runner = { optional = true, version = "0.70.0", path = "../swc_plugin_runner", default-features = false }

View File

@ -12,6 +12,15 @@ compile_error!(
run plugin, use 'plugin_transform_host_*' instead."
);
#[cfg(all(feature = "__plugin_transform", feature = "common_concurrent"))]
compile_error!("plugin transform cannot enable concurrent mode.");
#[cfg(all(feature = "transforms", feature = "transforms_concurrent"))]
compile_error!(
"'transforms' and 'transforms_concurrent' features are mutually exclusive. Please choose only \
one feature."
);
fn main() {
/* noop */
}

View File

@ -28,15 +28,22 @@ pub mod atoms {
}
// visit* interfaces
#[cfg(any(docsrs, feature = "__visit"))]
#[cfg_attr(docsrs, doc(cfg(feature = "__visit")))]
#[cfg(any(docsrs, feature = "visit"))]
#[cfg_attr(docsrs, doc(cfg(feature = "visit")))]
pub mod visit {
pub use swc_ecma_visit::*;
}
// swc features
#[cfg(any(docsrs, feature = "__base"))]
#[cfg_attr(docsrs, doc(cfg(feature = "__base")))]
pub mod base {
pub use swc::*;
}
// swc_common features
#[cfg(any(docsrs, feature = "common"))]
#[cfg_attr(docsrs, doc(cfg(feature = "common")))]
#[cfg(any(docsrs, feature = "__common"))]
#[cfg_attr(docsrs, doc(cfg(feature = "__common")))]
pub mod common {
pub use swc_common::*;
}
@ -54,3 +61,28 @@ pub mod plugin_runner {
pub mod trace_macro {
pub use swc_trace_macro::*;
}
// swc_ecma_transforms
#[cfg(any(docsrs, feature = "__transforms"))]
#[cfg_attr(docsrs, doc(cfg(feature = "__transforms")))]
pub mod transforms {
pub use swc_ecma_transforms::*;
}
// swc_bundler
#[cfg(any(docsrs, feature = "bundler"))]
#[cfg_attr(docsrs, doc(cfg(feature = "bundler")))]
pub mod bundler {
pub use swc_bundler::*;
}
// swc_ecma_loader
#[cfg(any(docsrs, feature = "loader"))]
#[cfg_attr(docsrs, doc(cfg(feature = "loader")))]
pub mod loader {
pub use swc_ecma_loader::*;
}
#[cfg(any(docsrs, feature = "allocator_node"))]
#[cfg_attr(docsrs, doc(cfg(feature = "allocator_node")))]
extern crate swc_node_base;

View File

@ -0,0 +1,3 @@
# Deprecated
In a effort to create a SDK for generic SWC custom runtime (https://github.com/swc-project/swc/discussions/5244), this package is being deprecated. Please refer `swc_core` instead (https://crates.io/crates/swc_core).

View File

@ -646,7 +646,7 @@ dependencies = [
[[package]]
name = "swc_core"
version = "0.1.1"
version = "0.2.0"
dependencies = [
"once_cell",
"swc_atoms",

View File

@ -1,6 +1,6 @@
module.exports = {
napi: {
name: "swc_host_plugin_transform_schema_vtest",
name: "swc_host___plugin_transform_vtest",
triples: {
defaults: true,
additional: [

View File

@ -30,7 +30,7 @@ const buildHost = async (feature) => {
"binding_core_node",
"-p",
"binding_core_node",
`--cargo-flags=--no-default-features --features swc_v1 --features plugin --features ${feature}`,
`--cargo-flags=--no-default-features --features swc_v1 --features ${feature}`,
"--config",
`./node-swc/e2e/fixtures/napi.host.${feature}.config.js`,
];
@ -70,7 +70,7 @@ describe("Plugins", () => {
plugin: ["plugin_transform_schema_v1"],
},
{
host: "plugin_transform_schema_vtest",
host: "__plugin_transform_vtest",
plugin: [
// TODO: reenable once new packages are published
// Note: this test runs against latest-published version of the plugin,