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
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 16 additions & 6 deletions packages/docusaurus/bin/beforeCli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import fs from 'fs-extra';
import path from 'path';
import Yaml from 'js-yaml';
import {createRequire} from 'module';
import logger from '@docusaurus/logger';
import semver from 'semver';
Expand Down Expand Up @@ -111,12 +112,21 @@ export default async function beforeCli() {
return `npm i ${siteDocusaurusPackagesForUpdate}`;
}

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

try {
const yamlData = Yaml.load(await fs.readFile(path.resolve('.yarnrc.yml'), 'utf8'));
// @ts-expect-error: yamlData is not typed
const isYarn2PlusUsed = 'yarnPath' in yamlData && !yamlData.yarnPath.includes('yarn-1.');
return isYarn2PlusUsed
? `yarn up ${siteDocusaurusPackagesForUpdate}`
: `yarn upgrade ${siteDocusaurusPackagesForUpdate}`;
} catch {
return `yarn upgrade ${siteDocusaurusPackagesForUpdate}`;
}
};

/** @type {import('boxen').Options} */
Expand Down
1 change: 1 addition & 0 deletions packages/docusaurus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"html-tags": "^3.2.0",
"html-webpack-plugin": "^5.5.0",
"import-fresh": "^3.3.0",
"js-yaml": "^4.1.0",
"leven": "^3.1.0",
"lodash": "^4.17.21",
"mini-css-extract-plugin": "^2.7.3",
Expand Down