Commit 76dddc43 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig

dedupe

parent b5599525
......@@ -3945,12 +3945,6 @@ export default async function build(
.traceAsyncFn(() => writeManifest(routesManifestPath, routesManifest))
}
const postBuildSpinner = createSpinner('Finalizing page optimization')
let buildTracesSpinner
if (buildTracesPromise) {
buildTracesSpinner = createSpinner('Collecting build traces')
}
// ensure the worker is not left hanging
worker.end()
......@@ -4096,6 +4090,11 @@ export default async function build(
})
}
let buildTracesSpinner
if (buildTracesPromise) {
buildTracesSpinner = createSpinner('Collecting build traces')
}
await buildTracesPromise
if (buildTracesSpinner) {
......@@ -4109,6 +4108,7 @@ export default async function build(
}
if (config.output === 'export') {
const spinner = createSpinner('Outputting static export')
await nextBuildSpan
.traceChild('output-export-full-static-export')
.traceAsyncFn(async () => {
......@@ -4121,6 +4121,8 @@ export default async function build(
appDirOnly
)
})
spinner.stopAndPersist()
}
// This should come after output: export handling but before
......@@ -4128,6 +4130,7 @@ export default async function build(
// not be allowed if an adapter with onBuildComplete is configured
const adapterPath = config.experimental.adapterPath
if (adapterPath) {
const spinner = createSpinner('Finalizing build with adapter')
await nextBuildSpan
.traceChild('adapter-handle-build-complete')
.traceAsyncFn(async () => {
......@@ -4152,9 +4155,11 @@ export default async function build(
requiredServerFiles: requiredServerFilesManifest.files,
})
})
spinner.stopAndPersist()
}
if (config.output === 'standalone') {
const spinner = createSpinner('Generating standalone output')
await nextBuildSpan
.traceChild('output-standalone')
.traceAsyncFn(async () => {
......@@ -4173,13 +4178,9 @@ export default async function build(
appDir
)
})
spinner.stopAndPersist()
}
if (postBuildSpinner) {
postBuildSpinner.stopAndPersist()
}
console.log()
if (debugOutput) {
nextBuildSpan
.traceChild('print-custom-routes')
......
import * as Log from '../build/output/log'
import { hrtimeDurationToString } from './duration-to-string'
import createSpinner from './spinner'
function divideSegments(number: number, segments: number): number[] {
......@@ -16,8 +14,6 @@ function divideSegments(number: number, segments: number): number[] {
}
export const createProgress = (total: number, label: string) => {
const progressStart = process.hrtime()
const segments = divideSegments(total, 4)
if (total === 0) {
......@@ -49,10 +45,6 @@ export const createProgress = (total: number, label: string) => {
interval: 200,
},
})
if (process.stdout.isTTY) {
// createSpinner logs the initial state, but doesn't do anything afterwards anyway.
progressSpinner = undefined
}
const run = () => {
curProgress++
......@@ -79,13 +71,8 @@ export const createProgress = (total: number, label: string) => {
if (progressSpinner && !isFinished) {
progressSpinner.setText(message)
} else {
progressSpinner?.stop()
if (isFinished) {
const progressEnd = process.hrtime(progressStart)
Log.event(`${message} in ${hrtimeDurationToString(progressEnd)}`)
} else {
Log.info(`${message} ${process.stdout.isTTY ? '\n' : '\r'}`)
}
progressSpinner.setText(message)
progressSpinner?.stopAndPersist()
}
}
......
......@@ -13,6 +13,7 @@ export default function createSpinner(
logFn: (...data: any[]) => void = console.log
) {
let prefixText = ` ${Log.prefixes.info} ${text} `
const progressStart = process.hrtime()
if (process.stdout.isTTY) {
let spinner = ora({
......@@ -34,8 +35,8 @@ export default function createSpinner(
const logHandle = (method: any, args: any[]) => {
// Enter a new line before logging new message, to avoid
// the new message shows up right after the spinner in the same line.
const isInProgress = spinner?.isSpinning
if (spinner && isInProgress) {
const isInProgress = spinner.isSpinning
if (isInProgress) {
// Reset the current running spinner to empty line by `\r`
spinner.prefixText = '\r'
spinner.text = '\r'
......@@ -43,7 +44,7 @@ export default function createSpinner(
origStop()
}
method(...args)
if (spinner && isInProgress) {
if (isInProgress) {
spinner.start()
}
}
......@@ -60,32 +61,27 @@ export default function createSpinner(
spinner.setText = (newText) => {
text = newText
prefixText = ` ${Log.prefixes.info} ${newText} `
spinner!.prefixText = prefixText
return spinner!
spinner.prefixText = prefixText
return spinner
}
spinner.stop = () => {
origStop()
resetLog()
return spinner!
return spinner
}
spinner.stopAndPersist = () => {
// Add \r at beginning to reset the current line of loading status text
const suffixText = `\r ${Log.prefixes.event} ${text} `
if (spinner) {
spinner.text = suffixText
} else {
logFn(suffixText)
}
const progressEnd = process.hrtime(progressStart)
text = `${text} in ${hrtimeDurationToString(progressEnd)}`
prefixText = ` ${Log.prefixes.info} ${text} `
spinner.prefixText = prefixText
origStopAndPersist()
resetLog()
return spinner!
return spinner
}
return spinner
} else if (prefixText || text) {
} else {
logFn(prefixText ? prefixText + '...' : text)
const progressStart = process.hrtime()
// @ts-ignore
let spinner = {
isSpinning: false,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment