Skip to content

Commit da9d7b5

Browse files
committed
#8 New files are only detect after deleting .eslint-meteor-files
- Expires cache - Adds changelog
1 parent 5910824 commit da9d7b5

File tree

4 files changed

+51
-12
lines changed

4 files changed

+51
-12
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Changelog
2+
3+
## 1.4.2 - 2024-03-22
4+
5+
### Bug fixes
6+
7+
- Detect new files after 5 seconds as now the cache is expiring. You can customize this time by providing `METEOR_ESLINT_PLUGIN_EXPIRES_CACHE_IN_SECONDS` env var.
8+
9+
### Changes
10+
11+
- Adds more debug statements to be logged when using `METEOR_ESLINT_PLUGIN_DEBUG` env var.
12+
- Adds an option to expires the cache after an amount of seconds, by default its 5. Env var `METEOR_ESLINT_PLUGIN_EXPIRES_CACHE_IN_SECONDS`
13+

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ Install the npm dependency
1616
npm i -D @quave/eslint-plugin-meteor-quave
1717
```
1818

19-
### License
19+
## Debug
20+
21+
You can debug by providing the `METEOR_ESLINT_PLUGIN_DEBUG` env var as `1` for example, so you will see more logs.
22+
23+
Run your eslint task like: `METEOR_ESLINT_PLUGIN_DEBUG=1 eslint .`
24+
25+
## Options
26+
27+
- Env var `METEOR_ESLINT_PLUGIN_EXPIRES_CACHE_IN_SECONDS`: default is `5`. You can customize the cache expiration time in seconds.
28+
29+
## Changelog
30+
31+
[CHANGELOG](./CHANGELOG.md)
32+
33+
## License
2034

2135
MIT

lib/util/walker.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ function findExt(filePath) {
7474
}
7575

7676
function shouldParse(filePath) {
77-
// console.log('shouldParse found filePath', filePath)
78-
7977
const ext = path.extname(filePath);
8078
const basename = path.basename(filePath);
8179

@@ -110,7 +108,6 @@ function getAbsFilePath(filePath) {
110108
// since we might be importing a file with no extension.
111109
const pathWithExt = findExt(filePath);
112110
if (!pathWithExt) {
113-
// console.log('unable to find ext', filePath);
114111
return pathWithExt;
115112
}
116113

@@ -129,8 +126,6 @@ function handleFile(_filePath, appPath, onFile, cachedParsedFile) {
129126
}
130127

131128
const relativeFilePath = path.relative(process.cwd(), filePath);
132-
console.log('handleFile:', {filePath, appPath, relativeFilePath});
133-
134129
if (!shouldParse(filePath) || handledFiles.has(filePath) || ig.ignores(relativeFilePath)) {
135130
return;
136131
}
@@ -164,10 +159,7 @@ function handleFile(_filePath, appPath, onFile, cachedParsedFile) {
164159
}
165160

166161
function handleFolder(folderPath, appPath, archList, onFile, cachedParsedFile) {
167-
console.log(`folderPath`, folderPath);
168-
169162
const dirents = fs.readdirSync(folderPath, { withFileTypes: true });
170-
// console.log('dirents', dirents)
171163
for (let i = 0; i < dirents.length; i += 1) {
172164
if (dirents[i].isDirectory()) {
173165
if (shouldWalk(path.resolve(folderPath, dirents[i].name), archList)) {
@@ -227,12 +219,26 @@ function shouldSkip(context) {
227219
: walker.cachedParsedFile;
228220

229221
if (!Object.keys(parsedFiles).length || !(realPath in parsedFiles)) {
230-
debug('Skipping', realPath);
222+
debug('Skipping file', realPath);
231223
return true;
232224
}
233225
return false;
234226
}
235227

228+
const EXPIRES_CACHE_IN_SECONDS = process.env.METEOR_ESLINT_PLUGIN_EXPIRES_CACHE_IN_SECONDS || 5;
229+
230+
const cacheExistsAndIsStillValid = (filePath) => {
231+
if (!fs.existsSync(filePath)) {
232+
return false;
233+
}
234+
235+
const stats = fs.statSync(filePath);
236+
const mtime = new Date(stats.mtime);
237+
const seconds = Math.abs(new Date() - mtime) / 1000;
238+
239+
return seconds <= EXPIRES_CACHE_IN_SECONDS;
240+
}
241+
236242

237243
class Walker {
238244
cachedParsedFile;
@@ -244,12 +250,17 @@ class Walker {
244250

245251
constructor(appPath) {
246252
this.appPath = appPath;
247-
this.cachedParsedFile = fs.existsSync(this.filePath())
253+
const useCache = cacheExistsAndIsStillValid(this.filePath());
254+
if (!useCache) {
255+
debug('Cache is not going to be used');
256+
}
257+
this.cachedParsedFile = useCache
248258
? JSON.parse(fs.readFileSync(this.filePath()))
249259
: {};
250260
}
251261
walkApp({ archList, onFile, isTest }) {
252262
if (Object.keys(this.cachedParsedFile).length > 0) {
263+
debug('Not walking the app as the cachedParsedFile is already present');
253264
return;
254265
}
255266

@@ -260,6 +271,7 @@ class Walker {
260271
const { meteor } = content;
261272
if (meteor && meteor.mainModule && meteor.mainModule.server) {
262273
initialServerFile = path.join(this.appPath, meteor.mainModule.server);
274+
debug('Starting from meteor.mainModule.server from package.json', meteor.mainModule.server);
263275
}
264276
}
265277
if (initialServerFile) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@quave/eslint-plugin-meteor-quave",
3-
"version": "1.4.1",
3+
"version": "1.4.2",
44
"description": "Quave linting rules for ESLint",
55
"main": "lib/index.js",
66
"scripts": {

0 commit comments

Comments
 (0)