mirror of
https://github.com/react/react-native.git
synced 2026-09-28 21:33:11 +08:00
Summary: Pull Request resolved: https://github.com/react/react-native/pull/57611 Directly follows D112733139 (Metro). **Motivation** - New Node builtins are *only* available under the prefix (e.g. `node:sqlite`), as this allows Node to introduce them without ecosystem-breaking changes, so this is the direction of travel and the only choice that'll allow consistency. - Encouraging them and grouping them separately makes it easier to reason about a module's 3rd party dependencies. Changelog: [Internal] Reviewed By: robhogan Differential Revision: D112803684 fbshipit-source-id: 40668d746a7151b3aa4800ff8af997902a18d198
94 lines
2.3 KiB
JavaScript
Executable File
94 lines
2.3 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
||
/**
|
||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||
*
|
||
* This source code is licensed under the MIT license found in the
|
||
* LICENSE file in the root directory of this source tree.
|
||
*
|
||
* @flow strict-local
|
||
* @format
|
||
*/
|
||
|
||
'use strict';
|
||
|
||
// $FlowFixMe[untyped-import]
|
||
const {name} = require('./package.json');
|
||
const {styleText} = require('node:util');
|
||
|
||
const deprecated = () => {
|
||
throw new Error(
|
||
'react-native/cli is deprecated, please use @react-native-community/cli instead',
|
||
);
|
||
};
|
||
|
||
function findCommunityCli(startDir /*: string */ = 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?: Array<string>, ...} */ = {paths: [startDir]};
|
||
const rncli = require.resolve('@react-native-community/cli', options);
|
||
// $FlowFixMe[unsupported-syntax]
|
||
return require(rncli);
|
||
}
|
||
|
||
function isMissingCliDependency(error /*: Error */) {
|
||
return (
|
||
// $FlowFixMe[prop-missing]
|
||
error.code === 'MODULE_NOT_FOUND' &&
|
||
/@react-native-community\/cli/.test(error.message)
|
||
);
|
||
}
|
||
|
||
let cli /*: Readonly<{
|
||
bin: string,
|
||
loadConfig: $FlowFixMe,
|
||
run: () => void
|
||
}> */ = {
|
||
bin: '/dev/null',
|
||
loadConfig: deprecated,
|
||
run: deprecated,
|
||
};
|
||
|
||
function warnWithExplicitDependency(version /*: string */ = '*') {
|
||
console.warn(`
|
||
${styleText('yellow', '⚠')}️ ${styleText(['dim'], 'react-native')} depends on ${styleText('dim', '@react-native-community/cli')} for cli commands. To fix update your ${styleText(['dim'], 'package.json')} to include:
|
||
|
||
${styleText(
|
||
['white', 'bold'],
|
||
` "devDependencies": {
|
||
"@react-native-community/cli": "latest",
|
||
}
|
||
`,
|
||
)}
|
||
|
||
`);
|
||
}
|
||
|
||
function main() {
|
||
try {
|
||
return findCommunityCli().run(name);
|
||
} catch (e) {
|
||
if (isMissingCliDependency(e)) {
|
||
warnWithExplicitDependency();
|
||
process.exit(1);
|
||
}
|
||
throw e;
|
||
}
|
||
}
|
||
|
||
if (require.main === module) {
|
||
void main();
|
||
} else {
|
||
try {
|
||
cli = findCommunityCli();
|
||
} catch (e) {
|
||
// We silence @react-native-community/cli missing as it is no
|
||
// longer a dependency
|
||
if (!isMissingCliDependency(e)) {
|
||
throw e;
|
||
}
|
||
}
|
||
}
|
||
|
||
module.exports = cli;
|