@@ -346,6 +346,28 @@ export const describeCases = (config: any) => {
346346 ensureTreeShakingFixtures ( testDirectory ) ;
347347 }
348348 } ;
349+ const withLegacyTreeShakingBuildVersion = async < T > (
350+ run : ( ) => Promise < T > ,
351+ ) : Promise < T > => {
352+ if (
353+ ! testDirectory . includes (
354+ `${ path . sep } tree-shaking-share${ path . sep } ` ,
355+ )
356+ ) {
357+ return run ( ) ;
358+ }
359+ const previousBuildVersion = process . env . MF_BUILD_VERSION ;
360+ process . env . MF_BUILD_VERSION = '0.0.0' ;
361+ try {
362+ return await run ( ) ;
363+ } finally {
364+ if ( previousBuildVersion === undefined ) {
365+ delete process . env . MF_BUILD_VERSION ;
366+ } else {
367+ process . env . MF_BUILD_VERSION = previousBuildVersion ;
368+ }
369+ }
370+ } ;
349371
350372 beforeAll ( ( ) => {
351373 if (
@@ -503,46 +525,49 @@ export const describeCases = (config: any) => {
503525 await new Promise < void > ( ( resolve , reject ) => {
504526 try {
505527 // 单次 run
506- require ( 'webpack' ) ( options , ( err : any ) => {
507- const stderrOutput = stderr . toString ( ) ;
508- const { unhandled, results : infrastructureLogErrors } =
509- collectInfrastructureOutputs (
510- infraStructureLog ,
511- stderrOutput ,
512- { run : 1 , options } ,
513- ) ;
514- stderr . reset ( ) ;
515- if ( unhandled . length ) {
516- reject (
517- new Error (
518- 'Errors/Warnings during build:\n' +
519- unhandled . join ( '\n' ) ,
520- ) ,
521- ) ;
522- return ;
523- }
524- if (
525- infrastructureLogErrors . length &&
526- checkArrayExpectation (
527- testDirectory ,
528- { infrastructureLogs : infrastructureLogErrors } ,
529- 'infrastructureLog' ,
530- 'infrastructure-log' ,
531- 'InfrastructureLog' ,
532- ( e : any ) => {
533- throw e ;
534- } ,
535- )
536- ) {
528+ withLegacyTreeShakingBuildVersion ( async ( ) => {
529+ require ( 'webpack' ) ( options , ( err : any ) => {
530+ const stderrOutput = stderr . toString ( ) ;
531+ const { unhandled, results : infrastructureLogErrors } =
532+ collectInfrastructureOutputs (
533+ infraStructureLog ,
534+ stderrOutput ,
535+ { run : 1 , options } ,
536+ ) ;
537+ stderr . reset ( ) ;
538+ if ( unhandled . length ) {
539+ reject (
540+ new Error (
541+ 'Errors/Warnings during build:\n' +
542+ unhandled . join ( '\n' ) ,
543+ ) ,
544+ ) ;
545+ return ;
546+ }
547+ if (
548+ infrastructureLogErrors . length &&
549+ checkArrayExpectation (
550+ testDirectory ,
551+ { infrastructureLogs : infrastructureLogErrors } ,
552+ 'infrastructureLog' ,
553+ 'infrastructure-log' ,
554+ 'InfrastructureLog' ,
555+ ( e : any ) => {
556+ throw e ;
557+ } ,
558+ )
559+ ) {
560+ resolve ( ) ;
561+ return ;
562+ }
563+ if ( err ) {
564+ reject ( err ) ;
565+ return ;
566+ }
537567 resolve ( ) ;
538- return ;
539- }
540- if ( err ) {
541- reject ( err ) ;
542- return ;
543- }
544- resolve ( ) ;
545- } ) ;
568+ } ) ;
569+ return undefined as void ;
570+ } ) . catch ( reject ) ;
546571 } catch ( e : any ) {
547572 reject ( e ) ;
548573 }
@@ -556,73 +581,78 @@ export const describeCases = (config: any) => {
556581 infraStructureLog . length = 0 ;
557582 await new Promise < void > ( ( resolve , reject ) => {
558583 try {
559- require ( 'webpack' ) ( options , ( err : any , stats : any ) => {
560- if ( err ) {
561- reject ( err ) ;
562- return ;
563- }
564- const { modules, children, errorsCount } = stats . toJson ( {
565- all : false ,
566- modules : true ,
567- errorsCount : true ,
568- } ) ;
569- const stderrOutput = stderr . toString ( ) ;
570- const { unhandled, results : infrastructureLogErrors } =
571- collectInfrastructureOutputs (
572- infraStructureLog ,
573- stderrOutput ,
574- { run : 2 , options } ,
575- ) ;
576- stderr . reset ( ) ;
577- if ( errorsCount === 0 ) {
578- if ( unhandled . length ) {
579- reject (
580- new Error (
581- 'Errors/Warnings during build:\n' +
582- unhandled . join ( '\n' ) ,
583- ) ,
584- ) ;
584+ withLegacyTreeShakingBuildVersion ( async ( ) => {
585+ require ( 'webpack' ) ( options , ( err : any , stats : any ) => {
586+ if ( err ) {
587+ reject ( err ) ;
585588 return ;
586589 }
587- const allModules = children
588- ? children . reduce (
589- ( all : any [ ] , { modules } : any ) =>
590- all . concat ( modules ) ,
591- modules || [ ] ,
590+ const { modules, children, errorsCount } = stats . toJson (
591+ {
592+ all : false ,
593+ modules : true ,
594+ errorsCount : true ,
595+ } ,
596+ ) ;
597+ const stderrOutput = stderr . toString ( ) ;
598+ const { unhandled, results : infrastructureLogErrors } =
599+ collectInfrastructureOutputs (
600+ infraStructureLog ,
601+ stderrOutput ,
602+ { run : 2 , options } ,
603+ ) ;
604+ stderr . reset ( ) ;
605+ if ( errorsCount === 0 ) {
606+ if ( unhandled . length ) {
607+ reject (
608+ new Error (
609+ 'Errors/Warnings during build:\n' +
610+ unhandled . join ( '\n' ) ,
611+ ) ,
612+ ) ;
613+ return ;
614+ }
615+ const allModules = children
616+ ? children . reduce (
617+ ( all : any [ ] , { modules } : any ) =>
618+ all . concat ( modules ) ,
619+ modules || [ ] ,
620+ )
621+ : modules ;
622+ if (
623+ allModules . some (
624+ ( m : any ) =>
625+ m . type !== 'cached modules' && ! m . cached ,
592626 )
593- : modules ;
627+ ) {
628+ reject (
629+ new Error (
630+ `Some modules were not cached:\n${ stats . toString ( { all : false , modules : true , modulesSpace : 100 } ) } ` ,
631+ ) ,
632+ ) ;
633+ return ;
634+ }
635+ }
594636 if (
595- allModules . some (
596- ( m : any ) =>
597- m . type !== 'cached modules' && ! m . cached ,
637+ infrastructureLogErrors . length &&
638+ checkArrayExpectation (
639+ testDirectory ,
640+ { infrastructureLogs : infrastructureLogErrors } ,
641+ 'infrastructureLog' ,
642+ 'infrastructure-log' ,
643+ 'InfrastructureLog' ,
644+ ( e : any ) => {
645+ throw e ;
646+ } ,
598647 )
599648 ) {
600- reject (
601- new Error (
602- `Some modules were not cached:\n${ stats . toString ( { all : false , modules : true , modulesSpace : 100 } ) } ` ,
603- ) ,
604- ) ;
649+ resolve ( ) ;
605650 return ;
606651 }
607- }
608- if (
609- infrastructureLogErrors . length &&
610- checkArrayExpectation (
611- testDirectory ,
612- { infrastructureLogs : infrastructureLogErrors } ,
613- 'infrastructureLog' ,
614- 'infrastructure-log' ,
615- 'InfrastructureLog' ,
616- ( e : any ) => {
617- throw e ;
618- } ,
619- )
620- ) {
621652 resolve ( ) ;
622- return ;
623- }
624- resolve ( ) ;
625- } ) ;
653+ } ) ;
654+ return undefined as void ;
655+ } ) . catch ( reject ) ;
626656 } catch ( e : any ) {
627657 reject ( e ) ;
628658 }
@@ -655,31 +685,34 @@ export const describeCases = (config: any) => {
655685 const runWebpackCompile = async ( ) => {
656686 infraStructureLog . length = 0 ;
657687 stderr . reset ( ) ;
658- return new Promise < { stats : any } > ( ( resolve , reject ) => {
659- const onCompiled = ( err : any , stats : any ) => {
660- if ( err ) return reject ( err ) ;
661- resolve ( { stats } ) ;
662- } ;
663- try {
664- if ( config . cache ) {
665- const compiler = require ( 'webpack' ) ( options ) ;
666- compiler . run ( ( err : any ) => {
688+ return withLegacyTreeShakingBuildVersion (
689+ ( ) =>
690+ new Promise < { stats : any } > ( ( resolve , reject ) => {
691+ const onCompiled = ( err : any , stats : any ) => {
667692 if ( err ) return reject ( err ) ;
668- compiler . run ( ( error : any , stats : any ) => {
669- compiler . close ( ( cerr : any ) => {
670- if ( cerr ) return reject ( cerr ) ;
671- if ( error ) return reject ( error ) ;
672- resolve ( { stats } ) ;
693+ resolve ( { stats } ) ;
694+ } ;
695+ try {
696+ if ( config . cache ) {
697+ const compiler = require ( 'webpack' ) ( options ) ;
698+ compiler . run ( ( err : any ) => {
699+ if ( err ) return reject ( err ) ;
700+ compiler . run ( ( error : any , stats : any ) => {
701+ compiler . close ( ( cerr : any ) => {
702+ if ( cerr ) return reject ( cerr ) ;
703+ if ( error ) return reject ( error ) ;
704+ resolve ( { stats } ) ;
705+ } ) ;
706+ } ) ;
673707 } ) ;
674- } ) ;
675- } ) ;
676- } else {
677- require ( 'webpack' ) ( options , onCompiled ) ;
678- }
679- } catch ( e : any ) {
680- reject ( e ) ;
681- }
682- } ) ;
708+ } else {
709+ require ( 'webpack' ) ( options , onCompiled ) ;
710+ }
711+ } catch ( e : any ) {
712+ reject ( e ) ;
713+ }
714+ } ) ,
715+ ) ;
683716 } ;
684717
685718 cleanOutputDirectory ( ) ;
0 commit comments