Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: skip creation of log directory if logs-max is set to 0 #7033

Merged
merged 7 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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