Skip to content

Commit 03634be

Browse files
committed
fix: remove granular config timers
1 parent 28019d5 commit 03634be

File tree

2 files changed

+43
-37
lines changed

2 files changed

+43
-37
lines changed

workspaces/config/lib/index.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -233,27 +233,24 @@ class Config {
233233
throw new Error('attempting to load npm config multiple times')
234234
}
235235

236-
const timeEnd = time.start('config:load')
237-
238236
// first load the defaults, which sets the global prefix
239-
time.start('config:load:defaults', () => this.loadDefaults())
237+
this.loadDefaults()
240238

241239
// next load the builtin config, as this sets new effective defaults
242-
await time.start('config:load:builtin', () => this.loadBuiltinConfig())
240+
await this.loadBuiltinConfig()
243241

244242
// cli and env are not async, and can set the prefix, relevant to project
245-
time.start('config:load:cli', () => this.loadCLI())
246-
247-
time.start('config:load:env', () => this.loadEnv())
243+
this.loadCLI()
244+
this.loadEnv()
248245

249246
// next project config, which can affect userconfig location
250-
await time.start('config:load:project', () => this.loadProjectConfig())
247+
await this.loadProjectConfig()
251248

252249
// then user config, which can affect globalconfig location
253-
await time.start('config:load:user', () => this.loadUserConfig())
250+
await this.loadUserConfig()
254251

255252
// last but not least, global config file
256-
await time.start('config:load:global', () => this.loadGlobalConfig())
253+
await this.loadGlobalConfig()
257254

258255
// set this before calling setEnvs, so that we don't have to share
259256
// private attributes, as that module also does a bunch of get operations
@@ -262,9 +259,7 @@ class Config {
262259
// set proper globalPrefix now that everything is loaded
263260
this.globalPrefix = this.get('prefix')
264261

265-
time.start('config:load:setEnvs', () => this.setEnvs())
266-
267-
timeEnd()
262+
this.setEnvs()
268263
}
269264

270265
loadDefaults () {
@@ -590,7 +585,8 @@ class Config {
590585

591586
async #loadFile (file, type) {
592587
// only catch the error from readFile, not from the loadObject call
593-
await time.start(`config:load:file:${file}`, () => readFile(file, 'utf8').then(
588+
log.silly(`config:load:file:${file}`)
589+
await readFile(file, 'utf8').then(
594590
data => {
595591
const parsedConfig = ini.parse(data)
596592
if (type === 'project' && parsedConfig.prefix) {
@@ -601,7 +597,7 @@ class Config {
601597
return this.#loadObject(parsedConfig, type, file)
602598
},
603599
er => this.#loadObject(null, type, file, er)
604-
))
600+
)
605601
}
606602

607603
loadBuiltinConfig () {

workspaces/config/test/index.js

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,10 @@ loglevel = yolo
237237
})
238238
logs.length = 0
239239
await config.load()
240-
t.match(logs, [['verbose', 'config', 'error loading user config', {
241-
message: 'weird error',
242-
}]])
240+
t.match(logs.find(l => l[0] === 'verbose'),
241+
['verbose', 'config', 'error loading user config', {
242+
message: 'weird error',
243+
}])
243244
logs.length = 0
244245
})
245246

@@ -375,7 +376,7 @@ loglevel = yolo
375376

376377
// warn logs are emitted as a side effect of validate
377378
config.validate()
378-
t.strictSame(logs, [
379+
t.strictSame(logs.filter(l => l[0] === 'warn'), [
379380
['warn', 'invalid config', 'registry="hello"', 'set in command line options'],
380381
['warn', 'invalid config', 'Must be', 'full url with "http://"'],
381382
['warn', 'invalid config', 'proxy="hello"', 'set in command line options'],
@@ -392,8 +393,7 @@ loglevel = yolo
392393
['warn', 'invalid config', 'prefix=true', 'set in command line options'],
393394
['warn', 'invalid config', 'Must be', 'valid filesystem path'],
394395
['warn', 'config', 'also', 'Please use --include=dev instead.'],
395-
['warn', 'invalid config', 'loglevel="yolo"',
396-
`set in ${resolve(path, 'project/.npmrc')}`],
396+
['warn', 'invalid config', 'loglevel="yolo"', `set in ${resolve(path, 'project/.npmrc')}`],
397397
['warn', 'invalid config', 'Must be one of:',
398398
['silent', 'error', 'warn', 'notice', 'http', 'info', 'verbose', 'silly'].join(', '),
399399
],
@@ -570,7 +570,7 @@ loglevel = yolo
570570
all: config.get('all'),
571571
})
572572

573-
t.strictSame(logs, [
573+
t.strictSame(logs.filter(l => l[0] === 'warn'), [
574574
['warn', 'invalid config', 'registry="hello"', 'set in command line options'],
575575
['warn', 'invalid config', 'Must be', 'full url with "http://"'],
576576
['warn', 'invalid config', 'proxy="hello"', 'set in command line options'],
@@ -1183,8 +1183,9 @@ t.test('workspaces', async (t) => {
11831183
await config.load()
11841184
t.equal(config.localPrefix, path, 'localPrefix is the root')
11851185
t.same(config.get('workspace'), [join(path, 'workspaces', 'one')], 'set the workspace')
1186-
t.equal(logs.length, 1, 'got one log message')
1187-
t.match(logs[0], ['info', /^found workspace root at/], 'logged info about workspace root')
1186+
const info = logs.filter(l => l[0] === 'info')
1187+
t.equal(info.length, 1, 'got one log message')
1188+
t.match(info[0], ['info', /^found workspace root at/], 'logged info about workspace root')
11881189
})
11891190

11901191
t.test('finds other workspace parent', async (t) => {
@@ -1204,8 +1205,9 @@ t.test('workspaces', async (t) => {
12041205
await config.load()
12051206
t.equal(config.localPrefix, path, 'localPrefix is the root')
12061207
t.same(config.get('workspace'), ['../two'], 'kept the specified workspace')
1207-
t.equal(logs.length, 1, 'got one log message')
1208-
t.match(logs[0], ['info', /^found workspace root at/], 'logged info about workspace root')
1208+
const info = logs.filter(l => l[0] === 'info')
1209+
t.equal(info.length, 1, 'got one log message')
1210+
t.match(info[0], ['info', /^found workspace root at/], 'logged info about workspace root')
12091211
})
12101212

12111213
t.test('warns when workspace has .npmrc', async (t) => {
@@ -1225,9 +1227,10 @@ t.test('workspaces', async (t) => {
12251227
await config.load()
12261228
t.equal(config.localPrefix, path, 'localPrefix is the root')
12271229
t.same(config.get('workspace'), [join(path, 'workspaces', 'three')], 'kept the workspace')
1228-
t.equal(logs.length, 2, 'got two log messages')
1229-
t.match(logs[0], ['warn', /^ignoring workspace config/], 'warned about ignored config')
1230-
t.match(logs[1], ['info', /^found workspace root at/], 'logged info about workspace root')
1230+
const filtered = logs.filter(l => l[0] === 'info' || l[0] === 'warn')
1231+
t.equal(filtered.length, 2, 'got two log messages')
1232+
t.match(filtered[0], ['warn', /^ignoring workspace config/], 'warned about ignored config')
1233+
t.match(filtered[1], ['info', /^found workspace root at/], 'logged info about workspace root')
12311234
})
12321235

12331236
t.test('prefix skips auto detect', async (t) => {
@@ -1247,7 +1250,8 @@ t.test('workspaces', async (t) => {
12471250
await config.load()
12481251
t.equal(config.localPrefix, join(path, 'workspaces', 'one'), 'localPrefix is the root')
12491252
t.same(config.get('workspace'), [], 'did not set workspace')
1250-
t.equal(logs.length, 0, 'got no log messages')
1253+
const filtered = logs.filter(l => l[0] !== 'silly')
1254+
t.equal(filtered.length, 0, 'got no log messages')
12511255
})
12521256

12531257
t.test('no-workspaces skips auto detect', async (t) => {
@@ -1267,7 +1271,8 @@ t.test('workspaces', async (t) => {
12671271
await config.load()
12681272
t.equal(config.localPrefix, join(path, 'workspaces', 'one'), 'localPrefix is the root')
12691273
t.same(config.get('workspace'), [], 'did not set workspace')
1270-
t.equal(logs.length, 0, 'got no log messages')
1274+
const filtered = logs.filter(l => l[0] !== 'silly')
1275+
t.equal(filtered.length, 0, 'got no log messages')
12711276
})
12721277

12731278
t.test('global skips auto detect', async (t) => {
@@ -1287,7 +1292,8 @@ t.test('workspaces', async (t) => {
12871292
await config.load()
12881293
t.equal(config.localPrefix, join(path, 'workspaces', 'one'), 'localPrefix is the root')
12891294
t.same(config.get('workspace'), [], 'did not set workspace')
1290-
t.equal(logs.length, 0, 'got no log messages')
1295+
const filtered = logs.filter(l => l[0] !== 'silly')
1296+
t.equal(filtered.length, 0, 'got no log messages')
12911297
})
12921298

12931299
t.test('location=global skips auto detect', async (t) => {
@@ -1307,7 +1313,8 @@ t.test('workspaces', async (t) => {
13071313
await config.load()
13081314
t.equal(config.localPrefix, join(path, 'workspaces', 'one'), 'localPrefix is the root')
13091315
t.same(config.get('workspace'), [], 'did not set workspace')
1310-
t.equal(logs.length, 0, 'got no log messages')
1316+
const filtered = logs.filter(l => l[0] !== 'silly')
1317+
t.equal(filtered.length, 0, 'got no log messages')
13111318
})
13121319

13131320
t.test('excludeNpmCwd skips auto detect', async (t) => {
@@ -1328,7 +1335,8 @@ t.test('workspaces', async (t) => {
13281335
await config.load()
13291336
t.equal(config.localPrefix, join(path, 'workspaces', 'one'), 'localPrefix is the root')
13301337
t.same(config.get('workspace'), [], 'did not set workspace')
1331-
t.equal(logs.length, 0, 'got no log messages')
1338+
const filtered = logs.filter(l => l[0] !== 'silly')
1339+
t.equal(filtered.length, 0, 'got no log messages')
13321340
})
13331341

13341342
t.test('does not error for invalid package.json', async (t) => {
@@ -1354,8 +1362,9 @@ t.test('workspaces', async (t) => {
13541362
await config.load()
13551363
t.equal(config.localPrefix, path, 'localPrefix is the root')
13561364
t.same(config.get('workspace'), [join(path, 'workspaces', 'one')], 'set the workspace')
1357-
t.equal(logs.length, 1, 'got one log message')
1358-
t.match(logs[0], ['info', /^found workspace root at/], 'logged info about workspace root')
1365+
const filtered = logs.filter(l => l[0] !== 'silly')
1366+
t.equal(filtered.length, 1, 'got one log message')
1367+
t.match(filtered[0], ['info', /^found workspace root at/], 'logged info about workspace root')
13591368
})
13601369
})
13611370

@@ -1474,7 +1483,8 @@ t.test('catch project config prefix error', async t => {
14741483
logs.length = 0
14751484
// config.load() triggers the error to be logged
14761485
await config.load()
1477-
t.match(logs, [[
1486+
const filtered = logs.filter(l => l[0] !== 'silly')
1487+
t.match(filtered, [[
14781488
'error', 'config', `prefix cannot be changed from project config: ${path}`,
14791489
]], 'Expected error logged')
14801490
})

0 commit comments

Comments
 (0)