Skip to content

Commit

Permalink
Check if regex and regex.test is available before calling it (#608)
Browse files Browse the repository at this point in the history
* Check if regex and regex.test is available before calling it

* If the json loader test is a function, execute it

* rename loader to matcher
  • Loading branch information
kitze authored and arunoda committed Nov 9, 2016
1 parent 4f42aeb commit 1711fd5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
12 changes: 10 additions & 2 deletions dist/server/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,16 @@ var logger = console;

function addJsonLoaderIfNotAvailable(config) {
var jsonLoaderExists = config.module.loaders.reduce(function (value, loader) {
return value || [].concat(loader.test).some(function (regex) {
return regex.test('my_package.json');
return value || [].concat(loader.test).some(function (matcher) {
var isRegex = matcher instanceof RegExp;
var testString = 'my_package.json';
if (isRegex) {
return matcher.test(testString);
}
if (typeof matcher === 'function') {
return matcher(testString);
}
return false;
});
}, false);

Expand Down
12 changes: 11 additions & 1 deletion src/server/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,17 @@ const logger = console;
export function addJsonLoaderIfNotAvailable(config) {
const jsonLoaderExists = config.module.loaders.reduce(
(value, loader) => {
return value || [].concat(loader.test).some(regex => regex.test('my_package.json'));
return value || [].concat(loader.test).some((matcher) => {
const isRegex = matcher instanceof RegExp;
const testString = 'my_package.json';
if (isRegex) {
return matcher.test(testString);
}
if (typeof matcher === 'function') {
return matcher(testString);
}
return false;
});
},
false
);
Expand Down

0 comments on commit 1711fd5

Please sign in to comment.