From ae0ed260d7f9469588f8fdeb50ff43f742c16df1 Mon Sep 17 00:00:00 2001 From: Bryce Kalow Date: Tue, 14 Nov 2017 00:44:48 -0600 Subject: [PATCH 1/2] Simplifies webpack config linting and adds webpack function config test --- .eslintignore | 2 +- test/index.spec.js | 8 +++++++- test/webpack.function.config.js | 13 +++++++++++++ ...lticompile.js => webpack.multicompile.config.js} | 3 +-- 4 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 test/webpack.function.config.js rename test/{webpack.multicompile.js => webpack.multicompile.config.js} (70%) diff --git a/.eslintignore b/.eslintignore index 19a8a9e..363a780 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +1,3 @@ test/fixtures/ test/*.config.js -test/*.config.babel.js \ No newline at end of file +test/*.config.babel.js diff --git a/test/index.spec.js b/test/index.spec.js index cdf3212..ed0b2df 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -105,7 +105,7 @@ test('should ignore empty object', t => { }); test('works with webpack configs that export an array, instead of a single object (multicompile mode)', t => { - const actual = transformFixture('multicompile/source.js', {config: './webpack.multicompile.js'}); + const actual = transformFixture('multicompile/source.js', {config: './webpack.multicompile.config.js'}); const expected = readFixture('multicompile/expected.js'); t.is(actual, expected); }); @@ -115,3 +115,9 @@ test('doesnt output extensions when noOutputExtension is set to true', t => { const expected = readFixture('no-extension/expected.js'); t.is(actual, expected); }); + +test('works with webpack configs that export function', t => { + const actual = transformFixture('basic/absolute.js', {config: './webpack.function.config.js'}); + const expected = readFixture('basic/expected.js'); + t.is(actual, expected); +}); diff --git a/test/webpack.function.config.js b/test/webpack.function.config.js new file mode 100644 index 0000000..e795087 --- /dev/null +++ b/test/webpack.function.config.js @@ -0,0 +1,13 @@ + +var path = require('path'); + +module.exports = function() { + return { + resolve: { + alias: { + 'my-absolute-test-lib': path.join(__dirname, 'assets/le-test-lib'), + 'same-folder-lib': path.resolve(__dirname, 'fixtures/basic') + } + } + }; +}; diff --git a/test/webpack.multicompile.js b/test/webpack.multicompile.config.js similarity index 70% rename from test/webpack.multicompile.js rename to test/webpack.multicompile.config.js index d5863ff..d5b5661 100644 --- a/test/webpack.multicompile.js +++ b/test/webpack.multicompile.config.js @@ -1,7 +1,6 @@ -var path = require('path'); // eslint-disable-line no-var, import/no-commonjs +var path = require('path'); -// eslint-disable-next-line import/no-commonjs module.exports = [{ resolve: { alias: { From 1fd34aa0c56cdea4937f98aa32ec6a6d23845af8 Mon Sep 17 00:00:00 2001 From: Bryce Kalow Date: Tue, 14 Nov 2017 00:45:09 -0600 Subject: [PATCH 2/2] Adds support for configurations that are functions --- src/index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/index.js b/src/index.js index 7af48b3..aeb3787 100644 --- a/src/index.js +++ b/src/index.js @@ -68,6 +68,11 @@ export default function({ types: t }) { // Require the config let conf = require(confPath); + // if the configuration expots a function, invoke it + if (typeof conf === 'function') { + conf = conf(); + } + // if the object is empty, we might be in a dependency of the config - bail without warning if (!Object.keys(conf).length) { return;