diff --git a/lib/npm.js b/lib/npm.js index 14706629e79c2..3322131d8df44 100644 --- a/lib/npm.js +++ b/lib/npm.js @@ -216,11 +216,13 @@ class Npm { fs.mkdir(this.cache, { recursive: true }) .catch((e) => log.verbose('cache', `could not create cache: ${e}`))) - // its ok if this fails. user might have specified an invalid dir + // it's ok if this fails. user might have specified an invalid dir // which we will tell them about at the end - await this.time('npm:load:mkdirplogs', () => - fs.mkdir(this.logsDir, { recursive: true }) - .catch((e) => log.verbose('logfile', `could not create logs-dir: ${e}`))) + if (this.config.get('logs-max') > 0) { + await this.time('npm:load:mkdirplogs', () => + fs.mkdir(this.logsDir, { recursive: true }) + .catch((e) => log.verbose('logfile', `could not create logs-dir: ${e}`))) + } // note: this MUST be shorter than the actual argv length, because it // uses the same memory, so node will truncate it if it's too long. diff --git a/test/lib/utils/exit-handler.js b/test/lib/utils/exit-handler.js index 3eb5840985b8f..b48f96d581775 100644 --- a/test/lib/utils/exit-handler.js +++ b/test/lib/utils/exit-handler.js @@ -344,12 +344,12 @@ t.test('no logs dir', async (t) => { const { exitHandler, logs } = await mockExitHandler(t, { config: { 'logs-max': 0 }, }) - await exitHandler(new Error()) t.match(logs.error.filter(([t]) => t === ''), [ ['', 'Log files were not written due to the config logs-max=0'], ]) + t.match(logs.filter(([_, task]) => task === 'npm.load.mkdirplogs'), []) }) t.test('timers fail to write', async (t) => {