file-entry-cache 10.1.4 → 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 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
- - Ability to rename keys in the cache. Useful when renaming directories.
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
- let fileDescriptor = cache.getFileDescriptor('file.txt');
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 = cache.getFileDescriptor('file.txt');
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 Reconsile files that are no longer found
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
- fileEntryCache.reconcile(); // save the cache to disk and remove files that are no longer found
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` and `currentWorkingDirectory`. This allows for better control and access to the options. For the Cache options they are assigned to `cache` such as `cache.ttl` and `cache.lruSize`.
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, currentWorkingDirectory?: string)` - Creates a new instance of the `FileEntryCache` class
91
- - `createFromFile(cachePath: string, useCheckSum?: boolean, currentWorkingDirectory?: string)` - Creates a new instance of the `FileEntryCache` class and loads the cache from a file.
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` - Creates a key for the file path. This is used to store the data in the cache based on relative or absolute paths.
116
- - `deleteCacheFile(filePath: string): void` - Deletes the cache file
117
- - `destroy(): void` - Destroys the cache. This will also delete the cache file. If using cache persistence it will stop the interval.
118
- - `removeEntry(filePath: string): void` - Removes an entry from the cache. This can be `relative` or `absolute` paths.
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, currentWorkingDirectory?: string }): FileEntryDescriptor` - Gets the file descriptor for the file. Please refer to the entire section on `Get File Descriptor` for more information.
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, currentWorkingDirectory?: string }): FileEntryDescriptor` function is used to get the file descriptor for the file. This function will return a `FileEntryDescriptor` object that has the following properties:
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 relative or absolute path of the file.
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 prperties: `size`, `mtime`, `ctime`, `hash`, `data`. Note that `data` is an object that can be used to store additional information.
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
- We have added the ability to use `relative` or `absolute` paths. If you pass in a `relative` path it will use the `currentWorkingDirectory` to resolve the path. If you pass in an `absolute` path it will use the path as is. This is useful when you want to use `relative` paths but also want to use `absolute` paths.
175
+ ## Path Handling
139
176
 
140
- If you do not pass in `currentWorkingDirectory` in the class options or in the `getFileDescriptor` function it will use the `process.cwd()` as the default `currentWorkingDirectory`.
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
- Since this is a relative path it will use the `currentWorkingDirectory` to resolve the path. If you want to use an absolute path you can do the following:
186
+ // Using a relative path
187
+ const relativeDescriptor = fileEntryCache.getFileDescriptor('./file.txt');
188
+ console.log(relativeDescriptor.key); // './file.txt'
148
189
 
149
- ```javascript
150
- const fileEntryCache = new FileEntryCache();
151
- const filePath = path.resolve('/path/to/directory', 'file.txt');
152
- const fileDescriptor = fileEntryCache.getFileDescriptor(filePath);
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 will save the key as the absolute path.
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, currentWorkingDirectory) {
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, currentWorkingDirectory);
46
+ return create(fname, directory, useCheckSum);
47
47
  }
48
- function create(cacheId, cacheDirectory, useCheckSum, currentWorkingDirectory) {
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,20 +145,6 @@ 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
@@ -179,19 +160,8 @@ var FileEntryCache = class {
179
160
  * @param {String} filePath
180
161
  * @return {String}
181
162
  */
182
- createFileKey(filePath, options) {
183
- let result = filePath;
184
- const currentWorkingDirectory = options?.currentWorkingDirectory ?? this._currentWorkingDirectory;
185
- if (currentWorkingDirectory && filePath.startsWith(currentWorkingDirectory)) {
186
- const splitPath = filePath.split(currentWorkingDirectory).pop();
187
- if (splitPath) {
188
- result = splitPath;
189
- if (result.startsWith("/")) {
190
- result = result.slice(1);
191
- }
192
- }
193
- }
194
- return result;
163
+ createFileKey(filePath) {
164
+ return filePath;
195
165
  }
196
166
  /**
197
167
  * Check if the file path is a relative path
@@ -222,16 +192,8 @@ var FileEntryCache = class {
222
192
  * @method removeEntry
223
193
  * @param filePath - The file path to remove from the cache
224
194
  */
225
- removeEntry(filePath, options) {
226
- if (this.isRelativePath(filePath)) {
227
- filePath = this.getAbsolutePath(filePath, {
228
- currentWorkingDirectory: options?.currentWorkingDirectory
229
- });
230
- this._cache.removeKey(this.createFileKey(filePath));
231
- }
232
- const key = this.createFileKey(filePath, {
233
- currentWorkingDirectory: options?.currentWorkingDirectory
234
- });
195
+ removeEntry(filePath) {
196
+ const key = this.createFileKey(filePath);
235
197
  this._cache.removeKey(key);
236
198
  }
237
199
  /**
@@ -277,19 +239,17 @@ var FileEntryCache = class {
277
239
  meta: {}
278
240
  };
279
241
  result.meta = this._cache.getKey(result.key) ?? {};
280
- filePath = this.getAbsolutePath(filePath, {
281
- currentWorkingDirectory: options?.currentWorkingDirectory
282
- });
242
+ const absolutePath = this.getAbsolutePath(filePath);
283
243
  const useCheckSumValue = options?.useCheckSum ?? this._useCheckSum;
284
244
  const useModifiedTimeValue = options?.useModifiedTime ?? this._useModifiedTime;
285
245
  try {
286
- fstat = import_node_fs.default.statSync(filePath);
246
+ fstat = import_node_fs.default.statSync(absolutePath);
287
247
  result.meta = {
288
248
  size: fstat.size
289
249
  };
290
250
  result.meta.mtime = fstat.mtime.getTime();
291
251
  if (useCheckSumValue) {
292
- const buffer = import_node_fs.default.readFileSync(filePath);
252
+ const buffer = import_node_fs.default.readFileSync(absolutePath);
293
253
  result.meta.hash = this.getHash(buffer);
294
254
  }
295
255
  } catch (error) {
@@ -391,17 +351,16 @@ var FileEntryCache = class {
391
351
  return result;
392
352
  }
393
353
  /**
394
- * Get the not found files
354
+ * Get the file descriptors by path prefix
395
355
  * @method getFileDescriptorsByPath
396
- * @param filePath - the files that you want to get from a path
397
- * @returns {FileDescriptor[]} The not found files
356
+ * @param filePath - the path prefix to match
357
+ * @returns {FileDescriptor[]} The file descriptors
398
358
  */
399
359
  getFileDescriptorsByPath(filePath) {
400
360
  const result = [];
401
361
  const keys = this._cache.keys();
402
362
  for (const key of keys) {
403
- const absolutePath = this.getAbsolutePath(filePath);
404
- if (absolutePath.startsWith(filePath)) {
363
+ if (key.startsWith(filePath)) {
405
364
  const fileDescriptor = this.getFileDescriptor(key);
406
365
  result.push(fileDescriptor);
407
366
  }
@@ -412,23 +371,21 @@ var FileEntryCache = class {
412
371
  * Get the Absolute Path. If it is already absolute it will return the path as is.
413
372
  * @method getAbsolutePath
414
373
  * @param filePath - The file path to get the absolute path for
415
- * @param options - The options for getting the absolute path. The current working directory is used if not provided.
416
374
  * @returns {string}
417
375
  */
418
- getAbsolutePath(filePath, options) {
376
+ getAbsolutePath(filePath) {
419
377
  if (this.isRelativePath(filePath)) {
420
- const currentWorkingDirectory = options?.currentWorkingDirectory ?? this._currentWorkingDirectory ?? process.cwd();
421
- filePath = import_node_path.default.resolve(currentWorkingDirectory, filePath);
378
+ return import_node_path.default.resolve(process.cwd(), filePath);
422
379
  }
423
380
  return filePath;
424
381
  }
425
382
  /**
426
- * Rename the absolute path keys. This is used when a directory is changed or renamed.
427
- * @method renameAbsolutePathKeys
428
- * @param oldPath - The old path to rename
429
- * @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
430
387
  */
431
- renameAbsolutePathKeys(oldPath, newPath) {
388
+ renameCacheKeys(oldPath, newPath) {
432
389
  const keys = this._cache.keys();
433
390
  for (const key of keys) {
434
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, currentWorkingDirectory?: string): FileEntryCache;
35
- declare function create(cacheId: string, cacheDirectory?: string, useCheckSum?: boolean, currentWorkingDirectory?: string): FileEntryCache;
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, options?: {
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
@@ -137,9 +122,7 @@ declare class FileEntryCache {
137
122
  * @method removeEntry
138
123
  * @param filePath - The file path to remove from the cache
139
124
  */
140
- removeEntry(filePath: string, options?: {
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 not found files
168
+ * Get the file descriptors by path prefix
186
169
  * @method getFileDescriptorsByPath
187
- * @param filePath - the files that you want to get from a path
188
- * @returns {FileDescriptor[]} The not found files
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, options?: {
199
- currentWorkingDirectory?: string;
200
- }): string;
180
+ getAbsolutePath(filePath: string): string;
201
181
  /**
202
- * Rename the absolute path keys. This is used when a directory is changed or renamed.
203
- * @method renameAbsolutePathKeys
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
- renameAbsolutePathKeys(oldPath: string, newPath: string): void;
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, currentWorkingDirectory?: string): FileEntryCache;
35
- declare function create(cacheId: string, cacheDirectory?: string, useCheckSum?: boolean, currentWorkingDirectory?: string): FileEntryCache;
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, options?: {
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
@@ -137,9 +122,7 @@ declare class FileEntryCache {
137
122
  * @method removeEntry
138
123
  * @param filePath - The file path to remove from the cache
139
124
  */
140
- removeEntry(filePath: string, options?: {
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 not found files
168
+ * Get the file descriptors by path prefix
186
169
  * @method getFileDescriptorsByPath
187
- * @param filePath - the files that you want to get from a path
188
- * @returns {FileDescriptor[]} The not found files
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, options?: {
199
- currentWorkingDirectory?: string;
200
- }): string;
180
+ getAbsolutePath(filePath: string): string;
201
181
  /**
202
- * Rename the absolute path keys. This is used when a directory is changed or renamed.
203
- * @method renameAbsolutePathKeys
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
- renameAbsolutePathKeys(oldPath: string, newPath: string): void;
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
@@ -6,14 +6,13 @@ import {
6
6
  createFromFile as createFlatCacheFile,
7
7
  FlatCache
8
8
  } from "flat-cache";
9
- function createFromFile(filePath, useCheckSum, currentWorkingDirectory) {
9
+ function createFromFile(filePath, useCheckSum) {
10
10
  const fname = path.basename(filePath);
11
11
  const directory = path.dirname(filePath);
12
- return create(fname, directory, useCheckSum, currentWorkingDirectory);
12
+ return create(fname, directory, useCheckSum);
13
13
  }
14
- function create(cacheId, cacheDirectory, useCheckSum, currentWorkingDirectory) {
14
+ function create(cacheId, cacheDirectory, useCheckSum) {
15
15
  const options = {
16
- currentWorkingDirectory,
17
16
  useCheckSum,
18
17
  cache: {
19
18
  cacheId,
@@ -37,7 +36,6 @@ var FileEntryCache = class {
37
36
  _cache = new FlatCache({ useClone: false });
38
37
  _useCheckSum = false;
39
38
  _useModifiedTime = true;
40
- _currentWorkingDirectory;
41
39
  _hashAlgorithm = "md5";
42
40
  /**
43
41
  * Create a new FileEntryCache instance
@@ -53,9 +51,6 @@ var FileEntryCache = class {
53
51
  if (options?.useCheckSum) {
54
52
  this._useCheckSum = options.useCheckSum;
55
53
  }
56
- if (options?.currentWorkingDirectory) {
57
- this._currentWorkingDirectory = options.currentWorkingDirectory;
58
- }
59
54
  if (options?.hashAlgorithm) {
60
55
  this._hashAlgorithm = options.hashAlgorithm;
61
56
  }
@@ -116,20 +111,6 @@ var FileEntryCache = class {
116
111
  set hashAlgorithm(value) {
117
112
  this._hashAlgorithm = value;
118
113
  }
119
- /**
120
- * Get the current working directory
121
- * @returns {string | undefined} The current working directory
122
- */
123
- get currentWorkingDirectory() {
124
- return this._currentWorkingDirectory;
125
- }
126
- /**
127
- * Set the current working directory
128
- * @param {string | undefined} value - The value to set
129
- */
130
- set currentWorkingDirectory(value) {
131
- this._currentWorkingDirectory = value;
132
- }
133
114
  /**
134
115
  * Given a buffer, calculate md5 hash of its content.
135
116
  * @method getHash
@@ -145,19 +126,8 @@ var FileEntryCache = class {
145
126
  * @param {String} filePath
146
127
  * @return {String}
147
128
  */
148
- createFileKey(filePath, options) {
149
- let result = filePath;
150
- const currentWorkingDirectory = options?.currentWorkingDirectory ?? this._currentWorkingDirectory;
151
- if (currentWorkingDirectory && filePath.startsWith(currentWorkingDirectory)) {
152
- const splitPath = filePath.split(currentWorkingDirectory).pop();
153
- if (splitPath) {
154
- result = splitPath;
155
- if (result.startsWith("/")) {
156
- result = result.slice(1);
157
- }
158
- }
159
- }
160
- return result;
129
+ createFileKey(filePath) {
130
+ return filePath;
161
131
  }
162
132
  /**
163
133
  * Check if the file path is a relative path
@@ -188,16 +158,8 @@ var FileEntryCache = class {
188
158
  * @method removeEntry
189
159
  * @param filePath - The file path to remove from the cache
190
160
  */
191
- removeEntry(filePath, options) {
192
- if (this.isRelativePath(filePath)) {
193
- filePath = this.getAbsolutePath(filePath, {
194
- currentWorkingDirectory: options?.currentWorkingDirectory
195
- });
196
- this._cache.removeKey(this.createFileKey(filePath));
197
- }
198
- const key = this.createFileKey(filePath, {
199
- currentWorkingDirectory: options?.currentWorkingDirectory
200
- });
161
+ removeEntry(filePath) {
162
+ const key = this.createFileKey(filePath);
201
163
  this._cache.removeKey(key);
202
164
  }
203
165
  /**
@@ -243,19 +205,17 @@ var FileEntryCache = class {
243
205
  meta: {}
244
206
  };
245
207
  result.meta = this._cache.getKey(result.key) ?? {};
246
- filePath = this.getAbsolutePath(filePath, {
247
- currentWorkingDirectory: options?.currentWorkingDirectory
248
- });
208
+ const absolutePath = this.getAbsolutePath(filePath);
249
209
  const useCheckSumValue = options?.useCheckSum ?? this._useCheckSum;
250
210
  const useModifiedTimeValue = options?.useModifiedTime ?? this._useModifiedTime;
251
211
  try {
252
- fstat = fs.statSync(filePath);
212
+ fstat = fs.statSync(absolutePath);
253
213
  result.meta = {
254
214
  size: fstat.size
255
215
  };
256
216
  result.meta.mtime = fstat.mtime.getTime();
257
217
  if (useCheckSumValue) {
258
- const buffer = fs.readFileSync(filePath);
218
+ const buffer = fs.readFileSync(absolutePath);
259
219
  result.meta.hash = this.getHash(buffer);
260
220
  }
261
221
  } catch (error) {
@@ -357,17 +317,16 @@ var FileEntryCache = class {
357
317
  return result;
358
318
  }
359
319
  /**
360
- * Get the not found files
320
+ * Get the file descriptors by path prefix
361
321
  * @method getFileDescriptorsByPath
362
- * @param filePath - the files that you want to get from a path
363
- * @returns {FileDescriptor[]} The not found files
322
+ * @param filePath - the path prefix to match
323
+ * @returns {FileDescriptor[]} The file descriptors
364
324
  */
365
325
  getFileDescriptorsByPath(filePath) {
366
326
  const result = [];
367
327
  const keys = this._cache.keys();
368
328
  for (const key of keys) {
369
- const absolutePath = this.getAbsolutePath(filePath);
370
- if (absolutePath.startsWith(filePath)) {
329
+ if (key.startsWith(filePath)) {
371
330
  const fileDescriptor = this.getFileDescriptor(key);
372
331
  result.push(fileDescriptor);
373
332
  }
@@ -378,23 +337,21 @@ var FileEntryCache = class {
378
337
  * Get the Absolute Path. If it is already absolute it will return the path as is.
379
338
  * @method getAbsolutePath
380
339
  * @param filePath - The file path to get the absolute path for
381
- * @param options - The options for getting the absolute path. The current working directory is used if not provided.
382
340
  * @returns {string}
383
341
  */
384
- getAbsolutePath(filePath, options) {
342
+ getAbsolutePath(filePath) {
385
343
  if (this.isRelativePath(filePath)) {
386
- const currentWorkingDirectory = options?.currentWorkingDirectory ?? this._currentWorkingDirectory ?? process.cwd();
387
- filePath = path.resolve(currentWorkingDirectory, filePath);
344
+ return path.resolve(process.cwd(), filePath);
388
345
  }
389
346
  return filePath;
390
347
  }
391
348
  /**
392
- * Rename the absolute path keys. This is used when a directory is changed or renamed.
393
- * @method renameAbsolutePathKeys
394
- * @param oldPath - The old path to rename
395
- * @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
396
353
  */
397
- renameAbsolutePathKeys(oldPath, newPath) {
354
+ renameCacheKeys(oldPath, newPath) {
398
355
  const keys = this._cache.keys();
399
356
  for (const key of keys) {
400
357
  if (key.startsWith(oldPath)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "file-entry-cache",
3
- "version": "10.1.4",
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,8 +29,8 @@
29
29
  "cache"
30
30
  ],
31
31
  "devDependencies": {
32
- "@biomejs/biome": "^2.2.0",
33
- "@types/node": "^24.3.0",
32
+ "@biomejs/biome": "^2.2.4",
33
+ "@types/node": "^24.5.0",
34
34
  "@vitest/coverage-v8": "^3.2.4",
35
35
  "rimraf": "^6.0.1",
36
36
  "tsup": "^8.5.0",
@@ -38,7 +38,7 @@
38
38
  "vitest": "^3.2.4"
39
39
  },
40
40
  "dependencies": {
41
- "flat-cache": "^6.1.13"
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
- "test": "biome check --write && vitest run --coverage",
51
- "test:ci": "biome check && vitest run --coverage",
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
  }