Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webpack Resolver fix for case config is an array of functions #1220

Merged
merged 4 commits into from
Oct 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
),
]),
],
}
}]