From ac436ced51f924983443c9328d1ab792bb1f4175 Mon Sep 17 00:00:00 2001 From: kitze Date: Tue, 8 Nov 2016 13:26:29 +0100 Subject: [PATCH 1/3] Check if regex and regex.test is available before calling it --- dist/server/config.js | 2 +- src/server/config.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/server/config.js b/dist/server/config.js index 7f108488d202..5b99e05ca596 100644 --- a/dist/server/config.js +++ b/dist/server/config.js @@ -99,7 +99,7 @@ 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 regex && regex.test && regex.test('my_package.json'); }); }, false); diff --git a/src/server/config.js b/src/server/config.js index 84cba3cd3d34..ec0c6c78de92 100644 --- a/src/server/config.js +++ b/src/server/config.js @@ -11,7 +11,7 @@ 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(regex => regex && regex.test && regex.test('my_package.json')); }, false ); From 6ef4ad36159c77770065cb7d18ec0a053d510fff Mon Sep 17 00:00:00 2001 From: kitze Date: Tue, 8 Nov 2016 14:07:14 +0100 Subject: [PATCH 2/3] If the json loader test is a function, execute it --- dist/server/config.js | 12 ++++++++++-- src/server/config.js | 12 +++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/dist/server/config.js b/dist/server/config.js index 5b99e05ca596..0068393f5604 100644 --- a/dist/server/config.js +++ b/dist/server/config.js @@ -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 && regex.test && regex.test('my_package.json'); + return value || [].concat(loader.test).some(function (loader) { + var isRegex = loader instanceof RegExp; + var testString = 'my_package.json'; + if (isRegex) { + return loader.test(testString); + } + if (typeof loader === 'function') { + return loader(testString); + } + return false; }); }, false); diff --git a/src/server/config.js b/src/server/config.js index ec0c6c78de92..b5a7db686651 100644 --- a/src/server/config.js +++ b/src/server/config.js @@ -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 && regex.test && regex.test('my_package.json')); + return value || [].concat(loader.test).some((loader) => { + const isRegex = loader instanceof RegExp; + const testString = 'my_package.json'; + if (isRegex) { + return loader.test(testString); + } + if (typeof loader === 'function') { + return loader(testString); + } + return false; + }); }, false ); From a86a5f3f80a0b323676fbf33505f6503486678a4 Mon Sep 17 00:00:00 2001 From: kitze Date: Wed, 9 Nov 2016 10:29:25 +0100 Subject: [PATCH 3/3] rename loader to matcher --- dist/server/config.js | 10 +++++----- src/server/config.js | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/dist/server/config.js b/dist/server/config.js index 0068393f5604..6e040f40d98a 100644 --- a/dist/server/config.js +++ b/dist/server/config.js @@ -98,14 +98,14 @@ var logger = console; function addJsonLoaderIfNotAvailable(config) { var jsonLoaderExists = config.module.loaders.reduce(function (value, loader) { - return value || [].concat(loader.test).some(function (loader) { - var isRegex = loader instanceof RegExp; + return value || [].concat(loader.test).some(function (matcher) { + var isRegex = matcher instanceof RegExp; var testString = 'my_package.json'; if (isRegex) { - return loader.test(testString); + return matcher.test(testString); } - if (typeof loader === 'function') { - return loader(testString); + if (typeof matcher === 'function') { + return matcher(testString); } return false; }); diff --git a/src/server/config.js b/src/server/config.js index b5a7db686651..6cc8b126d4bb 100644 --- a/src/server/config.js +++ b/src/server/config.js @@ -11,14 +11,14 @@ const logger = console; export function addJsonLoaderIfNotAvailable(config) { const jsonLoaderExists = config.module.loaders.reduce( (value, loader) => { - return value || [].concat(loader.test).some((loader) => { - const isRegex = loader instanceof RegExp; + return value || [].concat(loader.test).some((matcher) => { + const isRegex = matcher instanceof RegExp; const testString = 'my_package.json'; if (isRegex) { - return loader.test(testString); + return matcher.test(testString); } - if (typeof loader === 'function') { - return loader(testString); + if (typeof matcher === 'function') { + return matcher(testString); } return false; });