Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLuke Karrys <luke@lukekarrys.com>2022-04-13 20:19:58 +0300
committerNathan Fritz <fritzy@github.com>2022-04-14 01:02:47 +0300
commitba8b2a753d63c8a8c7a44a48c2e13626b12025fe (patch)
tree971c44b3d8e7a23eb2546f8af4b7c603d282b549 /lib
parentc22fb1e756d43b54fefd826f2c3f459d4f1204b5 (diff)
fix(ls): make `--omit` filter `npm ls`
This makes `npm ls` use the same logic as other commands (eg `outdated`) when parsing config items that filter the output based on package type. Previously `--development` and `--production` has special semantics when used with `npm ls` that were inconsistent with the rest of the CLI. To achieve the same behavior as these deprecated flags use: - in place of `--development` use `--omit peer --omit prod --omit optional` - in place of `--production` use `--omit dev --omit peer` Fixes #4739
Diffstat (limited to 'lib')
-rw-r--r--lib/commands/ls.js45
-rw-r--r--lib/commands/outdated.js2
2 files changed, 12 insertions, 35 deletions
diff --git a/lib/commands/ls.js b/lib/commands/ls.js
index e56c90dae..06268fe7e 100644
--- a/lib/commands/ls.js
+++ b/lib/commands/ls.js
@@ -52,16 +52,12 @@ class LS extends ArboristWorkspaceCmd {
const all = this.npm.config.get('all')
const color = this.npm.color
const depth = this.npm.config.get('depth')
- const dev = this.npm.config.get('dev')
- const development = this.npm.config.get('development')
const global = this.npm.config.get('global')
const json = this.npm.config.get('json')
const link = this.npm.config.get('link')
const long = this.npm.config.get('long')
- const only = this.npm.config.get('only')
+ const omit = this.npm.flatOptions.omit
const parseable = this.npm.config.get('parseable')
- 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 workspacesEnabled = this.npm.flatOptions.workspacesEnabled
@@ -138,15 +134,10 @@ class LS extends ArboristWorkspaceCmd {
? []
: [...(node.target).edgesOut.values()]
.filter(filterBySelectedWorkspaces)
- .filter(filterByEdgesTypes({
- currentDepth,
- dev,
- development,
+ .filter(currentDepth === 0 ? filterByEdgesTypes({
link,
- prod,
- production,
- only,
- }))
+ omit,
+ }) : () => true)
.map(mapEdgesToNodes({ seenPaths }))
.concat(appendExtraneousChildren({ node, seenPaths }))
.sort(sortAlphabetically)
@@ -399,27 +390,13 @@ const getJsonOutputItem = (node, { global, long }) => {
return augmentItemWithIncludeMetadata(node, item)
}
-const filterByEdgesTypes = ({
- currentDepth,
- dev,
- development,
- link,
- prod,
- production,
- only,
-}) => {
- // filter deps by type, allows for: `npm ls --dev`, `npm ls --prod`,
- // `npm ls --link`, `npm ls --only=dev`, etc
- const filterDev = currentDepth === 0 &&
- (dev || development || /^dev(elopment)?$/.test(only))
- const filterProd = currentDepth === 0 &&
- (prod || production || /^prod(uction)?$/.test(only))
- const filterLink = currentDepth === 0 && link
-
- return (edge) =>
- (filterDev ? edge.dev : true) &&
- (filterProd ? (!edge.dev && !edge.peer && !edge.peerOptional) : true) &&
- (filterLink ? (edge.to && edge.to.isLink) : true)
+const filterByEdgesTypes = ({ link, omit = [] }) => (edge) => {
+ for (const omitType of omit) {
+ if (edge[omitType]) {
+ return false
+ }
+ }
+ return link ? edge.to && edge.to.isLink : true
}
const appendExtraneousChildren = ({ node, seenPaths }) =>
diff --git a/lib/commands/outdated.js b/lib/commands/outdated.js
index 1420d94cd..0953c17ca 100644
--- a/lib/commands/outdated.js
+++ b/lib/commands/outdated.js
@@ -207,7 +207,7 @@ class Outdated extends ArboristWorkspaceCmd {
: edge.dev ? 'devDependencies'
: 'dependencies'
- for (const omitType of this.npm.config.get('omit')) {
+ for (const omitType of this.npm.flatOptions.omit) {
if (node[omitType]) {
return
}