Skip to content

Commit ff00ecc

Browse files
committed
Build: Log amount of workers during static generation
1 parent 50f5fbe commit ff00ecc

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
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
},
@@ -1915,8 +1916,11 @@ export default async function build(
19151916
traceMemoryUsage('Finished type checking', nextBuildSpan)
19161917
}
19171918

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

19211925
const buildManifestPath = path.join(distDir, BUILD_MANIFEST)
19221926

@@ -1958,7 +1962,10 @@ export default async function build(
19581962

19591963
process.env.NEXT_PHASE = PHASE_PRODUCTION_BUILD
19601964

1961-
const worker = createStaticWorker(config, { debuggerPortOffset: -1 })
1965+
const worker = createStaticWorker(config, {
1966+
numberOfWorkers,
1967+
debuggerPortOffset: -1,
1968+
})
19621969

19631970
const analysisBegin = process.hrtime()
19641971
const staticCheckSpan = nextBuildSpan.traceChild('static-check')
@@ -2480,7 +2487,7 @@ export default async function build(
24802487
if (postCompileSpinner) {
24812488
const collectingPageDataEnd = process.hrtime(collectingPageDataStart)
24822489
postCompileSpinner.setText(
2483-
`Collecting page data in ${hrtimeDurationToString(collectingPageDataEnd)}`
2490+
`Collecting page data using ${numberOfWorkers} worker${numberOfWorkers > 1 ? 's' : ''} in ${hrtimeDurationToString(collectingPageDataEnd)}`
24842491
)
24852492
postCompileSpinner.stopAndPersist()
24862493
}
@@ -3063,8 +3070,8 @@ export default async function build(
30633070
debugPrerender,
30643071
pages: combinedPages,
30653072
outdir,
3066-
statusMessage: 'Generating static pages',
3067-
numWorkers: getNumberOfWorkers(exportConfig),
3073+
statusMessage: `Generating static pages using ${numberOfWorkers} worker${numberOfWorkers > 1 ? 's' : ''}`,
3074+
numWorkers: numberOfWorkers,
30683075
appDirOnly,
30693076
},
30703077
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/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)