Skip to content

Commit 11ec231

Browse files
authoredNov 29, 2023
fix: skip creation of log directory if logs-max is set to 0 (#7033)
Closes: #7032
1 parent 6267f54 commit 11ec231

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed
 

‎lib/npm.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,13 @@ class Npm {
216216
fs.mkdir(this.cache, { recursive: true })
217217
.catch((e) => log.verbose('cache', `could not create cache: ${e}`)))
218218

219-
// its ok if this fails. user might have specified an invalid dir
219+
// it's ok if this fails. user might have specified an invalid dir
220220
// which we will tell them about at the end
221-
await this.time('npm:load:mkdirplogs', () =>
222-
fs.mkdir(this.logsDir, { recursive: true })
223-
.catch((e) => log.verbose('logfile', `could not create logs-dir: ${e}`)))
221+
if (this.config.get('logs-max') > 0) {
222+
await this.time('npm:load:mkdirplogs', () =>
223+
fs.mkdir(this.logsDir, { recursive: true })
224+
.catch((e) => log.verbose('logfile', `could not create logs-dir: ${e}`)))
225+
}
224226

225227
// note: this MUST be shorter than the actual argv length, because it
226228
// uses the same memory, so node will truncate it if it's too long.

‎test/lib/utils/exit-handler.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -344,12 +344,12 @@ t.test('no logs dir', async (t) => {
344344
const { exitHandler, logs } = await mockExitHandler(t, {
345345
config: { 'logs-max': 0 },
346346
})
347-
348347
await exitHandler(new Error())
349348

350349
t.match(logs.error.filter(([t]) => t === ''), [
351350
['', 'Log files were not written due to the config logs-max=0'],
352351
])
352+
t.match(logs.filter(([_, task]) => task === 'npm.load.mkdirplogs'), [])
353353
})
354354

355355
t.test('timers fail to write', async (t) => {

0 commit comments

Comments
 (0)
Please sign in to comment.