File tree Expand file tree Collapse file tree 4 files changed +34
-3
lines changed Expand file tree Collapse file tree 4 files changed +34
-3
lines changed Original file line number Diff line number Diff line change 7070 "@yarnpkg/lockfile" : " ^1.1.0" ,
7171 "chalk" : " ^2.4.2" ,
7272 "cross-spawn" : " ^6.0.5" ,
73+ "find-yarn-workspace-root" : " ^1.2.1" ,
7374 "fs-extra" : " ^7.0.1" ,
7475 "is-ci" : " ^2.0.0" ,
7576 "klaw-sync" : " ^6.0.0" ,
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import fs from "fs-extra"
22import { join } from "./path"
33import chalk from "chalk"
44import process from "process"
5+ import findWorkspaceRoot from "find-yarn-workspace-root"
56
67export type PackageManager = "yarn" | "npm" | "npm-shrinkwrap"
78
@@ -61,7 +62,7 @@ export const detectPackageManager = (
6162 } else {
6263 return shrinkWrapExists ? "npm-shrinkwrap" : "npm"
6364 }
64- } else if ( yarnLockExists ) {
65+ } else if ( yarnLockExists || findWorkspaceRoot ( ) ) {
6566 return "yarn"
6667 } else {
6768 printNoLockfilesError ( )
Original file line number Diff line number Diff line change 11import { join , resolve } from "./path"
22import { PackageDetails , getPatchDetailsFromCliString } from "./PackageDetails"
33import { PackageManager , detectPackageManager } from "./detectPackageManager"
4- import { readFileSync } from "fs-extra"
4+ import { readFileSync , existsSync } from "fs-extra"
55import { parse as parseYarnLockFile } from "@yarnpkg/lockfile"
6+ import findWorkspaceRoot from "find-yarn-workspace-root"
67
78export function getPackageResolution ( {
89 packageDetails,
@@ -14,7 +15,18 @@ export function getPackageResolution({
1415 appPath : string
1516} ) {
1617 if ( packageManager === "yarn" ) {
17- const appLockFile = parseYarnLockFile ( readFileSync ( "yarn.lock" ) . toString ( ) )
18+ let lockFilePath = "yarn.lock"
19+ if ( ! existsSync ( lockFilePath ) ) {
20+ const workspaceRoot = findWorkspaceRoot ( )
21+ if ( ! workspaceRoot ) {
22+ throw new Error ( "Can't find yarn.lock file" )
23+ }
24+ lockFilePath = join ( workspaceRoot , "yarn.lock" )
25+ }
26+ if ( ! existsSync ( lockFilePath ) ) {
27+ throw new Error ( "Can't find yarn.lock file" )
28+ }
29+ const appLockFile = parseYarnLockFile ( readFileSync ( lockFilePath ) . toString ( ) )
1830 if ( appLockFile . type !== "success" ) {
1931 throw new Error ( "Can't parse lock file" )
2032 }
Original file line number Diff line number Diff line change @@ -1580,6 +1580,14 @@ find-up@^3.0.0:
15801580 dependencies :
15811581 locate-path "^3.0.0"
15821582
1583+ find-yarn-workspace-root@^1.2.1 :
1584+ version "1.2.1"
1585+ resolved "https://registry.yarnpkg.com/find-yarn-workspace-root/-/find-yarn-workspace-root-1.2.1.tgz#40eb8e6e7c2502ddfaa2577c176f221422f860db"
1586+ integrity sha512-dVtfb0WuQG+8Ag2uWkbG79hOUzEsRrhBzgfn86g2sJPkzmcpGdghbNTfUKGTxymFrY/tLIodDzLoW9nOJ4FY8Q==
1587+ dependencies :
1588+ fs-extra "^4.0.3"
1589+ micromatch "^3.1.4"
1590+
15831591fn-name@~2.0.1 :
15841592 version "2.0.1"
15851593 resolved "https://registry.yarnpkg.com/fn-name/-/fn-name-2.0.1.tgz#5214d7537a4d06a4a301c0cc262feb84188002e7"
@@ -1609,6 +1617,15 @@ fragment-cache@^0.2.1:
16091617 dependencies :
16101618 map-cache "^0.2.2"
16111619
1620+ fs-extra@^4.0.3 :
1621+ version "4.0.3"
1622+ resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-4.0.3.tgz#0d852122e5bc5beb453fb028e9c0c9bf36340c94"
1623+ integrity sha512-q6rbdDd1o2mAnQreO7YADIxf/Whx4AHBiRf6d+/cVT8h44ss+lHgxf1FemcqDnQt9X3ct4McHr+JMGlYSsK7Cg==
1624+ dependencies :
1625+ graceful-fs "^4.1.2"
1626+ jsonfile "^4.0.0"
1627+ universalify "^0.1.0"
1628+
16121629fs-extra@^7.0.1 :
16131630 version "7.0.1"
16141631 resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-7.0.1.tgz#4f189c44aa123b895f722804f55ea23eadc348e9"
You can’t perform that action at this time.
0 commit comments