From 123bcbc8333b1ddce312618b1b0ae6ebb6326346 Mon Sep 17 00:00:00 2001 From: winches <329487092@qq.com> Date: Sat, 7 Dec 2024 17:31:08 +0800 Subject: [PATCH] fix: upgrade peerDep version required min version --- src/helpers/utils.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/helpers/utils.ts b/src/helpers/utils.ts index 350e939..ab4920f 100644 --- a/src/helpers/utils.ts +++ b/src/helpers/utils.ts @@ -2,6 +2,7 @@ import type {Agent} from './detect'; import type {PascalCase, SAFE_ANY} from './type'; import chalk from 'chalk'; +import {compareVersions} from 'compare-versions'; import fg, {type Options} from 'fast-glob'; import {ROOT} from 'src/constants/path'; @@ -164,10 +165,24 @@ export function getPackageManagerInfo(packageManager: T /** * @example transformPeerVersion('>=1.0.0') // '1.0.0' + * @example transformPeerVersion(">=11.5.6 || >=12.0.0-alpha.1") // 11.5.6 * @param version */ -export function transformPeerVersion(version: string) { - return version.replace(/\^|~|>=|<=|>| r.trim()); + const result = ranges + .map((range) => { + return range.replace(/^[<=>^~]+\s*/, '').trim(); + }) + .sort((a, b) => { + if (isLatest) { + return compareVersions(b, a); + } + + return compareVersions(a, b); + }); + + return result[0]!; } export function fillAnsiLength(str: string, length: number) {