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 --use-pnp for Yarn 2 #8460

Merged
merged 2 commits into from
May 5, 2020
Merged
Changes from 1 commit
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
22 changes: 18 additions & 4 deletions packages/create-react-app/createReactApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -783,14 +792,17 @@ 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')
.toString()
.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
Expand All @@ -799,13 +811,15 @@ function checkYarnVersion() {
if (trimmedYarnVersionMatch) {
const trimmedYarnVersion = trimmedYarnVersionMatch.pop();
hasMinYarnPnp = semver.gte(trimmedYarnVersion, minYarnPnp);
hasMaxYarnPnp = semver.lt(trimmedYarnVersion, maxYarnPnp);
}
}
} catch (err) {
// ignore
}
return {
hasMinYarnPnp: hasMinYarnPnp,
hasMaxYarnPnp: hasMaxYarnPnp,
yarnVersion: yarnVersion,
};
}
Expand Down