fix(dts): preserve explicit module extensions#1648
Merged
Conversation
Contributor
There was a problem hiding this comment.
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
redirectDtsImportsto detect when an explicit.mjs/.cjs(and related) specifier should be preserved based on the existence of a sibling.d.mts/.d.ctsfile. - Extend redirect integration fixtures to include a
.mtsmodule imported via./foo.mjs. - Update inline snapshots for both
tscandtsgointegration suites to assert the preserved.mjsspecifier and the new emittedfoo.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. |
fi3ework
approved these changes
May 14, 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
This PR fixes declaration import redirection for explicit module-kind specifiers. When source code imports a path like
./foo.mjsand declaration emit producesfoo.d.mts,redirect.dts.extensionnow preserves the.mjsspecifier instead of rewriting it to the current declaration file's default JS extension.Checklist