From d963e6ce0e70cbc0bc6e72defa507eec86a95bf6 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Thu, 30 Jul 2026 03:56:53 +0530 Subject: [PATCH] refactor: return the task callback result Lets bundle() receive the build outputs from the spinner-wrapped callback directly instead of smuggling them through outer let bindings with a definite-assignment assertion. Co-Authored-By: Claude Fable 5 --- src/node/build/bundle.ts | 24 ++++++++++++++---------- src/node/utils/task.ts | 9 +++++++-- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/node/build/bundle.ts b/src/node/build/bundle.ts index c6d14d96..3edbfcd4 100644 --- a/src/node/build/bundle.ts +++ b/src/node/build/bundle.ts @@ -172,16 +172,20 @@ export async function bundle( configFile: config.vite?.configFile }) - let clientResult: Rolldown.RolldownOutput | null = null - let serverResult!: Rolldown.RolldownOutput - - // prettier-ignore - await task('building client + server bundles', async () => { - if (!config.mpa) clientResult = - (await build(await resolveViteConfig(false))) as Rolldown.RolldownOutput - serverResult = - (await build(await resolveViteConfig(true))) as Rolldown.RolldownOutput - }) + let { clientResult, serverResult } = await task( + 'building client + server bundles', + async () => { + const clientResult = config.mpa + ? null + : ((await build( + await resolveViteConfig(false) + )) as Rolldown.RolldownOutput) + const serverResult = (await build( + await resolveViteConfig(true) + )) as Rolldown.RolldownOutput + return { clientResult, serverResult } + } + ) if (config.mpa) { // in MPA mode, we need to copy over the non-js asset files from the diff --git a/src/node/utils/task.ts b/src/node/utils/task.ts index 8fd169bf..c0b4159e 100644 --- a/src/node/utils/task.ts +++ b/src/node/utils/task.ts @@ -3,16 +3,21 @@ import ora from 'ora' export const okMark = '\x1b[32m✓\x1b[0m' export const failMark = '\x1b[31m✗\x1b[0m' -export async function task(taskName: string, task: () => Promise) { +export async function task( + taskName: string, + task: () => Promise +): Promise { const spinner = ora({ discardStdin: false }) spinner.start(taskName + '...') + let result: T try { - await task() + result = await task() } catch (e) { spinner.stopAndPersist({ symbol: failMark }) throw e } spinner.stopAndPersist({ symbol: okMark }) + return result }