feat(oxc): add oxc_napi crate (#7612)

This commit is contained in:
Boshen 2024-12-03 14:02:47 +00:00
parent 6af8659624
commit bd977cf742
18 changed files with 70 additions and 76 deletions

View file

@ -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 <https://github.com/napi-rs/napi-rs/issues/1005#issuecomment-1011034770>
# 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"]

20
Cargo.lock generated
View file

@ -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]]

View file

@ -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" }

View file

@ -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

View file

@ -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)]

View file

@ -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;

View file

@ -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 }

View file

@ -0,0 +1,7 @@
pub mod parse;
pub mod source_map;
pub mod isolated_declarations;
pub mod transform;

View file

@ -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 }

View file

@ -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() {

View file

@ -22,6 +22,7 @@ doctest = false
[dependencies]
oxc = { workspace = true, features = ["full", "napi"] }
oxc_napi = { workspace = true }
napi = { workspace = true }
napi-derive = { workspace = true }

View file

@ -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;

View file

@ -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::*;

View file

@ -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;