Skip to content

feat(core): gate the #[napi] items and mimalloc behind a napi feature - #831

Merged
Brooooooklyn merged 1 commit into
mainfrom
feat/807-napi-feature
Oct 13, 2026
Merged

Brooooooklyn merged 1 commit into
mainfrom
feat/807-napi-feature

Conversation

@Brooooooklyn

Copy link
Copy Markdown
Member

Summary

Implements the lighter variant of #807: hide the #[napi] items (and mimalloc-safe) behind a napi Cargo feature, so an embedder like Vite+ can link the crate as a library without its exports registering into the host addon's module.

# embedder (Vite+): no registrations, no allocator, no transform/TransformTask collision
oxc-node = { path = "...", default-features = false }
  • napi is on by default — the published @oxc-node/core package, its napi build pipeline, and every test are unchanged.
  • default-features = false drops all ~29 #[napi] registrations (verified: 0 __napi_register* symbols vs ~34 in the default build), module_init, transform_async/TransformTask, and mimalloc-safe (now optional) — covering the name collision and the allocator part of Vite+'s carried patch.
  • napi/napi-derive stay as dependencies: Function, PromiseRaw, Either, Env, and LoadFnOutput are woven through the core signatures (create_resolve, load), so removing them would be the two-crate split the issue discusses instead. An embedder compiles against the same napi 3.x and writes its own thin #[napi] forwarders.
  • The residual contract is documented in the Cargo.toml feature comment: the host must forward detect_runtime_syntax (otherwise using stays lowered on Node ≥ 24) and init_tracing (for OXC_LOG), reuse source()/source_map() for Output, and not redeclare the #[napi(object)] interface names its own .d.ts would gain.

CI

The Lint job now runs cargo check --all-targets --no-default-features (with and without default_global_allocator) and — since cargo check cannot catch a leaked #[napi] (it still compiles) — builds the rlib and asserts it contains no __napi_register symbols.

Test plan

  • cargo check under both configurations, cargo clippy --all-targets --all-features -D warnings, cargo test, pnpm test, vp check all pass.
  • llvm-nm on the embed rlib: 0 __napi_register symbols; default build unchanged at ~34; napi build --platform produces the identical package.

napi-rs registers every #[napi] item of every linked crate into one
module, so oxc-node's exports collide with oxc_transform_napi's when an
embedder compiles both into one addon (#807). A default-on `napi`
feature now gates every registration item, module_init, the async
transform task, and mimalloc-safe: --no-default-features builds a plain
library with zero __napi_register symbols, while the published package
builds exactly as before. napi itself stays a dependency — Function,
PromiseRaw and Either run through the core signatures — and the
feature's doc spells out what an embedder forwards instead.

CI checks the embed configuration and asserts the built rlib carries no
registration symbols, since cargo check alone cannot catch an ungated
#[napi] site.

Refs #807
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T08:23:24.740256Z 58bc788 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Brooooooklyn
Brooooooklyn merged commit 0ab9350 into main Oct 13, 2026
67 checks passed
@Brooooooklyn
Brooooooklyn deleted the feat/807-napi-feature branch October 13, 2026 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant