[WIP] ⟡ fix(babel-plugin-import-path-remapper): honor source conditions in exports - #4369
Open
Sverre Johansen (sverrejoh) wants to merge 1 commit into
Open
Sverre Johansen (sverrejoh) wants to merge 1 commit into
Sverre Johansen (sverrejoh) wants to merge 1 commit into
Conversation
…ports Packages that declare entry points via exports were skipped entirely, making lib -> src remapping impossible even when the package explicitly declares its source entry. Honor an explicitly declared source condition on the root export (the shape create-react-native-library generates), make the remap callback reachable for exports packages, and leave everything else untouched.
Sverre Johansen (sverrejoh)
requested review from
Jason Morse (JasonVMo),
Saad Najmi (Saadnajmi),
acoates-ms and
Tommy Nguyen (tido64)
as code owners
September 15, 2026 12:37
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.
Description
babel-plugin-import-path-remapperskips any package that declaresexports,returning before a remap is attempted. That makes
lib->srcremappingimpossible for those packages even when the package explicitly declares where
its source lives, which blocks monorepos that would like to move off
hand-maintained alias maps and onto
exportsmaps.This change honors an explicitly declared source condition on the root
"."export — the shape
create-react-native-librarygenerates:sourceExportConditionoption (string | string[]), defaulting to[].With no configuration nothing changes, so the new behavior is opt-in.
"."export is considered. Nested conditionsand subpath exports are deliberately not resolved.
exportsbut no matching source condition is stillleft alone.
exportsis the package's public contract, so the plugin does notguess its way around it.
One behavior change worth calling out for existing users: a custom
remapcallback is now reachable for packages that declare
exports. Previously suchpackages returned early, so
remapwas never invoked for them.Follow-up to #4023, which was closed for inactivity with an offer to reopen.
This is a re-authored and narrower take on a fresh branch rather than a revival
of that diff.
Test plan
yarn testinpackages/babel-plugin-import-path-remapper— 20/20 pass.Six tests are added, backed by fixtures under
test/__fixtures__/node_modules/@rnx-kit/example:sourceExportConditionis validated and throws if it is not a string or anarray of strings
sourcecondition on the root export is remapped tothat entry
exportsbut no matching source condition is left untouchedsourceExportConditionis setremapcallback runs for packages withexportsRun against the pre-change source as a control, four of the six fail (16/20
pass), so they pin the new behavior rather than only describing it. The
remaining two pass in both directions by design: they assert the opt-in default
is a no-op, which the previous code also satisfied by skipping
exportspackages outright.