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

feat: introduce end event for logger #1058

Merged
merged 1 commit into from
Jan 5, 2025
Merged
Changes from all 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
2 changes: 1 addition & 1 deletion .size-limit.json
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@
{
"name": "dts libdefs",
"path": "build/*.d.ts",
"limit": "37.5 kB",
"limit": "38 kB",
"brotli": false,
"gzip": false
},
1 change: 1 addition & 0 deletions src/core.ts
Original file line number Diff line number Diff line change
@@ -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()) {
8 changes: 8 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -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
13 changes: 11 additions & 2 deletions test/core.test.js
Original file line number Diff line number Diff line change
@@ -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',
@@ -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,
})
})
})