fix(packaging): ship dist/entry.js hub-daemon spawn target (#495) - #582
Open
bradrushworth wants to merge 1 commit into
Open
fix(packaging): ship dist/entry.js hub-daemon spawn target (#495)#582bradrushworth wants to merge 1 commit into
bradrushworth wants to merge 1 commit into
Conversation
The kanban CLI spawns the hub daemon from dist/entry.js, but the published package only ships dist/cli.js and dist/index.js. On a fresh install the spawn fails with: Error: Cannot find module '.../kanban/dist/entry.js' This crash-loops the hub daemon (~75 repetitions in hub-daemon.log), hangs the CLI on startup, and freezes the frontend before any task runs. The daemon implementation already ships inside the embedded @clinebot/core SDK, whose package.json exports map exposes it as the public subpath "@clinebot/core/hub/daemon-entry". This commit adds a third esbuild entry point (src/entry.ts -> dist/entry.js) that re-exports that entry, so the file ships in the tarball and no post-install patching is needed. The shim uses ESM import syntax (kanban package.json has "type": "module"); CommonJS require() throws ReferenceError in this context. The primary import uses the exports-mapped subpath because the deep path @clinebot/core/dist/hub/daemon/entry.js is blocked by the exports field. A __dirname-relative fallback covers environments that don't honor the exports map. Fixes cline#495
|
PR author is not in the allowed authors list. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
kanbanCLI spawns the hub daemon fromdist/entry.js, but the build only emitsdist/cli.jsanddist/index.js. On a fresh install, every spawn attempt crashes with:This crash-loops ~75 times on startup (see
hub-daemon.log), hanging the CLI and freezing the frontend. The real daemon implementation already ships inside the embedded@clinebot/coreSDK, whoseexportsmap exposes it as the public subpath@clinebot/core/hub/daemon-entry→./dist/hub/daemon/entry.js.Fixes #495.
Root cause
scripts/build.mjsbundles two entry points (src/cli.ts→dist/cli.js,src/index.ts→dist/index.js) but there is no third entry point for the hub daemon spawn target. The daemon spawn code (inlined from@clinebot/coreintodist/cli.js) resolves its own location relative to the package root and expectsdist/entry.jsto exist — but nothing builds it, so it's absent from the published tarball.The fix
Add
src/entry.tsas a thin re-export shim and a thirdesbuild.build()entry point inscripts/build.mjssodist/entry.jsis emitted and shipped in the tarball.Two non-obvious traps that the shim handles
ESM constraint: The
kanbanpackage declares"type": "module"(ESM). A CommonJS shim usingrequire()/module.exportsthrowsReferenceError: require is not defined in ES module scopewhen Node loads it. The shim must use ESMimport/exportsyntax.Exports-map gotcha: The deep path
@clinebot/core/dist/hub/daemon/entry.jsis blocked by theexportsfield in@clinebot/core/package.json. The shim uses the public exports-mapped subpath@clinebot/core/hub/daemon-entryas the primary import, with aimport.meta.url-relative fallback to the nested file for environments that don't honor the exports map.Changes
src/entry.ts(new): ESM re-export shim. Uses top-levelawait import("@clinebot/core/hub/daemon-entry")with a fallback that resolvesnode_modules/@clinebot/core/dist/hub/daemon/entry.jsrelative toimport.meta.url(since__dirnameis not defined in ESM). Exportsdefaultand re-exports all named exports.scripts/build.mjs: Add a thirdesbuild.build()entry point (src/entry.ts→dist/entry.js) to the existingPromise.all([...]), and update the completion log message.Verification
This shim was validated against a live v0.1.70 install before porting to the build pipeline:
node dist/entry.jsloads the core daemon module with noCannot find moduleerror.hub-daemon.loggoes to 0 bytes and stays clean — zeroCannot find module .../kanban/dist/entry.jsentries.Acceptance criteria
npm run build,dist/entry.jsexists.npm pack --dry-runlistsdist/entry.jsin the tarball (filesalready includesdist).npm install -g kanbanstarts the hub daemon cleanly with no manual patching.hub-daemon.logcontains zeroCannot find module .../kanban/dist/entry.jsentries.Out of scope
cli.jsspawn-target path (staysdist/entry.js).@clinebot/core'sexportsmap —@clinebot/core/hub/daemon-entryis the correct public entry.kanbanpackage packaging fix only; no runtime/workspace code changes beyond the new shim.