From 5947e6e9221a53518e1b5a09a197ef0077ec40be Mon Sep 17 00:00:00 2001 From: Nick McCurdy Date: Thu, 30 Jan 2020 17:18:09 -0500 Subject: [PATCH 1/2] Fix --use-pnp for Yarn 2 --- packages/create-react-app/createReactApp.js | 22 +++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/create-react-app/createReactApp.js b/packages/create-react-app/createReactApp.js index 4d39b208767..7ac2e955ce5 100755 --- a/packages/create-react-app/createReactApp.js +++ b/packages/create-react-app/createReactApp.js @@ -269,17 +269,26 @@ function createApp( } } else if (usePnp) { const yarnInfo = checkYarnVersion(); - if (!yarnInfo.hasMinYarnPnp) { - if (yarnInfo.yarnVersion) { + if (yarnInfo.yarnVersion) { + if (!yarnInfo.hasMinYarnPnp) { console.log( chalk.yellow( `You are using Yarn ${yarnInfo.yarnVersion} together with the --use-pnp flag, but Plug'n'Play is only supported starting from the 1.12 release.\n\n` + `Please update to Yarn 1.12 or higher for a better, fully supported experience.\n` ) ); + // 1.11 had an issue with webpack-dev-middleware, so better not use PnP with it (never reached stable, but still) + usePnp = false; + } + if (!yarnInfo.hasMaxYarnPnp) { + console.log( + chalk.yellow( + `The --use-pnp flag is no longer necessary with yarn ${yarnInfo.yarnVersion} and will be deprecated and removed in a future release.\n` + ) + ); + // 2 supports PnP by default and breaks when trying to use the flag + usePnp = false; } - // 1.11 had an issue with webpack-dev-middleware, so better not use PnP with it (never reached stable, but still) - usePnp = false; } } @@ -783,7 +792,9 @@ function checkNpmVersion() { function checkYarnVersion() { const minYarnPnp = '1.12.0'; + const maxYarnPnp = '2.0.0'; let hasMinYarnPnp = false; + let hasMaxYarnPnp = false; let yarnVersion = null; try { yarnVersion = execSync('yarnpkg --version') @@ -791,6 +802,7 @@ function checkYarnVersion() { .trim(); if (semver.valid(yarnVersion)) { hasMinYarnPnp = semver.gte(yarnVersion, minYarnPnp); + hasMaxYarnPnp = semver.lt(yarnVersion, maxYarnPnp); } else { // Handle non-semver compliant yarn version strings, which yarn currently // uses for nightly builds. The regex truncates anything after the first @@ -799,6 +811,7 @@ function checkYarnVersion() { if (trimmedYarnVersionMatch) { const trimmedYarnVersion = trimmedYarnVersionMatch.pop(); hasMinYarnPnp = semver.gte(trimmedYarnVersion, minYarnPnp); + hasMaxYarnPnp = semver.lt(trimmedYarnVersion, maxYarnPnp); } } } catch (err) { @@ -806,6 +819,7 @@ function checkYarnVersion() { } return { hasMinYarnPnp: hasMinYarnPnp, + hasMaxYarnPnp: hasMaxYarnPnp, yarnVersion: yarnVersion, }; } From 07af204a09b228f5e304823d62642da5334d3c29 Mon Sep 17 00:00:00 2001 From: Ian Schmitz Date: Mon, 6 Apr 2020 20:59:31 -0700 Subject: [PATCH 2/2] Update createReactApp.js --- packages/create-react-app/createReactApp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/create-react-app/createReactApp.js b/packages/create-react-app/createReactApp.js index 7ac2e955ce5..a15ba19ecb9 100755 --- a/packages/create-react-app/createReactApp.js +++ b/packages/create-react-app/createReactApp.js @@ -283,7 +283,7 @@ function createApp( if (!yarnInfo.hasMaxYarnPnp) { console.log( chalk.yellow( - `The --use-pnp flag is no longer necessary with yarn ${yarnInfo.yarnVersion} and will be deprecated and removed in a future release.\n` + 'The --use-pnp flag is no longer necessary with yarn 2 and will be deprecated and removed in a future release.\n' ) ); // 2 supports PnP by default and breaks when trying to use the flag