file-entry-cache 10.1.3 → 11.0.0-beta.1
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 +81 -38
- package/dist/index.cjs +31 -70
- package/dist/index.d.cts +20 -40
- package/dist/index.d.ts +20 -40
- package/dist/index.js +35 -71
- package/package.json +9 -8
package/README.md
CHANGED
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
- Ideal for processes that work on a specific set of files
|
|
16
16
|
- Persists cache to Disk via `reconcile()` or `persistInterval` on `cache` options.
|
|
17
17
|
- Uses `checksum` to determine if a file has changed
|
|
18
|
-
- Supports `relative` and `absolute` paths
|
|
19
|
-
-
|
|
18
|
+
- Supports `relative` and `absolute` paths - paths are stored exactly as provided
|
|
19
|
+
- Portable cache files when using relative paths
|
|
20
20
|
- ESM and CommonJS support with Typescript
|
|
21
21
|
|
|
22
22
|
# Table of Contents
|
|
@@ -43,24 +43,30 @@ npm install file-entry-cache
|
|
|
43
43
|
```javascript
|
|
44
44
|
import fileEntryCache from 'file-entry-cache';
|
|
45
45
|
const cache = fileEntryCache.create('cache1');
|
|
46
|
-
|
|
46
|
+
|
|
47
|
+
// Using relative paths
|
|
48
|
+
let fileDescriptor = cache.getFileDescriptor('./src/file.txt');
|
|
47
49
|
console.log(fileDescriptor.changed); // true as it is the first time
|
|
48
|
-
fileDescriptor
|
|
50
|
+
console.log(fileDescriptor.key); // './src/file.txt' (stored as provided)
|
|
51
|
+
|
|
52
|
+
fileDescriptor = cache.getFileDescriptor('./src/file.txt');
|
|
49
53
|
console.log(fileDescriptor.changed); // false as it has not changed
|
|
54
|
+
|
|
50
55
|
// do something to change the file
|
|
51
|
-
fs.writeFileSync('file.txt', 'new data foo bar');
|
|
56
|
+
fs.writeFileSync('./src/file.txt', 'new data foo bar');
|
|
57
|
+
|
|
52
58
|
// check if the file has changed
|
|
53
|
-
fileDescriptor = cache.getFileDescriptor('file.txt');
|
|
59
|
+
fileDescriptor = cache.getFileDescriptor('./src/file.txt');
|
|
54
60
|
console.log(fileDescriptor.changed); // true
|
|
55
61
|
```
|
|
56
62
|
|
|
57
|
-
Save it to Disk and
|
|
63
|
+
Save it to Disk and Reconcile files that are no longer found
|
|
58
64
|
```javascript
|
|
59
65
|
import fileEntryCache from 'file-entry-cache';
|
|
60
66
|
const cache = fileEntryCache.create('cache1');
|
|
61
|
-
let fileDescriptor = cache.getFileDescriptor('file.txt');
|
|
67
|
+
let fileDescriptor = cache.getFileDescriptor('./src/file.txt');
|
|
62
68
|
console.log(fileDescriptor.changed); // true as it is the first time
|
|
63
|
-
|
|
69
|
+
cache.reconcile(); // save the cache to disk and remove files that are no longer found
|
|
64
70
|
```
|
|
65
71
|
|
|
66
72
|
Load the cache from a file:
|
|
@@ -68,30 +74,63 @@ Load the cache from a file:
|
|
|
68
74
|
```javascript
|
|
69
75
|
import fileEntryCache from 'file-entry-cache';
|
|
70
76
|
const cache = fileEntryCache.createFromFile('/path/to/cache/file');
|
|
71
|
-
let fileDescriptor = cache.getFileDescriptor('file.txt');
|
|
77
|
+
let fileDescriptor = cache.getFileDescriptor('./src/file.txt');
|
|
72
78
|
console.log(fileDescriptor.changed); // false as it has not changed from the saved cache.
|
|
73
79
|
```
|
|
74
80
|
|
|
81
|
+
## Migration Guide from v10 to v11
|
|
82
|
+
|
|
83
|
+
The main breaking change is the removal of `currentWorkingDirectory`. Here's how to update your code:
|
|
84
|
+
|
|
85
|
+
**Before (v10):**
|
|
86
|
+
```javascript
|
|
87
|
+
const cache = new FileEntryCache({
|
|
88
|
+
currentWorkingDirectory: '/project/root'
|
|
89
|
+
});
|
|
90
|
+
// This would store the key as 'src/file.js'
|
|
91
|
+
cache.getFileDescriptor('/project/root/src/file.js');
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**After (v11):**
|
|
95
|
+
```javascript
|
|
96
|
+
const cache = new FileEntryCache();
|
|
97
|
+
// Now stores the key exactly as provided
|
|
98
|
+
cache.getFileDescriptor('./src/file.js'); // Key: './src/file.js'
|
|
99
|
+
cache.getFileDescriptor('/project/root/src/file.js'); // Key: '/project/root/src/file.js'
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
If you were using absolute paths with `currentWorkingDirectory`, you'll need to update your code to use relative paths if you want portable cache files.
|
|
103
|
+
|
|
104
|
+
# Changes from v10 to v11
|
|
105
|
+
|
|
106
|
+
**BREAKING CHANGES:**
|
|
107
|
+
- **Removed `currentWorkingDirectory`** - This option has been completely removed from the API. Paths are now stored exactly as provided (relative or absolute).
|
|
108
|
+
- **Path handling changes** - The cache now stores paths exactly as they are provided:
|
|
109
|
+
- Relative paths remain relative in the cache
|
|
110
|
+
- Absolute paths remain absolute in the cache
|
|
111
|
+
- The same file accessed with different path formats will create separate cache entries
|
|
112
|
+
- **Renamed method** - `renameAbsolutePathKeys()` is now `renameCacheKeys()` to reflect that it works with any path format
|
|
113
|
+
- **Simplified API** - Removed `currentWorkingDirectory` parameter from all methods including `getFileDescriptor()`, `removeEntry()`, and factory functions
|
|
114
|
+
|
|
115
|
+
These changes make cache files portable when using relative paths, and simplify the API by removing path manipulation logic.
|
|
116
|
+
|
|
75
117
|
# Changes from v9 to v10
|
|
76
118
|
|
|
77
119
|
There have been many features added and changes made to the `file-entry-cache` class. Here are the main changes:
|
|
78
120
|
- Added `cache` object to the options to allow for more control over the cache
|
|
79
|
-
- Added `hashAlgorithm` to the options to allow for different checksum algorithms. Note that if you load from file it most likely will break if the value was something before.
|
|
80
|
-
- Updated more on using Relative or Absolute paths. We now support both on `getFileDescriptor()`. You can read more on this in the `Get File Descriptor` section.
|
|
121
|
+
- Added `hashAlgorithm` to the options to allow for different checksum algorithms. Note that if you load from file it most likely will break if the value was something before.
|
|
81
122
|
- Migrated to Typescript with ESM and CommonJS support. This allows for better type checking and support for both ESM and CommonJS.
|
|
82
|
-
- Once options are passed in they get assigned as properties such as `hashAlgorithm
|
|
123
|
+
- Once options are passed in they get assigned as properties such as `hashAlgorithm`. For the Cache options they are assigned to `cache` such as `cache.ttl` and `cache.lruSize`.
|
|
83
124
|
- Added `cache.persistInterval` to allow for saving the cache to disk at a specific interval. This will save the cache to disk at the interval specified instead of calling `reconsile()` to save. (`off` by default)
|
|
84
125
|
- Added `getFileDescriptorsByPath(filePath: string): FileEntryDescriptor[]` to get all the file descriptors that start with the path specified. This is useful when you want to get all the files in a directory or a specific path.
|
|
85
|
-
- Added `renameAbsolutePathKeys(oldPath: string, newPath: string): void` will rename the keys in the cache from the old path to the new path. This is useful when you rename a directory and want to update the cache without reanalyzing the files.
|
|
86
126
|
- Using `flat-cache` v6 which is a major update. This allows for better performance and more control over the cache.
|
|
87
127
|
- On `FileEntryDescriptor.meta` if using typescript you need to use the `meta.data` to set additional information. This is to allow for better type checking and to avoid conflicts with the `meta` object which was `any`.
|
|
88
128
|
|
|
89
129
|
# Global Default Functions
|
|
90
|
-
- `create(cacheId: string, cacheDirectory?: string, useCheckSum?: boolean
|
|
91
|
-
- `createFromFile(cachePath: string, useCheckSum?: boolean
|
|
130
|
+
- `create(cacheId: string, cacheDirectory?: string, useCheckSum?: boolean)` - Creates a new instance of the `FileEntryCache` class
|
|
131
|
+
- `createFromFile(cachePath: string, useCheckSum?: boolean)` - Creates a new instance of the `FileEntryCache` class and loads the cache from a file.
|
|
92
132
|
|
|
93
133
|
# FileEntryCache Options (FileEntryCacheOptions)
|
|
94
|
-
- `currentWorkingDirectory?` - The current working directory. Used when resolving relative paths.
|
|
95
134
|
- `useModifiedTime?` - If `true` it will use the modified time to determine if the file has changed. Default is `true`
|
|
96
135
|
- `useCheckSum?` - If `true` it will use a checksum to determine if the file has changed. Default is `false`
|
|
97
136
|
- `hashAlgorithm?` - The algorithm to use for the checksum. Default is `md5` but can be any algorithm supported by `crypto.createHash`
|
|
@@ -110,49 +149,53 @@ There have been many features added and changes made to the `file-entry-cache` c
|
|
|
110
149
|
- `constructor(options?: FileEntryCacheOptions)` - Creates a new instance of the `FileEntryCache` class
|
|
111
150
|
- `useCheckSum: boolean` - If `true` it will use a checksum to determine if the file has changed. Default is `false`
|
|
112
151
|
- `hashAlgorithm: string` - The algorithm to use for the checksum. Default is `md5` but can be any algorithm supported by `crypto.createHash`
|
|
113
|
-
- `currentWorkingDirectory: string` - The current working directory. Used when resolving relative paths.
|
|
114
152
|
- `getHash(buffer: Buffer): string` - Gets the hash of a buffer used for checksums
|
|
115
|
-
- `createFileKey(filePath: string): string` -
|
|
116
|
-
- `deleteCacheFile(
|
|
117
|
-
- `destroy(): void` - Destroys the cache. This will
|
|
118
|
-
- `removeEntry(filePath: string): void` - Removes an entry from the cache
|
|
153
|
+
- `createFileKey(filePath: string): string` - Returns the cache key for the file path (returns the path exactly as provided).
|
|
154
|
+
- `deleteCacheFile(): boolean` - Deletes the cache file from disk
|
|
155
|
+
- `destroy(): void` - Destroys the cache. This will clear the cache in memory. If using cache persistence it will stop the interval.
|
|
156
|
+
- `removeEntry(filePath: string): void` - Removes an entry from the cache using the exact path provided.
|
|
119
157
|
- `reconcile(): void` - Saves the cache to disk and removes any files that are no longer found.
|
|
120
158
|
- `hasFileChanged(filePath: string): boolean` - Checks if the file has changed. This will return `true` if the file has changed.
|
|
121
|
-
- `getFileDescriptor(filePath: string, options?: { useModifiedTime?: boolean, useCheckSum?: boolean
|
|
159
|
+
- `getFileDescriptor(filePath: string, options?: { useModifiedTime?: boolean, useCheckSum?: boolean }): FileEntryDescriptor` - Gets the file descriptor for the file. Please refer to the entire section on `Get File Descriptor` for more information.
|
|
122
160
|
- `normalizeEntries(entries: FileEntryDescriptor[]): FileEntryDescriptor[]` - Normalizes the entries to have the correct paths. This is used when loading the cache from disk.
|
|
123
161
|
- `analyzeFiles(files: string[])` will return `AnalyzedFiles` object with `changedFiles`, `notFoundFiles`, and `notChangedFiles` as FileDescriptor arrays.
|
|
124
162
|
- `getUpdatedFiles(files: string[])` will return an array of `FileEntryDescriptor` objects that have changed.
|
|
125
|
-
- `getFileDescriptorsByPath(filePath: string): FileEntryDescriptor[]` will return an array of `FileEntryDescriptor` objects that starts with the path specified.
|
|
126
|
-
- `renameAbsolutePathKeys(oldPath: string, newPath: string): void` - Renames the keys in the cache from the old path to the new path. This is useful when you rename a directory and want to update the cache without reanalyzing the files.
|
|
163
|
+
- `getFileDescriptorsByPath(filePath: string): FileEntryDescriptor[]` will return an array of `FileEntryDescriptor` objects that starts with the path prefix specified.
|
|
127
164
|
|
|
128
165
|
# Get File Descriptor
|
|
129
166
|
|
|
130
|
-
The `getFileDescriptor(filePath: string, options?: { useCheckSum?: boolean,
|
|
167
|
+
The `getFileDescriptor(filePath: string, options?: { useCheckSum?: boolean, useModifiedTime?: boolean }): FileEntryDescriptor` function is used to get the file descriptor for the file. This function will return a `FileEntryDescriptor` object that has the following properties:
|
|
131
168
|
|
|
132
|
-
- `key: string` - The key for the file. This is the
|
|
169
|
+
- `key: string` - The cache key for the file. This is exactly the path that was provided (relative or absolute).
|
|
133
170
|
- `changed: boolean` - If the file has changed since the last time it was analyzed.
|
|
134
171
|
- `notFound: boolean` - If the file was not found.
|
|
135
|
-
- `meta: FileEntryMeta` - The meta data for the file. This has the following
|
|
172
|
+
- `meta: FileEntryMeta` - The meta data for the file. This has the following properties: `size`, `mtime`, `hash`, `data`. Note that `data` is an object that can be used to store additional information.
|
|
136
173
|
- `err` - If there was an error analyzing the file.
|
|
137
174
|
|
|
138
|
-
|
|
175
|
+
## Path Handling
|
|
139
176
|
|
|
140
|
-
|
|
177
|
+
The cache stores paths exactly as they are provided:
|
|
178
|
+
|
|
179
|
+
- **Relative paths** remain relative in the cache
|
|
180
|
+
- **Absolute paths** remain absolute in the cache
|
|
181
|
+
- The same file accessed with different path formats creates **separate cache entries**
|
|
141
182
|
|
|
142
183
|
```javascript
|
|
143
184
|
const fileEntryCache = new FileEntryCache();
|
|
144
|
-
const fileDescriptor = fileEntryCache.getFileDescriptor('file.txt', { currentWorkingDirectory: '/path/to/directory' });
|
|
145
|
-
```
|
|
146
185
|
|
|
147
|
-
|
|
186
|
+
// Using a relative path
|
|
187
|
+
const relativeDescriptor = fileEntryCache.getFileDescriptor('./file.txt');
|
|
188
|
+
console.log(relativeDescriptor.key); // './file.txt'
|
|
148
189
|
|
|
149
|
-
|
|
150
|
-
const
|
|
151
|
-
const
|
|
152
|
-
|
|
190
|
+
// Using an absolute path
|
|
191
|
+
const absolutePath = path.resolve('./file.txt');
|
|
192
|
+
const absoluteDescriptor = fileEntryCache.getFileDescriptor(absolutePath);
|
|
193
|
+
console.log(absoluteDescriptor.key); // '/full/path/to/file.txt'
|
|
194
|
+
|
|
195
|
+
// These create two separate cache entries even though they refer to the same file
|
|
153
196
|
```
|
|
154
197
|
|
|
155
|
-
This
|
|
198
|
+
This behavior makes cache files portable when using relative paths, as they will work correctly when the project is moved to a different location.
|
|
156
199
|
|
|
157
200
|
If there is an error when trying to get the file descriptor it will return an ``notFound` and `err` property with the error.
|
|
158
201
|
|
package/dist/index.cjs
CHANGED
|
@@ -40,14 +40,13 @@ var import_node_crypto = __toESM(require("crypto"), 1);
|
|
|
40
40
|
var import_node_fs = __toESM(require("fs"), 1);
|
|
41
41
|
var import_node_path = __toESM(require("path"), 1);
|
|
42
42
|
var import_flat_cache = require("flat-cache");
|
|
43
|
-
function createFromFile(filePath, useCheckSum
|
|
43
|
+
function createFromFile(filePath, useCheckSum) {
|
|
44
44
|
const fname = import_node_path.default.basename(filePath);
|
|
45
45
|
const directory = import_node_path.default.dirname(filePath);
|
|
46
|
-
return create(fname, directory, useCheckSum
|
|
46
|
+
return create(fname, directory, useCheckSum);
|
|
47
47
|
}
|
|
48
|
-
function create(cacheId, cacheDirectory, useCheckSum
|
|
48
|
+
function create(cacheId, cacheDirectory, useCheckSum) {
|
|
49
49
|
const options = {
|
|
50
|
-
currentWorkingDirectory,
|
|
51
50
|
useCheckSum,
|
|
52
51
|
cache: {
|
|
53
52
|
cacheId,
|
|
@@ -71,7 +70,6 @@ var FileEntryCache = class {
|
|
|
71
70
|
_cache = new import_flat_cache.FlatCache({ useClone: false });
|
|
72
71
|
_useCheckSum = false;
|
|
73
72
|
_useModifiedTime = true;
|
|
74
|
-
_currentWorkingDirectory;
|
|
75
73
|
_hashAlgorithm = "md5";
|
|
76
74
|
/**
|
|
77
75
|
* Create a new FileEntryCache instance
|
|
@@ -87,9 +85,6 @@ var FileEntryCache = class {
|
|
|
87
85
|
if (options?.useCheckSum) {
|
|
88
86
|
this._useCheckSum = options.useCheckSum;
|
|
89
87
|
}
|
|
90
|
-
if (options?.currentWorkingDirectory) {
|
|
91
|
-
this._currentWorkingDirectory = options.currentWorkingDirectory;
|
|
92
|
-
}
|
|
93
88
|
if (options?.hashAlgorithm) {
|
|
94
89
|
this._hashAlgorithm = options.hashAlgorithm;
|
|
95
90
|
}
|
|
@@ -150,27 +145,12 @@ var FileEntryCache = class {
|
|
|
150
145
|
set hashAlgorithm(value) {
|
|
151
146
|
this._hashAlgorithm = value;
|
|
152
147
|
}
|
|
153
|
-
/**
|
|
154
|
-
* Get the current working directory
|
|
155
|
-
* @returns {string | undefined} The current working directory
|
|
156
|
-
*/
|
|
157
|
-
get currentWorkingDirectory() {
|
|
158
|
-
return this._currentWorkingDirectory;
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Set the current working directory
|
|
162
|
-
* @param {string | undefined} value - The value to set
|
|
163
|
-
*/
|
|
164
|
-
set currentWorkingDirectory(value) {
|
|
165
|
-
this._currentWorkingDirectory = value;
|
|
166
|
-
}
|
|
167
148
|
/**
|
|
168
149
|
* Given a buffer, calculate md5 hash of its content.
|
|
169
150
|
* @method getHash
|
|
170
151
|
* @param {Buffer} buffer buffer to calculate hash on
|
|
171
152
|
* @return {String} content hash digest
|
|
172
153
|
*/
|
|
173
|
-
// eslint-disable-next-line @typescript-eslint/no-restricted-types
|
|
174
154
|
getHash(buffer) {
|
|
175
155
|
return import_node_crypto.default.createHash(this._hashAlgorithm).update(buffer).digest("hex");
|
|
176
156
|
}
|
|
@@ -180,19 +160,8 @@ var FileEntryCache = class {
|
|
|
180
160
|
* @param {String} filePath
|
|
181
161
|
* @return {String}
|
|
182
162
|
*/
|
|
183
|
-
createFileKey(filePath
|
|
184
|
-
|
|
185
|
-
const currentWorkingDirectory = options?.currentWorkingDirectory ?? this._currentWorkingDirectory;
|
|
186
|
-
if (currentWorkingDirectory && filePath.startsWith(currentWorkingDirectory)) {
|
|
187
|
-
const splitPath = filePath.split(currentWorkingDirectory).pop();
|
|
188
|
-
if (splitPath) {
|
|
189
|
-
result = splitPath;
|
|
190
|
-
if (result.startsWith("/")) {
|
|
191
|
-
result = result.slice(1);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
return result;
|
|
163
|
+
createFileKey(filePath) {
|
|
164
|
+
return filePath;
|
|
196
165
|
}
|
|
197
166
|
/**
|
|
198
167
|
* Check if the file path is a relative path
|
|
@@ -204,17 +173,17 @@ var FileEntryCache = class {
|
|
|
204
173
|
return !import_node_path.default.isAbsolute(filePath);
|
|
205
174
|
}
|
|
206
175
|
/**
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
176
|
+
* Delete the cache file from the disk
|
|
177
|
+
* @method deleteCacheFile
|
|
178
|
+
* @return {boolean} true if the file was deleted, false otherwise
|
|
179
|
+
*/
|
|
211
180
|
deleteCacheFile() {
|
|
212
181
|
return this._cache.removeCacheFile();
|
|
213
182
|
}
|
|
214
183
|
/**
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
184
|
+
* Remove the cache from the file and clear the memory cache
|
|
185
|
+
* @method destroy
|
|
186
|
+
*/
|
|
218
187
|
destroy() {
|
|
219
188
|
this._cache.destroy();
|
|
220
189
|
}
|
|
@@ -223,12 +192,8 @@ var FileEntryCache = class {
|
|
|
223
192
|
* @method removeEntry
|
|
224
193
|
* @param filePath - The file path to remove from the cache
|
|
225
194
|
*/
|
|
226
|
-
removeEntry(filePath
|
|
227
|
-
|
|
228
|
-
filePath = this.getAbsolutePath(filePath, { currentWorkingDirectory: options?.currentWorkingDirectory });
|
|
229
|
-
this._cache.removeKey(this.createFileKey(filePath));
|
|
230
|
-
}
|
|
231
|
-
const key = this.createFileKey(filePath, { currentWorkingDirectory: options?.currentWorkingDirectory });
|
|
195
|
+
removeEntry(filePath) {
|
|
196
|
+
const key = this.createFileKey(filePath);
|
|
232
197
|
this._cache.removeKey(key);
|
|
233
198
|
}
|
|
234
199
|
/**
|
|
@@ -266,7 +231,6 @@ var FileEntryCache = class {
|
|
|
266
231
|
* @param options - The options for getting the file descriptor
|
|
267
232
|
* @returns The file descriptor
|
|
268
233
|
*/
|
|
269
|
-
// eslint-disable-next-line complexity
|
|
270
234
|
getFileDescriptor(filePath, options) {
|
|
271
235
|
let fstat;
|
|
272
236
|
const result = {
|
|
@@ -275,17 +239,17 @@ var FileEntryCache = class {
|
|
|
275
239
|
meta: {}
|
|
276
240
|
};
|
|
277
241
|
result.meta = this._cache.getKey(result.key) ?? {};
|
|
278
|
-
|
|
242
|
+
const absolutePath = this.getAbsolutePath(filePath);
|
|
279
243
|
const useCheckSumValue = options?.useCheckSum ?? this._useCheckSum;
|
|
280
244
|
const useModifiedTimeValue = options?.useModifiedTime ?? this._useModifiedTime;
|
|
281
245
|
try {
|
|
282
|
-
fstat = import_node_fs.default.statSync(
|
|
246
|
+
fstat = import_node_fs.default.statSync(absolutePath);
|
|
283
247
|
result.meta = {
|
|
284
248
|
size: fstat.size
|
|
285
249
|
};
|
|
286
250
|
result.meta.mtime = fstat.mtime.getTime();
|
|
287
251
|
if (useCheckSumValue) {
|
|
288
|
-
const buffer = import_node_fs.default.readFileSync(
|
|
252
|
+
const buffer = import_node_fs.default.readFileSync(absolutePath);
|
|
289
253
|
result.meta.hash = this.getHash(buffer);
|
|
290
254
|
}
|
|
291
255
|
} catch (error) {
|
|
@@ -329,7 +293,7 @@ var FileEntryCache = class {
|
|
|
329
293
|
* @returns The file descriptors
|
|
330
294
|
*/
|
|
331
295
|
normalizeEntries(files) {
|
|
332
|
-
const result =
|
|
296
|
+
const result = [];
|
|
333
297
|
if (files) {
|
|
334
298
|
for (const file of files) {
|
|
335
299
|
const fileDescriptor = this.getFileDescriptor(file);
|
|
@@ -377,7 +341,7 @@ var FileEntryCache = class {
|
|
|
377
341
|
* @returns {string[]} The updated files
|
|
378
342
|
*/
|
|
379
343
|
getUpdatedFiles(files) {
|
|
380
|
-
const result =
|
|
344
|
+
const result = [];
|
|
381
345
|
const fileDescriptors = this.normalizeEntries(files);
|
|
382
346
|
for (const fileDescriptor of fileDescriptors) {
|
|
383
347
|
if (fileDescriptor.changed) {
|
|
@@ -387,17 +351,16 @@ var FileEntryCache = class {
|
|
|
387
351
|
return result;
|
|
388
352
|
}
|
|
389
353
|
/**
|
|
390
|
-
* Get the
|
|
354
|
+
* Get the file descriptors by path prefix
|
|
391
355
|
* @method getFileDescriptorsByPath
|
|
392
|
-
* @param filePath - the
|
|
393
|
-
* @returns {FileDescriptor[]} The
|
|
356
|
+
* @param filePath - the path prefix to match
|
|
357
|
+
* @returns {FileDescriptor[]} The file descriptors
|
|
394
358
|
*/
|
|
395
359
|
getFileDescriptorsByPath(filePath) {
|
|
396
|
-
const result =
|
|
360
|
+
const result = [];
|
|
397
361
|
const keys = this._cache.keys();
|
|
398
362
|
for (const key of keys) {
|
|
399
|
-
|
|
400
|
-
if (absolutePath.startsWith(filePath)) {
|
|
363
|
+
if (key.startsWith(filePath)) {
|
|
401
364
|
const fileDescriptor = this.getFileDescriptor(key);
|
|
402
365
|
result.push(fileDescriptor);
|
|
403
366
|
}
|
|
@@ -408,23 +371,21 @@ var FileEntryCache = class {
|
|
|
408
371
|
* Get the Absolute Path. If it is already absolute it will return the path as is.
|
|
409
372
|
* @method getAbsolutePath
|
|
410
373
|
* @param filePath - The file path to get the absolute path for
|
|
411
|
-
* @param options - The options for getting the absolute path. The current working directory is used if not provided.
|
|
412
374
|
* @returns {string}
|
|
413
375
|
*/
|
|
414
|
-
getAbsolutePath(filePath
|
|
376
|
+
getAbsolutePath(filePath) {
|
|
415
377
|
if (this.isRelativePath(filePath)) {
|
|
416
|
-
|
|
417
|
-
filePath = import_node_path.default.resolve(currentWorkingDirectory, filePath);
|
|
378
|
+
return import_node_path.default.resolve(process.cwd(), filePath);
|
|
418
379
|
}
|
|
419
380
|
return filePath;
|
|
420
381
|
}
|
|
421
382
|
/**
|
|
422
|
-
* Rename
|
|
423
|
-
* @method
|
|
424
|
-
* @param oldPath - The old path to rename
|
|
425
|
-
* @param newPath - The new path to rename to
|
|
383
|
+
* Rename cache keys that start with a given path prefix.
|
|
384
|
+
* @method renameCacheKeys
|
|
385
|
+
* @param oldPath - The old path prefix to rename
|
|
386
|
+
* @param newPath - The new path prefix to rename to
|
|
426
387
|
*/
|
|
427
|
-
|
|
388
|
+
renameCacheKeys(oldPath, newPath) {
|
|
428
389
|
const keys = this._cache.keys();
|
|
429
390
|
for (const key of keys) {
|
|
430
391
|
if (key.startsWith(oldPath)) {
|
package/dist/index.d.cts
CHANGED
|
@@ -2,7 +2,6 @@ import { Buffer } from 'node:buffer';
|
|
|
2
2
|
import { FlatCacheOptions, FlatCache } from 'flat-cache';
|
|
3
3
|
|
|
4
4
|
type FileEntryCacheOptions = {
|
|
5
|
-
currentWorkingDirectory?: string;
|
|
6
5
|
useModifiedTime?: boolean;
|
|
7
6
|
useCheckSum?: boolean;
|
|
8
7
|
hashAlgorithm?: string;
|
|
@@ -11,7 +10,6 @@ type FileEntryCacheOptions = {
|
|
|
11
10
|
type GetFileDescriptorOptions = {
|
|
12
11
|
useCheckSum?: boolean;
|
|
13
12
|
useModifiedTime?: boolean;
|
|
14
|
-
currentWorkingDirectory?: string;
|
|
15
13
|
};
|
|
16
14
|
type FileDescriptor = {
|
|
17
15
|
key: string;
|
|
@@ -31,8 +29,8 @@ type AnalyzedFiles = {
|
|
|
31
29
|
notFoundFiles: string[];
|
|
32
30
|
notChangedFiles: string[];
|
|
33
31
|
};
|
|
34
|
-
declare function createFromFile(filePath: string, useCheckSum?: boolean
|
|
35
|
-
declare function create(cacheId: string, cacheDirectory?: string, useCheckSum?: boolean
|
|
32
|
+
declare function createFromFile(filePath: string, useCheckSum?: boolean): FileEntryCache;
|
|
33
|
+
declare function create(cacheId: string, cacheDirectory?: string, useCheckSum?: boolean): FileEntryCache;
|
|
36
34
|
declare class FileEntryDefault {
|
|
37
35
|
static create: typeof create;
|
|
38
36
|
static createFromFile: typeof createFromFile;
|
|
@@ -41,7 +39,6 @@ declare class FileEntryCache {
|
|
|
41
39
|
private _cache;
|
|
42
40
|
private _useCheckSum;
|
|
43
41
|
private _useModifiedTime;
|
|
44
|
-
private _currentWorkingDirectory;
|
|
45
42
|
private _hashAlgorithm;
|
|
46
43
|
/**
|
|
47
44
|
* Create a new FileEntryCache instance
|
|
@@ -88,16 +85,6 @@ declare class FileEntryCache {
|
|
|
88
85
|
* @param {string} value - The value to set
|
|
89
86
|
*/
|
|
90
87
|
set hashAlgorithm(value: string);
|
|
91
|
-
/**
|
|
92
|
-
* Get the current working directory
|
|
93
|
-
* @returns {string | undefined} The current working directory
|
|
94
|
-
*/
|
|
95
|
-
get currentWorkingDirectory(): string | undefined;
|
|
96
|
-
/**
|
|
97
|
-
* Set the current working directory
|
|
98
|
-
* @param {string | undefined} value - The value to set
|
|
99
|
-
*/
|
|
100
|
-
set currentWorkingDirectory(value: string | undefined);
|
|
101
88
|
/**
|
|
102
89
|
* Given a buffer, calculate md5 hash of its content.
|
|
103
90
|
* @method getHash
|
|
@@ -111,9 +98,7 @@ declare class FileEntryCache {
|
|
|
111
98
|
* @param {String} filePath
|
|
112
99
|
* @return {String}
|
|
113
100
|
*/
|
|
114
|
-
createFileKey(filePath: string
|
|
115
|
-
currentWorkingDirectory?: string;
|
|
116
|
-
}): string;
|
|
101
|
+
createFileKey(filePath: string): string;
|
|
117
102
|
/**
|
|
118
103
|
* Check if the file path is a relative path
|
|
119
104
|
* @method isRelativePath
|
|
@@ -122,24 +107,22 @@ declare class FileEntryCache {
|
|
|
122
107
|
*/
|
|
123
108
|
isRelativePath(filePath: string): boolean;
|
|
124
109
|
/**
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
110
|
+
* Delete the cache file from the disk
|
|
111
|
+
* @method deleteCacheFile
|
|
112
|
+
* @return {boolean} true if the file was deleted, false otherwise
|
|
113
|
+
*/
|
|
129
114
|
deleteCacheFile(): boolean;
|
|
130
115
|
/**
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
116
|
+
* Remove the cache from the file and clear the memory cache
|
|
117
|
+
* @method destroy
|
|
118
|
+
*/
|
|
134
119
|
destroy(): void;
|
|
135
120
|
/**
|
|
136
121
|
* Remove and Entry From the Cache
|
|
137
122
|
* @method removeEntry
|
|
138
123
|
* @param filePath - The file path to remove from the cache
|
|
139
124
|
*/
|
|
140
|
-
removeEntry(filePath: string
|
|
141
|
-
currentWorkingDirectory?: string;
|
|
142
|
-
}): void;
|
|
125
|
+
removeEntry(filePath: string): void;
|
|
143
126
|
/**
|
|
144
127
|
* Reconcile the cache
|
|
145
128
|
* @method reconcile
|
|
@@ -182,29 +165,26 @@ declare class FileEntryCache {
|
|
|
182
165
|
*/
|
|
183
166
|
getUpdatedFiles(files: string[]): string[];
|
|
184
167
|
/**
|
|
185
|
-
* Get the
|
|
168
|
+
* Get the file descriptors by path prefix
|
|
186
169
|
* @method getFileDescriptorsByPath
|
|
187
|
-
* @param filePath - the
|
|
188
|
-
* @returns {FileDescriptor[]} The
|
|
170
|
+
* @param filePath - the path prefix to match
|
|
171
|
+
* @returns {FileDescriptor[]} The file descriptors
|
|
189
172
|
*/
|
|
190
173
|
getFileDescriptorsByPath(filePath: string): FileDescriptor[];
|
|
191
174
|
/**
|
|
192
175
|
* Get the Absolute Path. If it is already absolute it will return the path as is.
|
|
193
176
|
* @method getAbsolutePath
|
|
194
177
|
* @param filePath - The file path to get the absolute path for
|
|
195
|
-
* @param options - The options for getting the absolute path. The current working directory is used if not provided.
|
|
196
178
|
* @returns {string}
|
|
197
179
|
*/
|
|
198
|
-
getAbsolutePath(filePath: string
|
|
199
|
-
currentWorkingDirectory?: string;
|
|
200
|
-
}): string;
|
|
180
|
+
getAbsolutePath(filePath: string): string;
|
|
201
181
|
/**
|
|
202
|
-
* Rename
|
|
203
|
-
* @method
|
|
204
|
-
* @param oldPath - The old path to rename
|
|
205
|
-
* @param newPath - The new path to rename to
|
|
182
|
+
* Rename cache keys that start with a given path prefix.
|
|
183
|
+
* @method renameCacheKeys
|
|
184
|
+
* @param oldPath - The old path prefix to rename
|
|
185
|
+
* @param newPath - The new path prefix to rename to
|
|
206
186
|
*/
|
|
207
|
-
|
|
187
|
+
renameCacheKeys(oldPath: string, newPath: string): void;
|
|
208
188
|
}
|
|
209
189
|
|
|
210
190
|
export { type AnalyzedFiles, type FileDescriptor, type FileDescriptorMeta, FileEntryCache, type FileEntryCacheOptions, type GetFileDescriptorOptions, create, createFromFile, FileEntryDefault as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { Buffer } from 'node:buffer';
|
|
|
2
2
|
import { FlatCacheOptions, FlatCache } from 'flat-cache';
|
|
3
3
|
|
|
4
4
|
type FileEntryCacheOptions = {
|
|
5
|
-
currentWorkingDirectory?: string;
|
|
6
5
|
useModifiedTime?: boolean;
|
|
7
6
|
useCheckSum?: boolean;
|
|
8
7
|
hashAlgorithm?: string;
|
|
@@ -11,7 +10,6 @@ type FileEntryCacheOptions = {
|
|
|
11
10
|
type GetFileDescriptorOptions = {
|
|
12
11
|
useCheckSum?: boolean;
|
|
13
12
|
useModifiedTime?: boolean;
|
|
14
|
-
currentWorkingDirectory?: string;
|
|
15
13
|
};
|
|
16
14
|
type FileDescriptor = {
|
|
17
15
|
key: string;
|
|
@@ -31,8 +29,8 @@ type AnalyzedFiles = {
|
|
|
31
29
|
notFoundFiles: string[];
|
|
32
30
|
notChangedFiles: string[];
|
|
33
31
|
};
|
|
34
|
-
declare function createFromFile(filePath: string, useCheckSum?: boolean
|
|
35
|
-
declare function create(cacheId: string, cacheDirectory?: string, useCheckSum?: boolean
|
|
32
|
+
declare function createFromFile(filePath: string, useCheckSum?: boolean): FileEntryCache;
|
|
33
|
+
declare function create(cacheId: string, cacheDirectory?: string, useCheckSum?: boolean): FileEntryCache;
|
|
36
34
|
declare class FileEntryDefault {
|
|
37
35
|
static create: typeof create;
|
|
38
36
|
static createFromFile: typeof createFromFile;
|
|
@@ -41,7 +39,6 @@ declare class FileEntryCache {
|
|
|
41
39
|
private _cache;
|
|
42
40
|
private _useCheckSum;
|
|
43
41
|
private _useModifiedTime;
|
|
44
|
-
private _currentWorkingDirectory;
|
|
45
42
|
private _hashAlgorithm;
|
|
46
43
|
/**
|
|
47
44
|
* Create a new FileEntryCache instance
|
|
@@ -88,16 +85,6 @@ declare class FileEntryCache {
|
|
|
88
85
|
* @param {string} value - The value to set
|
|
89
86
|
*/
|
|
90
87
|
set hashAlgorithm(value: string);
|
|
91
|
-
/**
|
|
92
|
-
* Get the current working directory
|
|
93
|
-
* @returns {string | undefined} The current working directory
|
|
94
|
-
*/
|
|
95
|
-
get currentWorkingDirectory(): string | undefined;
|
|
96
|
-
/**
|
|
97
|
-
* Set the current working directory
|
|
98
|
-
* @param {string | undefined} value - The value to set
|
|
99
|
-
*/
|
|
100
|
-
set currentWorkingDirectory(value: string | undefined);
|
|
101
88
|
/**
|
|
102
89
|
* Given a buffer, calculate md5 hash of its content.
|
|
103
90
|
* @method getHash
|
|
@@ -111,9 +98,7 @@ declare class FileEntryCache {
|
|
|
111
98
|
* @param {String} filePath
|
|
112
99
|
* @return {String}
|
|
113
100
|
*/
|
|
114
|
-
createFileKey(filePath: string
|
|
115
|
-
currentWorkingDirectory?: string;
|
|
116
|
-
}): string;
|
|
101
|
+
createFileKey(filePath: string): string;
|
|
117
102
|
/**
|
|
118
103
|
* Check if the file path is a relative path
|
|
119
104
|
* @method isRelativePath
|
|
@@ -122,24 +107,22 @@ declare class FileEntryCache {
|
|
|
122
107
|
*/
|
|
123
108
|
isRelativePath(filePath: string): boolean;
|
|
124
109
|
/**
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
110
|
+
* Delete the cache file from the disk
|
|
111
|
+
* @method deleteCacheFile
|
|
112
|
+
* @return {boolean} true if the file was deleted, false otherwise
|
|
113
|
+
*/
|
|
129
114
|
deleteCacheFile(): boolean;
|
|
130
115
|
/**
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
116
|
+
* Remove the cache from the file and clear the memory cache
|
|
117
|
+
* @method destroy
|
|
118
|
+
*/
|
|
134
119
|
destroy(): void;
|
|
135
120
|
/**
|
|
136
121
|
* Remove and Entry From the Cache
|
|
137
122
|
* @method removeEntry
|
|
138
123
|
* @param filePath - The file path to remove from the cache
|
|
139
124
|
*/
|
|
140
|
-
removeEntry(filePath: string
|
|
141
|
-
currentWorkingDirectory?: string;
|
|
142
|
-
}): void;
|
|
125
|
+
removeEntry(filePath: string): void;
|
|
143
126
|
/**
|
|
144
127
|
* Reconcile the cache
|
|
145
128
|
* @method reconcile
|
|
@@ -182,29 +165,26 @@ declare class FileEntryCache {
|
|
|
182
165
|
*/
|
|
183
166
|
getUpdatedFiles(files: string[]): string[];
|
|
184
167
|
/**
|
|
185
|
-
* Get the
|
|
168
|
+
* Get the file descriptors by path prefix
|
|
186
169
|
* @method getFileDescriptorsByPath
|
|
187
|
-
* @param filePath - the
|
|
188
|
-
* @returns {FileDescriptor[]} The
|
|
170
|
+
* @param filePath - the path prefix to match
|
|
171
|
+
* @returns {FileDescriptor[]} The file descriptors
|
|
189
172
|
*/
|
|
190
173
|
getFileDescriptorsByPath(filePath: string): FileDescriptor[];
|
|
191
174
|
/**
|
|
192
175
|
* Get the Absolute Path. If it is already absolute it will return the path as is.
|
|
193
176
|
* @method getAbsolutePath
|
|
194
177
|
* @param filePath - The file path to get the absolute path for
|
|
195
|
-
* @param options - The options for getting the absolute path. The current working directory is used if not provided.
|
|
196
178
|
* @returns {string}
|
|
197
179
|
*/
|
|
198
|
-
getAbsolutePath(filePath: string
|
|
199
|
-
currentWorkingDirectory?: string;
|
|
200
|
-
}): string;
|
|
180
|
+
getAbsolutePath(filePath: string): string;
|
|
201
181
|
/**
|
|
202
|
-
* Rename
|
|
203
|
-
* @method
|
|
204
|
-
* @param oldPath - The old path to rename
|
|
205
|
-
* @param newPath - The new path to rename to
|
|
182
|
+
* Rename cache keys that start with a given path prefix.
|
|
183
|
+
* @method renameCacheKeys
|
|
184
|
+
* @param oldPath - The old path prefix to rename
|
|
185
|
+
* @param newPath - The new path prefix to rename to
|
|
206
186
|
*/
|
|
207
|
-
|
|
187
|
+
renameCacheKeys(oldPath: string, newPath: string): void;
|
|
208
188
|
}
|
|
209
189
|
|
|
210
190
|
export { type AnalyzedFiles, type FileDescriptor, type FileDescriptorMeta, FileEntryCache, type FileEntryCacheOptions, type GetFileDescriptorOptions, create, createFromFile, FileEntryDefault as default };
|
package/dist/index.js
CHANGED
|
@@ -2,15 +2,17 @@
|
|
|
2
2
|
import crypto from "crypto";
|
|
3
3
|
import fs from "fs";
|
|
4
4
|
import path from "path";
|
|
5
|
-
import {
|
|
6
|
-
|
|
5
|
+
import {
|
|
6
|
+
createFromFile as createFlatCacheFile,
|
|
7
|
+
FlatCache
|
|
8
|
+
} from "flat-cache";
|
|
9
|
+
function createFromFile(filePath, useCheckSum) {
|
|
7
10
|
const fname = path.basename(filePath);
|
|
8
11
|
const directory = path.dirname(filePath);
|
|
9
|
-
return create(fname, directory, useCheckSum
|
|
12
|
+
return create(fname, directory, useCheckSum);
|
|
10
13
|
}
|
|
11
|
-
function create(cacheId, cacheDirectory, useCheckSum
|
|
14
|
+
function create(cacheId, cacheDirectory, useCheckSum) {
|
|
12
15
|
const options = {
|
|
13
|
-
currentWorkingDirectory,
|
|
14
16
|
useCheckSum,
|
|
15
17
|
cache: {
|
|
16
18
|
cacheId,
|
|
@@ -34,7 +36,6 @@ var FileEntryCache = class {
|
|
|
34
36
|
_cache = new FlatCache({ useClone: false });
|
|
35
37
|
_useCheckSum = false;
|
|
36
38
|
_useModifiedTime = true;
|
|
37
|
-
_currentWorkingDirectory;
|
|
38
39
|
_hashAlgorithm = "md5";
|
|
39
40
|
/**
|
|
40
41
|
* Create a new FileEntryCache instance
|
|
@@ -50,9 +51,6 @@ var FileEntryCache = class {
|
|
|
50
51
|
if (options?.useCheckSum) {
|
|
51
52
|
this._useCheckSum = options.useCheckSum;
|
|
52
53
|
}
|
|
53
|
-
if (options?.currentWorkingDirectory) {
|
|
54
|
-
this._currentWorkingDirectory = options.currentWorkingDirectory;
|
|
55
|
-
}
|
|
56
54
|
if (options?.hashAlgorithm) {
|
|
57
55
|
this._hashAlgorithm = options.hashAlgorithm;
|
|
58
56
|
}
|
|
@@ -113,27 +111,12 @@ var FileEntryCache = class {
|
|
|
113
111
|
set hashAlgorithm(value) {
|
|
114
112
|
this._hashAlgorithm = value;
|
|
115
113
|
}
|
|
116
|
-
/**
|
|
117
|
-
* Get the current working directory
|
|
118
|
-
* @returns {string | undefined} The current working directory
|
|
119
|
-
*/
|
|
120
|
-
get currentWorkingDirectory() {
|
|
121
|
-
return this._currentWorkingDirectory;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Set the current working directory
|
|
125
|
-
* @param {string | undefined} value - The value to set
|
|
126
|
-
*/
|
|
127
|
-
set currentWorkingDirectory(value) {
|
|
128
|
-
this._currentWorkingDirectory = value;
|
|
129
|
-
}
|
|
130
114
|
/**
|
|
131
115
|
* Given a buffer, calculate md5 hash of its content.
|
|
132
116
|
* @method getHash
|
|
133
117
|
* @param {Buffer} buffer buffer to calculate hash on
|
|
134
118
|
* @return {String} content hash digest
|
|
135
119
|
*/
|
|
136
|
-
// eslint-disable-next-line @typescript-eslint/no-restricted-types
|
|
137
120
|
getHash(buffer) {
|
|
138
121
|
return crypto.createHash(this._hashAlgorithm).update(buffer).digest("hex");
|
|
139
122
|
}
|
|
@@ -143,19 +126,8 @@ var FileEntryCache = class {
|
|
|
143
126
|
* @param {String} filePath
|
|
144
127
|
* @return {String}
|
|
145
128
|
*/
|
|
146
|
-
createFileKey(filePath
|
|
147
|
-
|
|
148
|
-
const currentWorkingDirectory = options?.currentWorkingDirectory ?? this._currentWorkingDirectory;
|
|
149
|
-
if (currentWorkingDirectory && filePath.startsWith(currentWorkingDirectory)) {
|
|
150
|
-
const splitPath = filePath.split(currentWorkingDirectory).pop();
|
|
151
|
-
if (splitPath) {
|
|
152
|
-
result = splitPath;
|
|
153
|
-
if (result.startsWith("/")) {
|
|
154
|
-
result = result.slice(1);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return result;
|
|
129
|
+
createFileKey(filePath) {
|
|
130
|
+
return filePath;
|
|
159
131
|
}
|
|
160
132
|
/**
|
|
161
133
|
* Check if the file path is a relative path
|
|
@@ -167,17 +139,17 @@ var FileEntryCache = class {
|
|
|
167
139
|
return !path.isAbsolute(filePath);
|
|
168
140
|
}
|
|
169
141
|
/**
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
142
|
+
* Delete the cache file from the disk
|
|
143
|
+
* @method deleteCacheFile
|
|
144
|
+
* @return {boolean} true if the file was deleted, false otherwise
|
|
145
|
+
*/
|
|
174
146
|
deleteCacheFile() {
|
|
175
147
|
return this._cache.removeCacheFile();
|
|
176
148
|
}
|
|
177
149
|
/**
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
150
|
+
* Remove the cache from the file and clear the memory cache
|
|
151
|
+
* @method destroy
|
|
152
|
+
*/
|
|
181
153
|
destroy() {
|
|
182
154
|
this._cache.destroy();
|
|
183
155
|
}
|
|
@@ -186,12 +158,8 @@ var FileEntryCache = class {
|
|
|
186
158
|
* @method removeEntry
|
|
187
159
|
* @param filePath - The file path to remove from the cache
|
|
188
160
|
*/
|
|
189
|
-
removeEntry(filePath
|
|
190
|
-
|
|
191
|
-
filePath = this.getAbsolutePath(filePath, { currentWorkingDirectory: options?.currentWorkingDirectory });
|
|
192
|
-
this._cache.removeKey(this.createFileKey(filePath));
|
|
193
|
-
}
|
|
194
|
-
const key = this.createFileKey(filePath, { currentWorkingDirectory: options?.currentWorkingDirectory });
|
|
161
|
+
removeEntry(filePath) {
|
|
162
|
+
const key = this.createFileKey(filePath);
|
|
195
163
|
this._cache.removeKey(key);
|
|
196
164
|
}
|
|
197
165
|
/**
|
|
@@ -229,7 +197,6 @@ var FileEntryCache = class {
|
|
|
229
197
|
* @param options - The options for getting the file descriptor
|
|
230
198
|
* @returns The file descriptor
|
|
231
199
|
*/
|
|
232
|
-
// eslint-disable-next-line complexity
|
|
233
200
|
getFileDescriptor(filePath, options) {
|
|
234
201
|
let fstat;
|
|
235
202
|
const result = {
|
|
@@ -238,17 +205,17 @@ var FileEntryCache = class {
|
|
|
238
205
|
meta: {}
|
|
239
206
|
};
|
|
240
207
|
result.meta = this._cache.getKey(result.key) ?? {};
|
|
241
|
-
|
|
208
|
+
const absolutePath = this.getAbsolutePath(filePath);
|
|
242
209
|
const useCheckSumValue = options?.useCheckSum ?? this._useCheckSum;
|
|
243
210
|
const useModifiedTimeValue = options?.useModifiedTime ?? this._useModifiedTime;
|
|
244
211
|
try {
|
|
245
|
-
fstat = fs.statSync(
|
|
212
|
+
fstat = fs.statSync(absolutePath);
|
|
246
213
|
result.meta = {
|
|
247
214
|
size: fstat.size
|
|
248
215
|
};
|
|
249
216
|
result.meta.mtime = fstat.mtime.getTime();
|
|
250
217
|
if (useCheckSumValue) {
|
|
251
|
-
const buffer = fs.readFileSync(
|
|
218
|
+
const buffer = fs.readFileSync(absolutePath);
|
|
252
219
|
result.meta.hash = this.getHash(buffer);
|
|
253
220
|
}
|
|
254
221
|
} catch (error) {
|
|
@@ -292,7 +259,7 @@ var FileEntryCache = class {
|
|
|
292
259
|
* @returns The file descriptors
|
|
293
260
|
*/
|
|
294
261
|
normalizeEntries(files) {
|
|
295
|
-
const result =
|
|
262
|
+
const result = [];
|
|
296
263
|
if (files) {
|
|
297
264
|
for (const file of files) {
|
|
298
265
|
const fileDescriptor = this.getFileDescriptor(file);
|
|
@@ -340,7 +307,7 @@ var FileEntryCache = class {
|
|
|
340
307
|
* @returns {string[]} The updated files
|
|
341
308
|
*/
|
|
342
309
|
getUpdatedFiles(files) {
|
|
343
|
-
const result =
|
|
310
|
+
const result = [];
|
|
344
311
|
const fileDescriptors = this.normalizeEntries(files);
|
|
345
312
|
for (const fileDescriptor of fileDescriptors) {
|
|
346
313
|
if (fileDescriptor.changed) {
|
|
@@ -350,17 +317,16 @@ var FileEntryCache = class {
|
|
|
350
317
|
return result;
|
|
351
318
|
}
|
|
352
319
|
/**
|
|
353
|
-
* Get the
|
|
320
|
+
* Get the file descriptors by path prefix
|
|
354
321
|
* @method getFileDescriptorsByPath
|
|
355
|
-
* @param filePath - the
|
|
356
|
-
* @returns {FileDescriptor[]} The
|
|
322
|
+
* @param filePath - the path prefix to match
|
|
323
|
+
* @returns {FileDescriptor[]} The file descriptors
|
|
357
324
|
*/
|
|
358
325
|
getFileDescriptorsByPath(filePath) {
|
|
359
|
-
const result =
|
|
326
|
+
const result = [];
|
|
360
327
|
const keys = this._cache.keys();
|
|
361
328
|
for (const key of keys) {
|
|
362
|
-
|
|
363
|
-
if (absolutePath.startsWith(filePath)) {
|
|
329
|
+
if (key.startsWith(filePath)) {
|
|
364
330
|
const fileDescriptor = this.getFileDescriptor(key);
|
|
365
331
|
result.push(fileDescriptor);
|
|
366
332
|
}
|
|
@@ -371,23 +337,21 @@ var FileEntryCache = class {
|
|
|
371
337
|
* Get the Absolute Path. If it is already absolute it will return the path as is.
|
|
372
338
|
* @method getAbsolutePath
|
|
373
339
|
* @param filePath - The file path to get the absolute path for
|
|
374
|
-
* @param options - The options for getting the absolute path. The current working directory is used if not provided.
|
|
375
340
|
* @returns {string}
|
|
376
341
|
*/
|
|
377
|
-
getAbsolutePath(filePath
|
|
342
|
+
getAbsolutePath(filePath) {
|
|
378
343
|
if (this.isRelativePath(filePath)) {
|
|
379
|
-
|
|
380
|
-
filePath = path.resolve(currentWorkingDirectory, filePath);
|
|
344
|
+
return path.resolve(process.cwd(), filePath);
|
|
381
345
|
}
|
|
382
346
|
return filePath;
|
|
383
347
|
}
|
|
384
348
|
/**
|
|
385
|
-
* Rename
|
|
386
|
-
* @method
|
|
387
|
-
* @param oldPath - The old path to rename
|
|
388
|
-
* @param newPath - The new path to rename to
|
|
349
|
+
* Rename cache keys that start with a given path prefix.
|
|
350
|
+
* @method renameCacheKeys
|
|
351
|
+
* @param oldPath - The old path prefix to rename
|
|
352
|
+
* @param newPath - The new path prefix to rename to
|
|
389
353
|
*/
|
|
390
|
-
|
|
354
|
+
renameCacheKeys(oldPath, newPath) {
|
|
391
355
|
const keys = this._cache.keys();
|
|
392
356
|
for (const key of keys) {
|
|
393
357
|
if (key.startsWith(oldPath)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "file-entry-cache",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.0-beta.1",
|
|
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
|
-
"@
|
|
32
|
+
"@biomejs/biome": "^2.2.4",
|
|
33
|
+
"@types/node": "^24.5.0",
|
|
33
34
|
"@vitest/coverage-v8": "^3.2.4",
|
|
34
35
|
"rimraf": "^6.0.1",
|
|
35
36
|
"tsup": "^8.5.0",
|
|
36
|
-
"typescript": "^5.
|
|
37
|
-
"vitest": "^3.2.4"
|
|
38
|
-
"xo": "^1.2.1"
|
|
37
|
+
"typescript": "^5.9.2",
|
|
38
|
+
"vitest": "^3.2.4"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"flat-cache": "^6.1.
|
|
41
|
+
"flat-cache": "^6.1.14"
|
|
42
42
|
},
|
|
43
43
|
"files": [
|
|
44
44
|
"dist",
|
|
@@ -47,8 +47,9 @@
|
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "rimraf ./dist && tsup src/index.ts --format cjs,esm --dts --clean",
|
|
49
49
|
"prepublish": "pnpm build",
|
|
50
|
-
"
|
|
51
|
-
"test
|
|
50
|
+
"lint": "biome check --write --error-on-warnings",
|
|
51
|
+
"test": "pnpm lint && vitest run --coverage",
|
|
52
|
+
"test:ci": "biome check --error-on-warnings && vitest run --coverage",
|
|
52
53
|
"clean": "rimraf ./dist ./coverage ./node_modules"
|
|
53
54
|
}
|
|
54
55
|
}
|