@npmcli/config 10.0.1 → 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.
@@ -954,6 +954,14 @@ const definitions = {
954
954
  more information, or [npm init](/commands/npm-init).
955
955
  `,
956
956
  }),
957
+ 'init-type': new Definition('init-type', {
958
+ default: 'commonjs',
959
+ type: String,
960
+ hint: '<type>',
961
+ description: `
962
+ The value that \`npm init\` should use by default for the package.json type field.
963
+ `,
964
+ }),
957
965
  'init-version': new Definition('init-version', {
958
966
  default: '1.0.0',
959
967
  type: Semver,
@@ -1286,6 +1294,19 @@ const definitions = {
1286
1294
  `,
1287
1295
  flatten,
1288
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
+ }),
1289
1310
  'node-options': new Definition('node-options', {
1290
1311
  default: null,
1291
1312
  type: [null, String],
@@ -2231,7 +2252,6 @@ const definitions = {
2231
2252
  workspaces: new Definition('workspaces', {
2232
2253
  default: null,
2233
2254
  type: [null, Boolean],
2234
- short: 'ws',
2235
2255
  envExport: false,
2236
2256
  description: `
2237
2257
  Set to true to run the command in the context of **all** configured
@@ -55,12 +55,26 @@ const shorthands = {
55
55
  readonly: ['--read-only'],
56
56
  reg: ['--registry'],
57
57
  iwr: ['--include-workspace-root'],
58
+ ws: ['--workspaces'],
58
59
  ...definitionProps.shorthands,
59
60
  }
60
61
 
62
+ // These are the configs that we can nerf-dart. Only _auth even has a config definition so we have to explicitly validate them here.
63
+ // This is used to validate during "npm config set" and to not warn on loading unknown configs when we see these.
64
+ const nerfDarts = [
65
+ '_auth', // Has a config
66
+ '_authToken', // Does not have a config
67
+ '_password', // Does not have a config
68
+ 'certfile', // Does not have a config
69
+ 'email', // Does not have a config
70
+ 'keyfile', // Does not have a config
71
+ 'username', // Does not have a config
72
+ ]
73
+
61
74
  module.exports = {
62
75
  defaults: definitionProps.defaults,
63
76
  definitions,
64
77
  flatten,
78
+ nerfDarts,
65
79
  shorthands,
66
80
  }
package/lib/index.js CHANGED
@@ -15,6 +15,13 @@ const {
15
15
  mkdir,
16
16
  } = require('node:fs/promises')
17
17
 
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
+ const internalEnv = [
20
+ 'npm-version',
21
+ 'global-prefix',
22
+ 'local-prefix',
23
+ ]
24
+
18
25
  const fileExists = (...p) => stat(resolve(...p))
19
26
  .then((st) => st.isFile())
20
27
  .catch(() => false)
@@ -61,6 +68,7 @@ class Config {
61
68
  definitions,
62
69
  shorthands,
63
70
  flatten,
71
+ nerfDarts = [],
64
72
  npmPath,
65
73
 
66
74
  // options just to override in tests, mostly
@@ -71,8 +79,9 @@ class Config {
71
79
  cwd = process.cwd(),
72
80
  excludeNpmCwd = false,
73
81
  }) {
74
- // turn the definitions into nopt's weirdo syntax
82
+ this.nerfDarts = nerfDarts
75
83
  this.definitions = definitions
84
+ // turn the definitions into nopt's weirdo syntax
76
85
  const types = {}
77
86
  const defaults = {}
78
87
  this.deprecated = {}
@@ -272,6 +281,7 @@ class Config {
272
281
  }
273
282
 
274
283
  try {
284
+ // This does not have an actual definition because this is not user defineable
275
285
  defaultsObject['npm-version'] = require(join(this.npmPath, 'package.json')).version
276
286
  } catch {
277
287
  // in some weird state where the passed in npmPath does not have a package.json
@@ -346,10 +356,18 @@ class Config {
346
356
  }
347
357
 
348
358
  loadCLI () {
359
+ for (const s of Object.keys(this.shorthands)) {
360
+ if (s.length > 1 && this.argv.includes(`-${s}`)) {
361
+ log.warn(`-${s} is not a valid single-hyphen cli flag and will be removed in the future`)
362
+ }
363
+ }
349
364
  nopt.invalidHandler = (k, val, type) =>
350
365
  this.invalidHandler(k, val, type, 'command line options', 'cli')
366
+ nopt.unknownHandler = this.unknownHandler
367
+ nopt.abbrevHandler = this.abbrevHandler
351
368
  const conf = nopt(this.types, this.shorthands, this.argv)
352
369
  nopt.invalidHandler = null
370
+ nopt.unknownHandler = null
353
371
  this.parsedArgv = conf.argv
354
372
  delete conf.argv
355
373
  this.#loadObject(conf, 'cli', 'command line options')
@@ -515,6 +533,16 @@ class Config {
515
533
  log.warn('invalid config', msg, desc)
516
534
  }
517
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
+
518
546
  #getOneOfKeywords (mustBe, typeDesc) {
519
547
  let keyword
520
548
  if (mustBe.length === 1 && typeDesc.includes(Array)) {
@@ -566,13 +594,31 @@ class Config {
566
594
  }
567
595
  }
568
596
  }
597
+ if (where !== 'default' || key === 'npm-version') {
598
+ this.checkUnknown(where, key)
599
+ }
569
600
  conf.data[k] = v
570
601
  }
571
602
  }
572
603
  }
573
604
 
605
+ checkUnknown (where, key) {
606
+ if (!this.definitions[key]) {
607
+ if (internalEnv.includes(key)) {
608
+ return
609
+ }
610
+ if (!key.includes(':')) {
611
+ log.warn(`Unknown ${where} config "${where === 'cli' ? '--' : ''}${key}". This will stop working in the next major version of npm.`)
612
+ return
613
+ }
614
+ const baseKey = key.split(':').pop()
615
+ if (!this.definitions[baseKey] && !this.nerfDarts.includes(baseKey)) {
616
+ log.warn(`Unknown ${where} config "${baseKey}" (${key}). This will stop working in the next major version of npm.`)
617
+ }
618
+ }
619
+ }
620
+
574
621
  #checkDeprecated (key) {
575
- // XXX(npm9+) make this throw an error
576
622
  if (this.deprecated[key]) {
577
623
  log.warn('config', key, this.deprecated[key])
578
624
  }
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@npmcli/config",
3
- "version": "10.0.1",
3
+ "version": "10.2.0",
4
4
  "files": [
5
5
  "bin/",
6
6
  "lib/"
@@ -41,7 +41,7 @@
41
41
  "@npmcli/package-json": "^6.0.1",
42
42
  "ci-info": "^4.0.0",
43
43
  "ini": "^5.0.0",
44
- "nopt": "^8.0.0",
44
+ "nopt": "^8.1.0",
45
45
  "proc-log": "^5.0.0",
46
46
  "semver": "^7.3.5",
47
47
  "walk-up-path": "^4.0.0"