eslint-module-utils
Advanced tools
Comparing version 0.2.0 to 0.2.1
{ | ||
"name": "eslint-module-utils", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Core utilities to support eslint-plugin-import and other module-related plugins.", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -8,2 +8,3 @@ "use strict" | ||
const hashObject = require('./hash').hashObject | ||
, ModuleCache = require('./ModuleCache').default | ||
@@ -13,18 +14,4 @@ const CASE_INSENSITIVE = fs.existsSync(path.join(__dirname, 'reSOLVE.js')) | ||
const fileExistsCache = new Map() | ||
const fileExistsCache = new ModuleCache() | ||
function cachePath(cacheKey, result) { | ||
fileExistsCache.set(cacheKey, { result, lastSeen: Date.now() }) | ||
} | ||
function checkCache(cacheKey, settings) { | ||
if (fileExistsCache.has(cacheKey)) { | ||
const f = fileExistsCache.get(cacheKey) | ||
// check fresness | ||
if (Date.now() - f.lastSeen < (settings.lifetime * 1000)) return f.result | ||
} | ||
// cache miss | ||
return undefined | ||
} | ||
// http://stackoverflow.com/a/27382838 | ||
@@ -34,3 +21,3 @@ function fileExistsWithCaseSync(filepath, cacheSettings) { | ||
let result = checkCache(filepath, cacheSettings) | ||
let result = fileExistsCache.get(filepath, cacheSettings) | ||
if (result != null) return result | ||
@@ -49,3 +36,3 @@ | ||
} | ||
cachePath(filepath, result) | ||
fileExistsCache.set(filepath, result) | ||
return result | ||
@@ -59,16 +46,9 @@ } | ||
const cacheSettings = Object.assign({ | ||
lifetime: 30, // seconds | ||
}, settings['import/cache']) | ||
const cacheSettings = ModuleCache.getSettings(settings) | ||
// parse infinity | ||
if (cacheSettings.lifetime === '∞' || cacheSettings.lifetime === 'Infinity') { | ||
cacheSettings.lifetime = Infinity | ||
} | ||
const cachedPath = checkCache(cacheKey, cacheSettings) | ||
const cachedPath = fileExistsCache.get(cacheKey, cacheSettings) | ||
if (cachedPath !== undefined) return cachedPath | ||
function cache(p) { | ||
cachePath(cacheKey, p) | ||
fileExistsCache.set(cacheKey, p) | ||
return p | ||
@@ -75,0 +55,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12092
9
371