Skip to content

Commit

Permalink
fixup! feat: add ls workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
ruyadorno committed May 20, 2021
1 parent eec6224 commit f2c9efa
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
10 changes: 10 additions & 0 deletions docs/content/commands/npm-ls.md
Expand Up @@ -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
Expand Down
22 changes: 15 additions & 7 deletions lib/ls.js
Expand Up @@ -50,7 +50,7 @@ class LS extends ArboristWorkspaceCmd {
'omit',
'link',
'unicode',
'workspace',
...super.params,
]
}

Expand Down Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions tap-snapshots/test/lib/load-all-commands.js.test.cjs
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tap-snapshots/test/lib/utils/npm-usage.js.test.cjs
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f2c9efa

Please sign in to comment.