File tree Expand file tree Collapse file tree 5 files changed +28
-7
lines changed
e2e/cases/plugin-api/plugin-hooks-environment Expand file tree Collapse file tree 5 files changed +28
-7
lines changed Original file line number Diff line number Diff line change @@ -51,8 +51,9 @@ const createPlugin = () => {
5151 api . onBeforeEnvironmentCompile ( ( { environment } ) => {
5252 names . push ( `BeforeEnvironmentCompile ${ environment . name } ` ) ;
5353 } ) ;
54- api . onAfterEnvironmentCompile ( ( { stats, environment } ) => {
54+ api . onAfterEnvironmentCompile ( ( { stats, environment, time } ) => {
5555 expect ( stats ?. compilation . name ) . toBe ( environment . name ) ;
56+ expect ( time ) . toBeGreaterThan ( 0 ) ;
5657 names . push ( `AfterEnvironmentCompile ${ environment . name } ` ) ;
5758 } ) ;
5859 api . onBeforeStartProdServer ( ( ) => {
Original file line number Diff line number Diff line change @@ -407,15 +407,19 @@ export const registerBuildHook = ({
407407 await promise ;
408408 } ;
409409
410- const onEnvironmentDone = async ( buildIndex : number , stats : Rspack . Stats ) => {
410+ const onEnvironmentDone = async ( index : number , stats : Rspack . Stats ) => {
411+ const environment = environmentList [ index ] ;
412+ const time = context . buildState . time [ environment . name ] ?? 0 ;
413+
411414 await context . hooks . onAfterEnvironmentCompile . callBatch ( {
412- environment : environmentList [ buildIndex ] . name ,
415+ environment : environment . name ,
413416 args : [
414417 {
415418 isFirstCompile,
416419 stats,
417- environment : environmentList [ buildIndex ] ,
420+ environment,
418421 isWatch,
422+ time,
419423 } ,
420424 ] ,
421425 } ) ;
@@ -484,15 +488,19 @@ export const registerDevHook = ({
484488 await promise ;
485489 } ;
486490
487- const onEnvironmentDone = async ( buildIndex : number , stats : Rspack . Stats ) => {
491+ const onEnvironmentDone = async ( index : number , stats : Rspack . Stats ) => {
492+ const environment = environmentList [ index ] ;
493+ const time = context . buildState . time [ environment . name ] ?? 0 ;
494+
488495 await context . hooks . onAfterEnvironmentCompile . callBatch ( {
489- environment : environmentList [ buildIndex ] . name ,
496+ environment : environment . name ,
490497 args : [
491498 {
492499 isFirstCompile,
493500 stats,
494- environment : environmentList [ buildIndex ] ,
501+ environment,
495502 isWatch : true ,
503+ time,
496504 } ,
497505 ] ,
498506 } ) ;
Original file line number Diff line number Diff line change @@ -55,6 +55,10 @@ export type OnBeforeDevCompileFn<B = 'rspack'> = (
5555export type OnAfterEnvironmentCompileFn = (
5656 params : CompileCommonParams & {
5757 stats ?: Rspack . Stats ;
58+ /**
59+ * The time it takes to build the current environment in milliseconds.
60+ */
61+ time : number ;
5862 environment : EnvironmentContext ;
5963 } ,
6064) => MaybePromise < void > ;
Original file line number Diff line number Diff line change @@ -11,6 +11,10 @@ function OnAfterEnvironmentCompile(
1111 isWatch: boolean ;
1212 stats? : Stats ;
1313 environment: EnvironmentContext ;
14+ /**
15+ * The time it takes to build the current environment in milliseconds.
16+ */
17+ time: number ;
1418 }) => Promise <void > | void ,
1519): void ;
1620```
Original file line number Diff line number Diff line change @@ -11,6 +11,10 @@ function OnAfterEnvironmentCompile(
1111 isWatch: boolean ;
1212 stats? : Stats ;
1313 environment: EnvironmentContext ;
14+ /**
15+ * The time it takes to build the current environment in milliseconds.
16+ */
17+ time: number ;
1418 }) => Promise <void > | void ,
1519): void ;
1620```
You can’t perform that action at this time.
0 commit comments