From bd977cf7427144b349e264545cad3344ee556dfc Mon Sep 17 00:00:00 2001 From: Boshen <1430279+Boshen@users.noreply.github.com> Date: Tue, 3 Dec 2024 14:02:47 +0000 Subject: [PATCH] feat(oxc): add `oxc_napi` crate (#7612) --- .cargo/config.toml | 28 ---------------- Cargo.lock | 20 ++++++++--- Cargo.toml | 1 + crates/oxc/Cargo.toml | 10 ------ crates/oxc/src/lib.rs | 12 ------- crates/oxc/src/napi/mod.rs | 11 ------- crates/oxc_napi/Cargo.toml | 33 +++++++++++++++++++ .../src}/isolated_declarations.rs | 0 crates/oxc_napi/src/lib.rs | 7 ++++ .../{oxc/src/napi => oxc_napi/src}/parse.rs | 0 .../src/napi => oxc_napi/src}/source_map.rs | 0 .../src/napi => oxc_napi/src}/transform.rs | 0 napi/parser/Cargo.toml | 3 +- napi/parser/src/lib.rs | 2 +- napi/transform/Cargo.toml | 1 + napi/transform/src/isolated_declaration.rs | 8 ++--- napi/transform/src/lib.rs | 2 +- napi/transform/src/transformer.rs | 8 ++--- 18 files changed, 70 insertions(+), 76 deletions(-) delete mode 100644 crates/oxc/src/napi/mod.rs create mode 100644 crates/oxc_napi/Cargo.toml rename crates/{oxc/src/napi => oxc_napi/src}/isolated_declarations.rs (100%) create mode 100644 crates/oxc_napi/src/lib.rs rename crates/{oxc/src/napi => oxc_napi/src}/parse.rs (100%) rename crates/{oxc/src/napi => oxc_napi/src}/source_map.rs (100%) rename crates/{oxc/src/napi => oxc_napi/src}/transform.rs (100%) diff --git a/.cargo/config.toml b/.cargo/config.toml index 1394a0b0b1365..239cf0e41e2f8 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -10,31 +10,3 @@ rule = "run -p rulegen" # Build oxlint in release mode oxlint = "build --release --bin oxlint --features allocator" - -# Fix napi breaking in test environment -# To be able to run unit tests on macOS, support compilation to 'x86_64-apple-darwin'. -[target.'cfg(target_vendor = "apple")'] -rustflags = ["-C", "link-args=-Wl,-undefined,dynamic_lookup,-no_fixup_chains"] - -# To be able to run unit tests on Linux, support compilation to 'x86_64-unknown-linux-gnu'. -[target.'cfg(target_os = "linux")'] -rustflags = ["-C", "link-args=-Wl,--warn-unresolved-symbols"] - -# To be able to run unit tests on Windows, support compilation to 'x86_64-pc-windows-msvc'. -# Use Hybrid CRT to reduce the size of the binary (Coming by default with Windows 10 and later versions). -[target.'cfg(target_os = "windows")'] -rustflags = [ - "-C", - "link-args=/FORCE", - "-C", - "link-args=/NODEFAULTLIB:libucrt.lib", - "-C", - "link-args=/DEFAULTLIB:ucrt.lib", -] - -[target.x86_64-pc-windows-msvc] -rustflags = ["-C", "target-feature=+crt-static"] -[target.i686-pc-windows-msvc] -rustflags = ["-C", "target-feature=+crt-static"] -[target.aarch64-pc-windows-msvc] -rustflags = ["-C", "target-feature=+crt-static"] diff --git a/Cargo.lock b/Cargo.lock index 224f379c934c1..51118298c9c16 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1385,7 +1385,6 @@ name = "oxc" version = "0.38.0" dependencies = [ "napi", - "napi-derive", "oxc_allocator", "oxc_ast", "oxc_cfg", @@ -1397,11 +1396,9 @@ dependencies = [ "oxc_parser", "oxc_regular_expression", "oxc_semantic", - "oxc_sourcemap", "oxc_span", "oxc_syntax", "oxc_transformer", - "rustc-hash", ] [[package]] @@ -1797,6 +1794,20 @@ dependencies = [ "rustc-hash", ] +[[package]] +name = "oxc_napi" +version = "0.38.0" +dependencies = [ + "napi", + "napi-derive", + "oxc_isolated_declarations", + "oxc_sourcemap", + "oxc_span", + "oxc_syntax", + "oxc_transformer", + "rustc-hash", +] + [[package]] name = "oxc_parser" version = "0.38.0" @@ -1828,6 +1839,7 @@ dependencies = [ "napi-build", "napi-derive", "oxc", + "oxc_napi", "serde_json", ] @@ -1940,7 +1952,6 @@ dependencies = [ "base64-simd", "cfg-if", "cow-utils", - "rayon", "rustc-hash", "serde", "serde_json", @@ -2025,6 +2036,7 @@ dependencies = [ "napi-build", "napi-derive", "oxc", + "oxc_napi", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index b7611448fad97..c0deb11531b74 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -91,6 +91,7 @@ oxc_estree = { version = "0.38.0", path = "crates/oxc_estree" } oxc_isolated_declarations = { version = "0.38.0", path = "crates/oxc_isolated_declarations" } oxc_mangler = { version = "0.38.0", path = "crates/oxc_mangler" } oxc_minifier = { version = "0.38.0", path = "crates/oxc_minifier" } +oxc_napi = { version = "0.38.0", path = "crates/oxc_napi" } oxc_parser = { version = "0.38.0", path = "crates/oxc_parser" } oxc_regular_expression = { version = "0.38.0", path = "crates/oxc_regular_expression" } oxc_semantic = { version = "0.38.0", path = "crates/oxc_semantic" } diff --git a/crates/oxc/Cargo.toml b/crates/oxc/Cargo.toml index dcf66360bc97f..be2e600cb7a8a 100644 --- a/crates/oxc/Cargo.toml +++ b/crates/oxc/Cargo.toml @@ -38,15 +38,11 @@ oxc_isolated_declarations = { workspace = true, optional = true } oxc_mangler = { workspace = true, optional = true } oxc_minifier = { workspace = true, optional = true } oxc_semantic = { workspace = true, optional = true } -oxc_sourcemap = { workspace = true, optional = true } oxc_span = { workspace = true } oxc_syntax = { workspace = true } oxc_transformer = { workspace = true, optional = true } napi = { workspace = true, optional = true, features = ["async"] } -napi-derive = { workspace = true, optional = true } - -rustc-hash = { workspace = true, optional = true } [features] full = [ @@ -56,11 +52,9 @@ full = [ "semantic", "transformer", "isolated_declarations", - "sourcemap", "cfg", ] -parser = [] # for napi semantic = ["oxc_semantic"] transformer = ["oxc_transformer"] minifier = ["oxc_mangler", "oxc_minifier"] @@ -76,11 +70,7 @@ serialize = [ "oxc_syntax/serialize", ] -sourcemap = ["oxc_sourcemap"] -sourcemap_concurrent = ["oxc_sourcemap/concurrent", "sourcemap"] - wasm = ["oxc_transformer/wasm"] -napi = ["dep:napi", "dep:napi-derive", "dep:rustc-hash"] [package.metadata.docs.rs] all-features = true diff --git a/crates/oxc/src/lib.rs b/crates/oxc/src/lib.rs index 8a3fb70f1cf79..07f30f0955e82 100644 --- a/crates/oxc/src/lib.rs +++ b/crates/oxc/src/lib.rs @@ -3,9 +3,6 @@ #[cfg(feature = "full")] mod compiler; -#[cfg(feature = "napi")] -pub mod napi; - #[cfg(feature = "full")] pub use compiler::{Compiler, CompilerInterface}; @@ -112,15 +109,6 @@ pub mod isolated_declarations { pub use oxc_isolated_declarations::*; } -#[cfg(feature = "sourcemap")] -pub mod sourcemap { - //! Source Maps - //! - //! See the [`oxc_sourcemap` module-level documentation](oxc_sourcemap) for more information. - #[doc(inline)] - pub use oxc_sourcemap::*; -} - #[cfg(feature = "cfg")] pub mod cfg { #[doc(inline)] diff --git a/crates/oxc/src/napi/mod.rs b/crates/oxc/src/napi/mod.rs deleted file mode 100644 index d61a33ec2eb00..0000000000000 --- a/crates/oxc/src/napi/mod.rs +++ /dev/null @@ -1,11 +0,0 @@ -#[cfg(feature = "parser")] -pub mod parse; - -#[cfg(feature = "sourcemap")] -pub mod source_map; - -#[cfg(feature = "isolated_declarations")] -pub mod isolated_declarations; - -#[cfg(feature = "transformer")] -pub mod transform; diff --git a/crates/oxc_napi/Cargo.toml b/crates/oxc_napi/Cargo.toml new file mode 100644 index 0000000000000..08d21000bcf6f --- /dev/null +++ b/crates/oxc_napi/Cargo.toml @@ -0,0 +1,33 @@ +[package] +name = "oxc_napi" +version = "0.38.0" +authors.workspace = true +categories.workspace = true +edition.workspace = true +homepage.workspace = true +include = ["/src"] +keywords.workspace = true +license.workspace = true +publish = false +repository.workspace = true +rust-version.workspace = true +description.workspace = true + +[lints] +workspace = true + +[lib] +test = false +doctest = false + +[dependencies] +oxc_isolated_declarations = { workspace = true } +oxc_sourcemap = { workspace = true } +oxc_span = { workspace = true } +oxc_syntax = { workspace = true } +oxc_transformer = { workspace = true } + +napi = { workspace = true } +napi-derive = { workspace = true } + +rustc-hash = { workspace = true } diff --git a/crates/oxc/src/napi/isolated_declarations.rs b/crates/oxc_napi/src/isolated_declarations.rs similarity index 100% rename from crates/oxc/src/napi/isolated_declarations.rs rename to crates/oxc_napi/src/isolated_declarations.rs diff --git a/crates/oxc_napi/src/lib.rs b/crates/oxc_napi/src/lib.rs new file mode 100644 index 0000000000000..0b5958cce77bc --- /dev/null +++ b/crates/oxc_napi/src/lib.rs @@ -0,0 +1,7 @@ +pub mod parse; + +pub mod source_map; + +pub mod isolated_declarations; + +pub mod transform; diff --git a/crates/oxc/src/napi/parse.rs b/crates/oxc_napi/src/parse.rs similarity index 100% rename from crates/oxc/src/napi/parse.rs rename to crates/oxc_napi/src/parse.rs diff --git a/crates/oxc/src/napi/source_map.rs b/crates/oxc_napi/src/source_map.rs similarity index 100% rename from crates/oxc/src/napi/source_map.rs rename to crates/oxc_napi/src/source_map.rs diff --git a/crates/oxc/src/napi/transform.rs b/crates/oxc_napi/src/transform.rs similarity index 100% rename from crates/oxc/src/napi/transform.rs rename to crates/oxc_napi/src/transform.rs diff --git a/napi/parser/Cargo.toml b/napi/parser/Cargo.toml index d2e1b43b3775f..1a26303e4892f 100644 --- a/napi/parser/Cargo.toml +++ b/napi/parser/Cargo.toml @@ -21,7 +21,8 @@ test = false doctest = false [dependencies] -oxc = { workspace = true, features = ["napi", "serialize", "parser"] } +oxc = { workspace = true, features = ["napi", "serialize"] } +oxc_napi = { workspace = true } napi = { workspace = true, features = ["async"] } napi-derive = { workspace = true } diff --git a/napi/parser/src/lib.rs b/napi/parser/src/lib.rs index 016eaf9dec8eb..cdf78570f30a9 100644 --- a/napi/parser/src/lib.rs +++ b/napi/parser/src/lib.rs @@ -11,10 +11,10 @@ use oxc::{ allocator::Allocator, ast::CommentKind, diagnostics::{Error, NamedSource}, - napi::parse::{Comment, EcmaScriptModule, ParseResult, ParserOptions}, parser::{ParseOptions, Parser, ParserReturn}, span::SourceType, }; +use oxc_napi::parse::{Comment, EcmaScriptModule, ParseResult, ParserOptions}; fn get_source_type(filename: &str, options: &ParserOptions) -> SourceType { match options.lang.as_deref() { diff --git a/napi/transform/Cargo.toml b/napi/transform/Cargo.toml index 7128b2cab874e..d7e414d758acc 100644 --- a/napi/transform/Cargo.toml +++ b/napi/transform/Cargo.toml @@ -22,6 +22,7 @@ doctest = false [dependencies] oxc = { workspace = true, features = ["full", "napi"] } +oxc_napi = { workspace = true } napi = { workspace = true } napi-derive = { workspace = true } diff --git a/napi/transform/src/isolated_declaration.rs b/napi/transform/src/isolated_declaration.rs index f8aa5938288ee..5983cf0cc84c7 100644 --- a/napi/transform/src/isolated_declaration.rs +++ b/napi/transform/src/isolated_declaration.rs @@ -6,13 +6,13 @@ use oxc::{ allocator::Allocator, codegen::{CodeGenerator, CodegenOptions}, isolated_declarations::IsolatedDeclarations, - napi::{ - isolated_declarations::{IsolatedDeclarationsOptions, IsolatedDeclarationsResult}, - source_map::SourceMap, - }, parser::Parser, span::SourceType, }; +use oxc_napi::{ + isolated_declarations::{IsolatedDeclarationsOptions, IsolatedDeclarationsResult}, + source_map::SourceMap, +}; use crate::errors::wrap_diagnostics; diff --git a/napi/transform/src/lib.rs b/napi/transform/src/lib.rs index ad8e001a33cb3..a4568decfefcd 100644 --- a/napi/transform/src/lib.rs +++ b/napi/transform/src/lib.rs @@ -1,6 +1,6 @@ mod errors; -pub use oxc::napi::{isolated_declarations, transform}; +pub use oxc_napi::{isolated_declarations, transform}; mod isolated_declaration; pub use isolated_declaration::*; diff --git a/napi/transform/src/transformer.rs b/napi/transform/src/transformer.rs index 29886efb6dbeb..54c52748340b1 100644 --- a/napi/transform/src/transformer.rs +++ b/napi/transform/src/transformer.rs @@ -7,14 +7,14 @@ use oxc::{ codegen::CodegenReturn, diagnostics::OxcDiagnostic, isolated_declarations::IsolatedDeclarationsOptions, - napi::{ - source_map::SourceMap, - transform::{TransformOptions, TransformResult}, - }, span::SourceType, transformer::{InjectGlobalVariablesConfig, InjectImport, ReplaceGlobalDefinesConfig}, CompilerInterface, }; +use oxc_napi::{ + source_map::SourceMap, + transform::{TransformOptions, TransformResult}, +}; use crate::errors::wrap_diagnostics;