@@ -3,6 +3,7 @@ import { PackageDetails, getPatchDetailsFromCliString } from "./PackageDetails"
33import { PackageManager , detectPackageManager } from "./detectPackageManager"
44import { readFileSync , existsSync } from "fs-extra"
55import { parse as parseYarnLockFile } from "@yarnpkg/lockfile"
6+ import yaml from "yaml"
67import findWorkspaceRoot from "find-yarn-workspace-root"
78import { getPackageVersion } from "./getPackageVersion"
89
@@ -27,22 +28,35 @@ export function getPackageResolution({
2728 if ( ! existsSync ( lockFilePath ) ) {
2829 throw new Error ( "Can't find yarn.lock file" )
2930 }
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+ }
3345 }
3446
3547 const installedVersion = getPackageVersion (
3648 join ( resolve ( appPath , packageDetails . path ) , "package.json" ) ,
3749 )
3850
39- const entries = Object . entries ( appLockFile . object ) . filter (
51+ const entries = Object . entries ( appLockFile . object || appLockFile ) . filter (
4052 ( [ k , v ] ) =>
4153 k . startsWith ( packageDetails . name + "@" ) &&
54+ // @ts -ignore
4255 v . version === installedVersion ,
4356 )
4457
4558 const resolutions = entries . map ( ( [ _ , v ] ) => {
59+ // @ts -ignore
4660 return v . resolved
4761 } )
4862
@@ -70,6 +84,10 @@ export function getPackageResolution({
7084 return `file:${ resolve ( appPath , resolution . slice ( "file:" . length ) ) } `
7185 }
7286
87+ if ( resolution . startsWith ( "npm:" ) ) {
88+ return resolution . replace ( "npm:" , "" )
89+ }
90+
7391 return resolution
7492 } else {
7593 const lockfile = require ( join (
0 commit comments