diff --git a/resolvers/webpack/CHANGELOG.md b/resolvers/webpack/CHANGELOG.md index 93246bf0b..8ea232a3b 100644 --- a/resolvers/webpack/CHANGELOG.md +++ b/resolvers/webpack/CHANGELOG.md @@ -4,6 +4,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com). ## Unreleased +### Fixed +- crash when webpack config is an array of functions ([#1219]/[#1220] by [@idudinov]) ## 0.10.1 - 2018-06-24 ### Fixed @@ -104,6 +106,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel - `interpret` configs (such as `.babel.js`). Thanks to [@gausie] for the initial PR ([#164], ages ago! 😅) and [@jquense] for tests ([#278]). +[#1220]: https://github.com/benmosher/eslint-plugin-import/pull/1220 [#1091]: https://github.com/benmosher/eslint-plugin-import/pull/1091 [#969]: https://github.com/benmosher/eslint-plugin-import/pull/969 [#968]: https://github.com/benmosher/eslint-plugin-import/pull/968 @@ -121,6 +124,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel [#181]: https://github.com/benmosher/eslint-plugin-import/pull/181 [#164]: https://github.com/benmosher/eslint-plugin-import/pull/164 +[#1219]: https://github.com/benmosher/eslint-plugin-import/issues/1219 [#788]: https://github.com/benmosher/eslint-plugin-import/issues/788 [#767]: https://github.com/benmosher/eslint-plugin-import/issues/767 [#681]: https://github.com/benmosher/eslint-plugin-import/issues/681 @@ -147,3 +151,4 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel [@SkeLLLa]: https://github.com/SkeLLLa [@graingert]: https://github.com/graingert [@mattkrick]: https://github.com/mattkrick +[@idudinov]: https://github.com/idudinov diff --git a/resolvers/webpack/index.js b/resolvers/webpack/index.js index 4c9abc61d..b1b0e45f6 100644 --- a/resolvers/webpack/index.js +++ b/resolvers/webpack/index.js @@ -87,10 +87,18 @@ exports.resolve = function (source, file, settings) { } if (typeof webpackConfig === 'function') { - webpackConfig = webpackConfig(env) + webpackConfig = webpackConfig(env, {}) } if (Array.isArray(webpackConfig)) { + webpackConfig = webpackConfig.map(cfg => { + if (typeof cfg === 'function') { + return cfg(env, {}) + } + + return cfg + }) + if (typeof configIndex !== 'undefined' && webpackConfig.length > configIndex) { webpackConfig = webpackConfig[configIndex] } diff --git a/resolvers/webpack/test/config.js b/resolvers/webpack/test/config.js index 2519daf8a..16a4a6dda 100644 --- a/resolvers/webpack/test/config.js +++ b/resolvers/webpack/test/config.js @@ -103,4 +103,15 @@ describe("config", function () { .and.equal(path.join(__dirname, 'files', 'some', 'goofy', 'path', 'bar.js')) }) + it('finds the config at option env when config is an array of functions', function() { + var settings = { + config: require(path.join(__dirname, './files/webpack.function.config.multiple.js')), + env: { + dummy: true, + }, + } + + expect(resolve('bar', file, settings)).to.have.property('path') + .and.equal(path.join(__dirname, 'files', 'some', 'goofy', 'path', 'bar.js')) + }) }) diff --git a/resolvers/webpack/test/files/webpack.function.config.multiple.js b/resolvers/webpack/test/files/webpack.function.config.multiple.js new file mode 100644 index 000000000..4dbc94bbc --- /dev/null +++ b/resolvers/webpack/test/files/webpack.function.config.multiple.js @@ -0,0 +1,43 @@ +var path = require('path') +var pluginsTest = require('webpack-resolver-plugin-test') + +module.exports = [function(env) { + return { + resolve: { + alias: { + 'foo': path.join(__dirname, 'some', 'goofy', 'path', 'foo.js'), + 'bar': env ? path.join(__dirname, 'some', 'goofy', 'path', 'bar.js') : undefined, + 'some-alias': path.join(__dirname, 'some'), + }, + modules: [ + path.join(__dirname, 'src'), + path.join(__dirname, 'fallback'), + 'node_modules', + 'bower_components', + ], + modulesDirectories: ['node_modules', 'bower_components'], + root: path.join(__dirname, 'src'), + fallback: path.join(__dirname, 'fallback'), + }, + + externals: [ + { 'jquery': 'jQuery' }, + 'bootstrap', + function (context, request, callback) { + if (request === 'underscore') { + return callback(null, 'underscore') + } + callback() + }, + ], + + plugins: [ + new pluginsTest.ResolverPlugin([ + new pluginsTest.SimpleResolver( + path.join(__dirname, 'some', 'bar', 'bar.js'), + path.join(__dirname, 'some', 'bar') + ), + ]), + ], + } +}]