Skip to content

[js_repl] Support local ESM file imports#13437

Merged
aaronl-openai merged 9 commits intomainfrom
dev/aaronl/js-repl-local-import
Mar 5, 2026
Merged

[js_repl] Support local ESM file imports#13437
aaronl-openai merged 9 commits intomainfrom
dev/aaronl/js-repl-local-import

Conversation

@aaronl-openai
Copy link
Contributor

@aaronl-openai aaronl-openai commented Mar 4, 2026

Summary

  • add js_repl support for dynamic imports of relative and absolute local ESM .js / .mjs files
  • keep bare package imports on the native Node path and resolved from REPL-global search roots (CODEX_JS_REPL_NODE_MODULE_DIRS, then cwd), even when they originate from imported local files
  • restrict static imports inside imported local files to other local relative/absolute .js / .mjs files, and surface a clear error for unsupported top-level static imports in the REPL cell
  • run imported local files inside the REPL VM context so they can access codex.tmpDir, codex.tool, captured console, and Node-like import.meta helpers
  • reload local files between execs so later await import("./file.js") calls pick up edits and fixed failures, while preserving package/builtin caching and persistent top-level REPL bindings
  • make import.meta.resolve() self-consistent by allowing the returned file://... URLs to round-trip through await import(...)
  • update both public and injected js_repl docs to clarify the narrowed contract, including global bare-import resolution behavior for local absolute files

Testing

  • cargo test -p codex-core js_repl_
  • built codex binary and verified behavior

aaronl-openai and others added 2 commits March 3, 2026 23:18
Allow js_repl to import relative and absolute local .js/.mjs files while keeping package loading on the native path and documenting the ESM-only/local-static-import contract.

Co-authored-by: Codex <noreply@openai.com>
@aaronl-openai aaronl-openai requested a review from fjord-oai March 4, 2026 07:23
@aaronl-openai aaronl-openai marked this pull request as draft March 4, 2026 07:23
Copy link
Contributor

Choose a reason for hiding this comment

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

from my local codex conversation:

[P3] Top-level static local imports still fail with a low-level VM error. In kernel.js (line 1004) the cell linker returns importResolved(...); for file specifiers, that path (line 432) returns module.namespace, not a vm.Module. So import "./foo.js" still trips ERR_VM_MODULE_NOT_MODULE rather than a purposeful js_repl message.

Copy link
Contributor

Choose a reason for hiding this comment

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

codex also suggested:

I’d add one runtime test proving an imported local file can see REPL globals such as codex.tmpDir or captured console. That’s the behavior a future “simplify to native import” refactor is most likely to break.

Copy link
Contributor

@fjord-oai fjord-oai left a comment

Choose a reason for hiding this comment

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

lgtm after comments

aaronl-openai and others added 3 commits March 4, 2026 11:56
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
aaronl-openai and others added 4 commits March 4, 2026 20:43
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Make package results from import.meta.resolve() round-trip through the native
package loader, and align the public and injected js_repl docs with the
current local-file import behavior, VM-context semantics, and per-exec reload
rules.

Co-authored-by: Codex <noreply@openai.com>
Update the local-file ancestor node_modules test to use a dynamic bare import
so it actually covers the runtime search-root restriction instead of the
separate static-bare-import rejection path.

Co-authored-by: Codex <noreply@openai.com>
@aaronl-openai aaronl-openai changed the title Support js_repl local ESM file imports [js_repl] Support local ESM file imports Mar 5, 2026
@aaronl-openai aaronl-openai marked this pull request as ready for review March 5, 2026 06:19
@aaronl-openai aaronl-openai merged commit ff0341d into main Mar 5, 2026
31 checks passed
@aaronl-openai aaronl-openai deleted the dev/aaronl/js-repl-local-import branch March 5, 2026 06:40
@github-actions github-actions bot locked and limited conversation to collaborators Mar 5, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants