@npmcli/config 8.2.2 → 8.3.1

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.
@@ -7,10 +7,10 @@ const { join } = require('node:path')
7
7
  const isWindows = process.platform === 'win32'
8
8
 
9
9
  // used by cafile flattening to flatOptions.ca
10
- const fs = require('fs')
10
+ const { readFileSync } = require('fs')
11
11
  const maybeReadFile = file => {
12
12
  try {
13
- return fs.readFileSync(file, 'utf8')
13
+ return readFileSync(file, 'utf8')
14
14
  } catch (er) {
15
15
  if (er.code !== 'ENOENT') {
16
16
  throw er
package/lib/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  const { walkUp } = require('walk-up-path')
3
3
  const ini = require('ini')
4
4
  const nopt = require('nopt')
5
- const log = require('proc-log')
5
+ const { log, time } = require('proc-log')
6
6
 
7
7
  const { resolve, dirname, join } = require('node:path')
8
8
  const { homedir } = require('node:os')
@@ -201,7 +201,7 @@ class Config {
201
201
  }
202
202
 
203
203
  // create the object for flat options passed to deps
204
- process.emit('time', 'config:load:flatten')
204
+ const timeEnd = time.start('config:load:flatten')
205
205
  this.#flatOptions = {}
206
206
  // walk from least priority to highest
207
207
  for (const { data } of this.data.values()) {
@@ -209,7 +209,7 @@ class Config {
209
209
  }
210
210
  this.#flatOptions.nodeBin = this.execPath
211
211
  this.#flatOptions.npmBin = this.npmBin
212
- process.emit('timeEnd', 'config:load:flatten')
212
+ timeEnd()
213
213
 
214
214
  return this.#flatOptions
215
215
  }
@@ -233,37 +233,24 @@ class Config {
233
233
  throw new Error('attempting to load npm config multiple times')
234
234
  }
235
235
 
236
- process.emit('time', 'config:load')
237
236
  // first load the defaults, which sets the global prefix
238
- process.emit('time', 'config:load:defaults')
239
237
  this.loadDefaults()
240
- process.emit('timeEnd', 'config:load:defaults')
241
238
 
242
239
  // next load the builtin config, as this sets new effective defaults
243
- process.emit('time', 'config:load:builtin')
244
240
  await this.loadBuiltinConfig()
245
- process.emit('timeEnd', 'config:load:builtin')
246
241
 
247
242
  // cli and env are not async, and can set the prefix, relevant to project
248
- process.emit('time', 'config:load:cli')
249
243
  this.loadCLI()
250
- process.emit('timeEnd', 'config:load:cli')
251
- process.emit('time', 'config:load:env')
252
244
  this.loadEnv()
253
- process.emit('timeEnd', 'config:load:env')
254
245
 
255
246
  // next project config, which can affect userconfig location
256
- process.emit('time', 'config:load:project')
257
247
  await this.loadProjectConfig()
258
- process.emit('timeEnd', 'config:load:project')
248
+
259
249
  // then user config, which can affect globalconfig location
260
- process.emit('time', 'config:load:user')
261
250
  await this.loadUserConfig()
262
- process.emit('timeEnd', 'config:load:user')
251
+
263
252
  // last but not least, global config file
264
- process.emit('time', 'config:load:global')
265
253
  await this.loadGlobalConfig()
266
- process.emit('timeEnd', 'config:load:global')
267
254
 
268
255
  // set this before calling setEnvs, so that we don't have to share
269
256
  // private attributes, as that module also does a bunch of get operations
@@ -272,11 +259,7 @@ class Config {
272
259
  // set proper globalPrefix now that everything is loaded
273
260
  this.globalPrefix = this.get('prefix')
274
261
 
275
- process.emit('time', 'config:load:setEnvs')
276
262
  this.setEnvs()
277
- process.emit('timeEnd', 'config:load:setEnvs')
278
-
279
- process.emit('timeEnd', 'config:load')
280
263
  }
281
264
 
282
265
  loadDefaults () {
@@ -574,7 +557,7 @@ class Config {
574
557
  const k = envReplace(key, this.env)
575
558
  const v = this.parseField(value, k)
576
559
  if (where !== 'default') {
577
- this.#checkDeprecated(k, where, obj, [key, value])
560
+ this.#checkDeprecated(k)
578
561
  if (this.definitions[key]?.exclusive) {
579
562
  for (const exclusive of this.definitions[key].exclusive) {
580
563
  if (!this.isDefault(exclusive)) {
@@ -588,7 +571,7 @@ class Config {
588
571
  }
589
572
  }
590
573
 
591
- #checkDeprecated (key, where, obj, kv) {
574
+ #checkDeprecated (key) {
592
575
  // XXX(npm9+) make this throw an error
593
576
  if (this.deprecated[key]) {
594
577
  log.warn('config', key, this.deprecated[key])
@@ -601,8 +584,8 @@ class Config {
601
584
  }
602
585
 
603
586
  async #loadFile (file, type) {
604
- process.emit('time', 'config:load:file:' + file)
605
587
  // only catch the error from readFile, not from the loadObject call
588
+ log.silly(`config:load:file:${file}`)
606
589
  await readFile(file, 'utf8').then(
607
590
  data => {
608
591
  const parsedConfig = ini.parse(data)
@@ -615,7 +598,6 @@ class Config {
615
598
  },
616
599
  er => this.#loadObject(null, type, file, er)
617
600
  )
618
- process.emit('timeEnd', 'config:load:file:' + file)
619
601
  }
620
602
 
621
603
  loadBuiltinConfig () {
@@ -757,7 +739,7 @@ class Config {
757
739
  const iniData = ini.stringify(conf.raw).trim() + '\n'
758
740
  if (!iniData.trim()) {
759
741
  // ignore the unlink error (eg, if file doesn't exist)
760
- await unlink(conf.source).catch(er => {})
742
+ await unlink(conf.source).catch(() => {})
761
743
  return
762
744
  }
763
745
  const dir = dirname(conf.source)
@@ -792,12 +774,9 @@ class Config {
792
774
  this.delete(`${nerfed}:keyfile`, level)
793
775
  }
794
776
 
795
- setCredentialsByURI (uri, { token, username, password, email, certfile, keyfile }) {
777
+ setCredentialsByURI (uri, { token, username, password, certfile, keyfile }) {
796
778
  const nerfed = nerfDart(uri)
797
779
 
798
- // email is either provided, a top level key, or nothing
799
- email = email || this.get('email', 'user')
800
-
801
780
  // field that hasn't been used as documented for a LONG time,
802
781
  // and as of npm 7.10.0, isn't used at all. We just always
803
782
  // send auth if we have it, only to the URIs under the nerf dart.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@npmcli/config",
3
- "version": "8.2.2",
3
+ "version": "8.3.1",
4
4
  "files": [
5
5
  "bin/",
6
6
  "lib/"
@@ -9,7 +9,7 @@
9
9
  "description": "Configuration management for the npm cli",
10
10
  "repository": {
11
11
  "type": "git",
12
- "url": "https://github.com/npm/cli.git",
12
+ "url": "git+https://github.com/npm/cli.git",
13
13
  "directory": "workspaces/config"
14
14
  },
15
15
  "author": "GitHub Inc.",
@@ -40,7 +40,7 @@
40
40
  "ci-info": "^4.0.0",
41
41
  "ini": "^4.1.2",
42
42
  "nopt": "^7.0.0",
43
- "proc-log": "^3.0.0",
43
+ "proc-log": "^4.2.0",
44
44
  "read-package-json-fast": "^3.0.2",
45
45
  "semver": "^7.3.5",
46
46
  "walk-up-path": "^3.0.1"