Skip to content

Commit b98c5b9

Browse files
szymonrybczakfacebook-github-bot
authored andcommitted
fix: warn only in init command when CLI uses cached npx version (#44644)
Summary: In #37510, a check was introduced to check if user is using `latest` version of `npx`, but right now it checks for every command executed, but it should only ensure that `latest` is included when creating a new project. In this Pull Request I've added a condition to only warn if `init` was fired. ## Changelog: [GENERAL] [FIXED] - Warn only in `init` command when CLI uses cached `npx` version Pull Request resolved: #44644 Test Plan: Warning about using `latest` version CLI should only be presented when running `init` command. Reviewed By: arushikesarwani94 Differential Revision: D57681864 Pulled By: blakef fbshipit-source-id: 5c81b9a08141396efcd24539b2560cea16028dd9
1 parent 053e302 commit b98c5b9

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

packages/react-native/cli.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ let cli = {
2929
};
3030

3131
const isNpxRuntime = process.env.npm_lifecycle_event === 'npx';
32+
const isInitCommand = process.argv[2] === 'init';
3233
const DEFAULT_REGISTRY_HOST =
3334
process.env.npm_config_registry ?? 'https://registry.npmjs.org/';
3435
const HEAD = '1000.0.0';
@@ -65,7 +66,7 @@ async function getLatestVersion(registryHost = DEFAULT_REGISTRY_HOST) {
6566
* @see https://github.com/react-native-community/discussions-and-proposals/tree/main/proposals/0759-react-native-frameworks.md
6667
*/
6768
function warnWhenRunningInit() {
68-
if (process.argv[2] === 'init') {
69+
if (isInitCommand) {
6970
console.warn(
7071
`\nRunning: ${chalk.grey.bold('npx @react-native-community/cli init')}\n`,
7172
);
@@ -80,7 +81,7 @@ function warnWhenRunningInit() {
8081
* @see https://github.com/react-native-community/discussions-and-proposals/tree/main/proposals/0759-react-native-frameworks.md
8182
*/
8283
function warnWithDeprecationSchedule() {
83-
if (process.argv[2] !== 'init') {
84+
if (!isInitCommand) {
8485
return;
8586
}
8687

@@ -127,7 +128,12 @@ ${chalk.yellow('⚠')}️ The \`init\` command is deprecated.
127128
*
128129
*/
129130
async function main() {
130-
if (isNpxRuntime && !process.env.SKIP && currentVersion !== HEAD) {
131+
if (
132+
isNpxRuntime &&
133+
!process.env.SKIP &&
134+
currentVersion !== HEAD &&
135+
isInitCommand
136+
) {
131137
try {
132138
const latest = await getLatestVersion();
133139
// TODO: T184416093 When cli is deprecated, remove semver from package.json

0 commit comments

Comments
 (0)