Skip to content

chore: drop #/ import array fallbacks and custom resolution plugins#1594

Merged
kermanx merged 3 commits into
mainfrom
chore/drop-hash-import-fallbacks
Jul 13, 2026
Merged

chore: drop #/ import array fallbacks and custom resolution plugins#1594
kermanx merged 3 commits into
mainfrom
chore/drop-hash-import-fallbacks

Conversation

@kermanx

@kermanx kermanx commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue — build tooling cleanup.

Problem

Every package declared its #/* subpath import as an array fallback:

"#/*": ["./src/*.ts", "./src/*/index.ts"]

tsx, Vite/vitest and tsdown only honor the first array element, so directory-style #/foo imports (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 into dev:kap-server
  • build/hash-imports-plugin.mjs used by both kimi-code tsdown configs
  • an inlined hashImportsPlugin copy-pasted into the agent-core-v2, kap-server, server-e2e and klient vitest configs

Each 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's imports field.

What changed

  • Replaced the array fallback with a single "#/*": "./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.
  • Directory-style #/foo imports now get explicit entries instead of relying on the array fallback: packages/agent-core declares its 15 directory barrels (#/agent, #/flags, …), and apps/kimi-code adds #/tui/commands next to the existing #/tui/theme. All other packages only import #/x/y paths that map to real .ts files, 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).
  • Removed hashImportsPlugin from tsdown.config.ts / tsdown.native.config.ts, from the four vitest configs that inlined it, and dropped register-hash-imports-loader.mjs from the dev:kap-server script.

Verified: pnpm run typecheck (all packages + apps), pnpm run lint, full pnpm run test (13659 passed; the handful of failures reproduce identically on clean main or pass in isolation), both tsdown builds, and a tsx smoke test of the dev:kap-server resolution path.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works. (Resolution config change — covered by existing typecheck/tests/builds.)
  • Ran gen-changesets skill, or this PR needs no changeset. (No changeset — build/dev tooling only, no runtime behavior change.)
  • Ran gen-docs skill, or this PR needs no doc update. (Internal tooling only.)

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
@changeset-bot

changeset-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 733ec5d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

…t-fallbacks

# Conflicts:
#	apps/kimi-code/package.json

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

@pkg-pr-new

pkg-pr-new Bot commented Jul 13, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@733ec5d
npx https://pkg.pr.new/@moonshot-ai/kimi-code@733ec5d

commit: 733ec5d

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.
@kermanx

kermanx commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator Author

@codex

@kermanx kermanx merged commit bc8eb1e into main Jul 13, 2026
10 checks passed
@kermanx kermanx deleted the chore/drop-hash-import-fallbacks branch July 13, 2026 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant