diff --git a/workspaces/config/lib/index.js b/workspaces/config/lib/index.js index c3e73dc761c57..49c4f0a18115c 100644 --- a/workspaces/config/lib/index.js +++ b/workspaces/config/lib/index.js @@ -233,27 +233,24 @@ class Config { throw new Error('attempting to load npm config multiple times') } - const timeEnd = time.start('config:load') - // first load the defaults, which sets the global prefix - time.start('config:load:defaults', () => this.loadDefaults()) + this.loadDefaults() // next load the builtin config, as this sets new effective defaults - await time.start('config:load:builtin', () => this.loadBuiltinConfig()) + await this.loadBuiltinConfig() // cli and env are not async, and can set the prefix, relevant to project - time.start('config:load:cli', () => this.loadCLI()) - - time.start('config:load:env', () => this.loadEnv()) + this.loadCLI() + this.loadEnv() // next project config, which can affect userconfig location - await time.start('config:load:project', () => this.loadProjectConfig()) + await this.loadProjectConfig() // then user config, which can affect globalconfig location - await time.start('config:load:user', () => this.loadUserConfig()) + await this.loadUserConfig() // last but not least, global config file - await time.start('config:load:global', () => this.loadGlobalConfig()) + await this.loadGlobalConfig() // set this before calling setEnvs, so that we don't have to share // private attributes, as that module also does a bunch of get operations @@ -262,9 +259,7 @@ class Config { // set proper globalPrefix now that everything is loaded this.globalPrefix = this.get('prefix') - time.start('config:load:setEnvs', () => this.setEnvs()) - - timeEnd() + this.setEnvs() } loadDefaults () { @@ -590,7 +585,8 @@ class Config { async #loadFile (file, type) { // only catch the error from readFile, not from the loadObject call - await time.start(`config:load:file:${file}`, () => readFile(file, 'utf8').then( + log.silly(`config:load:file:${file}`) + await readFile(file, 'utf8').then( data => { const parsedConfig = ini.parse(data) if (type === 'project' && parsedConfig.prefix) { @@ -601,7 +597,7 @@ class Config { return this.#loadObject(parsedConfig, type, file) }, er => this.#loadObject(null, type, file, er) - )) + ) } loadBuiltinConfig () { diff --git a/workspaces/config/test/index.js b/workspaces/config/test/index.js index 9e9fac4f6dc34..e1c976e2e52d0 100644 --- a/workspaces/config/test/index.js +++ b/workspaces/config/test/index.js @@ -237,9 +237,10 @@ loglevel = yolo }) logs.length = 0 await config.load() - t.match(logs, [['verbose', 'config', 'error loading user config', { - message: 'weird error', - }]]) + t.match(logs.find(l => l[0] === 'verbose'), + ['verbose', 'config', 'error loading user config', { + message: 'weird error', + }]) logs.length = 0 }) @@ -375,7 +376,7 @@ loglevel = yolo // warn logs are emitted as a side effect of validate config.validate() - t.strictSame(logs, [ + t.strictSame(logs.filter(l => l[0] === 'warn'), [ ['warn', 'invalid config', 'registry="hello"', 'set in command line options'], ['warn', 'invalid config', 'Must be', 'full url with "http://"'], ['warn', 'invalid config', 'proxy="hello"', 'set in command line options'], @@ -392,8 +393,7 @@ loglevel = yolo ['warn', 'invalid config', 'prefix=true', 'set in command line options'], ['warn', 'invalid config', 'Must be', 'valid filesystem path'], ['warn', 'config', 'also', 'Please use --include=dev instead.'], - ['warn', 'invalid config', 'loglevel="yolo"', - `set in ${resolve(path, 'project/.npmrc')}`], + ['warn', 'invalid config', 'loglevel="yolo"', `set in ${resolve(path, 'project/.npmrc')}`], ['warn', 'invalid config', 'Must be one of:', ['silent', 'error', 'warn', 'notice', 'http', 'info', 'verbose', 'silly'].join(', '), ], @@ -570,7 +570,7 @@ loglevel = yolo all: config.get('all'), }) - t.strictSame(logs, [ + t.strictSame(logs.filter(l => l[0] === 'warn'), [ ['warn', 'invalid config', 'registry="hello"', 'set in command line options'], ['warn', 'invalid config', 'Must be', 'full url with "http://"'], ['warn', 'invalid config', 'proxy="hello"', 'set in command line options'], @@ -1183,8 +1183,9 @@ t.test('workspaces', async (t) => { await config.load() t.equal(config.localPrefix, path, 'localPrefix is the root') t.same(config.get('workspace'), [join(path, 'workspaces', 'one')], 'set the workspace') - t.equal(logs.length, 1, 'got one log message') - t.match(logs[0], ['info', /^found workspace root at/], 'logged info about workspace root') + const info = logs.filter(l => l[0] === 'info') + t.equal(info.length, 1, 'got one log message') + t.match(info[0], ['info', /^found workspace root at/], 'logged info about workspace root') }) t.test('finds other workspace parent', async (t) => { @@ -1204,8 +1205,9 @@ t.test('workspaces', async (t) => { await config.load() t.equal(config.localPrefix, path, 'localPrefix is the root') t.same(config.get('workspace'), ['../two'], 'kept the specified workspace') - t.equal(logs.length, 1, 'got one log message') - t.match(logs[0], ['info', /^found workspace root at/], 'logged info about workspace root') + const info = logs.filter(l => l[0] === 'info') + t.equal(info.length, 1, 'got one log message') + t.match(info[0], ['info', /^found workspace root at/], 'logged info about workspace root') }) t.test('warns when workspace has .npmrc', async (t) => { @@ -1225,9 +1227,10 @@ t.test('workspaces', async (t) => { await config.load() t.equal(config.localPrefix, path, 'localPrefix is the root') t.same(config.get('workspace'), [join(path, 'workspaces', 'three')], 'kept the workspace') - t.equal(logs.length, 2, 'got two log messages') - t.match(logs[0], ['warn', /^ignoring workspace config/], 'warned about ignored config') - t.match(logs[1], ['info', /^found workspace root at/], 'logged info about workspace root') + const filtered = logs.filter(l => l[0] === 'info' || l[0] === 'warn') + t.equal(filtered.length, 2, 'got two log messages') + t.match(filtered[0], ['warn', /^ignoring workspace config/], 'warned about ignored config') + t.match(filtered[1], ['info', /^found workspace root at/], 'logged info about workspace root') }) t.test('prefix skips auto detect', async (t) => { @@ -1247,7 +1250,8 @@ t.test('workspaces', async (t) => { await config.load() t.equal(config.localPrefix, join(path, 'workspaces', 'one'), 'localPrefix is the root') t.same(config.get('workspace'), [], 'did not set workspace') - t.equal(logs.length, 0, 'got no log messages') + const filtered = logs.filter(l => l[0] !== 'silly') + t.equal(filtered.length, 0, 'got no log messages') }) t.test('no-workspaces skips auto detect', async (t) => { @@ -1267,7 +1271,8 @@ t.test('workspaces', async (t) => { await config.load() t.equal(config.localPrefix, join(path, 'workspaces', 'one'), 'localPrefix is the root') t.same(config.get('workspace'), [], 'did not set workspace') - t.equal(logs.length, 0, 'got no log messages') + const filtered = logs.filter(l => l[0] !== 'silly') + t.equal(filtered.length, 0, 'got no log messages') }) t.test('global skips auto detect', async (t) => { @@ -1287,7 +1292,8 @@ t.test('workspaces', async (t) => { await config.load() t.equal(config.localPrefix, join(path, 'workspaces', 'one'), 'localPrefix is the root') t.same(config.get('workspace'), [], 'did not set workspace') - t.equal(logs.length, 0, 'got no log messages') + const filtered = logs.filter(l => l[0] !== 'silly') + t.equal(filtered.length, 0, 'got no log messages') }) t.test('location=global skips auto detect', async (t) => { @@ -1307,7 +1313,8 @@ t.test('workspaces', async (t) => { await config.load() t.equal(config.localPrefix, join(path, 'workspaces', 'one'), 'localPrefix is the root') t.same(config.get('workspace'), [], 'did not set workspace') - t.equal(logs.length, 0, 'got no log messages') + const filtered = logs.filter(l => l[0] !== 'silly') + t.equal(filtered.length, 0, 'got no log messages') }) t.test('excludeNpmCwd skips auto detect', async (t) => { @@ -1328,7 +1335,8 @@ t.test('workspaces', async (t) => { await config.load() t.equal(config.localPrefix, join(path, 'workspaces', 'one'), 'localPrefix is the root') t.same(config.get('workspace'), [], 'did not set workspace') - t.equal(logs.length, 0, 'got no log messages') + const filtered = logs.filter(l => l[0] !== 'silly') + t.equal(filtered.length, 0, 'got no log messages') }) t.test('does not error for invalid package.json', async (t) => { @@ -1354,8 +1362,9 @@ t.test('workspaces', async (t) => { await config.load() t.equal(config.localPrefix, path, 'localPrefix is the root') t.same(config.get('workspace'), [join(path, 'workspaces', 'one')], 'set the workspace') - t.equal(logs.length, 1, 'got one log message') - t.match(logs[0], ['info', /^found workspace root at/], 'logged info about workspace root') + const filtered = logs.filter(l => l[0] !== 'silly') + t.equal(filtered.length, 1, 'got one log message') + t.match(filtered[0], ['info', /^found workspace root at/], 'logged info about workspace root') }) }) @@ -1474,7 +1483,8 @@ t.test('catch project config prefix error', async t => { logs.length = 0 // config.load() triggers the error to be logged await config.load() - t.match(logs, [[ + const filtered = logs.filter(l => l[0] !== 'silly') + t.match(filtered, [[ 'error', 'config', `prefix cannot be changed from project config: ${path}`, ]], 'Expected error logged') })