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

feat(oxc): add oxc_napi crate #7612

Merged
merged 1 commit into from
Dec 3, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 16 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
10 changes: 0 additions & 10 deletions crates/oxc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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"]
Expand All @@ -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
12 changes: 0 additions & 12 deletions crates/oxc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
#[cfg(feature = "full")]
mod compiler;

#[cfg(feature = "napi")]
pub mod napi;

#[cfg(feature = "full")]
pub use compiler::{Compiler, CompilerInterface};

Expand Down Expand Up @@ -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)]
Expand Down
11 changes: 0 additions & 11 deletions crates/oxc/src/napi/mod.rs

This file was deleted.

33 changes: 33 additions & 0 deletions crates/oxc_napi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 }
7 changes: 7 additions & 0 deletions crates/oxc_napi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub mod parse;

pub mod source_map;

pub mod isolated_declarations;

pub mod transform;
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion napi/parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion napi/parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions napi/transform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ doctest = false

[dependencies]
oxc = { workspace = true, features = ["full", "napi"] }
oxc_napi = { workspace = true }

napi = { workspace = true }
napi-derive = { workspace = true }
Expand Down
8 changes: 4 additions & 4 deletions napi/transform/src/isolated_declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion napi/transform/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Expand Down
8 changes: 4 additions & 4 deletions napi/transform/src/transformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading