diff --git a/.gitignore b/.gitignore index 0bf60608a..818ef0756 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,7 @@ build/Release # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- node_modules !tests/**/node_modules/ +!resolvers/**/test/**/node_modules # Users Environment Variables .lock-wscript diff --git a/resolvers/webpack/CHANGELOG.md b/resolvers/webpack/CHANGELOG.md index 7b8f9a662..99a39b953 100644 --- a/resolvers/webpack/CHANGELOG.md +++ b/resolvers/webpack/CHANGELOG.md @@ -4,6 +4,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com). ## Unreleased +- Fix [#666] - only respect config and configIndex settings if not in a node_module ([#994]) ## 0.8.3 - 2017-06-23 ### Changed @@ -87,7 +88,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel ### Added - `interpret` configs (such as `.babel.js`). Thanks to [@gausie] for the initial PR ([#164], ages ago! 😅) and [@jquense] for tests ([#278]). - +[#994]: https://github.com/benmosher/eslint-plugin-import/pull/994 [#683]: https://github.com/benmosher/eslint-plugin-import/pull/683 [#572]: https://github.com/benmosher/eslint-plugin-import/pull/572 [#569]: https://github.com/benmosher/eslint-plugin-import/pull/569 @@ -102,6 +103,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel [#164]: https://github.com/benmosher/eslint-plugin-import/pull/164 [#681]: https://github.com/benmosher/eslint-plugin-import/issues/681 +[#666]: https://github.com/benmosher/eslint-plugin-import/issues/666 [#435]: https://github.com/benmosher/eslint-plugin-import/issues/435 [#411]: https://github.com/benmosher/eslint-plugin-import/issues/411 [#357]: https://github.com/benmosher/eslint-plugin-import/issues/357 diff --git a/resolvers/webpack/index.js b/resolvers/webpack/index.js index 42f9e9828..5927cf73e 100644 --- a/resolvers/webpack/index.js +++ b/resolvers/webpack/index.js @@ -15,13 +15,18 @@ var log = require('debug')('eslint-plugin-import:resolver:webpack') exports.interfaceVersion = 2 +/** + * Settings object + * @typedef {Object} settings + * @property {string} configPath the path to the webpack config + */ /** * Find the full path to 'source', given 'file' as a full reference path. * * resolveImport('./foo', '/Users/ben/bar.js') => '/Users/ben/foo.js' * @param {string} source - the module to resolve; i.e './some-module' * @param {string} file - the importing file's full path; i.e. '/usr/local/bin/file.js' - * TODO: take options as a third param, with webpack config file name + * @param {settings} settings - settings object * @return {string?} the resolved path to source, undefined if not resolved, or null * if resolved to a non-FS resource (i.e. script tag at page load) */ @@ -44,12 +49,16 @@ exports.resolve = function (source, file, settings) { } var webpackConfig - - var configPath = get(settings, 'config') - , configIndex = get(settings, 'config-index') + , configPath + , configIndex , packageDir - log('Config path from settings:', configPath) + // Only respect webpackConfig settings if not in a node_module + if (!~file.indexOf('/node_modules/')) { + configPath = get(settings, 'config') + configIndex = get(settings, 'config-index') + log('Config path from settings:', configPath) + } // see if we've got a config path, a config object, an array of config objects or a config function if (!configPath || typeof configPath === 'string') { diff --git a/resolvers/webpack/test/config.js b/resolvers/webpack/test/config.js index 42c5eca1f..2cbccd258 100644 --- a/resolvers/webpack/test/config.js +++ b/resolvers/webpack/test/config.js @@ -91,4 +91,16 @@ describe("config", function () { .and.equal(path.join(__dirname, 'files', 'some', 'goofy', 'path', 'foo.js')) }) + it("ignores config setting when resolving inside a dependency", function () { + const npmModulePath = path.resolve(__dirname, 'files', 'node_modules', 'some-module') + const npmModuleFile = path.resolve(npmModulePath, 'foo.js') + + // Repeat of test against foo alias, for a control + // (Without this, if the alias was changed, this test would silently regress) + expect(resolve('foo', file, absoluteSettings)).to.have.property('path') + .and.equal(path.join(__dirname, 'files', 'some', 'absolutely', 'goofy', 'path', 'foo.js')) + // Actual test + expect(resolve('foo', npmModuleFile, absoluteSettings)).to.have.property('found') + .and.equal(false) + }) }) diff --git a/resolvers/webpack/test/files/node_modules/some-module/package.json b/resolvers/webpack/test/files/node_modules/some-module/package.json new file mode 100644 index 000000000..e69de29bb