Skip to content

Commit 7bddaef

Browse files
timneutkenshuozhi
authored andcommitted
Build: Log amount of workers during static generation (#85706)
## What? Added the amount of workers used to the relevant steps as `using X workers`. Example: ``` ✓ Compiled successfully in 610.3ms ✓ Finished TypeScript in 954.4ms ✓ Collecting page data using 15 workers in 207.5ms ✓ Generating static pages using 15 workers (4/4) in 258.4ms ✓ Finalizing page optimization in 6.7ms ```
1 parent 4e90714 commit 7bddaef

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

packages/next/src/build/index.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -836,17 +836,18 @@ export type StaticWorker = typeof import('./worker') & Worker
836836
export function createStaticWorker(
837837
config: NextConfigComplete,
838838
options: {
839+
numberOfWorkers: number
839840
debuggerPortOffset: number
840841
progress?: {
841842
run: () => void
842843
clear: () => void
843844
}
844845
}
845846
): StaticWorker {
846-
const { debuggerPortOffset, progress } = options
847+
const { numberOfWorkers, debuggerPortOffset, progress } = options
847848
return new Worker(staticWorkerPath, {
848849
logger: Log,
849-
numWorkers: getNumberOfWorkers(config),
850+
numWorkers: numberOfWorkers,
850851
onActivity: () => {
851852
progress?.run()
852853
},
@@ -1917,8 +1918,11 @@ export default async function build(
19171918
traceMemoryUsage('Finished type checking', nextBuildSpan)
19181919
}
19191920

1921+
const numberOfWorkers = getNumberOfWorkers(config)
19201922
const collectingPageDataStart = process.hrtime()
1921-
const postCompileSpinner = createSpinner('Collecting page data')
1923+
const postCompileSpinner = createSpinner(
1924+
`Collecting page data using ${numberOfWorkers} worker${numberOfWorkers > 1 ? 's' : ''}`
1925+
)
19221926

19231927
const buildManifestPath = path.join(distDir, BUILD_MANIFEST)
19241928

@@ -1960,7 +1964,10 @@ export default async function build(
19601964

19611965
process.env.NEXT_PHASE = PHASE_PRODUCTION_BUILD
19621966

1963-
const worker = createStaticWorker(config, { debuggerPortOffset: -1 })
1967+
const worker = createStaticWorker(config, {
1968+
numberOfWorkers,
1969+
debuggerPortOffset: -1,
1970+
})
19641971

19651972
const analysisBegin = process.hrtime()
19661973
const staticCheckSpan = nextBuildSpan.traceChild('static-check')
@@ -2482,7 +2489,7 @@ export default async function build(
24822489
if (postCompileSpinner) {
24832490
const collectingPageDataEnd = process.hrtime(collectingPageDataStart)
24842491
postCompileSpinner.setText(
2485-
`Collecting page data in ${hrtimeDurationToString(collectingPageDataEnd)}`
2492+
`Collecting page data using ${numberOfWorkers} worker${numberOfWorkers > 1 ? 's' : ''} in ${hrtimeDurationToString(collectingPageDataEnd)}`
24862493
)
24872494
postCompileSpinner.stopAndPersist()
24882495
}
@@ -3065,8 +3072,8 @@ export default async function build(
30653072
debugPrerender,
30663073
pages: combinedPages,
30673074
outdir,
3068-
statusMessage: 'Generating static pages',
3069-
numWorkers: getNumberOfWorkers(exportConfig),
3075+
statusMessage: `Generating static pages using ${numberOfWorkers} worker${numberOfWorkers > 1 ? 's' : ''}`,
3076+
numWorkers: numberOfWorkers,
30703077
appDirOnly,
30713078
},
30723079
nextBuildSpan

packages/next/src/export/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,13 +641,15 @@ async function exportAppImpl(
641641
if (totalExportPaths > 0) {
642642
const progress = createProgress(
643643
totalExportPaths,
644-
options.statusMessage || 'Exporting'
644+
options.statusMessage ??
645+
`Exporting using ${options.numWorkers} worker${options.numWorkers > 1 ? 's' : ''}`
645646
)
646647

647648
worker = createStaticWorker(nextConfig, {
648649
debuggerPortOffset: getNextBuildDebuggerPortOffset({
649650
kind: 'export-page',
650651
}),
652+
numberOfWorkers: options.numWorkers,
651653
progress,
652654
})
653655

test/integration/polyfills/test/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ describe('Polyfills', () => {
4949
})
5050

5151
it('should contain generated page count in output', async () => {
52-
expect(output).toContain('Generating static pages (0/5)')
53-
expect(output).toContain('Generating static pages (5/5)')
52+
expect(output).toMatch(/Generating static pages.*\(0\/5\)/g)
53+
expect(output).toMatch(/Generating static pages.*\(5\/5\)/g)
5454
// we should only have 1 segment and the initial message logged out
5555
expect(output.match(/Generating static pages/g).length).toBe(5)
5656
})

test/production/pages-dir/production/test/index.test.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,14 @@ describe('Production Usage', () => {
112112

113113
it('should contain generated page count in output', async () => {
114114
const pageCount = 34
115-
expect(next.cliOutput).toContain(`Generating static pages (0/${pageCount})`)
116-
expect(next.cliOutput).toContain(
117-
`Generating static pages (${pageCount}/${pageCount})`
115+
expect(next.cliOutput).toMatch(
116+
new RegExp(`Generating static pages.*\\(0\\/${pageCount}\\)`, 'g')
117+
)
118+
expect(next.cliOutput).toMatch(
119+
new RegExp(
120+
`Generating static pages.*\\(${pageCount}\\/${pageCount}\\)`,
121+
'g'
122+
)
118123
)
119124
// we should only have 4 segments and the initial message logged out
120125
expect(next.cliOutput.match(/Generating static pages/g).length).toBe(5)

0 commit comments

Comments
 (0)