mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
fix: fix @react-native-community/cli not being found in pnpm setups (#47304)
Summary: Fix `react-native-community/cli` not being found in pnpm setups ## Changelog: [GENERAL] [FIXED] - Fix `react-native-community/cli` not being found in pnpm setups Pull Request resolved: https://github.com/facebook/react-native/pull/47304 Test Plan: 1. Clone/check out this branch: https://github.com/microsoft/rnx-kit/pull/3409 2. Run `yarn react-native config` Reviewed By: cortinico Differential Revision: D65209065 Pulled By: robhogan fbshipit-source-id: 2ceb73ad140b4afe193e879779c2d8a4b9adf3fc
This commit is contained in:
committed by
React Native Bot
parent
e2b081e66f
commit
9ba96ad79d
Vendored
+11
-2
@@ -23,6 +23,15 @@ const deprecated = () => {
|
||||
);
|
||||
};
|
||||
|
||||
function findCommunityCli(startDir = process.cwd()) {
|
||||
// With isolated node_modules (eg pnpm), we won't be able to find
|
||||
// `@react-native-community/cli` starting from the `react-native` directory.
|
||||
// Instead, we should use the project root, which we assume to be the cwd.
|
||||
const options = {paths: [startDir]};
|
||||
const rncli = require.resolve('@react-native-community/cli', options);
|
||||
return require(rncli);
|
||||
}
|
||||
|
||||
function isMissingCliDependency(error) {
|
||||
return (
|
||||
error.code === 'MODULE_NOT_FOUND' &&
|
||||
@@ -217,7 +226,7 @@ async function main() {
|
||||
}
|
||||
|
||||
try {
|
||||
return require('@react-native-community/cli').run(name);
|
||||
return findCommunityCli().run(name);
|
||||
} catch (e) {
|
||||
if (isMissingCliDependency(e)) {
|
||||
warnWithExplicitDependency();
|
||||
@@ -231,7 +240,7 @@ if (require.main === module) {
|
||||
main();
|
||||
} else {
|
||||
try {
|
||||
cli = require('@react-native-community/cli');
|
||||
cli = findCommunityCli();
|
||||
} catch (e) {
|
||||
// We silence @react-native-community/cli missing as it is no
|
||||
// longer a dependency
|
||||
|
||||
Reference in New Issue
Block a user