11---
22title : bunx kitcn self-resolution must not break scaffold codegen
33date : 2026-04-07
4- last_updated : 2026-04-07
4+ last_updated : 2026-04-11
55category : integration-issues
66module : cli-codegen
77problem_type : integration_issue
@@ -49,6 +49,8 @@ The failing files were the stock scaffold backend demo files, not user code.
4949- relying on source-level cache-path tests alone; the published bundled
5050 ` backend-core ` artifact can still miss a direct-import rewrite that never
5151 shows up in the raw TypeScript path
52+ - relying on entry-file rewrites alone; Bun-native imports can bypass Jiti
53+ aliases for transitive files like the generated server placeholder
5254- treating local deployment detection as only ` local:* ` or ` anonymous:* ` ; plain
5355 ` anonymous-agent ` now shows up too
5456
@@ -59,10 +61,12 @@ Patch the loader seam, not each scaffold file:
59611 . create a project-aware ` jiti ` helper for CLI parsing
60622 . alias ` kitcn/server ` to a tiny parser shim so scaffold parsing does not need
6163 the real runtime package graph during bootstrap
62- 3 . rewrite direct ` from "kitcn/server" ` imports to the project shim path before
64+ 3 . force ` tryNative: false ` so Bun never takes over parse-time project imports
65+ and skips the Jiti alias table for transitive files
66+ 4 . rewrite direct ` from "kitcn/server" ` imports to the project shim path before
6367 the bundled parser imports the module
64- 4 . keep local ` convex ` export aliases so project-local resolution still works
65- 5 . treat plain ` anonymous-agent ` as a local deployment and preserve
68+ 5 . keep local ` convex ` export aliases so project-local resolution still works
69+ 6 . treat plain ` anonymous-agent ` as a local deployment and preserve
6670 ` CONVEX_AGENT_MODE=anonymous ` in ` dev `
6771
6872## Why This Works
@@ -77,9 +81,15 @@ install-cache copy of `kitcn`, which then re-entered `dist/api-entry-*.js` and
7781crashed on ` convex/server ` even though the generated app had already installed
7882the right dependencies.
7983
80- Rewriting direct ` kitcn/server ` imports to the absolute project shim path
81- removes bare-specifier resolution from that parse step, so the bundled parser
82- never falls back to the Bun cache copy.
84+ The missing piece was Bun-native import. ` createProjectJiti ` still allowed
85+ ` tryNative ` , so the entry module could be rewritten but transitive files were
86+ still imported by Bun directly. Once Bun owned that transitive import chain,
87+ Jiti aliases no longer applied, and the generated server placeholder could fall
88+ back to the packaged ` kitcn/server ` bundle in Bun's temp install cache.
89+
90+ Turning native import off keeps parse-time project modules inside Jiti end to
91+ end. That makes the project shim and local package aliases apply to the whole
92+ import graph instead of only the root file.
8393
8494The ` anonymous-agent ` follow-up bug was separate but adjacent: local deployment
8595classification missed the plain ` anonymous-agent ` value, so ` dev ` failed to
@@ -89,8 +99,12 @@ carry the anonymous mode back into Convex subprocesses.
8999
90100- When a CLI package parses scaffolded project files during bootstrap, do not
91101 assume package self-resolution points at the new app install
102+ - Do not rely on Bun-native import for parse-time project modules when aliasing
103+ or shim rewrites are part of the contract
92104- For Bun-specific bootstrap bugs, verify both the source path and the packed
93105 artifact path; source tests alone can miss a bundled regression
106+ - Lock the Jiti helper itself so packed builds cannot silently re-enable native
107+ import
94108- Add a packed-artifact regression whenever the real bug only reproduces from
95109 ` bunx ` or another published-package entry point
96110- Treat local deployment-name formats as compatibility inputs; upstream CLI
0 commit comments