From 27cf947f57f21db0182714b6ae8b2d30627f549f Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Mon, 6 Jan 2025 00:33:03 +0300 Subject: [PATCH] feat: introduce `end` event for logger --- .size-limit.json | 2 +- src/core.ts | 1 + src/util.ts | 8 ++++++++ test/core.test.js | 13 +++++++++++-- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.size-limit.json b/.size-limit.json index 248104fc2a..0ac5c42dab 100644 --- a/.size-limit.json +++ b/.size-limit.json @@ -16,7 +16,7 @@ { "name": "dts libdefs", "path": "build/*.d.ts", - "limit": "37.5 kB", + "limit": "38 kB", "brotli": false, "gzip": false }, diff --git a/src/core.ts b/src/core.ts index 04aec7443c..278244b3d6 100644 --- a/src/core.ts +++ b/src/core.ts @@ -333,6 +333,7 @@ export class ProcessPromise extends Promise { 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()) { diff --git a/src/util.ts b/src/util.ts index 390a5b826c..0743324184 100644 --- a/src/util.ts +++ b/src/util.ts @@ -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 diff --git a/test/core.test.js b/test/core.test.js index 63bcf82d44..a6b34c9868 100644 --- a/test/core.test.js +++ b/test/core.test.js @@ -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, + }) }) })