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(core): docusaurus CLI should detect the correct yarn version when suggesting upgrades #9006

Merged
merged 6 commits into from
May 31, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 23 additions & 7 deletions packages/docusaurus/bin/beforeCli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import fs from 'fs-extra';
import path from 'path';
import {createRequire} from 'module';
import shell from 'shelljs';
import logger from '@docusaurus/logger';
import semver from 'semver';
import updateNotifier from 'update-notifier';
Expand Down Expand Up @@ -105,16 +106,31 @@ export default async function beforeCli() {
.map((p) => p.concat('@latest'))
.join(' ');

const getYarnVersion = async () => {
const fallbackYarnVersion = 1;
const yarnVersionResult = shell.exec('yarn --version');
if (yarnVersionResult?.code === 0) {
const yarnVersionOutput = yarnVersionResult.stdout?.trim();
const majorVersion = parseInt(
yarnVersionOutput?.split('.')[0] ?? '',
10,
);
if (typeof majorVersion === 'number' && !Number.isNaN(majorVersion)) {
return majorVersion;
0420syj marked this conversation as resolved.
Show resolved Hide resolved
}
}
if (await fs.pathExists(path.resolve('yarn.lock'))) {
return fallbackYarnVersion;
}
return undefined;
};

const getUpgradeCommand = async () => {
const isYarnUsed = await fs.pathExists(path.resolve('yarn.lock'));
if (!isYarnUsed) {
const yarnVersion = await getYarnVersion();
if (!yarnVersion) {
return `npm i ${siteDocusaurusPackagesForUpdate}`;
}

const isYarnClassicUsed = !(await fs.pathExists(
path.resolve('.yarnrc.yml'),
));
return isYarnClassicUsed
return yarnVersion === 1
? `yarn upgrade ${siteDocusaurusPackagesForUpdate}`
: `yarn up ${siteDocusaurusPackagesForUpdate}`;
};
Expand Down