@@ -7,6 +7,7 @@ import yaml from "yaml"
77import findWorkspaceRoot from "find-yarn-workspace-root"
88import { getPackageVersion } from "./getPackageVersion"
99import { coerceSemVer } from "./coerceSemVer"
10+ import { parseBunLockfile } from "./parseBunLockfile"
1011
1112export function getPackageResolution ( {
1213 packageDetails,
@@ -17,24 +18,32 @@ export function getPackageResolution({
1718 packageManager : PackageManager
1819 appPath : string
1920} ) {
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
2225 if ( ! existsSync ( lockFilePath ) ) {
2326 const workspaceRoot = findWorkspaceRoot ( )
2427 if ( ! workspaceRoot ) {
25- throw new Error ( " Can't find yarn.lock file" )
28+ throw new Error ( ` Can't find ${ lockFileName } file` )
2629 }
27- lockFilePath = join ( workspaceRoot , "yarn.lock" )
30+ lockFilePath = join ( workspaceRoot , lockFilePath )
2831 }
2932 if ( ! existsSync ( lockFilePath ) ) {
30- throw new Error ( " Can't find yarn.lock file" )
33+ throw new Error ( ` Can't find ${ lockFileName } file` )
3134 }
32- const lockFileString = readFileSync ( lockFilePath ) . toString ( )
35+ const lockFileString = isBun
36+ ? parseBunLockfile ( lockFilePath )
37+ : readFileSync ( lockFilePath ) . toString ( )
3338 let appLockFile
3439 if ( lockFileString . includes ( "yarn lockfile v1" ) ) {
3540 const parsedYarnLockFile = parseYarnLockFile ( lockFileString )
3641 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+ )
3847 } else {
3948 appLockFile = parsedYarnLockFile . object
4049 }
@@ -43,7 +52,11 @@ export function getPackageResolution({
4352 appLockFile = yaml . parse ( lockFileString )
4453 } catch ( e ) {
4554 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+ )
4760 }
4861 }
4962
0 commit comments