From ace515b3f9e4ea956271cad281855f3d9a168da7 Mon Sep 17 00:00:00 2001 From: Yuxuan Zhang Date: Sat, 30 Dec 2023 19:10:58 -0500 Subject: [PATCH 1/4] use picocolors instead of terminal control sequence for color marks --- src/node/utils/task.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/node/utils/task.ts b/src/node/utils/task.ts index cd77d4fd..9ceb247a 100644 --- a/src/node/utils/task.ts +++ b/src/node/utils/task.ts @@ -1,8 +1,9 @@ import ora from 'ora' import humanizeDuration from 'humanize-duration' +import c from 'picocolors' -export const okMark = '\x1b[32m✓\x1b[0m' -export const failMark = '\x1b[31m✖\x1b[0m' +export const okMark = c.green('✓') +export const failMark = c.red('✖') export type UpdateHandle = (done: number, total?: number) => any From 9195369746adc479d354e5d0362c265cc0d9894e Mon Sep 17 00:00:00 2001 From: Yuxuan Zhang Date: Sat, 30 Dec 2023 19:32:02 -0500 Subject: [PATCH 2/4] expose updateHandle for subtasks --- src/node/utils/task.ts | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/node/utils/task.ts b/src/node/utils/task.ts index 9ceb247a..1466454b 100644 --- a/src/node/utils/task.ts +++ b/src/node/utils/task.ts @@ -5,7 +5,17 @@ import c from 'picocolors' export const okMark = c.green('✓') export const failMark = c.red('✖') -export type UpdateHandle = (done: number, total?: number) => any +export type UpdateHandle = ( + done?: number, + total?: number, + subtask?: string +) => any + +let updateHandle: UpdateHandle | null = null + +export const updateCurrentTask: UpdateHandle = (...args) => { + updateHandle?.(...args) +} export async function task( taskName: string, @@ -14,14 +24,17 @@ export async function task( const spinner = ora({ discardStdin: false }) spinner.start(taskName + '...') - const updateHandle: UpdateHandle = (done, total) => { - if (total === undefined) { - spinner.text = `${taskName} [ ${done} ]` + updateHandle = (done, total, subtask) => { + const taskFullName = subtask ? `${taskName} - ${subtask}` : taskName + if (done === undefined) { + spinner.text = taskFullName + '...' + } else if (total === undefined) { + spinner.text = `${taskFullName} [ ${done} ]` } else { // match length to display them in same width const _total = `${total}` const _done = `${done}`.padStart(_total.length, ' ') - spinner.text = `${taskName} [ ${_done} / ${_total} ]` + spinner.text = `${taskFullName} [ ${_done} / ${_total} ]` } } @@ -34,6 +47,7 @@ export async function task( success = false throw e } finally { + updateHandle = null const timeEnd = performance.now() const duration = humanizeDuration(timeEnd - timeStart, { maxDecimalPoints: 2 From 007fa592dafacaf8e16a3a550c85a1c4ef3eb3de Mon Sep 17 00:00:00 2001 From: Yuxuan Zhang Date: Sat, 30 Dec 2023 20:24:54 -0500 Subject: [PATCH 3/4] build/bundle: use task return value passthrough --- src/node/build/bundle.ts | 63 ++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/src/node/build/bundle.ts b/src/node/build/bundle.ts index 159bb43c..8d19cee3 100644 --- a/src/node/build/bundle.ts +++ b/src/node/build/bundle.ts @@ -143,40 +143,41 @@ export async function bundle( configFile: config.vite?.configFile }) - let clientResult!: Rollup.RollupOutput | null - let serverResult!: Rollup.RollupOutput - - await task('building client + server bundles', async () => { - clientResult = config.mpa - ? null - : ((await build(await resolveViteConfig(false))) as Rollup.RollupOutput) - serverResult = (await build( - await resolveViteConfig(true) - )) as Rollup.RollupOutput - }) + const serverResult = await task( + 'building server bundle', + () => resolveViteConfig(true).then(build) as Promise + ) - if (config.mpa) { - // in MPA mode, we need to copy over the non-js asset files from the - // server build since there is no client-side build. - await Promise.all( - serverResult.output.map(async (chunk) => { - if (!chunk.fileName.endsWith('.js')) { - const tempPath = path.resolve(config.tempDir, chunk.fileName) - const outPath = path.resolve(config.outDir, chunk.fileName) - await fs.copy(tempPath, outPath) + const clientResult = !config.mpa + ? await task( + 'building client bundle', + () => + resolveViteConfig(false).then(build) as Promise + ) + : await task('building client bundle (MPA)', async () => { + // in MPA mode, we need to copy over the non-js asset files from the + // server build since there is no client-side build. + await Promise.all( + serverResult.output.map(async (chunk) => { + if (!chunk.fileName.endsWith('.js')) { + const tempPath = path.resolve(config.tempDir, chunk.fileName) + const outPath = path.resolve(config.outDir, chunk.fileName) + await fs.copy(tempPath, outPath) + } + }) + ) + // also copy over public dir + const publicDir = path.resolve(config.srcDir, 'public') + if (fs.existsSync(publicDir)) { + await fs.copy(publicDir, config.outDir) + } + // build