-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Don't respect config setting if in a node_module #994
base: main
Are you sure you want to change the base?
Changes from all commits
082663b
457342a
4681285
6989a3a
35970ae
f34cdde
415b002
8293c1e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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/')) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please never use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that is a pretty neat combo operator, but I agree with @ljharb 😁 |
||
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') { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm not sure why this is something we'd want to do. webpack config applies to every single JS file, potentially, including everything inside a node_modules directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That’s true, for rules, etc., but I wonder if it applies to aliases or other resolve configs, too? I would be surpsied since I can’t think why anyone would want to affect the module resolution within node_modules... and if webpack did do that then surely there would be tonnes of problems as a result..?
I’d also argue that since this is an eslint plugin, the user is never interested in node_modules, thus this change does not have an adverse affect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It applies to everything. Webpack is used all the time to modify the resolution of things within node_modules - Airbnb does it at times.
This eslint plugin checks across files - so it's interested in every JS file that's required/imported, full stop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, so is the only solution to resolve the path relative to the user’s project? I can’t see any obvious way to do that..