Repository navigation
feat(codemode): let an extension name the modules that load its globals - #64516
Conversation
There was a problem hiding this comment.
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.
a034635 to
beb4a0d
Compare
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Issue for this PR
Closes #
Type of change
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:modulesmaps 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.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?
packages/codemode/test/extensions.test.ts:import,requireandimport()load the global; a run without the extension can't import it; and the later of two extensions claiming a name wins.bun testandbun run test:roundtripinpackages/codemode, andbun run checkfrom the root, pass.Screenshots / recordings
N/A
Checklist
Added by the opencode bot (AI-generated).
Public API: adds optional
modulesto codemode's Extension.make and Runtime.make options (backwards compatible)