@@ -38,6 +38,7 @@ function Deps (opts) {
3838 this . pkgFileCache = { } ;
3939 this . pkgFileCachePending = { } ;
4040 this . _emittedPkg = { } ;
41+ this . _transformDeps = { } ;
4142 this . visited = { } ;
4243 this . walking = { } ;
4344 this . entries = [ ] ;
@@ -261,6 +262,11 @@ Deps.prototype.getTransforms = function (file, pkg, opts) {
261262 trOpts . _flags = trOpts . hasOwnProperty ( '_flags' ) ? trOpts . _flags : self . options ;
262263 if ( typeof tr === 'function' ) {
263264 var t = tr ( file , trOpts ) ;
265+ // allow transforms to `stream.emit('dep', path)` to add dependencies for this file
266+ self . _transformDeps [ file ] = [ ] ;
267+ t . on ( 'dep' , function ( dep ) {
268+ self . _transformDeps [ file ] . push ( dep ) ;
269+ } ) ;
264270 self . emit ( 'transform' , t , file ) ;
265271 nextTick ( cb , null , wrapTransform ( t ) ) ;
266272 }
@@ -302,6 +308,11 @@ Deps.prototype.getTransforms = function (file, pkg, opts) {
302308 }
303309
304310 var trs = r ( file , trOpts ) ;
311+ // allow transforms to `stream.emit('dep', path)` to add dependencies for this file
312+ self . _transformDeps [ file ] = [ ] ;
313+ trs . on ( 'dep' , function ( dep ) {
314+ self . _transformDeps [ file ] . push ( dep ) ;
315+ } ) ;
305316 self . emit ( 'transform' , trs , file ) ;
306317 cb ( null , trs ) ;
307318 } ) ;
@@ -422,7 +433,10 @@ Deps.prototype.walk = function (id, parent, cb) {
422433 } ) ;
423434
424435 function getDeps ( file , src ) {
425- return rec . noparse ? [ ] : self . parseDeps ( file , src ) ;
436+ var deps = rec . noparse ? [ ] : self . parseDeps ( file , src ) ;
437+ // dependencies emitted by transforms
438+ if ( self . _transformDeps [ file ] ) deps = deps . concat ( self . _transformDeps [ file ] ) ;
439+ return deps ;
426440 }
427441
428442 function fromSource ( file , src , pkg , fakePath ) {
0 commit comments