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

Allow plugin load() to return empty string #1908

Merged
merged 2 commits into from
Jan 26, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ export default class Graph {
})
.then(source => {
if (typeof source === 'string') return source;
if (source && typeof source === 'object' && source.code) return source;
if (source && typeof source === 'object' && typeof source.code === 'string') return source;

// TODO report which plugin failed
error({
Expand Down
21 changes: 21 additions & 0 deletions test/function/samples/load-returns-empty-string/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
description: 'loaders are permitted to return the empty string',
options: {
plugins: [
{
load: function ( id ) {
if ( /foo\.js/.test( id ) ) {
return '';
}
}
},
{
load: function ( id ) {
if ( /bar\.js/.test( id ) ) {
return { code: '', map: null };
}
}
}
]
}
};
1 change: 1 addition & 0 deletions test/function/samples/load-returns-empty-string/bar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
throw new Error('should not be reached');
1 change: 1 addition & 0 deletions test/function/samples/load-returns-empty-string/foo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
throw new Error('should not be reached');
4 changes: 4 additions & 0 deletions test/function/samples/load-returns-empty-string/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import './foo.js';
import './bar.js';

assert(true);