Skip to content

Commit

Permalink
Webpack Resolver fix for case config is an array of functions (#1220)
Browse files Browse the repository at this point in the history
* Added test for plugin-webpack-resolver: webpack config is an array of functions

* plugin-webpack-resolver: handle case when webpack config is an array of functions

* Updated Changelog

* Updated call of webpack config function
  • Loading branch information
idudinov authored and benmosher committed Oct 25, 2018
1 parent b4a2f11 commit db471a8
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
5 changes: 5 additions & 0 deletions resolvers/webpack/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
10 changes: 9 additions & 1 deletion resolvers/webpack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down
11 changes: 11 additions & 0 deletions resolvers/webpack/test/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
})
})
43 changes: 43 additions & 0 deletions resolvers/webpack/test/files/webpack.function.config.multiple.js
Original file line number Diff line number Diff line change
@@ -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')
),
]),
],
}
}]

0 comments on commit db471a8

Please sign in to comment.