From 704841fc5882899e4c77d0f8c46977a988055a46 Mon Sep 17 00:00:00 2001 From: Andrew Lyons Date: Thu, 20 Apr 2023 22:54:04 +0800 Subject: [PATCH] fix(core): Correct yarn upgrade command for yarn 2.x (#8908) Co-authored-by: sebastienlorber --- packages/docusaurus/bin/beforeCli.mjs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/docusaurus/bin/beforeCli.mjs b/packages/docusaurus/bin/beforeCli.mjs index 238939f2a0b8..da868f2330eb 100644 --- a/packages/docusaurus/bin/beforeCli.mjs +++ b/packages/docusaurus/bin/beforeCli.mjs @@ -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 = { @@ -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, );