You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here is a suggested updated cache file, with relative paths instead of full paths. The . is the directory from which
88
91
eslint is run. Typically, eslint is always run from the same place, so using a relative path should not cause a problem.
89
92
93
+
Note that the obscure hash value is still there, and is now Ak0sovs. This hash value will need to be calculated using
94
+
relative paths only.
95
+
90
96
```
91
97
[
92
98
{
@@ -115,7 +121,7 @@ eslint is run. Typically, eslint is always run from the same place, so using a r
115
121
"fixableErrorCount": 0,
116
122
"fixableWarningCount": 0
117
123
},
118
-
"1k0siqs",
124
+
"Ak0sovs",
119
125
{
120
126
"filePath": "9",
121
127
"messages": "10",
@@ -138,13 +144,24 @@ eslint is run. Typically, eslint is always run from the same place, so using a r
138
144
### Adding the command line parameter
139
145
- conf/default-cli-options.js: add the property 'shareableCache' with a default of false. It should be put in the section with the other cache variables, below cacheStrategy.
140
146
- 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."
141
-
- eslint-helpers.js: add shareableCache variable (set to false) to the processOptions
147
+
- eslint-helpers.js: add shareableCache variable (set to false) to the processOptions, and make sure it must be a boolean.
142
148
- 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.
143
-
149
+
- lib/cli.js: Add the shareableCache option, defaulted to false, in the translateOptions function.
144
150
145
151
### Changing cache file serialization
146
-
- lib/eslint/flat-eslint.js: Define the shearableCache property at the top, with the other properties, as a boolean
147
-
- 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.
152
+
- lib/cli-engine/lint-result-cache.js: Add the properties 'cwd' and 'shareableCache' to the LintResultCache class. 'cwd' is a string, the current working directory. shareableCache is a boolean, the result of the user's passed in command line parameter. Use these values in two main places:
153
+
1. Whenever we store or retrieve file results in the cache, use the results of the new class function, getFileKey(filePath). If shareableCache is false, it uses a full file path as the key. If shareableCache is true, uses a relative file path.
154
+
2. Update the function hashOfConfigFor, so that when the configuration object is hashed into a hash key and put into the eslintcache, if shareableCache is set to true, the file paths hashed are all relative paths. Implementation detail:
155
+
```
156
+
function hashOfConfigFor(config, cwd) {
157
+
if (!configHashCache.has(config)) {
158
+
// replace the full directory path in the config string to make the hash location-neutral
- lib/cli-engine/cli-engine.js: Update the constructor call to LintResultCache to add the new parameters cwd and shareableCache.
164
+
- lib/eslint/flat-eslint.js: Update the constructor call to LintResultCache to add the new parameters cwd and shareableCache.
148
165
149
166
## Documentation
150
167
@@ -159,21 +176,35 @@ Furthermore, defaulting to the existing behavior does help make upgrading less p
159
176
## Backwards Compatibility Analysis
160
177
161
178
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
162
-
be used. They will not need to regenerate their cache unless they set this flag.
179
+
be used. Users of the eslint cache will still need to regenerate their cache no matter how they set this flag, because the current implementation forces a cache rebuild if there are
180
+
any configuration changes. Adding a new property counts as a change.
163
181
164
182
## Alternatives
165
183
166
-
A CLI tool which translates the existing cache to the current folder structure. This could be any sort of script that will basically do a replace-all on the paths in the .eslintcache file so that they are the new location rather than the old. A downside to this is that any tool based on string replacement would be fragile at best.
184
+
A CLI tool which translates the existing cache to the current folder structure. This could be any sort of script that will basically do a replace-all on the paths in
185
+
the .eslintcache file and also recalculates the hash so that they are the new location rather than the old. A downside to this is that any tool based on string
186
+
replacement would be fragile at best.
167
187
168
188
## Open Questions
169
189
170
190
No.
171
191
172
192
## Help Needed
173
193
174
-
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
175
-
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
176
-
on the eslintproject and they all pass. My fork is here: https://github.com/cs6cs6/eslint_patch/tree/fork/shareable-eslintcache
194
+
Decision needed: Make every cache shareable, or keep the shreable-cache flag default to false?
195
+
196
+
I originally planned the shareable-cache flag so that users of eslint could not be surprised by changed cache behavior, and would also not have to regenerate their cache
197
+
for a patch version change. But I discovered by testing that there is no way to NOT force people to regenerate their eslint cache with this change. That's because by adding
198
+
the 'shareable-cache' flag, it adds a property to the ConfigArray object. Even if it's set to false (the old behavior), the object's structure changes with a new property
199
+
field. This in turn changes the ConfigArray object's stringify results, which are fed into a hash function to create a hash key. (See lint-result-cache.js function hashOfConfigFor.)
200
+
In turn, that becomes a part of the eslintcache file. I think it's so that everything will be re-scanned with configuration changes.
201
+
202
+
For that reason, should we simply have a shareable cache full of relative paths be the only behavior? That means no command line flag, and strictly internal changes that
203
+
would be invisible to the end user. On the other hand, if this change DOES have undesirable side effects because people are using eslint in unexpected ways, having the flag
204
+
default to the old behavior would save them from surprises on upgrade. Judging by the number of .gitignore files with .eslintcache in them, people are used to this
205
+
cache not being shareable.
206
+
207
+
What would the eslint team prefer? No flag, or keep the shareable-cache flag and default to false?
0 commit comments