feat(resolve): add applyExtensionAliasToExportsField option#554
Merged
alexander-akait merged 3 commits intomainfrom Apr 22, 2026
Merged
feat(resolve): add applyExtensionAliasToExportsField option#554alexander-akait merged 3 commits intomainfrom
alexander-akait merged 3 commits intomainfrom
Conversation
Node.js does not substitute extensions on paths resolved through the package.json `exports` field (even under `--experimental-strip-types`), but TypeScript's resolver does. The default remains Node-aligned; passing `applyExtensionAliasToExportsField: true` opts into the TypeScript-aligned behavior for users who ship TS sources alongside the compiled JS that `exports` declares (monorepo source packages, eslint-import-resolver-typescript, etc.). When enabled, the wiring mirrors the `imports` side: an `exports-field-relative` hook sits between `ExportsFieldPlugin` and `relative`, with one `ExtensionAliasPlugin` per alias tapped there and `NextPlugin` falling through to `relative`. When disabled (the default), the hook is not created and `ExportsFieldPlugin` forwards directly to `relative`, matching Node.js. - `lib/ResolverFactory.js`: accept and thread the new option, add the hook + tap conditionally, retarget `ExportsFieldPlugin`'s forward. - `types.d.ts`: document the new option on `UserResolveOptions` and `ResolveOptions`. - `README.md`: update the `extensionAlias` description, document `applyExtensionAliasToExportsField`, add a row to the options table. - Tests: two cases — default-off (resolves the declared `.js`) and opt-in (prefers the `.ts` source), with a dedicated fixture.
…orExports
The new name is shorter, reads more naturally ("apply the extensionAlias
for exports"), and directly parallels the existing extensionAlias
option. Also adds a changeset entry describing the new option.
🦋 Changeset detectedLatest commit: c1319d1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #554 +/- ##
==========================================
+ Coverage 96.57% 96.62% +0.05%
==========================================
Files 50 50
Lines 2800 2812 +12
Branches 863 871 +8
==========================================
+ Hits 2704 2717 +13
+ Misses 80 79 -1
Partials 16 16
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
`lint:special` regenerates the JSDoc string from lib/ResolverFactory.js, which sits on a single line, so the types.d.ts comment collapses to the same one-line form.
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.
Node.js does not substitute extensions on paths resolved through the
package.json
exportsfield (even under--experimental-strip-types),but TypeScript's resolver does. The default remains Node-aligned;
passing
applyExtensionAliasToExportsField: trueopts into theTypeScript-aligned behavior for users who ship TS sources alongside
the compiled JS that
exportsdeclares (monorepo source packages,eslint-import-resolver-typescript, etc.).
When enabled, the wiring mirrors the
importsside: anexports-field-relativehook sits betweenExportsFieldPluginandrelative, with oneExtensionAliasPluginper alias tapped thereand
NextPluginfalling through torelative. When disabled(the default), the hook is not created and
ExportsFieldPluginforwards directly to
relative, matching Node.js.lib/ResolverFactory.js: accept and thread the new option, add thehook + tap conditionally, retarget
ExportsFieldPlugin's forward.types.d.ts: document the new option onUserResolveOptionsandResolveOptions.README.md: update theextensionAliasdescription, documentapplyExtensionAliasToExportsField, add a row to the options table..js) andopt-in (prefers the
.tssource), with a dedicated fixture.