Skip to content

Commit 5d193c0

Browse files
authored
feat: introduce end event for logger (#1058)
1 parent 681b93b commit 5d193c0

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

.size-limit.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
{
1717
"name": "dts libdefs",
1818
"path": "build/*.d.ts",
19-
"limit": "37.5 kB",
19+
"limit": "38 kB",
2020
"brotli": false,
2121
"gzip": false
2222
},

src/core.ts

+1
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ export class ProcessPromise extends Promise<ProcessOutput> {
333333
if (stdout.length && !stdout[stdout.length - 1]!.toString().endsWith('\n')) c.on.stdout!(EOL, c)
334334
if (stderr.length && !stderr[stderr.length - 1]!.toString().endsWith('\n')) c.on.stderr!(EOL, c)
335335

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

338339
if (error || status !== 0 && !self.isNothrow()) {

src/util.ts

+8
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ export type LogEntry = {
153153
data: Buffer
154154
id: string
155155
}
156+
| {
157+
kind: 'end'
158+
exitCode: number | null
159+
signal: NodeJS.Signals | null
160+
duration: number
161+
error: null | Error
162+
id: string
163+
}
156164
| {
157165
kind: 'cd'
158166
dir: string

test/core.test.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,9 @@ describe('core', () => {
362362
const log = (entry) => entries.push(entry)
363363
const p = $({ log })`echo foo`
364364
const { id } = p
365-
await p
365+
const { duration } = await p
366366

367-
assert.equal(entries.length, 2)
367+
assert.equal(entries.length, 3)
368368
assert.deepEqual(entries[0], {
369369
kind: 'cmd',
370370
cmd: 'echo foo',
@@ -377,6 +377,15 @@ describe('core', () => {
377377
verbose: false,
378378
id,
379379
})
380+
assert.deepEqual(entries[2], {
381+
kind: 'end',
382+
duration,
383+
exitCode: 0,
384+
signal: null,
385+
error: null,
386+
verbose: false,
387+
id,
388+
})
380389
})
381390
})
382391

0 commit comments

Comments
 (0)