Expose cache class and allow to inject it
See original GitHub issueThe version of ESLint you are using.
eslint v5.4.0
The problem you want to solve.
Hi eslint team 👋
I’m the maintainer of eslint_d which aims at accelerating eslint, especially when used frequently on single files, e.g. as an editor plugin.
Looking at the eslint cache implementation, it strikes me that the eslint_d
background server could keep an in-memory cache instance, making it obsolete to read and write the cache file. To support this, I would need slightly more control over the cache.
Your take on the correct solution to problem.
My suggestion is to expose a cache class and allow to inject instances as an option for the CLIEngine
. If the cache is injected, it would be the callers responsibility to persist the cache.
If you’d consider changing the API for this, I’m happy to contribute a pull request.
Thanks for making eslint!
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:11 (5 by maintainers)
Top GitHub Comments
Regarding @not-an-aardvark’s last question:
executeOnFiles(pattern)
receives a pattern which is then resolved to a list of files. Therefore the roundabout way of doing things. Since I’m trying to be 100% eslint compatible, I wouldn’t want to expand patterns myself. We could expose that separately though, e.g.engine.listFilesToProcess(pattern)
. With the normalized file list, I might even be able to implement my own results caching without touching the eslint core cache implementation 🤔EDIT: Just noticed that2nd edit: I got confused. This does something else.resolveFileGlobPatterns
does exactly that.Thanks for working on this!
I’m hesitant to add something like
engine.createResultCache
or the ability to inject afile-entry-cache
instance, because it seems like would lock us into usingfile-entry-cache
’s API indefinitely. In the future, it’s possible that we will want to change the cache file format and/or use a different library with a different API. My impression is that the “injection” approach would be easy to implement in the short term but would cause problems in the long term by exposing term because it would expose too much API surface and prevent us from changing the implementation.To me, it seems like it would be nice to have the API look vaguely like this:
Then
CLIEngine
would call the providedgetUpdatedFiles
andupdateCache
methods while running in order to get data from the cache.--cache
flag, the default behavior would be forgetUpdatedFiles
to read.eslintcache
and check the mtime, and forupdateCache
to write an.eslintcache
file to the filesystem, as it does now.--cache
flag, the default behavior would be forgetUpdateFiles
to assume all files are updated, and forupdateCache
to be a no-op. This would be the same as the current behavior when running without a cache. However, it would remove some complexity fromCLIEngine#executeOnText
because it would no longer be necessary to have special logic for the--cache
flag – the difference in behavior would be encapsulated in the differentgetUpdatedFiles
andupdateCache
methods.eslint_d
would provide agetUpdatedFiles
method that reads information from memory, and anupdateCache
method that writes to memory.