@npmcli/config 10.5.0 → 10.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/definitions/definition.js +2 -0
- package/lib/definitions/definitions.js +37 -0
- package/lib/index.js +55 -14
- package/package.json +1 -1
|
@@ -187,6 +187,20 @@ const definitions = {
|
|
|
187
187
|
`,
|
|
188
188
|
flatten,
|
|
189
189
|
}),
|
|
190
|
+
'allow-git': new Definition('allow-git', {
|
|
191
|
+
default: 'all',
|
|
192
|
+
type: ['all', 'none', 'root'],
|
|
193
|
+
description: `
|
|
194
|
+
Limits the ability for npm to fetch dependencies from git references.
|
|
195
|
+
That is, dependencies that point to a git repo instead of a version or semver range.
|
|
196
|
+
Please note that this could leave your tree incomplete and some packages may not function as intended or designed.
|
|
197
|
+
|
|
198
|
+
\`all\` allows any git dependencies to be fetched and installed.
|
|
199
|
+
\`none\` prevents any git dependencies from being fetched and installed.
|
|
200
|
+
\`root\` only allows git dependencies defined in your project's package.json to be fetched installed. Also allows git dependencies to be fetched for other commands like \`npm view\`
|
|
201
|
+
`,
|
|
202
|
+
flatten,
|
|
203
|
+
}),
|
|
190
204
|
also: new Definition('also', {
|
|
191
205
|
default: null,
|
|
192
206
|
type: [null, 'dev', 'development'],
|
|
@@ -232,6 +246,7 @@ const definitions = {
|
|
|
232
246
|
default: null,
|
|
233
247
|
hint: '<date>',
|
|
234
248
|
type: [null, Date],
|
|
249
|
+
exclusive: ['min-release-age'],
|
|
235
250
|
description: `
|
|
236
251
|
If passed to \`npm install\`, will rebuild the npm tree such that only
|
|
237
252
|
versions that were available **on or before** the given date are
|
|
@@ -1333,6 +1348,28 @@ const definitions = {
|
|
|
1333
1348
|
`,
|
|
1334
1349
|
flatten,
|
|
1335
1350
|
}),
|
|
1351
|
+
'min-release-age': new Definition('min-release-age', {
|
|
1352
|
+
default: null,
|
|
1353
|
+
hint: '<days>',
|
|
1354
|
+
type: [null, Number],
|
|
1355
|
+
exclusive: ['before'],
|
|
1356
|
+
description: `
|
|
1357
|
+
If set, npm will build the npm tree such that only versions that were
|
|
1358
|
+
available more than the given number of days ago will be installed. If
|
|
1359
|
+
there are no versions available for the current set of dependencies, the
|
|
1360
|
+
command will error.
|
|
1361
|
+
|
|
1362
|
+
This flag is a complement to \`before\`, which accepts an exact date
|
|
1363
|
+
instead of a relative number of days.
|
|
1364
|
+
`,
|
|
1365
|
+
flatten: (key, obj, flatOptions) => {
|
|
1366
|
+
if (obj['min-release-age'] !== null) {
|
|
1367
|
+
flatOptions.before = new Date(Date.now() - (86400000 * obj['min-release-age']))
|
|
1368
|
+
obj.before = flatOptions.before
|
|
1369
|
+
delete obj['min-release-age']
|
|
1370
|
+
}
|
|
1371
|
+
},
|
|
1372
|
+
}),
|
|
1336
1373
|
'node-gyp': new Definition('node-gyp', {
|
|
1337
1374
|
default: (() => {
|
|
1338
1375
|
try {
|
package/lib/index.js
CHANGED
|
@@ -59,6 +59,7 @@ class Config {
|
|
|
59
59
|
#flatten
|
|
60
60
|
// populated the first time we flatten the object
|
|
61
61
|
#flatOptions = null
|
|
62
|
+
#warnings = []
|
|
62
63
|
|
|
63
64
|
static get typeDefs () {
|
|
64
65
|
return typeDefs
|
|
@@ -78,20 +79,13 @@ class Config {
|
|
|
78
79
|
execPath = process.execPath,
|
|
79
80
|
cwd = process.cwd(),
|
|
80
81
|
excludeNpmCwd = false,
|
|
82
|
+
warn = true,
|
|
81
83
|
}) {
|
|
82
84
|
this.nerfDarts = nerfDarts
|
|
83
85
|
this.definitions = definitions
|
|
84
86
|
// turn the definitions into nopt's weirdo syntax
|
|
85
|
-
const types =
|
|
86
|
-
|
|
87
|
-
this.deprecated = {}
|
|
88
|
-
for (const [key, def] of Object.entries(definitions)) {
|
|
89
|
-
defaults[key] = def.default
|
|
90
|
-
types[key] = def.type
|
|
91
|
-
if (def.deprecated) {
|
|
92
|
-
this.deprecated[key] = def.deprecated.trim().replace(/\n +/, '\n')
|
|
93
|
-
}
|
|
94
|
-
}
|
|
87
|
+
const { types, defaults, deprecated } = getTypesFromDefinitions(definitions)
|
|
88
|
+
this.deprecated = deprecated
|
|
95
89
|
|
|
96
90
|
this.#flatten = flatten
|
|
97
91
|
this.types = types
|
|
@@ -137,6 +131,7 @@ class Config {
|
|
|
137
131
|
}
|
|
138
132
|
|
|
139
133
|
this.#loaded = false
|
|
134
|
+
this.warn = warn
|
|
140
135
|
}
|
|
141
136
|
|
|
142
137
|
get list () {
|
|
@@ -369,7 +364,7 @@ class Config {
|
|
|
369
364
|
}
|
|
370
365
|
nopt.invalidHandler = (k, val, type) =>
|
|
371
366
|
this.invalidHandler(k, val, type, 'command line options', 'cli')
|
|
372
|
-
nopt.unknownHandler = this.unknownHandler
|
|
367
|
+
nopt.unknownHandler = (k, next) => this.unknownHandler(k, next)
|
|
373
368
|
nopt.abbrevHandler = this.abbrevHandler
|
|
374
369
|
const conf = nopt(this.types, this.shorthands, this.argv)
|
|
375
370
|
nopt.invalidHandler = null
|
|
@@ -545,7 +540,7 @@ class Config {
|
|
|
545
540
|
|
|
546
541
|
unknownHandler (key, next) {
|
|
547
542
|
if (next) {
|
|
548
|
-
|
|
543
|
+
this.queueWarning(`unknown:${next}`, `"${next}" is being parsed as a normal command line argument.`)
|
|
549
544
|
}
|
|
550
545
|
}
|
|
551
546
|
|
|
@@ -614,12 +609,12 @@ class Config {
|
|
|
614
609
|
return
|
|
615
610
|
}
|
|
616
611
|
if (!key.includes(':')) {
|
|
617
|
-
|
|
612
|
+
this.queueWarning(key, `Unknown ${where} config "${where === 'cli' ? '--' : ''}${key}". This will stop working in the next major version of npm.`)
|
|
618
613
|
return
|
|
619
614
|
}
|
|
620
615
|
const baseKey = key.split(':').pop()
|
|
621
616
|
if (!this.definitions[baseKey] && !this.nerfDarts.includes(baseKey)) {
|
|
622
|
-
|
|
617
|
+
this.queueWarning(baseKey, `Unknown ${where} config "${baseKey}" (${key}). This will stop working in the next major version of npm.`)
|
|
623
618
|
}
|
|
624
619
|
}
|
|
625
620
|
}
|
|
@@ -923,6 +918,35 @@ class Config {
|
|
|
923
918
|
setEnvs () {
|
|
924
919
|
setEnvs(this)
|
|
925
920
|
}
|
|
921
|
+
|
|
922
|
+
removeWarning (key) {
|
|
923
|
+
this.#warnings = this.#warnings.filter(w => w.type !== key)
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
getUnknownPositionals () {
|
|
927
|
+
return this.#warnings
|
|
928
|
+
.filter(w => w.type.startsWith('unknown:'))
|
|
929
|
+
.map(w => w.type.slice('unknown:'.length))
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
removeUnknownPositional (value) {
|
|
933
|
+
this.removeWarning(`unknown:${value}`)
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
queueWarning (type, ...args) {
|
|
937
|
+
if (!this.warn) {
|
|
938
|
+
this.#warnings.push({ type, args })
|
|
939
|
+
} else {
|
|
940
|
+
log.warn(...args)
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
logWarnings () {
|
|
945
|
+
for (const warning of this.#warnings) {
|
|
946
|
+
log.warn(...warning.args)
|
|
947
|
+
}
|
|
948
|
+
this.#warnings = []
|
|
949
|
+
}
|
|
926
950
|
}
|
|
927
951
|
|
|
928
952
|
const _loadError = Symbol('loadError')
|
|
@@ -980,4 +1004,21 @@ class ConfigData {
|
|
|
980
1004
|
}
|
|
981
1005
|
}
|
|
982
1006
|
|
|
1007
|
+
const getTypesFromDefinitions = (definitions) => {
|
|
1008
|
+
const types = {}
|
|
1009
|
+
const defaults = {}
|
|
1010
|
+
const deprecated = {}
|
|
1011
|
+
|
|
1012
|
+
for (const [key, def] of Object.entries(definitions)) {
|
|
1013
|
+
defaults[key] = def.default
|
|
1014
|
+
types[key] = def.type
|
|
1015
|
+
if (def.deprecated) {
|
|
1016
|
+
deprecated[key] = def.deprecated.trim().replace(/\n +/, '\n')
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
return { types, defaults, deprecated }
|
|
1021
|
+
}
|
|
1022
|
+
|
|
983
1023
|
module.exports = Config
|
|
1024
|
+
module.exports.getTypesFromDefinitions = getTypesFromDefinitions
|