@@ -6,15 +6,13 @@ var path = require("path");
66var Tapable = require ( "tapable" ) ;
77
88var Compilation = require ( "./Compilation" ) ;
9-
9+ var Stats = require ( "./Stats" ) ;
1010var NormalModuleFactory = require ( "./NormalModuleFactory" ) ;
1111var ContextModuleFactory = require ( "./ContextModuleFactory" ) ;
1212
1313function Watching ( compiler , watchOptions , handler ) {
1414 this . startTime = null ;
1515 this . invalid = false ;
16- this . error = null ;
17- this . stats = null ;
1816 this . handler = handler ;
1917 this . closed = false ;
2018 if ( typeof watchOptions === "number" ) {
@@ -61,7 +59,7 @@ Watching.prototype._go = function() {
6159 if ( compilation . applyPluginsBailResult ( "need-additional-pass" ) ) {
6260 compilation . needAdditionalPass = true ;
6361
64- var stats = compilation . getStats ( ) ;
62+ var stats = new Stats ( compilation ) ;
6563 stats . startTime = self . startTime ;
6664 stats . endTime = new Date ( ) . getTime ( ) ;
6765 self . compiler . applyPlugins ( "done" , stats ) ;
@@ -79,22 +77,29 @@ Watching.prototype._go = function() {
7977 } ) ;
8078} ;
8179
80+ Watching . prototype . _getStats = function ( compilation ) {
81+ var stats = new Stats ( compilation ) ;
82+ stats . startTime = this . startTime ;
83+ stats . endTime = new Date ( ) . getTime ( ) ;
84+ return stats ;
85+ } ;
86+
8287Watching . prototype . _done = function ( err , compilation ) {
8388 this . running = false ;
8489 if ( this . invalid ) return this . _go ( ) ;
85- this . error = err || null ;
86- this . stats = compilation ? compilation . getStats ( ) : null ;
87- if ( this . stats ) {
88- this . stats . startTime = this . startTime ;
89- this . stats . endTime = new Date ( ) . getTime ( ) ;
90+
91+ var stats = this . _getStats ( compilation ) ;
92+ if ( err ) {
93+ this . compiler . applyPlugins ( "failed" , err ) ;
94+ this . handler ( err , stats ) ;
95+ return ;
9096 }
91- if ( this . stats )
92- this . compiler . applyPlugins ( "done" , this . stats ) ;
93- else
94- this . compiler . applyPlugins ( "failed" , this . error ) ;
95- this . handler ( this . error , this . stats ) ;
96- if ( ! this . error && ! this . closed )
97+
98+ this . compiler . applyPlugins ( "done" , stats ) ;
99+ this . handler ( null , stats ) ;
100+ if ( ! this . closed ) {
97101 this . watch ( compilation . fileDependencies , compilation . contextDependencies , compilation . missingDependencies ) ;
102+ }
98103} ;
99104
100105Watching . prototype . watch = function ( files , dirs , missing ) {
@@ -232,7 +237,7 @@ Compiler.prototype.run = function(callback) {
232237 if ( err ) return callback ( err ) ;
233238
234239 if ( self . applyPluginsBailResult ( "should-emit" , compilation ) === false ) {
235- var stats = compilation . getStats ( ) ;
240+ var stats = new Stats ( compilation ) ;
236241 stats . startTime = startTime ;
237242 stats . endTime = new Date ( ) . getTime ( ) ;
238243 self . applyPlugins ( "done" , stats ) ;
@@ -245,7 +250,7 @@ Compiler.prototype.run = function(callback) {
245250 if ( compilation . applyPluginsBailResult ( "need-additional-pass" ) ) {
246251 compilation . needAdditionalPass = true ;
247252
248- var stats = compilation . getStats ( ) ;
253+ var stats = new Stats ( compilation ) ;
249254 stats . startTime = startTime ;
250255 stats . endTime = new Date ( ) . getTime ( ) ;
251256 self . applyPlugins ( "done" , stats ) ;
@@ -260,7 +265,7 @@ Compiler.prototype.run = function(callback) {
260265 self . emitRecords ( function ( err ) {
261266 if ( err ) return callback ( err ) ;
262267
263- var stats = compilation . getStats ( ) ;
268+ var stats = new Stats ( compilation ) ;
264269 stats . startTime = startTime ;
265270 stats . endTime = new Date ( ) . getTime ( ) ;
266271 self . applyPlugins ( "done" , stats ) ;
0 commit comments