Skip to content

Commit

Permalink
Merge pull request #439 from benmosher/issue-411-externals-context
Browse files Browse the repository at this point in the history
externals context
  • Loading branch information
benmosher committed Jul 14, 2016
2 parents 6fbb3eb + 6545cbf commit 8adfd2a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 7 additions & 0 deletions resolvers/webpack/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ All notable changes to this resolver will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com).

## Unreleased
### Fixed
- provide string `context` to `externals` functions ([#411] + [#413], thanks [@Satyam])

## 0.3.2 - 2016-06-30
### Added
- shared config ([config.js](./config.js)) with barebones settings needed to use this resolver. ([#283])
Expand Down Expand Up @@ -38,13 +42,15 @@ 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]).

[#413]: https://github.com/benmosher/eslint-plugin-import/pull/413
[#363]: https://github.com/benmosher/eslint-plugin-import/pull/363
[#289]: https://github.com/benmosher/eslint-plugin-import/pull/289
[#287]: https://github.com/benmosher/eslint-plugin-import/pull/287
[#278]: https://github.com/benmosher/eslint-plugin-import/pull/278
[#181]: https://github.com/benmosher/eslint-plugin-import/pull/181
[#164]: https://github.com/benmosher/eslint-plugin-import/pull/164

[#411]: https://github.com/benmosher/eslint-plugin-import/issues/411
[#357]: https://github.com/benmosher/eslint-plugin-import/issues/357
[#286]: https://github.com/benmosher/eslint-plugin-import/issues/286
[#283]: https://github.com/benmosher/eslint-plugin-import/issues/283
Expand All @@ -55,3 +61,4 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
[@GreenGremlin]: https://github.com/GreenGremlin
[@daltones]: https://github.com/daltones
[@kesne]: https://github.com/kesne
[@Satyam]: https://github.com/Satyam
10 changes: 5 additions & 5 deletions resolvers/webpack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ exports.resolve = function (source, file, settings) {
log('Using config: ', webpackConfig)

// externals
if (findExternal(source, webpackConfig.externals)) return { found: true, path: null }
if (findExternal(source, webpackConfig.externals, path.dirname(file))) return { found: true, path: null }


// otherwise, resolve "normally"
Expand Down Expand Up @@ -154,15 +154,15 @@ function makeRootPlugin(name, root) {
}
/* eslint-enable */

function findExternal(source, externals) {
function findExternal(source, externals, context) {
if (!externals) return false

// string match
if (typeof externals === 'string') return (source === externals)

// array: recurse
if (externals instanceof Array) {
return externals.some(function (e) { return findExternal(source, e) })
return externals.some(function (e) { return findExternal(source, e, context) })
}

if (externals instanceof RegExp) {
Expand All @@ -171,11 +171,11 @@ function findExternal(source, externals) {

if (typeof externals === 'function') {
var functionExternalFound = false
externals.call(null, null, source, function(err, value) {
externals.call(null, context, source, function(err, value) {
if (err) {
functionExternalFound = false
} else {
functionExternalFound = findExternal(source, value)
functionExternalFound = findExternal(source, value, context)
}
})
return functionExternalFound
Expand Down

0 comments on commit 8adfd2a

Please sign in to comment.