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 <noreply@anthropic.com>
pull/5342/head
Divyansh Singh 2 months ago
parent 412d4638c1
commit d963e6ce0e

@ -172,16 +172,20 @@ export async function bundle(
configFile: config.vite?.configFile configFile: config.vite?.configFile
}) })
let clientResult: Rolldown.RolldownOutput | null = null let { clientResult, serverResult } = await task(
let serverResult!: Rolldown.RolldownOutput 'building client + server bundles',
async () => {
// prettier-ignore const clientResult = config.mpa
await task('building client + server bundles', async () => { ? null
if (!config.mpa) clientResult = : ((await build(
(await build(await resolveViteConfig(false))) as Rolldown.RolldownOutput await resolveViteConfig(false)
serverResult = )) as Rolldown.RolldownOutput)
(await build(await resolveViteConfig(true))) as Rolldown.RolldownOutput const serverResult = (await build(
}) await resolveViteConfig(true)
)) as Rolldown.RolldownOutput
return { clientResult, serverResult }
}
)
if (config.mpa) { if (config.mpa) {
// in MPA mode, we need to copy over the non-js asset files from the // in MPA mode, we need to copy over the non-js asset files from the

@ -3,16 +3,21 @@ import ora from 'ora'
export const okMark = '\x1b[32m✓\x1b[0m' export const okMark = '\x1b[32m✓\x1b[0m'
export const failMark = '\x1b[31m✗\x1b[0m' export const failMark = '\x1b[31m✗\x1b[0m'
export async function task(taskName: string, task: () => Promise<void>) { export async function task<T>(
taskName: string,
task: () => Promise<T>
): Promise<T> {
const spinner = ora({ discardStdin: false }) const spinner = ora({ discardStdin: false })
spinner.start(taskName + '...') spinner.start(taskName + '...')
let result: T
try { try {
await task() result = await task()
} catch (e) { } catch (e) {
spinner.stopAndPersist({ symbol: failMark }) spinner.stopAndPersist({ symbol: failMark })
throw e throw e
} }
spinner.stopAndPersist({ symbol: okMark }) spinner.stopAndPersist({ symbol: okMark })
return result
} }

Loading…
Cancel
Save