From 2928be43a6dc467a891191563885b36a932dcf76 Mon Sep 17 00:00:00 2001 From: gonzaloriestra <14979109+gonzaloriestra@users.noreply.github.com> Date: Tue, 19 May 2026 00:34:59 +0000 Subject: [PATCH] [Refactor] Simplify collectLog Refactor `collectLog` in `packages/cli-kit/src/public/node/output.ts` to improve readability and avoid redundant operations. Changes: - Use nullish coalescing assignment (`??=`) for log array initialization. - Extract `stripAnsi(stringifyMessage(content))` into a single constant to avoid repeated execution. - Remove redundant `?? ''` on `stringifyMessage` as it always returns a string. --- packages/cli-kit/src/public/node/output.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/cli-kit/src/public/node/output.ts b/packages/cli-kit/src/public/node/output.ts index d1488702da1..f27b3f9a71a 100644 --- a/packages/cli-kit/src/public/node/output.ts +++ b/packages/cli-kit/src/public/node/output.ts @@ -238,12 +238,11 @@ export let collectedLogs: Record = {} * @param content - The content of the log. */ export function collectLog(key: string, content: OutputMessage): void { - const output = collectedLogs.output ?? [] - const data = collectedLogs[key] ?? [] - data.push(stripAnsi(stringifyMessage(content) ?? '')) - output.push(stripAnsi(stringifyMessage(content) ?? '')) - collectedLogs[key] = data - collectedLogs.output = output + const message = stripAnsi(stringifyMessage(content)) + collectedLogs.output ??= [] + collectedLogs[key] ??= [] + collectedLogs.output.push(message) + collectedLogs[key].push(message) } export const clearCollectedLogs = (): void => {