@npmcli/config 10.1.0 → 10.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.
@@ -847,7 +847,7 @@ const definitions = {
847
847
  type: Boolean,
848
848
  envExport: false,
849
849
  description: `
850
- If true, npm will not exit with an error code when \`run-script\` is
850
+ If true, npm will not exit with an error code when \`run\` is
851
851
  invoked for a script that isn't defined in the \`scripts\` section of
852
852
  \`package.json\`. This option can be used when it's desirable to
853
853
  optionally run a script when it's present and fail if the script fails.
@@ -864,7 +864,7 @@ const definitions = {
864
864
 
865
865
  Note that commands explicitly intended to run a particular script, such
866
866
  as \`npm start\`, \`npm stop\`, \`npm restart\`, \`npm test\`, and \`npm
867
- run-script\` will still run their intended script if \`ignore-scripts\` is
867
+ run\` will still run their intended script if \`ignore-scripts\` is
868
868
  set, but they will *not* run any pre- or post-scripts.
869
869
  `,
870
870
  flatten,
@@ -971,6 +971,14 @@ const definitions = {
971
971
  version number, if not already set in package.json.
972
972
  `,
973
973
  }),
974
+ 'init-private': new Definition('init-private', {
975
+ default: false,
976
+ type: Boolean,
977
+ description: `
978
+ The value \`npm init\` should use by default for the package's private flag.
979
+ `,
980
+ flatten,
981
+ }),
974
982
  // these "aliases" are historically supported in .npmrc files, unfortunately
975
983
  // They should be removed in a future npm version.
976
984
  'init.author.email': new Definition('init.author.email', {
@@ -1294,6 +1302,19 @@ const definitions = {
1294
1302
  `,
1295
1303
  flatten,
1296
1304
  }),
1305
+ 'node-gyp': new Definition('node-gyp', {
1306
+ default: require.resolve('node-gyp/bin/node-gyp.js'),
1307
+ defaultDescription: `
1308
+ The path to the node-gyp bin that ships with npm
1309
+ `,
1310
+ type: path,
1311
+ description: `
1312
+ This is the location of the "node-gyp" bin. By default it uses one that ships with npm itself.
1313
+
1314
+ You can use this config to specify your own "node-gyp" to run when it is required to build a package.
1315
+ `,
1316
+ flatten,
1317
+ }),
1297
1318
  'node-options': new Definition('node-options', {
1298
1319
  default: null,
1299
1320
  type: [null, String],
@@ -1682,6 +1703,7 @@ const definitions = {
1682
1703
  default: false,
1683
1704
  type: Boolean,
1684
1705
  short: 'D',
1706
+ exclusive: ['save-optional', 'save-peer', 'save-prod'],
1685
1707
  description: `
1686
1708
  Save installed packages to a package.json file as \`devDependencies\`.
1687
1709
  `,
@@ -1713,6 +1735,7 @@ const definitions = {
1713
1735
  default: false,
1714
1736
  type: Boolean,
1715
1737
  short: 'O',
1738
+ exclusive: ['save-dev', 'save-peer', 'save-prod'],
1716
1739
  description: `
1717
1740
  Save installed packages to a package.json file as
1718
1741
  \`optionalDependencies\`.
@@ -1741,6 +1764,7 @@ const definitions = {
1741
1764
  'save-peer': new Definition('save-peer', {
1742
1765
  default: false,
1743
1766
  type: Boolean,
1767
+ exclusive: ['save-dev', 'save-optional', 'save-prod'],
1744
1768
  description: `
1745
1769
  Save installed packages to a package.json file as \`peerDependencies\`
1746
1770
  `,
@@ -1786,6 +1810,7 @@ const definitions = {
1786
1810
  default: false,
1787
1811
  type: Boolean,
1788
1812
  short: 'P',
1813
+ exclusive: ['save-dev', 'save-optional', 'save-peer'],
1789
1814
  description: `
1790
1815
  Save installed packages into \`dependencies\` specifically. This is
1791
1816
  useful if a package already exists in \`devDependencies\` or
package/lib/index.js CHANGED
@@ -15,12 +15,11 @@ const {
15
15
  mkdir,
16
16
  } = require('node:fs/promises')
17
17
 
18
- // TODO these need to be either be ignored when parsing env, formalized as config, or not exported to the env in the first place. For now this list is just to suppress warnings till we can pay off this tech debt.
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
- // Some defaults like npm-version are not user-definable and thus don't have definitions
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@npmcli/config",
3
- "version": "10.1.0",
3
+ "version": "10.3.0",
4
4
  "files": [
5
5
  "bin/",
6
6
  "lib/"