Skip to content

Commit 33c31f9

Browse files
huntiefacebook-github-bot
authored andcommitted
Simplify react-native/setup-env require in community-cli-plugin
Summary: **Motivation** While sanity checking #57492, I double checked why we use `path.join(ctx.reactNativePath, ...)` here when adjacent OOT platforms resolve by package name. It turns out this complexity is historic and redundant: - `reactNativePath` doesn't customize the `react-native` package name — it only resolves the `node_modules` directory. [[1]](https://github.com/react-native-community/cli/blame/main/packages/cli-tools/src/findPackageDependencyDir.ts#L81) - We now (since ~2 years ago) resolve using `{paths: [ctx.root]}`, making the manual `path.join` redundant. **This diff** Drops the `reactNativePath` option and resolves `react-native/setup-env` directly by package name. Purely a refactor. No need to pick to 0.87. Changelog: [Internal] Differential Revision: D111225671
1 parent 5976273 commit 33c31f9

2 files changed

Lines changed: 2 additions & 6 deletions

File tree

packages/community-cli-plugin/src/utils/loadMetroConfig.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import type {MetroConfig} from 'metro';
1414
import {CLIError} from './errors';
1515
import {reactNativePlatformResolver} from './metroPlatformResolver';
1616
import {loadConfig, resolveConfig} from 'metro';
17-
import path from 'path';
1817

1918
const debug = require('debug')('ReactNative:CommunityCliPlugin');
2019

@@ -25,7 +24,6 @@ export type {Config};
2524

2625
export type ConfigLoadingContext = Readonly<{
2726
root: Config['root'],
28-
reactNativePath: Config['reactNativePath'],
2927
platforms: Config['platforms'],
3028
...
3129
}>;
@@ -63,9 +61,7 @@ function getCommunityCliDefaultConfig(
6361
// We can include multiple copies of setup-env here because Metro will
6462
// only add ones that are already part of the bundle
6563
getModulesRunBeforeMainModule: () => [
66-
// NOTE: ctx.reactNativePath is an absolute path, therefore we need to
67-
// reference setup-env.js here by exact path specifier.
68-
require.resolve(path.join(ctx.reactNativePath, 'src/setup-env.js'), {
64+
require.resolve('react-native/setup-env', {
6965
paths: [ctx.root],
7066
}),
7167
...outOfTreePlatforms.map(platform =>

packages/metro-config/src/index.flow.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function getDefaultConfig(projectRoot: string): ConfigT {
5959
unstable_conditionNames: ['react-native'],
6060
},
6161
serializer: {
62-
// Note: This option is overridden in cli-plugin-metro (getOverrideConfig)
62+
// NOTE: Overridden in community-cli-plugin
6363
getModulesRunBeforeMainModule: () => [
6464
require.resolve('react-native/setup-env'),
6565
],

0 commit comments

Comments
 (0)