Skip to content

Commit 107ccf3

Browse files
committed
fix: resolve workspace paths from an optional directory
1 parent 510f0ec commit 107ccf3

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

lib/base-command.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class BaseCommand {
8181
const ws = await getWorkspaces(filters, {
8282
path: this.npm.localPrefix,
8383
includeWorkspaceRoot: this.includeWorkspaceRoot,
84+
relativeFrom: process.cwd(),
8485
})
8586
this.workspaces = ws
8687
this.workspaceNames = [...ws.keys()]

lib/workspaces/get-workspaces.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const rpj = require('read-package-json-fast')
55

66
// Returns an Map of paths to workspaces indexed by workspace name
77
// { foo => '/path/to/foo' }
8-
const getWorkspaces = async (filters, { path, includeWorkspaceRoot }) => {
8+
const getWorkspaces = async (filters, { path, includeWorkspaceRoot, relativeFrom }) => {
99
// TODO we need a better error to be bubbled up here if this rpj call fails
1010
const pkg = await rpj(resolve(path, 'package.json'))
1111
const workspaces = await mapWorkspaces({ cwd: path, pkg })
@@ -21,8 +21,8 @@ const getWorkspaces = async (filters, { path, includeWorkspaceRoot }) => {
2121
for (const filterArg of filters) {
2222
for (const [workspaceName, workspacePath] of workspaces.entries()) {
2323
if (filterArg === workspaceName
24-
|| resolve(path, filterArg) === workspacePath
25-
|| minimatch(workspacePath, `${resolve(path, filterArg)}/*`)) {
24+
|| resolve(relativeFrom || path, filterArg) === workspacePath
25+
|| minimatch(workspacePath, `${resolve(relativeFrom || path, filterArg)}/*`)) {
2626
res.set(workspaceName, workspacePath)
2727
}
2828
}

0 commit comments

Comments
 (0)