@@ -74,8 +74,6 @@ function findExt(filePath) {
74
74
}
75
75
76
76
function shouldParse ( filePath ) {
77
- // console.log('shouldParse found filePath', filePath)
78
-
79
77
const ext = path . extname ( filePath ) ;
80
78
const basename = path . basename ( filePath ) ;
81
79
@@ -110,7 +108,6 @@ function getAbsFilePath(filePath) {
110
108
// since we might be importing a file with no extension.
111
109
const pathWithExt = findExt ( filePath ) ;
112
110
if ( ! pathWithExt ) {
113
- // console.log('unable to find ext', filePath);
114
111
return pathWithExt ;
115
112
}
116
113
@@ -129,8 +126,6 @@ function handleFile(_filePath, appPath, onFile, cachedParsedFile) {
129
126
}
130
127
131
128
const relativeFilePath = path . relative ( process . cwd ( ) , filePath ) ;
132
- console . log ( 'handleFile:' , { filePath, appPath, relativeFilePath} ) ;
133
-
134
129
if ( ! shouldParse ( filePath ) || handledFiles . has ( filePath ) || ig . ignores ( relativeFilePath ) ) {
135
130
return ;
136
131
}
@@ -164,10 +159,7 @@ function handleFile(_filePath, appPath, onFile, cachedParsedFile) {
164
159
}
165
160
166
161
function handleFolder ( folderPath , appPath , archList , onFile , cachedParsedFile ) {
167
- console . log ( `folderPath` , folderPath ) ;
168
-
169
162
const dirents = fs . readdirSync ( folderPath , { withFileTypes : true } ) ;
170
- // console.log('dirents', dirents)
171
163
for ( let i = 0 ; i < dirents . length ; i += 1 ) {
172
164
if ( dirents [ i ] . isDirectory ( ) ) {
173
165
if ( shouldWalk ( path . resolve ( folderPath , dirents [ i ] . name ) , archList ) ) {
@@ -227,12 +219,26 @@ function shouldSkip(context) {
227
219
: walker . cachedParsedFile ;
228
220
229
221
if ( ! Object . keys ( parsedFiles ) . length || ! ( realPath in parsedFiles ) ) {
230
- debug ( 'Skipping' , realPath ) ;
222
+ debug ( 'Skipping file ' , realPath ) ;
231
223
return true ;
232
224
}
233
225
return false ;
234
226
}
235
227
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
+
236
242
237
243
class Walker {
238
244
cachedParsedFile ;
@@ -244,12 +250,17 @@ class Walker {
244
250
245
251
constructor ( appPath ) {
246
252
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
248
258
? JSON . parse ( fs . readFileSync ( this . filePath ( ) ) )
249
259
: { } ;
250
260
}
251
261
walkApp ( { archList, onFile, isTest } ) {
252
262
if ( Object . keys ( this . cachedParsedFile ) . length > 0 ) {
263
+ debug ( 'Not walking the app as the cachedParsedFile is already present' ) ;
253
264
return ;
254
265
}
255
266
@@ -260,6 +271,7 @@ class Walker {
260
271
const { meteor } = content ;
261
272
if ( meteor && meteor . mainModule && meteor . mainModule . server ) {
262
273
initialServerFile = path . join ( this . appPath , meteor . mainModule . server ) ;
274
+ debug ( 'Starting from meteor.mainModule.server from package.json' , meteor . mainModule . server ) ;
263
275
}
264
276
}
265
277
if ( initialServerFile ) {
0 commit comments