Skip to content

Commit 6ce51f3

Browse files
committed
Fix minimumNodeVersion setting
1 parent e1a398f commit 6ce51f3

File tree

1 file changed

+43
-44
lines changed

1 file changed

+43
-44
lines changed

src/utils/package-manager-detector.ts

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,11 @@ import { isNonEmptyString } from './strings'
1313

1414
import type { Content as PackageJsonContent } from '@npmcli/package-json'
1515

16-
const PNPM_WORKSPACE = 'pnpm-workspace'
17-
1816
export const AGENTS = ['bun', 'npm', 'pnpm', 'yarn'] as const
19-
2017
export type AgentPlusBun = (typeof AGENTS)[number]
2118
export type Agent = Exclude<AgentPlusBun, 'bun'>
2219
export type StringKeyValueObject = { [key: string]: string }
2320

24-
export const LOCKS: Record<string, string> = {
25-
'bun.lockb': 'bun',
26-
'pnpm-lock.yaml': 'pnpm',
27-
'pnpm-lock.yml': 'pnpm',
28-
'yarn.lock': 'yarn',
29-
// If both package-lock.json and npm-shrinkwrap.json are present in the root
30-
// of a project, npm-shrinkwrap.json will take precedence and package-lock.json
31-
// will be ignored.
32-
// https://docs.npmjs.com/cli/v10/configuring-npm/package-lock-json#package-lockjson-vs-npm-shrinkwrapjson
33-
'npm-shrinkwrap.json': 'npm',
34-
'package-lock.json': 'npm',
35-
// Look for a hidden lock file if .npmrc has package-lock=false:
36-
// https://docs.npmjs.com/cli/v10/configuring-npm/package-lock-json#hidden-lockfiles
37-
//
38-
// Unlike the other LOCKS keys this key contains a directory AND filename so
39-
// it has to be handled differently.
40-
'node_modules/.package-lock.json': 'npm'
41-
}
42-
4321
const numericCollator = new Intl.Collator(undefined, {
4422
numeric: true,
4523
sensitivity: 'base'
@@ -85,29 +63,26 @@ const maintainedNodeVersions = (() => {
8563
)
8664
})()
8765

88-
export type DetectOptions = {
89-
cwd?: string
90-
onUnknown?: (pkgManager: string | undefined) => void
66+
const LOCKS: Record<string, string> = {
67+
'bun.lockb': 'bun',
68+
'pnpm-lock.yaml': 'pnpm',
69+
'pnpm-lock.yml': 'pnpm',
70+
'yarn.lock': 'yarn',
71+
// If both package-lock.json and npm-shrinkwrap.json are present in the root
72+
// of a project, npm-shrinkwrap.json will take precedence and package-lock.json
73+
// will be ignored.
74+
// https://docs.npmjs.com/cli/v10/configuring-npm/package-lock-json#package-lockjson-vs-npm-shrinkwrapjson
75+
'npm-shrinkwrap.json': 'npm',
76+
'package-lock.json': 'npm',
77+
// Look for a hidden lock file if .npmrc has package-lock=false:
78+
// https://docs.npmjs.com/cli/v10/configuring-npm/package-lock-json#hidden-lockfiles
79+
//
80+
// Unlike the other LOCKS keys this key contains a directory AND filename so
81+
// it has to be handled differently.
82+
'node_modules/.package-lock.json': 'npm'
9183
}
9284

93-
export type DetectResult = Readonly<{
94-
agent: AgentPlusBun
95-
agentExecPath: string
96-
agentVersion: string | undefined
97-
isPrivate: boolean
98-
isWorkspace: boolean
99-
lockPath: string | undefined
100-
lockSrc: string | undefined
101-
minimumNodeVersion: string
102-
pkgJson: PackageJsonContent | undefined
103-
pkgJsonPath: string | undefined
104-
pkgJsonStr: string | undefined
105-
supported: boolean
106-
targets: {
107-
browser: boolean
108-
node: boolean
109-
}
110-
}>
85+
const PNPM_WORKSPACE = 'pnpm-workspace'
11186

11287
type ReadLockFile = (
11388
lockPath: string,
@@ -149,6 +124,30 @@ const readLockFileByAgent: Record<AgentPlusBun, ReadLockFile> = (() => {
149124
}
150125
})()
151126

127+
export type DetectOptions = {
128+
cwd?: string
129+
onUnknown?: (pkgManager: string | undefined) => void
130+
}
131+
132+
export type DetectResult = Readonly<{
133+
agent: AgentPlusBun
134+
agentExecPath: string
135+
agentVersion: string | undefined
136+
isPrivate: boolean
137+
isWorkspace: boolean
138+
lockPath: string | undefined
139+
lockSrc: string | undefined
140+
minimumNodeVersion: string
141+
pkgJson: PackageJsonContent | undefined
142+
pkgJsonPath: string | undefined
143+
pkgJsonStr: string | undefined
144+
supported: boolean
145+
targets: {
146+
browser: boolean
147+
node: boolean
148+
}
149+
}>
150+
152151
export async function detect({
153152
cwd = process.cwd(),
154153
onUnknown
@@ -222,7 +221,7 @@ export async function detect({
222221
const nodeRange = (pkgJson as any)['engines']?.['node']
223222
if (isNonEmptyString(nodeRange)) {
224223
const coerced = semver.coerce(nodeRange)
225-
if (coerced) {
224+
if (coerced && semver.lt(coerced, minimumNodeVersion)) {
226225
minimumNodeVersion = coerced.version
227226
}
228227
}

0 commit comments

Comments
 (0)