@npmcli/config 8.2.1 → 8.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/index.js CHANGED
@@ -2,12 +2,10 @@
2
2
  const { walkUp } = require('walk-up-path')
3
3
  const ini = require('ini')
4
4
  const nopt = require('nopt')
5
- const mapWorkspaces = require('@npmcli/map-workspaces')
6
- const rpj = require('read-package-json-fast')
7
- const log = require('proc-log')
5
+ const { log, time } = require('proc-log')
8
6
 
9
- const { resolve, dirname, join } = require('path')
10
- const { homedir } = require('os')
7
+ const { resolve, dirname, join } = require('node:path')
8
+ const { homedir } = require('node:os')
11
9
  const {
12
10
  readFile,
13
11
  writeFile,
@@ -28,35 +26,12 @@ const dirExists = (...p) => stat(resolve(...p))
28
26
  const hasOwnProperty = (obj, key) =>
29
27
  Object.prototype.hasOwnProperty.call(obj, key)
30
28
 
31
- // define a custom getter, but turn into a normal prop
32
- // if we set it. otherwise it can't be set on child objects
33
- const settableGetter = (obj, key, get) => {
34
- Object.defineProperty(obj, key, {
35
- get,
36
- set (value) {
37
- Object.defineProperty(obj, key, {
38
- value,
39
- configurable: true,
40
- writable: true,
41
- enumerable: true,
42
- })
43
- },
44
- configurable: true,
45
- enumerable: true,
46
- })
47
- }
48
-
49
29
  const typeDefs = require('./type-defs.js')
50
30
  const nerfDart = require('./nerf-dart.js')
51
31
  const envReplace = require('./env-replace.js')
52
32
  const parseField = require('./parse-field.js')
53
- const typeDescription = require('./type-description.js')
54
33
  const setEnvs = require('./set-envs.js')
55
34
 
56
- const {
57
- ErrInvalidAuth,
58
- } = require('./errors.js')
59
-
60
35
  // types that can be saved back to
61
36
  const confFileTypes = new Set([
62
37
  'global',
@@ -226,7 +201,7 @@ class Config {
226
201
  }
227
202
 
228
203
  // create the object for flat options passed to deps
229
- process.emit('time', 'config:load:flatten')
204
+ const timeEnd = time.start('config:load:flatten')
230
205
  this.#flatOptions = {}
231
206
  // walk from least priority to highest
232
207
  for (const { data } of this.data.values()) {
@@ -234,7 +209,7 @@ class Config {
234
209
  }
235
210
  this.#flatOptions.nodeBin = this.execPath
236
211
  this.#flatOptions.npmBin = this.npmBin
237
- process.emit('timeEnd', 'config:load:flatten')
212
+ timeEnd()
238
213
 
239
214
  return this.#flatOptions
240
215
  }
@@ -258,37 +233,24 @@ class Config {
258
233
  throw new Error('attempting to load npm config multiple times')
259
234
  }
260
235
 
261
- process.emit('time', 'config:load')
262
236
  // first load the defaults, which sets the global prefix
263
- process.emit('time', 'config:load:defaults')
264
237
  this.loadDefaults()
265
- process.emit('timeEnd', 'config:load:defaults')
266
238
 
267
239
  // next load the builtin config, as this sets new effective defaults
268
- process.emit('time', 'config:load:builtin')
269
240
  await this.loadBuiltinConfig()
270
- process.emit('timeEnd', 'config:load:builtin')
271
241
 
272
242
  // cli and env are not async, and can set the prefix, relevant to project
273
- process.emit('time', 'config:load:cli')
274
243
  this.loadCLI()
275
- process.emit('timeEnd', 'config:load:cli')
276
- process.emit('time', 'config:load:env')
277
244
  this.loadEnv()
278
- process.emit('timeEnd', 'config:load:env')
279
245
 
280
246
  // next project config, which can affect userconfig location
281
- process.emit('time', 'config:load:project')
282
247
  await this.loadProjectConfig()
283
- process.emit('timeEnd', 'config:load:project')
248
+
284
249
  // then user config, which can affect globalconfig location
285
- process.emit('time', 'config:load:user')
286
250
  await this.loadUserConfig()
287
- process.emit('timeEnd', 'config:load:user')
251
+
288
252
  // last but not least, global config file
289
- process.emit('time', 'config:load:global')
290
253
  await this.loadGlobalConfig()
291
- process.emit('timeEnd', 'config:load:global')
292
254
 
293
255
  // set this before calling setEnvs, so that we don't have to share
294
256
  // private attributes, as that module also does a bunch of get operations
@@ -297,11 +259,7 @@ class Config {
297
259
  // set proper globalPrefix now that everything is loaded
298
260
  this.globalPrefix = this.get('prefix')
299
261
 
300
- process.emit('time', 'config:load:setEnvs')
301
262
  this.setEnvs()
302
- process.emit('timeEnd', 'config:load:setEnvs')
303
-
304
- process.emit('timeEnd', 'config:load')
305
263
  }
306
264
 
307
265
  loadDefaults () {
@@ -329,7 +287,21 @@ class Config {
329
287
  // default the globalconfig file to that location, instead of the default
330
288
  // global prefix. It's weird that `npm get globalconfig --prefix=/foo`
331
289
  // returns `/foo/etc/npmrc`, but better to not change it at this point.
332
- settableGetter(data, 'globalconfig', () => resolve(this.#get('prefix'), 'etc/npmrc'))
290
+ // define a custom getter, but turn into a normal prop
291
+ // if we set it. otherwise it can't be set on child objects
292
+ Object.defineProperty(data, 'globalconfig', {
293
+ get: () => resolve(this.#get('prefix'), 'etc/npmrc'),
294
+ set (value) {
295
+ Object.defineProperty(data, 'globalconfig', {
296
+ value,
297
+ configurable: true,
298
+ writable: true,
299
+ enumerable: true,
300
+ })
301
+ },
302
+ configurable: true,
303
+ enumerable: true,
304
+ })
333
305
  }
334
306
 
335
307
  loadHome () {
@@ -444,6 +416,7 @@ class Config {
444
416
  }
445
417
 
446
418
  if (authProblems.length) {
419
+ const { ErrInvalidAuth } = require('./errors.js')
447
420
  throw new ErrInvalidAuth(authProblems)
448
421
  }
449
422
 
@@ -512,6 +485,7 @@ class Config {
512
485
  }
513
486
 
514
487
  invalidHandler (k, val, type, source, where) {
488
+ const typeDescription = require('./type-description.js')
515
489
  log.warn(
516
490
  'invalid config',
517
491
  k + '=' + JSON.stringify(val),
@@ -610,8 +584,8 @@ class Config {
610
584
  }
611
585
 
612
586
  async #loadFile (file, type) {
613
- process.emit('time', 'config:load:file:' + file)
614
587
  // only catch the error from readFile, not from the loadObject call
588
+ log.silly(`config:load:file:${file}`)
615
589
  await readFile(file, 'utf8').then(
616
590
  data => {
617
591
  const parsedConfig = ini.parse(data)
@@ -624,7 +598,6 @@ class Config {
624
598
  },
625
599
  er => this.#loadObject(null, type, file, er)
626
600
  )
627
- process.emit('timeEnd', 'config:load:file:' + file)
628
601
  }
629
602
 
630
603
  loadBuiltinConfig () {
@@ -696,6 +669,7 @@ class Config {
696
669
  }
697
670
 
698
671
  if (this.localPrefix && hasPackageJson) {
672
+ const rpj = require('read-package-json-fast')
699
673
  // if we already set localPrefix but this dir has a package.json
700
674
  // then we need to see if `p` is a workspace root by reading its package.json
701
675
  // however, if reading it fails then we should just move on
@@ -704,6 +678,7 @@ class Config {
704
678
  continue
705
679
  }
706
680
 
681
+ const mapWorkspaces = require('@npmcli/map-workspaces')
707
682
  const workspaces = await mapWorkspaces({ cwd: p, pkg })
708
683
  for (const w of workspaces.values()) {
709
684
  if (w === this.localPrefix) {
package/lib/nerf-dart.js CHANGED
@@ -1,4 +1,4 @@
1
- const { URL } = require('url')
1
+ const { URL } = require('node:url')
2
2
 
3
3
  /**
4
4
  * Maps a URL to an identifier.
@@ -1,7 +1,7 @@
1
1
  // Parse a field, coercing it to the best type available.
2
2
  const typeDefs = require('./type-defs.js')
3
3
  const envReplace = require('./env-replace.js')
4
- const { resolve } = require('path')
4
+ const { resolve } = require('node:path')
5
5
 
6
6
  const { parse: umaskParse } = require('./umask.js')
7
7
 
package/lib/type-defs.js CHANGED
@@ -1,10 +1,12 @@
1
1
  const nopt = require('nopt')
2
2
 
3
- const { Umask, validate: validateUmask } = require('./umask.js')
3
+ const { validate: validateUmask } = require('./umask.js')
4
4
 
5
- const semver = require('semver')
5
+ class Umask {}
6
+ class Semver {}
7
+ const semverValid = require('semver/functions/valid')
6
8
  const validateSemver = (data, k, val) => {
7
- const valid = semver.valid(val)
9
+ const valid = semverValid(val)
8
10
  if (!valid) {
9
11
  return false
10
12
  }
@@ -23,7 +25,7 @@ const validatePath = (data, k, val) => {
23
25
  module.exports = {
24
26
  ...nopt.typeDefs,
25
27
  semver: {
26
- type: semver,
28
+ type: Semver,
27
29
  validate: validateSemver,
28
30
  description: 'full valid SemVer string',
29
31
  },
package/lib/umask.js CHANGED
@@ -1,4 +1,3 @@
1
- class Umask {}
2
1
  const parse = val => {
3
2
  // this is run via nopt and parse field where everything is
4
3
  // converted to a string first, ignoring coverage for now
@@ -33,4 +32,4 @@ const validate = (data, k, val) => {
33
32
  }
34
33
  }
35
34
 
36
- module.exports = { Umask, parse, validate }
35
+ module.exports = { parse, validate }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@npmcli/config",
3
- "version": "8.2.1",
3
+ "version": "8.3.0",
4
4
  "files": [
5
5
  "bin/",
6
6
  "lib/"
@@ -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"