@@ -7,6 +7,7 @@ import yaml from "yaml"
7
7
import findWorkspaceRoot from "find-yarn-workspace-root"
8
8
import { getPackageVersion } from "./getPackageVersion"
9
9
import { coerceSemVer } from "./coerceSemVer"
10
+ import { parseBunLockfile } from "./parseBunLockfile"
10
11
11
12
export function getPackageResolution ( {
12
13
packageDetails,
@@ -17,24 +18,32 @@ export function getPackageResolution({
17
18
packageManager : PackageManager
18
19
appPath : string
19
20
} ) {
20
- if ( packageManager === "yarn" ) {
21
- let lockFilePath = "yarn.lock"
21
+ if ( packageManager === "yarn" || packageManager === "bun" ) {
22
+ const isBun = packageManager === "bun"
23
+ const lockFileName = isBun ? "bun.lockb" : "yarn.lock"
24
+ let lockFilePath = lockFileName
22
25
if ( ! existsSync ( lockFilePath ) ) {
23
26
const workspaceRoot = findWorkspaceRoot ( )
24
27
if ( ! workspaceRoot ) {
25
- throw new Error ( " Can't find yarn.lock file" )
28
+ throw new Error ( ` Can't find ${ lockFileName } file` )
26
29
}
27
- lockFilePath = join ( workspaceRoot , "yarn.lock" )
30
+ lockFilePath = join ( workspaceRoot , lockFilePath )
28
31
}
29
32
if ( ! existsSync ( lockFilePath ) ) {
30
- throw new Error ( " Can't find yarn.lock file" )
33
+ throw new Error ( ` Can't find ${ lockFileName } file` )
31
34
}
32
- const lockFileString = readFileSync ( lockFilePath ) . toString ( )
35
+ const lockFileString = isBun
36
+ ? parseBunLockfile ( lockFilePath )
37
+ : readFileSync ( lockFilePath ) . toString ( )
33
38
let appLockFile
34
39
if ( lockFileString . includes ( "yarn lockfile v1" ) ) {
35
40
const parsedYarnLockFile = parseYarnLockFile ( lockFileString )
36
41
if ( parsedYarnLockFile . type !== "success" ) {
37
- throw new Error ( "Could not parse yarn v1 lock file" )
42
+ throw new Error (
43
+ `Could not parse yarn v1 lock file ${
44
+ isBun ? "- was originally a bun.lockb file" : ""
45
+ } `,
46
+ )
38
47
} else {
39
48
appLockFile = parsedYarnLockFile . object
40
49
}
@@ -43,7 +52,11 @@ export function getPackageResolution({
43
52
appLockFile = yaml . parse ( lockFileString )
44
53
} catch ( e ) {
45
54
console . log ( e )
46
- throw new Error ( "Could not parse yarn v2 lock file" )
55
+ throw new Error (
56
+ `Could not parse yarn v2 lock file ${
57
+ isBun ? "- was originally a bun.lockb file (should not happen)" : ""
58
+ } `,
59
+ )
47
60
}
48
61
}
49
62
0 commit comments