Skip to content

Commit

Permalink
Add option to turn off deduping
Browse files Browse the repository at this point in the history
  • Loading branch information
Giancarlo Anemone committed Jun 23, 2016
1 parent 071642a commit 7fbaee2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
4 changes: 4 additions & 0 deletions bin/advanced.txt
Expand Up @@ -70,6 +70,10 @@ Advanced Options:
Instead of standard bundle output, print the dependency array generated by
module-deps.

--no-dedupe

Turn off deduping.

--list

Print each file in the dependency graph. Useful for makefiles.
Expand Down
4 changes: 3 additions & 1 deletion bin/args.js
Expand Up @@ -47,6 +47,7 @@ module.exports = function (args, opts) {
commondir: true,
'bundle-external': true,
bf: true,
dedupe: true,
node: false
}
});
Expand Down Expand Up @@ -104,7 +105,8 @@ module.exports = function (args, opts) {
bundleExternal: argv['bundle-external'],
basedir: argv.basedir,
browserField: argv.browserField,

dedupe: argv['dedupe'],

detectGlobals: argv.detectGlobals,
insertGlobals: argv['insert-globals'] || argv.ig,
insertGlobalVars: insertGlobalVars,
Expand Down
6 changes: 4 additions & 2 deletions index.js
Expand Up @@ -49,7 +49,9 @@ function Browserify (files, opts) {
if (opts.basedir !== undefined && typeof opts.basedir !== 'string') {
throw new Error('opts.basedir must be either undefined or a string.');
}


opts.dedupe = opts.dedupe === false ? false : true;

self._external = [];
self._exclude = [];
self._ignore = [];
Expand Down Expand Up @@ -380,7 +382,7 @@ Browserify.prototype._createPipeline = function (opts) {

var dopts = {
index: !opts.fullPaths && !opts.exposeAll,
dedupe: true,
dedupe: opts.dedupe,
expose: this._expose
};
this._bpack = bpack(xtend(opts, { raw: true }));
Expand Down
4 changes: 4 additions & 0 deletions readme.markdown
Expand Up @@ -178,6 +178,10 @@ Advanced Options:
Instead of standard bundle output, print the dependency array generated by
module-deps.
--no-dedupe
Turn off deduping.
--list
Print each file in the dependency graph. Useful for makefiles.
Expand Down
16 changes: 16 additions & 0 deletions test/dedupe-deps.js
Expand Up @@ -41,3 +41,19 @@ test('identical content gets deduped with fullPaths', function (t) {
);
}
})

test('identical content does not get deduped with dedupe option false', function (t) {
t.plan(1)

var rows = [];
browserify({fullPaths: true, dedupe: false})
.on('dep', [].push.bind(rows))
.require(require.resolve('./dup'), { entry: true })
.bundle(check);

function check(err, src) {
if (err) return t.fail(err);
var deduped = rows.filter(function (x) { return x.dedupe });
t.equal(deduped.length, 0, 'does not dedupe');
}
})

0 comments on commit 7fbaee2

Please sign in to comment.