Conversation
|
@amroaltah has exported this pull request. If you are a Meta employee, you can view the originating Diff in D119701713. |
Summary: Fixes react#56641 The preset failed in two ways under strict-isolation installs (pnpm and Yarn pnpm-mode): `react-native` was not a declared dependency so `jest-preset.js` could not resolve it, and the `transformIgnorePatterns` rule only matched classic `node_modules` layouts so preset sources shipped untransformed. - Declare `react-native` as a peer dependency so the installer links it into the preset's scope. - Move `babel/core` from dependencies to peerDependencies: `babel-jest` peer-depends on it, so it must be provided, but as a direct dependency a strict installer gives the preset its own copy and the consumer's `babel.config.js` presets would then load under a different `babel/core` instance than the consumer's own. A peer keeps one copy, matching how `react` and `react-native` are already declared. `babel/runtime` stays a direct dependency: the preset's sources are compiled with `babel/plugin-transform-runtime` helpers enabled, so the transformed `jest/setup.js` requires `babel/runtime/helpers/*` from the preset's own scope at Jest runtime (verified: removing it makes the pnpm harness fail with `Cannot find module 'babel/runtime/helpers/interopRequireDefault'`). - Resolve the `babel-jest` transformer from the preset's own scope via `require.resolve('babel-jest')` instead of the bare specifier. - Match `react-native` sources in `transformIgnorePatterns` at each layout's anchored location - classic `node_modules`, pnpm (`.pnpm/<id>/node_modules/...`), and Yarn pnpm-mode (`.store/<flat>-npm-<version>-<hash>/package/...` (or `<flat>-virtual-<hash>/package/...` for packages declaring peer dependencies, verified against real Yarn installs)) - so strict-isolation layouts still transform preset and `react-native` sources. The prefixes are anchored rather than permitting arbitrary depth, so scoped third-party packages whose unscoped name is exactly `react-native` (`sentry/react-native`, `notifee/react-native`), nested directories literally named `react-native`, and real `-suffix` packages all stay ignored exactly as before. - Write the `.store` scoped-package segment as `(?:-[^-\/]+)*` rather than `(-[^\/]+)*`. The inner class in the original form could itself consume `-`, so a dash-separated name had exponentially many ways to be partitioned and any near-miss path under `node_modules/.store/react-native-...` forced catastrophic backtracking. Jest evaluates `transformIgnorePatterns` against every candidate file path, so one pathological path could hang a run. Restricting the segment to non-dash characters makes the partition unique and the match linear, with no change to which paths are ignored. Known limitation: under Yarn pnpm-mode's `.store` layout, a scoped package's slash flattens to a dash, erasing the scope boundary - so third-party `react-native-<scope>/*` packages (e.g. `react-native-async-storage/async-storage`) are indistinguishable from genuine `react-native/*` ones and are also transformed there. Transforming is the safe direction (a miss would ship untransformed sources); the impact is performance-only and confined to Yarn pnpm-mode. Changelog: [General][Fixed] - Fix `react-native/jest-preset` failing to resolve `react-native` and to transform preset sources under pnpm and Yarn pnpm-mode installs Differential Revision: D119701713
amroaltah
force-pushed
the
export-D119701713
branch
from
September 18, 2026 18:58
55f6749 to
d41db90
Compare
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:
Fixes #56641
The preset failed in two ways under strict-isolation installs (pnpm and Yarn pnpm-mode):
react-nativewas not a declared dependency sojest-preset.jscould not resolve it, and thetransformIgnorePatternsrule only matched classicnode_moduleslayouts so preset sources shipped untransformed.react-nativeas a peer dependency so the installer links it into the preset's scope.babel/corefrom dependencies to peerDependencies:babel-jestpeer-depends on it, so it must be provided, but as a direct dependency a strict installer gives the preset its own copy and the consumer'sbabel.config.jspresets would then load under a differentbabel/coreinstance than the consumer's own. A peer keeps one copy, matching howreactandreact-nativeare already declared.babel/runtimestays a direct dependency: the preset's sources are compiled withbabel/plugin-transform-runtimehelpers enabled, so the transformedjest/setup.jsrequiresbabel/runtime/helpers/*from the preset's own scope at Jest runtime (verified: removing it makes the pnpm harness fail withCannot find module 'babel/runtime/helpers/interopRequireDefault').babel-jesttransformer from the preset's own scope viarequire.resolve('babel-jest')instead of the bare specifier.react-nativesources intransformIgnorePatternsat each layout's anchored location - classicnode_modules, pnpm (.pnpm/<id>/node_modules/...), and Yarn pnpm-mode (.store/<flat>-npm-<version>-<hash>/package/...(or<flat>-virtual-<hash>/package/...for packages declaring peer dependencies, verified against real Yarn installs)) - so strict-isolation layouts still transform preset andreact-nativesources. The prefixes are anchored rather than permitting arbitrary depth, so scoped third-party packages whose unscoped name is exactlyreact-native(sentry/react-native,notifee/react-native), nested directories literally namedreact-native, and real-suffixpackages all stay ignored exactly as before..storescoped-package segment as(?:-[^-\/]+)*rather than(-[^\/]+)*. The inner class in the original form could itself consume-, so a dash-separated name had exponentially many ways to be partitioned and any near-miss path undernode_modules/.store/react-native-...forced catastrophic backtracking. Jest evaluatestransformIgnorePatternsagainst every candidate file path, so one pathological path could hang a run. Restricting the segment to non-dash characters makes the partition unique and the match linear, with no change to which paths are ignored.Known limitation: under Yarn pnpm-mode's
.storelayout, a scoped package's slash flattens to a dash, erasing the scope boundary - so third-partyreact-native-<scope>/*packages (e.g.react-native-async-storage/async-storage) are indistinguishable from genuinereact-native/*ones and are also transformed there. Transforming is the safe direction (a miss would ship untransformed sources); the impact is performance-only and confined to Yarn pnpm-mode.Changelog:
[General][Fixed] - Fix
react-native/jest-presetfailing to resolvereact-nativeand to transform preset sources under pnpm and Yarn pnpm-mode installsDifferential Revision: D119701713