Skip to content
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

Update to 2.29.1 #1

Merged
merged 29 commits into from Sep 9, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8d4a241
Use transforms with --deps and --list flags.
hughsk Jul 20, 2013
83c2800
2.25.1
invalid-email-address Jul 25, 2013
d0f3657
bump browser-pack for web workers
invalid-email-address Aug 2, 2013
901c665
2.26.0
invalid-email-address Aug 2, 2013
c8a4340
Allow arbitrary external ids
jmreidy Aug 15, 2013
bd146cf
2.27.0
invalid-email-address Aug 15, 2013
62a7b66
Merge branch 'master' of github.com:substack/node-browserify
invalid-email-address Aug 15, 2013
edc3c3f
-x works again for non-core module names
invalid-email-address Aug 15, 2013
860c95f
fix for external core module names
invalid-email-address Aug 15, 2013
b26e13d
filter deps for externals
invalid-email-address Aug 15, 2013
d89888b
external test passes
invalid-email-address Aug 15, 2013
cc2fb08
2.27.1
invalid-email-address Aug 15, 2013
b24fbc3
make `browserify -r events --standalone EventEmitter` work
invalid-email-address Aug 18, 2013
a0f2261
2.28.0
invalid-email-address Aug 18, 2013
9b6f2cb
hash test checks correct behavior for duplicate files
invalid-email-address Aug 25, 2013
a9b33cb
failing check for only 1 duplicate file included
invalid-email-address Aug 25, 2013
356bf6a
files with the same hash only included once
invalid-email-address Aug 25, 2013
ee84403
failing test for hash instances
invalid-email-address Aug 25, 2013
ef1589e
passing the hash instance test with a naive sameDeps() checker
invalid-email-address Aug 25, 2013
d62b317
update the reverse multi bundle test for hash matching to not depend …
invalid-email-address Aug 25, 2013
92b3092
passing hash instance context test dealing with single-level nested d…
invalid-email-address Aug 25, 2013
2ece486
a failing test for nested hash instance contexts
invalid-email-address Aug 25, 2013
63928d2
nested hash instance contexts test passes with a more sophisticated r…
invalid-email-address Aug 25, 2013
7d101ec
use stream-combiner directly instead of event-stream
invalid-email-address Aug 25, 2013
da4c2d6
2.29.0
invalid-email-address Aug 25, 2013
dc7c78e
Failing tests for sourcemaps on standalone builds.
noahmedling Sep 3, 2013
fc0f176
Standalone sourcemaps tests pass.
noahmedling Sep 3, 2013
1e5e0e9
2.29.1
invalid-email-address Sep 3, 2013
330476b
Merge branch 'refs/heads/substack'
alexgorbatchev Sep 9, 2013
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion bin/args.js
Expand Up @@ -27,6 +27,12 @@ module.exports = function (args) {
return path.resolve(process.cwd(), entry);
});

if (argv.s && entries.length === 0
&& [].concat(argv.r, argv.require).filter(Boolean).length === 1) {
entries.push([].concat(argv.r, argv.require).filter(Boolean)[0]);
argv.r = argv.require = [];
}

var b = browserify({
noParse: [].concat(argv.noparse).filter(Boolean),
entries: entries
Expand All @@ -50,7 +56,10 @@ module.exports = function (args) {

// resolve any external files and add them to the bundle as externals
[].concat(argv.x).concat(argv.external).filter(Boolean)
.forEach(function (x) { b.external(path.resolve(process.cwd(), x)) })
.forEach(function (x) {
if (/^[\/.]/.test(x)) b.external(path.resolve(process.cwd(), x))
else b.external(x)
})
;

[].concat(argv.t).concat(argv.transform).filter(Boolean)
Expand Down
6 changes: 4 additions & 2 deletions bin/cmd.js
Expand Up @@ -37,13 +37,15 @@ if (b.argv.pack) {

if (b.argv.deps) {
var stringify = JSONStream.stringify();
var d = b.deps({ packageFilter: packageFilter });
var t = [].concat(b.argv.t).concat(b.argv.transform);
var d = b.deps({ packageFilter: packageFilter, transform: t });
d.pipe(stringify).pipe(process.stdout);
return;
}

if (b.argv.list) {
var d = b.deps({ packageFilter: packageFilter });
var t = [].concat(b.argv.t).concat(b.argv.transform);
var d = b.deps({ packageFilter: packageFilter, transform: t });
d.pipe(through(function (dep) {
this.queue(dep.id + '\n');
})).pipe(process.stdout);
Expand Down
84 changes: 70 additions & 14 deletions index.js
@@ -1,6 +1,6 @@
var crypto = require('crypto');
var through = require('through');
var pipeline = require('event-stream').pipeline;
var pipeline = require('stream-combiner');
var concatStream = require('concat-stream');
var checkSyntax = require('syntax-error');
var parents = require('parents');
Expand All @@ -18,6 +18,8 @@ var inherits = require('inherits');
var EventEmitter = require('events').EventEmitter;
var fs = require('fs');

var emptyModulePath = path.join(__dirname, '_empty.js');

module.exports = function (opts) {
if (opts === undefined) opts = {};
if (typeof opts === 'string') opts = { entries: [ opts ] };
Expand Down Expand Up @@ -96,10 +98,12 @@ Browserify.prototype.require = function (id, opts) {
extensions: self._extensions
};
browserResolve(id, params, function (err, file) {
if (err) return self.emit('error', err);
if (!file) return self.emit('error', new Error(
'module ' + JSON.stringify(id) + ' not found in require()'
));
if ((err || !file) && !opts.external) {
if (err) return self.emit('error', err);
if (!file) return self.emit('error', new Error(
'module ' + JSON.stringify(id) + ' not found in require()'
));
}

if (opts.expose) {
self.exports[file] = hash(file);
Expand All @@ -109,9 +113,10 @@ Browserify.prototype.require = function (id, opts) {
self._mapped[opts.expose] = file;
}
}

if (opts.external) {
self._external[file] = true;
if (file) self._external[file] = true;
else self._external[id] = true;
}
else {
self.files.push(file);
Expand Down Expand Up @@ -247,6 +252,12 @@ Browserify.prototype.deps = function (opts) {
if (row.id === emptyModulePath) {
row.source = '';
}
row.deps = Object.keys(row.deps).reduce(function (acc, key) {
if (!self._external[key] && !self._external[row.id]) {
acc[key] = row.deps[key];
}
return acc;
}, {});

if (self._expose[row.id]) {
this.queue({
Expand Down Expand Up @@ -280,6 +291,7 @@ Browserify.prototype.pack = function (debug, standalone) {
var packer = browserPack({ raw: true });

var mainModule;
var hashes = {}, depList = {}, depHash = {};

var input = through(function (row_) {
var row = copy(row_);
Expand All @@ -289,6 +301,21 @@ Browserify.prototype.pack = function (debug, standalone) {
row.sourceFile = row.id;
}

var dup = hashes[row.hash];
if (dup && sameDeps(depList[dup._id], row.deps)) {
row.source = 'module.exports=require('
+ JSON.stringify(dup.id)
+ ')'
;
}
else if (dup) {
row.source = 'arguments[4]['
+ JSON.stringify(dup.id)
+ '][0].apply(exports,arguments)'
;
}
else hashes[row.hash] = { _id: row.id, id: getId(row) };

if (/^#!/.test(row.source)) row.source = '//' + row.source;
var err = checkSyntax(row.source, row.id);
if (err) return this.emit('error', err);
Expand Down Expand Up @@ -329,7 +356,7 @@ Browserify.prototype.pack = function (debug, standalone) {
var output = through(write, end);

var sort = depSorter({ index: true });
return pipeline(sort, input, packer, output);
return pipeline(through(hasher), sort, input, packer, output);

function write (buf) {
if (first) writePrelude.call(this);
Expand All @@ -340,7 +367,7 @@ Browserify.prototype.pack = function (debug, standalone) {
function end () {
if (first) writePrelude.call(this);
if (standalone) {
this.queue('(' + mainModule + ')' + umd.postlude(standalone));
this.queue('\n(' + mainModule + ')' + umd.postlude(standalone));
}
this.queue('\n;');
this.queue(null);
Expand All @@ -354,6 +381,29 @@ Browserify.prototype.pack = function (debug, standalone) {
if (!hasExports) return this.queue(';');
this.queue('require=');
}

function hasher (row) {
row.hash = hash(row.source);
depList[row.id] = row.deps;
depHash[row.id] = row.hash;
this.queue(row);
}

function sameDeps (a, b) {
var keys = Object.keys(a);
if (keys.length !== Object.keys(b).length) return false;

for (var i = 0; i < keys.length; i++) {
var k = keys[i], ka = a[k], kb = b[k];
var ha = depHash[ka];
var hb = depHash[kb];
var da = depList[ka];
var db = depList[kb];

if (ha !== hb || !sameDeps(da, db)) return false;
}
return true;
}
};

var packageFilter = function (info) {
Expand All @@ -364,7 +414,6 @@ var packageFilter = function (info) {
return info;
};

var emptyModulePath = require.resolve('./_empty');
Browserify.prototype._resolve = function (id, parent, cb) {
if (this._ignore[id]) return cb(null, emptyModulePath);
var self = this;
Expand Down Expand Up @@ -398,12 +447,19 @@ Browserify.prototype._resolve = function (id, parent, cb) {
parent.modules = browserBuiltins;
parent.extensions = self._extensions;

if (self._external[id]) return cb(null, emptyModulePath);

return browserResolve(id, parent, function(err, file, pkg) {
if (err) return cb(err);
if (!file) return cb(new Error('module '
+ JSON.stringify(id) + ' not found from '
+ JSON.stringify(parent.filename)
));
if (!file && (self._external[id] || self._external[file])) {
return cb(null, emptyModulePath);
}
else if (!file) {
return cb(new Error('module '
+ JSON.stringify(id) + ' not found from '
+ JSON.stringify(parent.filename)
));
}

if (self._ignore[file]) return cb(null, emptyModulePath);
if (self._external[file]) return result(file, pkg, true);
Expand Down
8 changes: 4 additions & 4 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "browserify",
"version": "2.25.0",
"version": "2.29.1",
"description": "browser-side require() the node way",
"main": "index.js",
"bin": {
Expand All @@ -20,13 +20,13 @@
"javascript"
],
"dependencies": {
"module-deps": "~1.0.1",
"browser-pack": "~0.9.4",
"module-deps": "~1.0.2",
"browser-pack": "~0.10.0",
"deps-sort": "~0.1.1",
"shell-quote": "~0.0.1",
"through": "~2.3.4",
"duplexer": "~0.1.1",
"event-stream": "~3.0.15",
"stream-combiner": "~0.0.2",
"concat-stream": "~1.0.0",
"insert-module-globals": "~1.2.0",
"syntax-error": "~0.0.0",
Expand Down
20 changes: 20 additions & 0 deletions test/external.js
@@ -0,0 +1,20 @@
var browserify = require('../');
var vm = require('vm');
var test = require('tap').test;

test('external', function (t) {
t.plan(2);

var b = browserify(__dirname + '/external/main.js');
b.external('freelist');
b.bundle(function (err, src) {
if (err) return t.fail(err);
vm.runInNewContext(
'function require (x) {'
+ 'if (x==="freelist") return function (n) { return n + 1000 }'
+ '}'
+ src,
{ t: t }
);
});
});
2 changes: 2 additions & 0 deletions test/external/main.js
@@ -0,0 +1,2 @@
t.equal(require('freelist')(5), 1005);
t.equal(require('./x.js')(6), 1016);
3 changes: 3 additions & 0 deletions test/external/x.js
@@ -0,0 +1,3 @@
var fl = require('freelist');

module.exports = function (n) { return fl(n) + 10 };
14 changes: 14 additions & 0 deletions test/hash.js
@@ -0,0 +1,14 @@
var browserify = require('../');
var vm = require('vm');
var test = require('tap').test;

test('hash', function (t) {
t.plan(3);

var b = browserify(__dirname + '/hash/main.js');
b.bundle(function (err, src) {
var c = { t: t };
t.equal(src.match(RegExp('// FILE CONTENTS', 'g')).length, 1);
vm.runInNewContext(src, c);
});
});
1 change: 1 addition & 0 deletions test/hash/foo/other.js
@@ -0,0 +1 @@
module.exports = 5;
2 changes: 2 additions & 0 deletions test/hash/foo/two.js
@@ -0,0 +1,2 @@
// FILE CONTENTS
module.exports = 111 * require('./other.js');
2 changes: 2 additions & 0 deletions test/hash/main.js
@@ -0,0 +1,2 @@
t.equal(require('./foo/two.js'), 555);
t.equal(require('./one.js'), 333);
2 changes: 2 additions & 0 deletions test/hash/one.js
@@ -0,0 +1,2 @@
// FILE CONTENTS
module.exports = 111 * require('./other.js');
1 change: 1 addition & 0 deletions test/hash/other.js
@@ -0,0 +1 @@
module.exports = 3;
14 changes: 14 additions & 0 deletions test/hash_instance.js
@@ -0,0 +1,14 @@
var browserify = require('../');
var vm = require('vm');
var test = require('tap').test;

test('hash instances', function (t) {
t.plan(6);

var b = browserify(__dirname + '/hash_instance/main.js');
b.bundle(function (err, src) {
var c = { t: t };
t.equal(src.match(RegExp('// abcdefg', 'g')).length, 1);
vm.runInNewContext(src, c);
});
});
3 changes: 3 additions & 0 deletions test/hash_instance/foo/two.js
@@ -0,0 +1,3 @@
// abcdefg
module.exports = Foo;
function Foo () {}
11 changes: 11 additions & 0 deletions test/hash_instance/main.js
@@ -0,0 +1,11 @@
var Foo1 = require('./one.js');
var Foo2 = require('./foo/two.js');

var f1 = new Foo1;
var f2 = new Foo2;

t.equal(Foo1, Foo2);
t.ok(f1 instanceof Foo1);
t.ok(f1 instanceof Foo2);
t.ok(f2 instanceof Foo1);
t.ok(f2 instanceof Foo2);
3 changes: 3 additions & 0 deletions test/hash_instance/one.js
@@ -0,0 +1,3 @@
// abcdefg
module.exports = Foo;
function Foo () {}
24 changes: 24 additions & 0 deletions test/hash_instance_context.js
@@ -0,0 +1,24 @@
var browserify = require('../');
var vm = require('vm');
var test = require('tap').test;

test('hash instances with hashed contexts', function (t) {
t.plan(17);

var b = browserify(__dirname + '/hash_instance_context/main.js');
b.bundle(function (err, src) {
var c = { t: t };
t.equal(src.match(RegExp('// FILE F ONE', 'g')).length, 1);
t.equal(src.match(RegExp('// FILE G ONE', 'g')).length, 2);

t.equal(src.match(RegExp('// FILE F TWO', 'g')).length, 1);
t.equal(src.match(RegExp('// FILE G TWO', 'g')).length, 1);
t.equal(src.match(RegExp('// FILE H TWO', 'g')).length, 2);

t.equal(src.match(RegExp('// FILE F THREE', 'g')).length, 1);
t.equal(src.match(RegExp('// FILE G THREE', 'g')).length, 1);
t.equal(src.match(RegExp('// FILE H THREE', 'g')).length, 1);

vm.runInNewContext(src, c);
});
});
17 changes: 17 additions & 0 deletions test/hash_instance_context/main.js
@@ -0,0 +1,17 @@
var A = require('./one/f.js');
var B = require('./one/dir/f.js');
t.notEqual(A, B);
t.equal(A(), 555);
t.equal(B(), 333);

var C = require('./two/f.js');
var D = require('./two/dir/f.js');
t.notEqual(C, D);
t.equal(C(), 555);
t.equal(D(), 333);

var E = require('./three/f.js');
var F = require('./three/dir/f.js');
t.equal(E, F);
t.equal(E(), 555);
t.equal(F(), 555);
3 changes: 3 additions & 0 deletions test/hash_instance_context/one/dir/f.js
@@ -0,0 +1,3 @@
// FILE F ONE
var G = require('./g.js');
module.exports = function () { return 111 * G };
2 changes: 2 additions & 0 deletions test/hash_instance_context/one/dir/g.js
@@ -0,0 +1,2 @@
// FILE G ONE
module.exports = 3
3 changes: 3 additions & 0 deletions test/hash_instance_context/one/f.js
@@ -0,0 +1,3 @@
// FILE F ONE
var G = require('./g.js');
module.exports = function () { return 111 * G };
2 changes: 2 additions & 0 deletions test/hash_instance_context/one/g.js
@@ -0,0 +1,2 @@
// FILE G ONE
module.exports = 5
3 changes: 3 additions & 0 deletions test/hash_instance_context/three/dir/f.js
@@ -0,0 +1,3 @@
// FILE F THREE
var G = require('./g.js');
module.exports = function () { return 111 * G };
2 changes: 2 additions & 0 deletions test/hash_instance_context/three/dir/g.js
@@ -0,0 +1,2 @@
// FILE G THREE
module.exports = require('./h.js') + 1;
2 changes: 2 additions & 0 deletions test/hash_instance_context/three/dir/h.js
@@ -0,0 +1,2 @@
// FILE H THREE
module.exports = 4
3 changes: 3 additions & 0 deletions test/hash_instance_context/three/f.js
@@ -0,0 +1,3 @@
// FILE F THREE
var G = require('./g.js');
module.exports = function () { return 111 * G };