Skip to content

Instantly share code, notes, and snippets.

@isaacs
Last active May 20, 2021 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacs/4e2a7225e7b9acdf6555536fdb13dcd0 to your computer and use it in GitHub Desktop.
Save isaacs/4e2a7225e7b9acdf6555536fdb13dcd0 to your computer and use it in GitHub Desktop.
diff --git a/docs/content/commands/npm-ls.md b/docs/content/commands/npm-ls.md
index fb752742d..3c6621763 100644
--- a/docs/content/commands/npm-ls.md
+++ b/docs/content/commands/npm-ls.md
@@ -199,6 +199,16 @@ brand new workspace within the project.
This value is not exported to the environment for child processes.
+#### `workspaces`
+
+* Default: false
+* Type: Boolean
+
+Enable running a command in the context of **all** the configured
+workspaces.
+
+This value is not exported to the environment for child processes.
+
<!-- AUTOGENERATED CONFIG DESCRIPTIONS END -->
### See Also
diff --git a/lib/ls.js b/lib/ls.js
index 7e9e65aa8..4e504912a 100644
--- a/lib/ls.js
+++ b/lib/ls.js
@@ -50,7 +50,7 @@ class LS extends ArboristWorkspaceCmd {
'omit',
'link',
'unicode',
- 'workspace',
+ ...super.params,
]
}
@@ -90,14 +90,22 @@ class LS extends ArboristWorkspaceCmd {
const tree = await this.initTree({arb, args })
// filters by workspaces nodes when using -w <workspace-name>
- let filterSet
+ // We only have to filter the first layer of edges, so we don't
+ // explore anything that isn't part of the selected workspace set.
+ let wsNodes
if (this.workspaces && this.workspaces.length)
- filterSet = arb.workspaceDependencySet(tree, this.workspaces)
+ wsNodes = arb.workspaceNodes(tree, this.workspaces)
const filterBySelectedWorkspaces = edge => {
- const node = edge && edge.to && (edge.to.target || edge.to)
- return !filterSet
- || filterSet.size === 0
- || (node && filterSet.has(node))
+ if (!wsNodes || !wsNodes.length)
+ return true
+
+ if (edge.from.isProjectRoot) {
+ return edge.to &&
+ edge.to.isWorkspace &
+ wsNodes.includes(edge.to.target)
+ }
+
+ return true
}
const seenItems = new Set()
diff --git a/tap-snapshots/test/lib/load-all-commands.js.test.cjs b/tap-snapshots/test/lib/load-all-commands.js.test.cjs
index a1f439452..f43b761d1 100644
--- a/tap-snapshots/test/lib/load-all-commands.js.test.cjs
+++ b/tap-snapshots/test/lib/load-all-commands.js.test.cjs
@@ -539,6 +539,8 @@ Options:
[-a|--all] [--json] [-l|--long] [-p|--parseable] [-g|--global] [--depth <depth>]
[--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]] [--link]
[--unicode]
+[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
+[-ws|--workspaces]
alias: la
@@ -587,6 +589,8 @@ Options:
[-a|--all] [--json] [-l|--long] [-p|--parseable] [-g|--global] [--depth <depth>]
[--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]] [--link]
[--unicode]
+[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
+[-ws|--workspaces]
alias: list
diff --git a/tap-snapshots/test/lib/utils/npm-usage.js.test.cjs b/tap-snapshots/test/lib/utils/npm-usage.js.test.cjs
index 776492c4d..f7fd7ccba 100644
--- a/tap-snapshots/test/lib/utils/npm-usage.js.test.cjs
+++ b/tap-snapshots/test/lib/utils/npm-usage.js.test.cjs
@@ -641,6 +641,7 @@ All commands:
[--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]] [--link]
[--unicode]
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
+ [-ws|--workspaces]
alias: la
@@ -684,6 +685,7 @@ All commands:
[--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]] [--link]
[--unicode]
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
+ [-ws|--workspaces]
alias: list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment