@@ -234,63 +234,106 @@ Compilation.prototype.processModuleDependencies = function(module, callback) {
234234 } ) ;
235235} ;
236236
237- Compilation . prototype . addEntry = function process ( context , entry , name , callback ) {
237+ Compilation . prototype . _addModuleChain = function process ( context , dependency , onModule , callback ) {
238238 var errorAndCallback = this . bail ? function errorAndCallback ( err ) {
239239 callback ( err ) ;
240240 } : function errorAndCallback ( err ) {
241- err . dependencies = [ entry ] ;
241+ err . dependencies = [ dependency ] ;
242242 this . errors . push ( err ) ;
243243 callback ( ) ;
244244 } . bind ( this ) ;
245245
246- if ( ! ( typeof entry == "object" && entry != null && entry . Class ) )
247- return callback ( new Error ( "Parameter 'entry ' must be a Dependency" ) ) ;
246+ if ( ! ( typeof dependency == "object" && dependency != null && dependency . Class ) )
247+ throw new Error ( "Parameter 'dependency ' must be a Dependency" ) ;
248248
249- var moduleFactory = this . dependencyFactories . get ( entry . Class ) ;
249+ var moduleFactory = this . dependencyFactories . get ( dependency . Class ) ;
250250 if ( ! moduleFactory )
251- return callback ( new Error ( "No dependency factory availible for this entry dependency type: " + entry . Class . name ) ) ;
251+ throw new Error ( "No dependency factory availible for this dependency type: " + dependency . Class . name ) ;
252252
253- moduleFactory . create ( context , entry , function ( err , module ) {
253+ if ( this . profile ) var start = + new Date ( ) ;
254+ moduleFactory . create ( context , dependency , function ( err , module ) {
254255 if ( err ) return errorAndCallback ( new EntryModuleNotFoundError ( err ) ) ;
255256
257+ if ( this . profile ) {
258+ if ( ! module . profile ) module . profile = { } ;
259+ var afterFactory = + new Date ( ) ;
260+ module . profile . factory = afterFactory - start ;
261+ }
262+
256263 var result = this . addModule ( module ) ;
257264 if ( ! result ) {
258- return callback ( new Error ( "Entry module is already added" ) ) ;
265+ module = this . getModule ( module ) ;
266+
267+ onModule ( module ) ;
268+
269+ return callback ( null , module ) ;
259270 }
260271
261272 if ( result instanceof Module ) {
273+ if ( this . profile ) {
274+ result . profile = module . profile ;
275+ }
276+
262277 module = result ;
263278 }
264279
265- this . entries . push ( module ) ;
266- module . id = 0 ;
280+ onModule ( module ) ;
267281
268282 if ( result instanceof Module ) {
269- entryReady . call ( this ) ;
283+ moduleReady . call ( this ) ;
270284 } else {
271285 this . buildModule ( module , function ( err ) {
272286 if ( err ) return errorAndCallback ( err ) ;
273287
274- entryReady . call ( this ) ;
288+ if ( this . profile ) {
289+ var afterBuilding = + new Date ( ) ;
290+ module . profile . building = afterBuilding - afterFactory ;
291+ }
292+
293+ moduleReady . call ( this ) ;
275294 } . bind ( this ) ) ;
276295 }
277296
278- function entryReady ( ) {
297+ function moduleReady ( ) {
279298 this . processModuleDependencies ( module , function ( err ) {
280299 if ( err ) return callback ( err ) ;
281300
282- var chunk = this . addChunk ( name ) ;
283- chunk . id = 0 ;
284- chunk . entry = true ;
285- chunk . addModule ( module ) ;
286- module . addChunk ( chunk ) ;
287- this . processDependenciesBlockForChunk ( module , chunk ) ;
288- return callback ( ) ;
301+ return callback ( null , module ) ;
289302 } . bind ( this ) ) ;
290303 }
291304 } . bind ( this ) ) ;
292305} ;
293306
307+ Compilation . prototype . addEntry = function process ( context , entry , name , callback ) {
308+ this . _addModuleChain ( context , entry , function ( module ) {
309+
310+ this . entries . push ( module ) ;
311+ module . id = 0 ;
312+
313+ } . bind ( this ) , function ( err , module ) {
314+ if ( err ) return callback ( err ) ;
315+
316+ if ( module ) {
317+ var chunk = this . addChunk ( name ) ;
318+ chunk . id = 0 ;
319+ chunk . entry = true ;
320+ chunk . addModule ( module ) ;
321+ module . addChunk ( chunk ) ;
322+ this . processDependenciesBlockForChunk ( module , chunk ) ;
323+ }
324+ return callback ( ) ;
325+ } . bind ( this ) ) ;
326+ } ;
327+
328+
329+ Compilation . prototype . prefetch = function process ( context , dependency , callback ) {
330+ this . _addModuleChain ( context , dependency , function ( module ) {
331+
332+ module . prefetched = true ;
333+
334+ } , callback ) ;
335+ } ;
336+
294337Compilation . prototype . seal = function seal ( callback ) {
295338 this . applyPlugins ( "seal" ) ;
296339 this . applyPlugins ( "optimize" ) ;
0 commit comments