@@ -69,6 +69,18 @@ function Deps (opts) {
69
69
} ;
70
70
}
71
71
72
+ Deps . prototype . _isTopLevel = function ( file ) {
73
+ var isTopLevel = this . entries . some ( function ( main ) {
74
+ var m = path . relative ( path . dirname ( main ) , file ) ;
75
+ return m . split ( / [ \\ \/ ] / ) . indexOf ( 'node_modules' ) < 0 ;
76
+ } ) ;
77
+ if ( ! isTopLevel ) {
78
+ var m = path . relative ( this . basedir , file ) ;
79
+ isTopLevel = m . split ( / [ \\ \/ ] / ) . indexOf ( 'node_modules' ) < 0 ;
80
+ }
81
+ return isTopLevel ;
82
+ } ;
83
+
72
84
Deps . prototype . _transform = function ( row , enc , next ) {
73
85
var self = this ;
74
86
if ( typeof row === 'string' ) {
@@ -197,20 +209,12 @@ Deps.prototype.readFile = function (file, id, pkg) {
197
209
} ;
198
210
199
211
Deps . prototype . getTransforms = function ( file , pkg , opts ) {
200
- // TODO: Needs FAKE path here.
201
212
if ( ! opts ) opts = { } ;
202
213
var self = this ;
203
214
204
215
var isTopLevel ;
205
- if ( opts . builtin ) isTopLevel = false ;
206
- else isTopLevel = this . entries . some ( function ( main ) {
207
- var m = path . relative ( path . dirname ( main ) , file ) ;
208
- return m . split ( / [ \\ \/ ] / ) . indexOf ( 'node_modules' ) < 0 ;
209
- } ) ;
210
- if ( ! isTopLevel && ! opts . builtin ) {
211
- var m = path . relative ( this . basedir , file ) ;
212
- isTopLevel = m . split ( / [ \\ \/ ] / ) . indexOf ( 'node_modules' ) < 0 ;
213
- }
216
+ if ( opts . builtin || opts . inNodeModules ) isTopLevel = false ;
217
+ else isTopLevel = this . _isTopLevel ( file ) ;
214
218
215
219
var transforms = [ ] . concat ( isTopLevel ? this . transforms : [ ] )
216
220
. concat ( getTransforms ( pkg , {
@@ -368,24 +372,25 @@ Deps.prototype.walk = function (id, parent, cb) {
368
372
}
369
373
370
374
var c = self . cache && self . cache [ file ] ;
371
- if ( c ) return fromDeps ( file , c . source , c . package , Object . keys ( c . deps ) ) ;
375
+ if ( c ) return fromDeps ( file , c . source , c . package , fakePath , Object . keys ( c . deps ) ) ;
372
376
373
377
self . readFile ( file , id , pkg )
374
378
. pipe ( self . getTransforms ( fakePath || file , pkg , {
375
- builtin : builtin
379
+ builtin : builtin ,
380
+ inNodeModules : parent . inNodeModules
376
381
} ) )
377
382
. pipe ( concat ( function ( body ) {
378
- fromSource ( file , body . toString ( 'utf8' ) , pkg ) ;
383
+ fromSource ( file , body . toString ( 'utf8' ) , pkg , fakePath ) ;
379
384
} ) )
380
385
;
381
386
} ) ;
382
387
383
- function fromSource ( file , src , pkg ) {
388
+ function fromSource ( file , src , pkg , fakePath ) {
384
389
var deps = rec . noparse ? [ ] : self . parseDeps ( file , src ) ;
385
- if ( deps ) fromDeps ( file , src , pkg , deps ) ;
390
+ if ( deps ) fromDeps ( file , src , pkg , fakePath , deps ) ;
386
391
}
387
392
388
- function fromDeps ( file , src , pkg , deps ) {
393
+ function fromDeps ( file , src , pkg , fakePath , deps ) {
389
394
var p = deps . length ;
390
395
var resolved = { } ;
391
396
@@ -399,11 +404,13 @@ Deps.prototype.walk = function (id, parent, cb) {
399
404
if ( -- p === 0 ) done ( ) ;
400
405
return ;
401
406
}
407
+ var isTopLevel = self . _isTopLevel ( fakePath || file ) ;
402
408
var current = {
403
409
id : file ,
404
410
filename : file ,
405
411
paths : self . paths ,
406
- package : pkg
412
+ package : pkg ,
413
+ inNodeModules : parent . inNodeModules || ! isTopLevel
407
414
} ;
408
415
self . walk ( id , current , function ( err , r ) {
409
416
resolved [ id ] = r ;
0 commit comments