Skip to content

fix(core): keep the loader initialization APIs for embedders - #895

Merged
Brooooooklyn merged 1 commit into
oxc-project:mainfrom
fengmk2:fix/expose-loader-initialization
Oct 30, 2026
Merged

Brooooooklyn merged 1 commit into
oxc-project:mainfrom
fengmk2:fix/expose-loader-initialization

Conversation

@fengmk2

@fengmk2 fengmk2 commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

With default-features = false, #[cfg(feature = "napi")] removes initialize_loader_js and freeze_tsconfig_js. An embedder then has only the plain functions:

  • initialize_loader does not keep the diagnostic source (setTsconfigPath(), TS_NODE_PROJECT, or OXC_TSCONFIG_PATH).
  • freeze_tsconfig reads the native process environment, not the process.env of the calling JavaScript thread.

The helpers that do both, set_tsconfig_override and LoaderEnvironmentGuard, are private. An embedder therefore cannot write forwarders that match initializeLoader and freezeTsconfig.

This PR uses cfg_attr for the two #[napi] registrations, as the other exports do. The functions now compile with or without the feature, and only their registration depends on it. The embedder list in Cargo.toml now names the _js functions.

🤖 Generated with Claude Code

An embedder that links oxc-node with `default-features = false` cannot
call `initialize_loader_js` or `freeze_tsconfig_js`, because
`#[cfg(feature = "napi")]` removes them. The plain `initialize_loader`
does not keep the diagnostic source, and the plain `freeze_tsconfig`
does not read the calling JavaScript thread's environment. The helpers
that do both are private, so an embedder cannot rebuild the functions.

Use `cfg_attr` for the two `#[napi]` registrations, as the other
exports do. The functions compile either way, and only the
registration depends on the feature.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Brooooooklyn
Brooooooklyn merged commit 0df77b5 into oxc-project:main Oct 30, 2026
67 checks passed
@fengmk2
fengmk2 deleted the fix/expose-loader-initialization branch November 3, 2026 13:19
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.

2 participants