@@ -90,7 +90,7 @@ const getOverridesDataByAgent: Record<Agent, GetOverrides> = {
90
90
type AgentLockIncludesFn = ( lockSrc : string , name : string ) => boolean
91
91
92
92
const lockIncludesByAgent : Record < Agent , AgentLockIncludesFn > = ( ( ) => {
93
- const yarn = ( lockSrc : string , name : string ) => {
93
+ function yarnLockIncludes ( lockSrc : string , name : string ) {
94
94
const escapedName = escapeRegExp ( name )
95
95
return new RegExp (
96
96
// Detects the package name in the following cases:
@@ -102,8 +102,9 @@ const lockIncludesByAgent: Record<Agent, AgentLockIncludesFn> = (() => {
102
102
'm'
103
103
) . test ( lockSrc )
104
104
}
105
+
105
106
return {
106
- bun : yarn ,
107
+ bun : yarnLockIncludes ,
107
108
npm ( lockSrc : string , name : string ) {
108
109
// Detects the package name in the following cases:
109
110
// "name":
@@ -126,8 +127,8 @@ const lockIncludesByAgent: Record<Agent, AgentLockIncludesFn> = (() => {
126
127
// "name"
127
128
return lockSrc . includes ( `"${ name } "` )
128
129
} ,
129
- 'yarn/berry' : yarn ,
130
- 'yarn/classic' : yarn
130
+ 'yarn/berry' : yarnLockIncludes ,
131
+ 'yarn/classic' : yarnLockIncludes
131
132
}
132
133
} ) ( )
133
134
@@ -142,6 +143,7 @@ const updateManifestByAgent: Record<Agent, AgentModifyManifestFn> = (() => {
142
143
[ OVERRIDES_FIELD_NAME ] : overrides
143
144
} )
144
145
}
146
+
145
147
function updateResolutions (
146
148
pkgJson : EditablePackageJson ,
147
149
overrides : Overrides
@@ -150,6 +152,7 @@ const updateManifestByAgent: Record<Agent, AgentModifyManifestFn> = (() => {
150
152
[ RESOLUTIONS_FIELD_NAME ] : < PnpmOrYarnOverrides > overrides
151
153
} )
152
154
}
155
+
153
156
return {
154
157
bun : updateResolutions ,
155
158
npm : updateOverrides ,
@@ -201,6 +204,17 @@ const lsByAgent = (() => {
201
204
return JSON . stringify ( [ ...names ] , null , 2 )
202
205
}
203
206
207
+ function parseableToQueryStdout ( stdout : string ) {
208
+ if ( stdout === '' ) {
209
+ return ''
210
+ }
211
+ // Convert the parseable stdout into a json array of unique names.
212
+ // The matchAll regexp looks for a forward (posix) or backward (win32) slash
213
+ // and matches one or more non-slashes until the newline.
214
+ const names = new Set ( stdout . matchAll ( / (?< = [ / \\ ] ) [ ^ / \\ ] + (? = \n ) / g) )
215
+ return JSON . stringify ( [ ...names ] , null , 2 )
216
+ }
217
+
204
218
async function npmQuery ( npmExecPath : string , cwd : string ) : Promise < string > {
205
219
let stdout = ''
206
220
try {
@@ -238,19 +252,17 @@ const lsByAgent = (() => {
238
252
return result
239
253
}
240
254
}
255
+ let stdout = ''
241
256
try {
242
- const { stdout } = await spawn (
243
- agentExecPath ,
244
- [ 'ls' , '--parseable' , '--prod' , '--depth' , 'Infinity' ] ,
245
- { cwd }
246
- )
247
- // Convert the parseable stdout into a json array of unique names.
248
- // The matchAll regexp looks for forward or backward slash followed by
249
- // one or more non-slashes until the newline.
250
- const names = new Set ( stdout . matchAll ( / (?< = [ / \\ ] ) [ ^ / \\ ] + (? = \n ) / g) )
251
- return JSON . stringify ( [ ...names ] , null , 2 )
257
+ stdout = (
258
+ await spawn (
259
+ agentExecPath ,
260
+ [ 'ls' , '--parseable' , '--prod' , '--depth' , 'Infinity' ] ,
261
+ { cwd }
262
+ )
263
+ ) . stdout
252
264
} catch { }
253
- return ''
265
+ return parseableToQueryStdout ( stdout )
254
266
} ,
255
267
async vlt ( agentExecPath : string , cwd : string ) {
256
268
let stdout = ''
@@ -294,14 +306,24 @@ const lsByAgent = (() => {
294
306
295
307
type AgentDepsIncludesFn = ( stdout : string , name : string ) => boolean
296
308
297
- const depsIncludesByAgent : Record < Agent , AgentDepsIncludesFn > = {
298
- bun : ( stdout : string , name : string ) => stdout . includes ( ` ${ name } @` ) ,
299
- npm : ( stdout : string , name : string ) => stdout . includes ( `"${ name } "` ) ,
300
- pnpm : ( stdout : string , name : string ) => stdout . includes ( `"${ name } "` ) ,
301
- vlt : ( stdout : string , name : string ) => stdout . includes ( ` ${ name } @` ) ,
302
- 'yarn/berry' : ( stdout : string , name : string ) => stdout . includes ( ` ${ name } @` ) ,
303
- 'yarn/classic' : ( stdout : string , name : string ) => stdout . includes ( ` ${ name } @` )
304
- }
309
+ const depsIncludesByAgent : Record < Agent , AgentDepsIncludesFn > = ( ( ) => {
310
+ function matchHumanStdout ( stdout : string , name : string ) {
311
+ return stdout . includes ( ` ${ name } @` )
312
+ }
313
+
314
+ function matchQueryStdout ( stdout : string , name : string ) {
315
+ return stdout . includes ( `"${ name } "` )
316
+ }
317
+
318
+ return {
319
+ bun : matchHumanStdout ,
320
+ npm : matchQueryStdout ,
321
+ pnpm : matchQueryStdout ,
322
+ vlt : matchQueryStdout ,
323
+ 'yarn/berry' : matchHumanStdout ,
324
+ 'yarn/classic' : matchHumanStdout
325
+ }
326
+ } ) ( )
305
327
306
328
function getDependencyEntries ( pkgJson : PackageJsonContent ) {
307
329
const {
0 commit comments