1
1
var fs = require ( 'fs' ) ;
2
2
var path = require ( 'path' ) ;
3
- var relativePath = require ( 'cached-path-relative' )
3
+ var relativePath = require ( 'cached-path-relative' ) ;
4
4
5
5
var browserResolve = require ( 'browser-resolve' ) ;
6
6
var nodeResolve = require ( 'resolve' ) ;
@@ -206,8 +206,6 @@ Deps.prototype.readFile = function (file, id, pkg) {
206
206
var rs = fs . createReadStream ( file , {
207
207
encoding : 'utf8'
208
208
} ) ;
209
- rs . on ( 'error' , function ( err ) { self . emit ( 'error' , err ) } ) ;
210
- this . emit ( 'file' , file , id ) ;
211
209
return rs ;
212
210
} ;
213
211
@@ -235,7 +233,9 @@ Deps.prototype.getTransforms = function (file, pkg, opts) {
235
233
236
234
for ( var i = 0 ; i < transforms . length ; i ++ ) ( function ( i ) {
237
235
makeTransform ( transforms [ i ] , function ( err , trs ) {
238
- if ( err ) return self . emit ( 'error' , err )
236
+ if ( err ) {
237
+ return dup . emit ( 'error' , err ) ;
238
+ }
239
239
streams [ i ] = trs ;
240
240
if ( -- pending === 0 ) done ( ) ;
241
241
} ) ;
@@ -247,7 +247,7 @@ Deps.prototype.getTransforms = function (file, pkg, opts) {
247
247
middle . on ( 'error' , function ( err ) {
248
248
err . message += ' while parsing file: ' + file ;
249
249
if ( ! err . filename ) err . filename = file ;
250
- self . emit ( 'error' , err ) ;
250
+ dup . emit ( 'error' , err ) ;
251
251
} ) ;
252
252
input . pipe ( middle ) . pipe ( output ) ;
253
253
}
@@ -283,7 +283,7 @@ Deps.prototype.getTransforms = function (file, pkg, opts) {
283
283
if ( err ) {
284
284
params . basedir = pkg . __dirname ;
285
285
return nodeResolve ( id , params , function ( e , r ) {
286
- nr ( e , r , true )
286
+ nr ( e , r , true ) ;
287
287
} ) ;
288
288
}
289
289
@@ -349,6 +349,9 @@ Deps.prototype.walk = function (id, parent, cb) {
349
349
file = rec . file ;
350
350
351
351
var ts = self . getTransforms ( file , pkg ) ;
352
+ ts . on ( 'error' , function ( err ) {
353
+ self . emit ( 'error' , err ) ;
354
+ } ) ;
352
355
ts . pipe ( concat ( function ( body ) {
353
356
rec . source = body . toString ( 'utf8' ) ;
354
357
fromSource ( file , rec . source , pkg ) ;
@@ -371,6 +374,9 @@ Deps.prototype.walk = function (id, parent, cb) {
371
374
372
375
if ( rec . source ) {
373
376
var ts = self . getTransforms ( file , pkg ) ;
377
+ ts . on ( 'error' , function ( err ) {
378
+ self . emit ( 'error' , err ) ;
379
+ } ) ;
374
380
ts . pipe ( concat ( function ( body ) {
375
381
rec . source = body . toString ( 'utf8' ) ;
376
382
fromSource ( file , rec . source , pkg ) ;
@@ -382,6 +388,7 @@ Deps.prototype.walk = function (id, parent, cb) {
382
388
if ( c ) return fromDeps ( file , c . source , c . package , fakePath , Object . keys ( c . deps ) ) ;
383
389
384
390
self . persistentCache ( file , id , pkg , persistentCacheFallback , function ( err , c ) {
391
+ self . emit ( 'file' , file , id ) ;
385
392
if ( err ) {
386
393
self . emit ( 'error' , err ) ;
387
394
return ;
@@ -390,12 +397,13 @@ Deps.prototype.walk = function (id, parent, cb) {
390
397
} ) ;
391
398
392
399
function persistentCacheFallback ( dataAsString , cb ) {
393
- var stream = dataAsString ? toStream ( dataAsString ) : self . readFile ( file , id , pkg ) ;
400
+ var stream = dataAsString ? toStream ( dataAsString ) : self . readFile ( file , id , pkg ) . on ( 'error' , cb ) ;
394
401
stream
395
402
. pipe ( self . getTransforms ( fakePath || file , pkg , {
396
403
builtin : builtin ,
397
404
inNodeModules : parent . inNodeModules
398
405
} ) )
406
+ . on ( 'error' , cb )
399
407
. pipe ( concat ( function ( body ) {
400
408
var src = body . toString ( 'utf8' ) ;
401
409
var deps = getDeps ( file , src ) ;
@@ -524,7 +532,7 @@ Deps.prototype.lookupPackage = function (file, cb) {
524
532
catch ( err ) {
525
533
return onpkg ( new Error ( [
526
534
err + ' while parsing json file ' + pkgfile
527
- ] . join ( '' ) ) )
535
+ ] . join ( '' ) ) ) ;
528
536
}
529
537
pkg . __dirname = dir ;
530
538
@@ -539,8 +547,8 @@ Deps.prototype.lookupPackage = function (file, cb) {
539
547
delete self . pkgFileCachePending [ pkgfile ] ;
540
548
fns . forEach ( function ( f ) { f ( err , pkg ) } ) ;
541
549
}
542
- if ( err ) cb ( err )
543
- else if ( pkg && typeof pkg === 'object' ) cb ( null , pkg )
550
+ if ( err ) cb ( err ) ;
551
+ else if ( pkg && typeof pkg === 'object' ) cb ( null , pkg ) ;
544
552
else {
545
553
self . pkgCache [ pkgfile ] = false ;
546
554
next ( ) ;
0 commit comments