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 5 days ago
parent 412d4638c1
commit d963e6ce0e

@ -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

@ -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<void>) {
export async function task<T>(
taskName: string,
task: () => Promise<T>
): Promise<T> {
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
}

Loading…
Cancel
Save