Skip to content

Commit

Permalink
feat: introduce end event for logger (#1058)
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub authored Jan 5, 2025
1 parent 681b93b commit 5d193c0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .size-limit.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{
"name": "dts libdefs",
"path": "build/*.d.ts",
"limit": "37.5 kB",
"limit": "38 kB",
"brotli": false,
"gzip": false
},
Expand Down
1 change: 1 addition & 0 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ export class ProcessPromise extends Promise<ProcessOutput> {
if (stdout.length && !stdout[stdout.length - 1]!.toString().endsWith('\n')) c.on.stdout!(EOL, c)
if (stderr.length && !stderr[stderr.length - 1]!.toString().endsWith('\n')) c.on.stderr!(EOL, c)

$.log({ kind: 'end', signal, exitCode: status, duration, error, verbose: self.isVerbose(), id })
const output = self._output = new ProcessOutput(dto)

if (error || status !== 0 && !self.isNothrow()) {
Expand Down
8 changes: 8 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ export type LogEntry = {
data: Buffer
id: string
}
| {
kind: 'end'
exitCode: number | null
signal: NodeJS.Signals | null
duration: number
error: null | Error
id: string
}
| {
kind: 'cd'
dir: string
Expand Down
13 changes: 11 additions & 2 deletions test/core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,9 @@ describe('core', () => {
const log = (entry) => entries.push(entry)
const p = $({ log })`echo foo`
const { id } = p
await p
const { duration } = await p

assert.equal(entries.length, 2)
assert.equal(entries.length, 3)
assert.deepEqual(entries[0], {
kind: 'cmd',
cmd: 'echo foo',
Expand All @@ -377,6 +377,15 @@ describe('core', () => {
verbose: false,
id,
})
assert.deepEqual(entries[2], {
kind: 'end',
duration,
exitCode: 0,
signal: null,
error: null,
verbose: false,
id,
})
})
})

Expand Down

0 comments on commit 5d193c0

Please sign in to comment.