From 287ea33fdaa7db39724a9ccbc4487040c31ef4f4 Mon Sep 17 00:00:00 2001 From: Brendan Allan Date: Wed, 7 Oct 2026 20:38:04 +0800 Subject: [PATCH] fix(core): resolve Node-safe defaults for subpath imports --- packages/core/package.json | 10 +++++----- .../core/src/persistent-pty/binary.node.ts | 2 +- .../core/src/persistent-pty/binary.workerd.ts | 2 +- packages/sdk/script/verify-package.ts | 20 +++++++++++++++++++ packages/tui/package.json | 6 +++--- packages/util/package.json | 2 +- 6 files changed, 31 insertions(+), 11 deletions(-) diff --git a/packages/core/package.json b/packages/core/package.json index 55323f5f2c..405497fc26 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -40,31 +40,31 @@ "workerd": "./src/pty/pty.workerd.ts", "bun": "./src/pty/pty.bun.ts", "node": "./src/pty/pty.node.ts", - "default": "./src/pty/pty.bun.ts" + "default": "./src/pty/pty.node.ts" }, "#persistent-pty-binary": { "workerd": "./src/persistent-pty/binary.workerd.ts", "bun": "./src/persistent-pty/binary.bun.ts", "node": "./src/persistent-pty/binary.node.ts", - "default": "./src/persistent-pty/binary.bun.ts" + "default": "./src/persistent-pty/binary.node.ts" }, "#fff": { "workerd": "./src/filesystem/fff.workerd.ts", "bun": "./src/filesystem/fff.bun.ts", "node": "./src/filesystem/fff.node.ts", - "default": "./src/filesystem/fff.bun.ts" + "default": "./src/filesystem/fff.node.ts" }, "#photon-wasm": { "workerd": "./src/image/photon-wasm.workerd.ts", "bun": "./src/image/photon-wasm.bun.ts", "node": "./src/image/photon-wasm.node.ts", - "default": "./src/image/photon-wasm.bun.ts" + "default": "./src/image/photon-wasm.node.ts" }, "#shell-parser-wasm": { "workerd": "./src/shell/parser-wasm.workerd.ts", "bun": "./src/shell/parser-wasm.bun.ts", "node": "./src/shell/parser-wasm.node.ts", - "default": "./src/shell/parser-wasm.bun.ts" + "default": "./src/shell/parser-wasm.node.ts" }, "#v1-migration": { "types": "./src/database/v1-migration.bun.ts", diff --git a/packages/core/src/persistent-pty/binary.node.ts b/packages/core/src/persistent-pty/binary.node.ts index a9b17da0ae..70bde7f51c 100644 --- a/packages/core/src/persistent-pty/binary.node.ts +++ b/packages/core/src/persistent-pty/binary.node.ts @@ -1,6 +1,6 @@ // opencode-pty does not ship Windows binaries. export const available = process.platform !== "win32" -export async function resolveBinary() { +export async function resolveBinary(_bin: string) { return process.env.OPENCODE_PTY_BIN || "opencode-pty" } diff --git a/packages/core/src/persistent-pty/binary.workerd.ts b/packages/core/src/persistent-pty/binary.workerd.ts index 1fb21a1962..17ce4b9f7d 100644 --- a/packages/core/src/persistent-pty/binary.workerd.ts +++ b/packages/core/src/persistent-pty/binary.workerd.ts @@ -1,5 +1,5 @@ export const available = false -export async function resolveBinary(): Promise { +export async function resolveBinary(_bin: string): Promise { throw new Error("Persistent PTYs are unavailable in this runtime") } diff --git a/packages/sdk/script/verify-package.ts b/packages/sdk/script/verify-package.ts index 4d1b601114..d9bf1f52f0 100644 --- a/packages/sdk/script/verify-package.ts +++ b/packages/sdk/script/verify-package.ts @@ -201,6 +201,25 @@ for (const module of modules) { const api = module.OpenCode ?? module.OpenCodeWorkerd if (typeof api?.create !== "function") throw new Error("Packed SDK entrypoint is missing create()") } +`, + ), + Bun.write( + join(consumer, "imports-default.mjs"), + `import { registerHooks } from "node:module" + +// Hide the "node" condition from package subpath imports so Node resolves their +// "default" targets, as condition-less loaders and bundlers do. +registerHooks({ + resolve(specifier, context, nextResolve) { + if (!specifier.startsWith("#")) return nextResolve(specifier, context) + return nextResolve(specifier, { + ...context, + conditions: context.conditions.filter((condition) => condition !== "node"), + }) + }, +}) + +await import("./imports.mjs") `, ), ]) @@ -214,6 +233,7 @@ for (const module of modules) { } await $`bun imports.mjs`.cwd(consumer) await $`node imports.mjs`.cwd(consumer) + await $`node imports-default.mjs`.cwd(consumer) await $`bun --conditions=workerd imports.mjs`.cwd(consumer) await $`node_modules/.bin/wrangler deploy --dry-run --config wrangler.jsonc --outdir dist`.cwd(consumer) diff --git a/packages/tui/package.json b/packages/tui/package.json index 6ac4ec64d9..11fa362fdb 100644 --- a/packages/tui/package.json +++ b/packages/tui/package.json @@ -29,17 +29,17 @@ "#attention-sounds": { "bun": "./src/attention-sounds.bun.ts", "node": "./src/attention-sounds.node.ts", - "default": "./src/attention-sounds.bun.ts" + "default": "./src/attention-sounds.node.ts" }, "#string-width": { "bun": "./src/util/string-width.bun.ts", "node": "./src/util/string-width.node.ts", - "default": "./src/util/string-width.bun.ts" + "default": "./src/util/string-width.node.ts" }, "#zed-sqlite": { "bun": "./src/editor-zed-sqlite.bun.ts", "node": "./src/editor-zed-sqlite.node.ts", - "default": "./src/editor-zed-sqlite.bun.ts" + "default": "./src/editor-zed-sqlite.node.ts" }, "#runtime-plugin-support": { "bun": "./src/plugin/runtime-plugin-support.bun.ts", diff --git a/packages/util/package.json b/packages/util/package.json index bddfa54213..651df056a7 100644 --- a/packages/util/package.json +++ b/packages/util/package.json @@ -28,7 +28,7 @@ "workerd": "./src/runtime/import.workerd.ts", "bun": "./src/runtime/import.bun.ts", "node": "./src/runtime/import.node.ts", - "default": "./src/runtime/import.bun.ts" + "default": "./src/runtime/import.node.ts" } }, "scripts": {