-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document required browserify option "dedupe: false" #93
base: master
Are you sure you want to change the base?
Changes from 4 commits
0b40888
c8195ef
dd34b23
c5f0f40
85a54a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = 42 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = 42 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
var a = require('./a1.js'); | ||
var z = require('./z.js'); | ||
var w = require('./w.js'); | ||
console.log(z(5) * w(2)); | ||
console.log(a * z(5) * w(2)); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
var a = require('./a2.js'); | ||
var z = require('./z.js'); | ||
console.log(z(2) + 111); | ||
console.log(a + z(2) + 111); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,9 +26,9 @@ module.exports = function f (b, opts) { | |
.concat(opts._).filter(Boolean); | ||
|
||
var needRecords = !files.length; | ||
|
||
var outopt = defined(opts.outputs, opts.output, opts.o); | ||
|
||
opts.objectMode = true; | ||
opts.raw = true; | ||
opts.rmap = {}; | ||
|
@@ -44,6 +44,7 @@ module.exports = function f (b, opts) { | |
|
||
function addHooks () { | ||
b.pipeline.get('record').push(through.obj(function(row, enc, next) { | ||
// record entrypoints | ||
if (row.file && needRecords) { | ||
files.push(row.file); | ||
} | ||
|
@@ -65,47 +66,59 @@ module.exports = function f (b, opts) { | |
outputs = []; | ||
} | ||
|
||
// utility for creating output streams | ||
function moreOutputs (file) { | ||
if (isarray(outopt)) return []; | ||
if (!outopt) return []; | ||
var xopts = { env: xtend(process.env, { FILE: file }) }; | ||
return [ outpipe(outopt, xopts) ]; | ||
} | ||
|
||
var pipelines = files.reduce(function (acc, x, ix) { | ||
// create a pipeline (labeled-stream-splicer) for every entry file | ||
// with only a packer | ||
var pipelines = files.reduce(function (acc, file, index) { | ||
var pipeline = splicer.obj([ | ||
'pack', [ pack(packOpts) ], | ||
'wrap', [] | ||
]); | ||
|
||
if (ix >= outputs.length) { | ||
outputs.push.apply(outputs, moreOutputs(x)); | ||
// if not enough specified outputs, possibly add additional outputs (?) | ||
if (index >= outputs.length) { | ||
outputs.push.apply(outputs, moreOutputs(file)); | ||
} | ||
if (outputs[ix]) pipeline.pipe(outputs[ix]); | ||
|
||
acc[path.resolve(cwd, x)] = pipeline; | ||
// pipe to output if one exists | ||
if (outputs[index]) pipeline.pipe(outputs[index]); | ||
|
||
acc[path.resolve(cwd, file)] = pipeline; | ||
return acc; | ||
}, {}); | ||
|
||
// Force browser-pack to wrap the common bundle | ||
b._bpack.hasExports = true; | ||
|
||
// for tests/debugging | ||
Object.keys(pipelines).forEach(function (id) { | ||
b.emit('factor.pipeline', id, pipelines[id]); | ||
}); | ||
|
||
// create factor stream | ||
var s = createStream(files, opts); | ||
|
||
// connect each factor groups module stream to bundle pipeline | ||
s.on('stream', function (bundle) { | ||
// each group's output stream | ||
bundle.pipe(pipelines[bundle.file]); | ||
}); | ||
|
||
// add factor stream before pack | ||
b.pipeline.get('pack').unshift(s); | ||
|
||
if (needRecords) files = []; | ||
|
||
next(); | ||
})); | ||
|
||
// capture module's relative path. used for recovering entry point pathnames | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would keep this comment but probably remove most of the others…tbh, I feel like many of the comments only restate the line and don't actually clarify much. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added the comments to stay sane while trying to read through the code which i found unintuitive |
||
b.pipeline.get('label').push(through.obj(function(row, enc, next) { | ||
opts.rmap[row.id] = path.resolve(cwd, row.file); | ||
next(null, row); | ||
|
@@ -118,10 +131,10 @@ module.exports = function f (b, opts) { | |
|
||
function createStream (files, opts) { | ||
if (!opts) opts = {}; | ||
|
||
var fr = new Factor(files, opts); | ||
var parse, dup; | ||
|
||
if (opts.objectMode) { | ||
dup = combine(depsTopoSort(), reverse(), fr); | ||
} | ||
|
@@ -135,7 +148,7 @@ function createStream (files, opts) { | |
; | ||
parse.on('error', function (err) { dup.emit('error', err) }); | ||
} | ||
|
||
fr.on('error', function (err) { dup.emit('error', err) }); | ||
fr.on('stream', function (s) { | ||
if (opts.raw) dup.emit('stream', s) | ||
|
@@ -150,21 +163,21 @@ function Factor (files, opts) { | |
var self = this; | ||
if (!(this instanceof Factor)) return new Factor(files, opts); | ||
Transform.call(this, { objectMode: true }); | ||
|
||
if (!opts) opts = {}; | ||
this.basedir = defined(opts.basedir, process.cwd()); | ||
|
||
this._streams = {}; | ||
this._groups = {}; | ||
this._buffered = {}; | ||
|
||
this._ensureCommon = {}; | ||
this._files = files.reduce(function (acc, file) { | ||
acc[path.resolve(self.basedir, file)] = true; | ||
return acc; | ||
}, {}); | ||
this._rmap = opts.rmap || {}; | ||
|
||
this._thresholdVal = typeof opts.threshold === "number" | ||
? opts.threshold : 1 | ||
; | ||
|
@@ -200,9 +213,9 @@ Factor.prototype._transform = function (row, enc, next) { | |
self._streams[id].push(row); | ||
}); | ||
} | ||
|
||
next(); | ||
|
||
function addGroups (gid) { | ||
Object.keys(row.deps || {}).forEach(function (key) { | ||
var file = row.deps[key]; | ||
|
@@ -215,7 +228,7 @@ Factor.prototype._transform = function (row, enc, next) { | |
|
||
Factor.prototype._flush = function () { | ||
var self = this; | ||
|
||
Object.keys(self._streams).forEach(function (key) { | ||
self._streams[key].push(null); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's also for plugins to hook into factored pipelines. If you have a minification step for example it can be added to the factored pipeline by using this event.