Skip to content

Commit

Permalink
fix(core): Correct yarn upgrade command for yarn 2.x (#8908)
Browse files Browse the repository at this point in the history
Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com>
  • Loading branch information
andrewnicols and slorber committed May 15, 2023
1 parent b345e9b commit 704841f
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions packages/docusaurus/bin/beforeCli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,20 @@ export default async function beforeCli() {
.filter((p) => p.startsWith('@docusaurus'))
.map((p) => p.concat('@latest'))
.join(' ');
const isYarnUsed = await fs.pathExists(path.resolve('yarn.lock'));
const upgradeCommand = isYarnUsed
? `yarn upgrade ${siteDocusaurusPackagesForUpdate}`
: `npm i ${siteDocusaurusPackagesForUpdate}`;

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

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

/** @type {import('boxen').Options} */
const boxenOptions = {
Expand All @@ -124,7 +134,7 @@ export default async function beforeCli() {
)}${logger.green(`${notifier.update.latest}`)}
To upgrade Docusaurus packages with the latest version, run the following command:
${logger.code(upgradeCommand)}`,
${logger.code(await getUpgradeCommand())}`,
boxenOptions,
);

Expand Down

0 comments on commit 704841f

Please sign in to comment.