-
-
Notifications
You must be signed in to change notification settings - Fork 239
feat: improve build time printing #6607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -215,6 +215,7 @@ export async function createContext( | |
| stats: null, | ||
| status: 'idle', | ||
| hasErrors: false, | ||
| time: {}, | ||
| }, | ||
| }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ import { isSatisfyRspackVersion, rspackMinVersion } from '../helpers/version'; | |
| import { registerDevHook } from '../hooks'; | ||
| import { logger } from '../logger'; | ||
| import { rspack } from '../rspack'; | ||
| import type { InternalContext, RsbuildStatsItem, Rspack } from '../types'; | ||
| import type { InternalContext, Rspack } from '../types'; | ||
| import { type InitConfigsOptions, initConfigs } from './initConfigs'; | ||
|
|
||
| // keep the last 3 parts of the path to make logs clean | ||
|
|
@@ -145,11 +145,15 @@ export async function createCompiler(options: InitConfigsOptions): Promise<{ | |
| } | ||
| }); | ||
|
|
||
| let startTime: number | null = null; | ||
|
|
||
| compiler.hooks.run.tap(HOOK_NAME, () => { | ||
| startTime = Date.now(); | ||
| context.buildState.status = 'building'; | ||
| }); | ||
|
|
||
| compiler.hooks.watchRun.tap(HOOK_NAME, (compiler) => { | ||
| startTime = Date.now(); | ||
| context.buildState.status = 'building'; | ||
| logRspackVersion(); | ||
|
|
||
|
|
@@ -182,6 +186,28 @@ export async function createCompiler(options: InitConfigsOptions): Promise<{ | |
| }); | ||
| } | ||
|
|
||
| const printTime = (index: number) => { | ||
| if (startTime === null) { | ||
| return; | ||
| } | ||
|
|
||
| const { name } = context.environmentList[index]; | ||
| const time = Date.now() - startTime; | ||
| context.buildState.time[name] = time; | ||
|
|
||
| // For multi compiler, print name to distinguish different environments | ||
| const suffix = isMultiCompiler ? color.dim(` (${name})`) : ''; | ||
| logger.ready(`built in ${prettyTime(time / 1000)}${suffix}`); | ||
| }; | ||
|
|
||
| if (isMultiCompiler) { | ||
| (compiler as Rspack.MultiCompiler).compilers.forEach((item, index) => { | ||
| item.hooks.done.tap(HOOK_NAME, () => { | ||
| printTime(index); | ||
| }); | ||
|
Comment on lines
189
to
207
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The new Useful? React with 👍 / 👎.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will improve the time logs when having build errors. |
||
| }); | ||
| } | ||
|
|
||
| compiler.hooks.done.tap( | ||
| HOOK_NAME, | ||
| (statsInstance: Rspack.Stats | Rspack.MultiStats) => { | ||
|
|
@@ -193,26 +219,8 @@ export async function createCompiler(options: InitConfigsOptions): Promise<{ | |
| context.buildState.hasErrors = hasErrors; | ||
| context.socketServer?.onBuildDone(); | ||
|
|
||
| const printTime = (statsItem: RsbuildStatsItem, index: number) => { | ||
| if (statsItem.time) { | ||
| const time = prettyTime(statsItem.time / 1000); | ||
| const { name } = rspackConfigs[index]; | ||
|
|
||
| // When using multi compiler, print name to distinguish different compilers | ||
| const suffix = name && isMultiCompiler ? color.dim(` (${name})`) : ''; | ||
| logger.ready(`built in ${time}${suffix}`); | ||
| } | ||
| }; | ||
|
|
||
| if (!hasErrors) { | ||
| // only print children compiler time when multi compiler | ||
| if (isMultiCompiler && stats.children?.length) { | ||
| stats.children.forEach((item, index) => { | ||
| printTime(item, index); | ||
| }); | ||
| } else { | ||
| printTime(stats, 0); | ||
| } | ||
| if (!isMultiCompiler) { | ||
| printTime(0); | ||
| } | ||
|
|
||
| const { message, level } = formatStats(stats, hasErrors); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.