|
| 1 | + Repo: eslint/eslint |
| 2 | +- Start Date: 2023-02-14 |
| 3 | +- RFC PR: <https://github.com/eslint/rfcs/pull/106> |
| 4 | +- Authors: Christian Schulz (@cschulz)i and cs6cs6 |
| 5 | + |
| 6 | +# Relative cache location strategy |
| 7 | + |
| 8 | +## Summary |
| 9 | + |
| 10 | +To be able to share the created eslint cache between different systems f.e. local machine and CI, there is a need for a relative path stored in the cache. |
| 11 | + |
| 12 | +## Motivation |
| 13 | + |
| 14 | +The overall motivation for doing this is performance during the eslint process. |
| 15 | + |
| 16 | +Most people are running eslint on local developer machine and additional on the CI workers. |
| 17 | +In high changing repositories there are several pull requests at the same time changing different files requiring linting all the time. |
| 18 | +This is a time consuming process depending on the enabled rules like type checking rules. |
| 19 | + |
| 20 | +If the CI worker is able to cache its last run, it can just pick this cache up and use it. |
| 21 | +Also developers can reuse this cache or commit it as part of a repository for the CI. |
| 22 | + |
| 23 | +## Detailed Design |
| 24 | + |
| 25 | +I have a branch with the following design already. It is not fully tested, so I'm not 100% sure this will be the final implementation but I think it is a good start. |
| 26 | + |
| 27 | +The LintResultCache takes a file path as parameter to find or store a file cache entry. |
| 28 | + |
| 29 | +One approach would be to truncate the given absolute path of the file by the path of the cache location. |
| 30 | + |
| 31 | +### Adding the command line parameter |
| 32 | +- conf/default-cli-options.js: add the property 'shearableCache' with a default of false. It should be put in the section with the other cache variables, below cacheStrategy. |
| 33 | +- docs/src/use/command-line-interface.md: Add an explanation of the 'shareable-cache' variable with the other cache variables: "By default, an eslintcache contains full file paths and thus cannot readily be shared across developers or ci machines. "False" is that default. "True" changes the internal storage to store a relative path to the process execution directory, thus making the eslintcache shareable across developers and ci machines. . If you change this setting, you must regenerate your entire eslint cache." |
| 34 | +- eslint-helpers.js: add shareableCache variable (set to false) to the processOptions |
| 35 | +- lib/options.js: Add an option 'shareable-cache' of type Boolean with a nice description for people to read: By default, an eslintcache contains full file paths and thus cannot readily be shared across developers or ci machines. "False" is that default. "True" changes the internal storage to store a relative path to the process execution directory, thus making the eslintcache shareable across developers and ci machines. . If you change this setting, you must regenerate your entire eslint cache. |
| 36 | + |
| 37 | + |
| 38 | +### Changing cache file serialization |
| 39 | +- lib/eslint/flat-eslint.js: Define the shearableCache property at the top, with the other properties, as a boolean |
| 40 | +- lib/eslint/flat-eslint.js: Around line 873, where the flat-eslint.js file is saving the cache in the cachefile, if processOptions.shareableCache is set to true, pass a PARTIAL path to the lintResultCache.setCachedLintResults() function instead of the full path. |
| 41 | + |
| 42 | +## Documentation |
| 43 | + |
| 44 | +Add the new CLI flag to the CLI documentation. The new cli flag will be called shareable-cache. |
| 45 | + |
| 46 | +## Drawbacks |
| 47 | + |
| 48 | +Adding a new CLI flag adds some complexity for the end user. They will need to understand why the feature exists. |
| 49 | + |
| 50 | +Furthermore, defaulting to the existing behavior does help make upgrading less painful, but it is possible most people expect a shareable cache by default. This may cause confusion. |
| 51 | + |
| 52 | +## Backwards Compatibility Analysis |
| 53 | + |
| 54 | +The new flag, shareable-cache, passed in on the command line, will default to false. Unless people explicitly set it to true, then the old algorithms will |
| 55 | +be used. They will not need to regenerate their cache unless they set this flag. |
| 56 | + |
| 57 | +## Alternatives |
| 58 | + |
| 59 | +A CLI tool which translates the existing cache to the current folder structure. |
| 60 | + |
| 61 | +## Open Questions |
| 62 | + |
| 63 | +No. |
| 64 | + |
| 65 | +## Help Needed |
| 66 | + |
| 67 | +I have a branch with code changes, but I am trying to figure out how to build an artifact to test with. Using the eslint.js artifact in the browser does not make sense |
| 68 | +with a cache change, and I would like to test it in my project. How can I build a package that I can install with NPM into my project to test?? I am able to run the tests |
| 69 | +on the eslintproject and they all pass. My fork is here: https://github.com/cs6cs6/eslint_patch/tree/fork/shareable-eslintcache |
| 70 | + |
| 71 | +## Frequently Asked Questions |
| 72 | + |
| 73 | +TBD |
| 74 | + |
| 75 | +## Related Discussions |
| 76 | + |
| 77 | +[Change Request: Eslintcache relative #16493](https://github.com/eslint/eslint/issues/16493) |
0 commit comments