Skip to content

Commit

Permalink
Merge pull request #254 from yp/master
Browse files Browse the repository at this point in the history
Consider also resolve.fallback while resolving modules with webpack
  • Loading branch information
benmosher committed Apr 22, 2016
2 parents e5480b7 + 8a920a9 commit d6b0ef6
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
### Added
- [`no-named-as-default-member`] to `warnings` canned config
- add [`no-extraneous-dependencies`] rule ([#241], thanks [@jfmengels])
- consider `resolve.fallback` config option in the webpack resolver ([#254])

## [1.5.0] - 2016-04-18
### Added
Expand Down Expand Up @@ -145,6 +146,7 @@ for info on changes for earlier releases.
[`no-named-as-default-member`]: ./docs/rules/no-named-as-default-member.md
[`no-extraneous-dependencies`]: ./docs/rules/no-extraneous-dependencies.md

[#254]: https://github.com/benmosher/eslint-plugin-import/pull/254
[#243]: https://github.com/benmosher/eslint-plugin-import/pull/243
[#241]: https://github.com/benmosher/eslint-plugin-import/pull/241
[#239]: https://github.com/benmosher/eslint-plugin-import/pull/239
Expand Down
7 changes: 7 additions & 0 deletions resolvers/webpack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ exports.resolve = function (source, file, settings) {
if (typeof rootPath === 'string') paths.push(rootPath)
else paths.push.apply(paths, rootPath)
}
// set fallback paths
var fallbackPath = get(webpackConfig, ['resolve', 'fallback'])
if (fallbackPath) {
if (typeof fallbackPath === 'string') paths.push(fallbackPath)
else paths.push.apply(paths, fallbackPath)
}


// otherwise, resolve "normally"
try {
Expand Down
28 changes: 28 additions & 0 deletions resolvers/webpack/test/fallback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var chai = require('chai')
, expect = chai.expect
, path = require('path')

var resolve = require('../index').resolve


var file = path.join(__dirname, 'files', 'src', 'dummy.js')

describe("fallback", function () {
it("works", function () {
expect(resolve('fb-module', file)).property('path')
.to.equal(path.join(__dirname, 'files', 'fallback', 'fb-module.js'))
})
it("really works", function () {
expect(resolve('jsx/some-fb-file', file)).property('path')
.to.equal(path.join(__dirname, 'files', 'fallback', 'jsx', 'some-fb-file.js'))
})
it("prefer root", function () {
expect(resolve('jsx/some-file', file)).property('path')
.to.equal(path.join(__dirname, 'files', 'src', 'jsx', 'some-file.js'))
})
it("supports definition as an array", function () {
expect(resolve('fb-module', file, { config: "webpack.array-root.config.js" }))
.property('path')
.to.equal(path.join(__dirname, 'files', 'fallback', 'fb-module.js'))
})
})
Empty file.
Empty file.
Empty file.
Empty file.
4 changes: 4 additions & 0 deletions resolvers/webpack/test/files/webpack.array-root.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ exports.resolve = {
path.join(__dirname, 'src'),
path.join(__dirname, 'bower_components'),
],
fallback: [
path.join(__dirname, 'fallback'),
path.join(__dirname, 'bower_components'),
],
}
1 change: 1 addition & 0 deletions resolvers/webpack/test/files/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {
},
modulesDirectories: ['node_modules', 'bower_components'],
root: path.join(__dirname, 'src'),
fallback: path.join(__dirname, 'fallback'),
},

externals: [
Expand Down

0 comments on commit d6b0ef6

Please sign in to comment.