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

Consider also resolve.fallback while resolving modules with webpack #254

Merged
merged 5 commits into from
Apr 22, 2016
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
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