Skip to content

feat(resolve): add applyExtensionAliasToExportsField option#554

Merged
alexander-akait merged 3 commits intomainfrom
claude/fix-extension-alias-alignment-xC6sZ
Apr 22, 2026
Merged

feat(resolve): add applyExtensionAliasToExportsField option#554
alexander-akait merged 3 commits intomainfrom
claude/fix-extension-alias-alignment-xC6sZ

Conversation

@alexander-akait
Copy link
Copy Markdown
Member

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.

claude added 2 commits April 22, 2026 20:42
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-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 22, 2026

🦋 Changeset detected

Latest commit: c1319d1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
enhanced-resolve Minor

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

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Apr 22, 2026

CLA Not Signed

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.62%. Comparing base (8757f67) to head (c1319d1).
⚠️ Report is 9 commits behind head on main.

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              
Flag Coverage Δ
integration 96.62% <100.00%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

`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.
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 22, 2026

Merging this PR will not alter performance

✅ 69 untouched benchmarks


Comparing claude/fix-extension-alias-alignment-xC6sZ (c1319d1) with main (f5adeee)

Open in CodSpeed

@alexander-akait alexander-akait merged commit f9f6d57 into main Apr 22, 2026
33 of 34 checks passed
@alexander-akait alexander-akait deleted the claude/fix-extension-alias-alignment-xC6sZ branch April 22, 2026 22:33
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.

2 participants