-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Fix: ensure configs from a plugin are cached separately (fixes #8792) #8798
Changes from 1 commit
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 |
---|---|---|
|
@@ -29,31 +29,31 @@ function hash(vector) { | |
class ConfigCache { | ||
|
||
constructor() { | ||
this.filePathCache = new Map(); | ||
this.configFullNameCache = new Map(); | ||
this.localHierarchyCache = new Map(); | ||
this.mergedVectorCache = new Map(); | ||
this.mergedCache = new Map(); | ||
} | ||
|
||
/** | ||
* Gets a config object from the cache for the specified config file path. | ||
* @param {string} configFilePath the absolute path to the config file | ||
* @param {string} configFullName the absolute path to the config file | ||
* @returns {Object|null} config object, if found in the cache, otherwise null | ||
* @private | ||
*/ | ||
getConfig(configFilePath) { | ||
return this.filePathCache.get(configFilePath); | ||
getConfig(configFullName) { | ||
return this.configFullNameCache.get(configFullName); | ||
} | ||
|
||
/** | ||
* Sets a config object in the cache for the specified config file path. | ||
* @param {string} configFilePath the absolute path to the config file | ||
* @param {string} configFullName the absolute path to the config file | ||
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. Could this line be updated to match lib/config/config-file.js lines 491-492? |
||
* @param {Object} config the config object to add to the cache | ||
* @returns {void} | ||
* @private | ||
*/ | ||
setConfig(configFilePath, config) { | ||
this.filePathCache.set(configFilePath, config); | ||
setConfig(configFullName, config) { | ||
this.configFullNameCache.set(configFullName, config); | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -488,12 +488,15 @@ function normalizePackageName(name, prefix) { | |
* @returns {Object} An object containing 3 properties: | ||
* - 'filePath' (required) the resolved path that can be used directly to load the configuration. | ||
* - 'configName' the name of the configuration inside the plugin. | ||
* - 'configFullName' the name of the configuration as used in the eslint config (e.g. 'plugin:node/recommended'). | ||
* - 'configFullName' (required) the name of the configuration as used in the eslint config(e.g. 'plugin:node/recommended'), | ||
* or the absolute path to a config file. This should uniquely identify a config. | ||
* @private | ||
*/ | ||
function resolve(filePath, relativeTo) { | ||
if (isFilePath(filePath)) { | ||
return { filePath: path.resolve(relativeTo || "", filePath) }; | ||
const fullPath = path.resolve(relativeTo || "", filePath); | ||
|
||
return { filePath: fullPath, configFullName: fullPath }; | ||
} | ||
let normalizedPackageName; | ||
|
||
|
@@ -510,7 +513,7 @@ function resolve(filePath, relativeTo) { | |
normalizedPackageName = normalizePackageName(filePath, "eslint-config"); | ||
debug(`Attempting to resolve ${normalizedPackageName}`); | ||
filePath = resolver.resolve(normalizedPackageName, getLookupPath(relativeTo)); | ||
return { filePath }; | ||
return { filePath, configFullName: filePath }; | ||
|
||
|
||
} | ||
|
@@ -524,7 +527,7 @@ function resolve(filePath, relativeTo) { | |
function loadFromDisk(resolvedPath, configContext) { | ||
const dirname = path.dirname(resolvedPath.filePath), | ||
lookupPath = getLookupPath(dirname); | ||
let config = loadConfigFile(resolvedPath); | ||
let config = loadConfigFile(resolvedPath, configContext); | ||
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.
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. Oops, this was unintentional, thanks. While working on this I initially considered adding a second argument to |
||
|
||
if (config) { | ||
|
||
|
@@ -579,7 +582,7 @@ function loadObject(configObject) { | |
function load(filePath, configContext, relativeTo) { | ||
const resolvedPath = resolve(filePath, relativeTo); | ||
|
||
const cachedConfig = configContext.configCache.getConfig(resolvedPath.filePath); | ||
const cachedConfig = configContext.configCache.getConfig(resolvedPath.configFullName); | ||
|
||
if (cachedConfig) { | ||
return cachedConfig; | ||
|
@@ -590,7 +593,7 @@ function load(filePath, configContext, relativeTo) { | |
if (config) { | ||
config.filePath = resolvedPath.filePath; | ||
config.baseDirectory = path.dirname(resolvedPath.filePath); | ||
configContext.configCache.setConfig(resolvedPath.filePath, config); | ||
configContext.configCache.setConfig(resolvedPath.configFullName, config); | ||
} | ||
|
||
return config; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
extends: | ||
- plugin:test/foo | ||
- plugin:test/bar |
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.
Could this line be updated to match lib/config/config-file.js lines 491-492?