Skip to content

Commit 0784e68

Browse files
authored
feat: adding back in useModifiedTime (#1400)
1 parent b6f2773 commit 0784e68

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

packages/file-entry-cache/src/index.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ export type FileEntryCacheOptions = {
4747
export type GetFileDescriptorOptions = {
4848
/** Whether to use checksum for this specific file check instead of modified time (mtime) (overrides instance setting) */
4949
useCheckSum?: boolean;
50+
/** Whether to use file modified time for change detection (default: true) */
51+
useModifiedTime?: boolean;
5052
};
5153

5254
export type FileDescriptor = {
@@ -147,6 +149,7 @@ export class FileEntryCache {
147149
private _restrictAccessToCwd = false;
148150
private _logger?: ILogger;
149151
private _useAbsolutePathAsKey = false;
152+
private _useModifiedTime = true;
150153

151154
/**
152155
* Create a new FileEntryCache instance
@@ -169,6 +172,10 @@ export class FileEntryCache {
169172
this._cwd = options.cwd;
170173
}
171174

175+
if (options?.useModifiedTime !== undefined) {
176+
this._useModifiedTime = options.useModifiedTime;
177+
}
178+
172179
if (options?.restrictAccessToCwd !== undefined) {
173180
this._restrictAccessToCwd = options.restrictAccessToCwd;
174181
}
@@ -262,6 +269,22 @@ export class FileEntryCache {
262269
this._cwd = value;
263270
}
264271

272+
/**
273+
* Get whether to use modified time for change detection
274+
* @returns {boolean} Whether modified time (mtime) is used for change detection (default: true)
275+
*/
276+
public get useModifiedTime(): boolean {
277+
return this._useModifiedTime;
278+
}
279+
280+
/**
281+
* Set whether to use modified time for change detection
282+
* @param {boolean} value - The value to set
283+
*/
284+
public set useModifiedTime(value: boolean) {
285+
this._useModifiedTime = value;
286+
}
287+
265288
/**
266289
* Get whether to restrict paths to cwd boundaries
267290
* @returns {boolean} Whether strict path checking is enabled (default: true)
@@ -435,6 +458,13 @@ export class FileEntryCache {
435458
"Using checksum setting",
436459
);
437460

461+
const useModifiedTimeValue =
462+
options?.useModifiedTime ?? this.useModifiedTime;
463+
this._logger?.debug(
464+
{ useModifiedTime: useModifiedTimeValue },
465+
"Using modified time (mtime) setting",
466+
);
467+
438468
try {
439469
fstat = fs.statSync(absolutePath);
440470
// Update the file stats while preserving existing meta properties
@@ -478,7 +508,7 @@ export class FileEntryCache {
478508
}
479509

480510
// If the file is in the cache, check if the file has changed
481-
if (useCheckSumValue === false && metaCache?.mtime !== result.meta?.mtime) {
511+
if (useModifiedTimeValue && metaCache?.mtime !== result.meta?.mtime) {
482512
result.changed = true;
483513
this._logger?.debug(
484514
{ filePath, oldMtime: metaCache.mtime, newMtime: result.meta.mtime },

packages/file-entry-cache/test/index.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ describe("file-entry-cache with options", () => {
5555
expect(fileEntryCache.restrictAccessToCwd).toBe(false);
5656
});
5757

58+
test("should be able to get and set useModifiedTime", () => {
59+
const fileEntryCache = new FileEntryCache({ useModifiedTime: false });
60+
expect(fileEntryCache.useModifiedTime).toBe(false);
61+
fileEntryCache.useModifiedTime = true;
62+
expect(fileEntryCache.useModifiedTime).toBe(true);
63+
});
64+
5865
test("create should initialize a file-entry-cache", () => {
5966
const fileEntryCache = defaultFileEntryCache.create("test1");
6067
expect(fileEntryCache).toBeDefined();

packages/file-entry-cache/test/relative-eslint.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ describe("eslint tests scenarios", () => {
1818
const cache = fileEntryCache.create(".eslintcache-foo43", cacheDirectory, {
1919
useCheckSum,
2020
cwd: path.resolve("./src"),
21+
useModifiedTime: false,
2122
});
2223

2324
if (cache.useAbsolutePathAsKey) {

0 commit comments

Comments
 (0)