Skip to content

Commit

Permalink
fixup! feat: write eresolve error files to the logs directory
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Sep 26, 2022
1 parent 7bbd88f commit 0aaafe5
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/exit-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/log-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -157,7 +157,7 @@ class LogFiles {
}

#getLogFilePath (count = '') {
return this.#path(`debug-${count}.log`)
return `${this.#path}debug-${count}.log`
}

#openLogFile () {
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Timers extends EE {

load ({ path } = {}) {
if (path) {
this.file = path('timing.json')
this.file = `${path}timing.json`
}
}

Expand Down
2 changes: 0 additions & 2 deletions test/lib/utils/exit-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
},
Expand Down
2 changes: 1 addition & 1 deletion test/lib/utils/log-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions test/lib/utils/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand All @@ -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']])
Expand Down

0 comments on commit 0aaafe5

Please sign in to comment.