@@ -12,6 +12,7 @@ var fs = require('fs');
12
12
var pack = require ( 'browser-pack' ) ;
13
13
var xtend = require ( 'xtend' ) ;
14
14
var defined = require ( 'defined' ) ;
15
+ var splicer = require ( 'labeled-stream-splicer' ) ;
15
16
16
17
module . exports = function f ( b , opts ) {
17
18
if ( ! opts ) opts = { } ;
@@ -24,40 +25,51 @@ module.exports = function f (b, opts) {
24
25
25
26
var needRecords = ! files . length ;
26
27
27
- opts . outputs = opts . outputs || opts . o ;
28
+ opts . outputs = defined ( opts . outputs , opts . o , { } ) ;
28
29
opts . objectMode = true ;
29
30
opts . raw = true ;
30
31
opts . rmap = { } ;
31
32
33
+ var packOpts = xtend ( b . _options , {
34
+ raw : true ,
35
+ hasExports : true
36
+ } ) ;
37
+
32
38
b . on ( 'reset' , addHooks ) ;
33
39
addHooks ( ) ;
34
40
35
- function addHooks ( ) {
41
+ function addHooks ( ) {
36
42
b . pipeline . get ( 'record' ) . push ( through . obj ( function ( row , enc , next ) {
37
43
if ( needRecords ) {
38
44
files . push ( row . file ) ;
39
45
}
40
46
next ( null , row ) ;
41
47
} , function ( next ) {
42
48
var cwd = defined ( opts . basedir , b . _options . basedir , process . cwd ( ) ) ;
43
- var fileMap = files . reduce ( function ( acc , x , ix ) {
44
- acc [ path . resolve ( cwd , x ) ] = opts . outputs [ ix ] ;
49
+ var pipelines = files . reduce ( function ( acc , x , ix ) {
50
+ var pipeline = splicer . obj ( [
51
+ 'pack' , [ pack ( packOpts ) ] ,
52
+ 'wrap' , [ ]
53
+ ] ) ;
54
+ var output = opts . outputs [ ix ] ;
55
+ if ( output ) {
56
+ var ws = isStream ( output ) ? output : fs . createWriteStream ( output ) ;
57
+ pipeline . push ( ws ) ;
58
+ }
59
+ acc [ path . resolve ( cwd , x ) ] = pipeline ;
45
60
return acc ;
46
61
} , { } ) ;
47
62
48
63
// Force browser-pack to wrap the common bundle
49
64
b . _bpack . hasExports = true ;
50
- var packOpts = xtend ( b . _options , {
51
- raw : true ,
52
- hasExports : true
65
+
66
+ Object . keys ( pipelines ) . forEach ( function ( id ) {
67
+ b . emit ( 'factor.pipeline' , id , pipelines [ id ] ) ;
53
68
} ) ;
54
69
55
70
var s = createStream ( files , opts ) ;
56
71
s . on ( 'stream' , function ( bundle ) {
57
- var output = fileMap [ bundle . file ] ;
58
- var ws = isStream ( output ) ? output : fs . createWriteStream ( output ) ;
59
-
60
- bundle . pipe ( pack ( packOpts ) ) . pipe ( ws ) ;
72
+ bundle . pipe ( pipelines [ bundle . file ] ) ;
61
73
} ) ;
62
74
63
75
b . pipeline . get ( 'pack' ) . unshift ( s ) ;
0 commit comments