fix(tools-react-native): find `metro` via `@react-native/community-cli-plugin` (#2608)

This commit is contained in:
Tommy Nguyen 2023-08-17 12:12:07 +02:00 коммит произвёл GitHub
Родитель 668c6f4003
Коммит 1bc772ccb0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 19 добавлений и 7 удалений

Просмотреть файл

@ -0,0 +1,5 @@
---
"@rnx-kit/tools-react-native": patch
---
Find `metro` via the new `@react-native/community-cli-plugin` package

Просмотреть файл

@ -16,21 +16,28 @@ function resolveFrom(name: string, startDir: string): string | undefined {
* @returns The path to the Metro installation; `undefined` if Metro could not be found
*/
export function findMetroPath(projectRoot = process.cwd()): string | undefined {
const rnPath = resolveFrom("react-native", projectRoot);
if (!rnPath) {
const rnDir = resolveFrom("react-native", projectRoot);
if (!rnDir) {
return undefined;
}
const cliPath = resolveFrom("@react-native-community/cli", rnPath);
if (!cliPath) {
// `metro` dependency was moved to `@react-native/community-cli-plugin` in 0.73
// https://github.com/facebook/react-native/commit/fdcb94ad1310af6613cfb2a2c3f22f200bfa1c86
const cliPluginDir = resolveFrom("@react-native/community-cli-plugin", rnDir);
if (cliPluginDir) {
return resolveFrom("metro", cliPluginDir);
}
const cliDir = resolveFrom("@react-native-community/cli", rnDir);
if (!cliDir) {
return undefined;
}
const cliMetroPath = resolveFrom(
const cliMetroDir = resolveFrom(
"@react-native-community/cli-plugin-metro",
cliPath
cliDir
);
return resolveFrom("metro", cliMetroPath || cliPath);
return resolveFrom("metro", cliMetroDir || cliDir);
}
/**