From 0aaafe5e6ca7f3232d6e949b302c7d286222cc03 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Mon, 26 Sep 2022 12:04:24 -0700 Subject: [PATCH] fixup! feat: write eresolve error files to the logs directory --- lib/npm.js | 4 ++-- lib/utils/exit-handler.js | 2 +- lib/utils/log-file.js | 4 ++-- lib/utils/timers.js | 2 +- test/lib/utils/exit-handler.js | 2 -- test/lib/utils/log-file.js | 2 +- test/lib/utils/timers.js | 4 ++-- 7 files changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/npm.js b/lib/npm.js index 4198ed905128c..852d91ad3f890 100644 --- a/lib/npm.js +++ b/lib/npm.js @@ -370,8 +370,8 @@ class Npm extends EventEmitter { return this.config.get('logs-dir') || join(this.cache, '_logs') } - logPath = (file = '') => { - return resolve(this.logsDir, `${this.#runId}-${file}`) + get logPath () { + return resolve(this.logsDir, `${this.#runId}-`) } get timingFile () { diff --git a/lib/utils/exit-handler.js b/lib/utils/exit-handler.js index 19bbba24045b4..f1843347bc324 100644 --- a/lib/utils/exit-handler.js +++ b/lib/utils/exit-handler.js @@ -183,7 +183,7 @@ const exitHandler = err => { const { summary, detail, files = [] } = errorMessage(err, npm) for (let [file, content] of files) { - file = npm.logPath(file) + file = `${npm.logPath}${file}` content = `'Log files:\n${npm.logFiles.join('\n')}\n\n${content.trim()}\n` try { fs.withOwnerSync( diff --git a/lib/utils/log-file.js b/lib/utils/log-file.js index a10b6953170c3..3351ae6cdd3d5 100644 --- a/lib/utils/log-file.js +++ b/lib/utils/log-file.js @@ -77,7 +77,7 @@ class LogFiles { return } - log.verbose('logfile', `logs-max:${logsMax} dir:${this.#path()}`) + log.verbose('logfile', `logs-max:${logsMax} dir:${this.#path}`) // Pipe our initial stream to our new file stream and // set that as the new log logstream for future writes @@ -157,7 +157,7 @@ class LogFiles { } #getLogFilePath (count = '') { - return this.#path(`debug-${count}.log`) + return `${this.#path}debug-${count}.log` } #openLogFile () { diff --git a/lib/utils/timers.js b/lib/utils/timers.js index 05b7f1813dfda..c84bbba3819ab 100644 --- a/lib/utils/timers.js +++ b/lib/utils/timers.js @@ -69,7 +69,7 @@ class Timers extends EE { load ({ path } = {}) { if (path) { - this.file = path('timing.json') + this.file = `${path}timing.json` } } diff --git a/test/lib/utils/exit-handler.js b/test/lib/utils/exit-handler.js index 1378d7b7555c4..7d2e7e061c365 100644 --- a/test/lib/utils/exit-handler.js +++ b/test/lib/utils/exit-handler.js @@ -345,9 +345,7 @@ t.test('files from error message with error', async (t) => { '@npmcli/fs': { ...fs, writeFileSync: (dir) => { - console.log(dir) if (dir.includes('LOGS_DIR') && dir.endsWith('error-file.txt')) { - console.log('throw') throw new Error('err') } }, diff --git a/test/lib/utils/log-file.js b/test/lib/utils/log-file.js index 41a0bc5a519a5..4be5231c1c4fa 100644 --- a/test/lib/utils/log-file.js +++ b/test/lib/utils/log-file.js @@ -49,7 +49,7 @@ const loadLogFile = async (t, { buffer = [], mocks, testdir = {}, ...options } = buffer.forEach((b) => logFile.log(...b)) const id = getId() - await logFile.load({ path: (f = '') => path.join(root, `${id}-${f}`), ...options }) + await logFile.load({ path: path.join(root, `${id}-`), ...options }) t.teardown(() => logFile.off()) return { diff --git a/test/lib/utils/timers.js b/test/lib/utils/timers.js index eee7aea142b7c..23d8eb6e2cafe 100644 --- a/test/lib/utils/timers.js +++ b/test/lib/utils/timers.js @@ -72,7 +72,7 @@ t.test('writes file', async (t) => { const dir = t.testdir() process.emit('time', 'foo') process.emit('timeEnd', 'foo') - timers.load({ path: (f) => resolve(dir, `TIMING_FILE-${f}`) }) + timers.load({ path: resolve(dir, `TIMING_FILE-`) }) timers.writeFile({ some: 'data' }) const data = JSON.parse(fs.readFileSync(resolve(dir, 'TIMING_FILE-timing.json'))) t.match(data, { @@ -88,7 +88,7 @@ t.test('fails to write file', async (t) => { const { logs, timers } = mockTimers(t) const dir = t.testdir() - timers.load({ path: () => join(dir, 'does', 'not', 'exist') }) + timers.load({ path: join(dir, 'does', 'not', 'exist') }) timers.writeFile() t.match(logs.warn, [['timing', 'could not write timing file']])