Skip to content

Commit

Permalink
fix(plug-in): use absolute paths to reference entry points
Browse files Browse the repository at this point in the history
Closes #52
  • Loading branch information
nikku committed Dec 20, 2014
1 parent 9d0fb16 commit bd0f38e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
13 changes: 11 additions & 2 deletions lib/bro.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,15 @@ function Bro(bundleFile) {
'transform', 'plugin', 'prebundle'
]));

if ('exposeAll' in browserifyOptions) {
log.warn('Overriding exposeAll=true. Ain\'t gonna work otherwise');
}

// we need exposeAll or browserify has huge issues getting file ids
// and requires (external and internal) right
browserifyOptions.exposeAll = true;


var w = watchify(browserify(browserifyOptions));

_.forEach(bopts.plugin, function(p) {
Expand Down Expand Up @@ -232,7 +241,7 @@ function Bro(bundleFile) {
log.debug('bundling');

files.forEach(function(f) {
w.require(f, { expose: path.relative(config.basePath, f) });
w.require(f);
});

w.bundle(function(err, content) {
Expand Down Expand Up @@ -276,7 +285,7 @@ function Bro(bundleFile) {
}

deferredBundle(function(err) {
done(err, 'require("' + escape(relativePath) + '");');
done(err, 'require("/' + relativePath + '");');
});
};

Expand Down
15 changes: 10 additions & 5 deletions test/spec/pluginSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,13 @@ function preprocess(bundle, testFiles, done) {
});
}

function expectedBundle(filename) {
return 'require("' + escape(path.relative('', filename)) + '");';
function expectedBundleFile(filename) {
return '/' + escape(path.relative('', filename));
}

function expectedBundle(filename) {
return 'require("' + expectedBundleFile(filename) + '");';
}

describe('bro', function() {

Expand Down Expand Up @@ -266,8 +269,8 @@ describe('bro', function() {
// bundle got created
var bundledFiles = unpack(bundleFile.bundled)
.map(function (row) { return row.id; });
expect(bundledFiles).to.contain(path.relative('', 'test/fixtures/c.js'));
expect(bundledFiles).to.contain(path.relative('', 'test/fixtures/b.js'));
expect(bundledFiles).to.contain(expectedBundleFile('test/fixtures/c.js'));
expect(bundledFiles).to.contain(expectedBundleFile('test/fixtures/b.js'));

// test file stub got created
expect(testFileB.bundled).to.eql(expectedBundle('test/fixtures/b.js'));
Expand Down Expand Up @@ -298,7 +301,7 @@ describe('bro', function() {
// bundle got passed through
var bundledFiles = unpack(bundleFile.bundled)
.map(function (row) { return row.id; });
expect(bundledFiles).to.contain(path.relative('', 'test/fixtures/b.js'));
expect(bundledFiles).to.contain(expectedBundleFile('test/fixtures/b.js'));

// test file got regenerated
expect(testFile.bundled).to.eql(expectedBundle('test/fixtures/b.js'));
Expand Down Expand Up @@ -547,6 +550,8 @@ describe('bro', function() {
// then
// bundle got created
expect(bundleFile.bundled).to.exist;
expect(bundleFile.bundled).to.contain('require(\'foobar\')');

done();
});
});
Expand Down

0 comments on commit bd0f38e

Please sign in to comment.