Skip to content

Commit

Permalink
Fix init behavior for 0.76 (#46560)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #46560

The `init` command should still keep on working till 2024-12-31

This handles this scenario as currently `npx react-native@next init` is broken.

Changelog:
[Internal] [Changed] - Clarify init behavior for 0.76

Reviewed By: huntie, cipolleschi

Differential Revision: D62958747

fbshipit-source-id: ce3d974df55162720d59a7ece7fcb816e257185d
  • Loading branch information
cortinico authored and facebook-github-bot committed Sep 19, 2024
1 parent 0fe234c commit 2524c8e
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions packages/react-native/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,19 @@ function warnWithDeprecationSchedule() {
${chalk.yellow('⚠️')} The \`init\` command is deprecated.
The behavior will be changed on ${chalk.white.bold(CLI_DEPRECATION_DATE.toLocaleDateString())} ${emphasis(`(${daysRemaining} day${daysRemaining > 1 ? 's' : ''})`)}.
- Switch to ${chalk.dim('npx @react-native-community/cli init')} for the identical behavior.
- Switch to ${chalk.grey.bold('npx @react-native-community/cli init')} for the identical behavior.
- Refer to the documentation for information about alternative tools: ${chalk.dim('https://reactnative.dev/docs/getting-started')}`);
}

function warnWithDeprecated() {
if (!isInitCommand) {
return;
}

console.warn(`
🚨️ Creating a project using ${chalk.green('npx react-native init')} is deprecated. Please use:
${chalk.green('npx @react-native-community/cli init')}
🚨️ The \`init\` command is deprecated.
Refer to the documentation for information about alternative tools: ${chalk.dim('https://reactnative.dev/docs/getting-started')}
${chalk.green('No changes made.')}`);
- Switch to ${chalk.grey.bold('npx @react-native-community/cli init')} for the identical behavior.
- Refer to the documentation for information about alternative tools: ${chalk.dim('https://reactnative.dev/docs/getting-started')}`);
}

function warnWithExplicitDependency(version = '*') {
Expand Down Expand Up @@ -177,7 +173,7 @@ async function main() {

const isDeprecated =
CLI_DEPRECATION_DATE.getTime() <= new Date().getTime() ||
currentVersion.startsWith('0.76');
currentVersion.startsWith('0.77');

/**
* This command is now deprecated. We will continue to proxy commands to @react-native-community/cli, but it
Expand All @@ -194,8 +190,13 @@ async function main() {
warnWithDeprecated();
// We only exit if the user calls `init` and it's deprecated. All other cases should proxy to to @react-native-community/cli.
// Be careful with this as it can break a lot of users.
console.warn(`${chalk.green('Exiting...')}`);
process.exit(1);
} else if (currentVersion.startsWith('0.75')) {
} else if (
currentVersion.startsWith('0.75') ||
currentVersion.startsWith('0.76')
) {
// We check deprecation schedule only for 0.75 and 0.76 and 0.77 is expected to land in Jan 2025.
warnWithDeprecationSchedule();
}
warnWhenRunningInit();
Expand Down

0 comments on commit 2524c8e

Please sign in to comment.