File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66
77const Tapable = require ( "tapable" ) . Tapable ;
88const SyncHook = require ( "tapable" ) . SyncHook ;
9+ const MultiHook = require ( "tapable" ) . MultiHook ;
910const asyncLib = require ( "async" ) ;
1011const MultiWatching = require ( "./MultiWatching" ) ;
1112const MultiStats = require ( "./MultiStats" ) ;
@@ -15,8 +16,10 @@ module.exports = class MultiCompiler extends Tapable {
1516 super ( ) ;
1617 this . hooks = {
1718 done : new SyncHook ( [ "stats" ] ) ,
18- invalid : new SyncHook ( [ ] ) ,
19- watchClose : new SyncHook ( [ ] )
19+ invalid : new MultiHook ( compilers . map ( c => c . hooks . invalid ) ) ,
20+ run : new MultiHook ( compilers . map ( c => c . hooks . run ) ) ,
21+ watchClose : new SyncHook ( [ ] ) ,
22+ watchRun : new MultiHook ( compilers . map ( c => c . hooks . watchRun ) )
2023 } ;
2124 if ( ! Array . isArray ( compilers ) ) {
2225 compilers = Object . keys ( compilers ) . map ( ( name ) => {
@@ -44,7 +47,6 @@ module.exports = class MultiCompiler extends Tapable {
4447 compilerDone = false ;
4548 doneCompilers -- ;
4649 }
47- this . hooks . invalid . call ( ) ;
4850 } ) ;
4951 } ) ;
5052 }
Original file line number Diff line number Diff line change 1+ "use strict" ;
2+
3+ /* globals describe it */
4+ const path = require ( "path" ) ;
5+ const should = require ( "should" ) ;
6+ const MemoryFs = require ( "memory-fs" ) ;
7+ const webpack = require ( "../" ) ;
8+
9+ const createMultiCompiler = ( ) => {
10+ const compiler = webpack ( [ {
11+ context : path . join ( __dirname , "fixtures" ) ,
12+ entry : "./a.js"
13+ } , {
14+ context : path . join ( __dirname , "fixtures" ) ,
15+ entry : "./b.js"
16+ } ] ) ;
17+ compiler . outputFileSystem = new MemoryFs ( ) ;
18+ return compiler ;
19+ } ;
20+
21+ describe ( "MultiCompiler" , function ( ) {
22+ it ( "should trigger 'run' for each child compiler" , done => {
23+ const compiler = createMultiCompiler ( ) ;
24+ let called = 0 ;
25+
26+ compiler . hooks . run . tap ( "MultiCompiler test" , ( ) => called ++ ) ;
27+ compiler . run ( err => {
28+ if ( err ) {
29+ throw err ;
30+ } else {
31+ should ( called ) . be . equal ( 2 ) ;
32+ done ( ) ;
33+ }
34+ } ) ;
35+ } ) ;
36+
37+ it ( "should trigger 'watchRun' for each child compiler" , done => {
38+ const compiler = createMultiCompiler ( ) ;
39+ let called = 0 ;
40+
41+ compiler . hooks . watchRun . tap ( "MultiCompiler test" , ( ) => called ++ ) ;
42+ const watcher = compiler . watch ( 1000 , err => {
43+ if ( err ) {
44+ throw err ;
45+ } else {
46+ watcher . close ( ) ;
47+ should ( called ) . be . equal ( 2 ) ;
48+ done ( ) ;
49+ }
50+ } ) ;
51+ } ) ;
52+ } ) ;
You can’t perform that action at this time.
0 commit comments