Skip to content

Discussion: split the crate into a Node-API-free core and a thin #[napi] crate for embedding #807

Closed

Description

@fengmk2

This is a discussion issue: would you accept splitting oxc-node into a Node-API-free core crate and a thin #[napi] crate on top, as oxc already does with oxc_transformer + oxc_transform_napi and oxc_resolver + oxc_resolver_napi?

Motivation

Vite+ compiles oxc-node's crate into its own Node-API addon, next to rolldown_binding, so that vpx script.ts runs oxc-node's hooks from the binary it already ships (vite-plus PR voidzero-dev/vite-plus#2936). napi-rs registers every #[napi] item of every linked crate into one module. oxc-node's exports collide with those of oxc_transform_napi, which Rolldown's binding links: both export transform and have a TransformTask. The duplicate export silently overwrites the other.

To link it today, Vite+ carries a patch that:

With a core crate, an embedder depends on the core and writes its own bindings, and the napi crate keeps today's @oxc-node/core API unchanged. The allocator and module_init would stay in the napi crate.

What the core would need

create_resolve and load take Node-API types directly: Function for nextResolve/nextLoad, PromiseRaw for asynchronous results, and Env. The core would need a small abstraction over "call the next hook, possibly asynchronously", with the napi crate adapting it. OxcTransformer, the tsconfig source, and the format detection look independent of napi already.

A lighter alternative is a feature that sets a namespace through cfg_attr on each item, but that adds two attributes per item and only fixes the name collision.

Happy to help with the split if the direction works for you.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions