├── .node-version ├── packages ├── core │ ├── .gitignore │ ├── browser.js │ ├── README.md │ ├── tsconfig.json │ ├── esm.mjs │ ├── wasi-worker-browser.mjs │ ├── register.mjs │ ├── reexport-oxc-runtime.mjs │ ├── wasi-worker.mjs │ ├── oxc-node.wasi-browser.js │ ├── index.d.ts │ ├── oxc-node.wasi.cjs │ ├── CHANGELOG.md │ ├── index.js │ └── package.json ├── condition-dev │ ├── condition-dev.ts │ ├── condition-node.mjs │ ├── condition-require.cjs │ └── package.json ├── integrate-module-bundler │ ├── src │ │ ├── common.d.cts │ │ ├── common.cjs │ │ ├── typescript-cjs │ │ │ ├── index.ts │ │ │ └── package.json │ │ ├── foo.ts │ │ ├── enforce-mts │ │ │ ├── package.json │ │ │ └── index.mts │ │ ├── subdirectory │ │ │ ├── bar.ts │ │ │ ├── baz.ts │ │ │ └── index.ts │ │ ├── compiled.d.ts │ │ ├── component.tsx │ │ ├── compiled.js │ │ ├── babel-generated-double-default │ │ │ ├── index.d.ts │ │ │ ├── package.json │ │ │ └── index.js │ │ ├── nestjs │ │ │ ├── config.ts │ │ │ ├── index.ts │ │ │ ├── app.controller.ts │ │ │ ├── app.module.ts │ │ │ └── app.service.ts │ │ ├── js-module.js │ │ └── index.ts │ ├── tsconfig.json │ └── package.json ├── integrate-module │ ├── src │ │ ├── foo.mts │ │ ├── subdirectory │ │ │ ├── bar.mts │ │ │ ├── baz.mts │ │ │ └── index.mts │ │ ├── compiled.d.ts │ │ ├── component.tsx │ │ ├── compiled.js │ │ ├── js-module.mjs │ │ └── index.ts │ ├── tsconfig.json │ └── package.json ├── integrate-ava │ ├── __tests__ │ │ ├── fixtures │ │ │ ├── source-map-fixture.ts │ │ │ ├── stacktrace-esm.mts │ │ │ ├── stacktrace-esm.ts │ │ │ └── stacktrace-cjs.cts │ │ ├── index.spec.ts │ │ └── cli.spec.ts │ ├── tsconfig.json │ └── package.json ├── bench │ ├── tsconfig.json │ ├── package.json │ └── index.ts └── cli │ ├── tsconfig.json │ ├── rolldown.config.js │ ├── README.md │ ├── package.json │ ├── src │ └── index.ts │ └── CHANGELOG.md ├── .husky └── pre-commit ├── .github ├── FUNDING.yml ├── renovate.json └── workflows │ ├── zizmor.yml │ ├── autofix.yml │ └── CI.yml ├── .oxfmtrc.json ├── rust-toolchain.toml ├── pnpm-workspace.yaml ├── .editorconfig ├── lerna.json ├── justfile ├── tsconfig.json ├── .gitattributes ├── README.md ├── package.json ├── .cargo └── config.toml ├── Cargo.toml ├── .gitignore ├── CHANGELOG.md └── src └── lib.rs /.node-version: -------------------------------------------------------------------------------- 1 | lts/* 2 | -------------------------------------------------------------------------------- /packages/core/.gitignore: -------------------------------------------------------------------------------- 1 | src -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | pnpm lint-staged 2 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [Brooooooklyn, Boshen] 2 | -------------------------------------------------------------------------------- /.oxfmtrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "ignorePatterns": ["pnpm-lock.yaml"] 3 | } 4 | -------------------------------------------------------------------------------- /packages/core/browser.js: -------------------------------------------------------------------------------- 1 | export * from "@oxc-node/core-wasm32-wasi"; 2 | -------------------------------------------------------------------------------- /packages/condition-dev/condition-dev.ts: -------------------------------------------------------------------------------- 1 | export const condition = "dev"; 2 | -------------------------------------------------------------------------------- /packages/condition-dev/condition-node.mjs: -------------------------------------------------------------------------------- 1 | export const condition = "node"; 2 | -------------------------------------------------------------------------------- /packages/integrate-module-bundler/src/common.d.cts: -------------------------------------------------------------------------------- 1 | export const common: string; 2 | -------------------------------------------------------------------------------- /rust-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "1.92.0" 3 | profile = "default" 4 | -------------------------------------------------------------------------------- /packages/condition-dev/condition-require.cjs: -------------------------------------------------------------------------------- 1 | module.exports.condition = "require"; 2 | -------------------------------------------------------------------------------- /packages/integrate-module-bundler/src/common.cjs: -------------------------------------------------------------------------------- 1 | module.exports.common = "common"; 2 | -------------------------------------------------------------------------------- /packages/integrate-module-bundler/src/typescript-cjs/index.ts: -------------------------------------------------------------------------------- 1 | export const foo = "foo"; 2 | -------------------------------------------------------------------------------- /packages/integrate-module/src/foo.mts: -------------------------------------------------------------------------------- 1 | export function foo() { 2 | return "foo"; 3 | } 4 | -------------------------------------------------------------------------------- /packages/integrate-module-bundler/src/foo.ts: -------------------------------------------------------------------------------- 1 | export function foo() { 2 | return "foo"; 3 | } 4 | -------------------------------------------------------------------------------- /pnpm-workspace.yaml: -------------------------------------------------------------------------------- 1 | packages: 2 | - packages/* 3 | 4 | catalog: 5 | "@napi-rs/cli": 3.5.0 6 | -------------------------------------------------------------------------------- /packages/integrate-module-bundler/src/enforce-mts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "commonjs" 3 | } 4 | -------------------------------------------------------------------------------- /packages/integrate-module-bundler/src/typescript-cjs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "commonjs" 3 | } 4 | -------------------------------------------------------------------------------- /packages/integrate-module/src/subdirectory/bar.mts: -------------------------------------------------------------------------------- 1 | export function bar() { 2 | return "bar"; 3 | } 4 | -------------------------------------------------------------------------------- /packages/integrate-module/src/subdirectory/baz.mts: -------------------------------------------------------------------------------- 1 | export function baz() { 2 | return "baz"; 3 | } 4 | -------------------------------------------------------------------------------- /packages/integrate-module-bundler/src/enforce-mts/index.mts: -------------------------------------------------------------------------------- 1 | export const exportFromMts = "exportFromMts"; 2 | -------------------------------------------------------------------------------- /packages/integrate-module-bundler/src/subdirectory/bar.ts: -------------------------------------------------------------------------------- 1 | export function bar() { 2 | return "bar"; 3 | } 4 | -------------------------------------------------------------------------------- /packages/integrate-module-bundler/src/subdirectory/baz.ts: -------------------------------------------------------------------------------- 1 | export function baz() { 2 | return "baz"; 3 | } 4 | -------------------------------------------------------------------------------- /packages/integrate-module/src/compiled.d.ts: -------------------------------------------------------------------------------- 1 | export declare class CompiledClass { 2 | name: string; 3 | } 4 | -------------------------------------------------------------------------------- /packages/integrate-module-bundler/src/compiled.d.ts: -------------------------------------------------------------------------------- 1 | export declare class CompiledClass { 2 | name: string; 3 | } 4 | -------------------------------------------------------------------------------- /packages/integrate-module/src/component.tsx: -------------------------------------------------------------------------------- 1 | export function Component() { 2 | return
Component
; 3 | } 4 | -------------------------------------------------------------------------------- /packages/integrate-module-bundler/src/component.tsx: -------------------------------------------------------------------------------- 1 | export function Component() { 2 | return
Component
; 3 | } 4 | -------------------------------------------------------------------------------- /packages/integrate-module/src/compiled.js: -------------------------------------------------------------------------------- 1 | export class CompiledClass { 2 | constructor() { 3 | this.name = "CompiledClass"; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /packages/integrate-module-bundler/src/subdirectory/index.ts: -------------------------------------------------------------------------------- 1 | export { baz } from "./baz"; 2 | export function module() { 3 | return "module"; 4 | } 5 | -------------------------------------------------------------------------------- /packages/integrate-module/src/subdirectory/index.mts: -------------------------------------------------------------------------------- 1 | export { baz } from "./baz.mjs"; 2 | export function module() { 3 | return "module"; 4 | } 5 | -------------------------------------------------------------------------------- /packages/integrate-module-bundler/src/compiled.js: -------------------------------------------------------------------------------- 1 | export class CompiledClass { 2 | constructor() { 3 | this.name = "CompiledClass"; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /packages/integrate-module-bundler/src/babel-generated-double-default/index.d.ts: -------------------------------------------------------------------------------- 1 | declare const exports: { 2 | default: () => string; 3 | }; 4 | 5 | export default exports; 6 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | insert_final_newline = true 6 | 7 | [*.{js,json,yml}] 8 | charset = utf-8 9 | indent_style = space 10 | indent_size = 2 11 | -------------------------------------------------------------------------------- /packages/core/README.md: -------------------------------------------------------------------------------- 1 | # `@oxc-node/core` 2 | 3 | Transformer and register for Node.js projects. 4 | 5 | ## Usage 6 | 7 | ```bash 8 | node --import @oxc-node/core/register ./path/to/entry.ts 9 | ``` 10 | -------------------------------------------------------------------------------- /packages/integrate-module-bundler/src/babel-generated-double-default/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "problematic cjs file type generated by babel", 3 | "main": "./index.js", 4 | "types": "./index.d.ts" 5 | } 6 | -------------------------------------------------------------------------------- /packages/integrate-ava/__tests__/fixtures/source-map-fixture.ts: -------------------------------------------------------------------------------- 1 | export function example(value: number): number { 2 | if (value < 0) { 3 | throw new Error("negative value"); 4 | } 5 | 6 | return value * 2; 7 | } 8 | -------------------------------------------------------------------------------- /packages/integrate-module-bundler/src/nestjs/config.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from "@nestjs/common"; 2 | 3 | @Injectable() 4 | export class ConfigService { 5 | public readonly server = { 6 | port: 3000, 7 | }; 8 | } 9 | -------------------------------------------------------------------------------- /packages/core/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "composite": true, 5 | "outDir": "./dist" 6 | }, 7 | "files": ["./index.d.ts"], 8 | "exclude": ["__tests__", "./dist"] 9 | } 10 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "node_modules/lerna/schemas/lerna-schema.json", 3 | "version": "0.0.35", 4 | "packages": ["packages/*"], 5 | "npmClient": "pnpm", 6 | "skipNxCache": true, 7 | "signGitCommit": true, 8 | "signGitTag": true, 9 | "private": false 10 | } 11 | -------------------------------------------------------------------------------- /packages/integrate-ava/__tests__/fixtures/stacktrace-esm.mts: -------------------------------------------------------------------------------- 1 | import assert from "node:assert/strict"; 2 | import { describe, it } from "node:test"; 3 | 4 | describe("stacktrace esm mts", () => { 5 | it("should preserve stack trace", () => { 6 | assert.ok(false); 7 | }); 8 | }); 9 | -------------------------------------------------------------------------------- /packages/integrate-ava/__tests__/fixtures/stacktrace-esm.ts: -------------------------------------------------------------------------------- 1 | import assert from "node:assert/strict"; 2 | import { describe, it } from "node:test"; 3 | 4 | describe("stacktrace esm ts", () => { 5 | it("should preserve stack trace", () => { 6 | assert.ok(false); 7 | }); 8 | }); 9 | -------------------------------------------------------------------------------- /packages/integrate-ava/__tests__/fixtures/stacktrace-cjs.cts: -------------------------------------------------------------------------------- 1 | const { describe, it } = require("node:test"); 2 | const assert = require("node:assert/strict"); 3 | 4 | describe("stacktrace cts", () => { 5 | it("should preserve stack trace", () => { 6 | assert.ok(false); 7 | }); 8 | }); 9 | -------------------------------------------------------------------------------- /packages/bench/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "dist", 5 | "composite": true, 6 | "module": "NodeNext", 7 | "moduleResolution": "NodeNext" 8 | }, 9 | "include": ["index.ts"], 10 | "exclude": ["dist"] 11 | } 12 | -------------------------------------------------------------------------------- /packages/condition-dev/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "condition-dev", 3 | "private": true, 4 | "type": "module", 5 | "exports": { 6 | ".": { 7 | "dev": "./condition-dev.ts", 8 | "node": "./condition-node.mjs", 9 | "require": "./condition-require.cjs" 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/cli/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "composite": true, 5 | "outDir": "./dist", 6 | "rootDir": "./src", 7 | "resolveJsonModule": true 8 | }, 9 | "include": ["package.json", "./src"], 10 | "exclude": ["__tests__", "./dist"] 11 | } 12 | -------------------------------------------------------------------------------- /justfile: -------------------------------------------------------------------------------- 1 | _default: 2 | @just --list -u 3 | 4 | alias r := ready 5 | 6 | ready: 7 | just build 8 | just test 9 | 10 | build: 11 | pnpm --filter @oxc-node/core build 12 | pnpm --filter @oxc-node/core export-oxc-runtime 13 | pnpm --filter @oxc-node/cli build 14 | pnpm install 15 | 16 | test: 17 | pnpm test 18 | -------------------------------------------------------------------------------- /packages/integrate-module-bundler/src/nestjs/index.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from "@nestjs/core"; 2 | 3 | import { AppModule } from "./app.module"; 4 | 5 | export async function bootstrap() { 6 | const app = await NestFactory.create(AppModule); 7 | await app.listen(3000); 8 | return { app, [Symbol.asyncDispose]: async () => app.close() }; 9 | } 10 | -------------------------------------------------------------------------------- /packages/integrate-ava/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | "composite": true, 6 | "module": "ESNext", 7 | "moduleResolution": "Bundler" 8 | }, 9 | "include": ["__tests__/**/*.ts"], 10 | "exclude": ["__tests__/fixtures/**/*"], 11 | "references": [{ "path": "../core" }] 12 | } 13 | -------------------------------------------------------------------------------- /packages/integrate-ava/__tests__/index.spec.ts: -------------------------------------------------------------------------------- 1 | import { OxcTransformer } from "@oxc-node/core"; 2 | import test from "ava"; 3 | 4 | test("transform", async (t) => { 5 | const transformer = new OxcTransformer(process.cwd()); 6 | const result = await transformer.transformAsync("foo.ts", "const foo: number = 1"); 7 | t.is(result.source(), '"use strict";\nconst foo = 1;\n'); 8 | }); 9 | -------------------------------------------------------------------------------- /packages/integrate-module-bundler/src/nestjs/app.controller.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get } from "@nestjs/common"; 2 | import { AppService } from "./app.service"; 3 | 4 | @Controller() 5 | export class AppController { 6 | constructor(public readonly appService: AppService) {} 7 | 8 | @Get() 9 | getHello(): string { 10 | return this.appService.getHello(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/integrate-module-bundler/src/nestjs/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from "@nestjs/common"; 2 | 3 | import { AppController } from "./app.controller"; 4 | import { AppService } from "./app.service"; 5 | import { ConfigService } from "./config"; 6 | 7 | @Module({ 8 | imports: [], 9 | controllers: [AppController], 10 | providers: [AppService, ConfigService], 11 | }) 12 | export class AppModule {} 13 | -------------------------------------------------------------------------------- /packages/integrate-module/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "target": "ESNext", 5 | "composite": true, 6 | "jsx": "react-jsx", 7 | "outDir": "dist", 8 | "resolveJsonModule": true, 9 | "baseUrl": "./", 10 | "paths": { 11 | "@subdirectory/*": ["./src/subdirectory/*"] 12 | } 13 | }, 14 | "include": ["src", "package.json"] 15 | } 16 | -------------------------------------------------------------------------------- /packages/bench/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bench", 3 | "version": "0.0.0", 4 | "private": true, 5 | "type": "module", 6 | "scripts": { 7 | "bench": "oxnode index.ts" 8 | }, 9 | "devDependencies": { 10 | "@oxc-node/cli": "workspace:*", 11 | "@swc/core": "^1.13.2", 12 | "esbuild": "^0.27.0", 13 | "rxjs": "^7.8.2", 14 | "tinybench": "^6.0.0", 15 | "typescript": "^5.8.3" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /.github/renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": ["github>Boshen/renovate", "helpers:pinGitHubActionDigestsToSemver"], 4 | "packageRules": [ 5 | { 6 | "matchManagers": ["cargo", "npm"], 7 | "matchDepNames": ["oxc", "oxc_resolver", "@oxc-project/runtime"], 8 | "groupName": "oxc", 9 | "schedule": ["at any time"] 10 | } 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /packages/cli/rolldown.config.js: -------------------------------------------------------------------------------- 1 | import { defineConfig } from "rolldown"; 2 | 3 | export default defineConfig({ 4 | input: "./src/index.ts", 5 | resolve: { 6 | conditionNames: ["module", "node"], 7 | mainFields: ["module", "main"], 8 | }, 9 | platform: "node", 10 | external: ["@oxc-node/core"], 11 | treeshake: true, 12 | output: { 13 | format: "esm", 14 | assetFileNames: "[name].js", 15 | }, 16 | }); 17 | -------------------------------------------------------------------------------- /packages/integrate-module-bundler/src/nestjs/app.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from "@nestjs/common"; 2 | 3 | import { ConfigService } from "./config"; 4 | 5 | @Injectable() 6 | export class AppService { 7 | public readonly websocket = { 8 | port: this.config.server.port + 1, 9 | }; 10 | 11 | constructor(private readonly config: ConfigService) {} 12 | 13 | getHello(): string { 14 | return "Hello World!"; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "strict": true, 4 | "target": "ESNext", 5 | "moduleResolution": "NodeNext", 6 | "module": "NodeNext" 7 | }, 8 | "references": [ 9 | { 10 | "path": "./packages/cli" 11 | }, 12 | { 13 | "path": "./packages/core" 14 | }, 15 | { 16 | "path": "./packages/integrate-module" 17 | }, 18 | { 19 | "path": "./packages/integrate-module-bundler" 20 | } 21 | ], 22 | "include": [] 23 | } 24 | -------------------------------------------------------------------------------- /packages/cli/README.md: -------------------------------------------------------------------------------- 1 | # `@oxc-node/cli` 2 | 3 | CLI tool for `oxc-node`. 4 | 5 | ## Features 6 | 7 | - Run a script with oxc transformer and oxc-resolver 8 | - Support run TypeScript without any configuration 9 | - Support ESM and CJS 10 | - Support source map 11 | 12 | ## Installation 13 | 14 | Install globally, you can use it replace `node` command anywhere. 15 | 16 | ```bash 17 | npm install @oxc-node/cli -g 18 | ``` 19 | 20 | ## Usage 21 | 22 | ```bash 23 | oxnode ./path/to/index.ts 24 | ``` 25 | -------------------------------------------------------------------------------- /packages/integrate-ava/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "integrate-ava", 3 | "private": true, 4 | "type": "module", 5 | "scripts": { 6 | "test": "ava" 7 | }, 8 | "devDependencies": { 9 | "@oxc-node/core": "workspace:*", 10 | "ava": "^6.4.1" 11 | }, 12 | "ava": { 13 | "cache": false, 14 | "extensions": { 15 | "ts": "module" 16 | }, 17 | "files": [ 18 | "__tests__/**/*.spec.ts" 19 | ], 20 | "nodeArguments": [ 21 | "--import", 22 | "@oxc-node/core/register" 23 | ], 24 | "timeout": "1m" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /packages/integrate-module-bundler/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "target": "ESNext", 5 | "module": "ESNext", 6 | "moduleResolution": "Bundler", 7 | "allowJs": true, 8 | "composite": true, 9 | "jsx": "react-jsx", 10 | "outDir": "dist", 11 | "experimentalDecorators": true, 12 | "emitDecoratorMetadata": true, 13 | "useDefineForClassFields": false, 14 | "baseUrl": "./", 15 | "paths": { 16 | "@subdirectory/*": ["./src/subdirectory/*"] 17 | } 18 | }, 19 | "include": ["src", "package.json"] 20 | } 21 | -------------------------------------------------------------------------------- /packages/core/esm.mjs: -------------------------------------------------------------------------------- 1 | import { isMainThread, MessageChannel } from "node:worker_threads"; 2 | 3 | import { createResolve, initTracing, load } from "./index.js"; 4 | 5 | initTracing(); 6 | 7 | if (!isMainThread) { 8 | const mc = new MessageChannel(); 9 | mc.port1.ref(); 10 | } 11 | 12 | /** 13 | * @type {import('node:module').ResolveHook} 14 | */ 15 | function resolve(specifier, context, nextResolve) { 16 | return createResolve( 17 | { 18 | getCurrentDirectory: () => process.cwd(), 19 | }, 20 | specifier, 21 | context, 22 | nextResolve, 23 | ); 24 | } 25 | 26 | export { load, resolve }; 27 | -------------------------------------------------------------------------------- /packages/integrate-module/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "integrate-module", 3 | "version": "0.0.0", 4 | "private": true, 5 | "type": "module", 6 | "scripts": { 7 | "test": "oxnode ./src/index.ts" 8 | }, 9 | "dependencies": { 10 | "file-type": "^21.0.0", 11 | "p-timeout": "^7.0.0" 12 | }, 13 | "devDependencies": { 14 | "@napi-rs/tar": "^1.0.0", 15 | "@napi-rs/wasm-runtime": "^1.0.1", 16 | "@oxc-node/cli": "workspace:*", 17 | "@types/node": "^25.0.0", 18 | "@types/react": "^19.1.8", 19 | "@types/react-dom": "^19.1.6", 20 | "canvaskit-wasm": "^0.40.0", 21 | "ipaddr.js": "^2.2.0", 22 | "postgres": "^3.4.7", 23 | "react": "^19.1.0", 24 | "react-dom": "^19.1.0", 25 | "simple-git": "^3.28.0", 26 | "ts-node": "^10.9.2" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | 5 | *.ts text eol=lf merge=union 6 | *.tsx text eol=lf merge=union 7 | *.rs text eol=lf merge=union 8 | *.js text eol=lf merge=union 9 | *.json text eol=lf merge=union 10 | *.debug text eol=lf merge=union 11 | 12 | 13 | /packages/core/index.js linguist-detectable=false 14 | /packages/core/index.d.ts linguist-detectable=false 15 | /packages/core/oxc-node.wasi-browser.js linguist-detectable=false 16 | /packages/core/oxc-node.wasi.cjs linguist-detectable=false 17 | /packages/core/wasi-workser.browser.mjs linguist-detectable=false 18 | /packages/core/wasi-worker.mjs linguist-detectable=false 19 | -------------------------------------------------------------------------------- /packages/integrate-module-bundler/src/js-module.js: -------------------------------------------------------------------------------- 1 | /* eslint import/order: off */ 2 | import assert from "node:assert"; 3 | import test from "node:test"; 4 | 5 | import { supportedExtensions } from "file-type"; 6 | 7 | import { bar as subBar } from "@subdirectory/bar.ts"; 8 | import { foo } from "./foo.ts"; 9 | import { bar } from "./subdirectory/bar.ts"; 10 | import { baz } from "./subdirectory/index.ts"; 11 | 12 | await test("js:file-type should work", () => { 13 | assert.ok(supportedExtensions.has("jpg")); 14 | }); 15 | 16 | await test("js:resolve adjacent file path", () => { 17 | assert.equal(foo(), "foo"); 18 | }); 19 | 20 | await test("js:resolve nested file path", () => { 21 | assert.equal(bar(), "bar"); 22 | }); 23 | 24 | await test("js:resolve nested entry point", () => { 25 | assert.equal(baz(), "baz"); 26 | }); 27 | 28 | await test("js:resolve paths", () => { 29 | assert.equal(subBar(), "bar"); 30 | }); 31 | -------------------------------------------------------------------------------- /packages/integrate-module/src/js-module.mjs: -------------------------------------------------------------------------------- 1 | /* eslint import/order: off */ 2 | import assert from "node:assert"; 3 | import test from "node:test"; 4 | 5 | import { supportedExtensions } from "file-type"; 6 | 7 | import { bar as subBar } from "@subdirectory/bar.mts"; 8 | import { foo } from "./foo.mts"; 9 | import { bar } from "./subdirectory/bar.mts"; 10 | import { baz } from "./subdirectory/index.mts"; 11 | 12 | await test("js:file-type should work", () => { 13 | assert.ok(supportedExtensions.has("jpg")); 14 | }); 15 | 16 | await test("js:resolve adjacent file path", () => { 17 | assert.equal(foo(), "foo"); 18 | }); 19 | 20 | await test("js:resolve nested file path", () => { 21 | assert.equal(bar(), "bar"); 22 | }); 23 | 24 | await test("js:resolve nested entry point", () => { 25 | assert.equal(baz(), "baz"); 26 | }); 27 | 28 | await test("js:resolve paths", () => { 29 | assert.equal(subBar(), "bar"); 30 | }); 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # `oxc-node` 2 | 3 | [![Build Status][ci-badge]][ci-url] 4 | [![npmjs.com][npm-badge]][npm-url] 5 | 6 | Fast and friendly Node.js dev tool based on [Oxc](https://github.com/oxc-project/oxc). 7 | 8 | ## `@oxc-node/core` 9 | 10 | Transformer and register for Node.js projects. 11 | 12 | ### Usage 13 | 14 | ```bash 15 | node --import @oxc-node/core/register ./path/to/entry.ts 16 | ``` 17 | 18 | ## [Sponsored By](https://github.com/sponsors/Boshen) 19 | 20 |

21 | 22 | My sponsors 23 | 24 |

25 | 26 | [ci-badge]: https://github.com/oxc-project/oxc-node/actions/workflows/CI.yml/badge.svg?branch=main 27 | [ci-url]: https://github.com/oxc-project/oxc-node/actions/workflows/CI.yml 28 | [npm-url]: https://www.npmjs.com/package/@oxc-node/core 29 | [npm-badge]: https://img.shields.io/npm/dw/@oxc-node/core?label=npm 30 | -------------------------------------------------------------------------------- /packages/core/wasi-worker-browser.mjs: -------------------------------------------------------------------------------- 1 | import { instantiateNapiModuleSync, MessageHandler, WASI } from "@napi-rs/wasm-runtime"; 2 | 3 | const handler = new MessageHandler({ 4 | onLoad({ wasmModule, wasmMemory }) { 5 | const wasi = new WASI({ 6 | print: function () { 7 | // eslint-disable-next-line no-console 8 | console.log.apply(console, arguments); 9 | }, 10 | printErr: function () { 11 | // eslint-disable-next-line no-console 12 | console.error.apply(console, arguments); 13 | }, 14 | }); 15 | return instantiateNapiModuleSync(wasmModule, { 16 | childThread: true, 17 | wasi, 18 | overwriteImports(importObject) { 19 | importObject.env = { 20 | ...importObject.env, 21 | ...importObject.napi, 22 | ...importObject.emnapi, 23 | memory: wasmMemory, 24 | }; 25 | }, 26 | }); 27 | }, 28 | }); 29 | 30 | globalThis.onmessage = function (e) { 31 | handler.handle(e); 32 | }; 33 | -------------------------------------------------------------------------------- /packages/integrate-module-bundler/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "integrate-module-bundler", 3 | "version": "0.0.0", 4 | "private": true, 5 | "type": "module", 6 | "scripts": { 7 | "test": "oxnode -C dev ./src/index.ts" 8 | }, 9 | "dependencies": { 10 | "file-type": "^21.0.0", 11 | "p-timeout": "^7.0.0" 12 | }, 13 | "devDependencies": { 14 | "@napi-rs/tar": "^1.0.0", 15 | "@napi-rs/wasm-runtime": "^1.0.1", 16 | "@nestjs/common": "^11.1.5", 17 | "@nestjs/core": "^11.1.5", 18 | "@nestjs/platform-express": "^11.1.5", 19 | "@oxc-node/cli": "workspace:*", 20 | "@oxc-project/runtime": "^0.104.0", 21 | "@types/express": "^5.0.3", 22 | "@types/node": "^25.0.0", 23 | "@types/react": "^19.1.8", 24 | "@types/react-dom": "^19.1.6", 25 | "condition-dev": "workspace:*", 26 | "core-js": "^3.44.0", 27 | "express": "^5.1.0", 28 | "react": "^19.1.0", 29 | "react-dom": "^19.1.0", 30 | "simple-git": "^3.28.0", 31 | "ts-node": "^10.9.2", 32 | "tsx": "^4.20.3" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /packages/integrate-module-bundler/src/babel-generated-double-default/index.js: -------------------------------------------------------------------------------- 1 | // this undesirable output was commonly generated by babel w browser-breaking 2 | // defineProperty and default.default definitions 3 | 4 | /* eslint-disable */ 5 | "use strict"; 6 | 7 | Object.defineProperty(exports, "__esModule", { 8 | value: true, 9 | }); 10 | exports["default"] = void 0; 11 | 12 | function _typeof(obj) { 13 | "@babel/helpers - typeof"; 14 | if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { 15 | _typeof = function _typeof(obj) { 16 | return typeof obj; 17 | }; 18 | } else { 19 | _typeof = function _typeof(obj) { 20 | return obj && 21 | typeof Symbol === "function" && 22 | obj.constructor === Symbol && 23 | obj !== Symbol.prototype 24 | ? "symbol" 25 | : typeof obj; 26 | }; 27 | } 28 | return _typeof(obj); 29 | } 30 | 31 | var _default = function _default() { 32 | return "default.default"; 33 | }; 34 | 35 | exports["default"] = _default; 36 | /* eslint-enable */ 37 | -------------------------------------------------------------------------------- /.github/workflows/zizmor.yml: -------------------------------------------------------------------------------- 1 | name: GitHub Actions Security Analysis 2 | 3 | on: 4 | workflow_dispatch: 5 | pull_request: 6 | types: [opened, synchronize] 7 | paths: 8 | - ".github/workflows/**" 9 | push: 10 | branches: 11 | - main 12 | paths: 13 | - ".github/workflows/**" 14 | 15 | permissions: {} 16 | 17 | jobs: 18 | zizmor: 19 | name: zizmor 20 | runs-on: ubuntu-latest 21 | permissions: 22 | security-events: write 23 | steps: 24 | - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 25 | with: 26 | persist-credentials: false 27 | 28 | - uses: taiki-e/install-action@5818d9684d2a52207bb7475983a18ba56127e337 # v2.63.2 29 | with: 30 | tool: zizmor 31 | 32 | - run: zizmor --format sarif . > results.sarif 33 | env: 34 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 35 | 36 | - uses: github/codeql-action/upload-sarif@1b168cd39490f61582a9beae412bb7057a6b2c4e # v4.31.8 37 | with: 38 | sarif_file: results.sarif 39 | category: zizmor 40 | -------------------------------------------------------------------------------- /.github/workflows/autofix.yml: -------------------------------------------------------------------------------- 1 | name: autofix.ci # For security reasons, the workflow in which the autofix.ci action is used must be named "autofix.ci". 2 | 3 | permissions: {} 4 | 5 | on: 6 | pull_request: 7 | types: [opened, synchronize] 8 | 9 | concurrency: 10 | group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} 11 | cancel-in-progress: ${{ github.ref_name != 'main' }} 12 | 13 | jobs: 14 | autofix: 15 | runs-on: ubuntu-latest 16 | steps: 17 | - uses: taiki-e/checkout-action@b13d20b7cda4e2f325ef19895128f7ff735c0b3d # v1.3.1 18 | 19 | - uses: oxc-project/setup-rust@ecabb7322a2ba5aeedb3612d2a40b86a85cee235 # v1.0.11 20 | with: 21 | restore-cache: false 22 | tools: cargo-shear@1 23 | components: rustfmt 24 | 25 | - uses: oxc-project/setup-node@141eb77546de6702f92d320926403fe3f9f6a6f2 # v1.0.5 26 | 27 | - run: cargo shear --fix 28 | - run: node --run fmt 29 | 30 | - uses: autofix-ci/action@635ffb0c9798bd160680f18fd73371e355b85f27 # v1.3.2 31 | with: 32 | fail-fast: false 33 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "oxc-node", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "bench": "pnpm --filter=bench bench", 7 | "fmt": "oxfmt && cargo fmt", 8 | "lint": "oxlint", 9 | "test": "pnpm --sequential --filter=integrate* run test", 10 | "prepare": "husky" 11 | }, 12 | "devDependencies": { 13 | "@napi-rs/cli": "catalog:", 14 | "@napi-rs/wasm-runtime": "^1.0.1", 15 | "@oxc-node/cli": "workspace:*", 16 | "@oxc-node/core": "workspace:*", 17 | "@oxc-project/runtime": "^0.104.0", 18 | "@types/node": "^25.0.0", 19 | "ava": "^6.4.1", 20 | "cross-env": "^10.0.0", 21 | "emnapi": "^1.4.5", 22 | "husky": "^9.1.7", 23 | "lerna": "^9.0.0", 24 | "lint-staged": "^16.1.2", 25 | "npm-run-all2": "^8.0.4", 26 | "oxfmt": "^0.19.0", 27 | "oxlint": "^1.8.0", 28 | "typescript": "^5.8.3" 29 | }, 30 | "lint-staged": { 31 | "*": [ 32 | "oxfmt --no-error-on-unmatched-pattern" 33 | ], 34 | "*.@(js|ts|tsx)": [ 35 | "oxlint --fix" 36 | ] 37 | }, 38 | "packageManager": "pnpm@10.25.0" 39 | } 40 | -------------------------------------------------------------------------------- /.cargo/config.toml: -------------------------------------------------------------------------------- 1 | [target.'cfg(target_env = "gnu")'] 2 | rustflags = ["-C", "link-args=-Wl,-z,nodelete"] 3 | 4 | [target.x86_64-pc-windows-msvc] 5 | rustflags = ["-C", "target-feature=+crt-static"] 6 | 7 | [target.i686-pc-windows-msvc] 8 | rustflags = ["-C", "target-feature=+crt-static"] 9 | 10 | [target.aarch64-pc-windows-msvc] 11 | rustflags = ["-C", "target-feature=+crt-static"] 12 | 13 | [target.'cfg(target_os = "windows")'] 14 | rustflags = [ 15 | # Disables linking against the default Universal C Runtime (libucrt.lib). This prevents conflicts if another CRT library is linked manually. 16 | "-C", 17 | "link-args=/NODEFAULTLIB:libucrt.lib", 18 | # Manually adds ucrt.lib (the Universal CRT) as a default library to link against, replacing the one you just excluded above. 19 | # This ensures consistent linking when multiple CRTs might be available. 20 | "-C", 21 | "link-args=/DEFAULTLIB:ucrt.lib", 22 | ] 23 | 24 | # LLD linker is currently broken for us, opt out. 25 | # https://blog.rust-lang.org/2025/09/18/Rust-1.90.0/#what-s-in-1-90-0-stable 26 | [target.x86_64-unknown-linux-gnu] 27 | rustflags = ["-C", "linker-features=-lld"] 28 | -------------------------------------------------------------------------------- /packages/cli/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@oxc-node/cli", 3 | "version": "0.0.35", 4 | "description": "OXC Node cli", 5 | "homepage": "https://github.com/oxc-project/oxc-node/tree/main/packages/cli", 6 | "license": "MIT", 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/oxc-project/oxc-node.git" 10 | }, 11 | "funding": [ 12 | { 13 | "type": "github", 14 | "url": "https://github.com/sponsors/Brooooooklyn" 15 | }, 16 | { 17 | "type": "github", 18 | "url": "https://github.com/sponsors/Boshen" 19 | } 20 | ], 21 | "bin": { 22 | "oxnode": "./dist/index.js" 23 | }, 24 | "files": [ 25 | "dist" 26 | ], 27 | "type": "module", 28 | "publishConfig": { 29 | "access": "public", 30 | "registry": "https://registry.npmjs.org/" 31 | }, 32 | "scripts": { 33 | "build": "rolldown --config ./rolldown.config.js", 34 | "dev": "node --import @oxc-node/core/register ./src/index.ts" 35 | }, 36 | "dependencies": { 37 | "@oxc-node/core": "workspace:*" 38 | }, 39 | "devDependencies": { 40 | "clipanion": "^4.0.0-rc.4", 41 | "rolldown": "^1.0.0-beta.29" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "oxc-node" 3 | version = "0.0.0" 4 | authors = ["LongYinan "] 5 | edition = "2024" 6 | 7 | [lib] 8 | crate-type = ["cdylib"] 9 | 10 | [dependencies] 11 | napi = { version = "3.5.1", default-features = false, features = ["serde-json", "napi3"] } 12 | napi-derive = { version = "3.3.2", default-features = false, features = ["type-def"] } 13 | oxc = { version = "0.104.0", features = ["codegen", "transformer", "semantic", "regular_expression"] } 14 | oxc_resolver = { version = "11.13.1" } 15 | phf = "0.13" 16 | serde_json = "1" 17 | tracing = "0.1" 18 | tracing-subscriber = { version = "0.3", default-features = false, features = ["std", "fmt"] } # Omit the `regex` feature 19 | 20 | [target.'cfg(all(not(target_os = "linux"), not(target_os = "freebsd"), not(target_arch = "arm"), not(target_arch = "x86"), not(target_family = "wasm")))'.dependencies] 21 | mimalloc-safe = { version = "0.1", features = ["skip_collect_on_exit"] } 22 | 23 | [target.'cfg(any(target_os = "linux", target_os = "freebsd"))'.dependencies] 24 | mimalloc-safe = { version = "0.1", features = ["skip_collect_on_exit", "local_dynamic_tls"] } 25 | 26 | [build-dependencies] 27 | napi-build = "2" 28 | 29 | [profile.release] 30 | codegen-units = 1 31 | lto = true 32 | strip = "symbols" 33 | -------------------------------------------------------------------------------- /packages/core/register.mjs: -------------------------------------------------------------------------------- 1 | import * as NodeModule from "node:module"; 2 | 3 | import { addHook } from "pirates"; 4 | 5 | import { OxcTransformer } from "./index.js"; 6 | 7 | // Destructure from NodeModule namespace to support older Node.js versions 8 | const { register, setSourceMapsSupport } = NodeModule; 9 | 10 | const DEFAULT_EXTENSIONS = new Set([ 11 | ".js", 12 | ".jsx", 13 | ".ts", 14 | ".tsx", 15 | ".mjs", 16 | ".mts", 17 | ".cjs", 18 | ".cts", 19 | ".es6", 20 | ".es", 21 | ]); 22 | 23 | register("@oxc-node/core/esm", import.meta.url); 24 | 25 | if (typeof setSourceMapsSupport === "function") { 26 | setSourceMapsSupport(true, { nodeModules: true, generatedCode: true }); 27 | } else if (typeof process.setSourceMapsEnabled === "function") { 28 | process.setSourceMapsEnabled(true); 29 | } 30 | 31 | const transformer = new OxcTransformer(process.cwd()); 32 | const SOURCEMAP_PREFIX = "\n//# sourceMappingURL="; 33 | const SOURCEMAP_MIME = "data:application/json;charset=utf-8;base64,"; 34 | 35 | addHook( 36 | (code, filename) => { 37 | const output = transformer.transform(filename, code); 38 | let transformed = output.source(); 39 | const sourceMap = output.sourceMap(); 40 | 41 | if (sourceMap) { 42 | const inlineMap = Buffer.from(sourceMap, "utf8").toString("base64"); 43 | transformed += SOURCEMAP_PREFIX + SOURCEMAP_MIME + inlineMap; 44 | } 45 | 46 | return transformed; 47 | }, 48 | { 49 | ext: Array.from(DEFAULT_EXTENSIONS), 50 | }, 51 | ); 52 | -------------------------------------------------------------------------------- /packages/core/reexport-oxc-runtime.mjs: -------------------------------------------------------------------------------- 1 | import { copyFile, mkdir, readdir, writeFile } from "node:fs/promises"; 2 | import { createRequire } from "node:module"; 3 | import { join } from "node:path"; 4 | 5 | import oxcRuntimePackageJson from "@oxc-project/runtime/package.json" with { type: "json" }; 6 | 7 | import currentPackageJson from "./package.json" with { type: "json" }; 8 | 9 | const { resolve } = createRequire(import.meta.url); 10 | 11 | const currentDir = join(resolve("."), ".."); 12 | 13 | const oxcRuntimeDir = join(resolve("@oxc-project/runtime/package.json"), ".."); 14 | 15 | const files = await readdir(oxcRuntimeDir, { recursive: true }); 16 | 17 | await mkdir(join(currentDir, "src", "helpers", "esm"), { recursive: true }).catch(() => { 18 | // ignore error 19 | }); 20 | 21 | for (const file of files.filter((file) => file.endsWith(".js"))) { 22 | const filePath = join(oxcRuntimeDir, file); 23 | await copyFile(filePath, join(currentDir, file)); 24 | } 25 | 26 | const packageJsonExports = { 27 | ".": { 28 | import: "./index.js", 29 | require: "./index.js", 30 | types: "./index.d.ts", 31 | }, 32 | "./esm": { 33 | import: "./esm.mjs", 34 | }, 35 | "./esm.mjs": { 36 | import: "./esm.mjs", 37 | }, 38 | "./register": { 39 | import: "./register.mjs", 40 | }, 41 | "./register.mjs": { 42 | import: "./register.mjs", 43 | }, 44 | ...oxcRuntimePackageJson.exports, 45 | }; 46 | 47 | await writeFile( 48 | join(currentDir, "package.json"), 49 | JSON.stringify( 50 | { 51 | ...currentPackageJson, 52 | exports: packageJsonExports, 53 | }, 54 | null, 55 | 2, 56 | ), 57 | ); 58 | -------------------------------------------------------------------------------- /packages/bench/index.ts: -------------------------------------------------------------------------------- 1 | import { readFile } from "node:fs/promises"; 2 | import { join } from "node:path"; 3 | import { fileURLToPath } from "node:url"; 4 | 5 | import { transform as oxc } from "@oxc-node/core"; 6 | import { transformSync as swc } from "@swc/core"; 7 | import { transformSync as esbuild } from "esbuild"; 8 | import { Bench } from "tinybench"; 9 | import ts from "typescript"; 10 | 11 | // https://github.com/tinylibs/tinybench/issues/83 12 | const bench = new Bench({ iterations: 1000 }); 13 | 14 | const fixture = ( 15 | await readFile( 16 | join(fileURLToPath(import.meta.url), "..", "node_modules/rxjs/src/internal/ajax/ajax.ts"), 17 | ) 18 | ).toString("utf8"); 19 | 20 | bench 21 | .add("@swc/core", () => { 22 | swc(fixture, { 23 | filename: "ajax.ts", 24 | jsc: { 25 | target: "esnext", 26 | parser: { 27 | syntax: "typescript", 28 | tsx: false, 29 | dynamicImport: false, 30 | decorators: false, 31 | }, 32 | }, 33 | sourceMaps: true, 34 | }); 35 | }) 36 | .add("oxc", () => { 37 | const { source: _source, sourceMap: _sourceMap } = oxc("ajax.ts", fixture); 38 | }) 39 | .add("esbuild", () => { 40 | esbuild(fixture, { 41 | loader: "ts", 42 | format: "esm", 43 | target: "esnext", 44 | }); 45 | }) 46 | .add("typescript", () => { 47 | ts.transpileModule(fixture, { 48 | fileName: "ajax.ts", 49 | compilerOptions: { 50 | target: ts.ScriptTarget.ESNext, 51 | module: ts.ModuleKind.ESNext, 52 | isolatedModules: true, 53 | sourceMap: true, 54 | }, 55 | }); 56 | }); 57 | 58 | await bench.run(); 59 | 60 | console.table(bench.table()); 61 | -------------------------------------------------------------------------------- /packages/core/wasi-worker.mjs: -------------------------------------------------------------------------------- 1 | import fs from "node:fs"; 2 | import { createRequire } from "node:module"; 3 | import { parse } from "node:path"; 4 | import { WASI } from "node:wasi"; 5 | import { parentPort, Worker } from "node:worker_threads"; 6 | 7 | const require = createRequire(import.meta.url); 8 | 9 | const { 10 | instantiateNapiModuleSync, 11 | MessageHandler, 12 | getDefaultContext, 13 | } = require("@napi-rs/wasm-runtime"); 14 | 15 | if (parentPort) { 16 | parentPort.on("message", (data) => { 17 | globalThis.onmessage({ data }); 18 | }); 19 | } 20 | 21 | Object.assign(globalThis, { 22 | self: globalThis, 23 | require, 24 | Worker, 25 | importScripts: function (f) { 26 | (0, eval)(fs.readFileSync(f, "utf8") + "//# sourceURL=" + f); 27 | }, 28 | postMessage: function (msg) { 29 | if (parentPort) { 30 | parentPort.postMessage(msg); 31 | } 32 | }, 33 | }); 34 | 35 | const emnapiContext = getDefaultContext(); 36 | 37 | const __rootDir = parse(process.cwd()).root; 38 | 39 | const handler = new MessageHandler({ 40 | onLoad({ wasmModule, wasmMemory }) { 41 | const wasi = new WASI({ 42 | version: "preview1", 43 | env: process.env, 44 | preopens: { 45 | [__rootDir]: __rootDir, 46 | }, 47 | }); 48 | 49 | return instantiateNapiModuleSync(wasmModule, { 50 | childThread: true, 51 | wasi, 52 | context: emnapiContext, 53 | overwriteImports(importObject) { 54 | importObject.env = { 55 | ...importObject.env, 56 | ...importObject.napi, 57 | ...importObject.emnapi, 58 | memory: wasmMemory, 59 | }; 60 | }, 61 | }); 62 | }, 63 | }); 64 | 65 | globalThis.onmessage = function (e) { 66 | handler.handle(e); 67 | }; 68 | -------------------------------------------------------------------------------- /packages/core/oxc-node.wasi-browser.js: -------------------------------------------------------------------------------- 1 | import { 2 | createOnMessage as __wasmCreateOnMessageForFsProxy, 3 | getDefaultContext as __emnapiGetDefaultContext, 4 | instantiateNapiModuleSync as __emnapiInstantiateNapiModuleSync, 5 | WASI as __WASI, 6 | } from "@napi-rs/wasm-runtime"; 7 | 8 | const __wasi = new __WASI({ 9 | version: "preview1", 10 | }); 11 | 12 | const __wasmUrl = new URL("./oxc-node.wasm32-wasi.wasm", import.meta.url).href; 13 | const __emnapiContext = __emnapiGetDefaultContext(); 14 | 15 | const __sharedMemory = new WebAssembly.Memory({ 16 | initial: 16384, 17 | maximum: 65536, 18 | shared: true, 19 | }); 20 | 21 | const __wasmFile = await fetch(__wasmUrl).then((res) => res.arrayBuffer()); 22 | 23 | const { 24 | instance: __napiInstance, 25 | module: __wasiModule, 26 | napiModule: __napiModule, 27 | } = __emnapiInstantiateNapiModuleSync(__wasmFile, { 28 | context: __emnapiContext, 29 | asyncWorkPoolSize: 4, 30 | wasi: __wasi, 31 | onCreateWorker() { 32 | const worker = new Worker(new URL("./wasi-worker-browser.mjs", import.meta.url), { 33 | type: "module", 34 | }); 35 | 36 | return worker; 37 | }, 38 | overwriteImports(importObject) { 39 | importObject.env = { 40 | ...importObject.env, 41 | ...importObject.napi, 42 | ...importObject.emnapi, 43 | memory: __sharedMemory, 44 | }; 45 | return importObject; 46 | }, 47 | beforeInit({ instance }) { 48 | for (const name of Object.keys(instance.exports)) { 49 | if (name.startsWith("__napi_register__")) { 50 | instance.exports[name](); 51 | } 52 | } 53 | }, 54 | }); 55 | export default __napiModule.exports; 56 | export const Output = __napiModule.exports.Output; 57 | export const OxcTransformer = __napiModule.exports.OxcTransformer; 58 | export const createResolve = __napiModule.exports.createResolve; 59 | export const initTracing = __napiModule.exports.initTracing; 60 | export const load = __napiModule.exports.load; 61 | export const transform = __napiModule.exports.transform; 62 | export const transformAsync = __napiModule.exports.transformAsync; 63 | -------------------------------------------------------------------------------- /packages/integrate-ava/__tests__/cli.spec.ts: -------------------------------------------------------------------------------- 1 | import test, { ExecutionContext } from "ava"; 2 | import { spawnSync } from "node:child_process"; 3 | import { fileURLToPath, pathToFileURL } from "node:url"; 4 | 5 | const STACKTRACE_LINE = 6; 6 | const STACKTRACE_COLUMN = 12; 7 | const FIXTURE_PATHS = new Map( 8 | ["stacktrace-esm.ts", "stacktrace-esm.mts", "stacktrace-cjs.cts"].map((name) => [ 9 | name, 10 | fileURLToPath(new URL(`./fixtures/${name}`, import.meta.url)), 11 | ]), 12 | ); 13 | const getFixturePath = (fixtureName: string) => { 14 | const resolved = FIXTURE_PATHS.get(fixtureName); 15 | if (!resolved) { 16 | throw new Error(`Unknown fixture: ${fixtureName}`); 17 | } 18 | return resolved; 19 | }; 20 | const runCliFixture = (fixtureName: string) => { 21 | const fixturePath = getFixturePath(fixtureName); 22 | const result = spawnSync( 23 | process.execPath, 24 | ["--import", "@oxc-node/core/register", "--test", fixturePath], 25 | { 26 | encoding: "utf8", 27 | env: { 28 | ...process.env, 29 | NODE_OPTIONS: undefined, 30 | }, 31 | }, 32 | ); 33 | 34 | return { ...result, fixturePath }; 35 | }; 36 | const escapeRegExp = (value: string) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); 37 | const expectStackLocation = (t: ExecutionContext, output: string, fixturePath: string) => { 38 | const fileUrl = pathToFileURL(fixturePath).href; 39 | const pattern = new RegExp( 40 | `(?:${escapeRegExp(fileUrl)}|${escapeRegExp(fixturePath)}):(\\d+):(\\d+)`, 41 | "g", 42 | ); 43 | const matches = [...output.matchAll(pattern)]; 44 | 45 | t.true(matches.length > 0, "stack trace should reference the failing fixture path"); 46 | 47 | const exactLocation = matches.find(([, line, column]) => { 48 | return Number(line) === STACKTRACE_LINE && Number(column) === STACKTRACE_COLUMN; 49 | }); 50 | 51 | t.truthy(exactLocation, "stack trace should include the original TypeScript location"); 52 | }; 53 | 54 | for (const fixture of FIXTURE_PATHS.keys()) { 55 | test(`CLI stack trace for ${fixture}`, (t) => { 56 | const { stdout, stderr, status, error, fixturePath } = runCliFixture(fixture); 57 | 58 | t.falsy(error, error?.message); 59 | t.not(status, 0, "fixture should fail to trigger stack trace output"); 60 | 61 | expectStackLocation(t, `${stdout}${stderr}`, fixturePath); 62 | }); 63 | } 64 | -------------------------------------------------------------------------------- /packages/cli/src/index.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | import { exec, execSync } from "node:child_process"; 4 | import process from "node:process"; 5 | 6 | import { Builtins, Cli, Command, Option, Usage } from "clipanion"; 7 | 8 | import pkgJson from "../package.json" with { type: "json" }; 9 | 10 | const [node, app, ...stdArgs] = process.argv; 11 | 12 | class MainCommand extends Command { 13 | static paths = [[]]; 14 | 15 | static usage: Usage = { 16 | description: `Run a script with oxc transformer and oxc-resolver`, 17 | details: `oxnode is a CLI tool that runs a script with oxc transformer and oxc-resolver. 18 | The esm module is resolved by oxc-resolver and transformed by oxc transformer. 19 | The cjs module support will be added in the future. 20 | `, 21 | examples: [ 22 | [`Run a script`, `oxnode ./src/index.ts`], 23 | [`repl`, `oxnode`], 24 | ], 25 | }; 26 | 27 | help = Option.Boolean(`-h,--help`, false, { 28 | description: `Show help`, 29 | }); 30 | 31 | nodeHelp = Option.Boolean(`--node-help`, false, { 32 | description: `Show Node.js help`, 33 | }); 34 | 35 | args = Option.Proxy(); 36 | 37 | async execute() { 38 | if (this.help) { 39 | this.context.stdout.write(this.cli.usage()); 40 | return; 41 | } 42 | if (this.nodeHelp) { 43 | this.args.push(`--help `); 44 | } 45 | const args = this.args.length ? `${this.args.join(" ")}` : ""; 46 | const register = import.meta.resolve("@oxc-node/core/register"); 47 | if (!args.length) { 48 | execSync(`node --enable-source-maps --import ${register}`, { 49 | env: process.env, 50 | cwd: process.cwd(), 51 | stdio: `inherit`, 52 | }); 53 | return; 54 | } 55 | const cp = exec(`node --enable-source-maps --import ${register} ${args}`, { 56 | env: process.env, 57 | cwd: process.cwd(), 58 | }); 59 | cp.addListener(`error`, (error) => { 60 | console.error(error); 61 | }); 62 | if (cp.stdin) { 63 | this.context.stdin.pipe(cp.stdin); 64 | } 65 | if (cp.stdout) { 66 | cp.stdout.pipe(this.context.stdout); 67 | } 68 | if (cp.stderr) { 69 | cp.stderr.pipe(this.context.stderr); 70 | } 71 | cp.addListener(`exit`, (code) => { 72 | process.exit(code ?? 0); 73 | }); 74 | } 75 | } 76 | 77 | const cli = new Cli({ 78 | binaryLabel: `oxnode`, 79 | binaryName: `${node} ${app}`, 80 | binaryVersion: pkgJson.version, 81 | }); 82 | 83 | cli.register(MainCommand); 84 | cli.register(Builtins.HelpCommand); 85 | cli.register(Builtins.VersionCommand); 86 | cli.runExit(stdArgs); 87 | -------------------------------------------------------------------------------- /packages/core/index.d.ts: -------------------------------------------------------------------------------- 1 | /* auto-generated by NAPI-RS */ 2 | /* eslint-disable */ 3 | export declare class Output { 4 | /** 5 | * Returns the generated code 6 | * Cache the result of this function if you need to use it multiple times 7 | */ 8 | source(): string; 9 | /** 10 | * Returns the source map as a JSON string 11 | * Cache the result of this function if you need to use it multiple times 12 | */ 13 | sourceMap(): string | null; 14 | } 15 | 16 | export declare class OxcTransformer { 17 | constructor(cwd?: string | undefined | null); 18 | transform(path: string, source: string | Uint8Array): Output; 19 | transformAsync(path: string, source: string | Uint8Array | Buffer): Promise; 20 | } 21 | 22 | export declare function createResolve( 23 | options: OxcResolveOptions, 24 | specifier: string, 25 | context: ResolveContext, 26 | nextResolve: ( 27 | arg0: string, 28 | arg1?: ResolveContext | undefined | null, 29 | ) => ResolveFnOutput | Promise, 30 | ): ResolveFnOutput | Promise; 31 | 32 | export declare function initTracing(): void; 33 | 34 | export declare function load( 35 | url: string, 36 | context: LoadContext, 37 | nextLoad: ( 38 | arg0: string, 39 | arg1?: LoadContext | undefined | null, 40 | ) => LoadFnOutput | Promise, 41 | ): LoadFnOutput | Promise; 42 | 43 | export interface LoadContext { 44 | /** Export conditions of the relevant `package.json` */ 45 | conditions?: Array; 46 | /** The format optionally supplied by the `resolve` hook chain */ 47 | format: string | null; 48 | /** An object whose key-value pairs represent the assertions for the module to import */ 49 | importAttributes: Record; 50 | } 51 | 52 | export interface LoadFnOutput { 53 | format: string; 54 | source?: string | Uint8Array | Buffer | null; 55 | responseURL?: string; 56 | } 57 | 58 | export interface OxcResolveOptions { 59 | getCurrentDirectory?: () => string; 60 | } 61 | 62 | export interface ResolveContext { 63 | /** Export conditions of the relevant `package.json` */ 64 | conditions: Array; 65 | /** An object whose key-value pairs represent the assertions for the module to import */ 66 | importAttributes: Record; 67 | parentURL?: string; 68 | } 69 | 70 | export interface ResolveFnOutput { 71 | format?: string | null; 72 | shortCircuit?: boolean; 73 | url: string; 74 | importAttributes?: Record | null; 75 | } 76 | 77 | export declare function transform(path: string, source: string | Uint8Array): Output; 78 | 79 | export declare function transformAsync( 80 | path: string, 81 | source: string | Uint8Array | Buffer, 82 | ): Promise; 83 | -------------------------------------------------------------------------------- /packages/integrate-module/src/index.ts: -------------------------------------------------------------------------------- 1 | import assert from "node:assert"; 2 | import test from "node:test"; 3 | 4 | import { EntryType } from "@napi-rs/tar"; 5 | import { OxcTransformer } from "@oxc-node/core"; 6 | import { bar as subBar } from "@subdirectory/bar.mjs"; 7 | import canvaskit from "canvaskit-wasm"; 8 | import { supportedExtensions } from "file-type"; 9 | import ipaddr from "ipaddr.js"; 10 | import postgres from "postgres"; 11 | import { renderToString } from "react-dom/server"; 12 | import { simpleGit } from "simple-git"; 13 | 14 | import { CompiledClass } from "./compiled.js"; 15 | import { Component } from "./component.js"; 16 | import { foo } from "./foo.mjs"; 17 | import { bar } from "./subdirectory/bar.mjs"; 18 | import { baz } from "./subdirectory/index.mjs"; 19 | import "./js-module.mjs"; 20 | import pkgJson from "../package.json"; 21 | import { version } from "../package.json"; 22 | 23 | const { foo: fooWithQuery } = await import(`./foo.mjs?q=${Date.now()}`); 24 | 25 | await test("file-type should work", () => { 26 | assert.ok(supportedExtensions.has("jpg")); 27 | }); 28 | 29 | await test("resolve adjacent file path", () => { 30 | assert.equal(foo(), "foo"); 31 | }); 32 | 33 | await test("resolve nested file path", () => { 34 | assert.equal(bar(), "bar"); 35 | }); 36 | 37 | await test("resolve nested entry point", () => { 38 | assert.equal(baz(), "baz"); 39 | }); 40 | 41 | await test("resolve paths", () => { 42 | assert.equal(subBar(), "bar"); 43 | }); 44 | 45 | await test("resolve with query", () => { 46 | assert.equal(fooWithQuery(), "foo"); 47 | }); 48 | 49 | await test("compiled js file with .d.ts", () => { 50 | const instance = new CompiledClass(); 51 | assert.equal(instance.name, "CompiledClass"); 52 | }); 53 | 54 | await test("jsx should work", () => { 55 | assert.equal(renderToString(Component()), "
Component
"); 56 | }); 57 | 58 | await test("resolve @napi-rs projects", () => { 59 | assert.equal(EntryType.GNUSparse, 10); 60 | }); 61 | 62 | await test("resolve simple-git", () => { 63 | assert.ok(simpleGit); 64 | }); 65 | 66 | await test("resolve package.json", () => { 67 | assert.equal(pkgJson.name, "integrate-module"); 68 | }); 69 | 70 | await test("named import from json", () => { 71 | assert.equal(version, "0.0.0"); 72 | }); 73 | 74 | await test("resolve ipaddr.js", () => { 75 | assert.ok(ipaddr.isValid("::1")); 76 | }); 77 | 78 | await test("resolve postgres", () => { 79 | const sql = postgres(); 80 | assert.ok(sql); 81 | }); 82 | 83 | await test("resolve canvaskit-wasm", async () => { 84 | if (process.arch === "s390x") { 85 | assert.ok("skipping test on s390x"); 86 | return; 87 | } 88 | // @ts-expect-error 89 | const canvas = await canvaskit(); 90 | assert.ok(canvas.MakeSurface(100, 100)); 91 | }); 92 | 93 | await test("should resolve native addon", async () => { 94 | const transformer = new OxcTransformer(process.cwd()); 95 | const result = await transformer.transformAsync("index.ts", "const a: number = 1"); 96 | assert.equal(result.source(), '"use strict";\nconst a = 1;\n'); 97 | }); 98 | -------------------------------------------------------------------------------- /packages/cli/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | ## [0.0.35](https://github.com/oxc-project/oxc-node/compare/v0.0.34...v0.0.35) (2025-12-01) 7 | 8 | **Note:** Version bump only for package @oxc-node/cli 9 | 10 | ## [0.0.34](https://github.com/oxc-project/oxc-node/compare/v0.0.33...v0.0.34) (2025-11-09) 11 | 12 | **Note:** Version bump only for package @oxc-node/cli 13 | 14 | ## [0.0.27](https://github.com/oxc-project/oxc-node/compare/v0.0.26...v0.0.27) (2025-05-03) 15 | 16 | **Note:** Version bump only for package @oxc-node/cli 17 | 18 | ## [0.0.26](https://github.com/oxc-project/oxc-node/compare/v0.0.25...v0.0.26) (2025-05-03) 19 | 20 | **Note:** Version bump only for package @oxc-node/cli 21 | 22 | ## [0.0.25](https://github.com/oxc-project/oxc-node/compare/v0.0.24...v0.0.25) (2025-05-02) 23 | 24 | ### Bug Fixes 25 | 26 | - respect module option in tsconfig.json ([#116](https://github.com/oxc-project/oxc-node/issues/116)) ([4acd6a9](https://github.com/oxc-project/oxc-node/commit/4acd6a9577f1108c0dc7c371f3e3ac2b16f6b3d6)) 27 | 28 | ## [0.0.24](https://github.com/oxc-project/oxc-node/compare/v0.0.23...v0.0.24) (2025-04-28) 29 | 30 | ### Bug Fixes 31 | 32 | - sourcemap generation ([#105](https://github.com/oxc-project/oxc-node/issues/105)) ([b583e28](https://github.com/oxc-project/oxc-node/commit/b583e28af61901b8a4314644b4c0dbe217f83a6d)) 33 | 34 | ## [0.0.23](https://github.com/oxc-project/oxc-node/compare/v0.0.22...v0.0.23) (2025-04-10) 35 | 36 | **Note:** Version bump only for package @oxc-node/cli 37 | 38 | ## [0.0.22](https://github.com/oxc-project/oxc-node/compare/v0.0.21...v0.0.22) (2025-04-02) 39 | 40 | **Note:** Version bump only for package @oxc-node/cli 41 | 42 | ## [0.0.21](https://github.com/oxc-project/oxc-node/compare/v0.0.20...v0.0.21) (2025-03-16) 43 | 44 | **Note:** Version bump only for package @oxc-node/cli 45 | 46 | ## [0.0.20](https://github.com/oxc-project/oxc-node/compare/v0.0.19...v0.0.20) (2025-03-05) 47 | 48 | **Note:** Version bump only for package @oxc-node/cli 49 | 50 | ## [0.0.19](https://github.com/oxc-project/oxc-node/compare/v0.0.18...v0.0.19) (2025-01-20) 51 | 52 | **Note:** Version bump only for package @oxc-node/cli 53 | 54 | ## [0.0.18](https://github.com/oxc-project/oxc-node/compare/v0.0.17...v0.0.18) (2025-01-20) 55 | 56 | **Note:** Version bump only for package @oxc-node/cli 57 | 58 | ## [0.0.17](https://github.com/oxc-project/oxc-node/compare/v0.0.16...v0.0.17) (2025-01-13) 59 | 60 | **Note:** Version bump only for package @oxc-node/cli 61 | 62 | ## [0.0.16](https://github.com/oxc-project/oxc-node/compare/v0.0.15...v0.0.16) (2024-12-13) 63 | 64 | **Note:** Version bump only for package @oxc-node/cli 65 | 66 | ## [0.0.14](https://github.com/oxc-project/oxc-node/compare/v0.0.12...v0.0.14) (2024-07-23) 67 | 68 | **Note:** Version bump only for package @oxc-node/cli 69 | 70 | ## [0.0.13](https://github.com/oxc-project/oxc-node/compare/v0.0.12...v0.0.13) (2024-07-23) 71 | 72 | **Note:** Version bump only for package @oxc-node/cli 73 | 74 | ## [0.0.12](https://github.com/oxc-project/oxc-node/compare/v0.0.11...v0.0.12) (2024-07-23) 75 | 76 | ### Features 77 | 78 | - **cli:** init oxnode ([#23](https://github.com/oxc-project/oxc-node/issues/23)) ([8740e05](https://github.com/oxc-project/oxc-node/commit/8740e05a97c33b99042824b09c92390421c90c81)) 79 | -------------------------------------------------------------------------------- /packages/integrate-module-bundler/src/index.ts: -------------------------------------------------------------------------------- 1 | import "core-js/modules/esnext.symbol.async-dispose"; 2 | import "core-js/modules/esnext.symbol.dispose"; 3 | 4 | import assert from "node:assert"; 5 | import { createRequire } from "node:module"; 6 | import test from "node:test"; 7 | 8 | import { EntryType } from "@napi-rs/tar"; 9 | import { bar as subBar } from "@subdirectory/bar"; 10 | import { supportedExtensions } from "file-type"; 11 | import { renderToString } from "react-dom/server"; 12 | import { simpleGit } from "simple-git"; 13 | 14 | import { common } from "./common.cjs"; 15 | import { CompiledClass } from "./compiled"; 16 | import { Component } from "./component"; 17 | // @ts-expect-error 18 | import { condition } from "condition-dev"; 19 | import { foo } from "./foo"; 20 | import { bar } from "./subdirectory/bar"; 21 | import { baz } from "./subdirectory/index"; 22 | import "./js-module"; 23 | import babelGeneratedDoubleDefault from "./babel-generated-double-default"; 24 | import { exportFromMts } from "./enforce-mts/index.mjs"; 25 | import { AppService } from "./nestjs/app.service"; 26 | import { bootstrap } from "./nestjs/index"; 27 | 28 | const { foo: fooWithQuery } = await import(`./foo.js?q=${Date.now()}`); 29 | 30 | await test("file-type should work", () => { 31 | assert.ok(supportedExtensions.has("jpg")); 32 | }); 33 | 34 | await test("resolve adjacent file path", () => { 35 | assert.equal(foo(), "foo"); 36 | }); 37 | 38 | await test("resolve nested file path", () => { 39 | assert.equal(bar(), "bar"); 40 | }); 41 | 42 | await test("resolve nested entry point", () => { 43 | assert.equal(baz(), "baz"); 44 | }); 45 | 46 | await test("resolve paths", () => { 47 | assert.equal(subBar(), "bar"); 48 | }); 49 | 50 | await test("resolve with query", () => { 51 | assert.equal(fooWithQuery(), "foo"); 52 | }); 53 | 54 | await test("compiled js file with .d.ts", () => { 55 | const instance = new CompiledClass(); 56 | assert.equal(instance.name, "CompiledClass"); 57 | }); 58 | 59 | await test("jsx should work", () => { 60 | assert.equal(renderToString(Component()), "
Component
"); 61 | }); 62 | 63 | await test("resolve @napi-rs projects", () => { 64 | assert.equal(EntryType.GNUSparse, 10); 65 | }); 66 | 67 | await test("resolve simple-git", () => { 68 | assert.ok(simpleGit); 69 | }); 70 | 71 | await test("import default from babel-generated cjs file", () => { 72 | assert.equal(babelGeneratedDoubleDefault.default(), "default.default"); 73 | }); 74 | 75 | await test("resolve cjs in type module package", () => { 76 | assert.equal(common, "common"); 77 | }); 78 | 79 | await test("resolve mts in type commonjs package", () => { 80 | assert.equal(exportFromMts, "exportFromMts"); 81 | }); 82 | 83 | await test("resolve nestjs", async () => { 84 | const { app } = await bootstrap(); 85 | const service = app.get(AppService); 86 | assert.equal(service.getHello(), "Hello World!"); 87 | assert.equal(service.websocket.port, 3001); 88 | await app.close(); 89 | }); 90 | 91 | await test("using syntax", async () => { 92 | await using nest = await bootstrap(); 93 | const service = nest.app.get(AppService); 94 | assert.equal(service.getHello(), "Hello World!"); 95 | }); 96 | 97 | await test("resolve correct condition", () => { 98 | assert.equal(condition, "dev"); 99 | }); 100 | 101 | await test("resolve typescript cjs", () => { 102 | const require = createRequire(import.meta.url); 103 | const fooCjs = require("./typescript-cjs").foo; 104 | assert.equal(fooCjs, "foo"); 105 | }); 106 | -------------------------------------------------------------------------------- /packages/core/oxc-node.wasi.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* prettier-ignore */ 3 | 4 | /* auto-generated by NAPI-RS */ 5 | 6 | const __nodeFs = require('node:fs') 7 | const __nodePath = require("node:path"); 8 | const { WASI: __nodeWASI } = require("node:wasi"); 9 | const { Worker } = require("node:worker_threads"); 10 | 11 | const { 12 | createOnMessage: __wasmCreateOnMessageForFsProxy, 13 | getDefaultContext: __emnapiGetDefaultContext, 14 | instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync, 15 | } = require("@napi-rs/wasm-runtime"); 16 | 17 | const __rootDir = __nodePath.parse(process.cwd()).root; 18 | 19 | const __wasi = new __nodeWASI({ 20 | version: "preview1", 21 | env: process.env, 22 | preopens: { 23 | [__rootDir]: __rootDir, 24 | }, 25 | }); 26 | 27 | const __emnapiContext = __emnapiGetDefaultContext(); 28 | 29 | const __sharedMemory = new WebAssembly.Memory({ 30 | initial: 16384, 31 | maximum: 65536, 32 | shared: true, 33 | }); 34 | 35 | let __wasmFilePath = __nodePath.join(__dirname, "oxc-node.wasm32-wasi.wasm"); 36 | const __wasmDebugFilePath = __nodePath.join(__dirname, "oxc-node.wasm32-wasi.debug.wasm"); 37 | 38 | if (__nodeFs.existsSync(__wasmDebugFilePath)) { 39 | __wasmFilePath = __wasmDebugFilePath; 40 | } else if (!__nodeFs.existsSync(__wasmFilePath)) { 41 | try { 42 | __wasmFilePath = __nodePath.resolve("@oxc-node/core-wasm32-wasi"); 43 | } catch { 44 | throw new Error( 45 | "Cannot find oxc-node.wasm32-wasi.wasm file, and @oxc-node/core-wasm32-wasi package is not installed.", 46 | ); 47 | } 48 | } 49 | 50 | const { 51 | instance: __napiInstance, 52 | module: __wasiModule, 53 | napiModule: __napiModule, 54 | } = __emnapiInstantiateNapiModuleSync(__nodeFs.readFileSync(__wasmFilePath), { 55 | context: __emnapiContext, 56 | asyncWorkPoolSize: (function () { 57 | const threadsSizeFromEnv = Number( 58 | process.env.NAPI_RS_ASYNC_WORK_POOL_SIZE ?? process.env.UV_THREADPOOL_SIZE, 59 | ); 60 | // NaN > 0 is false 61 | if (threadsSizeFromEnv > 0) { 62 | return threadsSizeFromEnv; 63 | } else { 64 | return 4; 65 | } 66 | })(), 67 | reuseWorker: true, 68 | wasi: __wasi, 69 | onCreateWorker() { 70 | const worker = new Worker(__nodePath.join(__dirname, "wasi-worker.mjs"), { 71 | env: process.env, 72 | }); 73 | worker.onmessage = ({ data }) => { 74 | __wasmCreateOnMessageForFsProxy(__nodeFs)(data); 75 | }; 76 | 77 | // The main thread of Node.js waits for all the active handles before exiting. 78 | // But Rust threads are never waited without `thread::join`. 79 | // So here we hack the code of Node.js to prevent the workers from being referenced (active). 80 | // According to https://github.com/nodejs/node/blob/19e0d472728c79d418b74bddff588bea70a403d0/lib/internal/worker.js#L415, 81 | // a worker is consist of two handles: kPublicPort and kHandle. 82 | { 83 | const kPublicPort = Object.getOwnPropertySymbols(worker).find((s) => 84 | s.toString().includes("kPublicPort"), 85 | ); 86 | if (kPublicPort) { 87 | worker[kPublicPort].ref = () => {}; 88 | } 89 | 90 | const kHandle = Object.getOwnPropertySymbols(worker).find((s) => 91 | s.toString().includes("kHandle"), 92 | ); 93 | if (kHandle) { 94 | worker[kHandle].ref = () => {}; 95 | } 96 | 97 | worker.unref(); 98 | } 99 | return worker; 100 | }, 101 | overwriteImports(importObject) { 102 | importObject.env = { 103 | ...importObject.env, 104 | ...importObject.napi, 105 | ...importObject.emnapi, 106 | memory: __sharedMemory, 107 | }; 108 | return importObject; 109 | }, 110 | beforeInit({ instance }) { 111 | for (const name of Object.keys(instance.exports)) { 112 | if (name.startsWith("__napi_register__")) { 113 | instance.exports[name](); 114 | } 115 | } 116 | }, 117 | }); 118 | module.exports = __napiModule.exports; 119 | module.exports.Output = __napiModule.exports.Output; 120 | module.exports.OxcTransformer = __napiModule.exports.OxcTransformer; 121 | module.exports.createResolve = __napiModule.exports.createResolve; 122 | module.exports.initTracing = __napiModule.exports.initTracing; 123 | module.exports.load = __napiModule.exports.load; 124 | module.exports.transform = __napiModule.exports.transform; 125 | module.exports.transformAsync = __napiModule.exports.transformAsync; 126 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .yarn/* 2 | !.yarn/patches 3 | !.yarn/plugins 4 | !.yarn/releases 5 | !.yarn/sdks 6 | !.yarn/versions 7 | 8 | # Swap the comments on the following lines if you wish to use zero-installs 9 | # In that case, don't forget to run `yarn config set enableGlobalCache false`! 10 | # Documentation here: https://yarnpkg.com/features/caching#zero-installs 11 | 12 | #!.yarn/cache 13 | .pnp.* 14 | 15 | 16 | ### Created by https://www.gitignore.io 17 | ### Node ### 18 | # Logs 19 | logs 20 | *.log 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | lerna-debug.log* 25 | .pnpm-debug.log* 26 | 27 | # Diagnostic reports (https://nodejs.org/api/report.html) 28 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 29 | 30 | # Runtime data 31 | pids 32 | *.pid 33 | *.seed 34 | *.pid.lock 35 | 36 | # Directory for instrumented libs generated by jscoverage/JSCover 37 | lib-cov 38 | 39 | # Coverage directory used by tools like istanbul 40 | coverage 41 | *.lcov 42 | 43 | # nyc test coverage 44 | .nyc_output 45 | 46 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 47 | .grunt 48 | 49 | # Bower dependency directory (https://bower.io/) 50 | bower_components 51 | 52 | # node-waf configuration 53 | .lock-wscript 54 | 55 | # Compiled binary addons (https://nodejs.org/api/addons.html) 56 | build/Release 57 | 58 | # Dependency directories 59 | node_modules/ 60 | jspm_packages/ 61 | 62 | # Snowpack dependency directory (https://snowpack.dev/) 63 | web_modules/ 64 | 65 | # TypeScript cache 66 | *.tsbuildinfo 67 | 68 | # Optional npm cache directory 69 | .npm 70 | 71 | # Optional eslint cache 72 | .eslintcache 73 | 74 | # Optional stylelint cache 75 | .stylelintcache 76 | 77 | # Microbundle cache 78 | .rpt2_cache/ 79 | .rts2_cache_cjs/ 80 | .rts2_cache_es/ 81 | .rts2_cache_umd/ 82 | 83 | # Optional REPL history 84 | .node_repl_history 85 | 86 | # Output of 'npm pack' 87 | *.tgz 88 | 89 | # Yarn Integrity file 90 | .yarn-integrity 91 | 92 | # dotenv environment variable files 93 | .env 94 | .env.development.local 95 | .env.test.local 96 | .env.production.local 97 | .env.local 98 | 99 | # parcel-bundler cache (https://parceljs.org/) 100 | .cache 101 | .parcel-cache 102 | 103 | # Next.js build output 104 | .next 105 | out 106 | 107 | # Nuxt.js build / generate output 108 | .nuxt 109 | dist 110 | 111 | # Gatsby files 112 | .cache/ 113 | # Comment in the public line in if your project uses Gatsby and not Next.js 114 | # https://nextjs.org/blog/next-9-1#public-directory-support 115 | # public 116 | 117 | # vuepress build output 118 | .vuepress/dist 119 | 120 | # vuepress v2.x temp and cache directory 121 | .temp 122 | .cache 123 | 124 | # Docusaurus cache and generated files 125 | .docusaurus 126 | 127 | # Serverless directories 128 | .serverless/ 129 | 130 | # FuseBox cache 131 | .fusebox/ 132 | 133 | # DynamoDB Local files 134 | .dynamodb/ 135 | 136 | # TernJS port file 137 | .tern-port 138 | 139 | # Stores VSCode versions used for testing VSCode extensions 140 | .vscode-test 141 | 142 | # yarn v2 143 | .yarn/cache 144 | .yarn/unplugged 145 | .yarn/build-state.yml 146 | .yarn/install-state.gz 147 | .pnp.* 148 | 149 | ### Node Patch ### 150 | # Serverless Webpack directories 151 | .webpack/ 152 | 153 | # Optional stylelint cache 154 | .stylelintcache 155 | 156 | # SvelteKit build / generate output 157 | .svelte-kit 158 | 159 | 160 | 161 | ### Created by https://www.gitignore.io 162 | ### macOS ### 163 | # General 164 | .DS_Store 165 | .AppleDouble 166 | .LSOverride 167 | 168 | # Icon must end with two \r 169 | Icon 170 | 171 | # Thumbnails 172 | ._* 173 | 174 | # Files that might appear in the root of a volume 175 | .DocumentRevisions-V100 176 | .fseventsd 177 | .Spotlight-V100 178 | .TemporaryItems 179 | .Trashes 180 | .VolumeIcon.icns 181 | .com.apple.timemachine.donotpresent 182 | 183 | # Directories potentially created on remote AFP share 184 | .AppleDB 185 | .AppleDesktop 186 | Network Trash Folder 187 | Temporary Items 188 | .apdisk 189 | 190 | ### macOS Patch ### 191 | # iCloud generated files 192 | *.icloud 193 | 194 | 195 | 196 | ### Created by https://www.gitignore.io 197 | ### Windows ### 198 | # Windows thumbnail cache files 199 | Thumbs.db 200 | Thumbs.db:encryptable 201 | ehthumbs.db 202 | ehthumbs_vista.db 203 | 204 | # Dump file 205 | *.stackdump 206 | 207 | # Folder config file 208 | [Dd]esktop.ini 209 | 210 | # Recycle Bin used on file shares 211 | $RECYCLE.BIN/ 212 | 213 | # Windows Installer files 214 | *.cab 215 | *.msi 216 | *.msix 217 | *.msm 218 | *.msp 219 | 220 | # Windows shortcuts 221 | *.lnk 222 | 223 | 224 | 225 | ### Created by https://www.gitignore.io 226 | ### Rust ### 227 | # Generated by Cargo 228 | # will have compiled files and executables 229 | debug/ 230 | target/ 231 | 232 | # These are backup files generated by rustfmt 233 | **/*.rs.bk 234 | 235 | # MSVC Windows builds of rustc generate these, which store debugging information 236 | *.pdb 237 | 238 | *.node 239 | *.wasm 240 | pgo-data 241 | /npm 242 | -------------------------------------------------------------------------------- /packages/core/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | ## [0.0.35](https://github.com/oxc-project/oxc-node/compare/v0.0.34...v0.0.35) (2025-12-01) 7 | 8 | ### Bug Fixes 9 | 10 | - **core:** transform tla error ([#355](https://github.com/oxc-project/oxc-node/issues/355)) ([3374ad1](https://github.com/oxc-project/oxc-node/commit/3374ad1f1be9ecd86ac76ed990b65013102ed806)) 11 | - sourcemaps for pirates hook. ([#350](https://github.com/oxc-project/oxc-node/issues/350)) ([dc915e0](https://github.com/oxc-project/oxc-node/commit/dc915e0336eeb9b326caa1fbd5628b8156f61d92)) 12 | 13 | ## [0.0.34](https://github.com/oxc-project/oxc-node/compare/v0.0.33...v0.0.34) (2025-11-09) 14 | 15 | **Note:** Version bump only for package @oxc-node/core 16 | 17 | ## [0.0.27](https://github.com/oxc-project/oxc-node/compare/v0.0.26...v0.0.27) (2025-05-03) 18 | 19 | **Note:** Version bump only for package @oxc-node/core 20 | 21 | ## [0.0.26](https://github.com/oxc-project/oxc-node/compare/v0.0.25...v0.0.26) (2025-05-03) 22 | 23 | **Note:** Version bump only for package @oxc-node/core 24 | 25 | ## [0.0.25](https://github.com/oxc-project/oxc-node/compare/v0.0.24...v0.0.25) (2025-05-02) 26 | 27 | **Note:** Version bump only for package @oxc-node/core 28 | 29 | ## [0.0.24](https://github.com/oxc-project/oxc-node/compare/v0.0.23...v0.0.24) (2025-04-28) 30 | 31 | ### Performance Improvements 32 | 33 | - remove with_scope_tree_child_ids workaround ([#104](https://github.com/oxc-project/oxc-node/issues/104)) ([d7df81e](https://github.com/oxc-project/oxc-node/commit/d7df81e7997bebd98f0d077f88a91390e65d1378)) 34 | 35 | ## [0.0.23](https://github.com/oxc-project/oxc-node/compare/v0.0.22...v0.0.23) (2025-04-10) 36 | 37 | ### Bug Fixes 38 | 39 | - **core:** pass resolved sources to nextResolve ([#96](https://github.com/oxc-project/oxc-node/issues/96)) ([3dd8faa](https://github.com/oxc-project/oxc-node/commit/3dd8faa8593968cf8585ec99d2f933db70419f97)) 40 | 41 | ## [0.0.22](https://github.com/oxc-project/oxc-node/compare/v0.0.21...v0.0.22) (2025-04-02) 42 | 43 | ### Features 44 | 45 | - resolve cjs files ([#93](https://github.com/oxc-project/oxc-node/issues/93)) ([9ef439e](https://github.com/oxc-project/oxc-node/commit/9ef439e78ed11069f93629d756316ae377618e20)) 46 | 47 | ## [0.0.21](https://github.com/oxc-project/oxc-node/compare/v0.0.20...v0.0.21) (2025-03-16) 48 | 49 | **Note:** Version bump only for package @oxc-node/core 50 | 51 | ## [0.0.20](https://github.com/oxc-project/oxc-node/compare/v0.0.19...v0.0.20) (2025-03-05) 52 | 53 | **Note:** Version bump only for package @oxc-node/core 54 | 55 | ## [0.0.19](https://github.com/oxc-project/oxc-node/compare/v0.0.18...v0.0.19) (2025-01-20) 56 | 57 | **Note:** Version bump only for package @oxc-node/core 58 | 59 | ## [0.0.18](https://github.com/oxc-project/oxc-node/compare/v0.0.17...v0.0.18) (2025-01-20) 60 | 61 | **Note:** Version bump only for package @oxc-node/core 62 | 63 | ## [0.0.17](https://github.com/oxc-project/oxc-node/compare/v0.0.16...v0.0.17) (2025-01-13) 64 | 65 | **Note:** Version bump only for package @oxc-node/core 66 | 67 | ## [0.0.16](https://github.com/oxc-project/oxc-node/compare/v0.0.15...v0.0.16) (2024-12-13) 68 | 69 | **Note:** Version bump only for package @oxc-node/core 70 | 71 | ## [0.0.14](https://github.com/oxc-project/oxc-node/compare/v0.0.12...v0.0.14) (2024-07-23) 72 | 73 | **Note:** Version bump only for package @oxc-node/core 74 | 75 | ## [0.0.13](https://github.com/oxc-project/oxc-node/compare/v0.0.12...v0.0.13) (2024-07-23) 76 | 77 | **Note:** Version bump only for package @oxc-node/core 78 | 79 | ## [0.0.12](https://github.com/oxc-project/oxc-node/compare/v0.0.11...v0.0.12) (2024-07-23) 80 | 81 | ### Features 82 | 83 | - **cli:** init oxnode ([#23](https://github.com/oxc-project/oxc-node/issues/23)) ([8740e05](https://github.com/oxc-project/oxc-node/commit/8740e05a97c33b99042824b09c92390421c90c81)) 84 | 85 | ## [0.0.11](https://github.com/oxc-project/oxc-node/compare/v0.0.10...v0.0.11) (2024-07-21) 86 | 87 | ### Bug Fixes 88 | 89 | - **core:** wasi target ([#22](https://github.com/oxc-project/oxc-node/issues/22)) ([e7a57f3](https://github.com/oxc-project/oxc-node/commit/e7a57f334bce84f15b04f781b5ce7078d52a8872)) 90 | 91 | ## [0.0.10](https://github.com/oxc-project/oxc-node/compare/v0.0.9...v0.0.10) (2024-07-18) 92 | 93 | **Note:** Version bump only for package @oxc-node/core 94 | 95 | ## [0.0.9](https://github.com/oxc-project/oxc-node/compare/v0.0.8...v0.0.9) (2024-07-17) 96 | 97 | **Note:** Version bump only for package @oxc-node/core 98 | 99 | ## [0.0.8](https://github.com/oxc-project/oxc-node/compare/v0.0.7...v0.0.8) (2024-07-16) 100 | 101 | **Note:** Version bump only for package @oxc-node/core 102 | 103 | ## [0.0.6](https://github.com/oxc-project/oxc-node/compare/v0.0.5...v0.0.6) (2024-07-13) 104 | 105 | ### Bug Fixes 106 | 107 | - **core:** resolve .cjs/.cts file in esm pacakge ([#7](https://github.com/oxc-project/oxc-node/issues/7)) ([9616417](https://github.com/oxc-project/oxc-node/commit/9616417cb5c78ef3eae234b831c6aa425979f34b)) 108 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | ## [0.0.35](https://github.com/oxc-project/oxc-node/compare/v0.0.34...v0.0.35) (2025-12-01) 7 | 8 | ### Bug Fixes 9 | 10 | - **core:** transform tla error ([#355](https://github.com/oxc-project/oxc-node/issues/355)) ([3374ad1](https://github.com/oxc-project/oxc-node/commit/3374ad1f1be9ecd86ac76ed990b65013102ed806)) 11 | - sourcemaps for pirates hook. ([#350](https://github.com/oxc-project/oxc-node/issues/350)) ([dc915e0](https://github.com/oxc-project/oxc-node/commit/dc915e0336eeb9b326caa1fbd5628b8156f61d92)) 12 | 13 | ## [0.0.34](https://github.com/oxc-project/oxc-node/compare/v0.0.33...v0.0.34) (2025-11-09) 14 | 15 | **Note:** Version bump only for package oxc-node 16 | 17 | ## [0.0.27](https://github.com/oxc-project/oxc-node/compare/v0.0.26...v0.0.27) (2025-05-03) 18 | 19 | **Note:** Version bump only for package oxc-node 20 | 21 | ## [0.0.26](https://github.com/oxc-project/oxc-node/compare/v0.0.25...v0.0.26) (2025-05-03) 22 | 23 | **Note:** Version bump only for package oxc-node 24 | 25 | ## [0.0.25](https://github.com/oxc-project/oxc-node/compare/v0.0.24...v0.0.25) (2025-05-02) 26 | 27 | ### Bug Fixes 28 | 29 | - respect module option in tsconfig.json ([#116](https://github.com/oxc-project/oxc-node/issues/116)) ([4acd6a9](https://github.com/oxc-project/oxc-node/commit/4acd6a9577f1108c0dc7c371f3e3ac2b16f6b3d6)) 30 | 31 | ## [0.0.24](https://github.com/oxc-project/oxc-node/compare/v0.0.23...v0.0.24) (2025-04-28) 32 | 33 | ### Bug Fixes 34 | 35 | - sourcemap generation ([#105](https://github.com/oxc-project/oxc-node/issues/105)) ([b583e28](https://github.com/oxc-project/oxc-node/commit/b583e28af61901b8a4314644b4c0dbe217f83a6d)) 36 | 37 | ### Performance Improvements 38 | 39 | - remove with_scope_tree_child_ids workaround ([#104](https://github.com/oxc-project/oxc-node/issues/104)) ([d7df81e](https://github.com/oxc-project/oxc-node/commit/d7df81e7997bebd98f0d077f88a91390e65d1378)) 40 | 41 | ## [0.0.23](https://github.com/oxc-project/oxc-node/compare/v0.0.22...v0.0.23) (2025-04-10) 42 | 43 | ### Bug Fixes 44 | 45 | - **core:** pass resolved sources to nextResolve ([#96](https://github.com/oxc-project/oxc-node/issues/96)) ([3dd8faa](https://github.com/oxc-project/oxc-node/commit/3dd8faa8593968cf8585ec99d2f933db70419f97)) 46 | - **core:** resolve path in node_modules ([#94](https://github.com/oxc-project/oxc-node/issues/94)) ([f211208](https://github.com/oxc-project/oxc-node/commit/f2112082a18c6b07755f7f568967247ac0d57eb6)) 47 | 48 | ### Features 49 | 50 | - allow read useDefineForClassFields compiler option in tsconfig.json ([#97](https://github.com/oxc-project/oxc-node/issues/97)) ([55830b3](https://github.com/oxc-project/oxc-node/commit/55830b32bf8a9bb557ec7f0a32017c9f9a9ab1da)) 51 | 52 | ## [0.0.22](https://github.com/oxc-project/oxc-node/compare/v0.0.21...v0.0.22) (2025-04-02) 53 | 54 | ### Bug Fixes 55 | 56 | - **core:** pass tsconfig: None to Resolver if tsconfig not exists ([#84](https://github.com/oxc-project/oxc-node/issues/84)) ([9b46f48](https://github.com/oxc-project/oxc-node/commit/9b46f487e2d5775cb7b124ca1308733f720536f3)) 57 | 58 | ### Features 59 | 60 | - **core:** pass tsconfig options to oxc ([#92](https://github.com/oxc-project/oxc-node/issues/92)) ([2771453](https://github.com/oxc-project/oxc-node/commit/2771453654414ad1960f28ab89b5a90cbaf6b988)) 61 | - resolve cjs files ([#93](https://github.com/oxc-project/oxc-node/issues/93)) ([9ef439e](https://github.com/oxc-project/oxc-node/commit/9ef439e78ed11069f93629d756316ae377618e20)) 62 | 63 | ## [0.0.21](https://github.com/oxc-project/oxc-node/compare/v0.0.20...v0.0.21) (2025-03-16) 64 | 65 | **Note:** Version bump only for package oxc-node 66 | 67 | ## [0.0.20](https://github.com/oxc-project/oxc-node/compare/v0.0.19...v0.0.20) (2025-03-05) 68 | 69 | **Note:** Version bump only for package oxc-node 70 | 71 | ## [0.0.19](https://github.com/oxc-project/oxc-node/compare/v0.0.18...v0.0.19) (2025-01-20) 72 | 73 | **Note:** Version bump only for package oxc-node 74 | 75 | ## [0.0.18](https://github.com/oxc-project/oxc-node/compare/v0.0.17...v0.0.18) (2025-01-20) 76 | 77 | ### Bug Fixes 78 | 79 | - **core:** enfore to esm if file extensions match ([#55](https://github.com/oxc-project/oxc-node/issues/55)) ([560ee7a](https://github.com/oxc-project/oxc-node/commit/560ee7a3e5c120a57b34fdba81e9e8f57b0826d1)) 80 | 81 | ## [0.0.17](https://github.com/oxc-project/oxc-node/compare/v0.0.16...v0.0.17) (2025-01-13) 82 | 83 | ### Bug Fixes 84 | 85 | - **core:** resolve entry with oxc_resolver ([#53](https://github.com/oxc-project/oxc-node/issues/53)) ([85af142](https://github.com/oxc-project/oxc-node/commit/85af1423129a582a72aea52de426f1f6cc5c091f)) 86 | 87 | ## [0.0.16](https://github.com/oxc-project/oxc-node/compare/v0.0.15...v0.0.16) (2024-12-13) 88 | 89 | **Note:** Version bump only for package oxc-node 90 | 91 | ## [0.0.14](https://github.com/oxc-project/oxc-node/compare/v0.0.12...v0.0.14) (2024-07-23) 92 | 93 | **Note:** Version bump only for package oxc-node 94 | 95 | ## [0.0.13](https://github.com/oxc-project/oxc-node/compare/v0.0.12...v0.0.13) (2024-07-23) 96 | 97 | **Note:** Version bump only for package oxc-node 98 | 99 | ## [0.0.12](https://github.com/oxc-project/oxc-node/compare/v0.0.11...v0.0.12) (2024-07-23) 100 | 101 | ### Features 102 | 103 | - **cli:** init oxnode ([#23](https://github.com/oxc-project/oxc-node/issues/23)) ([8740e05](https://github.com/oxc-project/oxc-node/commit/8740e05a97c33b99042824b09c92390421c90c81)) 104 | 105 | ## [0.0.11](https://github.com/oxc-project/oxc-node/compare/v0.0.10...v0.0.11) (2024-07-21) 106 | 107 | ### Bug Fixes 108 | 109 | - **core:** wasi target ([#22](https://github.com/oxc-project/oxc-node/issues/22)) ([e7a57f3](https://github.com/oxc-project/oxc-node/commit/e7a57f334bce84f15b04f781b5ce7078d52a8872)) 110 | 111 | ## [0.0.10](https://github.com/oxc-project/oxc-node/compare/v0.0.9...v0.0.10) (2024-07-18) 112 | 113 | ### Features 114 | 115 | - support named import from json ([#20](https://github.com/oxc-project/oxc-node/issues/20)) ([622f1fa](https://github.com/oxc-project/oxc-node/commit/622f1fa880cd596057bf41ea44dca60951f80180)) 116 | 117 | ## [0.0.9](https://github.com/Brooooooklyn/oxc-node/compare/v0.0.8...v0.0.9) (2024-07-17) 118 | 119 | **Note:** Version bump only for package oxc-node 120 | 121 | ## [0.0.8](https://github.com/Brooooooklyn/oxc-node/compare/v0.0.7...v0.0.8) (2024-07-16) 122 | 123 | ### Features 124 | 125 | - **core:** handle TypeScript resolveJsonModule option ([#12](https://github.com/Brooooooklyn/oxc-node/issues/12)) ([3b0d0a4](https://github.com/Brooooooklyn/oxc-node/commit/3b0d0a46072be64752b70cfaf4cfcdcab4617335)) 126 | 127 | ### Performance Improvements 128 | 129 | - **core:** skip transform files in node_modules ([#13](https://github.com/Brooooooklyn/oxc-node/issues/13)) ([0ed2c19](https://github.com/Brooooooklyn/oxc-node/commit/0ed2c1915902613968735aacc6c41a2ae7c77531)) 130 | 131 | ## [0.0.6](https://github.com/Brooooooklyn/oxc-node/compare/v0.0.5...v0.0.6) (2024-07-13) 132 | 133 | ### Bug Fixes 134 | 135 | - **core:** resolve .cjs/.cts file in esm pacakge ([#7](https://github.com/Brooooooklyn/oxc-node/issues/7)) ([9616417](https://github.com/Brooooooklyn/oxc-node/commit/9616417cb5c78ef3eae234b831c6aa425979f34b)) 136 | -------------------------------------------------------------------------------- /.github/workflows/CI.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | env: 4 | DEBUG: napi:* 5 | APP_NAME: oxc-node 6 | OXC_LOG: "debug" 7 | MACOSX_DEPLOYMENT_TARGET: "10.13" 8 | TARGET_CC: clang 9 | 10 | permissions: {} 11 | 12 | on: 13 | push: 14 | branches: 15 | - main 16 | tags-ignore: 17 | - "**" 18 | paths-ignore: 19 | - "**/*.md" 20 | - LICENSE 21 | - "**/*.gitignore" 22 | - .editorconfig 23 | - docs/** 24 | pull_request: null 25 | 26 | concurrency: 27 | group: ${{ github.workflow }}-${{ github.ref }} 28 | cancel-in-progress: true 29 | 30 | jobs: 31 | lint: 32 | name: Lint 33 | runs-on: ubuntu-latest 34 | steps: 35 | - uses: taiki-e/checkout-action@b13d20b7cda4e2f325ef19895128f7ff735c0b3d # v1.3.1 36 | - name: setup pnpm 37 | uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4.2.0 38 | - name: Setup node 39 | uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0 40 | with: 41 | node-version: 22 42 | cache: pnpm 43 | - name: Install dependencies 44 | run: pnpm install 45 | - name: Lint 46 | run: pnpm lint 47 | - name: Clippy 48 | run: cargo clippy --all-targets --all-features -- -D warnings 49 | 50 | build-cli: 51 | name: Build CLI 52 | runs-on: ubuntu-latest 53 | steps: 54 | - uses: taiki-e/checkout-action@b13d20b7cda4e2f325ef19895128f7ff735c0b3d # v1.3.1 55 | - name: setup pnpm 56 | uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4.2.0 57 | - name: Setup node 58 | uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0 59 | with: 60 | node-version: 22 61 | cache: pnpm 62 | - name: Install dependencies 63 | run: pnpm install 64 | - name: Build 65 | run: pnpm --filter="@oxc-node/cli" build 66 | - name: Test global install 67 | run: | 68 | npm install -g ./packages/cli 69 | cd /tmp 70 | which oxnode 71 | oxnode --version 72 | oxnode --help 73 | - name: Upload artifact 74 | uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 75 | with: 76 | name: cli 77 | path: ./packages/cli/dist 78 | 79 | build: 80 | strategy: 81 | fail-fast: false 82 | matrix: 83 | settings: 84 | - host: macos-latest 85 | target: x86_64-apple-darwin 86 | build: pnpm --filter=@oxc-node/core build --target x86_64-apple-darwin 87 | - host: windows-latest 88 | build: pnpm --filter=@oxc-node/core build --target x86_64-pc-windows-msvc 89 | target: x86_64-pc-windows-msvc 90 | - host: windows-latest 91 | build: pnpm --filter=@oxc-node/core build --target i686-pc-windows-msvc 92 | target: i686-pc-windows-msvc 93 | - host: ubuntu-latest 94 | target: x86_64-unknown-linux-gnu 95 | build: pnpm --filter=@oxc-node/core build --target x86_64-unknown-linux-gnu --use-napi-cross 96 | - host: ubuntu-latest 97 | target: x86_64-unknown-linux-musl 98 | build: pnpm --filter=@oxc-node/core build --target x86_64-unknown-linux-musl -x 99 | - host: macos-latest 100 | target: aarch64-apple-darwin 101 | build: pnpm --filter=@oxc-node/core build --target aarch64-apple-darwin 102 | - host: ubuntu-latest 103 | target: aarch64-unknown-linux-gnu 104 | build: pnpm --filter=@oxc-node/core build --target aarch64-unknown-linux-gnu --use-napi-cross 105 | - host: ubuntu-latest 106 | target: armv7-unknown-linux-gnueabihf 107 | build: pnpm --filter=@oxc-node/core build --target armv7-unknown-linux-gnueabihf --use-napi-cross 108 | - host: ubuntu-latest 109 | target: aarch64-linux-android 110 | build: pnpm --filter=@oxc-node/core build --target aarch64-linux-android 111 | - host: ubuntu-latest 112 | target: armv7-linux-androideabi 113 | build: pnpm --filter=@oxc-node/core build --target armv7-linux-androideabi 114 | - host: ubuntu-latest 115 | target: aarch64-unknown-linux-musl 116 | build: pnpm --filter=@oxc-node/core build --target aarch64-unknown-linux-musl -x 117 | - host: windows-latest 118 | target: aarch64-pc-windows-msvc 119 | build: pnpm --filter=@oxc-node/core build --target aarch64-pc-windows-msvc 120 | - host: ubuntu-latest 121 | target: powerpc64le-unknown-linux-gnu 122 | build: | 123 | export CC=clang 124 | pnpm --filter=@oxc-node/core build --target powerpc64le-unknown-linux-gnu --use-napi-cross 125 | # Segmentation fault (core dumped) 126 | # https://github.com/tonistiigi/binfmt/issues/215 127 | - host: ubuntu-latest 128 | target: s390x-unknown-linux-gnu 129 | build: | 130 | export CC=clang 131 | export CFLAGS="-fuse-ld=lld" 132 | pnpm --filter=@oxc-node/core build --target s390x-unknown-linux-gnu --use-napi-cross 133 | - host: ubuntu-latest 134 | target: aarch64-unknown-linux-ohos 135 | build: pnpm --filter=@oxc-node/core build --target aarch64-unknown-linux-ohos 136 | - host: ubuntu-latest 137 | target: wasm32-wasip1-threads 138 | build: pnpm --filter=@oxc-node/core build --target wasm32-wasip1-threads 139 | name: stable - ${{ matrix.settings.target }} - node@22 140 | runs-on: ${{ matrix.settings.host }} 141 | steps: 142 | - uses: taiki-e/checkout-action@b13d20b7cda4e2f325ef19895128f7ff735c0b3d # v1.3.1 143 | - name: setup pnpm 144 | uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4.2.0 145 | - name: Setup node 146 | uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0 147 | with: 148 | node-version: 22 149 | cache: pnpm 150 | - name: Install 151 | run: rustup target add ${{ matrix.settings.target }} 152 | - uses: oxc-project/setup-rust@ecabb7322a2ba5aeedb3612d2a40b86a85cee235 # v1.0.11 153 | with: 154 | cache-key: ${{ matrix.settings.target }}-${{ matrix.settings.host }} 155 | save-cache: ${{ github.ref_name == 'main' }} 156 | - name: Cache cross toolchain 157 | uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1 158 | with: 159 | path: ~/.napi-rs 160 | key: ${{ matrix.settings.target }}-cargo-${{ matrix.settings.host }} 161 | - uses: mlugg/setup-zig@fa65c4058643678a4e4a9a60513944a7d8d35440 # v2.1.0 162 | if: ${{ contains(matrix.settings.target, 'musl') }} 163 | with: 164 | version: 0.15.2 165 | - name: Install cargo-zigbuild 166 | uses: taiki-e/install-action@5818d9684d2a52207bb7475983a18ba56127e337 # v2.63.2 167 | if: ${{ contains(matrix.settings.target, 'musl') }} 168 | with: 169 | tool: cargo-zigbuild 170 | - name: Setup OpenHarmony toolchain 171 | if: ${{ contains(matrix.settings.target, 'ohos') }} 172 | uses: Boshen/setup-ohos-sdk@edb865a89a712f1f15dbad932dfa9cfce849d95c # v1.0.0 173 | - name: Setup toolchain 174 | run: ${{ matrix.settings.setup }} 175 | if: ${{ matrix.settings.setup }} 176 | shell: bash 177 | - name: Install dependencies 178 | run: pnpm install 179 | - name: Setup node x86 180 | uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0 181 | if: matrix.settings.target == 'i686-pc-windows-msvc' 182 | with: 183 | node-version: 22 184 | cache: pnpm 185 | architecture: x86 186 | - name: Build 187 | run: ${{ matrix.settings.build }} 188 | shell: bash 189 | - name: Upload artifact 190 | uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 191 | with: 192 | name: bindings-${{ matrix.settings.target }} 193 | path: | 194 | ./packages/core/*.node 195 | ./packages/core/*.wasm 196 | if-no-files-found: error 197 | 198 | build-freebsd: 199 | name: Build FreeBSD 200 | runs-on: ubuntu-latest 201 | steps: 202 | - uses: taiki-e/checkout-action@b13d20b7cda4e2f325ef19895128f7ff735c0b3d # v1.3.1 203 | - name: Build 204 | id: build 205 | uses: cross-platform-actions/action@46e8d7fb25520a8d6c64fd2b7a1192611da98eda # v0.30.0 206 | env: 207 | DEBUG: napi:* 208 | RUSTUP_IO_THREADS: 1 209 | with: 210 | operating_system: freebsd 211 | version: "14.2" 212 | memory: 8G 213 | cpu_count: 3 214 | environment_variables: "DEBUG RUSTUP_IO_THREADS" 215 | shell: bash 216 | run: | 217 | sudo pkg install -y -f curl node libnghttp2 npm cmake 218 | curl https://sh.rustup.rs -sSf --output rustup.sh 219 | sh rustup.sh -y --profile minimal --default-toolchain stable 220 | source "$HOME/.cargo/env" 221 | rustup install 222 | echo "~~~~ rustc --version ~~~~" 223 | rustc --version 224 | echo "~~~~ node -v ~~~~" 225 | node -v 226 | pwd 227 | ls -lah 228 | whoami 229 | env 230 | sudo npm install -g corepack 231 | sudo corepack enable 232 | pnpm install 233 | pnpm --filter=@oxc-node/core build --target x86_64-unknown-freebsd 234 | pnpm --filter=@oxc-node/core export-oxc-runtime 235 | pnpm --filter @oxc-node/cli build 236 | pnpm rebuild 237 | pnpm test 238 | rm -rf node_modules 239 | rm -rf target 240 | - name: Upload artifact 241 | uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 242 | with: 243 | name: bindings-x86_64-unknown-freebsd 244 | path: ./packages/core/*.node 245 | if-no-files-found: error 246 | 247 | test-macOS-windows-binding: 248 | name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }} - transform all@${{ matrix.transform_all }} 249 | needs: 250 | - build 251 | - build-cli 252 | strategy: 253 | fail-fast: false 254 | matrix: 255 | settings: 256 | - host: windows-latest 257 | target: x86_64-pc-windows-msvc 258 | architecture: x64 259 | - host: windows-latest 260 | target: i686-pc-windows-msvc 261 | architecture: x86 262 | - host: windows-11-arm 263 | target: aarch64-pc-windows-msvc 264 | architecture: arm64 265 | - host: macos-latest 266 | target: x86_64-apple-darwin 267 | architecture: x64 268 | - host: macos-latest 269 | target: aarch64-apple-darwin 270 | architecture: arm64 271 | node: 272 | - "20" 273 | - "22" 274 | transform_all: 275 | - "true" 276 | - "false" 277 | exclude: 278 | - settings: 279 | target: i686-pc-windows-msvc 280 | node: "20" 281 | runs-on: ${{ matrix.settings.host }} 282 | steps: 283 | - uses: taiki-e/checkout-action@b13d20b7cda4e2f325ef19895128f7ff735c0b3d # v1.3.1 284 | - name: setup pnpm 285 | uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4.2.0 286 | - name: Setup node 287 | uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0 288 | with: 289 | node-version: ${{ matrix.node }} 290 | cache: pnpm 291 | check-latest: true 292 | architecture: ${{ matrix.settings.architecture }} 293 | - uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0 294 | with: 295 | name: cli 296 | path: ./packages/cli/dist 297 | - name: Install dependencies 298 | run: pnpm install 299 | - name: Download artifacts 300 | uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0 301 | with: 302 | name: bindings-${{ matrix.settings.target }} 303 | path: ./packages/core 304 | - name: List packages 305 | run: ls -R . 306 | shell: bash 307 | - name: Copy OXC Runtime 308 | run: pnpm --filter=@oxc-node/core export-oxc-runtime 309 | - name: Test bindings 310 | run: pnpm test 311 | env: 312 | OXC_TRANSFORM_ALL: ${{ matrix.transform_all }} 313 | test-linux-binding: 314 | name: Test ${{ matrix.target }} - node@${{ matrix.node }} 315 | needs: 316 | - build 317 | - build-cli 318 | strategy: 319 | fail-fast: false 320 | matrix: 321 | target: 322 | - x86_64-unknown-linux-gnu 323 | - x86_64-unknown-linux-musl 324 | - aarch64-unknown-linux-gnu 325 | - aarch64-unknown-linux-musl 326 | - armv7-unknown-linux-gnueabihf 327 | - s390x-unknown-linux-gnu 328 | - powerpc64le-unknown-linux-gnu 329 | node: 330 | - "20" 331 | - "22" 332 | # Node.js on qemu segfaults on s390x and arm64v8 when using 24.04 333 | # See also https://github.com/actions/runner-images/issues/11471 334 | runs-on: ${{ contains(matrix.target, 'aarch64') && 'ubuntu-24.04-arm' || 'ubuntu-24.04' }} 335 | steps: 336 | - uses: taiki-e/checkout-action@b13d20b7cda4e2f325ef19895128f7ff735c0b3d # v1.3.1 337 | - name: setup pnpm 338 | uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4.2.0 339 | - name: Setup node 340 | uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0 341 | with: 342 | node-version: ${{ matrix.node }} 343 | cache: pnpm 344 | - name: Output docker params 345 | id: docker 346 | run: | 347 | node -e " 348 | if ('${{ matrix.target }}'.startsWith('aarch64')) { 349 | console.log('PLATFORM=linux/arm64') 350 | } else if ('${{ matrix.target }}'.startsWith('armv7')) { 351 | console.log('PLATFORM=linux/arm/v7') 352 | } else if ('${{ matrix.target }}'.startsWith('powerpc64le')) { 353 | console.log('PLATFORM=linux/ppc64le') 354 | } else if ('${{ matrix.target }}'.startsWith('s390x')) { 355 | console.log('PLATFORM=linux/s390x') 356 | } else { 357 | console.log('PLATFORM=linux/amd64') 358 | } 359 | " >> $GITHUB_OUTPUT 360 | node -e " 361 | if ('${{ matrix.target }}'.endsWith('-musl')) { 362 | console.log('IMAGE=node:${{ matrix.node }}-alpine') 363 | } else { 364 | console.log('IMAGE=node:${{ matrix.node }}-slim') 365 | } 366 | " >> $GITHUB_OUTPUT 367 | echo "PNPM_STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_OUTPUT 368 | - uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0 369 | with: 370 | name: cli 371 | path: ./packages/cli/dist 372 | # use --force to download the all platform/arch dependencies 373 | - name: Install dependencies 374 | run: pnpm install --force 375 | - name: Download artifacts 376 | uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0 377 | with: 378 | name: bindings-${{ matrix.target }} 379 | path: ./packages/core 380 | - name: List packages 381 | run: ls -R . 382 | shell: bash 383 | - name: Copy OXC Runtime 384 | run: pnpm --filter=@oxc-node/core export-oxc-runtime 385 | - name: Set up QEMU 386 | if: ${{ !contains(matrix.target, 'aarch64') }} 387 | uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0 388 | with: 389 | platforms: all 390 | image: tonistiigi/binfmt:qemu-v10.0.4 391 | - run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes 392 | if: ${{ !contains(matrix.target, 'aarch64') }} 393 | - name: Test bindings 394 | uses: addnab/docker-run-action@4f65fabd2431ebc8d299f8e5a018d79a769ae185 # v3 395 | # Node.js on qemu randomly segfaults on powerpc64le and s390x 396 | continue-on-error: ${{ matrix.target == 'powerpc64le-unknown-linux-gnu' || matrix.target == 's390x-unknown-linux-gnu' }} 397 | with: 398 | image: ${{ steps.docker.outputs.IMAGE }} 399 | options: -v ${{ steps.docker.outputs.PNPM_STORE_PATH }}:${{ steps.docker.outputs.PNPM_STORE_PATH }} -v ${{ github.workspace }}:${{ github.workspace }} -w ${{ github.workspace }} --platform ${{ steps.docker.outputs.PLATFORM }} 400 | run: npm i -g corepack && corepack enable && pnpm test 401 | test-wasi: 402 | name: Test WASI target 403 | needs: 404 | - build 405 | - build-cli 406 | runs-on: ubuntu-latest 407 | steps: 408 | - uses: taiki-e/checkout-action@b13d20b7cda4e2f325ef19895128f7ff735c0b3d # v1.3.1 409 | - name: setup pnpm 410 | uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4.2.0 411 | - name: Setup node 412 | uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0 413 | with: 414 | node-version: 22 415 | cache: pnpm 416 | - uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0 417 | with: 418 | name: cli 419 | path: ./packages/cli/dist 420 | - name: Install dependencies 421 | run: pnpm install --force 422 | - name: Download artifacts 423 | uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0 424 | with: 425 | name: bindings-wasm32-wasip1-threads 426 | path: ./packages/core 427 | - name: List packages 428 | run: ls -R . 429 | shell: bash 430 | - name: Copy OXC Runtime 431 | run: pnpm --filter=@oxc-node/core export-oxc-runtime 432 | - name: Test bindings 433 | run: pnpm test 434 | env: 435 | NAPI_RS_FORCE_WASI: 1 436 | publish: 437 | name: Publish 438 | runs-on: ubuntu-latest 439 | needs: 440 | - lint 441 | - test-macOS-windows-binding 442 | - test-linux-binding 443 | - build-freebsd 444 | - test-wasi 445 | permissions: 446 | contents: write 447 | id-token: write 448 | steps: 449 | - uses: taiki-e/checkout-action@b13d20b7cda4e2f325ef19895128f7ff735c0b3d # v1.3.1 450 | - name: setup pnpm 451 | uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4.2.0 452 | - name: Setup node 453 | uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0 454 | with: 455 | node-version: 22 456 | cache: pnpm 457 | - name: Install dependencies 458 | run: pnpm install 459 | - name: Download all artifacts 460 | uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0 461 | with: 462 | path: artifacts 463 | - name: Prepare publish 464 | run: | 465 | pnpm napi create-npm-dirs --package-json-path packages/core/package.json 466 | pnpm napi artifacts --package-json-path packages/core/package.json --build-output-dir packages/core 467 | pnpm --filter=@oxc-node/core export-oxc-runtime 468 | - name: List packages 469 | run: ls -R ./npm 470 | shell: bash 471 | - uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0 472 | with: 473 | name: cli 474 | path: ./packages/cli/dist 475 | - name: Publish 476 | run: | 477 | npm install -g npm 478 | if git log -1 --pretty=%B | grep "^v\?[0-9]\+\.[0-9]\+\.[0-9]\+$"; 479 | then 480 | pnpm napi pre-publish -t npm --package-json-path packages/core/package.json 481 | pnpm publish -r --access public --no-git-checks 482 | elif git log -1 --pretty=%B | grep "^v\?[0-9]\+\.[0-9]\+\.[0-9]\+"; 483 | then 484 | pnpm napi pre-publish -t npm --package-json-path packages/core/package.json 485 | pnpm -r publish --tag next --access public --no-git-checks 486 | else 487 | echo "Not a release, skipping publish" 488 | fi 489 | -------------------------------------------------------------------------------- /packages/core/index.js: -------------------------------------------------------------------------------- 1 | // prettier-ignore 2 | /* eslint-disable */ 3 | // @ts-nocheck 4 | /* auto-generated by NAPI-RS */ 5 | 6 | const { readFileSync } = require('node:fs') 7 | let nativeBinding = null; 8 | const loadErrors = []; 9 | 10 | const isMusl = () => { 11 | let musl = false; 12 | if (process.platform === "linux") { 13 | musl = isMuslFromFilesystem(); 14 | if (musl === null) { 15 | musl = isMuslFromReport(); 16 | } 17 | if (musl === null) { 18 | musl = isMuslFromChildProcess(); 19 | } 20 | } 21 | return musl; 22 | }; 23 | 24 | const isFileMusl = (f) => f.includes("libc.musl-") || f.includes("ld-musl-"); 25 | 26 | const isMuslFromFilesystem = () => { 27 | try { 28 | return readFileSync("/usr/bin/ldd", "utf-8").includes("musl"); 29 | } catch { 30 | return null; 31 | } 32 | }; 33 | 34 | const isMuslFromReport = () => { 35 | let report = null; 36 | if (typeof process.report?.getReport === "function") { 37 | process.report.excludeNetwork = true; 38 | report = process.report.getReport(); 39 | } 40 | if (!report) { 41 | return null; 42 | } 43 | if (report.header && report.header.glibcVersionRuntime) { 44 | return false; 45 | } 46 | if (Array.isArray(report.sharedObjects)) { 47 | if (report.sharedObjects.some(isFileMusl)) { 48 | return true; 49 | } 50 | } 51 | return false; 52 | }; 53 | 54 | const isMuslFromChildProcess = () => { 55 | try { 56 | return require("child_process") 57 | .execSync("ldd --version", { encoding: "utf8" }) 58 | .includes("musl"); 59 | } catch (e) { 60 | // If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false 61 | return false; 62 | } 63 | }; 64 | 65 | function requireNative() { 66 | if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) { 67 | try { 68 | return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH); 69 | } catch (err) { 70 | loadErrors.push(err); 71 | } 72 | } else if (process.platform === "android") { 73 | if (process.arch === "arm64") { 74 | try { 75 | return require("./oxc-node.android-arm64.node"); 76 | } catch (e) { 77 | loadErrors.push(e); 78 | } 79 | try { 80 | const binding = require("@oxc-node/core-android-arm64"); 81 | const bindingPackageVersion = require("@oxc-node/core-android-arm64/package.json").version; 82 | if ( 83 | bindingPackageVersion !== "0.0.34" && 84 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK && 85 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" 86 | ) { 87 | throw new Error( 88 | `Native binding package version mismatch, expected 0.0.34 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, 89 | ); 90 | } 91 | return binding; 92 | } catch (e) { 93 | loadErrors.push(e); 94 | } 95 | } else if (process.arch === "arm") { 96 | try { 97 | return require("./oxc-node.android-arm-eabi.node"); 98 | } catch (e) { 99 | loadErrors.push(e); 100 | } 101 | try { 102 | const binding = require("@oxc-node/core-android-arm-eabi"); 103 | const bindingPackageVersion = 104 | require("@oxc-node/core-android-arm-eabi/package.json").version; 105 | if ( 106 | bindingPackageVersion !== "0.0.34" && 107 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK && 108 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" 109 | ) { 110 | throw new Error( 111 | `Native binding package version mismatch, expected 0.0.34 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, 112 | ); 113 | } 114 | return binding; 115 | } catch (e) { 116 | loadErrors.push(e); 117 | } 118 | } else { 119 | loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`)); 120 | } 121 | } else if (process.platform === "win32") { 122 | if (process.arch === "x64") { 123 | if ( 124 | process.config?.variables?.shlib_suffix === "dll.a" || 125 | process.config?.variables?.node_target_type === "shared_library" 126 | ) { 127 | try { 128 | return require("./oxc-node.win32-x64-gnu.node"); 129 | } catch (e) { 130 | loadErrors.push(e); 131 | } 132 | try { 133 | const binding = require("@oxc-node/core-win32-x64-gnu"); 134 | const bindingPackageVersion = 135 | require("@oxc-node/core-win32-x64-gnu/package.json").version; 136 | if ( 137 | bindingPackageVersion !== "0.0.34" && 138 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK && 139 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" 140 | ) { 141 | throw new Error( 142 | `Native binding package version mismatch, expected 0.0.34 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, 143 | ); 144 | } 145 | return binding; 146 | } catch (e) { 147 | loadErrors.push(e); 148 | } 149 | } else { 150 | try { 151 | return require("./oxc-node.win32-x64-msvc.node"); 152 | } catch (e) { 153 | loadErrors.push(e); 154 | } 155 | try { 156 | const binding = require("@oxc-node/core-win32-x64-msvc"); 157 | const bindingPackageVersion = 158 | require("@oxc-node/core-win32-x64-msvc/package.json").version; 159 | if ( 160 | bindingPackageVersion !== "0.0.34" && 161 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK && 162 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" 163 | ) { 164 | throw new Error( 165 | `Native binding package version mismatch, expected 0.0.34 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, 166 | ); 167 | } 168 | return binding; 169 | } catch (e) { 170 | loadErrors.push(e); 171 | } 172 | } 173 | } else if (process.arch === "ia32") { 174 | try { 175 | return require("./oxc-node.win32-ia32-msvc.node"); 176 | } catch (e) { 177 | loadErrors.push(e); 178 | } 179 | try { 180 | const binding = require("@oxc-node/core-win32-ia32-msvc"); 181 | const bindingPackageVersion = 182 | require("@oxc-node/core-win32-ia32-msvc/package.json").version; 183 | if ( 184 | bindingPackageVersion !== "0.0.34" && 185 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK && 186 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" 187 | ) { 188 | throw new Error( 189 | `Native binding package version mismatch, expected 0.0.34 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, 190 | ); 191 | } 192 | return binding; 193 | } catch (e) { 194 | loadErrors.push(e); 195 | } 196 | } else if (process.arch === "arm64") { 197 | try { 198 | return require("./oxc-node.win32-arm64-msvc.node"); 199 | } catch (e) { 200 | loadErrors.push(e); 201 | } 202 | try { 203 | const binding = require("@oxc-node/core-win32-arm64-msvc"); 204 | const bindingPackageVersion = 205 | require("@oxc-node/core-win32-arm64-msvc/package.json").version; 206 | if ( 207 | bindingPackageVersion !== "0.0.34" && 208 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK && 209 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" 210 | ) { 211 | throw new Error( 212 | `Native binding package version mismatch, expected 0.0.34 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, 213 | ); 214 | } 215 | return binding; 216 | } catch (e) { 217 | loadErrors.push(e); 218 | } 219 | } else { 220 | loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`)); 221 | } 222 | } else if (process.platform === "darwin") { 223 | try { 224 | return require("./oxc-node.darwin-universal.node"); 225 | } catch (e) { 226 | loadErrors.push(e); 227 | } 228 | try { 229 | const binding = require("@oxc-node/core-darwin-universal"); 230 | const bindingPackageVersion = require("@oxc-node/core-darwin-universal/package.json").version; 231 | if ( 232 | bindingPackageVersion !== "0.0.34" && 233 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK && 234 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" 235 | ) { 236 | throw new Error( 237 | `Native binding package version mismatch, expected 0.0.34 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, 238 | ); 239 | } 240 | return binding; 241 | } catch (e) { 242 | loadErrors.push(e); 243 | } 244 | if (process.arch === "x64") { 245 | try { 246 | return require("./oxc-node.darwin-x64.node"); 247 | } catch (e) { 248 | loadErrors.push(e); 249 | } 250 | try { 251 | const binding = require("@oxc-node/core-darwin-x64"); 252 | const bindingPackageVersion = require("@oxc-node/core-darwin-x64/package.json").version; 253 | if ( 254 | bindingPackageVersion !== "0.0.34" && 255 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK && 256 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" 257 | ) { 258 | throw new Error( 259 | `Native binding package version mismatch, expected 0.0.34 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, 260 | ); 261 | } 262 | return binding; 263 | } catch (e) { 264 | loadErrors.push(e); 265 | } 266 | } else if (process.arch === "arm64") { 267 | try { 268 | return require("./oxc-node.darwin-arm64.node"); 269 | } catch (e) { 270 | loadErrors.push(e); 271 | } 272 | try { 273 | const binding = require("@oxc-node/core-darwin-arm64"); 274 | const bindingPackageVersion = require("@oxc-node/core-darwin-arm64/package.json").version; 275 | if ( 276 | bindingPackageVersion !== "0.0.34" && 277 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK && 278 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" 279 | ) { 280 | throw new Error( 281 | `Native binding package version mismatch, expected 0.0.34 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, 282 | ); 283 | } 284 | return binding; 285 | } catch (e) { 286 | loadErrors.push(e); 287 | } 288 | } else { 289 | loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`)); 290 | } 291 | } else if (process.platform === "freebsd") { 292 | if (process.arch === "x64") { 293 | try { 294 | return require("./oxc-node.freebsd-x64.node"); 295 | } catch (e) { 296 | loadErrors.push(e); 297 | } 298 | try { 299 | const binding = require("@oxc-node/core-freebsd-x64"); 300 | const bindingPackageVersion = require("@oxc-node/core-freebsd-x64/package.json").version; 301 | if ( 302 | bindingPackageVersion !== "0.0.34" && 303 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK && 304 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" 305 | ) { 306 | throw new Error( 307 | `Native binding package version mismatch, expected 0.0.34 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, 308 | ); 309 | } 310 | return binding; 311 | } catch (e) { 312 | loadErrors.push(e); 313 | } 314 | } else if (process.arch === "arm64") { 315 | try { 316 | return require("./oxc-node.freebsd-arm64.node"); 317 | } catch (e) { 318 | loadErrors.push(e); 319 | } 320 | try { 321 | const binding = require("@oxc-node/core-freebsd-arm64"); 322 | const bindingPackageVersion = require("@oxc-node/core-freebsd-arm64/package.json").version; 323 | if ( 324 | bindingPackageVersion !== "0.0.34" && 325 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK && 326 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" 327 | ) { 328 | throw new Error( 329 | `Native binding package version mismatch, expected 0.0.34 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, 330 | ); 331 | } 332 | return binding; 333 | } catch (e) { 334 | loadErrors.push(e); 335 | } 336 | } else { 337 | loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`)); 338 | } 339 | } else if (process.platform === "linux") { 340 | if (process.arch === "x64") { 341 | if (isMusl()) { 342 | try { 343 | return require("./oxc-node.linux-x64-musl.node"); 344 | } catch (e) { 345 | loadErrors.push(e); 346 | } 347 | try { 348 | const binding = require("@oxc-node/core-linux-x64-musl"); 349 | const bindingPackageVersion = 350 | require("@oxc-node/core-linux-x64-musl/package.json").version; 351 | if ( 352 | bindingPackageVersion !== "0.0.34" && 353 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK && 354 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" 355 | ) { 356 | throw new Error( 357 | `Native binding package version mismatch, expected 0.0.34 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, 358 | ); 359 | } 360 | return binding; 361 | } catch (e) { 362 | loadErrors.push(e); 363 | } 364 | } else { 365 | try { 366 | return require("./oxc-node.linux-x64-gnu.node"); 367 | } catch (e) { 368 | loadErrors.push(e); 369 | } 370 | try { 371 | const binding = require("@oxc-node/core-linux-x64-gnu"); 372 | const bindingPackageVersion = 373 | require("@oxc-node/core-linux-x64-gnu/package.json").version; 374 | if ( 375 | bindingPackageVersion !== "0.0.34" && 376 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK && 377 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" 378 | ) { 379 | throw new Error( 380 | `Native binding package version mismatch, expected 0.0.34 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, 381 | ); 382 | } 383 | return binding; 384 | } catch (e) { 385 | loadErrors.push(e); 386 | } 387 | } 388 | } else if (process.arch === "arm64") { 389 | if (isMusl()) { 390 | try { 391 | return require("./oxc-node.linux-arm64-musl.node"); 392 | } catch (e) { 393 | loadErrors.push(e); 394 | } 395 | try { 396 | const binding = require("@oxc-node/core-linux-arm64-musl"); 397 | const bindingPackageVersion = 398 | require("@oxc-node/core-linux-arm64-musl/package.json").version; 399 | if ( 400 | bindingPackageVersion !== "0.0.34" && 401 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK && 402 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" 403 | ) { 404 | throw new Error( 405 | `Native binding package version mismatch, expected 0.0.34 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, 406 | ); 407 | } 408 | return binding; 409 | } catch (e) { 410 | loadErrors.push(e); 411 | } 412 | } else { 413 | try { 414 | return require("./oxc-node.linux-arm64-gnu.node"); 415 | } catch (e) { 416 | loadErrors.push(e); 417 | } 418 | try { 419 | const binding = require("@oxc-node/core-linux-arm64-gnu"); 420 | const bindingPackageVersion = 421 | require("@oxc-node/core-linux-arm64-gnu/package.json").version; 422 | if ( 423 | bindingPackageVersion !== "0.0.34" && 424 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK && 425 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" 426 | ) { 427 | throw new Error( 428 | `Native binding package version mismatch, expected 0.0.34 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, 429 | ); 430 | } 431 | return binding; 432 | } catch (e) { 433 | loadErrors.push(e); 434 | } 435 | } 436 | } else if (process.arch === "arm") { 437 | if (isMusl()) { 438 | try { 439 | return require("./oxc-node.linux-arm-musleabihf.node"); 440 | } catch (e) { 441 | loadErrors.push(e); 442 | } 443 | try { 444 | const binding = require("@oxc-node/core-linux-arm-musleabihf"); 445 | const bindingPackageVersion = 446 | require("@oxc-node/core-linux-arm-musleabihf/package.json").version; 447 | if ( 448 | bindingPackageVersion !== "0.0.34" && 449 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK && 450 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" 451 | ) { 452 | throw new Error( 453 | `Native binding package version mismatch, expected 0.0.34 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, 454 | ); 455 | } 456 | return binding; 457 | } catch (e) { 458 | loadErrors.push(e); 459 | } 460 | } else { 461 | try { 462 | return require("./oxc-node.linux-arm-gnueabihf.node"); 463 | } catch (e) { 464 | loadErrors.push(e); 465 | } 466 | try { 467 | const binding = require("@oxc-node/core-linux-arm-gnueabihf"); 468 | const bindingPackageVersion = 469 | require("@oxc-node/core-linux-arm-gnueabihf/package.json").version; 470 | if ( 471 | bindingPackageVersion !== "0.0.34" && 472 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK && 473 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" 474 | ) { 475 | throw new Error( 476 | `Native binding package version mismatch, expected 0.0.34 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, 477 | ); 478 | } 479 | return binding; 480 | } catch (e) { 481 | loadErrors.push(e); 482 | } 483 | } 484 | } else if (process.arch === "loong64") { 485 | if (isMusl()) { 486 | try { 487 | return require("./oxc-node.linux-loong64-musl.node"); 488 | } catch (e) { 489 | loadErrors.push(e); 490 | } 491 | try { 492 | const binding = require("@oxc-node/core-linux-loong64-musl"); 493 | const bindingPackageVersion = 494 | require("@oxc-node/core-linux-loong64-musl/package.json").version; 495 | if ( 496 | bindingPackageVersion !== "0.0.34" && 497 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK && 498 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" 499 | ) { 500 | throw new Error( 501 | `Native binding package version mismatch, expected 0.0.34 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, 502 | ); 503 | } 504 | return binding; 505 | } catch (e) { 506 | loadErrors.push(e); 507 | } 508 | } else { 509 | try { 510 | return require("./oxc-node.linux-loong64-gnu.node"); 511 | } catch (e) { 512 | loadErrors.push(e); 513 | } 514 | try { 515 | const binding = require("@oxc-node/core-linux-loong64-gnu"); 516 | const bindingPackageVersion = 517 | require("@oxc-node/core-linux-loong64-gnu/package.json").version; 518 | if ( 519 | bindingPackageVersion !== "0.0.34" && 520 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK && 521 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" 522 | ) { 523 | throw new Error( 524 | `Native binding package version mismatch, expected 0.0.34 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, 525 | ); 526 | } 527 | return binding; 528 | } catch (e) { 529 | loadErrors.push(e); 530 | } 531 | } 532 | } else if (process.arch === "riscv64") { 533 | if (isMusl()) { 534 | try { 535 | return require("./oxc-node.linux-riscv64-musl.node"); 536 | } catch (e) { 537 | loadErrors.push(e); 538 | } 539 | try { 540 | const binding = require("@oxc-node/core-linux-riscv64-musl"); 541 | const bindingPackageVersion = 542 | require("@oxc-node/core-linux-riscv64-musl/package.json").version; 543 | if ( 544 | bindingPackageVersion !== "0.0.34" && 545 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK && 546 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" 547 | ) { 548 | throw new Error( 549 | `Native binding package version mismatch, expected 0.0.34 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, 550 | ); 551 | } 552 | return binding; 553 | } catch (e) { 554 | loadErrors.push(e); 555 | } 556 | } else { 557 | try { 558 | return require("./oxc-node.linux-riscv64-gnu.node"); 559 | } catch (e) { 560 | loadErrors.push(e); 561 | } 562 | try { 563 | const binding = require("@oxc-node/core-linux-riscv64-gnu"); 564 | const bindingPackageVersion = 565 | require("@oxc-node/core-linux-riscv64-gnu/package.json").version; 566 | if ( 567 | bindingPackageVersion !== "0.0.34" && 568 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK && 569 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" 570 | ) { 571 | throw new Error( 572 | `Native binding package version mismatch, expected 0.0.34 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, 573 | ); 574 | } 575 | return binding; 576 | } catch (e) { 577 | loadErrors.push(e); 578 | } 579 | } 580 | } else if (process.arch === "ppc64") { 581 | try { 582 | return require("./oxc-node.linux-ppc64-gnu.node"); 583 | } catch (e) { 584 | loadErrors.push(e); 585 | } 586 | try { 587 | const binding = require("@oxc-node/core-linux-ppc64-gnu"); 588 | const bindingPackageVersion = 589 | require("@oxc-node/core-linux-ppc64-gnu/package.json").version; 590 | if ( 591 | bindingPackageVersion !== "0.0.34" && 592 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK && 593 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" 594 | ) { 595 | throw new Error( 596 | `Native binding package version mismatch, expected 0.0.34 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, 597 | ); 598 | } 599 | return binding; 600 | } catch (e) { 601 | loadErrors.push(e); 602 | } 603 | } else if (process.arch === "s390x") { 604 | try { 605 | return require("./oxc-node.linux-s390x-gnu.node"); 606 | } catch (e) { 607 | loadErrors.push(e); 608 | } 609 | try { 610 | const binding = require("@oxc-node/core-linux-s390x-gnu"); 611 | const bindingPackageVersion = 612 | require("@oxc-node/core-linux-s390x-gnu/package.json").version; 613 | if ( 614 | bindingPackageVersion !== "0.0.34" && 615 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK && 616 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" 617 | ) { 618 | throw new Error( 619 | `Native binding package version mismatch, expected 0.0.34 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, 620 | ); 621 | } 622 | return binding; 623 | } catch (e) { 624 | loadErrors.push(e); 625 | } 626 | } else { 627 | loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`)); 628 | } 629 | } else if (process.platform === "openharmony") { 630 | if (process.arch === "arm64") { 631 | try { 632 | return require("./oxc-node.openharmony-arm64.node"); 633 | } catch (e) { 634 | loadErrors.push(e); 635 | } 636 | try { 637 | const binding = require("@oxc-node/core-openharmony-arm64"); 638 | const bindingPackageVersion = 639 | require("@oxc-node/core-openharmony-arm64/package.json").version; 640 | if ( 641 | bindingPackageVersion !== "0.0.34" && 642 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK && 643 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" 644 | ) { 645 | throw new Error( 646 | `Native binding package version mismatch, expected 0.0.34 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, 647 | ); 648 | } 649 | return binding; 650 | } catch (e) { 651 | loadErrors.push(e); 652 | } 653 | } else if (process.arch === "x64") { 654 | try { 655 | return require("./oxc-node.openharmony-x64.node"); 656 | } catch (e) { 657 | loadErrors.push(e); 658 | } 659 | try { 660 | const binding = require("@oxc-node/core-openharmony-x64"); 661 | const bindingPackageVersion = 662 | require("@oxc-node/core-openharmony-x64/package.json").version; 663 | if ( 664 | bindingPackageVersion !== "0.0.34" && 665 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK && 666 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" 667 | ) { 668 | throw new Error( 669 | `Native binding package version mismatch, expected 0.0.34 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, 670 | ); 671 | } 672 | return binding; 673 | } catch (e) { 674 | loadErrors.push(e); 675 | } 676 | } else if (process.arch === "arm") { 677 | try { 678 | return require("./oxc-node.openharmony-arm.node"); 679 | } catch (e) { 680 | loadErrors.push(e); 681 | } 682 | try { 683 | const binding = require("@oxc-node/core-openharmony-arm"); 684 | const bindingPackageVersion = 685 | require("@oxc-node/core-openharmony-arm/package.json").version; 686 | if ( 687 | bindingPackageVersion !== "0.0.34" && 688 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK && 689 | process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" 690 | ) { 691 | throw new Error( 692 | `Native binding package version mismatch, expected 0.0.34 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, 693 | ); 694 | } 695 | return binding; 696 | } catch (e) { 697 | loadErrors.push(e); 698 | } 699 | } else { 700 | loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`)); 701 | } 702 | } else { 703 | loadErrors.push( 704 | new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`), 705 | ); 706 | } 707 | } 708 | 709 | nativeBinding = requireNative(); 710 | 711 | if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) { 712 | let wasiBinding = null; 713 | let wasiBindingError = null; 714 | try { 715 | wasiBinding = require("./oxc-node.wasi.cjs"); 716 | nativeBinding = wasiBinding; 717 | } catch (err) { 718 | if (process.env.NAPI_RS_FORCE_WASI) { 719 | wasiBindingError = err; 720 | } 721 | } 722 | if (!nativeBinding) { 723 | try { 724 | wasiBinding = require("@oxc-node/core-wasm32-wasi"); 725 | nativeBinding = wasiBinding; 726 | } catch (err) { 727 | if (process.env.NAPI_RS_FORCE_WASI) { 728 | wasiBindingError.cause = err; 729 | loadErrors.push(err); 730 | } 731 | } 732 | } 733 | if (process.env.NAPI_RS_FORCE_WASI === "error" && !wasiBinding) { 734 | const error = new Error("WASI binding not found and NAPI_RS_FORCE_WASI is set to error"); 735 | error.cause = wasiBindingError; 736 | throw error; 737 | } 738 | } 739 | 740 | if (!nativeBinding) { 741 | if (loadErrors.length > 0) { 742 | throw new Error( 743 | `Cannot find native binding. ` + 744 | `npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` + 745 | "Please try `npm i` again after removing both package-lock.json and node_modules directory.", 746 | { 747 | cause: loadErrors.reduce((err, cur) => { 748 | cur.cause = err; 749 | return cur; 750 | }), 751 | }, 752 | ); 753 | } 754 | throw new Error(`Failed to load native binding`); 755 | } 756 | 757 | module.exports = nativeBinding; 758 | module.exports.Output = nativeBinding.Output; 759 | module.exports.OxcTransformer = nativeBinding.OxcTransformer; 760 | module.exports.createResolve = nativeBinding.createResolve; 761 | module.exports.initTracing = nativeBinding.initTracing; 762 | module.exports.load = nativeBinding.load; 763 | module.exports.transform = nativeBinding.transform; 764 | module.exports.transformAsync = nativeBinding.transformAsync; 765 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | use std::{ 2 | borrow::Cow, 3 | collections::HashMap, 4 | env, fs, mem, 5 | path::{Path, PathBuf}, 6 | sync::{Arc, OnceLock}, 7 | }; 8 | 9 | use napi::bindgen_prelude::*; 10 | use napi_derive::napi; 11 | use oxc::{ 12 | allocator::Allocator, 13 | codegen::{Codegen, CodegenOptions, CodegenReturn}, 14 | diagnostics::OxcDiagnostic, 15 | parser::{Parser, ParserReturn}, 16 | semantic::SemanticBuilder, 17 | span::SourceType, 18 | transformer::{ 19 | ClassPropertiesOptions, CompilerAssumptions, DecoratorOptions, ES2022Options, 20 | ES2026Options, EnvOptions, HelperLoaderOptions, JsxOptions, JsxRuntime, Module, 21 | ProposalOptions, RewriteExtensionsMode, TransformOptions, Transformer, TransformerReturn, 22 | TypeScriptOptions, 23 | }, 24 | }; 25 | use oxc_resolver::{ 26 | CompilerOptions, EnforceExtension, ModuleType, Resolution, ResolveOptions, Resolver, TsConfig, 27 | TsconfigDiscovery, TsconfigOptions, TsconfigReferences, 28 | }; 29 | use phf::Set; 30 | 31 | #[cfg(all( 32 | not(target_arch = "x86"), 33 | not(target_arch = "arm"), 34 | not(target_family = "wasm") 35 | ))] 36 | #[global_allocator] 37 | static ALLOC: mimalloc_safe::MiMalloc = mimalloc_safe::MiMalloc; 38 | 39 | const BUILTIN_MODULES: Set<&str> = phf::phf_set! { 40 | "_http_agent", 41 | "_http_client", 42 | "_http_common", 43 | "_http_incoming", 44 | "_http_outgoing", 45 | "_http_server", 46 | "_stream_duplex", 47 | "_stream_passthrough", 48 | "_stream_readable", 49 | "_stream_transform", 50 | "_stream_wrap", 51 | "_stream_writable", 52 | "_tls_common", 53 | "_tls_wrap", 54 | "assert", 55 | "assert/strict", 56 | "async_hooks", 57 | "buffer", 58 | "child_process", 59 | "cluster", 60 | "console", 61 | "constants", 62 | "crypto", 63 | "dgram", 64 | "diagnostics_channel", 65 | "dns", 66 | "dns/promises", 67 | "domain", 68 | "events", 69 | "fs", 70 | "fs/promises", 71 | "http", 72 | "http2", 73 | "https", 74 | "inspector", 75 | "module", 76 | "net", 77 | "os", 78 | "path", 79 | "path/posix", 80 | "path/win32", 81 | "perf_hooks", 82 | "process", 83 | "punycode", 84 | "querystring", 85 | "readline", 86 | "repl", 87 | "stream", 88 | "stream/consumers", 89 | "stream/promises", 90 | "stream/web", 91 | "string_decoder", 92 | "sys", 93 | "timers", 94 | "timers/promises", 95 | "tls", 96 | "trace_events", 97 | "tty", 98 | "url", 99 | "util", 100 | "util/types", 101 | "v8", 102 | "vm", 103 | "worker_threads", 104 | "zlib", 105 | }; 106 | 107 | #[allow(clippy::type_complexity)] 108 | static RESOLVER_AND_TSCONFIG: OnceLock<(Resolver, Option>, Option<&'static str>)> = 109 | OnceLock::new(); 110 | 111 | #[cfg(not(target_os = "windows"))] 112 | const NODE_MODULES_PATH: &str = "/node_modules/"; 113 | 114 | #[cfg(target_os = "windows")] 115 | const NODE_MODULES_PATH: &str = "\\node_modules\\"; 116 | 117 | #[cfg(not(target_os = "windows"))] 118 | const PATH_PREFIX: &str = "file://"; 119 | 120 | #[cfg(target_os = "windows")] 121 | const PATH_PREFIX: &str = "file:///"; 122 | 123 | #[cfg(target_family = "wasm")] 124 | #[napi] 125 | pub fn init_tracing() { 126 | init(); 127 | } 128 | 129 | #[cfg(not(target_family = "wasm"))] 130 | #[napi] 131 | pub fn init_tracing() {} 132 | 133 | #[cfg_attr(not(target_family = "wasm"), napi_derive::module_init)] 134 | fn init() { 135 | use tracing_subscriber::filter::Targets; 136 | use tracing_subscriber::prelude::__tracing_subscriber_SubscriberExt; 137 | use tracing_subscriber::util::SubscriberInitExt; 138 | 139 | // Usage without the `regex` feature. 140 | // 141 | tracing_subscriber::registry() 142 | .with(std::env::var("OXC_LOG").map_or_else( 143 | |_| Targets::new(), 144 | |env_var| { 145 | use std::str::FromStr; 146 | Targets::from_str(&env_var).unwrap() 147 | }, 148 | )) 149 | .with(tracing_subscriber::fmt::layer()) 150 | .init(); 151 | } 152 | 153 | #[napi] 154 | pub struct Output(CodegenReturn); 155 | 156 | #[napi] 157 | impl Output { 158 | #[napi] 159 | /// Returns the generated code 160 | /// Cache the result of this function if you need to use it multiple times 161 | pub fn source(&self) -> String { 162 | self.0.code.clone() 163 | } 164 | 165 | #[napi] 166 | /// Returns the source map as a JSON string 167 | /// Cache the result of this function if you need to use it multiple times 168 | pub fn source_map(&self) -> Option { 169 | self.0.map.clone().map(|s| s.to_json_string()) 170 | } 171 | } 172 | 173 | #[napi] 174 | pub fn transform(path: String, source: Either) -> Result { 175 | let transformer = OxcTransformer::new(None); 176 | transformer.transform(path, source) 177 | } 178 | 179 | #[napi] 180 | pub fn transform_async( 181 | path: String, 182 | source: Either3, 183 | ) -> AsyncTask { 184 | let transformer = OxcTransformer::new(None); 185 | transformer.transform_async(path, source) 186 | } 187 | 188 | pub struct TransformTask { 189 | cwd: String, 190 | path: String, 191 | source: Either3, 192 | } 193 | 194 | #[napi] 195 | impl Task for TransformTask { 196 | type Output = Output; 197 | type JsValue = Output; 198 | 199 | fn compute(&mut self) -> Result { 200 | let src_path = Path::new(&self.path); 201 | let cwd = PathBuf::from(&self.cwd); 202 | let (_, resolved_tsconfig, _) = 203 | RESOLVER_AND_TSCONFIG.get_or_init(|| init_resolver(cwd, vec![])); 204 | oxc_transform( 205 | src_path, 206 | &self.source, 207 | resolved_tsconfig.as_ref().map(|t| &t.compiler_options), 208 | Some(Module::CommonJS), 209 | true, 210 | ) 211 | } 212 | 213 | fn resolve(&mut self, _: Env, output: Self::Output) -> Result { 214 | Ok(output) 215 | } 216 | 217 | fn finally(mut self, _: Env) -> Result<()> { 218 | mem::drop(mem::replace(&mut self.source, Either3::A(String::new()))); 219 | Ok(()) 220 | } 221 | } 222 | 223 | #[napi] 224 | pub struct OxcTransformer { 225 | cwd: String, 226 | } 227 | 228 | #[napi] 229 | impl OxcTransformer { 230 | #[napi(constructor)] 231 | pub fn new(cwd: Option) -> Self { 232 | Self { 233 | cwd: match cwd { 234 | Some(cwd) => cwd, 235 | None => env::current_dir() 236 | .map(|p| p.to_string_lossy().to_string()) 237 | .unwrap(), 238 | }, 239 | } 240 | } 241 | 242 | #[napi] 243 | pub fn transform(&self, path: String, source: Either) -> Result { 244 | let cwd = PathBuf::from(&self.cwd); 245 | let (_, resolved_tsconfig, _) = 246 | RESOLVER_AND_TSCONFIG.get_or_init(|| init_resolver(cwd, vec![])); 247 | oxc_transform( 248 | Path::new(&path), 249 | &source, 250 | resolved_tsconfig.as_ref().map(|t| &t.compiler_options), 251 | Some(Module::CommonJS), 252 | true, 253 | ) 254 | } 255 | 256 | #[napi] 257 | pub fn transform_async( 258 | &self, 259 | path: String, 260 | source: Either3, 261 | ) -> AsyncTask { 262 | AsyncTask::new(TransformTask { 263 | path, 264 | source, 265 | cwd: self.cwd.clone(), 266 | }) 267 | } 268 | } 269 | 270 | fn oxc_transform( 271 | src_path: &Path, 272 | code: &S, 273 | compiler_options: Option<&'static CompilerOptions>, 274 | module_target: Option, 275 | enable_top_level_await: bool, 276 | ) -> Result { 277 | let allocator = Allocator::default(); 278 | let source_type = SourceType::from_path(src_path).unwrap_or_default(); 279 | let source_str = code.try_as_str()?; 280 | let ParserReturn { 281 | mut program, 282 | errors, 283 | .. 284 | } = Parser::new(&allocator, source_str, source_type).parse(); 285 | if !errors.is_empty() { 286 | let msg = join_errors(errors, source_str); 287 | return Err(Error::new( 288 | Status::GenericFailure, 289 | format!("Failed to parse {}: {}", src_path.display(), msg), 290 | )); 291 | } 292 | let scoping = SemanticBuilder::new() 293 | .build(&program) 294 | .semantic 295 | .into_scoping(); 296 | 297 | let use_define_for_class_fields = compiler_options 298 | .and_then(|c| c.use_define_for_class_fields) 299 | .unwrap_or_default(); 300 | let TransformerReturn { errors, .. } = Transformer::new( 301 | &allocator, 302 | src_path, 303 | &TransformOptions { 304 | assumptions: CompilerAssumptions { 305 | set_public_class_fields: use_define_for_class_fields, 306 | ..Default::default() 307 | }, 308 | decorator: DecoratorOptions { 309 | legacy: compiler_options 310 | .and_then(|c| c.experimental_decorators) 311 | .unwrap_or(false), 312 | emit_decorator_metadata: compiler_options 313 | .and_then(|c| c.emit_decorator_metadata) 314 | .unwrap_or(false), 315 | }, 316 | jsx: JsxOptions { 317 | runtime: compiler_options 318 | .and_then(|c| c.jsx.as_ref()) 319 | .map(|s| match s.as_str() { 320 | "automatic" => JsxRuntime::Automatic, 321 | "classic" => JsxRuntime::Classic, 322 | _ => JsxRuntime::default(), 323 | }) 324 | .unwrap_or_default(), 325 | import_source: compiler_options.and_then(|c| c.jsx_import_source.clone()), 326 | pragma: compiler_options.and_then(|c| c.jsx_factory.clone()), 327 | pragma_frag: compiler_options.and_then(|c| c.jsx_fragment_factory.clone()), 328 | ..Default::default() 329 | }, 330 | typescript: TypeScriptOptions { 331 | jsx_pragma: compiler_options 332 | .and_then(|c| c.jsx_factory.as_deref()) 333 | .map(Cow::Borrowed) 334 | .unwrap_or_default(), 335 | jsx_pragma_frag: compiler_options 336 | .and_then(|c| c.jsx_fragment_factory.as_ref()) 337 | .map(|c| Cow::Borrowed(c.as_str())) 338 | .unwrap_or_default(), 339 | rewrite_import_extensions: compiler_options 340 | .and_then(|c| c.rewrite_relative_import_extensions) 341 | .unwrap_or_default() 342 | .then_some(RewriteExtensionsMode::Rewrite), 343 | only_remove_type_imports: false, 344 | ..Default::default() 345 | }, 346 | env: EnvOptions { 347 | module: module_target.unwrap_or_default(), 348 | es2022: ES2022Options { 349 | class_static_block: true, 350 | class_properties: Some(ClassPropertiesOptions { 351 | loose: use_define_for_class_fields, 352 | }), 353 | // Turn this on would throw error for all top-level awaits. 354 | top_level_await: enable_top_level_await, 355 | }, 356 | es2026: ES2026Options { 357 | explicit_resource_management: true, 358 | }, 359 | ..Default::default() 360 | }, 361 | proposals: ProposalOptions {}, 362 | helper_loader: HelperLoaderOptions { 363 | module_name: Cow::Borrowed("@oxc-node/core"), 364 | ..Default::default() 365 | }, 366 | ..Default::default() 367 | }, 368 | ) 369 | .build_with_scoping(scoping, &mut program); 370 | 371 | if !errors.is_empty() { 372 | let msg = join_errors(errors, source_str); 373 | return Err(Error::new( 374 | Status::GenericFailure, 375 | format!("Failed to transform {}: {}", src_path.display(), msg), 376 | )); 377 | } 378 | 379 | Ok(Output( 380 | Codegen::new() 381 | .with_options(CodegenOptions { 382 | source_map_path: Some(src_path.to_path_buf()), 383 | ..Default::default() 384 | }) 385 | .build(&program), 386 | )) 387 | } 388 | 389 | #[napi(object)] 390 | #[derive(Debug)] 391 | pub struct ResolveContext { 392 | /// Export conditions of the relevant `package.json` 393 | pub conditions: Vec, 394 | /// An object whose key-value pairs represent the assertions for the module to import 395 | pub import_attributes: HashMap, 396 | 397 | #[napi(js_name = "parentURL")] 398 | pub parent_url: Option, 399 | } 400 | 401 | #[napi(object)] 402 | pub struct ResolveFnOutput { 403 | pub format: Option>, 404 | pub short_circuit: Option, 405 | pub url: String, 406 | pub import_attributes: Option, Null>>, 407 | } 408 | 409 | #[cfg_attr( 410 | not(target_family = "wasm"), 411 | napi(object, object_from_js = false, object_to_js = false) 412 | )] 413 | #[cfg_attr(target_family = "wasm", napi(object, object_to_js = false))] 414 | pub struct OxcResolveOptions { 415 | pub get_current_directory: Option>, 416 | } 417 | 418 | #[cfg(not(target_family = "wasm"))] 419 | impl FromNapiValue for OxcResolveOptions { 420 | unsafe fn from_napi_value(_: sys::napi_env, _value: sys::napi_value) -> Result { 421 | Ok(OxcResolveOptions { 422 | get_current_directory: None, 423 | }) 424 | } 425 | } 426 | 427 | #[napi] 428 | #[cfg_attr(not(target_family = "wasm"), allow(unused_variables))] 429 | #[allow(clippy::type_complexity)] 430 | pub fn create_resolve<'env>( 431 | env: &'env Env, 432 | options: OxcResolveOptions, 433 | specifier: String, 434 | context: ResolveContext, 435 | next_resolve: Function< 436 | 'env, 437 | FnArgs<(String, Option)>, 438 | Either>, 439 | >, 440 | ) -> Result>> { 441 | tracing::debug!(specifier = ?specifier, context = ?context); 442 | if specifier.starts_with("node:") || specifier.starts_with("nodejs:") { 443 | tracing::debug!("short-circuiting builtin protocol resolve: {}", specifier); 444 | return add_short_circuit(specifier, Some("builtin"), context, next_resolve); 445 | } 446 | if BUILTIN_MODULES.contains(specifier.as_str()) { 447 | tracing::debug!("short-circuiting builtin resolve: {}", specifier); 448 | return add_short_circuit(specifier, Some("builtin"), context, next_resolve); 449 | } 450 | if specifier.starts_with("data:") { 451 | tracing::debug!("short-circuiting data URL resolve: {}", specifier); 452 | return add_short_circuit(specifier, Some("builtin"), context, next_resolve); 453 | } 454 | if specifier.ends_with(".json") { 455 | tracing::debug!("short-circuiting JSON resolve: {}", specifier); 456 | if context.import_attributes.contains_key("type") { 457 | return add_short_circuit(specifier, Some("json"), context, next_resolve); 458 | } 459 | return add_short_circuit(specifier, Some("module"), context, next_resolve); 460 | } 461 | 462 | #[cfg(target_family = "wasm")] 463 | let cwd = { 464 | if let Some(get_cwd) = options.get_current_directory { 465 | Path::new(get_cwd.borrow_back(&env)?.call(())?.as_str()).to_path_buf() 466 | } else { 467 | Path::new("/").to_path_buf() 468 | } 469 | }; 470 | 471 | #[cfg(not(target_family = "wasm"))] 472 | let cwd = env::current_dir()?; 473 | 474 | let conditions = context.conditions.as_slice(); 475 | 476 | let (resolver, tsconfig, default_module_resolved_from_tsconfig) = 477 | RESOLVER_AND_TSCONFIG.get_or_init(|| init_resolver(cwd.clone(), conditions.to_vec())); 478 | 479 | let is_absolute_path = specifier.starts_with(PATH_PREFIX); 480 | 481 | let directory = { 482 | if let Some(parent) = context.parent_url.as_deref() { 483 | if let Some(parent) = parent 484 | .strip_prefix(PATH_PREFIX) 485 | .and_then(|p| Path::new(p).parent()) 486 | { 487 | tracing::debug!(directory = ?parent); 488 | Ok(parent) 489 | } else { 490 | Err(Error::new( 491 | Status::GenericFailure, 492 | "Parent URL is not a file URL", 493 | )) 494 | } 495 | } else { 496 | Ok(cwd.as_path()) 497 | } 498 | }?; 499 | 500 | let resolution = resolver.resolve( 501 | if is_absolute_path { 502 | Path::new("/") 503 | } else { 504 | directory 505 | }, 506 | if is_absolute_path { 507 | specifier.strip_prefix(PATH_PREFIX).unwrap() 508 | } else { 509 | &specifier 510 | }, 511 | ); 512 | 513 | // import attributes 514 | if !context.import_attributes.is_empty() { 515 | tracing::debug!( 516 | "short-circuiting import attributes resolve: {}, attributes: {:?}", 517 | specifier, 518 | context.import_attributes 519 | ); 520 | return next_resolve.call((specifier, Some(context)).into()); 521 | }; 522 | 523 | if let Ok(resolution) = resolution { 524 | tracing::debug!(resolution = ?resolution, "resolved"); 525 | let p = resolution.path(); 526 | let url = oxc_resolved_path_to_url(&resolution); 527 | if !p 528 | .to_str() 529 | .map(|p| p.contains(NODE_MODULES_PATH)) 530 | .unwrap_or(false) 531 | { 532 | let format = { 533 | let ext = p.extension().and_then(|ext| ext.to_str()); 534 | 535 | let format = ext 536 | .and_then(|ext| match ext { 537 | "cjs" | "cts" | "node" => None, 538 | "mts" | "mjs" => Some("module"), 539 | _ => { 540 | if (ext == "ts" || ext == "tsx") 541 | && let Some(default_module_resolved_from_tsconfig) = 542 | default_module_resolved_from_tsconfig 543 | { 544 | return Some(default_module_resolved_from_tsconfig); 545 | } 546 | match resolution.module_type() { 547 | Some(ModuleType::Module) => Some("module"), 548 | Some(ModuleType::CommonJs) => Some("commonjs"), 549 | _ => None, 550 | } 551 | } 552 | }) 553 | .unwrap_or("commonjs"); 554 | tracing::debug!(path = ?p, format = ?format); 555 | format 556 | }; 557 | return add_short_circuit(url, Some(format), context, next_resolve); 558 | } else { 559 | return add_short_circuit(url, None, context, next_resolve); 560 | } 561 | } 562 | 563 | tracing::debug!("default resolve: {}", specifier); 564 | 565 | add_short_circuit(specifier, None, context, next_resolve) 566 | } 567 | 568 | #[napi(object)] 569 | #[derive(Debug)] 570 | pub struct LoadContext { 571 | /// Export conditions of the relevant `package.json` 572 | pub conditions: Option>, 573 | /// The format optionally supplied by the `resolve` hook chain 574 | pub format: Either, 575 | /// An object whose key-value pairs represent the assertions for the module to import 576 | pub import_attributes: HashMap, 577 | } 578 | 579 | #[napi(object)] 580 | pub struct LoadFnOutput { 581 | pub format: String, 582 | pub source: Option>, 583 | #[napi(js_name = "responseURL")] 584 | pub response_url: Option, 585 | } 586 | 587 | #[napi] 588 | #[allow(clippy::type_complexity)] 589 | pub fn load<'env>( 590 | url: String, 591 | context: LoadContext, 592 | next_load: Function< 593 | 'env, 594 | FnArgs<(String, Option)>, 595 | Either>, 596 | >, 597 | ) -> Result>> { 598 | tracing::debug!(url = ?url, context = ?context, "load"); 599 | if url.starts_with("data:") || { 600 | match context.format { 601 | Either::A(ref format) => format == "builtin" || format == "json" || format == "wasm", 602 | _ => true, 603 | } 604 | } { 605 | tracing::debug!("short-circuiting load: {}", url); 606 | return next_load.call((url, Some(context)).into()); 607 | } 608 | 609 | let loaded = next_load.call((url.clone(), Some(context)).into())?; 610 | let (_, tsconfig, _) = RESOLVER_AND_TSCONFIG.get().ok_or_else(|| { 611 | Error::new( 612 | Status::GenericFailure, 613 | "Failed to get resolver and tsconfig", 614 | ) 615 | })?; 616 | 617 | let resolved_compiler_options = tsconfig.as_ref().map(|tsconfig| &tsconfig.compiler_options); 618 | match loaded { 619 | Either::A(output) => Ok(Either::A(transform_output( 620 | url, 621 | output, 622 | resolved_compiler_options, 623 | )?)), 624 | Either::B(promise) => promise 625 | .then(move |ctx| transform_output(url, ctx.value, resolved_compiler_options)) 626 | .map(Either::B), 627 | } 628 | } 629 | 630 | fn transform_output( 631 | url: String, 632 | output: LoadFnOutput, 633 | resolved_compiler_options: Option<&'static CompilerOptions>, 634 | ) -> Result { 635 | match &output.source { 636 | Some(Either4::D(_)) | None => { 637 | tracing::debug!("No source code to transform {}", url); 638 | Ok(LoadFnOutput { 639 | format: output.format, 640 | source: None, 641 | response_url: Some(url), 642 | }) 643 | } 644 | Some(Either4::A(_) | Either4::B(_) | Either4::C(_)) => { 645 | let src_path = Path::new(&url); 646 | // url is a file path, so it's always unix style path separator in it 647 | if env::var("OXC_TRANSFORM_ALL") 648 | .map(|value| value.is_empty() || value == "0" || value == "false") 649 | .unwrap_or(true) 650 | && url.contains("/node_modules/") 651 | { 652 | tracing::debug!("Skip transforming node_modules {}", url); 653 | return Ok(output); 654 | } 655 | let ext = src_path.extension().and_then(|ext| ext.to_str()); 656 | 657 | if ext.map(|ext| ext == "json").unwrap_or(false) { 658 | let source_str = output.source.as_ref().unwrap().try_as_str()?; 659 | let json: serde_json::Value = serde_json::from_str(source_str)?; 660 | if let serde_json::Value::Object(obj) = json { 661 | let obj_len = obj.len(); 662 | let mut source = String::with_capacity(obj_len * 24 + source_str.len() * 2); 663 | source.push_str("const json = "); 664 | source.push_str(source_str); 665 | source.push('\n'); 666 | source.push_str("export default json\n"); 667 | for key in obj.keys() { 668 | if !oxc::syntax::keyword::is_reserved_keyword(key) 669 | && oxc::syntax::identifier::is_identifier_name(key) 670 | { 671 | source.push_str(&format!("export const {key} = json.{key};\n")); 672 | } 673 | } 674 | tracing::debug!("loaded {} format: module", url); 675 | return Ok(LoadFnOutput { 676 | format: "module".to_owned(), 677 | source: Some(Either4::A(source)), 678 | response_url: Some(url), 679 | }); 680 | } 681 | return Ok(LoadFnOutput { 682 | format: "commonjs".to_owned(), 683 | source: Some(Either4::A(format!("module.exports = {source_str}"))), 684 | response_url: Some(url), 685 | }); 686 | } 687 | 688 | let transform_output = oxc_transform( 689 | src_path, 690 | output.source.as_ref().unwrap(), 691 | resolved_compiler_options, 692 | Some(Module::Preserve), 693 | output.format != "module", 694 | )?; 695 | let output_code = transform_output 696 | .0 697 | .map 698 | .map(|sm| { 699 | let sm = sm.to_data_url(); 700 | const SOURCEMAP_PREFIX: &str = "\n//# sourceMappingURL="; 701 | let len = sm.len() + transform_output.0.code.len() + 22; 702 | let mut output_code = String::with_capacity(len + 22); 703 | output_code.push_str(&transform_output.0.code); 704 | output_code.push_str(SOURCEMAP_PREFIX); 705 | output_code.push_str(sm.as_str()); 706 | output_code 707 | }) 708 | .unwrap_or_else(|| transform_output.0.code); 709 | tracing::debug!("loaded {} format: {}", url, output.format); 710 | Ok(LoadFnOutput { 711 | format: output.format, 712 | source: Some(Either4::B(Uint8Array::from_string(output_code))), 713 | response_url: Some(url), 714 | }) 715 | } 716 | } 717 | } 718 | 719 | trait TryAsStr { 720 | fn try_as_str(&self) -> Result<&str>; 721 | } 722 | 723 | impl TryAsStr for Either { 724 | fn try_as_str(&self) -> Result<&str> { 725 | match self { 726 | Either::A(s) => Ok(s), 727 | Either::B(b) => std::str::from_utf8(b).map_err(|err| { 728 | Error::new( 729 | Status::GenericFailure, 730 | format!("Failed to convert &[u8] to &str: {err}"), 731 | ) 732 | }), 733 | } 734 | } 735 | } 736 | 737 | impl TryAsStr for Either3 { 738 | fn try_as_str(&self) -> Result<&str> { 739 | match self { 740 | Either3::A(s) => Ok(s), 741 | Either3::B(arr) => std::str::from_utf8(arr).map_err(|_| { 742 | Error::new( 743 | Status::GenericFailure, 744 | "Failed to convert Uint8Array to Vec", 745 | ) 746 | }), 747 | Either3::C(buf) => std::str::from_utf8(buf).map_err(|_| { 748 | Error::new( 749 | Status::GenericFailure, 750 | "Failed to convert Buffer to Vec", 751 | ) 752 | }), 753 | } 754 | } 755 | } 756 | 757 | impl TryAsStr for Either4 { 758 | fn try_as_str(&self) -> Result<&str> { 759 | match self { 760 | Either4::A(s) => Ok(s), 761 | Either4::B(arr) => std::str::from_utf8(arr).map_err(|_| { 762 | Error::new( 763 | Status::GenericFailure, 764 | "Failed to convert Uint8Array to Vec", 765 | ) 766 | }), 767 | Either4::C(buf) => std::str::from_utf8(buf).map_err(|_| { 768 | Error::new( 769 | Status::GenericFailure, 770 | "Failed to convert Buffer to Vec", 771 | ) 772 | }), 773 | Either4::D(_) => Err(Error::new( 774 | Status::InvalidArg, 775 | "Invalid value type in LoadFnOutput::source", 776 | )), 777 | } 778 | } 779 | } 780 | 781 | fn init_resolver( 782 | cwd: PathBuf, 783 | conditions: Vec, 784 | ) -> (Resolver, Option>, Option<&'static str>) { 785 | let tsconfig = env::var("TS_NODE_PROJECT") 786 | .or_else(|_| env::var("OXC_TSCONFIG_PATH")) 787 | .map(Cow::Owned) 788 | .unwrap_or(Cow::Borrowed("tsconfig.json")); 789 | tracing::debug!(tsconfig = ?tsconfig); 790 | let tsconfig_full_path = if !tsconfig.starts_with('/') { 791 | cwd.join(PathBuf::from(&*tsconfig)) 792 | } else { 793 | PathBuf::from(&*tsconfig) 794 | }; 795 | tracing::debug!(tsconfig_full_path = ?tsconfig_full_path); 796 | let tsconfig = 797 | fs::exists(&tsconfig_full_path) 798 | .unwrap_or(false) 799 | .then_some(TsconfigDiscovery::Manual(TsconfigOptions { 800 | config_file: tsconfig_full_path.clone(), 801 | references: TsconfigReferences::Auto, 802 | })); 803 | let resolver = Resolver::new(ResolveOptions { 804 | tsconfig, 805 | condition_names: conditions, 806 | extension_alias: vec![ 807 | ( 808 | ".js".to_owned(), 809 | vec![".js".to_owned(), ".ts".to_owned(), ".tsx".to_owned()], 810 | ), 811 | ( 812 | ".mjs".to_owned(), 813 | vec![".mjs".to_owned(), ".mts".to_owned()], 814 | ), 815 | ( 816 | ".cjs".to_owned(), 817 | vec![".cjs".to_owned(), ".cts".to_owned()], 818 | ), 819 | ], 820 | enforce_extension: EnforceExtension::Auto, 821 | extensions: vec![ 822 | ".js".to_owned(), 823 | ".mjs".to_owned(), 824 | ".cjs".to_owned(), 825 | ".ts".to_owned(), 826 | ".tsx".to_owned(), 827 | ".mts".to_owned(), 828 | ".cts".to_owned(), 829 | ".json".to_owned(), 830 | ".wasm".to_owned(), 831 | ".node".to_owned(), 832 | ], 833 | module_type: true, 834 | ..Default::default() 835 | }); 836 | 837 | let tsconfig = resolver.resolve_tsconfig(tsconfig_full_path).ok(); 838 | 839 | tracing::debug!(tsconfig = ?tsconfig); 840 | 841 | let default_module_resolved_from_tsconfig = if let Some(tsconfig) = tsconfig.as_ref() { 842 | if matches!( 843 | tsconfig 844 | .compiler_options 845 | .module 846 | .as_deref() 847 | .map(|m| m.to_ascii_lowercase()) 848 | .as_deref(), 849 | Some("nodenext") 850 | | Some("node16") 851 | | Some("node18") 852 | | Some("es6") 853 | | Some("es2015") 854 | | Some("es2020") 855 | | Some("es2022") 856 | | Some("esnext") 857 | ) { 858 | Some("module") 859 | } else { 860 | None 861 | } 862 | } else { 863 | None 864 | }; 865 | 866 | (resolver, tsconfig, default_module_resolved_from_tsconfig) 867 | } 868 | 869 | fn join_errors(errors: Vec, source_str: &str) -> String { 870 | errors 871 | .into_iter() 872 | .map(|err| err.with_source_code(source_str.to_owned()).to_string()) 873 | .collect::>() 874 | .join("\n") 875 | } 876 | 877 | #[allow(clippy::type_complexity)] 878 | fn add_short_circuit<'env>( 879 | specifier: String, 880 | format: Option<&'static str>, 881 | context: ResolveContext, 882 | next_resolve: Function< 883 | 'env, 884 | FnArgs<(String, Option)>, 885 | Either>, 886 | >, 887 | ) -> Result>> { 888 | let builtin_resolved = next_resolve.call((specifier, Some(context)).into())?; 889 | 890 | match builtin_resolved { 891 | Either::A(mut output) => { 892 | output.short_circuit = Some(true); 893 | if let Some(format) = format { 894 | output.format = Some(Either::A(format.to_owned())); 895 | } 896 | Ok(Either::A(output)) 897 | } 898 | Either::B(promise) => promise 899 | .then(move |mut ctx| { 900 | ctx.value.short_circuit = Some(true); 901 | if let Some(format) = format { 902 | ctx.value.format = Some(Either::A(format.to_owned())); 903 | } 904 | Ok(ctx.value) 905 | }) 906 | .map(Either::B), 907 | } 908 | } 909 | 910 | fn oxc_resolved_path_to_url(resolution: &Resolution) -> String { 911 | #[cfg_attr(not(target_os = "windows"), allow(unused_mut))] 912 | let mut url = if resolution.query().is_some() || resolution.fragment().is_some() { 913 | format!("{PATH_PREFIX}{}", resolution.full_path().to_string_lossy()) 914 | } else { 915 | format!("{PATH_PREFIX}{}", resolution.path().to_string_lossy()) 916 | }; 917 | #[cfg(target_os = "windows")] 918 | { 919 | url = url.replace("\\", "/"); 920 | } 921 | url 922 | } 923 | -------------------------------------------------------------------------------- /packages/core/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@oxc-node/core", 3 | "version": "0.0.35", 4 | "license": "MIT", 5 | "repository": { 6 | "type": "git", 7 | "url": "git+https://github.com/oxc-project/oxc-node.git" 8 | }, 9 | "funding": [ 10 | { 11 | "type": "github", 12 | "url": "https://github.com/sponsors/Brooooooklyn" 13 | }, 14 | { 15 | "type": "github", 16 | "url": "https://github.com/sponsors/Boshen" 17 | } 18 | ], 19 | "files": [ 20 | "browser.js", 21 | "esm.mjs", 22 | "index.d.ts", 23 | "index.js", 24 | "register.mjs", 25 | "src/**/*" 26 | ], 27 | "main": "./index.js", 28 | "browser": "./browser.js", 29 | "types": "./index.d.ts", 30 | "exports": { 31 | ".": { 32 | "types": "./index.d.ts", 33 | "import": "./index.js", 34 | "require": "./index.js" 35 | }, 36 | "./esm": { 37 | "import": "./esm.mjs" 38 | }, 39 | "./esm.mjs": { 40 | "import": "./esm.mjs" 41 | }, 42 | "./helpers/AwaitValue": [ 43 | { 44 | "node": "./src/helpers/AwaitValue.js", 45 | "import": "./src/helpers/esm/AwaitValue.js", 46 | "default": "./src/helpers/AwaitValue.js" 47 | }, 48 | "./src/helpers/AwaitValue.js" 49 | ], 50 | "./helpers/OverloadYield": [ 51 | { 52 | "node": "./src/helpers/OverloadYield.js", 53 | "import": "./src/helpers/esm/OverloadYield.js", 54 | "default": "./src/helpers/OverloadYield.js" 55 | }, 56 | "./src/helpers/OverloadYield.js" 57 | ], 58 | "./helpers/applyDecoratedDescriptor": [ 59 | { 60 | "node": "./src/helpers/applyDecoratedDescriptor.js", 61 | "import": "./src/helpers/esm/applyDecoratedDescriptor.js", 62 | "default": "./src/helpers/applyDecoratedDescriptor.js" 63 | }, 64 | "./src/helpers/applyDecoratedDescriptor.js" 65 | ], 66 | "./helpers/applyDecs": [ 67 | { 68 | "node": "./src/helpers/applyDecs.js", 69 | "import": "./src/helpers/esm/applyDecs.js", 70 | "default": "./src/helpers/applyDecs.js" 71 | }, 72 | "./src/helpers/applyDecs.js" 73 | ], 74 | "./helpers/applyDecs2203": [ 75 | { 76 | "node": "./src/helpers/applyDecs2203.js", 77 | "import": "./src/helpers/esm/applyDecs2203.js", 78 | "default": "./src/helpers/applyDecs2203.js" 79 | }, 80 | "./src/helpers/applyDecs2203.js" 81 | ], 82 | "./helpers/applyDecs2203R": [ 83 | { 84 | "node": "./src/helpers/applyDecs2203R.js", 85 | "import": "./src/helpers/esm/applyDecs2203R.js", 86 | "default": "./src/helpers/applyDecs2203R.js" 87 | }, 88 | "./src/helpers/applyDecs2203R.js" 89 | ], 90 | "./helpers/applyDecs2301": [ 91 | { 92 | "node": "./src/helpers/applyDecs2301.js", 93 | "import": "./src/helpers/esm/applyDecs2301.js", 94 | "default": "./src/helpers/applyDecs2301.js" 95 | }, 96 | "./src/helpers/applyDecs2301.js" 97 | ], 98 | "./helpers/applyDecs2305": [ 99 | { 100 | "node": "./src/helpers/applyDecs2305.js", 101 | "import": "./src/helpers/esm/applyDecs2305.js", 102 | "default": "./src/helpers/applyDecs2305.js" 103 | }, 104 | "./src/helpers/applyDecs2305.js" 105 | ], 106 | "./helpers/applyDecs2311": [ 107 | { 108 | "node": "./src/helpers/applyDecs2311.js", 109 | "import": "./src/helpers/esm/applyDecs2311.js", 110 | "default": "./src/helpers/applyDecs2311.js" 111 | }, 112 | "./src/helpers/applyDecs2311.js" 113 | ], 114 | "./helpers/arrayLikeToArray": [ 115 | { 116 | "node": "./src/helpers/arrayLikeToArray.js", 117 | "import": "./src/helpers/esm/arrayLikeToArray.js", 118 | "default": "./src/helpers/arrayLikeToArray.js" 119 | }, 120 | "./src/helpers/arrayLikeToArray.js" 121 | ], 122 | "./helpers/arrayWithHoles": [ 123 | { 124 | "node": "./src/helpers/arrayWithHoles.js", 125 | "import": "./src/helpers/esm/arrayWithHoles.js", 126 | "default": "./src/helpers/arrayWithHoles.js" 127 | }, 128 | "./src/helpers/arrayWithHoles.js" 129 | ], 130 | "./helpers/arrayWithoutHoles": [ 131 | { 132 | "node": "./src/helpers/arrayWithoutHoles.js", 133 | "import": "./src/helpers/esm/arrayWithoutHoles.js", 134 | "default": "./src/helpers/arrayWithoutHoles.js" 135 | }, 136 | "./src/helpers/arrayWithoutHoles.js" 137 | ], 138 | "./helpers/assertClassBrand": [ 139 | { 140 | "node": "./src/helpers/assertClassBrand.js", 141 | "import": "./src/helpers/esm/assertClassBrand.js", 142 | "default": "./src/helpers/assertClassBrand.js" 143 | }, 144 | "./src/helpers/assertClassBrand.js" 145 | ], 146 | "./helpers/assertThisInitialized": [ 147 | { 148 | "node": "./src/helpers/assertThisInitialized.js", 149 | "import": "./src/helpers/esm/assertThisInitialized.js", 150 | "default": "./src/helpers/assertThisInitialized.js" 151 | }, 152 | "./src/helpers/assertThisInitialized.js" 153 | ], 154 | "./helpers/asyncGeneratorDelegate": [ 155 | { 156 | "node": "./src/helpers/asyncGeneratorDelegate.js", 157 | "import": "./src/helpers/esm/asyncGeneratorDelegate.js", 158 | "default": "./src/helpers/asyncGeneratorDelegate.js" 159 | }, 160 | "./src/helpers/asyncGeneratorDelegate.js" 161 | ], 162 | "./helpers/asyncIterator": [ 163 | { 164 | "node": "./src/helpers/asyncIterator.js", 165 | "import": "./src/helpers/esm/asyncIterator.js", 166 | "default": "./src/helpers/asyncIterator.js" 167 | }, 168 | "./src/helpers/asyncIterator.js" 169 | ], 170 | "./helpers/asyncToGenerator": [ 171 | { 172 | "node": "./src/helpers/asyncToGenerator.js", 173 | "import": "./src/helpers/esm/asyncToGenerator.js", 174 | "default": "./src/helpers/asyncToGenerator.js" 175 | }, 176 | "./src/helpers/asyncToGenerator.js" 177 | ], 178 | "./helpers/awaitAsyncGenerator": [ 179 | { 180 | "node": "./src/helpers/awaitAsyncGenerator.js", 181 | "import": "./src/helpers/esm/awaitAsyncGenerator.js", 182 | "default": "./src/helpers/awaitAsyncGenerator.js" 183 | }, 184 | "./src/helpers/awaitAsyncGenerator.js" 185 | ], 186 | "./helpers/callSuper": [ 187 | { 188 | "node": "./src/helpers/callSuper.js", 189 | "import": "./src/helpers/esm/callSuper.js", 190 | "default": "./src/helpers/callSuper.js" 191 | }, 192 | "./src/helpers/callSuper.js" 193 | ], 194 | "./helpers/checkInRHS": [ 195 | { 196 | "node": "./src/helpers/checkInRHS.js", 197 | "import": "./src/helpers/esm/checkInRHS.js", 198 | "default": "./src/helpers/checkInRHS.js" 199 | }, 200 | "./src/helpers/checkInRHS.js" 201 | ], 202 | "./helpers/checkPrivateRedeclaration": [ 203 | { 204 | "node": "./src/helpers/checkPrivateRedeclaration.js", 205 | "import": "./src/helpers/esm/checkPrivateRedeclaration.js", 206 | "default": "./src/helpers/checkPrivateRedeclaration.js" 207 | }, 208 | "./src/helpers/checkPrivateRedeclaration.js" 209 | ], 210 | "./helpers/classApplyDescriptorDestructureSet": [ 211 | { 212 | "node": "./src/helpers/classApplyDescriptorDestructureSet.js", 213 | "import": "./src/helpers/esm/classApplyDescriptorDestructureSet.js", 214 | "default": "./src/helpers/classApplyDescriptorDestructureSet.js" 215 | }, 216 | "./src/helpers/classApplyDescriptorDestructureSet.js" 217 | ], 218 | "./helpers/classApplyDescriptorGet": [ 219 | { 220 | "node": "./src/helpers/classApplyDescriptorGet.js", 221 | "import": "./src/helpers/esm/classApplyDescriptorGet.js", 222 | "default": "./src/helpers/classApplyDescriptorGet.js" 223 | }, 224 | "./src/helpers/classApplyDescriptorGet.js" 225 | ], 226 | "./helpers/classApplyDescriptorSet": [ 227 | { 228 | "node": "./src/helpers/classApplyDescriptorSet.js", 229 | "import": "./src/helpers/esm/classApplyDescriptorSet.js", 230 | "default": "./src/helpers/classApplyDescriptorSet.js" 231 | }, 232 | "./src/helpers/classApplyDescriptorSet.js" 233 | ], 234 | "./helpers/classCallCheck": [ 235 | { 236 | "node": "./src/helpers/classCallCheck.js", 237 | "import": "./src/helpers/esm/classCallCheck.js", 238 | "default": "./src/helpers/classCallCheck.js" 239 | }, 240 | "./src/helpers/classCallCheck.js" 241 | ], 242 | "./helpers/classCheckPrivateStaticAccess": [ 243 | { 244 | "node": "./src/helpers/classCheckPrivateStaticAccess.js", 245 | "import": "./src/helpers/esm/classCheckPrivateStaticAccess.js", 246 | "default": "./src/helpers/classCheckPrivateStaticAccess.js" 247 | }, 248 | "./src/helpers/classCheckPrivateStaticAccess.js" 249 | ], 250 | "./helpers/classCheckPrivateStaticFieldDescriptor": [ 251 | { 252 | "node": "./src/helpers/classCheckPrivateStaticFieldDescriptor.js", 253 | "import": "./src/helpers/esm/classCheckPrivateStaticFieldDescriptor.js", 254 | "default": "./src/helpers/classCheckPrivateStaticFieldDescriptor.js" 255 | }, 256 | "./src/helpers/classCheckPrivateStaticFieldDescriptor.js" 257 | ], 258 | "./helpers/classExtractFieldDescriptor": [ 259 | { 260 | "node": "./src/helpers/classExtractFieldDescriptor.js", 261 | "import": "./src/helpers/esm/classExtractFieldDescriptor.js", 262 | "default": "./src/helpers/classExtractFieldDescriptor.js" 263 | }, 264 | "./src/helpers/classExtractFieldDescriptor.js" 265 | ], 266 | "./helpers/classNameTDZError": [ 267 | { 268 | "node": "./src/helpers/classNameTDZError.js", 269 | "import": "./src/helpers/esm/classNameTDZError.js", 270 | "default": "./src/helpers/classNameTDZError.js" 271 | }, 272 | "./src/helpers/classNameTDZError.js" 273 | ], 274 | "./helpers/classPrivateFieldDestructureSet": [ 275 | { 276 | "node": "./src/helpers/classPrivateFieldDestructureSet.js", 277 | "import": "./src/helpers/esm/classPrivateFieldDestructureSet.js", 278 | "default": "./src/helpers/classPrivateFieldDestructureSet.js" 279 | }, 280 | "./src/helpers/classPrivateFieldDestructureSet.js" 281 | ], 282 | "./helpers/classPrivateFieldGet": [ 283 | { 284 | "node": "./src/helpers/classPrivateFieldGet.js", 285 | "import": "./src/helpers/esm/classPrivateFieldGet.js", 286 | "default": "./src/helpers/classPrivateFieldGet.js" 287 | }, 288 | "./src/helpers/classPrivateFieldGet.js" 289 | ], 290 | "./helpers/classPrivateFieldGet2": [ 291 | { 292 | "node": "./src/helpers/classPrivateFieldGet2.js", 293 | "import": "./src/helpers/esm/classPrivateFieldGet2.js", 294 | "default": "./src/helpers/classPrivateFieldGet2.js" 295 | }, 296 | "./src/helpers/classPrivateFieldGet2.js" 297 | ], 298 | "./helpers/classPrivateFieldInitSpec": [ 299 | { 300 | "node": "./src/helpers/classPrivateFieldInitSpec.js", 301 | "import": "./src/helpers/esm/classPrivateFieldInitSpec.js", 302 | "default": "./src/helpers/classPrivateFieldInitSpec.js" 303 | }, 304 | "./src/helpers/classPrivateFieldInitSpec.js" 305 | ], 306 | "./helpers/classPrivateFieldLooseBase": [ 307 | { 308 | "node": "./src/helpers/classPrivateFieldLooseBase.js", 309 | "import": "./src/helpers/esm/classPrivateFieldLooseBase.js", 310 | "default": "./src/helpers/classPrivateFieldLooseBase.js" 311 | }, 312 | "./src/helpers/classPrivateFieldLooseBase.js" 313 | ], 314 | "./helpers/classPrivateFieldLooseKey": [ 315 | { 316 | "node": "./src/helpers/classPrivateFieldLooseKey.js", 317 | "import": "./src/helpers/esm/classPrivateFieldLooseKey.js", 318 | "default": "./src/helpers/classPrivateFieldLooseKey.js" 319 | }, 320 | "./src/helpers/classPrivateFieldLooseKey.js" 321 | ], 322 | "./helpers/classPrivateFieldSet": [ 323 | { 324 | "node": "./src/helpers/classPrivateFieldSet.js", 325 | "import": "./src/helpers/esm/classPrivateFieldSet.js", 326 | "default": "./src/helpers/classPrivateFieldSet.js" 327 | }, 328 | "./src/helpers/classPrivateFieldSet.js" 329 | ], 330 | "./helpers/classPrivateFieldSet2": [ 331 | { 332 | "node": "./src/helpers/classPrivateFieldSet2.js", 333 | "import": "./src/helpers/esm/classPrivateFieldSet2.js", 334 | "default": "./src/helpers/classPrivateFieldSet2.js" 335 | }, 336 | "./src/helpers/classPrivateFieldSet2.js" 337 | ], 338 | "./helpers/classPrivateGetter": [ 339 | { 340 | "node": "./src/helpers/classPrivateGetter.js", 341 | "import": "./src/helpers/esm/classPrivateGetter.js", 342 | "default": "./src/helpers/classPrivateGetter.js" 343 | }, 344 | "./src/helpers/classPrivateGetter.js" 345 | ], 346 | "./helpers/classPrivateMethodGet": [ 347 | { 348 | "node": "./src/helpers/classPrivateMethodGet.js", 349 | "import": "./src/helpers/esm/classPrivateMethodGet.js", 350 | "default": "./src/helpers/classPrivateMethodGet.js" 351 | }, 352 | "./src/helpers/classPrivateMethodGet.js" 353 | ], 354 | "./helpers/classPrivateMethodInitSpec": [ 355 | { 356 | "node": "./src/helpers/classPrivateMethodInitSpec.js", 357 | "import": "./src/helpers/esm/classPrivateMethodInitSpec.js", 358 | "default": "./src/helpers/classPrivateMethodInitSpec.js" 359 | }, 360 | "./src/helpers/classPrivateMethodInitSpec.js" 361 | ], 362 | "./helpers/classPrivateMethodSet": [ 363 | { 364 | "node": "./src/helpers/classPrivateMethodSet.js", 365 | "import": "./src/helpers/esm/classPrivateMethodSet.js", 366 | "default": "./src/helpers/classPrivateMethodSet.js" 367 | }, 368 | "./src/helpers/classPrivateMethodSet.js" 369 | ], 370 | "./helpers/classPrivateSetter": [ 371 | { 372 | "node": "./src/helpers/classPrivateSetter.js", 373 | "import": "./src/helpers/esm/classPrivateSetter.js", 374 | "default": "./src/helpers/classPrivateSetter.js" 375 | }, 376 | "./src/helpers/classPrivateSetter.js" 377 | ], 378 | "./helpers/classStaticPrivateFieldDestructureSet": [ 379 | { 380 | "node": "./src/helpers/classStaticPrivateFieldDestructureSet.js", 381 | "import": "./src/helpers/esm/classStaticPrivateFieldDestructureSet.js", 382 | "default": "./src/helpers/classStaticPrivateFieldDestructureSet.js" 383 | }, 384 | "./src/helpers/classStaticPrivateFieldDestructureSet.js" 385 | ], 386 | "./helpers/classStaticPrivateFieldSpecGet": [ 387 | { 388 | "node": "./src/helpers/classStaticPrivateFieldSpecGet.js", 389 | "import": "./src/helpers/esm/classStaticPrivateFieldSpecGet.js", 390 | "default": "./src/helpers/classStaticPrivateFieldSpecGet.js" 391 | }, 392 | "./src/helpers/classStaticPrivateFieldSpecGet.js" 393 | ], 394 | "./helpers/classStaticPrivateFieldSpecSet": [ 395 | { 396 | "node": "./src/helpers/classStaticPrivateFieldSpecSet.js", 397 | "import": "./src/helpers/esm/classStaticPrivateFieldSpecSet.js", 398 | "default": "./src/helpers/classStaticPrivateFieldSpecSet.js" 399 | }, 400 | "./src/helpers/classStaticPrivateFieldSpecSet.js" 401 | ], 402 | "./helpers/classStaticPrivateMethodGet": [ 403 | { 404 | "node": "./src/helpers/classStaticPrivateMethodGet.js", 405 | "import": "./src/helpers/esm/classStaticPrivateMethodGet.js", 406 | "default": "./src/helpers/classStaticPrivateMethodGet.js" 407 | }, 408 | "./src/helpers/classStaticPrivateMethodGet.js" 409 | ], 410 | "./helpers/classStaticPrivateMethodSet": [ 411 | { 412 | "node": "./src/helpers/classStaticPrivateMethodSet.js", 413 | "import": "./src/helpers/esm/classStaticPrivateMethodSet.js", 414 | "default": "./src/helpers/classStaticPrivateMethodSet.js" 415 | }, 416 | "./src/helpers/classStaticPrivateMethodSet.js" 417 | ], 418 | "./helpers/construct": [ 419 | { 420 | "node": "./src/helpers/construct.js", 421 | "import": "./src/helpers/esm/construct.js", 422 | "default": "./src/helpers/construct.js" 423 | }, 424 | "./src/helpers/construct.js" 425 | ], 426 | "./helpers/createClass": [ 427 | { 428 | "node": "./src/helpers/createClass.js", 429 | "import": "./src/helpers/esm/createClass.js", 430 | "default": "./src/helpers/createClass.js" 431 | }, 432 | "./src/helpers/createClass.js" 433 | ], 434 | "./helpers/createForOfIteratorHelper": [ 435 | { 436 | "node": "./src/helpers/createForOfIteratorHelper.js", 437 | "import": "./src/helpers/esm/createForOfIteratorHelper.js", 438 | "default": "./src/helpers/createForOfIteratorHelper.js" 439 | }, 440 | "./src/helpers/createForOfIteratorHelper.js" 441 | ], 442 | "./helpers/createForOfIteratorHelperLoose": [ 443 | { 444 | "node": "./src/helpers/createForOfIteratorHelperLoose.js", 445 | "import": "./src/helpers/esm/createForOfIteratorHelperLoose.js", 446 | "default": "./src/helpers/createForOfIteratorHelperLoose.js" 447 | }, 448 | "./src/helpers/createForOfIteratorHelperLoose.js" 449 | ], 450 | "./helpers/createSuper": [ 451 | { 452 | "node": "./src/helpers/createSuper.js", 453 | "import": "./src/helpers/esm/createSuper.js", 454 | "default": "./src/helpers/createSuper.js" 455 | }, 456 | "./src/helpers/createSuper.js" 457 | ], 458 | "./helpers/decorate": [ 459 | { 460 | "node": "./src/helpers/decorate.js", 461 | "import": "./src/helpers/esm/decorate.js", 462 | "default": "./src/helpers/decorate.js" 463 | }, 464 | "./src/helpers/decorate.js" 465 | ], 466 | "./helpers/decorateMetadata": [ 467 | { 468 | "node": "./src/helpers/decorateMetadata.js", 469 | "import": "./src/helpers/esm/decorateMetadata.js", 470 | "default": "./src/helpers/decorateMetadata.js" 471 | }, 472 | "./src/helpers/decorateMetadata.js" 473 | ], 474 | "./helpers/decorateParam": [ 475 | { 476 | "node": "./src/helpers/decorateParam.js", 477 | "import": "./src/helpers/esm/decorateParam.js", 478 | "default": "./src/helpers/decorateParam.js" 479 | }, 480 | "./src/helpers/decorateParam.js" 481 | ], 482 | "./helpers/defaults": [ 483 | { 484 | "node": "./src/helpers/defaults.js", 485 | "import": "./src/helpers/esm/defaults.js", 486 | "default": "./src/helpers/defaults.js" 487 | }, 488 | "./src/helpers/defaults.js" 489 | ], 490 | "./helpers/defineAccessor": [ 491 | { 492 | "node": "./src/helpers/defineAccessor.js", 493 | "import": "./src/helpers/esm/defineAccessor.js", 494 | "default": "./src/helpers/defineAccessor.js" 495 | }, 496 | "./src/helpers/defineAccessor.js" 497 | ], 498 | "./helpers/defineEnumerableProperties": [ 499 | { 500 | "node": "./src/helpers/defineEnumerableProperties.js", 501 | "import": "./src/helpers/esm/defineEnumerableProperties.js", 502 | "default": "./src/helpers/defineEnumerableProperties.js" 503 | }, 504 | "./src/helpers/defineEnumerableProperties.js" 505 | ], 506 | "./helpers/defineProperty": [ 507 | { 508 | "node": "./src/helpers/defineProperty.js", 509 | "import": "./src/helpers/esm/defineProperty.js", 510 | "default": "./src/helpers/defineProperty.js" 511 | }, 512 | "./src/helpers/defineProperty.js" 513 | ], 514 | "./helpers/dispose": [ 515 | { 516 | "node": "./src/helpers/dispose.js", 517 | "import": "./src/helpers/esm/dispose.js", 518 | "default": "./src/helpers/dispose.js" 519 | }, 520 | "./src/helpers/dispose.js" 521 | ], 522 | "./helpers/esm/AwaitValue": "./src/helpers/esm/AwaitValue.js", 523 | "./helpers/esm/OverloadYield": "./src/helpers/esm/OverloadYield.js", 524 | "./helpers/esm/applyDecoratedDescriptor": "./src/helpers/esm/applyDecoratedDescriptor.js", 525 | "./helpers/esm/applyDecs": "./src/helpers/esm/applyDecs.js", 526 | "./helpers/esm/applyDecs2203": "./src/helpers/esm/applyDecs2203.js", 527 | "./helpers/esm/applyDecs2203R": "./src/helpers/esm/applyDecs2203R.js", 528 | "./helpers/esm/applyDecs2301": "./src/helpers/esm/applyDecs2301.js", 529 | "./helpers/esm/applyDecs2305": "./src/helpers/esm/applyDecs2305.js", 530 | "./helpers/esm/applyDecs2311": "./src/helpers/esm/applyDecs2311.js", 531 | "./helpers/esm/arrayLikeToArray": "./src/helpers/esm/arrayLikeToArray.js", 532 | "./helpers/esm/arrayWithHoles": "./src/helpers/esm/arrayWithHoles.js", 533 | "./helpers/esm/arrayWithoutHoles": "./src/helpers/esm/arrayWithoutHoles.js", 534 | "./helpers/esm/assertClassBrand": "./src/helpers/esm/assertClassBrand.js", 535 | "./helpers/esm/assertThisInitialized": "./src/helpers/esm/assertThisInitialized.js", 536 | "./helpers/esm/asyncGeneratorDelegate": "./src/helpers/esm/asyncGeneratorDelegate.js", 537 | "./helpers/esm/asyncIterator": "./src/helpers/esm/asyncIterator.js", 538 | "./helpers/esm/asyncToGenerator": "./src/helpers/esm/asyncToGenerator.js", 539 | "./helpers/esm/awaitAsyncGenerator": "./src/helpers/esm/awaitAsyncGenerator.js", 540 | "./helpers/esm/callSuper": "./src/helpers/esm/callSuper.js", 541 | "./helpers/esm/checkInRHS": "./src/helpers/esm/checkInRHS.js", 542 | "./helpers/esm/checkPrivateRedeclaration": "./src/helpers/esm/checkPrivateRedeclaration.js", 543 | "./helpers/esm/classApplyDescriptorDestructureSet": "./src/helpers/esm/classApplyDescriptorDestructureSet.js", 544 | "./helpers/esm/classApplyDescriptorGet": "./src/helpers/esm/classApplyDescriptorGet.js", 545 | "./helpers/esm/classApplyDescriptorSet": "./src/helpers/esm/classApplyDescriptorSet.js", 546 | "./helpers/esm/classCallCheck": "./src/helpers/esm/classCallCheck.js", 547 | "./helpers/esm/classCheckPrivateStaticAccess": "./src/helpers/esm/classCheckPrivateStaticAccess.js", 548 | "./helpers/esm/classCheckPrivateStaticFieldDescriptor": "./src/helpers/esm/classCheckPrivateStaticFieldDescriptor.js", 549 | "./helpers/esm/classExtractFieldDescriptor": "./src/helpers/esm/classExtractFieldDescriptor.js", 550 | "./helpers/esm/classNameTDZError": "./src/helpers/esm/classNameTDZError.js", 551 | "./helpers/esm/classPrivateFieldDestructureSet": "./src/helpers/esm/classPrivateFieldDestructureSet.js", 552 | "./helpers/esm/classPrivateFieldGet": "./src/helpers/esm/classPrivateFieldGet.js", 553 | "./helpers/esm/classPrivateFieldGet2": "./src/helpers/esm/classPrivateFieldGet2.js", 554 | "./helpers/esm/classPrivateFieldInitSpec": "./src/helpers/esm/classPrivateFieldInitSpec.js", 555 | "./helpers/esm/classPrivateFieldLooseBase": "./src/helpers/esm/classPrivateFieldLooseBase.js", 556 | "./helpers/esm/classPrivateFieldLooseKey": "./src/helpers/esm/classPrivateFieldLooseKey.js", 557 | "./helpers/esm/classPrivateFieldSet": "./src/helpers/esm/classPrivateFieldSet.js", 558 | "./helpers/esm/classPrivateFieldSet2": "./src/helpers/esm/classPrivateFieldSet2.js", 559 | "./helpers/esm/classPrivateGetter": "./src/helpers/esm/classPrivateGetter.js", 560 | "./helpers/esm/classPrivateMethodGet": "./src/helpers/esm/classPrivateMethodGet.js", 561 | "./helpers/esm/classPrivateMethodInitSpec": "./src/helpers/esm/classPrivateMethodInitSpec.js", 562 | "./helpers/esm/classPrivateMethodSet": "./src/helpers/esm/classPrivateMethodSet.js", 563 | "./helpers/esm/classPrivateSetter": "./src/helpers/esm/classPrivateSetter.js", 564 | "./helpers/esm/classStaticPrivateFieldDestructureSet": "./src/helpers/esm/classStaticPrivateFieldDestructureSet.js", 565 | "./helpers/esm/classStaticPrivateFieldSpecGet": "./src/helpers/esm/classStaticPrivateFieldSpecGet.js", 566 | "./helpers/esm/classStaticPrivateFieldSpecSet": "./src/helpers/esm/classStaticPrivateFieldSpecSet.js", 567 | "./helpers/esm/classStaticPrivateMethodGet": "./src/helpers/esm/classStaticPrivateMethodGet.js", 568 | "./helpers/esm/classStaticPrivateMethodSet": "./src/helpers/esm/classStaticPrivateMethodSet.js", 569 | "./helpers/esm/construct": "./src/helpers/esm/construct.js", 570 | "./helpers/esm/createClass": "./src/helpers/esm/createClass.js", 571 | "./helpers/esm/createForOfIteratorHelper": "./src/helpers/esm/createForOfIteratorHelper.js", 572 | "./helpers/esm/createForOfIteratorHelperLoose": "./src/helpers/esm/createForOfIteratorHelperLoose.js", 573 | "./helpers/esm/createSuper": "./src/helpers/esm/createSuper.js", 574 | "./helpers/esm/decorate": "./src/helpers/esm/decorate.js", 575 | "./helpers/esm/decorateMetadata": "./src/helpers/esm/decorateMetadata.js", 576 | "./helpers/esm/defaults": "./src/helpers/esm/defaults.js", 577 | "./helpers/esm/defineAccessor": "./src/helpers/esm/defineAccessor.js", 578 | "./helpers/esm/defineEnumerableProperties": "./src/helpers/esm/defineEnumerableProperties.js", 579 | "./helpers/esm/defineProperty": "./src/helpers/esm/defineProperty.js", 580 | "./helpers/esm/dispose": "./src/helpers/esm/dispose.js", 581 | "./helpers/esm/extends": "./src/helpers/esm/extends.js", 582 | "./helpers/esm/get": "./src/helpers/esm/get.js", 583 | "./helpers/esm/getPrototypeOf": "./src/helpers/esm/getPrototypeOf.js", 584 | "./helpers/esm/identity": "./src/helpers/esm/identity.js", 585 | "./helpers/esm/importDeferProxy": "./src/helpers/esm/importDeferProxy.js", 586 | "./helpers/esm/inherits": "./src/helpers/esm/inherits.js", 587 | "./helpers/esm/inheritsLoose": "./src/helpers/esm/inheritsLoose.js", 588 | "./helpers/esm/initializerDefineProperty": "./src/helpers/esm/initializerDefineProperty.js", 589 | "./helpers/esm/initializerWarningHelper": "./src/helpers/esm/initializerWarningHelper.js", 590 | "./helpers/esm/instanceof": "./src/helpers/esm/instanceof.js", 591 | "./helpers/esm/interopRequireDefault": "./src/helpers/esm/interopRequireDefault.js", 592 | "./helpers/esm/interopRequireWildcard": "./src/helpers/esm/interopRequireWildcard.js", 593 | "./helpers/esm/isNativeFunction": "./src/helpers/esm/isNativeFunction.js", 594 | "./helpers/esm/isNativeReflectConstruct": "./src/helpers/esm/isNativeReflectConstruct.js", 595 | "./helpers/esm/iterableToArray": "./src/helpers/esm/iterableToArray.js", 596 | "./helpers/esm/iterableToArrayLimit": "./src/helpers/esm/iterableToArrayLimit.js", 597 | "./helpers/esm/jsx": "./src/helpers/esm/jsx.js", 598 | "./helpers/esm/maybeArrayLike": "./src/helpers/esm/maybeArrayLike.js", 599 | "./helpers/esm/newArrowCheck": "./src/helpers/esm/newArrowCheck.js", 600 | "./helpers/esm/nonIterableRest": "./src/helpers/esm/nonIterableRest.js", 601 | "./helpers/esm/nonIterableSpread": "./src/helpers/esm/nonIterableSpread.js", 602 | "./helpers/esm/nullishReceiverError": "./src/helpers/esm/nullishReceiverError.js", 603 | "./helpers/esm/objectDestructuringEmpty": "./src/helpers/esm/objectDestructuringEmpty.js", 604 | "./helpers/esm/objectSpread": "./src/helpers/esm/objectSpread.js", 605 | "./helpers/esm/objectSpread2": "./src/helpers/esm/objectSpread2.js", 606 | "./helpers/esm/objectWithoutProperties": "./src/helpers/esm/objectWithoutProperties.js", 607 | "./helpers/esm/objectWithoutPropertiesLoose": "./src/helpers/esm/objectWithoutPropertiesLoose.js", 608 | "./helpers/esm/possibleConstructorReturn": "./src/helpers/esm/possibleConstructorReturn.js", 609 | "./helpers/esm/readOnlyError": "./src/helpers/esm/readOnlyError.js", 610 | "./helpers/esm/regeneratorRuntime": "./src/helpers/esm/regeneratorRuntime.js", 611 | "./helpers/esm/set": "./src/helpers/esm/set.js", 612 | "./helpers/esm/setFunctionName": "./src/helpers/esm/setFunctionName.js", 613 | "./helpers/esm/setPrototypeOf": "./src/helpers/esm/setPrototypeOf.js", 614 | "./helpers/esm/skipFirstGeneratorNext": "./src/helpers/esm/skipFirstGeneratorNext.js", 615 | "./helpers/esm/slicedToArray": "./src/helpers/esm/slicedToArray.js", 616 | "./helpers/esm/superPropBase": "./src/helpers/esm/superPropBase.js", 617 | "./helpers/esm/superPropGet": "./src/helpers/esm/superPropGet.js", 618 | "./helpers/esm/superPropSet": "./src/helpers/esm/superPropSet.js", 619 | "./helpers/esm/taggedTemplateLiteral": "./src/helpers/esm/taggedTemplateLiteral.js", 620 | "./helpers/esm/taggedTemplateLiteralLoose": "./src/helpers/esm/taggedTemplateLiteralLoose.js", 621 | "./helpers/esm/tdz": "./src/helpers/esm/tdz.js", 622 | "./helpers/esm/temporalRef": "./src/helpers/esm/temporalRef.js", 623 | "./helpers/esm/temporalUndefined": "./src/helpers/esm/temporalUndefined.js", 624 | "./helpers/esm/toArray": "./src/helpers/esm/toArray.js", 625 | "./helpers/esm/toConsumableArray": "./src/helpers/esm/toConsumableArray.js", 626 | "./helpers/esm/toPrimitive": "./src/helpers/esm/toPrimitive.js", 627 | "./helpers/esm/toPropertyKey": "./src/helpers/esm/toPropertyKey.js", 628 | "./helpers/esm/toSetter": "./src/helpers/esm/toSetter.js", 629 | "./helpers/esm/typeof": "./src/helpers/esm/typeof.js", 630 | "./helpers/esm/unsupportedIterableToArray": "./src/helpers/esm/unsupportedIterableToArray.js", 631 | "./helpers/esm/using": "./src/helpers/esm/using.js", 632 | "./helpers/esm/usingCtx": "./src/helpers/esm/usingCtx.js", 633 | "./helpers/esm/wrapAsyncGenerator": "./src/helpers/esm/wrapAsyncGenerator.js", 634 | "./helpers/esm/wrapNativeSuper": "./src/helpers/esm/wrapNativeSuper.js", 635 | "./helpers/esm/wrapRegExp": "./src/helpers/esm/wrapRegExp.js", 636 | "./helpers/esm/writeOnlyError": "./src/helpers/esm/writeOnlyError.js", 637 | "./helpers/extends": [ 638 | { 639 | "node": "./src/helpers/extends.js", 640 | "import": "./src/helpers/esm/extends.js", 641 | "default": "./src/helpers/extends.js" 642 | }, 643 | "./src/helpers/extends.js" 644 | ], 645 | "./helpers/get": [ 646 | { 647 | "node": "./src/helpers/get.js", 648 | "import": "./src/helpers/esm/get.js", 649 | "default": "./src/helpers/get.js" 650 | }, 651 | "./src/helpers/get.js" 652 | ], 653 | "./helpers/getPrototypeOf": [ 654 | { 655 | "node": "./src/helpers/getPrototypeOf.js", 656 | "import": "./src/helpers/esm/getPrototypeOf.js", 657 | "default": "./src/helpers/getPrototypeOf.js" 658 | }, 659 | "./src/helpers/getPrototypeOf.js" 660 | ], 661 | "./helpers/identity": [ 662 | { 663 | "node": "./src/helpers/identity.js", 664 | "import": "./src/helpers/esm/identity.js", 665 | "default": "./src/helpers/identity.js" 666 | }, 667 | "./src/helpers/identity.js" 668 | ], 669 | "./helpers/importDeferProxy": [ 670 | { 671 | "node": "./src/helpers/importDeferProxy.js", 672 | "import": "./src/helpers/esm/importDeferProxy.js", 673 | "default": "./src/helpers/importDeferProxy.js" 674 | }, 675 | "./src/helpers/importDeferProxy.js" 676 | ], 677 | "./helpers/inherits": [ 678 | { 679 | "node": "./src/helpers/inherits.js", 680 | "import": "./src/helpers/esm/inherits.js", 681 | "default": "./src/helpers/inherits.js" 682 | }, 683 | "./src/helpers/inherits.js" 684 | ], 685 | "./helpers/inheritsLoose": [ 686 | { 687 | "node": "./src/helpers/inheritsLoose.js", 688 | "import": "./src/helpers/esm/inheritsLoose.js", 689 | "default": "./src/helpers/inheritsLoose.js" 690 | }, 691 | "./src/helpers/inheritsLoose.js" 692 | ], 693 | "./helpers/initializerDefineProperty": [ 694 | { 695 | "node": "./src/helpers/initializerDefineProperty.js", 696 | "import": "./src/helpers/esm/initializerDefineProperty.js", 697 | "default": "./src/helpers/initializerDefineProperty.js" 698 | }, 699 | "./src/helpers/initializerDefineProperty.js" 700 | ], 701 | "./helpers/initializerWarningHelper": [ 702 | { 703 | "node": "./src/helpers/initializerWarningHelper.js", 704 | "import": "./src/helpers/esm/initializerWarningHelper.js", 705 | "default": "./src/helpers/initializerWarningHelper.js" 706 | }, 707 | "./src/helpers/initializerWarningHelper.js" 708 | ], 709 | "./helpers/instanceof": [ 710 | { 711 | "node": "./src/helpers/instanceof.js", 712 | "import": "./src/helpers/esm/instanceof.js", 713 | "default": "./src/helpers/instanceof.js" 714 | }, 715 | "./src/helpers/instanceof.js" 716 | ], 717 | "./helpers/interopRequireDefault": [ 718 | { 719 | "node": "./src/helpers/interopRequireDefault.js", 720 | "import": "./src/helpers/esm/interopRequireDefault.js", 721 | "default": "./src/helpers/interopRequireDefault.js" 722 | }, 723 | "./src/helpers/interopRequireDefault.js" 724 | ], 725 | "./helpers/interopRequireWildcard": [ 726 | { 727 | "node": "./src/helpers/interopRequireWildcard.js", 728 | "import": "./src/helpers/esm/interopRequireWildcard.js", 729 | "default": "./src/helpers/interopRequireWildcard.js" 730 | }, 731 | "./src/helpers/interopRequireWildcard.js" 732 | ], 733 | "./helpers/isNativeFunction": [ 734 | { 735 | "node": "./src/helpers/isNativeFunction.js", 736 | "import": "./src/helpers/esm/isNativeFunction.js", 737 | "default": "./src/helpers/isNativeFunction.js" 738 | }, 739 | "./src/helpers/isNativeFunction.js" 740 | ], 741 | "./helpers/isNativeReflectConstruct": [ 742 | { 743 | "node": "./src/helpers/isNativeReflectConstruct.js", 744 | "import": "./src/helpers/esm/isNativeReflectConstruct.js", 745 | "default": "./src/helpers/isNativeReflectConstruct.js" 746 | }, 747 | "./src/helpers/isNativeReflectConstruct.js" 748 | ], 749 | "./helpers/iterableToArray": [ 750 | { 751 | "node": "./src/helpers/iterableToArray.js", 752 | "import": "./src/helpers/esm/iterableToArray.js", 753 | "default": "./src/helpers/iterableToArray.js" 754 | }, 755 | "./src/helpers/iterableToArray.js" 756 | ], 757 | "./helpers/iterableToArrayLimit": [ 758 | { 759 | "node": "./src/helpers/iterableToArrayLimit.js", 760 | "import": "./src/helpers/esm/iterableToArrayLimit.js", 761 | "default": "./src/helpers/iterableToArrayLimit.js" 762 | }, 763 | "./src/helpers/iterableToArrayLimit.js" 764 | ], 765 | "./helpers/jsx": [ 766 | { 767 | "node": "./src/helpers/jsx.js", 768 | "import": "./src/helpers/esm/jsx.js", 769 | "default": "./src/helpers/jsx.js" 770 | }, 771 | "./src/helpers/jsx.js" 772 | ], 773 | "./helpers/maybeArrayLike": [ 774 | { 775 | "node": "./src/helpers/maybeArrayLike.js", 776 | "import": "./src/helpers/esm/maybeArrayLike.js", 777 | "default": "./src/helpers/maybeArrayLike.js" 778 | }, 779 | "./src/helpers/maybeArrayLike.js" 780 | ], 781 | "./helpers/newArrowCheck": [ 782 | { 783 | "node": "./src/helpers/newArrowCheck.js", 784 | "import": "./src/helpers/esm/newArrowCheck.js", 785 | "default": "./src/helpers/newArrowCheck.js" 786 | }, 787 | "./src/helpers/newArrowCheck.js" 788 | ], 789 | "./helpers/nonIterableRest": [ 790 | { 791 | "node": "./src/helpers/nonIterableRest.js", 792 | "import": "./src/helpers/esm/nonIterableRest.js", 793 | "default": "./src/helpers/nonIterableRest.js" 794 | }, 795 | "./src/helpers/nonIterableRest.js" 796 | ], 797 | "./helpers/nonIterableSpread": [ 798 | { 799 | "node": "./src/helpers/nonIterableSpread.js", 800 | "import": "./src/helpers/esm/nonIterableSpread.js", 801 | "default": "./src/helpers/nonIterableSpread.js" 802 | }, 803 | "./src/helpers/nonIterableSpread.js" 804 | ], 805 | "./helpers/nullishReceiverError": [ 806 | { 807 | "node": "./src/helpers/nullishReceiverError.js", 808 | "import": "./src/helpers/esm/nullishReceiverError.js", 809 | "default": "./src/helpers/nullishReceiverError.js" 810 | }, 811 | "./src/helpers/nullishReceiverError.js" 812 | ], 813 | "./helpers/objectDestructuringEmpty": [ 814 | { 815 | "node": "./src/helpers/objectDestructuringEmpty.js", 816 | "import": "./src/helpers/esm/objectDestructuringEmpty.js", 817 | "default": "./src/helpers/objectDestructuringEmpty.js" 818 | }, 819 | "./src/helpers/objectDestructuringEmpty.js" 820 | ], 821 | "./helpers/objectSpread": [ 822 | { 823 | "node": "./src/helpers/objectSpread.js", 824 | "import": "./src/helpers/esm/objectSpread.js", 825 | "default": "./src/helpers/objectSpread.js" 826 | }, 827 | "./src/helpers/objectSpread.js" 828 | ], 829 | "./helpers/objectSpread2": [ 830 | { 831 | "node": "./src/helpers/objectSpread2.js", 832 | "import": "./src/helpers/esm/objectSpread2.js", 833 | "default": "./src/helpers/objectSpread2.js" 834 | }, 835 | "./src/helpers/objectSpread2.js" 836 | ], 837 | "./helpers/objectWithoutProperties": [ 838 | { 839 | "node": "./src/helpers/objectWithoutProperties.js", 840 | "import": "./src/helpers/esm/objectWithoutProperties.js", 841 | "default": "./src/helpers/objectWithoutProperties.js" 842 | }, 843 | "./src/helpers/objectWithoutProperties.js" 844 | ], 845 | "./helpers/objectWithoutPropertiesLoose": [ 846 | { 847 | "node": "./src/helpers/objectWithoutPropertiesLoose.js", 848 | "import": "./src/helpers/esm/objectWithoutPropertiesLoose.js", 849 | "default": "./src/helpers/objectWithoutPropertiesLoose.js" 850 | }, 851 | "./src/helpers/objectWithoutPropertiesLoose.js" 852 | ], 853 | "./helpers/possibleConstructorReturn": [ 854 | { 855 | "node": "./src/helpers/possibleConstructorReturn.js", 856 | "import": "./src/helpers/esm/possibleConstructorReturn.js", 857 | "default": "./src/helpers/possibleConstructorReturn.js" 858 | }, 859 | "./src/helpers/possibleConstructorReturn.js" 860 | ], 861 | "./helpers/readOnlyError": [ 862 | { 863 | "node": "./src/helpers/readOnlyError.js", 864 | "import": "./src/helpers/esm/readOnlyError.js", 865 | "default": "./src/helpers/readOnlyError.js" 866 | }, 867 | "./src/helpers/readOnlyError.js" 868 | ], 869 | "./helpers/regeneratorRuntime": [ 870 | { 871 | "node": "./src/helpers/regeneratorRuntime.js", 872 | "import": "./src/helpers/esm/regeneratorRuntime.js", 873 | "default": "./src/helpers/regeneratorRuntime.js" 874 | }, 875 | "./src/helpers/regeneratorRuntime.js" 876 | ], 877 | "./helpers/set": [ 878 | { 879 | "node": "./src/helpers/set.js", 880 | "import": "./src/helpers/esm/set.js", 881 | "default": "./src/helpers/set.js" 882 | }, 883 | "./src/helpers/set.js" 884 | ], 885 | "./helpers/setFunctionName": [ 886 | { 887 | "node": "./src/helpers/setFunctionName.js", 888 | "import": "./src/helpers/esm/setFunctionName.js", 889 | "default": "./src/helpers/setFunctionName.js" 890 | }, 891 | "./src/helpers/setFunctionName.js" 892 | ], 893 | "./helpers/setPrototypeOf": [ 894 | { 895 | "node": "./src/helpers/setPrototypeOf.js", 896 | "import": "./src/helpers/esm/setPrototypeOf.js", 897 | "default": "./src/helpers/setPrototypeOf.js" 898 | }, 899 | "./src/helpers/setPrototypeOf.js" 900 | ], 901 | "./helpers/skipFirstGeneratorNext": [ 902 | { 903 | "node": "./src/helpers/skipFirstGeneratorNext.js", 904 | "import": "./src/helpers/esm/skipFirstGeneratorNext.js", 905 | "default": "./src/helpers/skipFirstGeneratorNext.js" 906 | }, 907 | "./src/helpers/skipFirstGeneratorNext.js" 908 | ], 909 | "./helpers/slicedToArray": [ 910 | { 911 | "node": "./src/helpers/slicedToArray.js", 912 | "import": "./src/helpers/esm/slicedToArray.js", 913 | "default": "./src/helpers/slicedToArray.js" 914 | }, 915 | "./src/helpers/slicedToArray.js" 916 | ], 917 | "./helpers/superPropBase": [ 918 | { 919 | "node": "./src/helpers/superPropBase.js", 920 | "import": "./src/helpers/esm/superPropBase.js", 921 | "default": "./src/helpers/superPropBase.js" 922 | }, 923 | "./src/helpers/superPropBase.js" 924 | ], 925 | "./helpers/superPropGet": [ 926 | { 927 | "node": "./src/helpers/superPropGet.js", 928 | "import": "./src/helpers/esm/superPropGet.js", 929 | "default": "./src/helpers/superPropGet.js" 930 | }, 931 | "./src/helpers/superPropGet.js" 932 | ], 933 | "./helpers/superPropSet": [ 934 | { 935 | "node": "./src/helpers/superPropSet.js", 936 | "import": "./src/helpers/esm/superPropSet.js", 937 | "default": "./src/helpers/superPropSet.js" 938 | }, 939 | "./src/helpers/superPropSet.js" 940 | ], 941 | "./helpers/taggedTemplateLiteral": [ 942 | { 943 | "node": "./src/helpers/taggedTemplateLiteral.js", 944 | "import": "./src/helpers/esm/taggedTemplateLiteral.js", 945 | "default": "./src/helpers/taggedTemplateLiteral.js" 946 | }, 947 | "./src/helpers/taggedTemplateLiteral.js" 948 | ], 949 | "./helpers/taggedTemplateLiteralLoose": [ 950 | { 951 | "node": "./src/helpers/taggedTemplateLiteralLoose.js", 952 | "import": "./src/helpers/esm/taggedTemplateLiteralLoose.js", 953 | "default": "./src/helpers/taggedTemplateLiteralLoose.js" 954 | }, 955 | "./src/helpers/taggedTemplateLiteralLoose.js" 956 | ], 957 | "./helpers/tdz": [ 958 | { 959 | "node": "./src/helpers/tdz.js", 960 | "import": "./src/helpers/esm/tdz.js", 961 | "default": "./src/helpers/tdz.js" 962 | }, 963 | "./src/helpers/tdz.js" 964 | ], 965 | "./helpers/temporalRef": [ 966 | { 967 | "node": "./src/helpers/temporalRef.js", 968 | "import": "./src/helpers/esm/temporalRef.js", 969 | "default": "./src/helpers/temporalRef.js" 970 | }, 971 | "./src/helpers/temporalRef.js" 972 | ], 973 | "./helpers/temporalUndefined": [ 974 | { 975 | "node": "./src/helpers/temporalUndefined.js", 976 | "import": "./src/helpers/esm/temporalUndefined.js", 977 | "default": "./src/helpers/temporalUndefined.js" 978 | }, 979 | "./src/helpers/temporalUndefined.js" 980 | ], 981 | "./helpers/toArray": [ 982 | { 983 | "node": "./src/helpers/toArray.js", 984 | "import": "./src/helpers/esm/toArray.js", 985 | "default": "./src/helpers/toArray.js" 986 | }, 987 | "./src/helpers/toArray.js" 988 | ], 989 | "./helpers/toConsumableArray": [ 990 | { 991 | "node": "./src/helpers/toConsumableArray.js", 992 | "import": "./src/helpers/esm/toConsumableArray.js", 993 | "default": "./src/helpers/toConsumableArray.js" 994 | }, 995 | "./src/helpers/toConsumableArray.js" 996 | ], 997 | "./helpers/toPrimitive": [ 998 | { 999 | "node": "./src/helpers/toPrimitive.js", 1000 | "import": "./src/helpers/esm/toPrimitive.js", 1001 | "default": "./src/helpers/toPrimitive.js" 1002 | }, 1003 | "./src/helpers/toPrimitive.js" 1004 | ], 1005 | "./helpers/toPropertyKey": [ 1006 | { 1007 | "node": "./src/helpers/toPropertyKey.js", 1008 | "import": "./src/helpers/esm/toPropertyKey.js", 1009 | "default": "./src/helpers/toPropertyKey.js" 1010 | }, 1011 | "./src/helpers/toPropertyKey.js" 1012 | ], 1013 | "./helpers/toSetter": [ 1014 | { 1015 | "node": "./src/helpers/toSetter.js", 1016 | "import": "./src/helpers/esm/toSetter.js", 1017 | "default": "./src/helpers/toSetter.js" 1018 | }, 1019 | "./src/helpers/toSetter.js" 1020 | ], 1021 | "./helpers/typeof": [ 1022 | { 1023 | "node": "./src/helpers/typeof.js", 1024 | "import": "./src/helpers/esm/typeof.js", 1025 | "default": "./src/helpers/typeof.js" 1026 | }, 1027 | "./src/helpers/typeof.js" 1028 | ], 1029 | "./helpers/unsupportedIterableToArray": [ 1030 | { 1031 | "node": "./src/helpers/unsupportedIterableToArray.js", 1032 | "import": "./src/helpers/esm/unsupportedIterableToArray.js", 1033 | "default": "./src/helpers/unsupportedIterableToArray.js" 1034 | }, 1035 | "./src/helpers/unsupportedIterableToArray.js" 1036 | ], 1037 | "./helpers/using": [ 1038 | { 1039 | "node": "./src/helpers/using.js", 1040 | "import": "./src/helpers/esm/using.js", 1041 | "default": "./src/helpers/using.js" 1042 | }, 1043 | "./src/helpers/using.js" 1044 | ], 1045 | "./helpers/usingCtx": [ 1046 | { 1047 | "node": "./src/helpers/usingCtx.js", 1048 | "import": "./src/helpers/esm/usingCtx.js", 1049 | "default": "./src/helpers/usingCtx.js" 1050 | }, 1051 | "./src/helpers/usingCtx.js" 1052 | ], 1053 | "./helpers/wrapAsyncGenerator": [ 1054 | { 1055 | "node": "./src/helpers/wrapAsyncGenerator.js", 1056 | "import": "./src/helpers/esm/wrapAsyncGenerator.js", 1057 | "default": "./src/helpers/wrapAsyncGenerator.js" 1058 | }, 1059 | "./src/helpers/wrapAsyncGenerator.js" 1060 | ], 1061 | "./helpers/wrapNativeSuper": [ 1062 | { 1063 | "node": "./src/helpers/wrapNativeSuper.js", 1064 | "import": "./src/helpers/esm/wrapNativeSuper.js", 1065 | "default": "./src/helpers/wrapNativeSuper.js" 1066 | }, 1067 | "./src/helpers/wrapNativeSuper.js" 1068 | ], 1069 | "./helpers/wrapRegExp": [ 1070 | { 1071 | "node": "./src/helpers/wrapRegExp.js", 1072 | "import": "./src/helpers/esm/wrapRegExp.js", 1073 | "default": "./src/helpers/wrapRegExp.js" 1074 | }, 1075 | "./src/helpers/wrapRegExp.js" 1076 | ], 1077 | "./helpers/writeOnlyError": [ 1078 | { 1079 | "node": "./src/helpers/writeOnlyError.js", 1080 | "import": "./src/helpers/esm/writeOnlyError.js", 1081 | "default": "./src/helpers/writeOnlyError.js" 1082 | }, 1083 | "./src/helpers/writeOnlyError.js" 1084 | ], 1085 | "./package": "./package.json", 1086 | "./package.json": "./package.json", 1087 | "./regenerator": "./regenerator/index.js", 1088 | "./regenerator/": "./regenerator/", 1089 | "./regenerator/*.js": "./regenerator/*.js", 1090 | "./register": { 1091 | "import": "./register.mjs" 1092 | }, 1093 | "./register.mjs": { 1094 | "import": "./register.mjs" 1095 | } 1096 | }, 1097 | "publishConfig": { 1098 | "access": "public", 1099 | "registry": "https://registry.npmjs.org/" 1100 | }, 1101 | "scripts": { 1102 | "build": "napi build --platform --release --manifest-path ../../Cargo.toml -o .", 1103 | "export-oxc-runtime": "node ./reexport-oxc-runtime.mjs", 1104 | "prepublishOnly": "node ./reexport-oxc-runtime.mjs", 1105 | "version": "napi version" 1106 | }, 1107 | "dependencies": { 1108 | "pirates": "^4.0.7" 1109 | }, 1110 | "devDependencies": { 1111 | "@napi-rs/cli": "catalog:", 1112 | "@oxc-project/runtime": "^0.104.0" 1113 | }, 1114 | "napi": { 1115 | "binaryName": "oxc-node", 1116 | "targets": [ 1117 | "x86_64-apple-darwin", 1118 | "aarch64-apple-darwin", 1119 | "x86_64-pc-windows-msvc", 1120 | "x86_64-unknown-linux-gnu", 1121 | "x86_64-unknown-freebsd", 1122 | "aarch64-linux-android", 1123 | "aarch64-unknown-linux-gnu", 1124 | "aarch64-unknown-linux-musl", 1125 | "aarch64-unknown-linux-ohos", 1126 | "aarch64-pc-windows-msvc", 1127 | "armv7-unknown-linux-gnueabihf", 1128 | "powerpc64le-unknown-linux-gnu", 1129 | "s390x-unknown-linux-gnu", 1130 | "x86_64-unknown-linux-musl", 1131 | "i686-pc-windows-msvc", 1132 | "armv7-linux-androideabi", 1133 | "wasm32-wasip1-threads" 1134 | ], 1135 | "wasm": { 1136 | "initialMemory": 16384, 1137 | "browser": { 1138 | "fs": false 1139 | } 1140 | } 1141 | } 1142 | } 1143 | --------------------------------------------------------------------------------