fix: rewrite local declare module specifiers to output chunk paths#191
Open
igordanchenko wants to merge 1 commit intosxzz:mainfrom
Open
fix: rewrite local declare module specifiers to output chunk paths#191igordanchenko wants to merge 1 commit intosxzz:mainfrom
declare module specifiers to output chunk paths#191igordanchenko wants to merge 1 commit intosxzz:mainfrom
Conversation
188c4a4 to
96dbcc7
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.
96dbcc7 to
90b2fba
Compare
This was referenced Mar 29, 2026
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.