Skip to content

Commit

Permalink
feat(ls): support --package-lock-only flag
Browse files Browse the repository at this point in the history
This enables using the virtual tree instead of node_modules.

PR-URL: #3408
Credit: @G-Rath
Close: #3408
Reviewed-by: @isaacs
  • Loading branch information
G-Rath authored and wraithgar committed Jun 16, 2021
1 parent 6b951c0 commit ae285b3
Show file tree
Hide file tree
Showing 6 changed files with 816 additions and 11 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',
'package-lock-only',
'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 packageLockOnly = this.npm.config.get('package-lock-only')

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, packageLockOnly })

// 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, packageLockOnly }) {
const tree = await (
packageLockOnly
? arb.loadVirtual()
: arb.loadActual()
)

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

Expand Down
10 changes: 8 additions & 2 deletions lib/utils/config/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1333,8 +1333,14 @@ define('package-lock-only', {
default: false,
type: Boolean,
description: `
If set to true, it will update only the \`package-lock.json\`, instead of
checking \`node_modules\` and downloading dependencies.
If set to true, the current operation will only use the \`package-lock.json\`,
ignoring \`node_modules\`.
For \`update\` this means only the \`package-lock.json\` will be updated,
instead of checking \`node_modules\` and downloading dependencies.
For \`list\` this means the output will be based on the tree described by the
\`package-lock.json\`, rather than the contents of \`node_modules\`.
`,
flatten,
})
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]
[--package-lock-only] [--unicode]
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
[-ws|--workspaces]
Expand Down Expand Up @@ -588,7 +588,7 @@ 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]
[--package-lock-only] [--unicode]
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
[-ws|--workspaces]
Expand Down
10 changes: 8 additions & 2 deletions tap-snapshots/test/lib/utils/config/describe-all.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -781,8 +781,14 @@ package-locks disabled use \`npm prune\`.
* Default: false
* Type: Boolean
If set to true, it will update only the \`package-lock.json\`, instead of
checking \`node_modules\` and downloading dependencies.
If set to true, the current operation will only use the \`package-lock.json\`,
ignoring \`node_modules\`.
For \`update\` this means only the \`package-lock.json\` will be updated,
instead of checking \`node_modules\` and downloading dependencies.
For \`list\` this means the output will be based on the tree described by the
\`package-lock.json\`, rather than the contents of \`node_modules\`.
#### \`parseable\`
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]
[--package-lock-only] [--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]
[--package-lock-only] [--unicode]
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
[-ws|--workspaces]
Expand Down
Loading

0 comments on commit ae285b3

Please sign in to comment.