Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 704841f

Browse files
andrewnicolsslorber
andcommittedMay 15, 2023
fix(core): Correct yarn upgrade command for yarn 2.x (#8908)
Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com>
1 parent b345e9b commit 704841f

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed
 

‎packages/docusaurus/bin/beforeCli.mjs

+15-5
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,20 @@ export default async function beforeCli() {
104104
.filter((p) => p.startsWith('@docusaurus'))
105105
.map((p) => p.concat('@latest'))
106106
.join(' ');
107-
const isYarnUsed = await fs.pathExists(path.resolve('yarn.lock'));
108-
const upgradeCommand = isYarnUsed
109-
? `yarn upgrade ${siteDocusaurusPackagesForUpdate}`
110-
: `npm i ${siteDocusaurusPackagesForUpdate}`;
107+
108+
const getUpgradeCommand = async () => {
109+
const isYarnUsed = await fs.pathExists(path.resolve('yarn.lock'));
110+
if (!isYarnUsed) {
111+
return `npm i ${siteDocusaurusPackagesForUpdate}`;
112+
}
113+
114+
const isYarnClassicUsed = !(await fs.pathExists(
115+
path.resolve('.yarnrc.yml'),
116+
));
117+
return isYarnClassicUsed
118+
? `yarn upgrade ${siteDocusaurusPackagesForUpdate}`
119+
: `yarn up ${siteDocusaurusPackagesForUpdate}`;
120+
};
111121

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

0 commit comments

Comments
 (0)
Please sign in to comment.