Skip to content

feat(codemode): let an extension name the modules that load its globals - #64516

Merged
rekram1-node merged 3 commits into
devfrom
codemode-bun-import
Nov 17, 2026
Merged

rekram1-node merged 3 commits into
devfrom
codemode-bun-import

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Issue for this PR

Closes #

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Lets an extension name the modules that load its globals, so a host can make import ... from "bun" work without Code Mode knowing about Bun:

Extension.make({ name: "bun", globals: { Bun }, modules: { bun: "Bun" } })
import { file } from "bun"   // the Bun global, in runs that get this extension
const { Glob } = require("bun")
  • modules maps a module name to one of the extension's own globals (the type only allows those). When two extensions claim the same name, the later one wins.
  • Each run only gets the module names of the extensions it gets, so a run without the extension still fails with "Cannot import".
  • The language runtime takes the same map (Runtime.make({ modules })) and checks it after a global's own name and before the built-in Node names (fs/promises, url, ...).

Nothing registers a module name yet; core's Bun extension will.

How did you verify your code works?

  • New tests in packages/codemode/test/extensions.test.ts: import, require and import() load the global; a run without the extension can't import it; and the later of two extensions claiming a name wins.
  • bun test and bun run test:roundtrip in packages/codemode, and bun run check from the root, pass.

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Added by the opencode bot (AI-generated).

Public API: adds optional modules to codemode's Extension.make and Runtime.make options (backwards compatible)

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good. On the base, import ... from "bun" fails with Cannot import "bun"; with this change, import and require of "bun" both return the host's Bun global, and without a Bun global the import still fails as before. The full packages/codemode test suite and tsc --noEmit pass.

Public API: no SDK, server, plugin, config or CLI changes. Programs gain one module name, bun, which only resolves when the host provides a Bun global, so this is backwards compatible.

No concerns.

@rekram1-node rekram1-node changed the title feat(codemode): load the Bun global with import from "bun" feat(codemode): let an extension name the modules that load its globals Nov 17, 2026

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good. I raised no concerns last time, so there was nothing to address. The new extension-level modules map works as described: a declared module name loads the extension's global through import, require and import(), only in runs that get that extension. A name pointing at a missing global, or claimed by two extensions, is rejected. Restored runs rebuild the module map from the setup. bun test, bun run test:roundtrip and tsc --noEmit in packages/codemode pass.

Public API: adds the optional modules field to Extension.make / Extension and to Runtime.make options. Existing extensions and runtimes are unaffected, so this is backwards compatible.

No concerns.

@rekram1-node
rekram1-node enabled auto-merge (squash) November 17, 2026 22:54
@rekram1-node
rekram1-node merged commit 9cfff5f into dev Nov 17, 2026
12 checks passed
@rekram1-node
rekram1-node deleted the codemode-bun-import branch November 17, 2026 22:59

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good. I had no earlier concerns to address. With the runtime checks gone, the type limits module names to the extension's own globals, and a name pointing at a missing global just fails the import with "Cannot import". The new test confirms a later extension's module name wins. bun test and tsc --noEmit in packages/codemode pass. test:roundtrip passes except for an unrelated call-depth test that timed out on this slow machine and passes on its own.

Public API: adds the optional modules field to Extension.make / Extension and to Runtime.make options, so it is backwards compatible. Compared with the previous commit, a module name claimed by two extensions or pointing at an unknown global no longer throws.

No concerns.

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.

1 participant