@@ -3,6 +3,7 @@ import { PackageDetails, getPatchDetailsFromCliString } from "./PackageDetails"
3
3
import { PackageManager , detectPackageManager } from "./detectPackageManager"
4
4
import { readFileSync , existsSync } from "fs-extra"
5
5
import { parse as parseYarnLockFile } from "@yarnpkg/lockfile"
6
+ import yaml from "yaml"
6
7
import findWorkspaceRoot from "find-yarn-workspace-root"
7
8
import { getPackageVersion } from "./getPackageVersion"
8
9
@@ -27,22 +28,35 @@ export function getPackageResolution({
27
28
if ( ! existsSync ( lockFilePath ) ) {
28
29
throw new Error ( "Can't find yarn.lock file" )
29
30
}
30
- const appLockFile = parseYarnLockFile ( readFileSync ( lockFilePath ) . toString ( ) )
31
- if ( appLockFile . type !== "success" ) {
32
- throw new Error ( "Can't parse lock file" )
31
+ const lockFileString = readFileSync ( lockFilePath ) . toString ( )
32
+ let appLockFile
33
+ if ( lockFileString . includes ( "yarn lockfile v1" ) ) {
34
+ appLockFile = parseYarnLockFile ( lockFileString )
35
+ if ( appLockFile . type !== "success" ) {
36
+ throw new Error ( "Can't parse lock file" )
37
+ }
38
+ } else {
39
+ try {
40
+ appLockFile = yaml . parse ( lockFileString )
41
+ } catch ( e ) {
42
+ console . error ( e )
43
+ throw new Error ( "Can't parse lock file" )
44
+ }
33
45
}
34
46
35
47
const installedVersion = getPackageVersion (
36
48
join ( resolve ( appPath , packageDetails . path ) , "package.json" ) ,
37
49
)
38
50
39
- const entries = Object . entries ( appLockFile . object ) . filter (
51
+ const entries = Object . entries ( appLockFile . object || appLockFile ) . filter (
40
52
( [ k , v ] ) =>
41
53
k . startsWith ( packageDetails . name + "@" ) &&
54
+ // @ts -ignore
42
55
v . version === installedVersion ,
43
56
)
44
57
45
58
const resolutions = entries . map ( ( [ _ , v ] ) => {
59
+ // @ts -ignore
46
60
return v . resolved
47
61
} )
48
62
@@ -70,6 +84,10 @@ export function getPackageResolution({
70
84
return `file:${ resolve ( appPath , resolution . slice ( "file:" . length ) ) } `
71
85
}
72
86
87
+ if ( resolution . startsWith ( "npm:" ) ) {
88
+ return resolution . replace ( "npm:" , "" )
89
+ }
90
+
73
91
return resolution
74
92
} else {
75
93
const lockfile = require ( join (
0 commit comments