Skip to content

Commit

Permalink
feat(ls): support --virtual flag to enable using the virtual tree
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Jun 13, 2021
1 parent 3f202cd commit 84845bc
Show file tree
Hide file tree
Showing 5 changed files with 809 additions and 7 deletions.
13 changes: 10 additions & 3 deletions lib/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class LS extends ArboristWorkspaceCmd {
'depth',
'omit',
'link',
'virtual',
'unicode',
...super.params,
]
Expand Down Expand Up @@ -79,6 +80,7 @@ class LS extends ArboristWorkspaceCmd {
const prod = this.npm.config.get('prod')
const production = this.npm.config.get('production')
const unicode = this.npm.config.get('unicode')
const virtual = this.npm.config.get('virtual')

const path = global ? resolve(this.npm.globalDir, '..') : this.npm.prefix

Expand All @@ -88,7 +90,7 @@ class LS extends ArboristWorkspaceCmd {
legacyPeerDeps: false,
path,
})
const tree = await this.initTree({arb, args })
const tree = await this.initTree({arb, args, virtual })

// filters by workspaces nodes when using -w <workspace-name>
// We only have to filter the first layer of edges, so we don't
Expand Down Expand Up @@ -216,8 +218,13 @@ class LS extends ArboristWorkspaceCmd {
}
}

async initTree ({ arb, args }) {
const tree = await arb.loadActual()
async initTree ({ arb, args, virtual }) {
const tree = await (
virtual
? arb.loadVirtual()
: arb.loadActual()
)

tree[_include] = args.length === 0
tree[_depth] = 0

Expand Down
9 changes: 9 additions & 0 deletions lib/utils/config/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2054,6 +2054,15 @@ define('viewer', {
`,
})

define('virtual', {
default: false,
type: Boolean,
description: `
Operates in "virtual" mode, meaning that the dependency tree is based off
the lockfile rather than the contents of \`node_modules\`.
`,
})

define('which', {
default: null,
hint: '<fundingSourceNumber>',
Expand Down
4 changes: 2 additions & 2 deletions tap-snapshots/test/lib/load-all-commands.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ npm ll [[<@scope>/]<pkg> ...]
Options:
[-a|--all] [--json] [-l|--long] [-p|--parseable] [-g|--global] [--depth <depth>]
[--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]] [--link]
[--unicode]
[--virtual] [--unicode]
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
[-ws|--workspaces]
Expand Down Expand Up @@ -588,7 +588,7 @@ npm ls npm ls [[<@scope>/]<pkg> ...]
Options:
[-a|--all] [--json] [-l|--long] [-p|--parseable] [-g|--global] [--depth <depth>]
[--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]] [--link]
[--unicode]
[--virtual] [--unicode]
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
[-ws|--workspaces]
Expand Down
4 changes: 2 additions & 2 deletions tap-snapshots/test/lib/utils/npm-usage.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ All commands:
Options:
[-a|--all] [--json] [-l|--long] [-p|--parseable] [-g|--global] [--depth <depth>]
[--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]] [--link]
[--unicode]
[--virtual] [--unicode]
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
[-ws|--workspaces]
Expand Down Expand Up @@ -683,7 +683,7 @@ All commands:
Options:
[-a|--all] [--json] [-l|--long] [-p|--parseable] [-g|--global] [--depth <depth>]
[--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]] [--link]
[--unicode]
[--virtual] [--unicode]
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
[-ws|--workspaces]
Expand Down
Loading

0 comments on commit 84845bc

Please sign in to comment.