fix(dts): add extensions for non-rootDir relative imports#1536
Merged
chenjiahan merged 1 commit intomainfrom Mar 16, 2026
Merged
fix(dts): add extensions for non-rootDir relative imports#1536chenjiahan merged 1 commit intomainfrom
chenjiahan merged 1 commit intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes declaration import rewriting for modules outside rootDir when redirect.dts.extension is enabled. Previously, .d.mts/.d.cts outputs would leave extensionless imports for paths rewritten by redirect.path to locations outside rootDir, breaking NodeNext module resolution.
Changes:
- Add a fallback from
.d.mts/.d.ctsto.d.tswhen checking for declaration files inaddExtension, so non-rootDir files get a resolvable.jssuffix. - Simplify the extension-addition condition to cover all rewritten, relative, and absolute import paths (not just those within
rootDir). - Update test snapshots to reflect the corrected import paths with
/index.jsextensions.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
packages/plugin-dts/src/utils.ts |
Core fix: fallback dts candidates in addExtension and simplified shouldAddExtension gate |
tests/integration/redirect/dts.test.ts |
Updated snapshots for prebundle-pkg imports now including /index.js |
tests/integration/redirect/dtsTsgo.test.ts |
Updated snapshots for tsgo variant with same /index.js fix |
fi3ework
approved these changes
Mar 16, 2026
chenjiahan
approved these changes
Mar 16, 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.
Summary
Fix declaration import rewriting for modules outside
rootDirwhenredirect.dts.extensionis enabled.Previously,
.d.mtsand.d.ctsoutputs only checked for matching declaration suffixes, so rewritten relative imports outsiderootDircould remain extensionless and fail under NodeNext. The redirect now falls back to.d.tsin those cases so generated imports receive a resolvable.jssuffix.Related Links
N/A
Checklist