Skip to content
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

feat: Add ESLINT_D_MAX_INSTANCES env variable. (#201) #232

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ It's possible to force `eslint_d` to only resolve local `eslint` by setting the
`ESLINT_D_LOCAL_ESLINT_ONLY` environment variable to a truthy value (ie. `true` or `1`).

To keep the memory footprint low, `eslint_d` keeps only the last 10 used
instances in the internal [nanolru][] cache.
instances in the internal [nanolru][] cache. To change the number of cached instances
set the `ESLINT_D_MAX_INSTANCES` environment variable to a positive integer.

## What if eslint or a plugin is updated?

Expand Down
20 changes: 19 additions & 1 deletion lib/caches.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,25 @@ const resolver = require('./resolver');
const eslint_path = require('./eslint-path');
const files_hash = require('./files-hash');

const lru_cache = new LRU(10);
// Setup LRU cache + error checking user config.
// 10 by default unless ESLINT_D_MAX_INSTANCES env variable is set.
const { ESLINT_D_MAX_INSTANCES } = process.env;
let maxInstances = ESLINT_D_MAX_INSTANCES
? Number.parseInt(ESLINT_D_MAX_INSTANCES, 10)
: 10;

if (Number.isInteger(maxInstances)) {
mantoni marked this conversation as resolved.
Show resolved Hide resolved
// eslint-disable-next-line max-len
console.error(new Error(`ESLINT_D_MAX_INSTANCES not a valid integer. Instead found "${ESLINT_D_MAX_INSTANCES}". Defaulting back to 10.`));
maxInstances = 10;
}
if (maxInstances <= 0) {
// eslint-disable-next-line max-len
console.error(new Error(`ESLINT_D_MAX_INSTANCES must be greater than 0. Instead found "${ESLINT_D_MAX_INSTANCES}". Defaulting back to 10.`));
maxInstances = 10;
}
const lru_cache = new LRU(maxInstances);

const check_files = [
'package.json',
'package-lock.json',
Expand Down