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

Fix exposed requires being persisted across bundles #1030

Merged
1 commit merged into from
Feb 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ Browserify.prototype._createDeps = function (opts) {
else if (opts.builtins && typeof opts.builtins === 'object') {
mopts.modules = opts.builtins;
}
else mopts.modules = builtins;
else mopts.modules = copy(builtins);

Object.keys(builtins).forEach(function (key) {
if (!has(mopts.modules, key)) self._exclude.push(key);
Expand Down
27 changes: 27 additions & 0 deletions test/require_expose.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
var browserify = require('../');
var test = require('tap').test;
var vm = require('vm');

test('exposed modules do not leak across bundles', function (t) {
var bundle1, bundle2;

bundle1 = browserify();
bundle1.add(__dirname + '/require_expose/main.js');
bundle1.require(__dirname + '/require_expose/some_dep.js', { expose: 'foo' });

bundle1.bundle(function (err, src) {
if (err) t.fail(err);

var c = {};
vm.runInNewContext(src, c);
t.equal(c.foo, 'some_dep');

bundle2 = browserify();
bundle2.add(__dirname + '/require_expose/main.js');

bundle2.bundle(function (err) {
t.ok(err && err.message.match(/Cannot find module 'foo'/), 'should fail with missing module');
t.end();
});
});
});
1 change: 1 addition & 0 deletions test/require_expose/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo = require('foo');
1 change: 1 addition & 0 deletions test/require_expose/some_dep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 'some_dep';