@@ -13,33 +13,11 @@ import { isNonEmptyString } from './strings'
13
13
14
14
import type { Content as PackageJsonContent } from '@npmcli/package-json'
15
15
16
- const PNPM_WORKSPACE = 'pnpm-workspace'
17
-
18
16
export const AGENTS = [ 'bun' , 'npm' , 'pnpm' , 'yarn' ] as const
19
-
20
17
export type AgentPlusBun = ( typeof AGENTS ) [ number ]
21
18
export type Agent = Exclude < AgentPlusBun , 'bun' >
22
19
export type StringKeyValueObject = { [ key : string ] : string }
23
20
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
-
43
21
const numericCollator = new Intl . Collator ( undefined , {
44
22
numeric : true ,
45
23
sensitivity : 'base'
@@ -85,29 +63,26 @@ const maintainedNodeVersions = (() => {
85
63
)
86
64
} ) ( )
87
65
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'
91
83
}
92
84
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'
111
86
112
87
type ReadLockFile = (
113
88
lockPath : string ,
@@ -149,6 +124,30 @@ const readLockFileByAgent: Record<AgentPlusBun, ReadLockFile> = (() => {
149
124
}
150
125
} ) ( )
151
126
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
+
152
151
export async function detect ( {
153
152
cwd = process . cwd ( ) ,
154
153
onUnknown
@@ -222,7 +221,7 @@ export async function detect({
222
221
const nodeRange = ( pkgJson as any ) [ 'engines' ] ?. [ 'node' ]
223
222
if ( isNonEmptyString ( nodeRange ) ) {
224
223
const coerced = semver . coerce ( nodeRange )
225
- if ( coerced ) {
224
+ if ( coerced && semver . lt ( coerced , minimumNodeVersion ) ) {
226
225
minimumNodeVersion = coerced . version
227
226
}
228
227
}
0 commit comments