fix: rewrite local declare module specifiers to output chunk paths#191
Open
igordanchenko wants to merge 1 commit into
Open
fix: rewrite local declare module specifiers to output chunk paths#191igordanchenko wants to merge 1 commit into
declare module specifiers to output chunk paths#191igordanchenko wants to merge 1 commit into
Conversation
188c4a4 to
96dbcc7
Compare
96dbcc7 to
90b2fba
Compare
This was referenced Mar 29, 2026
90b2fba to
ca48c6f
Compare
prisis
added a commit
to visulima/packem
that referenced
this pull request
Apr 23, 2026
Port upstream v0.23.0..main improvements to avoid identifier collisions and surface parser failures with actionable errors. Also adds the missing test coverage for the already-applied relative `declare module` rewriter. - Wrap parse() calls in fake-js.ts with try/catch so syntax errors in declaration files report the failing id instead of a bare babel stack (upstream sxzz/rolldown-plugin-dts@f8b8003). - Prefix namespace import identifiers with `_$` to prevent collisions with real identifiers in the bundled .d.ts output (upstream sxzz/rolldown-plugin-dts@aeae198). - Add fixtures + test for cross-chunk `declare module './foo.js'` specifier rewriting to exercise the placeholder mechanism already present locally (upstream sxzz/rolldown-plugin-dts#191). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
prisis
pushed a commit
to visulima/packem
that referenced
this pull request
Apr 23, 2026
…n\n## @visulima/rollup-plugin-dts [1.0.0-alpha.12](https://github.com/visulima/packem/compare/@visulima/rollup-plugin-dts@1.0.0-alpha.11...@visulima/rollup-plugin-dts@1.0.0-alpha.12) (2026-04-23) ### Bug Fixes * **rollup-plugin-dts:** sync fixes from upstream rolldown-plugin-dts ([449794f](449794f)), closes [sxzz/rolldown-plugin-dts#191](sxzz/rolldown-plugin-dts#191) ### Miscellaneous Chores * **rollup-plugin-dts:** restore isolatedDeclarationTransformer in build config ([46d54f4](46d54f4))
e355f38 to
6affa5a
Compare
ca48c6f to
0642ca6
Compare
…xzz#134) When `declare module './foo.js'` references a local file, the specifier was preserved as-is in bundled output, making it unreachable for consumers. Now resolves local module targets and rewrites specifiers to point to the correct output chunk.
0642ca6 to
6008746
Compare
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.
Description
When
declare module './foo.js'ordeclare module '@/foo.js'references a local file, the specifier was preserved as-is in the bundled.d.tsoutput. This made the augmentation unreachable for consumers since the internal path no longer resolves after bundling.Now resolves local
declare moduletargets and rewrites their specifiers to the relative path of the output chunk containing the target module.How it works
transform- resolves alldeclare modulestring literal specifiers usingthis.resolve(). If the target is a local (non-external) module, stores the resolved module ID in the declaration metadata.renderChunk- replaces resolved specifiers with an internal placeholder.generateBundle- builds a module-to-chunk mapping and rewrites placeholders to the correct relative path between output chunks.This approach works for both same-chunk (self-referencing) and cross-chunk augmentations, as well as tsconfig path aliases like
@/foo.js.Test plan
declare moduletest (ambientdeclare module 'virtual') still passes unchangedLinked Issues
Fixes #134
Additional context
While the original ticket #134 mentions same-chunk references being replaced with
declare module '.', I couldn't get that working with TypeScript. This PR rewrites same-chunk specifiers asdeclare module './current-chunk.js'instead.