@@ -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,37 @@ 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+ const parsedYarnLockFile = parseYarnLockFile ( lockFileString )
35+ if ( parsedYarnLockFile . type !== "success" ) {
36+ throw new Error ( "Could not parse yarn v1 lock file" )
37+ } else {
38+ appLockFile = parsedYarnLockFile . object
39+ }
40+ } else {
41+ try {
42+ appLockFile = yaml . parse ( lockFileString )
43+ } catch ( e ) {
44+ console . error ( e )
45+ throw new Error ( "Could not parse yarn v2 lock file" )
46+ }
3347 }
3448
3549 const installedVersion = getPackageVersion (
3650 join ( resolve ( appPath , packageDetails . path ) , "package.json" ) ,
3751 )
3852
39- const entries = Object . entries ( appLockFile . object ) . filter (
53+ const entries = Object . entries ( appLockFile ) . filter (
4054 ( [ k , v ] ) =>
4155 k . startsWith ( packageDetails . name + "@" ) &&
56+ // @ts -ignore
4257 v . version === installedVersion ,
4358 )
4459
4560 const resolutions = entries . map ( ( [ _ , v ] ) => {
61+ // @ts -ignore
4662 return v . resolved
4763 } )
4864
@@ -70,6 +86,10 @@ export function getPackageResolution({
7086 return `file:${ resolve ( appPath , resolution . slice ( "file:" . length ) ) } `
7187 }
7288
89+ if ( resolution . startsWith ( "npm:" ) ) {
90+ return resolution . replace ( "npm:" , "" )
91+ }
92+
7393 return resolution
7494 } else {
7595 const lockfile = require ( join (
0 commit comments