Skip to content

Commit

Permalink
#8 New files are only detect after deleting .eslint-meteor-files
Browse files Browse the repository at this point in the history
- Expires cache
- Adds changelog
  • Loading branch information
filipenevola committed Mar 22, 2024
1 parent 5910824 commit da9d7b5
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 12 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Changelog

## 1.4.2 - 2024-03-22

### Bug fixes

- 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.

### Changes

- Adds more debug statements to be logged when using `METEOR_ESLINT_PLUGIN_DEBUG` env var.
- 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`

16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ Install the npm dependency
npm i -D @quave/eslint-plugin-meteor-quave
```

### License
## Debug

You can debug by providing the `METEOR_ESLINT_PLUGIN_DEBUG` env var as `1` for example, so you will see more logs.

Run your eslint task like: `METEOR_ESLINT_PLUGIN_DEBUG=1 eslint .`

## Options

- Env var `METEOR_ESLINT_PLUGIN_EXPIRES_CACHE_IN_SECONDS`: default is `5`. You can customize the cache expiration time in seconds.

## Changelog

[CHANGELOG](./CHANGELOG.md)

## License

MIT
32 changes: 22 additions & 10 deletions lib/util/walker.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ function findExt(filePath) {
}

function shouldParse(filePath) {
// console.log('shouldParse found filePath', filePath)

const ext = path.extname(filePath);
const basename = path.basename(filePath);

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

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

const relativeFilePath = path.relative(process.cwd(), filePath);
console.log('handleFile:', {filePath, appPath, relativeFilePath});

if (!shouldParse(filePath) || handledFiles.has(filePath) || ig.ignores(relativeFilePath)) {
return;
}
Expand Down Expand Up @@ -164,10 +159,7 @@ function handleFile(_filePath, appPath, onFile, cachedParsedFile) {
}

function handleFolder(folderPath, appPath, archList, onFile, cachedParsedFile) {
console.log(`folderPath`, folderPath);

const dirents = fs.readdirSync(folderPath, { withFileTypes: true });
// console.log('dirents', dirents)
for (let i = 0; i < dirents.length; i += 1) {
if (dirents[i].isDirectory()) {
if (shouldWalk(path.resolve(folderPath, dirents[i].name), archList)) {
Expand Down Expand Up @@ -227,12 +219,26 @@ function shouldSkip(context) {
: walker.cachedParsedFile;

if (!Object.keys(parsedFiles).length || !(realPath in parsedFiles)) {
debug('Skipping', realPath);
debug('Skipping file', realPath);
return true;
}
return false;
}

const EXPIRES_CACHE_IN_SECONDS = process.env.METEOR_ESLINT_PLUGIN_EXPIRES_CACHE_IN_SECONDS || 5;

const cacheExistsAndIsStillValid = (filePath) => {
if (!fs.existsSync(filePath)) {
return false;
}

const stats = fs.statSync(filePath);
const mtime = new Date(stats.mtime);
const seconds = Math.abs(new Date() - mtime) / 1000;

return seconds <= EXPIRES_CACHE_IN_SECONDS;
}


class Walker {
cachedParsedFile;
Expand All @@ -244,12 +250,17 @@ class Walker {

constructor(appPath) {
this.appPath = appPath;
this.cachedParsedFile = fs.existsSync(this.filePath())
const useCache = cacheExistsAndIsStillValid(this.filePath());
if (!useCache) {
debug('Cache is not going to be used');
}
this.cachedParsedFile = useCache
? JSON.parse(fs.readFileSync(this.filePath()))
: {};
}
walkApp({ archList, onFile, isTest }) {
if (Object.keys(this.cachedParsedFile).length > 0) {
debug('Not walking the app as the cachedParsedFile is already present');
return;
}

Expand All @@ -260,6 +271,7 @@ class Walker {
const { meteor } = content;
if (meteor && meteor.mainModule && meteor.mainModule.server) {
initialServerFile = path.join(this.appPath, meteor.mainModule.server);
debug('Starting from meteor.mainModule.server from package.json', meteor.mainModule.server);
}
}
if (initialServerFile) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@quave/eslint-plugin-meteor-quave",
"version": "1.4.1",
"version": "1.4.2",
"description": "Quave linting rules for ESLint",
"main": "lib/index.js",
"scripts": {
Expand Down

0 comments on commit da9d7b5

Please sign in to comment.