Skip to content

Commit d6d15d7

Browse files
committed
feat(ls): support --virtual flag to enable using the virtual tree
1 parent 3f202cd commit d6d15d7

File tree

7 files changed

+818
-7
lines changed

7 files changed

+818
-7
lines changed

lib/ls.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class LS extends ArboristWorkspaceCmd {
5050
'depth',
5151
'omit',
5252
'link',
53+
'virtual',
5354
'unicode',
5455
...super.params,
5556
]
@@ -79,6 +80,7 @@ class LS extends ArboristWorkspaceCmd {
7980
const prod = this.npm.config.get('prod')
8081
const production = this.npm.config.get('production')
8182
const unicode = this.npm.config.get('unicode')
83+
const virtual = this.npm.config.get('virtual')
8284

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

@@ -88,7 +90,7 @@ class LS extends ArboristWorkspaceCmd {
8890
legacyPeerDeps: false,
8991
path,
9092
})
91-
const tree = await this.initTree({arb, args })
93+
const tree = await this.initTree({arb, args, virtual })
9294

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

219-
async initTree ({ arb, args }) {
220-
const tree = await arb.loadActual()
221+
async initTree ({ arb, args, virtual }) {
222+
const tree = await (
223+
virtual
224+
? arb.loadVirtual()
225+
: arb.loadActual()
226+
)
227+
221228
tree[_include] = args.length === 0
222229
tree[_depth] = 0
223230

lib/utils/config/definitions.js

+9
Original file line numberDiff line numberDiff line change
@@ -2054,6 +2054,15 @@ define('viewer', {
20542054
`,
20552055
})
20562056

2057+
define('virtual', {
2058+
default: false,
2059+
type: Boolean,
2060+
description: `
2061+
Operates in "virtual" mode, meaning that the dependency tree is based off
2062+
the lockfile rather than the contents of \`node_modules\`.
2063+
`,
2064+
})
2065+
20572066
define('which', {
20582067
default: null,
20592068
hint: '<fundingSourceNumber>',

tap-snapshots/test/lib/load-all-commands.js.test.cjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ npm ll [[<@scope>/]<pkg> ...]
538538
Options:
539539
[-a|--all] [--json] [-l|--long] [-p|--parseable] [-g|--global] [--depth <depth>]
540540
[--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]] [--link]
541-
[--unicode]
541+
[--virtual] [--unicode]
542542
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
543543
[-ws|--workspaces]
544544
@@ -588,7 +588,7 @@ npm ls npm ls [[<@scope>/]<pkg> ...]
588588
Options:
589589
[-a|--all] [--json] [-l|--long] [-p|--parseable] [-g|--global] [--depth <depth>]
590590
[--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]] [--link]
591-
[--unicode]
591+
[--virtual] [--unicode]
592592
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
593593
[-ws|--workspaces]
594594

tap-snapshots/test/lib/utils/config/definitions.js.test.cjs

+1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ Array [
144144
"version",
145145
"versions",
146146
"viewer",
147+
"virtual",
147148
"which",
148149
"workspace",
149150
"workspaces",

tap-snapshots/test/lib/utils/config/describe-all.js.test.cjs

+8
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,14 @@ The program to use to view help content.
12111211
12121212
Set to \`"browser"\` to view html help content in the default web browser.
12131213
1214+
#### \`virtual\`
1215+
1216+
* Default: false
1217+
* Type: Boolean
1218+
1219+
Operates in "virtual" mode, meaning that the dependency tree is based off
1220+
the lockfile rather than the contents of \`node_modules\`.
1221+
12141222
#### \`which\`
12151223
12161224
* Default: null

tap-snapshots/test/lib/utils/npm-usage.js.test.cjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ All commands:
639639
Options:
640640
[-a|--all] [--json] [-l|--long] [-p|--parseable] [-g|--global] [--depth <depth>]
641641
[--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]] [--link]
642-
[--unicode]
642+
[--virtual] [--unicode]
643643
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
644644
[-ws|--workspaces]
645645
@@ -683,7 +683,7 @@ All commands:
683683
Options:
684684
[-a|--all] [--json] [-l|--long] [-p|--parseable] [-g|--global] [--depth <depth>]
685685
[--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]] [--link]
686-
[--unicode]
686+
[--virtual] [--unicode]
687687
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
688688
[-ws|--workspaces]
689689

0 commit comments

Comments
 (0)