Skip to content

fix(dts): preserve explicit module extensions#1648

Merged
Timeless0911 merged 1 commit into
mainfrom
david/fix-dts-mjs-redirect
May 14, 2026
Merged

fix(dts): preserve explicit module extensions#1648
Timeless0911 merged 1 commit into
mainfrom
david/fix-dts-mjs-redirect

Conversation

@Timeless0911
Copy link
Copy Markdown
Contributor

@Timeless0911 Timeless0911 commented May 14, 2026

Summary

This PR fixes declaration import redirection for explicit module-kind specifiers. When source code imports a path like ./foo.mjs and declaration emit produces foo.d.mts, redirect.dts.extension now preserves the .mjs specifier instead of rewriting it to the current declaration file's default JS extension.

Checklist

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

Copilot AI review requested due to automatic review settings May 14, 2026 09:15
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

Fixes @rslib/plugin-dts import redirection so that when a source file explicitly imports a module-kind specifier (e.g. ./foo.mjs) and the emitted declaration target is module-kind (foo.d.mts / foo.d.cts), the redirected import keeps the explicit .mjs/.cjs extension instead of being rewritten to match the current declaration file’s default JS extension.

Changes:

  • Update redirectDtsImports to detect when an explicit .mjs/.cjs (and related) specifier should be preserved based on the existence of a sibling .d.mts/.d.cts file.
  • Extend redirect integration fixtures to include a .mts module imported via ./foo.mjs.
  • Update inline snapshots for both tsc and tsgo integration suites to assert the preserved .mjs specifier and the new emitted foo.d.mts.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/integration/redirect/dtsTsgo.test.ts Updates snapshots to assert .mjs specifiers are preserved under tsgo redirect scenarios.
tests/integration/redirect/dts/src/index.ts Adds an explicit ./foo.mjs import and re-exports it to exercise the redirect behavior.
tests/integration/redirect/dts/src/foo.mts New .mts module fixture that emits foo.d.mts to validate module-kind handling.
tests/integration/redirect/dts.test.ts Updates snapshots to assert .mjs specifiers are preserved under non-tsgo redirect scenarios.
packages/plugin-dts/src/utils.ts Implements the preservation logic for explicit module-kind specifiers when corresponding .d.mts/.d.cts outputs exist.

@Timeless0911 Timeless0911 enabled auto-merge (squash) May 14, 2026 09:31
@Timeless0911 Timeless0911 merged commit 8985562 into main May 14, 2026
10 checks passed
@Timeless0911 Timeless0911 deleted the david/fix-dts-mjs-redirect branch May 14, 2026 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants