Skip to content

Commit

Permalink
feat(cli): warn underlying command when using npx react-native init (
Browse files Browse the repository at this point in the history
…#43127)

Summary:
This adds a new warning for React Native 0.74, implementing the [RFC 0759](https://github.com/react-native-community/discussions-and-proposals/blob/nc/rnf/proposals/0759-react-native-frameworks.md#the-init-command) init command changes.

- It's added inside `react-native/cli.js` to avoid warning users when actually executing `npx react-native-community/cli` commands.
- The check is fairly simple: `process.argv[2] === 'init'`. The first two args are the Node bin and the actual script bin paths.
- The message is sent over `console.warn` to avoid potentially mixing JSON with non-JSON output.

## Changelog:

[GENERAL] [ADDED] - Warn with future command when using `npx react-native init`

Pull Request resolved: #43127

Test Plan:
Any command other than `init` must not warn.

- `$ node ./path/to/react-native/cli.js init`
- `$ node ./path/to/react-native/cli.js init --help`
  - Should warn with `Running: npx react-native-community/cli init`
    ![image](https://github.com/facebook/react-native/assets/1203991/a3f5e3d2-7b59-41fe-9a53-bc9ce5a21fd1)
- `$ node ./path/to/react-native/cli.js --help`
  - Must not warn
    ![image](https://github.com/facebook/react-native/assets/1203991/97679429-db35-47f8-bdeb-33187bb167cf)

Reviewed By: cipolleschi

Differential Revision: D54063131

Pulled By: cortinico

fbshipit-source-id: c60b8b6034087b584e98b51f5bedf68a46caf44c
  • Loading branch information
byCedric authored and facebook-github-bot committed Feb 24, 2024
1 parent 48a7233 commit a6397af
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/react-native/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ async function getLatestVersion(registryHost = DEFAULT_REGISTRY_HOST) {
});
}

/**
* Warn when users are using `npx react-native init`, to raise awareness of the changes from RFC 0759.
* @see https://github.com/react-native-community/discussions-and-proposals/tree/main/proposals/0759-react-native-frameworks.md
*/
function warnWhenRunningInit() {
if (process.argv[2] === 'init') {
console.warn('\nRunning: npx @react-native-community/cli init\n');
}
}

/**
* npx react-native -> @react-native-community/cli
*
Expand Down Expand Up @@ -66,6 +76,9 @@ async function main() {
// Ignore errors, since it's a nice to have warning
}
}

warnWhenRunningInit();

return cli.run(name);
}

Expand Down

0 comments on commit a6397af

Please sign in to comment.