Skip to content

Commit db471a8

Browse files
idudinovbenmosher
authored andcommitted
Webpack Resolver fix for case config is an array of functions (#1220)
* 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
1 parent b4a2f11 commit db471a8

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

resolvers/webpack/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
44
This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com).
55

66
## Unreleased
7+
### Fixed
8+
- crash when webpack config is an array of functions ([#1219]/[#1220] by [@idudinov])
79

810
## 0.10.1 - 2018-06-24
911
### Fixed
@@ -104,6 +106,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
104106
- `interpret` configs (such as `.babel.js`).
105107
Thanks to [@gausie] for the initial PR ([#164], ages ago! 😅) and [@jquense] for tests ([#278]).
106108

109+
[#1220]: https://github.com/benmosher/eslint-plugin-import/pull/1220
107110
[#1091]: https://github.com/benmosher/eslint-plugin-import/pull/1091
108111
[#969]: https://github.com/benmosher/eslint-plugin-import/pull/969
109112
[#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
121124
[#181]: https://github.com/benmosher/eslint-plugin-import/pull/181
122125
[#164]: https://github.com/benmosher/eslint-plugin-import/pull/164
123126

127+
[#1219]: https://github.com/benmosher/eslint-plugin-import/issues/1219
124128
[#788]: https://github.com/benmosher/eslint-plugin-import/issues/788
125129
[#767]: https://github.com/benmosher/eslint-plugin-import/issues/767
126130
[#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
147151
[@SkeLLLa]: https://github.com/SkeLLLa
148152
[@graingert]: https://github.com/graingert
149153
[@mattkrick]: https://github.com/mattkrick
154+
[@idudinov]: https://github.com/idudinov

resolvers/webpack/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,18 @@ exports.resolve = function (source, file, settings) {
8787
}
8888

8989
if (typeof webpackConfig === 'function') {
90-
webpackConfig = webpackConfig(env)
90+
webpackConfig = webpackConfig(env, {})
9191
}
9292

9393
if (Array.isArray(webpackConfig)) {
94+
webpackConfig = webpackConfig.map(cfg => {
95+
if (typeof cfg === 'function') {
96+
return cfg(env, {})
97+
}
98+
99+
return cfg
100+
})
101+
94102
if (typeof configIndex !== 'undefined' && webpackConfig.length > configIndex) {
95103
webpackConfig = webpackConfig[configIndex]
96104
}

resolvers/webpack/test/config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,15 @@ describe("config", function () {
103103
.and.equal(path.join(__dirname, 'files', 'some', 'goofy', 'path', 'bar.js'))
104104
})
105105

106+
it('finds the config at option env when config is an array of functions', function() {
107+
var settings = {
108+
config: require(path.join(__dirname, './files/webpack.function.config.multiple.js')),
109+
env: {
110+
dummy: true,
111+
},
112+
}
113+
114+
expect(resolve('bar', file, settings)).to.have.property('path')
115+
.and.equal(path.join(__dirname, 'files', 'some', 'goofy', 'path', 'bar.js'))
116+
})
106117
})
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
var path = require('path')
2+
var pluginsTest = require('webpack-resolver-plugin-test')
3+
4+
module.exports = [function(env) {
5+
return {
6+
resolve: {
7+
alias: {
8+
'foo': path.join(__dirname, 'some', 'goofy', 'path', 'foo.js'),
9+
'bar': env ? path.join(__dirname, 'some', 'goofy', 'path', 'bar.js') : undefined,
10+
'some-alias': path.join(__dirname, 'some'),
11+
},
12+
modules: [
13+
path.join(__dirname, 'src'),
14+
path.join(__dirname, 'fallback'),
15+
'node_modules',
16+
'bower_components',
17+
],
18+
modulesDirectories: ['node_modules', 'bower_components'],
19+
root: path.join(__dirname, 'src'),
20+
fallback: path.join(__dirname, 'fallback'),
21+
},
22+
23+
externals: [
24+
{ 'jquery': 'jQuery' },
25+
'bootstrap',
26+
function (context, request, callback) {
27+
if (request === 'underscore') {
28+
return callback(null, 'underscore')
29+
}
30+
callback()
31+
},
32+
],
33+
34+
plugins: [
35+
new pluginsTest.ResolverPlugin([
36+
new pluginsTest.SimpleResolver(
37+
path.join(__dirname, 'some', 'bar', 'bar.js'),
38+
path.join(__dirname, 'some', 'bar')
39+
),
40+
]),
41+
],
42+
}
43+
}]

0 commit comments

Comments
 (0)