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/utils
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2021-03-24 19:29:21 +0300
committerGar <gar+gh@danger.computer>2021-03-24 19:34:25 +0300
commita4df2b98d89429b19cd29b5fc895cdbfc0a6bd78 (patch)
tree2cc3972c371583377e924f5dfab4b59ea5ce9970 /lib/utils
parent62b783ad3dcac2bcadcf6fecbdba07284f3d640e (diff)
config: Restore --dev flag, unify --omit flatteners
This consolidates all the various --include and --omit configuration flatteners into a single function, since they have to be interdependent in order to function properly. Fix: #2936 PR-URL: https://github.com/npm/cli/pull/2942 Credit: @isaacs Close: #2942 Reviewed-by: @wraithgar
Diffstat (limited to 'lib/utils')
-rw-r--r--lib/utils/config/definitions.js73
1 files changed, 41 insertions, 32 deletions
diff --git a/lib/utils/config/definitions.js b/lib/utils/config/definitions.js
index 5001efb46..b8e021c52 100644
--- a/lib/utils/config/definitions.js
+++ b/lib/utils/config/definitions.js
@@ -22,6 +22,34 @@ const maybeReadFile = file => {
}
}
+const buildOmitList = obj => {
+ const include = obj.include || []
+ const omit = obj.omit || []
+
+ const only = obj.only
+ if (/^prod(uction)?$/.test(only) || obj.production)
+ omit.push('dev')
+
+ if (/^dev/.test(obj.also))
+ include.push('dev')
+
+ if (obj.dev)
+ include.push('dev')
+
+ if (obj.optional === false)
+ omit.push('optional')
+ else if (obj.optional === true)
+ include.push('optional')
+
+ obj.omit = [...new Set(omit)].filter(type => !include.includes(type))
+ obj.include = [...new Set(include)]
+
+ if (obj.omit.includes('dev'))
+ process.env.NODE_ENV = 'production'
+
+ return obj.omit
+}
+
const editor = process.env.EDITOR ||
process.env.VISUAL ||
(isWindows ? 'notepad.exe' : 'vi')
@@ -164,12 +192,6 @@ define('also', {
`,
deprecated: 'Please use --include=dev instead.',
flatten (key, obj, flatOptions) {
- if (!/^dev(elopment)?$/.test(obj.also))
- return
-
- // add to include, and call the omit flattener
- obj.include = obj.include || []
- obj.include.push('dev')
definitions.omit.flatten('omit', obj, flatOptions)
},
})
@@ -477,6 +499,18 @@ define('description', {
},
})
+define('dev', {
+ default: false,
+ type: Boolean,
+ description: `
+ Alias for \`--include=dev\`.
+ `,
+ deprecated: 'Please use --include=dev instead.',
+ flatten (key, obj, flatOptions) {
+ definitions.omit.flatten('omit', obj, flatOptions)
+ },
+})
+
define('diff', {
default: [],
type: [String, Array],
@@ -1218,10 +1252,7 @@ define('omit', {
scripts.
`,
flatten (key, obj, flatOptions) {
- const include = obj.include || []
- const omit = flatOptions.omit || []
- flatOptions.omit = omit.concat(obj[key])
- .filter(type => type && !include.includes(type))
+ flatOptions.omit = buildOmitList(obj)
},
})
@@ -1236,12 +1267,6 @@ define('only', {
\`--omit=dev\`.
`,
flatten (key, obj, flatOptions) {
- const value = obj[key]
- if (!/^prod(uction)?$/.test(value))
- return
-
- obj.omit = obj.omit || []
- obj.omit.push('dev')
definitions.omit.flatten('omit', obj, flatOptions)
},
})
@@ -1259,16 +1284,6 @@ define('optional', {
Alias for --include=optional or --omit=optional
`,
flatten (key, obj, flatOptions) {
- const value = obj[key]
- if (value === null)
- return
- else if (value === true) {
- obj.include = obj.include || []
- obj.include.push('optional')
- } else {
- obj.omit = obj.omit || []
- obj.omit.push('optional')
- }
definitions.omit.flatten('omit', obj, flatOptions)
},
})
@@ -1385,12 +1400,6 @@ define('production', {
deprecated: 'Use `--omit=dev` instead.',
description: 'Alias for `--omit=dev`',
flatten (key, obj, flatOptions) {
- const value = obj[key]
- if (!value)
- return
-
- obj.omit = obj.omit || []
- obj.omit.push('dev')
definitions.omit.flatten('omit', obj, flatOptions)
},
})