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

Make sure entry paths are always full paths #1248

Merged
1 commit merged into from
May 6, 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 bin/args.js
Expand Up @@ -61,7 +61,7 @@ module.exports = function (args, opts) {
s.resume();
return rs;
}
return path.resolve(process.cwd(), entry);
return entry;
});

if (argv.node) {
Expand Down
6 changes: 5 additions & 1 deletion index.js
Expand Up @@ -180,7 +180,11 @@ Browserify.prototype.require = function (file, opts) {
self._bpack.hasExports = true;
}

if (row.entry) row.order = self._entryOrder ++;
if (row.entry) {
row.file = path.resolve(basedir, row.file);
row.order = self._entryOrder ++;
}

if (opts.transform === false) row.transform = false;
self.pipeline.write(row);
return self;
Expand Down
25 changes: 24 additions & 1 deletion test/entry.js
Expand Up @@ -3,9 +3,32 @@ var vm = require('vm');
var test = require('tap').test;

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

var b = browserify(__dirname + '/entry/main.js');
b.on('dep', function(row) {
if (row.entry) t.equal(row.file, __dirname + '/entry/main.js');
});
b.bundle(function (err, src) {
var c = {
done : function (one, two) {
t.equal(one, 1);
t.equal(two, 2);
t.end();
}
};
vm.runInNewContext(src, c);
});
});

test('entry via add', function (t) {
t.plan(3);

var b = browserify();
b.add(__dirname + '/entry/main.js');
b.on('dep', function(row) {
if (row.entry) t.equal(row.file, __dirname + '/entry/main.js');
});
b.bundle(function (err, src) {
var c = {
done : function (one, two) {
Expand Down
42 changes: 42 additions & 0 deletions test/entry_relative.js
@@ -0,0 +1,42 @@
var browserify = require('../');
var vm = require('vm');
var test = require('tap').test;

test('entry - relative path', function (t) {
t.plan(3);

var b = browserify('entry/main.js');
b.on('dep', function(row) {
if (row.entry) t.equal(row.file, __dirname + '/entry/main.js');
});
b.bundle(function (err, src) {
var c = {
done : function (one, two) {
t.equal(one, 1);
t.equal(two, 2);
t.end();
}
};
vm.runInNewContext(src, c);
});
});

test('entry - relative path via add', function (t) {
t.plan(3);

var b = browserify({basedir: __dirname});
b.add('entry/main.js');
b.on('dep', function(row) {
if (row.entry) t.equal(row.file, __dirname + '/entry/main.js');
});
b.bundle(function (err, src) {
var c = {
done : function (one, two) {
t.equal(one, 1);
t.equal(two, 2);
t.end();
}
};
vm.runInNewContext(src, c);
});
});
22 changes: 19 additions & 3 deletions test/multi_entry.js
Expand Up @@ -10,14 +10,20 @@ var testFiles = [
];

test('multi entry', function (t) {
t.plan(3);
t.plan(6);

var b = browserify([
testFiles[0],
testFiles[1]
]);
b.add(testFiles[2]);


b.on('dep', function(row) {
if (row.entry) {
t.ok(testFiles.indexOf(row.file) > -1, 'should contain full entry path');
}
});

b.bundle(function (err, src) {
var c = {
times : 0,
Expand All @@ -28,7 +34,7 @@ test('multi entry', function (t) {
});

test('entries as streams', function (t) {
t.plan(3);
t.plan(6);

// transform paths to streams
for (var i = 0; i < testFiles.length; i++) {
Expand All @@ -44,6 +50,16 @@ test('entries as streams', function (t) {
], opts);
b.add(testFiles[2]);

b.on('dep', function(row) {
if (row.entry) {
t.similar(
row.file,
RegExp(__dirname + '/multi_entry/_stream_[\\d].js'),
'should be full entry path'
);
}
});

b.bundle(function (err, src) {
var c = {
times : 0,
Expand Down