|
10 | 10 | import fs from 'fs-extra';
|
11 | 11 | import path from 'path';
|
12 | 12 | import {createRequire} from 'module';
|
| 13 | +import shell from 'shelljs'; |
13 | 14 | import logger from '@docusaurus/logger';
|
14 | 15 | import semver from 'semver';
|
15 | 16 | import updateNotifier from 'update-notifier';
|
@@ -105,18 +106,33 @@ export default async function beforeCli() {
|
105 | 106 | .map((p) => p.concat('@latest'))
|
106 | 107 | .join(' ');
|
107 | 108 |
|
| 109 | + const getYarnVersion = async () => { |
| 110 | + if (!(await fs.pathExists(path.resolve('yarn.lock')))) { |
| 111 | + return undefined; |
| 112 | + } |
| 113 | + |
| 114 | + const yarnVersionResult = shell.exec('yarn --version', {silent: true}); |
| 115 | + if (yarnVersionResult?.code === 0) { |
| 116 | + const majorVersion = parseInt( |
| 117 | + yarnVersionResult.stdout?.trim().split('.')[0] ?? '', |
| 118 | + 10, |
| 119 | + ); |
| 120 | + if (!Number.isNaN(majorVersion)) { |
| 121 | + return majorVersion; |
| 122 | + } |
| 123 | + } |
| 124 | + |
| 125 | + return undefined; |
| 126 | + }; |
| 127 | + |
108 | 128 | const getUpgradeCommand = async () => {
|
109 |
| - const isYarnUsed = await fs.pathExists(path.resolve('yarn.lock')); |
110 |
| - if (!isYarnUsed) { |
| 129 | + const yarnVersion = await getYarnVersion(); |
| 130 | + if (!yarnVersion) { |
111 | 131 | return `npm i ${siteDocusaurusPackagesForUpdate}`;
|
112 | 132 | }
|
113 |
| - |
114 |
| - const isYarnClassicUsed = !(await fs.pathExists( |
115 |
| - path.resolve('.yarnrc.yml'), |
116 |
| - )); |
117 |
| - return isYarnClassicUsed |
118 |
| - ? `yarn upgrade ${siteDocusaurusPackagesForUpdate}` |
119 |
| - : `yarn up ${siteDocusaurusPackagesForUpdate}`; |
| 133 | + return yarnVersion >= 2 |
| 134 | + ? `yarn up ${siteDocusaurusPackagesForUpdate}` |
| 135 | + : `yarn upgrade ${siteDocusaurusPackagesForUpdate}`; |
120 | 136 | };
|
121 | 137 |
|
122 | 138 | /** @type {import('boxen').Options} */
|
|
0 commit comments