Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ls): support --package-lock-only flag to enable using the virtual tree #3408

Merged
merged 1 commit into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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