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): Correct yarn version detection #9005

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 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,23 @@ 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'));

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