Skip to content

Commit

Permalink
chore: update deps for lower pnpm 8 versions only (#12209)
Browse files Browse the repository at this point in the history
  • Loading branch information
fz6m authored Mar 21, 2024
1 parent aa1f9bf commit 5de9123
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions packages/create-umi/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
installWithNpmClient,
logger,
pkgUp,
semver,
tryPaths,
yParser,
} from '@umijs/utils';
Expand Down Expand Up @@ -238,8 +239,11 @@ export default async ({
let pnpmExtraNpmrc: string = '';
const isPnpm = npmClient === ENpmClient.pnpm;
let pnpmMajorVersion: number | undefined;
let pnpmVersion: string | undefined;
if (isPnpm) {
pnpmMajorVersion = await getPnpmMajorVersion();
pnpmVersion = await getPnpmVersion();
pnpmMajorVersion = parseInt(pnpmVersion.split('.')[0], 10);
logger.debug(`pnpm version: ${pnpmVersion}`);
if (pnpmMajorVersion === 7) {
// suppress pnpm v7 warning ( 7.0.0 < pnpm < 7.13.5 )
// https://pnpm.io/npmrc#strict-peer-dependencies
Expand Down Expand Up @@ -295,9 +299,14 @@ export default async ({

// install deps
const isPnpm8 = pnpmMajorVersion === 8;
// https://github.com/pnpm/pnpm/releases/tag/v8.7.0
// https://pnpm.io/npmrc#resolution-mode
const pnpmHighestResolutionMinVersion = '8.7.0';
const isPnpmHighestResolution =
isPnpm8 && semver.gte(pnpmVersion!, pnpmHighestResolutionMinVersion);
if (!useDefaultData && args.install !== false) {
if (isPnpm8) {
await installWithPnpm8(target);
if (isPnpm8 && !isPnpmHighestResolution) {
await installAndUpdateWithPnpm(target);
} else {
installWithNpmClient({ npmClient, cwd: target });
}
Expand Down Expand Up @@ -370,15 +379,14 @@ async function removeHusky(opts: IContext) {

// pnpm v8 will install minimal version of the dependencies
// so we upgrade all deps to the latest version
// https://pnpm.io/npmrc#resolution-mode
async function installWithPnpm8(cwd: string) {
async function installAndUpdateWithPnpm(cwd: string) {
await execa.execa('pnpm', ['up', '-L'], { cwd, stdio: 'inherit' });
}

async function getPnpmMajorVersion() {
async function getPnpmVersion() {
try {
const { stdout } = await execa.execa('pnpm', ['--version']);
return parseInt(stdout.trim().split('.')[0], 10);
return stdout.trim();
} catch (e) {
throw new Error('Please install pnpm first', { cause: e });
}
Expand Down

0 comments on commit 5de9123

Please sign in to comment.