Skip to content

feat(core): add @oxc-node/core/importer, a jiti-shaped TypeScript importer - #870

Merged
Brooooooklyn merged 22 commits into
mainfrom
feat/programmatic-import
Oct 20, 2026
Merged

Brooooooklyn merged 22 commits into
mainfrom
feat/programmatic-import

Conversation

@Brooooooklyn

Copy link
Copy Markdown
Member

Fixes #173

A tool can import a user's TypeScript file (e.g. eslint.config.ts) without registering hooks for the whole process. Same API shape and behaviour as jiti v2:

import { createImporter } from "@oxc-node/core/importer";
const importer = createImporter(import.meta.url, { moduleCache: false });
const config = await importer.import("./eslint.config.ts", { default: true });

How it works

import(id) → createResolve (oxc resolver, tsconfig paths)
   ├─ builtin / @oxc-node/core helper / JS in node_modules → native import()/require()
   ├─ .json / .node → loaded directly
   └─ user file → transformModuleRunner (load-hook transform + oxc ModuleRunnerTransform)
                  → vm (own module map; never in Module._cache)
        ├─ ESM: __vite_ssr_import__ … calls into the importer
        ├─ CJS: new Module(), own require()
        └─ require() of ESM → sync form; TLA → ERR_REQUIRE_ASYNC_MODULE
  • Nothing global: no hooks, no require.extensions, nothing in require.cache, process.sourceMapsEnabled untouched.
  • moduleCache: false re-runs user files per import(); interopDefault and { default: true } match jiti.
  • Output lines keep their source line numbers (like Babel's retainLines, which jiti uses), and errors escaping import() get columns mapped through the source map, with no global switch.

Rust

  • New napi export transformModuleRunner(path, source, sync?) -> { code, map, esm, topLevelAwait }. The runner flag is a real argument through oxc_transform/transform_program; existing callers pass None, so their output is unchanged.

Tests

  • jiti parity suite (64 checks, from ESM and CJS hosts): 64/64 on Node 22.18, 24.12 and 24.22. jiti 2.7 itself gets 57/64.
  • 19 extra probes: stack lines, .cts requiring ESM .ts, cycles (including parallel ones), live bindings, export * conflicts, retry after failure, memory bound with moduleCache: false, no global leaks.
  • A cargo unit test for the transform.
  • vp run test: 546 passed, 7 skipped.

Differences from jiti

  • Async import() only (no sync jiti(), alias, fsCache, transformOptions).
  • The returned module is a plain object, not a real namespace (jiti is the same).
  • import() inside eval/new Function falls back to Node's loader (no TS), and Node may print an experimental warning once.

🤖 Generated with Claude Code

…orter (#173)

`createImporter(parentId, { moduleCache, interopDefault })` with
`.import(id, { default, parentURL, conditions, try })` and `.resolve()`,
the same shape and behaviour as jiti v2.

It runs modules itself instead of through Node's loader: files are
resolved with the oxc-node resolver, transformed by the new
`transformModuleRunner` binding (the load hook's transform followed by
oxc's module runner transform) and evaluated with `vm`. Nothing global is
installed, so the host's own import() and require() stay as they are.

Fixes #173

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-20T13:22:29.230685Z 1b4020c New commits
ℹ️ About Codex in GitHub

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

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

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: aacc617079

ℹ️ About Codex in GitHub

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

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/importer.mjs Resolved
Comment thread packages/core/importer.mjs Resolved
Comment thread packages/core/importer.mjs Resolved
Brooooooklyn and others added 2 commits October 20, 2026 16:30
…rted

`reexport-oxc-runtime.mjs` rewrites `exports` from a fixed list on CI and
before publish, which dropped `./importer`.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…ith the import conditions

- An ES module with top-level await in its static graph, loaded by
  import() first, now fails require() with ERR_REQUIRE_ASYNC_MODULE, as
  Node.js does, instead of handing back the cached namespace.
- A package path exported only under `require` (or other conditions than
  the ones in use) now fails import with ERR_PACKAGE_PATH_NOT_EXPORTED and
  Node's message, instead of ERR_MODULE_NOT_FOUND.
- Docs: `default: true` is `mod.default ?? mod`, as in jiti.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

… literal

On Windows the folder path has backslashes, which read as escapes inside the
quoted key, so the module counted under another key and the cache checks saw
no runs.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 57c49d80e0

ℹ️ About Codex in GitHub

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

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/importer.mjs Resolved
Comment thread packages/core/importer.mjs Resolved
Comment thread packages/core/importer.mjs Resolved
…-level await

A static import that Node.js loads itself made no record, so a module
importing a node_modules package with top-level await was not marked async
and a later require() of it got the cached namespace. Node.js' own require()
of the loaded package now tells, as it throws ERR_REQUIRE_ASYNC_MODULE.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4eb07efb4f

ℹ️ About Codex in GitHub

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

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/lib.rs Resolved
…rter

oxc's module runner transform pops the namespace specifier and drops the
default one, so `a` was left unbound (ReferenceError). Split the declaration
into `import a from "x"; import * as b from "x";` before the transform.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 50445537d2

ℹ️ About Codex in GitHub

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

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/importer.mjs Resolved
They sat in one process-wide map, so a `moduleCache: false` importer that
loads new files every time kept every file's map forever. Each module map
now has its own, which goes when the graph goes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4115642d08

ℹ️ About Codex in GitHub

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

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/importer.mjs Resolved
Comment thread packages/core/importer.mjs Resolved
Brooooooklyn and others added 2 commits October 20, 2026 17:20
The mark came only after the dependency finished, so a require() of the
module while it still waited on the dependency's top-level await got the
partly filled namespace. The dependency's record knows about its own await
as soon as the import starts, so the mark is set then.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
A module that throws leaves the cache so that it is tried again, but its
source map, decoded to map the error's stack, stayed. Maps of modules no
longer in the cache are dropped once the error has used them.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 304dd9ea59

ℹ️ About Codex in GitHub

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

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/importer.mjs Resolved
Comment thread packages/core/importer.mjs Resolved
Comment thread packages/core/importer.mjs Resolved
Dropping the maps of failed modules only when an error left import() missed
failures caught inside a runner file. A failed module's map now moves from
the module map to its error, for the stack, and goes when the error does.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 93297308f6

ℹ️ About Codex in GitHub

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

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/importer.mjs Resolved
Comment thread packages/core/importer.mjs Resolved
`require.resolve.paths()` in a CommonJS runner file threw a TypeError. It now
returns the folders Node.js would look in, as Node's own does.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 41d2cc2dc2

ℹ️ About Codex in GitHub

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

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/importer.mjs Resolved
`memory-failed-new-files` decoded 220 source maps of 1200 lines to map each
error's stack, which ran past the 5 s probe limit on a macOS runner. The
failure probes now load 120 files of 600 lines, and the memory probes get
30 s. Each still fails on the code before its fix.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

…, as jiti does

- An import inside a runner file of CommonJS marked `__esModule` (Babel and
  tsc output) gets `exports.default` as its default, as jiti's transformed
  files do. The module `import()` returns stays as Node.js gives it, and
  `default: true` reads through the interop, so a function default is
  unwrapped, as in jiti.
- `__dirname`, `__filename` and `require` exist in ES module files, as in
  jiti, from an outer function so that a module declaring its own still
  works.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e9f0e4e8e3

ℹ️ About Codex in GitHub

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

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/importer.mjs Resolved
Comment thread packages/core/importer.mjs Resolved
Comment thread packages/core/importer.mjs Resolved
Brooooooklyn and others added 2 commits October 20, 2026 18:13
Babel and tsc define `__esModule` hidden, so it was left out of the
namespace of a CommonJS file the runner evaluates, and jiti's interop never
unwrapped its function default. Node.js' own CommonJS import exports it, so
the runner does too. Seen with OXC_TRANSFORM_ALL, where node_modules files
run in the runner.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…resolve options

- The `__esModule` interop also unwrapped the default of a real ES module
  Node.js loaded. Node.js' CommonJS sits in `require.cache` with its own
  exports, which tells the two apart on every supported version.
- `require.resolve(id, { paths })` in a runner file dropped the options; with
  them it is Node.js' own lookup.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 862951b8c0

ℹ️ About Codex in GitHub

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

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/importer.mjs Resolved
Comment thread packages/core/importer.mjs Resolved
- A named export defined with `Object.defineProperty(exports, "a", { value })`
  is hidden from Object.keys(), so `import { a }` of a runner CommonJS file
  got undefined. An exports object's hidden properties now count, as Node.js'
  CommonJS import finds them; a function's or an array's still do not.
- The runner's `require` has `main`, as Node.js' own does.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a29d075176

ℹ️ About Codex in GitHub

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

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/importer.mjs Resolved
A `file:` specifier that names no file kept no URL on its not-found error,
so `import.meta.resolve()` threw where Node.js returns the URL. The error
also names the path now, as Node's does.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cf02f91df3

ℹ️ About Codex in GitHub

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

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/importer.mjs Resolved
Comment thread packages/core/importer.mjs Resolved
…URLs

- A `data:` URL (or another non-file URL) resolved to nothing and failed as
  not found; it is now Node.js' to load, as `import()` and
  `import.meta.resolve()` do natively.
- `file:///a` has no path on Windows, where fileURLToPath() throws. Such a
  URL now fails as not found, and `import.meta.resolve()` returns it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 318eb9fc60

ℹ️ About Codex in GitHub

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

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/importer.mjs Resolved
Comment thread packages/core/importer.mjs Resolved
Where Node.js has `import.meta.main`, an imported module sees `false`; the
runner's `import.meta` left it out.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b341a8efe2

ℹ️ About Codex in GitHub

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

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/importer.mjs Resolved
Comment thread packages/core/importer.mjs Resolved
…resolve specifiers

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: acec2ba181

ℹ️ About Codex in GitHub

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

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/importer.mjs Resolved
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 61c82e3890

ℹ️ About Codex in GitHub

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

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/importer.mjs Resolved
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1b4020ce74

ℹ️ About Codex in GitHub

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

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/importer.mjs Resolved
Comment thread packages/core/importer.mjs Resolved
@Brooooooklyn
Brooooooklyn merged commit 77befcb into main Oct 20, 2026
67 checks passed
@Brooooooklyn
Brooooooklyn deleted the feat/programmatic-import branch October 20, 2026 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

js import function for dynamic ts support

1 participant