mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-06 21:03:47 +02:00
fix(core): docusaurus CLI should detect the correct yarn version when suggesting upgrades (#9006)
* fix(core): Correct yarn version detection Correct yarn version detection by checking `yarnPath` value inside `.yarnrc.yml` file Add js-yaml in package.json * Change to use `shelljs` instead of `js-yaml` * Change echo mode to silent * Check `yarn.lock` exist, before version checking * Remove unnecessary optional chaining Nullish coalescing operator still provides the fallback value Co-authored-by: Joshua Chen <sidachen2003@gmail.com> --------- Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
This commit is contained in:
parent
6939444c31
commit
b4087720cb
1 changed files with 26 additions and 10 deletions
|
@ -10,6 +10,7 @@
|
|||
import fs from 'fs-extra';
|
||||
import path from 'path';
|
||||
import {createRequire} from 'module';
|
||||
import shell from 'shelljs';
|
||||
import logger from '@docusaurus/logger';
|
||||
import semver from 'semver';
|
||||
import updateNotifier from 'update-notifier';
|
||||
|
@ -105,18 +106,33 @@ export default async function beforeCli() {
|
|||
.map((p) => p.concat('@latest'))
|
||||
.join(' ');
|
||||
|
||||
const getUpgradeCommand = async () => {
|
||||
const isYarnUsed = await fs.pathExists(path.resolve('yarn.lock'));
|
||||
if (!isYarnUsed) {
|
||||
return `npm i ${siteDocusaurusPackagesForUpdate}`;
|
||||
const getYarnVersion = async () => {
|
||||
if (!(await fs.pathExists(path.resolve('yarn.lock')))) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const isYarnClassicUsed = !(await fs.pathExists(
|
||||
path.resolve('.yarnrc.yml'),
|
||||
));
|
||||
return isYarnClassicUsed
|
||||
? `yarn upgrade ${siteDocusaurusPackagesForUpdate}`
|
||||
: `yarn up ${siteDocusaurusPackagesForUpdate}`;
|
||||
const yarnVersionResult = shell.exec('yarn --version', {silent: true});
|
||||
if (yarnVersionResult?.code === 0) {
|
||||
const majorVersion = parseInt(
|
||||
yarnVersionResult.stdout?.trim().split('.')[0] ?? '',
|
||||
10,
|
||||
);
|
||||
if (!Number.isNaN(majorVersion)) {
|
||||
return majorVersion;
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
};
|
||||
|
||||
const getUpgradeCommand = async () => {
|
||||
const yarnVersion = await getYarnVersion();
|
||||
if (!yarnVersion) {
|
||||
return `npm i ${siteDocusaurusPackagesForUpdate}`;
|
||||
}
|
||||
return yarnVersion >= 2
|
||||
? `yarn up ${siteDocusaurusPackagesForUpdate}`
|
||||
: `yarn upgrade ${siteDocusaurusPackagesForUpdate}`;
|
||||
};
|
||||
|
||||
/** @type {import('boxen').Options} */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue