@@ -4,6 +4,7 @@ var relativePath = require('cached-path-relative')
4
4
5
5
var browserResolve = require ( 'browser-resolve' ) ;
6
6
var nodeResolve = require ( 'resolve' ) ;
7
+ var detective = require ( 'detective' ) ;
7
8
var konan = require ( 'konan' ) ;
8
9
var through = require ( 'through2' ) ;
9
10
var concat = require ( 'concat-stream' ) ;
@@ -82,9 +83,9 @@ function Deps (opts) {
82
83
var self = this ;
83
84
if ( ! ( this instanceof Deps ) ) return new Deps ( opts ) ;
84
85
Transform . call ( this , { objectMode : true } ) ;
85
-
86
+
86
87
if ( ! opts ) opts = { } ;
87
-
88
+
88
89
this . basedir = opts . basedir || process . cwd ( ) ;
89
90
this . cache = opts . cache ;
90
91
this . fileCache = opts . fileCache ;
@@ -96,7 +97,7 @@ function Deps (opts) {
96
97
this . walking = { } ;
97
98
this . entries = [ ] ;
98
99
this . _input = [ ] ;
99
-
100
+
100
101
this . paths = opts . paths || process . env . NODE_PATH || '' ;
101
102
if ( typeof this . paths === 'string' ) {
102
103
var delimiter = path . delimiter || ( process . platform === 'win32' ? ';' : ':' ) ;
@@ -107,7 +108,7 @@ function Deps (opts) {
107
108
. map ( function ( p ) {
108
109
return path . resolve ( self . basedir , p ) ;
109
110
} ) ;
110
-
111
+
111
112
this . transforms = [ ] . concat ( opts . transform ) . filter ( Boolean ) ;
112
113
this . globalTransforms = [ ] . concat ( opts . globalTransform ) . filter ( Boolean ) ;
113
114
this . resolver = opts . resolve || browserResolve ;
@@ -119,7 +120,7 @@ function Deps (opts) {
119
120
if ( ! this . options . expose ) this . options . expose = { } ;
120
121
this . pending = 0 ;
121
122
this . inputPending = 0 ;
122
-
123
+
123
124
var topfile = path . join ( this . basedir , '__fake.js' ) ;
124
125
this . top = {
125
126
id : topfile ,
@@ -154,14 +155,14 @@ Deps.prototype._transform = function (row, enc, next) {
154
155
this . transforms . push ( [ row . transform , row . options ] ) ;
155
156
return next ( ) ;
156
157
}
157
-
158
+
158
159
self . pending ++ ;
159
160
var basedir = defined ( row . basedir , self . basedir ) ;
160
-
161
+
161
162
if ( row . entry !== false ) {
162
163
self . entries . push ( path . resolve ( basedir , row . file || row . id ) ) ;
163
164
}
164
-
165
+
165
166
self . lookupPackage ( row . file , function ( err , pkg ) {
166
167
if ( err && self . options . ignoreMissing ) {
167
168
self . emit ( 'missing' , row . file , self . top ) ;
@@ -190,7 +191,7 @@ Deps.prototype._flush = function () {
190
191
}
191
192
else files [ w . file || w . id ] = r ;
192
193
} ) ;
193
-
194
+
194
195
Object . keys ( files ) . forEach ( function ( key ) {
195
196
var r = files [ key ] ;
196
197
var pkg = r . pkg || { } ;
@@ -207,7 +208,7 @@ Deps.prototype._flush = function () {
207
208
Deps . prototype . resolve = function ( id , parent , cb ) {
208
209
var self = this ;
209
210
var opts = self . options ;
210
-
211
+
211
212
if ( xhas ( self . cache , parent . id , 'deps' , id )
212
213
&& self . cache [ parent . id ] . deps [ id ] ) {
213
214
var file = self . cache [ parent . id ] . deps [ id ] ;
@@ -217,25 +218,25 @@ Deps.prototype.resolve = function (id, parent, cb) {
217
218
cb ( null , file , pkg ) ;
218
219
} ) ;
219
220
}
220
-
221
+
221
222
parent . packageFilter = function ( p , x ) {
222
223
var pkgdir = dirname ( x ) ;
223
224
if ( opts . packageFilter ) p = opts . packageFilter ( p , x ) ;
224
225
p . __dirname = pkgdir ;
225
226
226
227
return p ;
227
228
} ;
228
-
229
+
229
230
if ( opts . extensions ) parent . extensions = opts . extensions ;
230
231
if ( opts . modules ) parent . modules = opts . modules ;
231
-
232
+
232
233
self . resolver ( id , parent , function onresolve ( err , file , pkg , fakePath ) {
233
234
if ( err ) return cb ( err ) ;
234
235
if ( ! file ) return cb ( new Error (
235
236
'module not found: "' + id + '" from file '
236
237
+ parent . filename
237
238
) ) ;
238
-
239
+
239
240
if ( ! pkg || ! pkg . __dirname ) {
240
241
self . lookupPackage ( file , function ( err , p ) {
241
242
if ( err ) return cb ( err ) ;
@@ -271,25 +272,25 @@ Deps.prototype.readFile = function (file, id, pkg) {
271
272
Deps . prototype . getTransforms = function ( file , pkg , opts ) {
272
273
if ( ! opts ) opts = { } ;
273
274
var self = this ;
274
-
275
+
275
276
var isTopLevel ;
276
277
if ( opts . builtin || opts . inNodeModules ) isTopLevel = false ;
277
278
else isTopLevel = this . _isTopLevel ( file ) ;
278
-
279
+
279
280
var transforms = [ ] . concat ( isTopLevel ? this . transforms : [ ] )
280
281
. concat ( getTransforms ( pkg , {
281
282
globalTransform : this . globalTransforms ,
282
283
transformKey : this . options . transformKey
283
284
} ) )
284
285
;
285
286
if ( transforms . length === 0 ) return through ( ) ;
286
-
287
+
287
288
var pending = transforms . length ;
288
289
var streams = [ ] ;
289
290
var input = through ( ) ;
290
291
var output = through ( ) ;
291
292
var dup = duplexer ( input , output ) ;
292
-
293
+
293
294
for ( var i = 0 ; i < transforms . length ; i ++ ) ( function ( i ) {
294
295
makeTransform ( transforms [ i ] , function ( err , trs ) {
295
296
if ( err ) return self . emit ( 'error' , err )
@@ -298,7 +299,7 @@ Deps.prototype.getTransforms = function (file, pkg, opts) {
298
299
} ) ;
299
300
} ) ( i ) ;
300
301
return dup ;
301
-
302
+
302
303
function done ( ) {
303
304
var middle = combine . apply ( null , streams ) ;
304
305
middle . on ( 'error' , function ( err ) {
@@ -308,7 +309,7 @@ Deps.prototype.getTransforms = function (file, pkg, opts) {
308
309
} ) ;
309
310
input . pipe ( middle ) . pipe ( output ) ;
310
311
}
311
-
312
+
312
313
function makeTransform ( tr , cb ) {
313
314
var trOpts = { } ;
314
315
if ( Array . isArray ( tr ) ) {
@@ -327,24 +328,24 @@ Deps.prototype.getTransforms = function (file, pkg, opts) {
327
328
} ) ;
328
329
}
329
330
}
330
-
331
+
331
332
function loadTransform ( id , trOpts , cb ) {
332
333
var params = { basedir : dirname ( file ) } ;
333
334
nodeResolve ( id , params , function nr ( err , res , again ) {
334
335
if ( err && again ) return cb && cb ( err ) ;
335
-
336
+
336
337
if ( err ) {
337
338
params . basedir = pkg . __dirname ;
338
339
return nodeResolve ( id , params , function ( e , r ) {
339
340
nr ( e , r , true )
340
341
} ) ;
341
342
}
342
-
343
+
343
344
if ( ! res ) return cb ( new Error (
344
345
'cannot find transform module ' + tr
345
346
+ ' while transforming ' + file
346
347
) ) ;
347
-
348
+
348
349
var r = require ( res ) ;
349
350
if ( typeof r !== 'function' ) {
350
351
return cb ( new Error (
@@ -353,7 +354,7 @@ Deps.prototype.getTransforms = function (file, pkg, opts) {
353
354
+ 'Expected a transform function.'
354
355
) ) ;
355
356
}
356
-
357
+
357
358
var trs = r ( file , trOpts ) ;
358
359
self . emit ( 'transform' , trs , file ) ;
359
360
cb ( null , trs ) ;
@@ -366,7 +367,7 @@ Deps.prototype.walk = function (id, parent, cb) {
366
367
var opts = self . options ;
367
368
var sortKey = parent . sortKey || '' ;
368
369
this . pending ++ ;
369
-
370
+
370
371
var rec = { } ;
371
372
var input ;
372
373
if ( typeof id === 'object' ) {
@@ -376,7 +377,7 @@ Deps.prototype.walk = function (id, parent, cb) {
376
377
input = true ;
377
378
this . inputPending ++ ;
378
379
}
379
-
380
+
380
381
self . resolve ( id , parent , function ( err , file , pkg , fakePath ) {
381
382
// this is checked early because parent.modules is also modified
382
383
// by this function.
@@ -393,15 +394,15 @@ Deps.prototype.walk = function (id, parent, cb) {
393
394
self . _emittedPkg [ pkg . __dirname ] = true ;
394
395
self . emit ( 'package' , pkg ) ;
395
396
}
396
-
397
+
397
398
if ( opts . postFilter && ! opts . postFilter ( id , file , pkg ) ) {
398
399
if ( -- self . pending === 0 ) self . push ( null ) ;
399
400
if ( input ) -- self . inputPending ;
400
401
return cb && cb ( null , undefined ) ;
401
402
}
402
403
if ( err && rec . source ) {
403
404
file = rec . file ;
404
-
405
+
405
406
var ts = self . getTransforms ( file , pkg ) ;
406
407
ts . pipe ( concat ( function ( body ) {
407
408
rec . source = body . toString ( 'utf8' ) ;
@@ -422,7 +423,7 @@ Deps.prototype.walk = function (id, parent, cb) {
422
423
return cb && cb ( null , file ) ;
423
424
}
424
425
self . visited [ file ] = true ;
425
-
426
+
426
427
if ( rec . source ) {
427
428
var ts = self . getTransforms ( file , pkg ) ;
428
429
ts . pipe ( concat ( function ( body ) {
@@ -431,10 +432,10 @@ Deps.prototype.walk = function (id, parent, cb) {
431
432
} ) ) ;
432
433
return ts . end ( rec . source ) ;
433
434
}
434
-
435
+
435
436
var c = self . cache && self . cache [ file ] ;
436
437
if ( c ) return fromDeps ( file , c . source , c . package , fakePath , Object . keys ( c . deps ) , sortKey ) ;
437
-
438
+
438
439
self . readFile ( file , id , pkg )
439
440
. pipe ( self . getTransforms ( fakePath || file , pkg , {
440
441
builtin : builtin ,
@@ -450,13 +451,13 @@ Deps.prototype.walk = function (id, parent, cb) {
450
451
var deps = rec . noparse ? [ ] : self . parseDeps ( file , src ) ;
451
452
if ( deps ) fromDeps ( file , src , pkg , fakePath , deps , sortKey ) ;
452
453
}
453
-
454
+
454
455
function fromDeps ( file , src , pkg , fakePath , deps , sortKey ) {
455
456
var p = deps . length ;
456
457
var resolved = { } ;
457
-
458
+
458
459
if ( input ) -- self . inputPending ;
459
-
460
+
460
461
( function resolve ( ) {
461
462
if ( self . inputPending > 0 ) return setTimeout ( resolve ) ;
462
463
deps . forEach ( function ( id , i ) {
@@ -481,19 +482,19 @@ Deps.prototype.walk = function (id, parent, cb) {
481
482
} ) ;
482
483
if ( deps . length === 0 ) done ( ) ;
483
484
} ) ( ) ;
484
-
485
+
485
486
function done ( ) {
486
487
if ( ! rec . id ) rec . id = file ;
487
488
if ( ! rec . source ) rec . source = src ;
488
489
if ( ! rec . deps ) rec . deps = resolved ;
489
490
if ( ! rec . file ) rec . file = file ;
490
491
rec . sortKey = sortKey + '!' + file ;
491
-
492
+
492
493
if ( self . entries . indexOf ( file ) >= 0 ) {
493
494
rec . entry = true ;
494
495
}
495
496
self . push ( rec ) ;
496
-
497
+
497
498
if ( cb ) cb ( null , file ) ;
498
499
if ( -- self . pending === 0 ) self . push ( null ) ;
499
500
}
@@ -503,13 +504,19 @@ Deps.prototype.walk = function (id, parent, cb) {
503
504
Deps . prototype . parseDeps = function ( file , src , cb ) {
504
505
if ( this . options . noParse === true ) return [ ] ;
505
506
if ( / \. j s o n $ / . test ( file ) ) return [ ] ;
506
-
507
+
507
508
if ( Array . isArray ( this . options . noParse )
508
509
&& this . options . noParse . indexOf ( file ) >= 0 ) {
509
510
return [ ] ;
510
511
}
511
-
512
- try { var deps = konan ( src ) . strings }
512
+
513
+ try {
514
+ try { var deps = konan ( src ) . strings }
515
+ catch ( ex ) {
516
+ // konan does not support Vue (component) file, try to parse using detective (as a fallback)
517
+ deps = detective ( src )
518
+ }
519
+ }
513
520
catch ( ex ) {
514
521
var message = ex && ex . message ? ex . message : ex ;
515
522
this . emit ( 'error' , new Error (
@@ -522,14 +529,14 @@ Deps.prototype.parseDeps = function (file, src, cb) {
522
529
523
530
Deps . prototype . lookupPackage = function ( file , cb ) {
524
531
var self = this ;
525
-
532
+
526
533
var cached = this . pkgCache [ file ] ;
527
534
if ( cached ) return nextTick ( cb , null , cached ) ;
528
535
if ( cached === false ) return nextTick ( cb , null , undefined ) ;
529
-
536
+
530
537
531
538
var dirs = parents ( path . dirname ( file || '' ) ) ;
532
-
539
+
533
540
( function next ( ) {
534
541
if ( dirs . length === 0 ) {
535
542
self . pkgCache [ file ] = false ;
@@ -539,17 +546,17 @@ Deps.prototype.lookupPackage = function (file, cb) {
539
546
if ( dir . split ( / [ \\ \/ ] / ) . slice ( - 1 ) [ 0 ] === 'node_modules' ) {
540
547
return cb ( null , undefined ) ;
541
548
}
542
-
549
+
543
550
var pkgfile = path . join ( dir , 'package.json' ) ;
544
-
551
+
545
552
var cached = self . pkgCache [ pkgfile ] ;
546
553
if ( cached ) return nextTick ( cb , null , cached ) ;
547
554
else if ( cached === false ) return next ( ) ;
548
-
555
+
549
556
var pcached = self . pkgFileCachePending [ pkgfile ] ;
550
557
if ( pcached ) return pcached . push ( onpkg ) ;
551
558
pcached = self . pkgFileCachePending [ pkgfile ] = [ ] ;
552
-
559
+
553
560
fs . readFile ( pkgfile , function ( err , src ) {
554
561
if ( err ) return onpkg ( ) ;
555
562
try { var pkg = JSON . parse ( src ) }
@@ -559,12 +566,12 @@ Deps.prototype.lookupPackage = function (file, cb) {
559
566
] . join ( '' ) ) )
560
567
}
561
568
pkg . __dirname = dir ;
562
-
569
+
563
570
self . pkgCache [ pkgfile ] = pkg ;
564
571
self . pkgCache [ file ] = pkg ;
565
572
onpkg ( null , pkg ) ;
566
573
} ) ;
567
-
574
+
568
575
function onpkg ( err , pkg ) {
569
576
if ( self . pkgFileCachePending [ pkgfile ] ) {
570
577
var fns = self . pkgFileCachePending [ pkgfile ] ;
@@ -580,7 +587,7 @@ Deps.prototype.lookupPackage = function (file, cb) {
580
587
}
581
588
} ) ( ) ;
582
589
} ;
583
-
590
+
584
591
function getTransforms ( pkg , opts ) {
585
592
var trx = [ ] ;
586
593
if ( opts . transformKey ) {
0 commit comments