Skip to content

Commit

Permalink
fix: skip creation of log directory if logs-max is set to 0 (#7033)
Browse files Browse the repository at this point in the history
Closes: #7032
  • Loading branch information
JJ authored Nov 29, 2023
1 parent 6267f54 commit 11ec231
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions lib/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion test/lib/utils/exit-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 11ec231

Please sign in to comment.