@npmcli/config 6.2.0 → 6.3.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 +253 -0
- package/lib/definitions/definitions.js +2406 -0
- package/lib/definitions/index.js +76 -0
- package/lib/errors.js +1 -0
- package/lib/index.js +13 -3
- package/lib/umask.js +13 -8
- package/package.json +6 -5
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const definitions = require('./definitions.js')
|
|
2
|
+
|
|
3
|
+
// use the defined flattening function, and copy over any scoped
|
|
4
|
+
// registries and registry-specific "nerfdart" configs verbatim
|
|
5
|
+
//
|
|
6
|
+
// TODO: make these getters so that we only have to make dirty
|
|
7
|
+
// the thing that changed, and then flatten the fields that
|
|
8
|
+
// could have changed when a config.set is called.
|
|
9
|
+
//
|
|
10
|
+
// TODO: move nerfdart auth stuff into a nested object that
|
|
11
|
+
// is only passed along to paths that end up calling npm-registry-fetch.
|
|
12
|
+
const flatten = (obj, flat = {}) => {
|
|
13
|
+
for (const [key, val] of Object.entries(obj)) {
|
|
14
|
+
const def = definitions[key]
|
|
15
|
+
if (def && def.flatten) {
|
|
16
|
+
def.flatten(key, obj, flat)
|
|
17
|
+
} else if (/@.*:registry$/i.test(key) || /^\/\//.test(key)) {
|
|
18
|
+
flat[key] = val
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// XXX make this the bin/npm-cli.js file explicitly instead
|
|
23
|
+
// otherwise using npm programmatically is a bit of a pain.
|
|
24
|
+
flat.npmBin = require.main ? require.main.filename
|
|
25
|
+
: /* istanbul ignore next - not configurable property */ undefined
|
|
26
|
+
flat.nodeBin = process.env.NODE || process.execPath
|
|
27
|
+
|
|
28
|
+
// XXX should this be sha512? is it even relevant?
|
|
29
|
+
flat.hashAlgorithm = 'sha1'
|
|
30
|
+
|
|
31
|
+
return flat
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const definitionProps = Object.entries(definitions)
|
|
35
|
+
.reduce((acc, [key, { short = [], default: d }]) => {
|
|
36
|
+
// can be either an array or string
|
|
37
|
+
for (const s of [].concat(short)) {
|
|
38
|
+
acc.shorthands[s] = [`--${key}`]
|
|
39
|
+
}
|
|
40
|
+
acc.defaults[key] = d
|
|
41
|
+
return acc
|
|
42
|
+
}, { shorthands: {}, defaults: {} })
|
|
43
|
+
|
|
44
|
+
// aliases where they get expanded into a completely different thing
|
|
45
|
+
// these are NOT supported in the environment or npmrc files, only
|
|
46
|
+
// expanded on the CLI.
|
|
47
|
+
// TODO: when we switch off of nopt, use an arg parser that supports
|
|
48
|
+
// more reasonable aliasing and short opts right in the definitions set.
|
|
49
|
+
const shorthands = {
|
|
50
|
+
'enjoy-by': ['--before'],
|
|
51
|
+
d: ['--loglevel', 'info'],
|
|
52
|
+
dd: ['--loglevel', 'verbose'],
|
|
53
|
+
ddd: ['--loglevel', 'silly'],
|
|
54
|
+
quiet: ['--loglevel', 'warn'],
|
|
55
|
+
q: ['--loglevel', 'warn'],
|
|
56
|
+
s: ['--loglevel', 'silent'],
|
|
57
|
+
silent: ['--loglevel', 'silent'],
|
|
58
|
+
verbose: ['--loglevel', 'verbose'],
|
|
59
|
+
desc: ['--description'],
|
|
60
|
+
help: ['--usage'],
|
|
61
|
+
local: ['--no-global'],
|
|
62
|
+
n: ['--no-yes'],
|
|
63
|
+
no: ['--no-yes'],
|
|
64
|
+
porcelain: ['--parseable'],
|
|
65
|
+
readonly: ['--read-only'],
|
|
66
|
+
reg: ['--registry'],
|
|
67
|
+
iwr: ['--include-workspace-root'],
|
|
68
|
+
...definitionProps.shorthands,
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
module.exports = {
|
|
72
|
+
defaults: definitionProps.defaults,
|
|
73
|
+
definitions,
|
|
74
|
+
flatten,
|
|
75
|
+
shorthands,
|
|
76
|
+
}
|
package/lib/errors.js
CHANGED
|
@@ -4,6 +4,7 @@ class ErrInvalidAuth extends Error {
|
|
|
4
4
|
constructor (problems) {
|
|
5
5
|
let message = 'Invalid auth configuration found: '
|
|
6
6
|
message += problems.map((problem) => {
|
|
7
|
+
// istanbul ignore else
|
|
7
8
|
if (problem.action === 'delete') {
|
|
8
9
|
return `\`${problem.key}\` is not allowed in ${problem.where} config`
|
|
9
10
|
} else if (problem.action === 'rename') {
|
package/lib/index.js
CHANGED
|
@@ -305,10 +305,20 @@ class Config {
|
|
|
305
305
|
this.loadGlobalPrefix()
|
|
306
306
|
this.loadHome()
|
|
307
307
|
|
|
308
|
-
|
|
308
|
+
const defaultsObject = {
|
|
309
309
|
...this.defaults,
|
|
310
310
|
prefix: this.globalPrefix,
|
|
311
|
-
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
try {
|
|
314
|
+
defaultsObject['npm-version'] = require(join(this.npmPath, 'package.json')).version
|
|
315
|
+
} catch {
|
|
316
|
+
// in some weird state where the passed in npmPath does not have a package.json
|
|
317
|
+
// this will never happen in npm, but is guarded here in case this is consumed
|
|
318
|
+
// in other ways + tests
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
this.#loadObject(defaultsObject, 'default', 'default values')
|
|
312
322
|
|
|
313
323
|
const { data } = this.data.get('default')
|
|
314
324
|
|
|
@@ -446,7 +456,7 @@ class Config {
|
|
|
446
456
|
nopt.invalidHandler = (k, val, type) =>
|
|
447
457
|
this.invalidHandler(k, val, type, obj.source, where)
|
|
448
458
|
|
|
449
|
-
nopt.clean(obj.data, this.types,
|
|
459
|
+
nopt.clean(obj.data, this.types, typeDefs)
|
|
450
460
|
|
|
451
461
|
nopt.invalidHandler = null
|
|
452
462
|
return obj[_valid]
|
package/lib/umask.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
class Umask {}
|
|
2
2
|
const parse = val => {
|
|
3
|
+
// this is run via nopt and parse field where everything is
|
|
4
|
+
// converted to a string first, ignoring coverage for now
|
|
5
|
+
// instead of figuring out what is happening under the hood in nopt
|
|
6
|
+
// istanbul ignore else
|
|
3
7
|
if (typeof val === 'string') {
|
|
4
8
|
if (/^0o?[0-7]+$/.test(val)) {
|
|
5
9
|
return parseInt(val.replace(/^0o?/, ''), 8)
|
|
@@ -8,15 +12,16 @@ const parse = val => {
|
|
|
8
12
|
} else {
|
|
9
13
|
throw new Error(`invalid umask value: ${val}`)
|
|
10
14
|
}
|
|
15
|
+
} else {
|
|
16
|
+
if (typeof val !== 'number') {
|
|
17
|
+
throw new Error(`invalid umask value: ${val}`)
|
|
18
|
+
}
|
|
19
|
+
val = Math.floor(val)
|
|
20
|
+
if (val < 0 || val > 511) {
|
|
21
|
+
throw new Error(`invalid umask value: ${val}`)
|
|
22
|
+
}
|
|
23
|
+
return val
|
|
11
24
|
}
|
|
12
|
-
if (typeof val !== 'number') {
|
|
13
|
-
throw new Error(`invalid umask value: ${val}`)
|
|
14
|
-
}
|
|
15
|
-
val = Math.floor(val)
|
|
16
|
-
if (val < 0 || val > 511) {
|
|
17
|
-
throw new Error(`invalid umask value: ${val}`)
|
|
18
|
-
}
|
|
19
|
-
return val
|
|
20
25
|
}
|
|
21
26
|
|
|
22
27
|
const validate = (data, k, val) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@npmcli/config",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.3.0",
|
|
4
4
|
"files": [
|
|
5
5
|
"bin/",
|
|
6
6
|
"lib/"
|
|
@@ -24,8 +24,6 @@
|
|
|
24
24
|
"template-oss-apply": "template-oss-apply --force"
|
|
25
25
|
},
|
|
26
26
|
"tap": {
|
|
27
|
-
"check-coverage": true,
|
|
28
|
-
"coverage-map": "map.js",
|
|
29
27
|
"nyc-arg": [
|
|
30
28
|
"--exclude",
|
|
31
29
|
"tap-snapshots/**"
|
|
@@ -33,11 +31,13 @@
|
|
|
33
31
|
},
|
|
34
32
|
"devDependencies": {
|
|
35
33
|
"@npmcli/eslint-config": "^4.0.0",
|
|
36
|
-
"@npmcli/
|
|
34
|
+
"@npmcli/mock-globals": "^1.0.0",
|
|
35
|
+
"@npmcli/template-oss": "4.19.0",
|
|
37
36
|
"tap": "^16.3.4"
|
|
38
37
|
},
|
|
39
38
|
"dependencies": {
|
|
40
39
|
"@npmcli/map-workspaces": "^3.0.2",
|
|
40
|
+
"ci-info": "^3.8.0",
|
|
41
41
|
"ini": "^4.1.0",
|
|
42
42
|
"nopt": "^7.0.0",
|
|
43
43
|
"proc-log": "^3.0.0",
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
},
|
|
51
51
|
"templateOSS": {
|
|
52
52
|
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
|
53
|
-
"version": "4.
|
|
53
|
+
"version": "4.19.0",
|
|
54
|
+
"content": "../../scripts/template-oss/index.js"
|
|
54
55
|
}
|
|
55
56
|
}
|