@@ -16,7 +16,16 @@ import { existsSync, findUp, readFileBinary, readFileUtf8 } from './fs'
1616import type { EditablePackageJson } from '@socketsecurity/registry/lib/packages'
1717import type { SemVer } from 'semver'
1818
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
2029
2130export const AGENTS = [ BUN , NPM , PNPM , YARN_BERRY , YARN_CLASSIC , VLT ] as const
2231export type Agent = ( typeof AGENTS ) [ number ]
@@ -46,9 +55,10 @@ async function getAgentVersion(
4655 return result
4756}
4857
58+ // The order of LOCKS properties IS significant as it affects iteration order.
4959const LOCKS : Record < string , Agent > = {
50- ' bun.lock' : BUN ,
51- ' bun.lockb' : BUN ,
60+ [ ` bun${ LOCK_EXT } ` ] : BUN ,
61+ [ ` bun${ BINARY_LOCK_EXT } ` ] : BUN ,
5262 // If both package-lock.json and npm-shrinkwrap.json are present in the root
5363 // of a project, npm-shrinkwrap.json will take precedence and package-lock.json
5464 // will be ignored.
@@ -57,9 +67,9 @@ const LOCKS: Record<string, Agent> = {
5767 'package-lock.json' : NPM ,
5868 'pnpm-lock.yaml' : PNPM ,
5969 'pnpm-lock.yml' : PNPM ,
60- ' yarn.lock' : YARN_CLASSIC ,
70+ [ ` yarn${ LOCK_EXT } ` ] : YARN_CLASSIC ,
6171 '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:
6373 // https://docs.npmjs.com/cli/v10/configuring-npm/package-lock-json#hidden-lockfiles
6474 //
6575 // Unlike the other LOCKS keys this key contains a directory AND filename so
@@ -92,10 +102,10 @@ const readLockFileByAgent: Record<Agent, ReadLockFile> = (() => {
92102 return {
93103 [ BUN ] : wrapReader ( async ( lockPath : string , agentExecPath : string ) => {
94104 const ext = path . extname ( lockPath )
95- if ( ext === '.lock' ) {
105+ if ( ext === LOCK_EXT ) {
96106 return await defaultReader ( lockPath )
97107 }
98- if ( ext === '.lockb' ) {
108+ if ( ext === BINARY_LOCK_EXT ) {
99109 const lockBuffer = await binaryReader ( lockPath )
100110 if ( lockBuffer ) {
101111 try {
@@ -107,6 +117,7 @@ const readLockFileByAgent: Record<Agent, ReadLockFile> = (() => {
107117 // https://bun.sh/guides/install/yarnlock
108118 return ( await spawn ( agentExecPath , [ lockPath ] ) ) . stdout . trim ( )
109119 }
120+ return undefined
110121 } ) ,
111122 [ NPM ] : defaultReader ,
112123 [ PNPM ] : defaultReader ,
0 commit comments