Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/base-command.js8
-rw-r--r--lib/workspaces/get-workspaces.js6
-rw-r--r--test/lib/arborist-cmd.js2
3 files changed, 12 insertions, 4 deletions
diff --git a/lib/base-command.js b/lib/base-command.js
index ad261b514..f67f99f36 100644
--- a/lib/base-command.js
+++ b/lib/base-command.js
@@ -1,4 +1,7 @@
// Base class for npm commands
+
+const { relative } = require('path')
+
const usageUtil = require('./utils/usage.js')
const ConfigDefinitions = require('./utils/config/definitions.js')
const getWorkspaces = require('./workspaces/get-workspaces.js')
@@ -78,9 +81,14 @@ class BaseCommand {
this.includeWorkspaceRoot = false
}
+ const relativeFrom = relative(this.npm.localPrefix, process.cwd()).startsWith('..')
+ ? this.npm.localPrefix
+ : process.cwd()
+
const ws = await getWorkspaces(filters, {
path: this.npm.localPrefix,
includeWorkspaceRoot: this.includeWorkspaceRoot,
+ relativeFrom,
})
this.workspaces = ws
this.workspaceNames = [...ws.keys()]
diff --git a/lib/workspaces/get-workspaces.js b/lib/workspaces/get-workspaces.js
index a59b5a6c5..0cddae2a4 100644
--- a/lib/workspaces/get-workspaces.js
+++ b/lib/workspaces/get-workspaces.js
@@ -5,7 +5,7 @@ const rpj = require('read-package-json-fast')
// Returns an Map of paths to workspaces indexed by workspace name
// { foo => '/path/to/foo' }
-const getWorkspaces = async (filters, { path, includeWorkspaceRoot }) => {
+const getWorkspaces = async (filters, { path, includeWorkspaceRoot, relativeFrom }) => {
// TODO we need a better error to be bubbled up here if this rpj call fails
const pkg = await rpj(resolve(path, 'package.json'))
const workspaces = await mapWorkspaces({ cwd: path, pkg })
@@ -21,8 +21,8 @@ const getWorkspaces = async (filters, { path, includeWorkspaceRoot }) => {
for (const filterArg of filters) {
for (const [workspaceName, workspacePath] of workspaces.entries()) {
if (filterArg === workspaceName
- || resolve(path, filterArg) === workspacePath
- || minimatch(workspacePath, `${resolve(path, filterArg)}/*`)) {
+ || resolve(relativeFrom || path, filterArg) === workspacePath
+ || minimatch(workspacePath, `${resolve(relativeFrom || path, filterArg)}/*`)) {
res.set(workspaceName, workspacePath)
}
}
diff --git a/test/lib/arborist-cmd.js b/test/lib/arborist-cmd.js
index 3db862d23..91d8a7b33 100644
--- a/test/lib/arborist-cmd.js
+++ b/test/lib/arborist-cmd.js
@@ -98,7 +98,7 @@ t.test('handle getWorkspaces raising an error', async t => {
})
class TestCmd extends ArboristCmd {}
const cmd = new TestCmd()
- cmd.npm = {}
+ cmd.npm = { localPrefix: t.testdir() }
await t.rejects(
cmd.execWorkspaces(['foo'], ['a']),