Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: warn only in init command when CLI uses cached npx version #44644

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions packages/react-native/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ let cli = {
};

const isNpxRuntime = process.env.npm_lifecycle_event === 'npx';
const isInitCommand = process.argv[2] === 'init';
const DEFAULT_REGISTRY_HOST =
process.env.npm_config_registry ?? 'https://registry.npmjs.org/';
const HEAD = '1000.0.0';
Expand Down Expand Up @@ -65,7 +66,7 @@ async function getLatestVersion(registryHost = DEFAULT_REGISTRY_HOST) {
* @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') {
if (isInitCommand) {
console.warn(
`\nRunning: ${chalk.grey.bold('npx @react-native-community/cli init')}\n`,
);
Expand All @@ -80,7 +81,7 @@ function warnWhenRunningInit() {
* @see https://github.com/react-native-community/discussions-and-proposals/tree/main/proposals/0759-react-native-frameworks.md
*/
function warnWithDeprecationSchedule() {
if (process.argv[2] !== 'init') {
if (!isInitCommand) {
return;
}

Expand Down Expand Up @@ -127,7 +128,12 @@ ${chalk.yellow('⚠')}️ The \`init\` command is deprecated.
*
*/
async function main() {
if (isNpxRuntime && !process.env.SKIP && currentVersion !== HEAD) {
if (
isNpxRuntime &&
!process.env.SKIP &&
currentVersion !== HEAD &&
isInitCommand
) {
try {
const latest = await getLatestVersion();
// TODO: T184416093 When cli is deprecated, remove semver from package.json
Expand Down
Loading