Skip to content

Commit

Permalink
preliminary support for yarn workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
ds300 committed Mar 26, 2019
1 parent 20d3be4 commit e3f8c94
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"@yarnpkg/lockfile": "^1.1.0",
"chalk": "^2.4.2",
"cross-spawn": "^6.0.5",
"find-yarn-workspace-root": "^1.2.1",
"fs-extra": "^7.0.1",
"is-ci": "^2.0.0",
"klaw-sync": "^6.0.0",
Expand Down
3 changes: 2 additions & 1 deletion src/detectPackageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from "fs-extra"
import { join } from "./path"
import chalk from "chalk"
import process from "process"
import findWorkspaceRoot from "find-yarn-workspace-root"

export type PackageManager = "yarn" | "npm" | "npm-shrinkwrap"

Expand Down Expand Up @@ -61,7 +62,7 @@ export const detectPackageManager = (
} else {
return shrinkWrapExists ? "npm-shrinkwrap" : "npm"
}
} else if (yarnLockExists) {
} else if (yarnLockExists || findWorkspaceRoot()) {
return "yarn"
} else {
printNoLockfilesError()
Expand Down
16 changes: 14 additions & 2 deletions src/getPackageResolution.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { join, resolve } from "./path"
import { PackageDetails, getPatchDetailsFromCliString } from "./PackageDetails"
import { PackageManager, detectPackageManager } from "./detectPackageManager"
import { readFileSync } from "fs-extra"
import { readFileSync, existsSync } from "fs-extra"
import { parse as parseYarnLockFile } from "@yarnpkg/lockfile"
import findWorkspaceRoot from "find-yarn-workspace-root"

export function getPackageResolution({
packageDetails,
Expand All @@ -14,7 +15,18 @@ export function getPackageResolution({
appPath: string
}) {
if (packageManager === "yarn") {
const appLockFile = parseYarnLockFile(readFileSync("yarn.lock").toString())
let lockFilePath = "yarn.lock"
if (!existsSync(lockFilePath)) {
const workspaceRoot = findWorkspaceRoot()
if (!workspaceRoot) {
throw new Error("Can't find yarn.lock file")
}
lockFilePath = join(workspaceRoot, "yarn.lock")
}
if (!existsSync(lockFilePath)) {
throw new Error("Can't find yarn.lock file")
}
const appLockFile = parseYarnLockFile(readFileSync(lockFilePath).toString())
if (appLockFile.type !== "success") {
throw new Error("Can't parse lock file")
}
Expand Down
17 changes: 17 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,14 @@ find-up@^3.0.0:
dependencies:
locate-path "^3.0.0"

find-yarn-workspace-root@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/find-yarn-workspace-root/-/find-yarn-workspace-root-1.2.1.tgz#40eb8e6e7c2502ddfaa2577c176f221422f860db"
integrity sha512-dVtfb0WuQG+8Ag2uWkbG79hOUzEsRrhBzgfn86g2sJPkzmcpGdghbNTfUKGTxymFrY/tLIodDzLoW9nOJ4FY8Q==
dependencies:
fs-extra "^4.0.3"
micromatch "^3.1.4"

fn-name@~2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/fn-name/-/fn-name-2.0.1.tgz#5214d7537a4d06a4a301c0cc262feb84188002e7"
Expand Down Expand Up @@ -1609,6 +1617,15 @@ fragment-cache@^0.2.1:
dependencies:
map-cache "^0.2.2"

fs-extra@^4.0.3:
version "4.0.3"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-4.0.3.tgz#0d852122e5bc5beb453fb028e9c0c9bf36340c94"
integrity sha512-q6rbdDd1o2mAnQreO7YADIxf/Whx4AHBiRf6d+/cVT8h44ss+lHgxf1FemcqDnQt9X3ct4McHr+JMGlYSsK7Cg==
dependencies:
graceful-fs "^4.1.2"
jsonfile "^4.0.0"
universalify "^0.1.0"

fs-extra@^7.0.1:
version "7.0.1"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-7.0.1.tgz#4f189c44aa123b895f722804f55ea23eadc348e9"
Expand Down

0 comments on commit e3f8c94

Please sign in to comment.