file-entry-cache 10.0.7 → 10.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/index.cjs +59 -1
- package/dist/index.d.cts +49 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.js +59 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -92,6 +92,7 @@ There have been many features added and changes made to the `file-entry-cache` c
|
|
|
92
92
|
|
|
93
93
|
# FileEntryCache Options (FileEntryCacheOptions)
|
|
94
94
|
- `currentWorkingDirectory?` - The current working directory. Used when resolving relative paths.
|
|
95
|
+
- `useModifiedTime?` - If `true` it will use the modified time to determine if the file has changed. Default is `true`
|
|
95
96
|
- `useCheckSum?` - If `true` it will use a checksum to determine if the file has changed. Default is `false`
|
|
96
97
|
- `hashAlgorithm?` - The algorithm to use for the checksum. Default is `md5` but can be any algorithm supported by `crypto.createHash`
|
|
97
98
|
- `cache.ttl?` - The time to live for the cache in milliseconds. Default is `0` which means no expiration
|
|
@@ -117,7 +118,7 @@ There have been many features added and changes made to the `file-entry-cache` c
|
|
|
117
118
|
- `removeEntry(filePath: string): void` - Removes an entry from the cache. This can be `relative` or `absolute` paths.
|
|
118
119
|
- `reconcile(): void` - Saves the cache to disk and removes any files that are no longer found.
|
|
119
120
|
- `hasFileChanged(filePath: string): boolean` - Checks if the file has changed. This will return `true` if the file has changed.
|
|
120
|
-
- `getFileDescriptor(filePath: string, options?: { useCheckSum?: boolean, currentWorkingDirectory?: string }): FileEntryDescriptor` - Gets the file descriptor for the file. Please refer to the entire section on `Get File Descriptor` for more information.
|
|
121
|
+
- `getFileDescriptor(filePath: string, options?: { useModifiedTime?: boolean, useCheckSum?: boolean, currentWorkingDirectory?: string }): FileEntryDescriptor` - Gets the file descriptor for the file. Please refer to the entire section on `Get File Descriptor` for more information.
|
|
121
122
|
- `normalizeEntries(entries: FileEntryDescriptor[]): FileEntryDescriptor[]` - Normalizes the entries to have the correct paths. This is used when loading the cache from disk.
|
|
122
123
|
- `analyzeFiles(files: string[])` will return `AnalyzedFiles` object with `changedFiles`, `notFoundFiles`, and `notChangedFiles` as FileDescriptor arrays.
|
|
123
124
|
- `getUpdatedFiles(files: string[])` will return an array of `FileEntryDescriptor` objects that have changed.
|
package/dist/index.cjs
CHANGED
|
@@ -70,12 +70,20 @@ var FileEntryDefault = class {
|
|
|
70
70
|
var FileEntryCache = class {
|
|
71
71
|
_cache = new import_flat_cache.FlatCache({ useClone: false });
|
|
72
72
|
_useCheckSum = false;
|
|
73
|
+
_useModifiedTime = true;
|
|
73
74
|
_currentWorkingDirectory;
|
|
74
75
|
_hashAlgorithm = "md5";
|
|
76
|
+
/**
|
|
77
|
+
* Create a new FileEntryCache instance
|
|
78
|
+
* @param options - The options for the FileEntryCache
|
|
79
|
+
*/
|
|
75
80
|
constructor(options) {
|
|
76
81
|
if (options?.cache) {
|
|
77
82
|
this._cache = new import_flat_cache.FlatCache(options.cache);
|
|
78
83
|
}
|
|
84
|
+
if (options?.useModifiedTime) {
|
|
85
|
+
this._useModifiedTime = options.useModifiedTime;
|
|
86
|
+
}
|
|
79
87
|
if (options?.useCheckSum) {
|
|
80
88
|
this._useCheckSum = options.useCheckSum;
|
|
81
89
|
}
|
|
@@ -86,27 +94,73 @@ var FileEntryCache = class {
|
|
|
86
94
|
this._hashAlgorithm = options.hashAlgorithm;
|
|
87
95
|
}
|
|
88
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Get the cache
|
|
99
|
+
* @returns {FlatCache} The cache
|
|
100
|
+
*/
|
|
89
101
|
get cache() {
|
|
90
102
|
return this._cache;
|
|
91
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Set the cache
|
|
106
|
+
* @param {FlatCache} cache - The cache to set
|
|
107
|
+
*/
|
|
92
108
|
set cache(cache) {
|
|
93
109
|
this._cache = cache;
|
|
94
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Use the hash to check if the file has changed
|
|
113
|
+
* @returns {boolean} if the hash is used to check if the file has changed
|
|
114
|
+
*/
|
|
95
115
|
get useCheckSum() {
|
|
96
116
|
return this._useCheckSum;
|
|
97
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Set the useCheckSum value
|
|
120
|
+
* @param {boolean} value - The value to set
|
|
121
|
+
*/
|
|
98
122
|
set useCheckSum(value) {
|
|
99
123
|
this._useCheckSum = value;
|
|
100
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* Use the modified time to check if the file has changed
|
|
127
|
+
* @returns {boolean} if the modified time is used to check if the file has changed
|
|
128
|
+
*/
|
|
129
|
+
get useModifiedTime() {
|
|
130
|
+
return this._useModifiedTime;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Set the useModifiedTime value
|
|
134
|
+
* @param {boolean} value - The value to set
|
|
135
|
+
*/
|
|
136
|
+
set useModifiedTime(value) {
|
|
137
|
+
this._useModifiedTime = value;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Get the hash algorithm
|
|
141
|
+
* @returns {string} The hash algorithm
|
|
142
|
+
*/
|
|
101
143
|
get hashAlgorithm() {
|
|
102
144
|
return this._hashAlgorithm;
|
|
103
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Set the hash algorithm
|
|
148
|
+
* @param {string} value - The value to set
|
|
149
|
+
*/
|
|
104
150
|
set hashAlgorithm(value) {
|
|
105
151
|
this._hashAlgorithm = value;
|
|
106
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* Get the current working directory
|
|
155
|
+
* @returns {string | undefined} The current working directory
|
|
156
|
+
*/
|
|
107
157
|
get currentWorkingDirectory() {
|
|
108
158
|
return this._currentWorkingDirectory;
|
|
109
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* Set the current working directory
|
|
162
|
+
* @param {string | undefined} value - The value to set
|
|
163
|
+
*/
|
|
110
164
|
set currentWorkingDirectory(value) {
|
|
111
165
|
this._currentWorkingDirectory = value;
|
|
112
166
|
}
|
|
@@ -222,6 +276,7 @@ var FileEntryCache = class {
|
|
|
222
276
|
result.meta = this._cache.getKey(result.key) ?? {};
|
|
223
277
|
filePath = this.getAbsolutePath(filePath, { currentWorkingDirectory: options?.currentWorkingDirectory });
|
|
224
278
|
const useCheckSumValue = options?.useCheckSum ?? this._useCheckSum;
|
|
279
|
+
const useModifiedTimeValue = options?.useModifiedTime ?? this._useModifiedTime;
|
|
225
280
|
try {
|
|
226
281
|
fstat = import_node_fs.default.statSync(filePath);
|
|
227
282
|
result.meta = {
|
|
@@ -254,7 +309,10 @@ var FileEntryCache = class {
|
|
|
254
309
|
if (result.meta.data === void 0) {
|
|
255
310
|
result.meta.data = metaCache.data;
|
|
256
311
|
}
|
|
257
|
-
if (metaCache?.mtime !== result.meta?.mtime
|
|
312
|
+
if (useModifiedTimeValue && metaCache?.mtime !== result.meta?.mtime) {
|
|
313
|
+
result.changed = true;
|
|
314
|
+
}
|
|
315
|
+
if (metaCache?.size !== result.meta?.size) {
|
|
258
316
|
result.changed = true;
|
|
259
317
|
}
|
|
260
318
|
if (useCheckSumValue && metaCache?.hash !== result.meta?.hash) {
|
package/dist/index.d.cts
CHANGED
|
@@ -2,12 +2,14 @@ import { FlatCacheOptions, FlatCache } from 'flat-cache';
|
|
|
2
2
|
|
|
3
3
|
type FileEntryCacheOptions = {
|
|
4
4
|
currentWorkingDirectory?: string;
|
|
5
|
+
useModifiedTime?: boolean;
|
|
5
6
|
useCheckSum?: boolean;
|
|
6
7
|
hashAlgorithm?: string;
|
|
7
8
|
cache?: FlatCacheOptions;
|
|
8
9
|
};
|
|
9
10
|
type GetFileDescriptorOptions = {
|
|
10
11
|
useCheckSum?: boolean;
|
|
12
|
+
useModifiedTime?: boolean;
|
|
11
13
|
currentWorkingDirectory?: string;
|
|
12
14
|
};
|
|
13
15
|
type FileDescriptor = {
|
|
@@ -37,16 +39,63 @@ declare class FileEntryDefault {
|
|
|
37
39
|
declare class FileEntryCache {
|
|
38
40
|
private _cache;
|
|
39
41
|
private _useCheckSum;
|
|
42
|
+
private _useModifiedTime;
|
|
40
43
|
private _currentWorkingDirectory;
|
|
41
44
|
private _hashAlgorithm;
|
|
45
|
+
/**
|
|
46
|
+
* Create a new FileEntryCache instance
|
|
47
|
+
* @param options - The options for the FileEntryCache
|
|
48
|
+
*/
|
|
42
49
|
constructor(options?: FileEntryCacheOptions);
|
|
50
|
+
/**
|
|
51
|
+
* Get the cache
|
|
52
|
+
* @returns {FlatCache} The cache
|
|
53
|
+
*/
|
|
43
54
|
get cache(): FlatCache;
|
|
55
|
+
/**
|
|
56
|
+
* Set the cache
|
|
57
|
+
* @param {FlatCache} cache - The cache to set
|
|
58
|
+
*/
|
|
44
59
|
set cache(cache: FlatCache);
|
|
60
|
+
/**
|
|
61
|
+
* Use the hash to check if the file has changed
|
|
62
|
+
* @returns {boolean} if the hash is used to check if the file has changed
|
|
63
|
+
*/
|
|
45
64
|
get useCheckSum(): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Set the useCheckSum value
|
|
67
|
+
* @param {boolean} value - The value to set
|
|
68
|
+
*/
|
|
46
69
|
set useCheckSum(value: boolean);
|
|
70
|
+
/**
|
|
71
|
+
* Use the modified time to check if the file has changed
|
|
72
|
+
* @returns {boolean} if the modified time is used to check if the file has changed
|
|
73
|
+
*/
|
|
74
|
+
get useModifiedTime(): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Set the useModifiedTime value
|
|
77
|
+
* @param {boolean} value - The value to set
|
|
78
|
+
*/
|
|
79
|
+
set useModifiedTime(value: boolean);
|
|
80
|
+
/**
|
|
81
|
+
* Get the hash algorithm
|
|
82
|
+
* @returns {string} The hash algorithm
|
|
83
|
+
*/
|
|
47
84
|
get hashAlgorithm(): string;
|
|
85
|
+
/**
|
|
86
|
+
* Set the hash algorithm
|
|
87
|
+
* @param {string} value - The value to set
|
|
88
|
+
*/
|
|
48
89
|
set hashAlgorithm(value: string);
|
|
90
|
+
/**
|
|
91
|
+
* Get the current working directory
|
|
92
|
+
* @returns {string | undefined} The current working directory
|
|
93
|
+
*/
|
|
49
94
|
get currentWorkingDirectory(): string | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* Set the current working directory
|
|
97
|
+
* @param {string | undefined} value - The value to set
|
|
98
|
+
*/
|
|
50
99
|
set currentWorkingDirectory(value: string | undefined);
|
|
51
100
|
/**
|
|
52
101
|
* Given a buffer, calculate md5 hash of its content.
|
package/dist/index.d.ts
CHANGED
|
@@ -2,12 +2,14 @@ import { FlatCacheOptions, FlatCache } from 'flat-cache';
|
|
|
2
2
|
|
|
3
3
|
type FileEntryCacheOptions = {
|
|
4
4
|
currentWorkingDirectory?: string;
|
|
5
|
+
useModifiedTime?: boolean;
|
|
5
6
|
useCheckSum?: boolean;
|
|
6
7
|
hashAlgorithm?: string;
|
|
7
8
|
cache?: FlatCacheOptions;
|
|
8
9
|
};
|
|
9
10
|
type GetFileDescriptorOptions = {
|
|
10
11
|
useCheckSum?: boolean;
|
|
12
|
+
useModifiedTime?: boolean;
|
|
11
13
|
currentWorkingDirectory?: string;
|
|
12
14
|
};
|
|
13
15
|
type FileDescriptor = {
|
|
@@ -37,16 +39,63 @@ declare class FileEntryDefault {
|
|
|
37
39
|
declare class FileEntryCache {
|
|
38
40
|
private _cache;
|
|
39
41
|
private _useCheckSum;
|
|
42
|
+
private _useModifiedTime;
|
|
40
43
|
private _currentWorkingDirectory;
|
|
41
44
|
private _hashAlgorithm;
|
|
45
|
+
/**
|
|
46
|
+
* Create a new FileEntryCache instance
|
|
47
|
+
* @param options - The options for the FileEntryCache
|
|
48
|
+
*/
|
|
42
49
|
constructor(options?: FileEntryCacheOptions);
|
|
50
|
+
/**
|
|
51
|
+
* Get the cache
|
|
52
|
+
* @returns {FlatCache} The cache
|
|
53
|
+
*/
|
|
43
54
|
get cache(): FlatCache;
|
|
55
|
+
/**
|
|
56
|
+
* Set the cache
|
|
57
|
+
* @param {FlatCache} cache - The cache to set
|
|
58
|
+
*/
|
|
44
59
|
set cache(cache: FlatCache);
|
|
60
|
+
/**
|
|
61
|
+
* Use the hash to check if the file has changed
|
|
62
|
+
* @returns {boolean} if the hash is used to check if the file has changed
|
|
63
|
+
*/
|
|
45
64
|
get useCheckSum(): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Set the useCheckSum value
|
|
67
|
+
* @param {boolean} value - The value to set
|
|
68
|
+
*/
|
|
46
69
|
set useCheckSum(value: boolean);
|
|
70
|
+
/**
|
|
71
|
+
* Use the modified time to check if the file has changed
|
|
72
|
+
* @returns {boolean} if the modified time is used to check if the file has changed
|
|
73
|
+
*/
|
|
74
|
+
get useModifiedTime(): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Set the useModifiedTime value
|
|
77
|
+
* @param {boolean} value - The value to set
|
|
78
|
+
*/
|
|
79
|
+
set useModifiedTime(value: boolean);
|
|
80
|
+
/**
|
|
81
|
+
* Get the hash algorithm
|
|
82
|
+
* @returns {string} The hash algorithm
|
|
83
|
+
*/
|
|
47
84
|
get hashAlgorithm(): string;
|
|
85
|
+
/**
|
|
86
|
+
* Set the hash algorithm
|
|
87
|
+
* @param {string} value - The value to set
|
|
88
|
+
*/
|
|
48
89
|
set hashAlgorithm(value: string);
|
|
90
|
+
/**
|
|
91
|
+
* Get the current working directory
|
|
92
|
+
* @returns {string | undefined} The current working directory
|
|
93
|
+
*/
|
|
49
94
|
get currentWorkingDirectory(): string | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* Set the current working directory
|
|
97
|
+
* @param {string | undefined} value - The value to set
|
|
98
|
+
*/
|
|
50
99
|
set currentWorkingDirectory(value: string | undefined);
|
|
51
100
|
/**
|
|
52
101
|
* Given a buffer, calculate md5 hash of its content.
|
package/dist/index.js
CHANGED
|
@@ -33,12 +33,20 @@ var FileEntryDefault = class {
|
|
|
33
33
|
var FileEntryCache = class {
|
|
34
34
|
_cache = new FlatCache({ useClone: false });
|
|
35
35
|
_useCheckSum = false;
|
|
36
|
+
_useModifiedTime = true;
|
|
36
37
|
_currentWorkingDirectory;
|
|
37
38
|
_hashAlgorithm = "md5";
|
|
39
|
+
/**
|
|
40
|
+
* Create a new FileEntryCache instance
|
|
41
|
+
* @param options - The options for the FileEntryCache
|
|
42
|
+
*/
|
|
38
43
|
constructor(options) {
|
|
39
44
|
if (options?.cache) {
|
|
40
45
|
this._cache = new FlatCache(options.cache);
|
|
41
46
|
}
|
|
47
|
+
if (options?.useModifiedTime) {
|
|
48
|
+
this._useModifiedTime = options.useModifiedTime;
|
|
49
|
+
}
|
|
42
50
|
if (options?.useCheckSum) {
|
|
43
51
|
this._useCheckSum = options.useCheckSum;
|
|
44
52
|
}
|
|
@@ -49,27 +57,73 @@ var FileEntryCache = class {
|
|
|
49
57
|
this._hashAlgorithm = options.hashAlgorithm;
|
|
50
58
|
}
|
|
51
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Get the cache
|
|
62
|
+
* @returns {FlatCache} The cache
|
|
63
|
+
*/
|
|
52
64
|
get cache() {
|
|
53
65
|
return this._cache;
|
|
54
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Set the cache
|
|
69
|
+
* @param {FlatCache} cache - The cache to set
|
|
70
|
+
*/
|
|
55
71
|
set cache(cache) {
|
|
56
72
|
this._cache = cache;
|
|
57
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Use the hash to check if the file has changed
|
|
76
|
+
* @returns {boolean} if the hash is used to check if the file has changed
|
|
77
|
+
*/
|
|
58
78
|
get useCheckSum() {
|
|
59
79
|
return this._useCheckSum;
|
|
60
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Set the useCheckSum value
|
|
83
|
+
* @param {boolean} value - The value to set
|
|
84
|
+
*/
|
|
61
85
|
set useCheckSum(value) {
|
|
62
86
|
this._useCheckSum = value;
|
|
63
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Use the modified time to check if the file has changed
|
|
90
|
+
* @returns {boolean} if the modified time is used to check if the file has changed
|
|
91
|
+
*/
|
|
92
|
+
get useModifiedTime() {
|
|
93
|
+
return this._useModifiedTime;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Set the useModifiedTime value
|
|
97
|
+
* @param {boolean} value - The value to set
|
|
98
|
+
*/
|
|
99
|
+
set useModifiedTime(value) {
|
|
100
|
+
this._useModifiedTime = value;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Get the hash algorithm
|
|
104
|
+
* @returns {string} The hash algorithm
|
|
105
|
+
*/
|
|
64
106
|
get hashAlgorithm() {
|
|
65
107
|
return this._hashAlgorithm;
|
|
66
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Set the hash algorithm
|
|
111
|
+
* @param {string} value - The value to set
|
|
112
|
+
*/
|
|
67
113
|
set hashAlgorithm(value) {
|
|
68
114
|
this._hashAlgorithm = value;
|
|
69
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Get the current working directory
|
|
118
|
+
* @returns {string | undefined} The current working directory
|
|
119
|
+
*/
|
|
70
120
|
get currentWorkingDirectory() {
|
|
71
121
|
return this._currentWorkingDirectory;
|
|
72
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Set the current working directory
|
|
125
|
+
* @param {string | undefined} value - The value to set
|
|
126
|
+
*/
|
|
73
127
|
set currentWorkingDirectory(value) {
|
|
74
128
|
this._currentWorkingDirectory = value;
|
|
75
129
|
}
|
|
@@ -185,6 +239,7 @@ var FileEntryCache = class {
|
|
|
185
239
|
result.meta = this._cache.getKey(result.key) ?? {};
|
|
186
240
|
filePath = this.getAbsolutePath(filePath, { currentWorkingDirectory: options?.currentWorkingDirectory });
|
|
187
241
|
const useCheckSumValue = options?.useCheckSum ?? this._useCheckSum;
|
|
242
|
+
const useModifiedTimeValue = options?.useModifiedTime ?? this._useModifiedTime;
|
|
188
243
|
try {
|
|
189
244
|
fstat = fs.statSync(filePath);
|
|
190
245
|
result.meta = {
|
|
@@ -217,7 +272,10 @@ var FileEntryCache = class {
|
|
|
217
272
|
if (result.meta.data === void 0) {
|
|
218
273
|
result.meta.data = metaCache.data;
|
|
219
274
|
}
|
|
220
|
-
if (metaCache?.mtime !== result.meta?.mtime
|
|
275
|
+
if (useModifiedTimeValue && metaCache?.mtime !== result.meta?.mtime) {
|
|
276
|
+
result.changed = true;
|
|
277
|
+
}
|
|
278
|
+
if (metaCache?.size !== result.meta?.size) {
|
|
221
279
|
result.changed = true;
|
|
222
280
|
}
|
|
223
281
|
if (useCheckSumValue && metaCache?.hash !== result.meta?.hash) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "file-entry-cache",
|
|
3
|
-
"version": "10.0
|
|
3
|
+
"version": "10.1.0",
|
|
4
4
|
"description": "A lightweight cache for file metadata, ideal for processes that work on a specific set of files and only need to reprocess files that have changed since the last run",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -29,16 +29,16 @@
|
|
|
29
29
|
"cache"
|
|
30
30
|
],
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@types/node": "^22.
|
|
33
|
-
"@vitest/coverage-v8": "^3.
|
|
32
|
+
"@types/node": "^22.15.8",
|
|
33
|
+
"@vitest/coverage-v8": "^3.1.3",
|
|
34
34
|
"rimraf": "^6.0.1",
|
|
35
35
|
"tsup": "^8.4.0",
|
|
36
|
-
"typescript": "^5.8.
|
|
37
|
-
"vitest": "^3.
|
|
36
|
+
"typescript": "^5.8.3",
|
|
37
|
+
"vitest": "^3.1.3",
|
|
38
38
|
"xo": "^0.60.0"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"flat-cache": "^6.1.
|
|
41
|
+
"flat-cache": "^6.1.9"
|
|
42
42
|
},
|
|
43
43
|
"files": [
|
|
44
44
|
"dist",
|