@@ -16,7 +16,16 @@ import { existsSync, findUp, readFileBinary, readFileUtf8 } from './fs'
16
16
import type { EditablePackageJson } from '@socketsecurity/registry/lib/packages'
17
17
import type { SemVer } from 'semver'
18
18
19
- const { BUN , NPM , PNPM , VLT , YARN_BERRY , YARN_CLASSIC } = constants
19
+ const {
20
+ BINARY_LOCK_EXT ,
21
+ BUN ,
22
+ LOCK_EXT ,
23
+ NPM ,
24
+ PNPM ,
25
+ VLT ,
26
+ YARN_BERRY ,
27
+ YARN_CLASSIC
28
+ } = constants
20
29
21
30
export const AGENTS = [ BUN , NPM , PNPM , YARN_BERRY , YARN_CLASSIC , VLT ] as const
22
31
export type Agent = ( typeof AGENTS ) [ number ]
@@ -46,9 +55,10 @@ async function getAgentVersion(
46
55
return result
47
56
}
48
57
58
+ // The order of LOCKS properties IS significant as it affects iteration order.
49
59
const LOCKS : Record < string , Agent > = {
50
- ' bun.lock' : BUN ,
51
- ' bun.lockb' : BUN ,
60
+ [ ` bun${ LOCK_EXT } ` ] : BUN ,
61
+ [ ` bun${ BINARY_LOCK_EXT } ` ] : BUN ,
52
62
// If both package-lock.json and npm-shrinkwrap.json are present in the root
53
63
// of a project, npm-shrinkwrap.json will take precedence and package-lock.json
54
64
// will be ignored.
@@ -57,9 +67,9 @@ const LOCKS: Record<string, Agent> = {
57
67
'package-lock.json' : NPM ,
58
68
'pnpm-lock.yaml' : PNPM ,
59
69
'pnpm-lock.yml' : PNPM ,
60
- ' yarn.lock' : YARN_CLASSIC ,
70
+ [ ` yarn${ LOCK_EXT } ` ] : YARN_CLASSIC ,
61
71
'vlt-lock.json' : VLT ,
62
- // Look for a hidden lock file if .npmrc has package-lock=false:
72
+ // Lastly, look for a hidden lock file which is present if .npmrc has package-lock=false:
63
73
// https://docs.npmjs.com/cli/v10/configuring-npm/package-lock-json#hidden-lockfiles
64
74
//
65
75
// Unlike the other LOCKS keys this key contains a directory AND filename so
@@ -92,10 +102,10 @@ const readLockFileByAgent: Record<Agent, ReadLockFile> = (() => {
92
102
return {
93
103
[ BUN ] : wrapReader ( async ( lockPath : string , agentExecPath : string ) => {
94
104
const ext = path . extname ( lockPath )
95
- if ( ext === '.lock' ) {
105
+ if ( ext === LOCK_EXT ) {
96
106
return await defaultReader ( lockPath )
97
107
}
98
- if ( ext === '.lockb' ) {
108
+ if ( ext === BINARY_LOCK_EXT ) {
99
109
const lockBuffer = await binaryReader ( lockPath )
100
110
if ( lockBuffer ) {
101
111
try {
@@ -107,6 +117,7 @@ const readLockFileByAgent: Record<Agent, ReadLockFile> = (() => {
107
117
// https://bun.sh/guides/install/yarnlock
108
118
return ( await spawn ( agentExecPath , [ lockPath ] ) ) . stdout . trim ( )
109
119
}
120
+ return undefined
110
121
} ) ,
111
122
[ NPM ] : defaultReader ,
112
123
[ PNPM ] : defaultReader ,
0 commit comments