file-entry-cache 9.1.0 → 10.0.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/LICENSE +10 -13
- package/README.md +179 -95
- package/dist/index.cjs +384 -0
- package/dist/index.d.cts +160 -0
- package/dist/index.d.ts +160 -0
- package/dist/index.js +347 -0
- package/package.json +33 -43
- package/cache.js +0 -318
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
FileEntryCache: () => FileEntryCache,
|
|
34
|
+
create: () => create,
|
|
35
|
+
createFromFile: () => createFromFile,
|
|
36
|
+
default: () => FileEntryDefault
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(src_exports);
|
|
39
|
+
var import_node_crypto = __toESM(require("crypto"), 1);
|
|
40
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
41
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
42
|
+
var import_flat_cache = require("flat-cache");
|
|
43
|
+
function createFromFile(filePath, useCheckSum, currentWorkingDirectory) {
|
|
44
|
+
const fname = import_node_path.default.basename(filePath);
|
|
45
|
+
const directory = import_node_path.default.dirname(filePath);
|
|
46
|
+
return create(fname, directory, useCheckSum, currentWorkingDirectory);
|
|
47
|
+
}
|
|
48
|
+
function create(cacheId, cacheDirectory, useCheckSum, currentWorkingDirectory) {
|
|
49
|
+
const options = {
|
|
50
|
+
currentWorkingDirectory,
|
|
51
|
+
useCheckSum,
|
|
52
|
+
cache: {
|
|
53
|
+
cacheId,
|
|
54
|
+
cacheDir: cacheDirectory
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const fileEntryCache = new FileEntryCache(options);
|
|
58
|
+
if (cacheDirectory) {
|
|
59
|
+
const cachePath = `${cacheDirectory}/${cacheId}`;
|
|
60
|
+
if (import_node_fs.default.existsSync(cachePath)) {
|
|
61
|
+
fileEntryCache.cache = (0, import_flat_cache.createFromFile)(cachePath, options.cache);
|
|
62
|
+
fileEntryCache.reconcile();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return fileEntryCache;
|
|
66
|
+
}
|
|
67
|
+
var FileEntryDefault = class {
|
|
68
|
+
static create = create;
|
|
69
|
+
static createFromFile = createFromFile;
|
|
70
|
+
};
|
|
71
|
+
var FileEntryCache = class {
|
|
72
|
+
_cache = new import_flat_cache.FlatCache();
|
|
73
|
+
_useCheckSum = false;
|
|
74
|
+
_currentWorkingDirectory;
|
|
75
|
+
_hashAlgorithm = "md5";
|
|
76
|
+
constructor(options) {
|
|
77
|
+
if (options?.cache) {
|
|
78
|
+
this._cache = new import_flat_cache.FlatCache(options.cache);
|
|
79
|
+
}
|
|
80
|
+
if (options?.useCheckSum) {
|
|
81
|
+
this._useCheckSum = options.useCheckSum;
|
|
82
|
+
}
|
|
83
|
+
if (options?.currentWorkingDirectory) {
|
|
84
|
+
this._currentWorkingDirectory = options.currentWorkingDirectory;
|
|
85
|
+
}
|
|
86
|
+
if (options?.hashAlgorithm) {
|
|
87
|
+
this._hashAlgorithm = options.hashAlgorithm;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
get cache() {
|
|
91
|
+
return this._cache;
|
|
92
|
+
}
|
|
93
|
+
set cache(cache) {
|
|
94
|
+
this._cache = cache;
|
|
95
|
+
}
|
|
96
|
+
get useCheckSum() {
|
|
97
|
+
return this._useCheckSum;
|
|
98
|
+
}
|
|
99
|
+
set useCheckSum(value) {
|
|
100
|
+
this._useCheckSum = value;
|
|
101
|
+
}
|
|
102
|
+
get hashAlgorithm() {
|
|
103
|
+
return this._hashAlgorithm;
|
|
104
|
+
}
|
|
105
|
+
set hashAlgorithm(value) {
|
|
106
|
+
this._hashAlgorithm = value;
|
|
107
|
+
}
|
|
108
|
+
get currentWorkingDirectory() {
|
|
109
|
+
return this._currentWorkingDirectory;
|
|
110
|
+
}
|
|
111
|
+
set currentWorkingDirectory(value) {
|
|
112
|
+
this._currentWorkingDirectory = value;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Given a buffer, calculate md5 hash of its content.
|
|
116
|
+
* @method getHash
|
|
117
|
+
* @param {Buffer} buffer buffer to calculate hash on
|
|
118
|
+
* @return {String} content hash digest
|
|
119
|
+
*/
|
|
120
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
121
|
+
getHash(buffer) {
|
|
122
|
+
return import_node_crypto.default.createHash(this._hashAlgorithm).update(buffer).digest("hex");
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Create the key for the file path used for caching.
|
|
126
|
+
* @method createFileKey
|
|
127
|
+
* @param {String} filePath
|
|
128
|
+
* @return {String}
|
|
129
|
+
*/
|
|
130
|
+
createFileKey(filePath, optons) {
|
|
131
|
+
let result = filePath;
|
|
132
|
+
const currentWorkingDirectory = optons?.currentWorkingDirectory ?? this._currentWorkingDirectory;
|
|
133
|
+
if (currentWorkingDirectory && filePath.startsWith(currentWorkingDirectory)) {
|
|
134
|
+
const splitPath = filePath.split(currentWorkingDirectory).pop();
|
|
135
|
+
if (splitPath) {
|
|
136
|
+
result = splitPath;
|
|
137
|
+
if (result.startsWith("/")) {
|
|
138
|
+
result = result.slice(1);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Check if the file path is a relative path
|
|
146
|
+
* @method isRelativePath
|
|
147
|
+
* @param filePath - The file path to check
|
|
148
|
+
* @returns {boolean} if the file path is a relative path, false otherwise
|
|
149
|
+
*/
|
|
150
|
+
isRelativePath(filePath) {
|
|
151
|
+
return !import_node_path.default.isAbsolute(filePath);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Delete the cache file from the disk
|
|
155
|
+
* @method deleteCacheFile
|
|
156
|
+
* @return {boolean} true if the file was deleted, false otherwise
|
|
157
|
+
*/
|
|
158
|
+
deleteCacheFile() {
|
|
159
|
+
return this._cache.removeCacheFile();
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Remove the cache from the file and clear the memory cache
|
|
163
|
+
* @method destroy
|
|
164
|
+
*/
|
|
165
|
+
destroy() {
|
|
166
|
+
this._cache.destroy();
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Remove and Entry From the Cache
|
|
170
|
+
* @method removeEntry
|
|
171
|
+
* @param filePath - The file path to remove from the cache
|
|
172
|
+
*/
|
|
173
|
+
removeEntry(filePath, options) {
|
|
174
|
+
if (this.isRelativePath(filePath)) {
|
|
175
|
+
filePath = this.getAbsolutePath(filePath, { currentWorkingDirectory: options?.currentWorkingDirectory });
|
|
176
|
+
this._cache.removeKey(this.createFileKey(filePath));
|
|
177
|
+
}
|
|
178
|
+
const key = this.createFileKey(filePath, { currentWorkingDirectory: options?.currentWorkingDirectory });
|
|
179
|
+
this._cache.removeKey(key);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Reconcile the cache
|
|
183
|
+
* @method reconcile
|
|
184
|
+
*/
|
|
185
|
+
reconcile() {
|
|
186
|
+
const items = this._cache.items;
|
|
187
|
+
for (const item of items) {
|
|
188
|
+
const fileDescriptor = this.getFileDescriptor(item.key);
|
|
189
|
+
if (fileDescriptor.notFound) {
|
|
190
|
+
this._cache.removeKey(item.key);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
this._cache.save();
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Check if the file has changed
|
|
197
|
+
* @method hasFileChanged
|
|
198
|
+
* @param filePath - The file path to check
|
|
199
|
+
* @returns {boolean} if the file has changed, false otherwise
|
|
200
|
+
*/
|
|
201
|
+
hasFileChanged(filePath) {
|
|
202
|
+
let result = false;
|
|
203
|
+
const fileDescriptor = this.getFileDescriptor(filePath);
|
|
204
|
+
if ((!fileDescriptor.err || !fileDescriptor.notFound) && fileDescriptor.changed) {
|
|
205
|
+
result = true;
|
|
206
|
+
}
|
|
207
|
+
return result;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Get the file descriptor for the file path
|
|
211
|
+
* @method getFileDescriptor
|
|
212
|
+
* @param filePath - The file path to get the file descriptor for
|
|
213
|
+
* @param options - The options for getting the file descriptor
|
|
214
|
+
* @returns The file descriptor
|
|
215
|
+
*/
|
|
216
|
+
getFileDescriptor(filePath, options) {
|
|
217
|
+
let fstat;
|
|
218
|
+
const result = {
|
|
219
|
+
key: this.createFileKey(filePath),
|
|
220
|
+
changed: false,
|
|
221
|
+
meta: {}
|
|
222
|
+
};
|
|
223
|
+
filePath = this.getAbsolutePath(filePath, { currentWorkingDirectory: options?.currentWorkingDirectory });
|
|
224
|
+
const useCheckSumValue = options?.useCheckSum ?? this._useCheckSum;
|
|
225
|
+
try {
|
|
226
|
+
fstat = import_node_fs.default.statSync(filePath);
|
|
227
|
+
result.meta = {
|
|
228
|
+
size: fstat.size
|
|
229
|
+
};
|
|
230
|
+
result.meta.mtime = fstat.mtime.getTime();
|
|
231
|
+
if (useCheckSumValue) {
|
|
232
|
+
const buffer = import_node_fs.default.readFileSync(filePath);
|
|
233
|
+
result.meta.hash = this.getHash(buffer);
|
|
234
|
+
}
|
|
235
|
+
} catch (error) {
|
|
236
|
+
this.removeEntry(filePath);
|
|
237
|
+
let notFound = false;
|
|
238
|
+
if (error.message.includes("ENOENT")) {
|
|
239
|
+
notFound = true;
|
|
240
|
+
}
|
|
241
|
+
return {
|
|
242
|
+
key: result.key,
|
|
243
|
+
err: error,
|
|
244
|
+
notFound,
|
|
245
|
+
meta: {}
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
const metaCache = this._cache.getKey(result.key);
|
|
249
|
+
if (!metaCache) {
|
|
250
|
+
result.changed = true;
|
|
251
|
+
this._cache.setKey(result.key, result.meta);
|
|
252
|
+
return result;
|
|
253
|
+
}
|
|
254
|
+
result.meta.data = metaCache.data;
|
|
255
|
+
if (metaCache?.mtime !== result.meta?.mtime || metaCache?.size !== result.meta?.size) {
|
|
256
|
+
result.changed = true;
|
|
257
|
+
this._cache.setKey(result.key, result.meta);
|
|
258
|
+
}
|
|
259
|
+
if (useCheckSumValue && metaCache?.hash !== result.meta?.hash) {
|
|
260
|
+
result.changed = true;
|
|
261
|
+
this._cache.setKey(result.key, result.meta);
|
|
262
|
+
}
|
|
263
|
+
return result;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Get the file descriptors for the files
|
|
267
|
+
* @method normalizeEntries
|
|
268
|
+
* @param files?: string[] - The files to get the file descriptors for
|
|
269
|
+
* @returns The file descriptors
|
|
270
|
+
*/
|
|
271
|
+
normalizeEntries(files) {
|
|
272
|
+
const result = new Array();
|
|
273
|
+
if (files) {
|
|
274
|
+
for (const file of files) {
|
|
275
|
+
const fileDescriptor = this.getFileDescriptor(file);
|
|
276
|
+
result.push(fileDescriptor);
|
|
277
|
+
}
|
|
278
|
+
return result;
|
|
279
|
+
}
|
|
280
|
+
const keys = this.cache.keys();
|
|
281
|
+
for (const key of keys) {
|
|
282
|
+
const fileDescriptor = this.getFileDescriptor(key);
|
|
283
|
+
if (!fileDescriptor.notFound && !fileDescriptor.err) {
|
|
284
|
+
result.push(fileDescriptor);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return result;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Analyze the files
|
|
291
|
+
* @method analyzeFiles
|
|
292
|
+
* @param files - The files to analyze
|
|
293
|
+
* @returns {AnalyzedFiles} The analysis of the files
|
|
294
|
+
*/
|
|
295
|
+
analyzeFiles(files) {
|
|
296
|
+
const result = {
|
|
297
|
+
changedFiles: [],
|
|
298
|
+
notFoundFiles: [],
|
|
299
|
+
notChangedFiles: []
|
|
300
|
+
};
|
|
301
|
+
const fileDescriptors = this.normalizeEntries(files);
|
|
302
|
+
for (const fileDescriptor of fileDescriptors) {
|
|
303
|
+
if (fileDescriptor.notFound) {
|
|
304
|
+
result.notFoundFiles.push(fileDescriptor.key);
|
|
305
|
+
} else if (fileDescriptor.changed) {
|
|
306
|
+
result.changedFiles.push(fileDescriptor.key);
|
|
307
|
+
} else {
|
|
308
|
+
result.notChangedFiles.push(fileDescriptor.key);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return result;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Get the updated files
|
|
315
|
+
* @method getUpdatedFiles
|
|
316
|
+
* @param files - The files to get the updated files for
|
|
317
|
+
* @returns {string[]} The updated files
|
|
318
|
+
*/
|
|
319
|
+
getUpdatedFiles(files) {
|
|
320
|
+
const result = new Array();
|
|
321
|
+
const fileDescriptors = this.normalizeEntries(files);
|
|
322
|
+
for (const fileDescriptor of fileDescriptors) {
|
|
323
|
+
if (fileDescriptor.changed) {
|
|
324
|
+
result.push(fileDescriptor.key);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return result;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Get the not found files
|
|
331
|
+
* @method getFileDescriptorsByPath
|
|
332
|
+
* @param filePath - the files that you want to get from a path
|
|
333
|
+
* @returns {FileDescriptor[]} The not found files
|
|
334
|
+
*/
|
|
335
|
+
getFileDescriptorsByPath(filePath) {
|
|
336
|
+
const result = new Array();
|
|
337
|
+
const keys = this._cache.keys();
|
|
338
|
+
for (const key of keys) {
|
|
339
|
+
const absolutePath = this.getAbsolutePath(filePath);
|
|
340
|
+
if (absolutePath.startsWith(filePath)) {
|
|
341
|
+
const fileDescriptor = this.getFileDescriptor(key);
|
|
342
|
+
result.push(fileDescriptor);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return result;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Get the Absolute Path. If it is already absolute it will return the path as is.
|
|
349
|
+
* @method getAbsolutePath
|
|
350
|
+
* @param filePath - The file path to get the absolute path for
|
|
351
|
+
* @param options - The options for getting the absolute path. The current working directory is used if not provided.
|
|
352
|
+
* @returns {string}
|
|
353
|
+
*/
|
|
354
|
+
getAbsolutePath(filePath, options) {
|
|
355
|
+
if (this.isRelativePath(filePath)) {
|
|
356
|
+
const currentWorkingDirectory = options?.currentWorkingDirectory ?? this._currentWorkingDirectory ?? process.cwd();
|
|
357
|
+
filePath = import_node_path.default.resolve(currentWorkingDirectory, filePath);
|
|
358
|
+
}
|
|
359
|
+
return filePath;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Rename the absolute path keys. This is used when a directory is changed or renamed.
|
|
363
|
+
* @method renameAbsolutePathKeys
|
|
364
|
+
* @param oldPath - The old path to rename
|
|
365
|
+
* @param newPath - The new path to rename to
|
|
366
|
+
*/
|
|
367
|
+
renameAbsolutePathKeys(oldPath, newPath) {
|
|
368
|
+
const keys = this._cache.keys();
|
|
369
|
+
for (const key of keys) {
|
|
370
|
+
if (key.startsWith(oldPath)) {
|
|
371
|
+
const newKey = key.replace(oldPath, newPath);
|
|
372
|
+
const meta = this._cache.getKey(key);
|
|
373
|
+
this._cache.removeKey(key);
|
|
374
|
+
this._cache.setKey(newKey, meta);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
380
|
+
0 && (module.exports = {
|
|
381
|
+
FileEntryCache,
|
|
382
|
+
create,
|
|
383
|
+
createFromFile
|
|
384
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { FlatCacheOptions, FlatCache } from 'flat-cache';
|
|
2
|
+
|
|
3
|
+
type FileEntryCacheOptions = {
|
|
4
|
+
currentWorkingDirectory?: string;
|
|
5
|
+
useCheckSum?: boolean;
|
|
6
|
+
hashAlgorithm?: string;
|
|
7
|
+
cache?: FlatCacheOptions;
|
|
8
|
+
};
|
|
9
|
+
type GetFileDescriptorOptions = {
|
|
10
|
+
useCheckSum?: boolean;
|
|
11
|
+
currentWorkingDirectory?: string;
|
|
12
|
+
};
|
|
13
|
+
type FileDescriptor = {
|
|
14
|
+
key: string;
|
|
15
|
+
changed?: boolean;
|
|
16
|
+
meta: FileDescriptorMeta;
|
|
17
|
+
notFound?: boolean;
|
|
18
|
+
err?: Error;
|
|
19
|
+
};
|
|
20
|
+
type FileDescriptorMeta = {
|
|
21
|
+
size?: number;
|
|
22
|
+
mtime?: number;
|
|
23
|
+
hash?: string;
|
|
24
|
+
data?: unknown;
|
|
25
|
+
};
|
|
26
|
+
type AnalyzedFiles = {
|
|
27
|
+
changedFiles: string[];
|
|
28
|
+
notFoundFiles: string[];
|
|
29
|
+
notChangedFiles: string[];
|
|
30
|
+
};
|
|
31
|
+
declare function createFromFile(filePath: string, useCheckSum?: boolean, currentWorkingDirectory?: string): FileEntryCache;
|
|
32
|
+
declare function create(cacheId: string, cacheDirectory?: string, useCheckSum?: boolean, currentWorkingDirectory?: string): FileEntryCache;
|
|
33
|
+
declare class FileEntryDefault {
|
|
34
|
+
static create: typeof create;
|
|
35
|
+
static createFromFile: typeof createFromFile;
|
|
36
|
+
}
|
|
37
|
+
declare class FileEntryCache {
|
|
38
|
+
private _cache;
|
|
39
|
+
private _useCheckSum;
|
|
40
|
+
private _currentWorkingDirectory;
|
|
41
|
+
private _hashAlgorithm;
|
|
42
|
+
constructor(options?: FileEntryCacheOptions);
|
|
43
|
+
get cache(): FlatCache;
|
|
44
|
+
set cache(cache: FlatCache);
|
|
45
|
+
get useCheckSum(): boolean;
|
|
46
|
+
set useCheckSum(value: boolean);
|
|
47
|
+
get hashAlgorithm(): string;
|
|
48
|
+
set hashAlgorithm(value: string);
|
|
49
|
+
get currentWorkingDirectory(): string | undefined;
|
|
50
|
+
set currentWorkingDirectory(value: string | undefined);
|
|
51
|
+
/**
|
|
52
|
+
* Given a buffer, calculate md5 hash of its content.
|
|
53
|
+
* @method getHash
|
|
54
|
+
* @param {Buffer} buffer buffer to calculate hash on
|
|
55
|
+
* @return {String} content hash digest
|
|
56
|
+
*/
|
|
57
|
+
getHash(buffer: Buffer): string;
|
|
58
|
+
/**
|
|
59
|
+
* Create the key for the file path used for caching.
|
|
60
|
+
* @method createFileKey
|
|
61
|
+
* @param {String} filePath
|
|
62
|
+
* @return {String}
|
|
63
|
+
*/
|
|
64
|
+
createFileKey(filePath: string, optons?: {
|
|
65
|
+
currentWorkingDirectory?: string;
|
|
66
|
+
}): string;
|
|
67
|
+
/**
|
|
68
|
+
* Check if the file path is a relative path
|
|
69
|
+
* @method isRelativePath
|
|
70
|
+
* @param filePath - The file path to check
|
|
71
|
+
* @returns {boolean} if the file path is a relative path, false otherwise
|
|
72
|
+
*/
|
|
73
|
+
isRelativePath(filePath: string): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Delete the cache file from the disk
|
|
76
|
+
* @method deleteCacheFile
|
|
77
|
+
* @return {boolean} true if the file was deleted, false otherwise
|
|
78
|
+
*/
|
|
79
|
+
deleteCacheFile(): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Remove the cache from the file and clear the memory cache
|
|
82
|
+
* @method destroy
|
|
83
|
+
*/
|
|
84
|
+
destroy(): void;
|
|
85
|
+
/**
|
|
86
|
+
* Remove and Entry From the Cache
|
|
87
|
+
* @method removeEntry
|
|
88
|
+
* @param filePath - The file path to remove from the cache
|
|
89
|
+
*/
|
|
90
|
+
removeEntry(filePath: string, options?: {
|
|
91
|
+
currentWorkingDirectory?: string;
|
|
92
|
+
}): void;
|
|
93
|
+
/**
|
|
94
|
+
* Reconcile the cache
|
|
95
|
+
* @method reconcile
|
|
96
|
+
*/
|
|
97
|
+
reconcile(): void;
|
|
98
|
+
/**
|
|
99
|
+
* Check if the file has changed
|
|
100
|
+
* @method hasFileChanged
|
|
101
|
+
* @param filePath - The file path to check
|
|
102
|
+
* @returns {boolean} if the file has changed, false otherwise
|
|
103
|
+
*/
|
|
104
|
+
hasFileChanged(filePath: string): boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Get the file descriptor for the file path
|
|
107
|
+
* @method getFileDescriptor
|
|
108
|
+
* @param filePath - The file path to get the file descriptor for
|
|
109
|
+
* @param options - The options for getting the file descriptor
|
|
110
|
+
* @returns The file descriptor
|
|
111
|
+
*/
|
|
112
|
+
getFileDescriptor(filePath: string, options?: GetFileDescriptorOptions): FileDescriptor;
|
|
113
|
+
/**
|
|
114
|
+
* Get the file descriptors for the files
|
|
115
|
+
* @method normalizeEntries
|
|
116
|
+
* @param files?: string[] - The files to get the file descriptors for
|
|
117
|
+
* @returns The file descriptors
|
|
118
|
+
*/
|
|
119
|
+
normalizeEntries(files?: string[]): FileDescriptor[];
|
|
120
|
+
/**
|
|
121
|
+
* Analyze the files
|
|
122
|
+
* @method analyzeFiles
|
|
123
|
+
* @param files - The files to analyze
|
|
124
|
+
* @returns {AnalyzedFiles} The analysis of the files
|
|
125
|
+
*/
|
|
126
|
+
analyzeFiles(files: string[]): AnalyzedFiles;
|
|
127
|
+
/**
|
|
128
|
+
* Get the updated files
|
|
129
|
+
* @method getUpdatedFiles
|
|
130
|
+
* @param files - The files to get the updated files for
|
|
131
|
+
* @returns {string[]} The updated files
|
|
132
|
+
*/
|
|
133
|
+
getUpdatedFiles(files: string[]): string[];
|
|
134
|
+
/**
|
|
135
|
+
* Get the not found files
|
|
136
|
+
* @method getFileDescriptorsByPath
|
|
137
|
+
* @param filePath - the files that you want to get from a path
|
|
138
|
+
* @returns {FileDescriptor[]} The not found files
|
|
139
|
+
*/
|
|
140
|
+
getFileDescriptorsByPath(filePath: string): FileDescriptor[];
|
|
141
|
+
/**
|
|
142
|
+
* Get the Absolute Path. If it is already absolute it will return the path as is.
|
|
143
|
+
* @method getAbsolutePath
|
|
144
|
+
* @param filePath - The file path to get the absolute path for
|
|
145
|
+
* @param options - The options for getting the absolute path. The current working directory is used if not provided.
|
|
146
|
+
* @returns {string}
|
|
147
|
+
*/
|
|
148
|
+
getAbsolutePath(filePath: string, options?: {
|
|
149
|
+
currentWorkingDirectory?: string;
|
|
150
|
+
}): string;
|
|
151
|
+
/**
|
|
152
|
+
* Rename the absolute path keys. This is used when a directory is changed or renamed.
|
|
153
|
+
* @method renameAbsolutePathKeys
|
|
154
|
+
* @param oldPath - The old path to rename
|
|
155
|
+
* @param newPath - The new path to rename to
|
|
156
|
+
*/
|
|
157
|
+
renameAbsolutePathKeys(oldPath: string, newPath: string): void;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export { type AnalyzedFiles, type FileDescriptor, type FileDescriptorMeta, FileEntryCache, type FileEntryCacheOptions, type GetFileDescriptorOptions, create, createFromFile, FileEntryDefault as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { FlatCacheOptions, FlatCache } from 'flat-cache';
|
|
2
|
+
|
|
3
|
+
type FileEntryCacheOptions = {
|
|
4
|
+
currentWorkingDirectory?: string;
|
|
5
|
+
useCheckSum?: boolean;
|
|
6
|
+
hashAlgorithm?: string;
|
|
7
|
+
cache?: FlatCacheOptions;
|
|
8
|
+
};
|
|
9
|
+
type GetFileDescriptorOptions = {
|
|
10
|
+
useCheckSum?: boolean;
|
|
11
|
+
currentWorkingDirectory?: string;
|
|
12
|
+
};
|
|
13
|
+
type FileDescriptor = {
|
|
14
|
+
key: string;
|
|
15
|
+
changed?: boolean;
|
|
16
|
+
meta: FileDescriptorMeta;
|
|
17
|
+
notFound?: boolean;
|
|
18
|
+
err?: Error;
|
|
19
|
+
};
|
|
20
|
+
type FileDescriptorMeta = {
|
|
21
|
+
size?: number;
|
|
22
|
+
mtime?: number;
|
|
23
|
+
hash?: string;
|
|
24
|
+
data?: unknown;
|
|
25
|
+
};
|
|
26
|
+
type AnalyzedFiles = {
|
|
27
|
+
changedFiles: string[];
|
|
28
|
+
notFoundFiles: string[];
|
|
29
|
+
notChangedFiles: string[];
|
|
30
|
+
};
|
|
31
|
+
declare function createFromFile(filePath: string, useCheckSum?: boolean, currentWorkingDirectory?: string): FileEntryCache;
|
|
32
|
+
declare function create(cacheId: string, cacheDirectory?: string, useCheckSum?: boolean, currentWorkingDirectory?: string): FileEntryCache;
|
|
33
|
+
declare class FileEntryDefault {
|
|
34
|
+
static create: typeof create;
|
|
35
|
+
static createFromFile: typeof createFromFile;
|
|
36
|
+
}
|
|
37
|
+
declare class FileEntryCache {
|
|
38
|
+
private _cache;
|
|
39
|
+
private _useCheckSum;
|
|
40
|
+
private _currentWorkingDirectory;
|
|
41
|
+
private _hashAlgorithm;
|
|
42
|
+
constructor(options?: FileEntryCacheOptions);
|
|
43
|
+
get cache(): FlatCache;
|
|
44
|
+
set cache(cache: FlatCache);
|
|
45
|
+
get useCheckSum(): boolean;
|
|
46
|
+
set useCheckSum(value: boolean);
|
|
47
|
+
get hashAlgorithm(): string;
|
|
48
|
+
set hashAlgorithm(value: string);
|
|
49
|
+
get currentWorkingDirectory(): string | undefined;
|
|
50
|
+
set currentWorkingDirectory(value: string | undefined);
|
|
51
|
+
/**
|
|
52
|
+
* Given a buffer, calculate md5 hash of its content.
|
|
53
|
+
* @method getHash
|
|
54
|
+
* @param {Buffer} buffer buffer to calculate hash on
|
|
55
|
+
* @return {String} content hash digest
|
|
56
|
+
*/
|
|
57
|
+
getHash(buffer: Buffer): string;
|
|
58
|
+
/**
|
|
59
|
+
* Create the key for the file path used for caching.
|
|
60
|
+
* @method createFileKey
|
|
61
|
+
* @param {String} filePath
|
|
62
|
+
* @return {String}
|
|
63
|
+
*/
|
|
64
|
+
createFileKey(filePath: string, optons?: {
|
|
65
|
+
currentWorkingDirectory?: string;
|
|
66
|
+
}): string;
|
|
67
|
+
/**
|
|
68
|
+
* Check if the file path is a relative path
|
|
69
|
+
* @method isRelativePath
|
|
70
|
+
* @param filePath - The file path to check
|
|
71
|
+
* @returns {boolean} if the file path is a relative path, false otherwise
|
|
72
|
+
*/
|
|
73
|
+
isRelativePath(filePath: string): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Delete the cache file from the disk
|
|
76
|
+
* @method deleteCacheFile
|
|
77
|
+
* @return {boolean} true if the file was deleted, false otherwise
|
|
78
|
+
*/
|
|
79
|
+
deleteCacheFile(): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Remove the cache from the file and clear the memory cache
|
|
82
|
+
* @method destroy
|
|
83
|
+
*/
|
|
84
|
+
destroy(): void;
|
|
85
|
+
/**
|
|
86
|
+
* Remove and Entry From the Cache
|
|
87
|
+
* @method removeEntry
|
|
88
|
+
* @param filePath - The file path to remove from the cache
|
|
89
|
+
*/
|
|
90
|
+
removeEntry(filePath: string, options?: {
|
|
91
|
+
currentWorkingDirectory?: string;
|
|
92
|
+
}): void;
|
|
93
|
+
/**
|
|
94
|
+
* Reconcile the cache
|
|
95
|
+
* @method reconcile
|
|
96
|
+
*/
|
|
97
|
+
reconcile(): void;
|
|
98
|
+
/**
|
|
99
|
+
* Check if the file has changed
|
|
100
|
+
* @method hasFileChanged
|
|
101
|
+
* @param filePath - The file path to check
|
|
102
|
+
* @returns {boolean} if the file has changed, false otherwise
|
|
103
|
+
*/
|
|
104
|
+
hasFileChanged(filePath: string): boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Get the file descriptor for the file path
|
|
107
|
+
* @method getFileDescriptor
|
|
108
|
+
* @param filePath - The file path to get the file descriptor for
|
|
109
|
+
* @param options - The options for getting the file descriptor
|
|
110
|
+
* @returns The file descriptor
|
|
111
|
+
*/
|
|
112
|
+
getFileDescriptor(filePath: string, options?: GetFileDescriptorOptions): FileDescriptor;
|
|
113
|
+
/**
|
|
114
|
+
* Get the file descriptors for the files
|
|
115
|
+
* @method normalizeEntries
|
|
116
|
+
* @param files?: string[] - The files to get the file descriptors for
|
|
117
|
+
* @returns The file descriptors
|
|
118
|
+
*/
|
|
119
|
+
normalizeEntries(files?: string[]): FileDescriptor[];
|
|
120
|
+
/**
|
|
121
|
+
* Analyze the files
|
|
122
|
+
* @method analyzeFiles
|
|
123
|
+
* @param files - The files to analyze
|
|
124
|
+
* @returns {AnalyzedFiles} The analysis of the files
|
|
125
|
+
*/
|
|
126
|
+
analyzeFiles(files: string[]): AnalyzedFiles;
|
|
127
|
+
/**
|
|
128
|
+
* Get the updated files
|
|
129
|
+
* @method getUpdatedFiles
|
|
130
|
+
* @param files - The files to get the updated files for
|
|
131
|
+
* @returns {string[]} The updated files
|
|
132
|
+
*/
|
|
133
|
+
getUpdatedFiles(files: string[]): string[];
|
|
134
|
+
/**
|
|
135
|
+
* Get the not found files
|
|
136
|
+
* @method getFileDescriptorsByPath
|
|
137
|
+
* @param filePath - the files that you want to get from a path
|
|
138
|
+
* @returns {FileDescriptor[]} The not found files
|
|
139
|
+
*/
|
|
140
|
+
getFileDescriptorsByPath(filePath: string): FileDescriptor[];
|
|
141
|
+
/**
|
|
142
|
+
* Get the Absolute Path. If it is already absolute it will return the path as is.
|
|
143
|
+
* @method getAbsolutePath
|
|
144
|
+
* @param filePath - The file path to get the absolute path for
|
|
145
|
+
* @param options - The options for getting the absolute path. The current working directory is used if not provided.
|
|
146
|
+
* @returns {string}
|
|
147
|
+
*/
|
|
148
|
+
getAbsolutePath(filePath: string, options?: {
|
|
149
|
+
currentWorkingDirectory?: string;
|
|
150
|
+
}): string;
|
|
151
|
+
/**
|
|
152
|
+
* Rename the absolute path keys. This is used when a directory is changed or renamed.
|
|
153
|
+
* @method renameAbsolutePathKeys
|
|
154
|
+
* @param oldPath - The old path to rename
|
|
155
|
+
* @param newPath - The new path to rename to
|
|
156
|
+
*/
|
|
157
|
+
renameAbsolutePathKeys(oldPath: string, newPath: string): void;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export { type AnalyzedFiles, type FileDescriptor, type FileDescriptorMeta, FileEntryCache, type FileEntryCacheOptions, type GetFileDescriptorOptions, create, createFromFile, FileEntryDefault as default };
|