Fix declaration chunk imports referencing non-existent .js files - #76
Merged
Conversation
rolldown-plugin-dts writes the relative imports between declaration chunks with a `.js` extension (mirroring the JS module graph). But the declaration chunks are content-hashed independently from the JS chunks, so the referenced `./Foo-<dtsHash>.js` never exists on disk — only `./Foo-<dtsHash>.d.ts` does, because the JS chunk carries a different hash. Served over HTTP, the editor's LSP fetches the literal `.js` specifier, 404s, and type resolution breaks for any code-split subpath. The specifier already carries the declaration chunk's own basename and hash; only the extension is wrong. Swap `.js` -> `.d.ts` on relative specifiers in emitted `.d.ts` chunks so every type import resolves to a real file. Bare specifiers (e.g. @studiometa/js-toolkit/utils) are left untouched. Co-authored-by: Claude <claude@anthropic.com> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Botz34NmFLdgRgm2QJpKkZ
Co-authored-by: Claude <claude@anthropic.com> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Botz34NmFLdgRgm2QJpKkZ
|
Size Change: +543 B (+1.01%) Total Size: 54.1 kB 📦 View Changed
ℹ️ View Unchanged
|
Deploying studiometa-playground with
|
| Latest commit: |
dfef01c
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://a49db5fd.studiometa-playground.pages.dev |
| Branch Preview URL: | https://fix-dts-chunk-import-extensi.studiometa-playground.pages.dev |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #76 +/- ##
==========================================
+ Coverage 33.95% 34.12% +0.17%
==========================================
Files 55 55
Lines 1128 1131 +3
Branches 230 231 +1
==========================================
+ Hits 383 386 +3
Misses 717 717
Partials 28 28
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Problem
When a self-hosted dependency code-splits, its emitted declaration files reference type chunks that don't exist on disk, so the editor's LSP fails to resolve types.
rolldown-plugin-dts writes the relative imports between declaration chunks with a
.jsextension (mirroring the JS module graph — the on-disk convention where./foo.jsresolves to a sibling./foo.d.ts). But the declaration chunks are content-hashed independently from the JS chunks. So for@studiometa/ui:Action-Bt0NVlQH.jsnever exists. Served over HTTP the LSP fetches that literal URL, 404s, and type resolution breaks for every code-split subpath.Fix
The specifier already carries the declaration chunk's own basename + hash — only the extension is wrong. In
emitBundleChunks, rewrite relative.jsspecifiers to.d.tsinside emitted.d.tschunks (from "./x.js",import("./x.js"),export … from "./x.js"). Bare specifiers (@studiometa/js-toolkit/utils) and the JS chunks themselves are untouched.Verified against a real
@studiometa/uimulti-entry build: before, 4 relative type imports pointed at non-existent.jsfiles; after, all 4 resolve to existing.d.tschunks.Tests
./Foo-<hash>.js(static, re-export, and dynamicimport()) is emitted with.d.ts; no relative.jsspecifier remains; bare specifiers and the JS entry are unchanged.Release
Bugfix — would ship as 0.3.13. Not published here.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Botz34NmFLdgRgm2QJpKkZ