Skip to content

Commit

Permalink
Make sure entry paths are always full paths
Browse files Browse the repository at this point in the history
  • Loading branch information
zertosh committed May 6, 2015
1 parent 0ad9b05 commit 5264f3a
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bin/args.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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

0 comments on commit 5264f3a

Please sign in to comment.