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

use same instance on symlinked modules #1318

Merged
1 commit merged into from
Jul 9, 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
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var readonly = require('read-only-stream');
module.exports = Browserify;
inherits(Browserify, EventEmitter);

var fs = require('fs');
var path = require('path');
var paths = {
empty: path.join(__dirname, 'lib/_empty.js')
Expand Down Expand Up @@ -481,7 +482,7 @@ Browserify.prototype._createDeps = function (opts) {
return cb(null, paths.empty, {});
}
}
cb(err, file, pkg);
cb(err, file && fs.realpathSync(file), pkg);
});
};

Expand Down
16 changes: 16 additions & 0 deletions test/symlink_dedupe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var browserify = require('../');
var vm = require('vm');
var test = require('tap').test;

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

var b = browserify(__dirname + '/symlink_dedupe/main.js');
b.bundle(function (err, buf) {
var c = { t: t };
var src = buf.toString('utf8');
t.equal(src.match(RegExp('// FILE F ONE', 'g')).length, 1);
t.equal(src.match(RegExp('// FILE G ONE', 'g')).length, 1);
vm.runInNewContext(src, c);
});
});
6 changes: 6 additions & 0 deletions test/symlink_dedupe/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var A = require('./one/f.js');
var B = require('./one/dir/f.js');
t.equal(A, B);
t.equal(A(), 555);
t.equal(B(), 555);

1 change: 1 addition & 0 deletions test/symlink_dedupe/one/dir
3 changes: 3 additions & 0 deletions test/symlink_dedupe/one/f.js
Original file line number Diff line number Diff line change
@@ -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/symlink_dedupe/one/g.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// FILE G ONE
module.exports = 5