Commit 7c66dbbd authored by Tim Neutkens's avatar Tim Neutkens

Build: Log amount of workers during static generation

parent 2c56a693
...@@ -836,6 +836,7 @@ export type StaticWorker = typeof import('./worker') & Worker ...@@ -836,6 +836,7 @@ export type StaticWorker = typeof import('./worker') & Worker
export function createStaticWorker( export function createStaticWorker(
config: NextConfigComplete, config: NextConfigComplete,
options: { options: {
numberOfWorkers: number
debuggerPortOffset: number debuggerPortOffset: number
progress?: { progress?: {
run: () => void run: () => void
...@@ -843,10 +844,10 @@ export function createStaticWorker( ...@@ -843,10 +844,10 @@ export function createStaticWorker(
} }
} }
): StaticWorker { ): StaticWorker {
const { debuggerPortOffset, progress } = options const { numberOfWorkers, debuggerPortOffset, progress } = options
return new Worker(staticWorkerPath, { return new Worker(staticWorkerPath, {
logger: Log, logger: Log,
numWorkers: getNumberOfWorkers(config), numWorkers: numberOfWorkers,
onActivity: () => { onActivity: () => {
progress?.run() progress?.run()
}, },
...@@ -1915,8 +1916,11 @@ export default async function build( ...@@ -1915,8 +1916,11 @@ export default async function build(
traceMemoryUsage('Finished type checking', nextBuildSpan) traceMemoryUsage('Finished type checking', nextBuildSpan)
} }
const numberOfWorkers = getNumberOfWorkers(config)
const collectingPageDataStart = process.hrtime() const collectingPageDataStart = process.hrtime()
const postCompileSpinner = createSpinner('Collecting page data') const postCompileSpinner = createSpinner(
`Collecting page data using ${numberOfWorkers} worker${numberOfWorkers > 1 ? 's' : ''}`
)
const buildManifestPath = path.join(distDir, BUILD_MANIFEST) const buildManifestPath = path.join(distDir, BUILD_MANIFEST)
...@@ -1958,7 +1962,10 @@ export default async function build( ...@@ -1958,7 +1962,10 @@ export default async function build(
process.env.NEXT_PHASE = PHASE_PRODUCTION_BUILD process.env.NEXT_PHASE = PHASE_PRODUCTION_BUILD
const worker = createStaticWorker(config, { debuggerPortOffset: -1 }) const worker = createStaticWorker(config, {
numberOfWorkers,
debuggerPortOffset: -1,
})
const analysisBegin = process.hrtime() const analysisBegin = process.hrtime()
const staticCheckSpan = nextBuildSpan.traceChild('static-check') const staticCheckSpan = nextBuildSpan.traceChild('static-check')
...@@ -2480,7 +2487,7 @@ export default async function build( ...@@ -2480,7 +2487,7 @@ export default async function build(
if (postCompileSpinner) { if (postCompileSpinner) {
const collectingPageDataEnd = process.hrtime(collectingPageDataStart) const collectingPageDataEnd = process.hrtime(collectingPageDataStart)
postCompileSpinner.setText( postCompileSpinner.setText(
`Collecting page data in ${hrtimeDurationToString(collectingPageDataEnd)}` `Collecting page data using ${numberOfWorkers} worker${numberOfWorkers > 1 ? 's' : ''} in ${hrtimeDurationToString(collectingPageDataEnd)}`
) )
postCompileSpinner.stopAndPersist() postCompileSpinner.stopAndPersist()
} }
...@@ -3063,8 +3070,8 @@ export default async function build( ...@@ -3063,8 +3070,8 @@ export default async function build(
debugPrerender, debugPrerender,
pages: combinedPages, pages: combinedPages,
outdir, outdir,
statusMessage: 'Generating static pages', statusMessage: `Generating static pages using ${numberOfWorkers} worker${numberOfWorkers > 1 ? 's' : ''}`,
numWorkers: getNumberOfWorkers(exportConfig), numWorkers: numberOfWorkers,
appDirOnly, appDirOnly,
}, },
nextBuildSpan nextBuildSpan
......
...@@ -641,13 +641,15 @@ async function exportAppImpl( ...@@ -641,13 +641,15 @@ async function exportAppImpl(
if (totalExportPaths > 0) { if (totalExportPaths > 0) {
const progress = createProgress( const progress = createProgress(
totalExportPaths, totalExportPaths,
options.statusMessage || 'Exporting' options.statusMessage ??
`Exporting using ${options.numWorkers} worker${options.numWorkers > 1 ? 's' : ''}`
) )
worker = createStaticWorker(nextConfig, { worker = createStaticWorker(nextConfig, {
debuggerPortOffset: getNextBuildDebuggerPortOffset({ debuggerPortOffset: getNextBuildDebuggerPortOffset({
kind: 'export-page', kind: 'export-page',
}), }),
numberOfWorkers: options.numWorkers,
progress, progress,
}) })
......
...@@ -49,8 +49,8 @@ describe('Polyfills', () => { ...@@ -49,8 +49,8 @@ describe('Polyfills', () => {
}) })
it('should contain generated page count in output', async () => { it('should contain generated page count in output', async () => {
expect(output).toContain('Generating static pages (0/5)') expect(output).match(/Generating static pages.*\(0\/5\)/g)
expect(output).toContain('Generating static pages (5/5)') expect(output).match(/Generating static pages.*\(5\/5\)/g)
// we should only have 1 segment and the initial message logged out // we should only have 1 segment and the initial message logged out
expect(output.match(/Generating static pages/g).length).toBe(5) expect(output.match(/Generating static pages/g).length).toBe(5)
}) })
......
...@@ -112,9 +112,14 @@ describe('Production Usage', () => { ...@@ -112,9 +112,14 @@ describe('Production Usage', () => {
it('should contain generated page count in output', async () => { it('should contain generated page count in output', async () => {
const pageCount = 34 const pageCount = 34
expect(next.cliOutput).toContain(`Generating static pages (0/${pageCount})`) expect(next.cliOutput).toMatch(
expect(next.cliOutput).toContain( new RegExp(`Generating static pages.*\\(0\\/${pageCount}\\)`, 'g')
`Generating static pages (${pageCount}/${pageCount})` )
expect(next.cliOutput).toMatch(
new RegExp(
`Generating static pages.*\\(${pageCount}\\/${pageCount}\\)`,
'g'
)
) )
// we should only have 4 segments and the initial message logged out // we should only have 4 segments and the initial message logged out
expect(next.cliOutput.match(/Generating static pages/g).length).toBe(5) expect(next.cliOutput.match(/Generating static pages/g).length).toBe(5)
......
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