From c5e953bcafa2e59d1f17210f7403ef93f6ac6897 Mon Sep 17 00:00:00 2001 From: fz6m <59400654+fz6m@users.noreply.github.com> Date: Sun, 17 Mar 2024 10:07:33 +0900 Subject: [PATCH] chore: update deps for lower pnpm 8 versions only --- packages/create-umi/src/index.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/create-umi/src/index.ts b/packages/create-umi/src/index.ts index a3157a03f0e5..759ae4cc99c3 100644 --- a/packages/create-umi/src/index.ts +++ b/packages/create-umi/src/index.ts @@ -8,6 +8,7 @@ import { installWithNpmClient, logger, pkgUp, + semver, tryPaths, yParser, } from '@umijs/utils'; @@ -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 @@ -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 }); } @@ -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 }); }