@@ -23,14 +23,18 @@ var RequireEnsureItemDependency = require("./dependencies/RequireEnsureItemDepen
2323
2424function Watching ( compiler , handler , watchDelay ) {
2525 this . startTime = null ;
26- this . running = false ;
2726 this . invalid = false ;
2827 this . error = null ;
2928 this . stats = null ;
3029 this . handler = handler ;
3130 this . watchDelay = watchDelay ;
3231 this . compiler = compiler ;
33- this . _go ( ) ;
32+ this . running = true ;
33+ this . compiler . readRecords ( function ( err ) {
34+ if ( err ) return this . _done ( err ) ;
35+
36+ this . _go ( ) ;
37+ } . bind ( this ) ) ;
3438}
3539
3640Watching . prototype . _go = function ( ) {
@@ -44,8 +48,13 @@ Watching.prototype._go = function() {
4448
4549 this . compiler . emitAssets ( compilation , function ( err ) {
4650 if ( err ) return this . _done ( err ) ;
51+ if ( this . invalid ) return this . _done ( ) ;
4752
48- return this . _done ( null , compilation ) ;
53+ this . compiler . emitRecords ( function ( err ) {
54+ if ( err ) return this . _done ( err ) ;
55+
56+ return this . _done ( null , compilation ) ;
57+ } . bind ( this ) ) ;
4958 } . bind ( this ) ) ;
5059 } . bind ( this ) ) ;
5160 } . bind ( this ) ) ;
@@ -101,6 +110,10 @@ function Compiler() {
101110 this . inputFileSystem = null ;
102111 this . separateExecutor = null ;
103112
113+ this . recordsInputPath = null ;
114+ this . recordsOutputPath = null ;
115+ this . records = { } ;
116+
104117 this . fileTimestamps = { } ;
105118 this . contextTimestamps = { } ;
106119
@@ -130,17 +143,25 @@ Compiler.prototype.run = function(callback) {
130143 this . applyPluginsAsync ( "run" , this , function ( err ) {
131144 if ( err ) return callback ( err ) ;
132145
133- this . compile ( function ( err , compilation ) {
146+ this . readRecords ( function ( err ) {
134147 if ( err ) return callback ( err ) ;
135148
136- this . emitAssets ( compilation , function ( err ) {
149+ this . compile ( function ( err , compilation ) {
137150 if ( err ) return callback ( err ) ;
138151
139- var stats = compilation . getStats ( ) ;
140- stats . startTime = startTime ;
141- stats . endTime = new Date ( ) . getTime ( ) ;
142- this . applyPlugins ( "done" , stats ) ;
143- return callback ( null , stats ) ;
152+ this . emitAssets ( compilation , function ( err ) {
153+ if ( err ) return callback ( err ) ;
154+
155+ this . emitRecords ( function ( err ) {
156+ if ( err ) return callback ( err ) ;
157+
158+ var stats = compilation . getStats ( ) ;
159+ stats . startTime = startTime ;
160+ stats . endTime = new Date ( ) . getTime ( ) ;
161+ this . applyPlugins ( "done" , stats ) ;
162+ return callback ( null , stats ) ;
163+ } . bind ( this ) ) ;
164+ } . bind ( this ) ) ;
144165 } . bind ( this ) ) ;
145166 } . bind ( this ) ) ;
146167 } . bind ( this ) ) ;
@@ -210,6 +231,36 @@ Compiler.prototype.emitAssets = function(compilation, callback) {
210231
211232} ;
212233
234+ Compiler . prototype . emitRecords = function emitRecords ( callback ) {
235+ if ( ! this . recordsOutputPath ) return callback ( ) ;
236+ this . outputFileSystem . writeFile ( this . recordsOutputPath , JSON . stringify ( this . records , undefined , 2 ) , callback ) ;
237+ } ;
238+
239+ Compiler . prototype . readRecords = function readRecords ( callback ) {
240+ if ( ! this . recordsInputPath ) {
241+ this . records = { } ;
242+ return callback ( ) ;
243+ }
244+ this . inputFileSystem . stat ( this . recordsInputPath , function ( err ) {
245+ // It doesn't exist
246+ // We can ignore this.
247+ if ( err ) return callback ( ) ;
248+
249+ this . inputFileSystem . readFile ( this . recordsInputPath , function ( err , content ) {
250+ if ( err ) return callback ( err ) ;
251+
252+ try {
253+ this . records = JSON . parse ( content ) ;
254+ } catch ( e ) {
255+ e . message = "Cannot parse records: " + e . message ;
256+ return callback ( e ) ;
257+ }
258+
259+ return callback ( ) ;
260+ } . bind ( this ) ) ;
261+ } . bind ( this ) ) ;
262+ } ;
263+
213264Compiler . prototype . createChildCompiler = function ( compilation , compilerName , outputOptions ) {
214265 var childCompiler = new Compiler ( ) ;
215266 for ( var name in this . _plugins ) {
@@ -248,6 +299,7 @@ Compiler.prototype.newCompilation = function(params) {
248299 compilation . fileTimestamps = this . fileTimestamps ;
249300 compilation . contextTimestamps = this . contextTimestamps ;
250301 compilation . name = this . name ;
302+ compilation . records = this . records ;
251303 this . applyPlugins ( "compilation" , compilation , params ) ;
252304 return compilation ;
253305} ;
0 commit comments