diff --git a/lib/util/customConfig.js b/lib/util/customConfig.js index 1ab15994..ccc4dc92 100644 --- a/lib/util/customConfig.js +++ b/lib/util/customConfig.js @@ -12,10 +12,9 @@ try { } const CHECK_REFRESH_RATE = 1_000; -let previousConfig = null; let lastCheck = null; -let mergedConfig = null; -let lastModifiedDate = null; +let mergedConfig = new Map(); +let lastModifiedDate = new Map(); /** * @see https://stackoverflow.com/questions/9210542/node-js-require-cache-possible-to-invalidate @@ -48,9 +47,9 @@ function loadConfig(config) { if (stats === null) { // Default to no config loadedConfig = {}; - } else if (lastModifiedDate !== mtime) { + } else if (lastModifiedDate.get(resolvedPath) !== mtime) { // Load the config based on path - lastModifiedDate = mtime; + lastModifiedDate.set(resolvedPath, mtime); loadedConfig = requireUncached(resolvedPath); } else { // Unchanged config @@ -70,31 +69,19 @@ function loadConfig(config) { } } -function convertConfigToString(config) { - switch (typeof config) { - case 'string': - return config; - case 'object': - return JSON.stringify(config); - default: - return config.toString(); - } -} - function resolve(twConfig) { - const newConfig = convertConfigToString(twConfig) !== convertConfigToString(previousConfig); + const newConfig = mergedConfig.get(twConfig) === undefined; const now = Date.now(); const expired = now - lastCheck > CHECK_REFRESH_RATE; if (newConfig || expired) { - previousConfig = twConfig; lastCheck = now; const userConfig = loadConfig(twConfig); // userConfig is null when config file was not modified if (userConfig !== null) { - mergedConfig = resolveConfig(userConfig); + mergedConfig.set(twConfig, resolveConfig(userConfig)); } } - return mergedConfig; + return mergedConfig.get(twConfig); } module.exports = {