Skip to content

Commit

Permalink
Fix error when dynamic importing js files which imports raw files (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcioj authored and devongovett committed Dec 11, 2017
1 parent d17dccc commit dc52638
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/builtins/bundle-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ function loadBundle(bundle) {
}

var type = bundle.match(/\.(.+)$/)[1].toLowerCase();
return bundles[bundle] = bundleLoaders[type](getBundleURL() + bundle);
var bundleLoader = bundleLoaders[type];
if (bundleLoader) {
return bundles[bundle] = bundleLoader(getBundleURL() + bundle);
}
}

function loadJSBundle(bundle) {
Expand Down
7 changes: 7 additions & 0 deletions test/integration/dynamic-references-raw/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var local = import('./local');

module.exports = function () {
return local.then(function (l) {
return l.a + l.b;
});
};
4 changes: 4 additions & 0 deletions test/integration/dynamic-references-raw/local.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import raw from './test.txt';

exports.a = 1;
exports.b = 2;
1 change: 1 addition & 0 deletions test/integration/dynamic-references-raw/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
raw file
21 changes: 21 additions & 0 deletions test/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,27 @@ describe('javascript', function() {
assert.equal(await output(), 3);
});

it('should dynamic import files which import raw files', async function() {
let b = await bundle(
__dirname + '/integration/dynamic-references-raw/index.js'
);

assertBundleTree(b, {
name: 'index.js',
assets: ['index.js', 'bundle-loader.js', 'bundle-url.js'],
childBundles: [
{
assets: ['local.js', 'test.txt'],
childBundles: ['test.txt']
}
]
});

let output = run(b);
assert.equal(typeof output, 'function');
assert.equal(await output(), 3);
});

it('should return all exports as an object when using ES modules', async function() {
let b = await bundle(__dirname + '/integration/dynamic-esm/index.js');

Expand Down

0 comments on commit dc52638

Please sign in to comment.