@npmcli/config 10.1.0 → 10.2.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/definitions.js +13 -0
- package/lib/index.js +17 -6
- package/lib/set-envs.js +5 -0
- package/package.json +1 -1
|
@@ -1294,6 +1294,19 @@ const definitions = {
|
|
|
1294
1294
|
`,
|
|
1295
1295
|
flatten,
|
|
1296
1296
|
}),
|
|
1297
|
+
'node-gyp': new Definition('node-gyp', {
|
|
1298
|
+
default: require.resolve('node-gyp/bin/node-gyp.js'),
|
|
1299
|
+
defaultDescription: `
|
|
1300
|
+
The path to the node-gyp bin that ships with npm
|
|
1301
|
+
`,
|
|
1302
|
+
type: path,
|
|
1303
|
+
description: `
|
|
1304
|
+
This is the location of the "node-gyp" bin. By default it uses one that ships with npm itself.
|
|
1305
|
+
|
|
1306
|
+
You can use this config to specify your own "node-gyp" to run when it is required to build a package.
|
|
1307
|
+
`,
|
|
1308
|
+
flatten,
|
|
1309
|
+
}),
|
|
1297
1310
|
'node-options': new Definition('node-options', {
|
|
1298
1311
|
default: null,
|
|
1299
1312
|
type: [null, String],
|
package/lib/index.js
CHANGED
|
@@ -15,12 +15,11 @@ const {
|
|
|
15
15
|
mkdir,
|
|
16
16
|
} = require('node:fs/promises')
|
|
17
17
|
|
|
18
|
-
// TODO
|
|
18
|
+
// TODO global-prefix and local-prefix are set by lib/set-envs.js. This may not be the best way to persist those, if we even want to persist them (see set-envs.js)
|
|
19
19
|
const internalEnv = [
|
|
20
|
+
'npm-version',
|
|
20
21
|
'global-prefix',
|
|
21
22
|
'local-prefix',
|
|
22
|
-
'npm-version',
|
|
23
|
-
'node-gyp',
|
|
24
23
|
]
|
|
25
24
|
|
|
26
25
|
const fileExists = (...p) => stat(resolve(...p))
|
|
@@ -282,7 +281,7 @@ class Config {
|
|
|
282
281
|
}
|
|
283
282
|
|
|
284
283
|
try {
|
|
285
|
-
// This does not have an actual definition
|
|
284
|
+
// This does not have an actual definition because this is not user defineable
|
|
286
285
|
defaultsObject['npm-version'] = require(join(this.npmPath, 'package.json')).version
|
|
287
286
|
} catch {
|
|
288
287
|
// in some weird state where the passed in npmPath does not have a package.json
|
|
@@ -364,8 +363,11 @@ class Config {
|
|
|
364
363
|
}
|
|
365
364
|
nopt.invalidHandler = (k, val, type) =>
|
|
366
365
|
this.invalidHandler(k, val, type, 'command line options', 'cli')
|
|
366
|
+
nopt.unknownHandler = this.unknownHandler
|
|
367
|
+
nopt.abbrevHandler = this.abbrevHandler
|
|
367
368
|
const conf = nopt(this.types, this.shorthands, this.argv)
|
|
368
369
|
nopt.invalidHandler = null
|
|
370
|
+
nopt.unknownHandler = null
|
|
369
371
|
this.parsedArgv = conf.argv
|
|
370
372
|
delete conf.argv
|
|
371
373
|
this.#loadObject(conf, 'cli', 'command line options')
|
|
@@ -531,6 +533,16 @@ class Config {
|
|
|
531
533
|
log.warn('invalid config', msg, desc)
|
|
532
534
|
}
|
|
533
535
|
|
|
536
|
+
abbrevHandler (short, long) {
|
|
537
|
+
log.warn(`Expanding --${short} to --${long}. This will stop working in the next major version of npm.`)
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
unknownHandler (key, next) {
|
|
541
|
+
if (next) {
|
|
542
|
+
log.warn(`"${next}" is being parsed as a normal command line argument.`)
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
|
|
534
546
|
#getOneOfKeywords (mustBe, typeDesc) {
|
|
535
547
|
let keyword
|
|
536
548
|
if (mustBe.length === 1 && typeDesc.includes(Array)) {
|
|
@@ -582,8 +594,7 @@ class Config {
|
|
|
582
594
|
}
|
|
583
595
|
}
|
|
584
596
|
}
|
|
585
|
-
|
|
586
|
-
if (where !== 'default') {
|
|
597
|
+
if (where !== 'default' || key === 'npm-version') {
|
|
587
598
|
this.checkUnknown(where, key)
|
|
588
599
|
}
|
|
589
600
|
conf.data[k] = v
|
package/lib/set-envs.js
CHANGED
|
@@ -90,6 +90,7 @@ const setEnvs = (config) => {
|
|
|
90
90
|
|
|
91
91
|
// also set some other common nice envs that we want to rely on
|
|
92
92
|
env.HOME = config.home
|
|
93
|
+
// TODO this may not be the best away to persist these
|
|
93
94
|
env.npm_config_global_prefix = config.globalPrefix
|
|
94
95
|
env.npm_config_local_prefix = config.localPrefix
|
|
95
96
|
if (cliConf.editor) {
|
|
@@ -101,6 +102,10 @@ const setEnvs = (config) => {
|
|
|
101
102
|
if (cliConf['node-options']) {
|
|
102
103
|
env.NODE_OPTIONS = cliConf['node-options']
|
|
103
104
|
}
|
|
105
|
+
// the node-gyp bin uses this so we always set it
|
|
106
|
+
env.npm_config_node_gyp = cliConf['node-gyp']
|
|
107
|
+
// this doesn't have a full definition so we manually export it here
|
|
108
|
+
env.npm_config_npm_version = cliConf['npm-version'] || 'unknown'
|
|
104
109
|
env.npm_execpath = config.npmBin
|
|
105
110
|
env.NODE = env.npm_node_execpath = config.execPath
|
|
106
111
|
}
|