Skip to content

fix(dts): add extensions for non-rootDir relative imports#1536

Merged
chenjiahan merged 1 commit intomainfrom
fix/dts-nodenext-relative-imports
Mar 16, 2026
Merged

fix(dts): add extensions for non-rootDir relative imports#1536
chenjiahan merged 1 commit intomainfrom
fix/dts-nodenext-relative-imports

Conversation

@Timeless0911
Copy link
Copy Markdown
Contributor

Summary

Fix declaration import rewriting for modules outside rootDir when redirect.dts.extension is enabled.

Previously, .d.mts and .d.cts outputs only checked for matching declaration suffixes, so rewritten relative imports outside rootDir could remain extensionless and fail under NodeNext. The redirect now falls back to .d.ts in those cases so generated imports receive a resolvable .js suffix.

Related Links

N/A

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings March 16, 2026 11:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.cts to .d.ts when checking for declaration files in addExtension, so non-rootDir files get a resolvable .js suffix.
  • 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.js extensions.

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

@chenjiahan chenjiahan merged commit c6a8a76 into main Mar 16, 2026
12 checks passed
@chenjiahan chenjiahan deleted the fix/dts-nodenext-relative-imports branch March 16, 2026 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants