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 }