chore: drop #/ import array fallbacks and custom resolution plugins#1594
Conversation
Replace the "#/*": ["./src/*.ts", "./src/*/index.ts"] array fallback in
every package's imports field with a single "./src/*.ts" target plus
explicit entries for directory-style imports (agent-core, kimi-code).
Directory-style #/foo imports now resolve through Node's standard
single-target subpath imports, so the custom resolution workarounds are
no longer needed:
- delete build/hash-imports-{loader,plugin,register-loader}.mjs
- remove the inlined hashImportsPlugin from the agent-core-v2,
kap-server, server-e2e and klient vitest configs
- remove hashImportsPlugin from both kimi-code tsdown configs
- drop register-hash-imports-loader.mjs from the dev:kap-server script
|
…t-fallbacks # Conflicts: # apps/kimi-code/package.json
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 04c07dbdec
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| "./src/*/index.ts", | ||
| "./src/*.d.ts" | ||
| ] | ||
| "#/*": "./src/*.ts" |
There was a problem hiding this comment.
Keep the declaration fallback for the generated vis asset
In a clean checkout, apps/kimi-code/src/generated/vis-web-asset.ts does not exist; only vis-web-asset.d.ts is checked in, and src/cli/sub/vis.ts imports #/generated/vis-web-asset. With this import map now resolving #/* only to ./src/*.ts, TypeScript treats that import as missing until scripts/build-vis-asset.mjs has been run, but CI typechecks apps/kimi-code/tsconfig.json directly before the app prebuild. Please keep an explicit declaration target for #/generated/vis-web-asset or restore the .d.ts fallback so source-only typecheck/tests still work.
Useful? React with 👍 / 👎.
commit: |
src/generated/vis-web-asset.ts is gitignored and only produced by the prebuild; on a fresh checkout (where CI typechecks before any build) only the committed vis-web-asset.d.ts exists. Map the exact specifier to ["./src/generated/vis-web-asset.ts", "./src/generated/vis-web-asset.d.ts"] so runtime/bundlers take the first entry (.ts) while TypeScript falls back to the declaration stub when the generated file is absent.
Related Issue
No linked issue — build tooling cleanup.
Problem
Every package declared its
#/*subpath import as an array fallback:tsx, Vite/vitest and tsdown only honor the first array element, so directory-style#/fooimports (src/foo/index.ts) broke outside of plain Node. The repo worked around this with three custom resolution shims:build/hash-imports-loader.mjs(+ register file) injected intodev:kap-serverbuild/hash-imports-plugin.mjsused by both kimi-code tsdown configshashImportsPlugincopy-pasted into the agent-core-v2, kap-server, server-e2e and klient vitest configsEach shim resolved
#/imports by hand against the importer's package root — ~370 lines of duplicated resolution logic that had to be kept in sync with every package'simportsfield.What changed
"#/*": "./src/*.ts"target in all 17 packages/apps that used it. Single-target subpath imports are honored natively by Node, tsx, Vite and tsdown, so the shims are no longer needed and are deleted.#/fooimports now get explicit entries instead of relying on the array fallback:packages/agent-coredeclares its 15 directory barrels (#/agent,#/flags, …), andapps/kimi-codeadds#/tui/commandsnext to the existing#/tui/theme. All other packages only import#/x/ypaths that map to real.tsfiles, so no explicit entries are needed there (verified programmatically: all 870 distinct#/import specifiers in the repo resolve to an existing file under the new mappings).hashImportsPluginfromtsdown.config.ts/tsdown.native.config.ts, from the four vitest configs that inlined it, and droppedregister-hash-imports-loader.mjsfrom thedev:kap-serverscript.Verified:
pnpm run typecheck(all packages + apps),pnpm run lint, fullpnpm run test(13659 passed; the handful of failures reproduce identically on cleanmainor pass in isolation), both tsdown builds, and atsxsmoke test of thedev:kap-serverresolution path.Checklist
gen-changesetsskill, or this PR needs no changeset. (No changeset — build/dev tooling only, no runtime behavior change.)gen-docsskill, or this PR needs no doc update. (Internal tooling only.)