Skip to content

Commit ae285b3

Browse files
G-Rathwraithgar
authored andcommitted
feat(ls): support --package-lock-only flag
This enables using the virtual tree instead of node_modules. PR-URL: #3408 Credit: @G-Rath Close: #3408 Reviewed-by: @isaacs
1 parent 6b951c0 commit ae285b3

File tree

6 files changed

+816
-11
lines changed

6 files changed

+816
-11
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+
'package-lock-only',
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 packageLockOnly = this.npm.config.get('package-lock-only')
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, packageLockOnly })
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, packageLockOnly }) {
222+
const tree = await (
223+
packageLockOnly
224+
? arb.loadVirtual()
225+
: arb.loadActual()
226+
)
227+
221228
tree[_include] = args.length === 0
222229
tree[_depth] = 0
223230

lib/utils/config/definitions.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -1333,8 +1333,14 @@ define('package-lock-only', {
13331333
default: false,
13341334
type: Boolean,
13351335
description: `
1336-
If set to true, it will update only the \`package-lock.json\`, instead of
1337-
checking \`node_modules\` and downloading dependencies.
1336+
If set to true, the current operation will only use the \`package-lock.json\`,
1337+
ignoring \`node_modules\`.
1338+
1339+
For \`update\` this means only the \`package-lock.json\` will be updated,
1340+
instead of checking \`node_modules\` and downloading dependencies.
1341+
1342+
For \`list\` this means the output will be based on the tree described by the
1343+
\`package-lock.json\`, rather than the contents of \`node_modules\`.
13381344
`,
13391345
flatten,
13401346
})

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+
[--package-lock-only] [--unicode]
542542
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
543543
[-ws|--workspaces]
544544
@@ -588,7 +588,7 @@ 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+
[--package-lock-only] [--unicode]
592592
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
593593
[-ws|--workspaces]
594594

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -781,8 +781,14 @@ package-locks disabled use \`npm prune\`.
781781
* Default: false
782782
* Type: Boolean
783783
784-
If set to true, it will update only the \`package-lock.json\`, instead of
785-
checking \`node_modules\` and downloading dependencies.
784+
If set to true, the current operation will only use the \`package-lock.json\`,
785+
ignoring \`node_modules\`.
786+
787+
For \`update\` this means only the \`package-lock.json\` will be updated,
788+
instead of checking \`node_modules\` and downloading dependencies.
789+
790+
For \`list\` this means the output will be based on the tree described by the
791+
\`package-lock.json\`, rather than the contents of \`node_modules\`.
786792
787793
#### \`parseable\`
788794

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+
[--package-lock-only] [--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+
[--package-lock-only] [--unicode]
687687
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
688688
[-ws|--workspaces]
689689

0 commit comments

Comments
 (0)