Socket
Socket
Sign inDemoInstall

eslint-module-utils

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-module-utils - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

ModuleCache.js

2

package.json
{
"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 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc