diff --git a/package.json b/package.json index ec247e293a..d516491331 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ ".": "./dist/agent/dsh-native.js", "./server": "./dist/agent/opencode-native.js", "./dsh": "./dist/agent/dsh-native.js", + "./package.json": "./package.json", "./dsh/package.json": "./package.json", "./client": "./dist/agent/dsh-native-client.js" }, diff --git a/src/launcher.ts b/src/launcher.ts index 14496d7d1b..0c7af1b770 100644 --- a/src/launcher.ts +++ b/src/launcher.ts @@ -2989,7 +2989,7 @@ export function writeDshClientShimFiles(shimDir: string, hostBundle: string, cli name: "billion-context", version, type: "module", - exports: { ".": "./index.js", "./dsh": "./index.js", "./dsh/package.json": "./package.json", "./client": "./bundle.js" }, + exports: { ".": "./index.js", "./dsh": "./index.js", "./package.json": "./package.json", "./dsh/package.json": "./package.json", "./client": "./bundle.js" }, dsh: { client: { platform: "web" } }, })}\n`, ); diff --git a/tests/dsh-settings-ui.test.ts b/tests/dsh-settings-ui.test.ts index 51d0ca724a..3fd6ef7a78 100644 --- a/tests/dsh-settings-ui.test.ts +++ b/tests/dsh-settings-ui.test.ts @@ -962,6 +962,18 @@ test("#2125: the manifest declares no dsh.client.inject (pre-0.2 dsh compat)", ( assert.equal(pkg.dsh?.client?.inject ?? null, null, "dsh.client.inject would break pre-0.2 dsh clients"); }); +test("#3043: the published manifest exposes ./package.json so dsh's client scanner can locate the package root", () => { + const pkg = JSON.parse(fs.readFileSync(new URL("../package.json", import.meta.url), "utf8")) as { + exports?: Record; + }; + // Node's `exports` map is closed once declared — an unlisted subpath throws + // ERR_PACKAGE_PATH_NOT_EXPORTED. dsh's client scanner resolves + // "/package.json" to find the package root before reading dsh.client; + // the self-mapping below looks redundant but is load-bearing: drop it and + // the scanner swallows the throw, so the browser half never registers. + assert.equal(pkg.exports?.["./package.json"], "./package.json"); +}); + test("#2448: embed face adapts the data tables to a narrow host panel (CSS pins)", () => { // The embed iframe lives inside a dsh settings column (400-760px), not a // browser tab — the standalone-page table floors (940px/520px + fixed diff --git a/tests/launcher.test.ts b/tests/launcher.test.ts index 67262b5154..0876d8b003 100644 --- a/tests/launcher.test.ts +++ b/tests/launcher.test.ts @@ -9,6 +9,7 @@ type SymlinkKind = "dir" | "file" | "junction"; import net from "node:net"; import os from "node:os"; import path from "node:path"; +import { createRequire } from "node:module"; import { claimStartingMarker, readStartingMarker, @@ -3722,7 +3723,7 @@ test("writeDshClientShimFiles + dshPluginEntry: resolvable shim yields the bare assert.equal(writeDshClientShimFiles(shimDir, hostBundle, clientBundle, "0.1.169"), true); const shimPkg = JSON.parse(fs.readFileSync(path.join(shimDir, "package.json"), "utf8")); assert.equal(shimPkg.name, "billion-context"); - assert.deepEqual(shimPkg.exports, { ".": "./index.js", "./dsh": "./index.js", "./dsh/package.json": "./package.json", "./client": "./bundle.js" }); + assert.deepEqual(shimPkg.exports, { ".": "./index.js", "./dsh": "./index.js", "./package.json": "./package.json", "./dsh/package.json": "./package.json", "./client": "./bundle.js" }); assert.equal(shimPkg.dsh.client.platform, "web"); // The bundles are SYMLINKS into bili's live dist — an auto-update that // moves dist self-heals on the next launch without rewriting the shim. @@ -3733,6 +3734,14 @@ test("writeDshClientShimFiles + dshPluginEntry: resolvable shim yields the bare // lands on the host module itself ⇒ the bare entry. assert.equal(dshPluginEntry(home), "billion-context"); + // #3043: dsh's client scanner locates the package root via + // require.resolve("billion-context/package.json") before reading dsh.client. + // Node's closed `exports` map throws ERR_PACKAGE_PATH_NOT_EXPORTED for any + // unlisted subpath — omit "./package.json" here (as in the published pkg) + // and the scanner swallows the throw, so the browser half never registers. + const shimRequire = createRequire(path.join(home, "probe.cjs")); + assert.equal(shimRequire.resolve("billion-context/package.json"), path.join(shimDir, "package.json")); + // A shim whose root "." export points elsewhere (e.g. a real install // whose root is the CLI entry, not the dsh host half) must NOT claim // the bare lane: importing the root would boot the CLI inside dsh.