Skip to content

Commit

Permalink
fix(core): Correct yarn upgrade command for yarn 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Apr 20, 2023
1 parent f154b2f commit 2c72a76
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'));
const isYarnClassicUsed = !(await fs.pathExists(
path.resolve('.yarnrc.yml'),
));
if (!isYarnUsed) {
return `npm i ${siteDocusaurusPackagesForUpdate}`;
}

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 2c72a76

Please sign in to comment.