@rspack/core 1.1.0-beta.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compiled/enhanced-resolve/CachedInputFileSystem.js +267 -80
- package/compiled/enhanced-resolve/index.d.ts +849 -236
- package/compiled/enhanced-resolve/package.json +1 -1
- package/compiled/graceful-fs/index.js +10 -10
- package/compiled/graceful-fs/package.json +1 -1
- package/compiled/zod/index.d.ts +2 -2
- package/dist/Compilation.d.ts +1 -1
- package/dist/DependenciesBlock.d.ts +6 -4
- package/dist/Module.d.ts +16 -15
- package/dist/builtin-plugin/EntryPlugin.d.ts +14 -11
- package/dist/builtin-plugin/FlagDependencyUsagePlugin.d.ts +10 -10
- package/dist/builtin-plugin/MangleExportsPlugin.d.ts +10 -10
- package/dist/builtin-plugin/ModuleConcatenationPlugin.d.ts +8 -10
- package/dist/builtin-plugin/lazy-compilation/lazyCompilation.d.ts +3 -3
- package/dist/builtin-plugin/lazy-compilation/plugin.d.ts +3 -3
- package/dist/config/normalization.d.ts +3 -11
- package/dist/config/types.d.ts +28 -6
- package/dist/config/zod.d.ts +243 -93
- package/dist/exports.d.ts +2 -2
- package/dist/index.js +619 -269
- package/package.json +6 -6
- package/dist/lib/Dependency.d.ts +0 -23
- package/dist/lib/formatLocation.d.ts +0 -16
- package/dist/logging/runtime.d.ts +0 -16
- package/dist/util/IterableHelpers.d.ts +0 -12
- package/dist/util/scheme.d.ts +0 -6
- package/dist/util/webpack.d.ts +0 -4
|
@@ -8,8 +8,20 @@
|
|
|
8
8
|
const nextTick = require("process").nextTick;
|
|
9
9
|
|
|
10
10
|
/** @typedef {import("./Resolver").FileSystem} FileSystem */
|
|
11
|
+
/** @typedef {import("./Resolver").PathLike} PathLike */
|
|
12
|
+
/** @typedef {import("./Resolver").PathOrFileDescriptor} PathOrFileDescriptor */
|
|
11
13
|
/** @typedef {import("./Resolver").SyncFileSystem} SyncFileSystem */
|
|
14
|
+
/** @typedef {FileSystem & SyncFileSystem} BaseFileSystem */
|
|
12
15
|
|
|
16
|
+
/**
|
|
17
|
+
* @template T
|
|
18
|
+
* @typedef {import("./Resolver").FileSystemCallback<T>} FileSystemCallback<T>
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {string} path path
|
|
23
|
+
* @returns {string} dirname
|
|
24
|
+
*/
|
|
13
25
|
const dirname = path => {
|
|
14
26
|
let idx = path.length - 1;
|
|
15
27
|
while (idx >= 0) {
|
|
@@ -22,6 +34,12 @@ const dirname = path => {
|
|
|
22
34
|
return path.slice(0, idx);
|
|
23
35
|
};
|
|
24
36
|
|
|
37
|
+
/**
|
|
38
|
+
* @template T
|
|
39
|
+
* @param {FileSystemCallback<T>[]} callbacks callbacks
|
|
40
|
+
* @param {Error | null} err error
|
|
41
|
+
* @param {T} result result
|
|
42
|
+
*/
|
|
25
43
|
const runCallbacks = (callbacks, err, result) => {
|
|
26
44
|
if (callbacks.length === 1) {
|
|
27
45
|
callbacks[0](err, result);
|
|
@@ -42,9 +60,9 @@ const runCallbacks = (callbacks, err, result) => {
|
|
|
42
60
|
|
|
43
61
|
class OperationMergerBackend {
|
|
44
62
|
/**
|
|
45
|
-
* @param {
|
|
46
|
-
* @param {
|
|
47
|
-
* @param {
|
|
63
|
+
* @param {Function | undefined} provider async method in filesystem
|
|
64
|
+
* @param {Function | undefined} syncProvider sync method in filesystem
|
|
65
|
+
* @param {BaseFileSystem} providerContext call context for the provider methods
|
|
48
66
|
*/
|
|
49
67
|
constructor(provider, syncProvider, providerContext) {
|
|
50
68
|
this._provider = provider;
|
|
@@ -53,38 +71,69 @@ class OperationMergerBackend {
|
|
|
53
71
|
this._activeAsyncOperations = new Map();
|
|
54
72
|
|
|
55
73
|
this.provide = this._provider
|
|
56
|
-
?
|
|
74
|
+
? /**
|
|
75
|
+
* @param {PathLike | PathOrFileDescriptor} path path
|
|
76
|
+
* @param {object | FileSystemCallback<any> | undefined} options options
|
|
77
|
+
* @param {FileSystemCallback<any>=} callback callback
|
|
78
|
+
* @returns {any} result
|
|
79
|
+
*/
|
|
80
|
+
(path, options, callback) => {
|
|
57
81
|
if (typeof options === "function") {
|
|
58
|
-
callback = options;
|
|
82
|
+
callback = /** @type {FileSystemCallback<any>} */ (options);
|
|
59
83
|
options = undefined;
|
|
60
84
|
}
|
|
85
|
+
if (
|
|
86
|
+
typeof path !== "string" &&
|
|
87
|
+
!Buffer.isBuffer(path) &&
|
|
88
|
+
!(path instanceof URL) &&
|
|
89
|
+
typeof path !== "number"
|
|
90
|
+
) {
|
|
91
|
+
/** @type {Function} */
|
|
92
|
+
(callback)(
|
|
93
|
+
new TypeError("path must be a string, Buffer, URL or number")
|
|
94
|
+
);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
61
97
|
if (options) {
|
|
62
|
-
return this._provider.call(
|
|
98
|
+
return /** @type {Function} */ (this._provider).call(
|
|
63
99
|
this._providerContext,
|
|
64
100
|
path,
|
|
65
101
|
options,
|
|
66
102
|
callback
|
|
67
103
|
);
|
|
68
104
|
}
|
|
69
|
-
if (typeof path !== "string") {
|
|
70
|
-
callback(new TypeError("path must be a string"));
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
105
|
let callbacks = this._activeAsyncOperations.get(path);
|
|
74
106
|
if (callbacks) {
|
|
75
107
|
callbacks.push(callback);
|
|
76
108
|
return;
|
|
77
109
|
}
|
|
78
110
|
this._activeAsyncOperations.set(path, (callbacks = [callback]));
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
111
|
+
/** @type {Function} */
|
|
112
|
+
(provider)(
|
|
113
|
+
path,
|
|
114
|
+
/**
|
|
115
|
+
* @param {Error} err error
|
|
116
|
+
* @param {any} result result
|
|
117
|
+
*/
|
|
118
|
+
(err, result) => {
|
|
119
|
+
this._activeAsyncOperations.delete(path);
|
|
120
|
+
runCallbacks(callbacks, err, result);
|
|
121
|
+
}
|
|
122
|
+
);
|
|
83
123
|
}
|
|
84
124
|
: null;
|
|
85
125
|
this.provideSync = this._syncProvider
|
|
86
|
-
?
|
|
87
|
-
|
|
126
|
+
? /**
|
|
127
|
+
* @param {PathLike | PathOrFileDescriptor} path path
|
|
128
|
+
* @param {object=} options options
|
|
129
|
+
* @returns {any} result
|
|
130
|
+
*/
|
|
131
|
+
(path, options) => {
|
|
132
|
+
return /** @type {Function} */ (this._syncProvider).call(
|
|
133
|
+
this._providerContext,
|
|
134
|
+
path,
|
|
135
|
+
options
|
|
136
|
+
);
|
|
88
137
|
}
|
|
89
138
|
: null;
|
|
90
139
|
}
|
|
@@ -117,21 +166,29 @@ const STORAGE_MODE_IDLE = 0;
|
|
|
117
166
|
const STORAGE_MODE_SYNC = 1;
|
|
118
167
|
const STORAGE_MODE_ASYNC = 2;
|
|
119
168
|
|
|
169
|
+
/**
|
|
170
|
+
* @callback Provide
|
|
171
|
+
* @param {PathLike | PathOrFileDescriptor} path path
|
|
172
|
+
* @param {any} options options
|
|
173
|
+
* @param {FileSystemCallback<any>} callback callback
|
|
174
|
+
* @returns {void}
|
|
175
|
+
*/
|
|
176
|
+
|
|
120
177
|
class CacheBackend {
|
|
121
178
|
/**
|
|
122
179
|
* @param {number} duration max cache duration of items
|
|
123
|
-
* @param {
|
|
124
|
-
* @param {
|
|
125
|
-
* @param {
|
|
180
|
+
* @param {function | undefined} provider async method
|
|
181
|
+
* @param {function | undefined} syncProvider sync method
|
|
182
|
+
* @param {BaseFileSystem} providerContext call context for the provider methods
|
|
126
183
|
*/
|
|
127
184
|
constructor(duration, provider, syncProvider, providerContext) {
|
|
128
185
|
this._duration = duration;
|
|
129
186
|
this._provider = provider;
|
|
130
187
|
this._syncProvider = syncProvider;
|
|
131
188
|
this._providerContext = providerContext;
|
|
132
|
-
/** @type {Map<string,
|
|
189
|
+
/** @type {Map<string, FileSystemCallback<any>[]>} */
|
|
133
190
|
this._activeAsyncOperations = new Map();
|
|
134
|
-
/** @type {Map<string, { err: Error, result
|
|
191
|
+
/** @type {Map<string, { err: Error | null, result?: any, level: Set<string> }>} */
|
|
135
192
|
this._data = new Map();
|
|
136
193
|
/** @type {Set<string>[]} */
|
|
137
194
|
this._levels = [];
|
|
@@ -147,21 +204,35 @@ class CacheBackend {
|
|
|
147
204
|
/** @type {number | undefined} */
|
|
148
205
|
this._nextDecay = undefined;
|
|
149
206
|
|
|
207
|
+
// @ts-ignore
|
|
150
208
|
this.provide = provider ? this.provide.bind(this) : null;
|
|
209
|
+
// @ts-ignore
|
|
151
210
|
this.provideSync = syncProvider ? this.provideSync.bind(this) : null;
|
|
152
211
|
}
|
|
153
212
|
|
|
213
|
+
/**
|
|
214
|
+
* @param {PathLike | PathOrFileDescriptor} path path
|
|
215
|
+
* @param {any} options options
|
|
216
|
+
* @param {FileSystemCallback<any>} callback callback
|
|
217
|
+
* @returns {void}
|
|
218
|
+
*/
|
|
154
219
|
provide(path, options, callback) {
|
|
155
220
|
if (typeof options === "function") {
|
|
156
221
|
callback = options;
|
|
157
222
|
options = undefined;
|
|
158
223
|
}
|
|
159
|
-
if (
|
|
160
|
-
|
|
224
|
+
if (
|
|
225
|
+
typeof path !== "string" &&
|
|
226
|
+
!Buffer.isBuffer(path) &&
|
|
227
|
+
!(path instanceof URL) &&
|
|
228
|
+
typeof path !== "number"
|
|
229
|
+
) {
|
|
230
|
+
callback(new TypeError("path must be a string, Buffer, URL or number"));
|
|
161
231
|
return;
|
|
162
232
|
}
|
|
233
|
+
const strPath = typeof path !== "string" ? path.toString() : path;
|
|
163
234
|
if (options) {
|
|
164
|
-
return this._provider.call(
|
|
235
|
+
return /** @type {Function} */ (this._provider).call(
|
|
165
236
|
this._providerContext,
|
|
166
237
|
path,
|
|
167
238
|
options,
|
|
@@ -175,38 +246,66 @@ class CacheBackend {
|
|
|
175
246
|
}
|
|
176
247
|
|
|
177
248
|
// Check in cache
|
|
178
|
-
let cacheEntry = this._data.get(
|
|
249
|
+
let cacheEntry = this._data.get(strPath);
|
|
179
250
|
if (cacheEntry !== undefined) {
|
|
180
251
|
if (cacheEntry.err) return nextTick(callback, cacheEntry.err);
|
|
181
252
|
return nextTick(callback, null, cacheEntry.result);
|
|
182
253
|
}
|
|
183
254
|
|
|
184
255
|
// Check if there is already the same operation running
|
|
185
|
-
let callbacks = this._activeAsyncOperations.get(
|
|
256
|
+
let callbacks = this._activeAsyncOperations.get(strPath);
|
|
186
257
|
if (callbacks !== undefined) {
|
|
187
258
|
callbacks.push(callback);
|
|
188
259
|
return;
|
|
189
260
|
}
|
|
190
|
-
this._activeAsyncOperations.set(
|
|
261
|
+
this._activeAsyncOperations.set(strPath, (callbacks = [callback]));
|
|
191
262
|
|
|
192
263
|
// Run the operation
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
this.
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
264
|
+
/** @type {Function} */
|
|
265
|
+
(this._provider).call(
|
|
266
|
+
this._providerContext,
|
|
267
|
+
path,
|
|
268
|
+
/**
|
|
269
|
+
* @param {Error | null} err error
|
|
270
|
+
* @param {any} [result] result
|
|
271
|
+
*/
|
|
272
|
+
(err, result) => {
|
|
273
|
+
this._activeAsyncOperations.delete(strPath);
|
|
274
|
+
this._storeResult(strPath, err, result);
|
|
275
|
+
|
|
276
|
+
// Enter async mode if not yet done
|
|
277
|
+
this._enterAsyncMode();
|
|
278
|
+
|
|
279
|
+
runCallbacks(
|
|
280
|
+
/** @type {FileSystemCallback<any>[]} */ (callbacks),
|
|
281
|
+
err,
|
|
282
|
+
result
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
);
|
|
202
286
|
}
|
|
203
287
|
|
|
288
|
+
/**
|
|
289
|
+
* @param {PathLike | PathOrFileDescriptor} path path
|
|
290
|
+
* @param {any} options options
|
|
291
|
+
* @returns {any} result
|
|
292
|
+
*/
|
|
204
293
|
provideSync(path, options) {
|
|
205
|
-
if (
|
|
294
|
+
if (
|
|
295
|
+
typeof path !== "string" &&
|
|
296
|
+
!Buffer.isBuffer(path) &&
|
|
297
|
+
!(path instanceof URL) &&
|
|
298
|
+
typeof path !== "number"
|
|
299
|
+
) {
|
|
206
300
|
throw new TypeError("path must be a string");
|
|
207
301
|
}
|
|
302
|
+
const strPath = typeof path !== "string" ? path.toString() : path;
|
|
208
303
|
if (options) {
|
|
209
|
-
return this._syncProvider.call(
|
|
304
|
+
return /** @type {Function} */ (this._syncProvider).call(
|
|
305
|
+
this._providerContext,
|
|
306
|
+
path,
|
|
307
|
+
options
|
|
308
|
+
);
|
|
210
309
|
}
|
|
211
310
|
|
|
212
311
|
// In sync mode we may have to decay some cache items
|
|
@@ -215,7 +314,7 @@ class CacheBackend {
|
|
|
215
314
|
}
|
|
216
315
|
|
|
217
316
|
// Check in cache
|
|
218
|
-
let cacheEntry = this._data.get(
|
|
317
|
+
let cacheEntry = this._data.get(strPath);
|
|
219
318
|
if (cacheEntry !== undefined) {
|
|
220
319
|
if (cacheEntry.err) throw cacheEntry.err;
|
|
221
320
|
return cacheEntry.result;
|
|
@@ -223,26 +322,36 @@ class CacheBackend {
|
|
|
223
322
|
|
|
224
323
|
// Get all active async operations
|
|
225
324
|
// This sync operation will also complete them
|
|
226
|
-
const callbacks = this._activeAsyncOperations.get(
|
|
227
|
-
this._activeAsyncOperations.delete(
|
|
325
|
+
const callbacks = this._activeAsyncOperations.get(strPath);
|
|
326
|
+
this._activeAsyncOperations.delete(strPath);
|
|
228
327
|
|
|
229
328
|
// Run the operation
|
|
230
329
|
// When in idle mode, we will enter sync mode
|
|
231
330
|
let result;
|
|
232
331
|
try {
|
|
233
|
-
result = this._syncProvider.call(
|
|
332
|
+
result = /** @type {Function} */ (this._syncProvider).call(
|
|
333
|
+
this._providerContext,
|
|
334
|
+
path
|
|
335
|
+
);
|
|
234
336
|
} catch (err) {
|
|
235
|
-
this._storeResult(
|
|
337
|
+
this._storeResult(strPath, /** @type {Error} */ (err), undefined);
|
|
236
338
|
this._enterSyncModeWhenIdle();
|
|
237
|
-
if (callbacks)
|
|
339
|
+
if (callbacks) {
|
|
340
|
+
runCallbacks(callbacks, /** @type {Error} */ (err), undefined);
|
|
341
|
+
}
|
|
238
342
|
throw err;
|
|
239
343
|
}
|
|
240
|
-
this._storeResult(
|
|
344
|
+
this._storeResult(strPath, null, result);
|
|
241
345
|
this._enterSyncModeWhenIdle();
|
|
242
|
-
if (callbacks)
|
|
346
|
+
if (callbacks) {
|
|
347
|
+
runCallbacks(callbacks, null, result);
|
|
348
|
+
}
|
|
243
349
|
return result;
|
|
244
350
|
}
|
|
245
351
|
|
|
352
|
+
/**
|
|
353
|
+
* @param {string | Buffer | URL | number | (string | URL | Buffer | number)[] | Set<string | URL | Buffer | number>} [what] what to purge
|
|
354
|
+
*/
|
|
246
355
|
purge(what) {
|
|
247
356
|
if (!what) {
|
|
248
357
|
if (this._mode !== STORAGE_MODE_IDLE) {
|
|
@@ -252,9 +361,15 @@ class CacheBackend {
|
|
|
252
361
|
}
|
|
253
362
|
this._enterIdleMode();
|
|
254
363
|
}
|
|
255
|
-
} else if (
|
|
364
|
+
} else if (
|
|
365
|
+
typeof what === "string" ||
|
|
366
|
+
Buffer.isBuffer(what) ||
|
|
367
|
+
what instanceof URL ||
|
|
368
|
+
typeof what === "number"
|
|
369
|
+
) {
|
|
370
|
+
const strWhat = typeof what !== "string" ? what.toString() : what;
|
|
256
371
|
for (let [key, data] of this._data) {
|
|
257
|
-
if (key.startsWith(
|
|
372
|
+
if (key.startsWith(strWhat)) {
|
|
258
373
|
this._data.delete(key);
|
|
259
374
|
data.level.delete(key);
|
|
260
375
|
}
|
|
@@ -265,7 +380,8 @@ class CacheBackend {
|
|
|
265
380
|
} else {
|
|
266
381
|
for (let [key, data] of this._data) {
|
|
267
382
|
for (const item of what) {
|
|
268
|
-
|
|
383
|
+
const strItem = typeof item !== "string" ? item.toString() : item;
|
|
384
|
+
if (key.startsWith(strItem)) {
|
|
269
385
|
this._data.delete(key);
|
|
270
386
|
data.level.delete(key);
|
|
271
387
|
break;
|
|
@@ -278,20 +394,35 @@ class CacheBackend {
|
|
|
278
394
|
}
|
|
279
395
|
}
|
|
280
396
|
|
|
397
|
+
/**
|
|
398
|
+
* @param {string | Buffer | URL | number | (string | URL | Buffer | number)[] | Set<string | URL | Buffer | number>} [what] what to purge
|
|
399
|
+
*/
|
|
281
400
|
purgeParent(what) {
|
|
282
401
|
if (!what) {
|
|
283
402
|
this.purge();
|
|
284
|
-
} else if (
|
|
285
|
-
|
|
403
|
+
} else if (
|
|
404
|
+
typeof what === "string" ||
|
|
405
|
+
Buffer.isBuffer(what) ||
|
|
406
|
+
what instanceof URL ||
|
|
407
|
+
typeof what === "number"
|
|
408
|
+
) {
|
|
409
|
+
const strWhat = typeof what !== "string" ? what.toString() : what;
|
|
410
|
+
this.purge(dirname(strWhat));
|
|
286
411
|
} else {
|
|
287
412
|
const set = new Set();
|
|
288
413
|
for (const item of what) {
|
|
289
|
-
|
|
414
|
+
const strItem = typeof item !== "string" ? item.toString() : item;
|
|
415
|
+
set.add(dirname(strItem));
|
|
290
416
|
}
|
|
291
417
|
this.purge(set);
|
|
292
418
|
}
|
|
293
419
|
}
|
|
294
420
|
|
|
421
|
+
/**
|
|
422
|
+
* @param {string} path path
|
|
423
|
+
* @param {Error | null} err error
|
|
424
|
+
* @param {any} result result
|
|
425
|
+
*/
|
|
295
426
|
_storeResult(path, err, result) {
|
|
296
427
|
if (this._data.has(path)) return;
|
|
297
428
|
const level = this._levels[this._currentLevel];
|
|
@@ -310,8 +441,8 @@ class CacheBackend {
|
|
|
310
441
|
if (this._data.size === 0) {
|
|
311
442
|
this._enterIdleMode();
|
|
312
443
|
} else {
|
|
313
|
-
|
|
314
|
-
this._nextDecay += this._tickInterval;
|
|
444
|
+
/** @type {number} */
|
|
445
|
+
(this._nextDecay) += this._tickInterval;
|
|
315
446
|
}
|
|
316
447
|
}
|
|
317
448
|
|
|
@@ -335,8 +466,12 @@ class CacheBackend {
|
|
|
335
466
|
break;
|
|
336
467
|
case STORAGE_MODE_SYNC:
|
|
337
468
|
this._runDecays();
|
|
338
|
-
//
|
|
339
|
-
if (
|
|
469
|
+
// _runDecays may change the mode
|
|
470
|
+
if (
|
|
471
|
+
/** @type {STORAGE_MODE_IDLE | STORAGE_MODE_SYNC | STORAGE_MODE_ASYNC}*/
|
|
472
|
+
(this._mode) === STORAGE_MODE_IDLE
|
|
473
|
+
)
|
|
474
|
+
return;
|
|
340
475
|
timeout = Math.max(
|
|
341
476
|
0,
|
|
342
477
|
/** @type {number} */ (this._nextDecay) - Date.now()
|
|
@@ -366,6 +501,16 @@ class CacheBackend {
|
|
|
366
501
|
}
|
|
367
502
|
}
|
|
368
503
|
|
|
504
|
+
/**
|
|
505
|
+
* @template {function} Provider
|
|
506
|
+
* @template {function} AsyncProvider
|
|
507
|
+
* @template FileSystem
|
|
508
|
+
* @param {number} duration duration in ms files are cached
|
|
509
|
+
* @param {Provider | undefined} provider provider
|
|
510
|
+
* @param {AsyncProvider | undefined} syncProvider sync provider
|
|
511
|
+
* @param {BaseFileSystem} providerContext provider context
|
|
512
|
+
* @returns {OperationMergerBackend | CacheBackend} backend
|
|
513
|
+
*/
|
|
369
514
|
const createBackend = (duration, provider, syncProvider, providerContext) => {
|
|
370
515
|
if (duration > 0) {
|
|
371
516
|
return new CacheBackend(duration, provider, syncProvider, providerContext);
|
|
@@ -374,6 +519,10 @@ const createBackend = (duration, provider, syncProvider, providerContext) => {
|
|
|
374
519
|
};
|
|
375
520
|
|
|
376
521
|
module.exports = class CachedInputFileSystem {
|
|
522
|
+
/**
|
|
523
|
+
* @param {BaseFileSystem} fileSystem file system
|
|
524
|
+
* @param {number} duration duration in ms files are cached
|
|
525
|
+
*/
|
|
377
526
|
constructor(fileSystem, duration) {
|
|
378
527
|
this.fileSystem = fileSystem;
|
|
379
528
|
|
|
@@ -408,7 +557,9 @@ module.exports = class CachedInputFileSystem {
|
|
|
408
557
|
const readdir = this._readdirBackend.provide;
|
|
409
558
|
this.readdir = /** @type {FileSystem["readdir"]} */ (readdir);
|
|
410
559
|
const readdirSync = this._readdirBackend.provideSync;
|
|
411
|
-
this.readdirSync = /** @type {SyncFileSystem["readdirSync"]} */ (
|
|
560
|
+
this.readdirSync = /** @type {SyncFileSystem["readdirSync"]} */ (
|
|
561
|
+
readdirSync
|
|
562
|
+
);
|
|
412
563
|
|
|
413
564
|
this._readFileBackend = createBackend(
|
|
414
565
|
duration,
|
|
@@ -419,40 +570,57 @@ module.exports = class CachedInputFileSystem {
|
|
|
419
570
|
const readFile = this._readFileBackend.provide;
|
|
420
571
|
this.readFile = /** @type {FileSystem["readFile"]} */ (readFile);
|
|
421
572
|
const readFileSync = this._readFileBackend.provideSync;
|
|
422
|
-
this.readFileSync = /** @type {SyncFileSystem["readFileSync"]} */ (
|
|
573
|
+
this.readFileSync = /** @type {SyncFileSystem["readFileSync"]} */ (
|
|
574
|
+
readFileSync
|
|
575
|
+
);
|
|
423
576
|
|
|
424
577
|
this._readJsonBackend = createBackend(
|
|
425
578
|
duration,
|
|
579
|
+
// prettier-ignore
|
|
426
580
|
this.fileSystem.readJson ||
|
|
427
581
|
(this.readFile &&
|
|
428
|
-
(
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
582
|
+
(
|
|
583
|
+
/**
|
|
584
|
+
* @param {string} path path
|
|
585
|
+
* @param {FileSystemCallback<any>} callback
|
|
586
|
+
*/
|
|
587
|
+
(path, callback) => {
|
|
588
|
+
this.readFile(path, (err, buffer) => {
|
|
589
|
+
if (err) return callback(err);
|
|
590
|
+
if (!buffer || buffer.length === 0)
|
|
591
|
+
return callback(new Error("No file content"));
|
|
592
|
+
let data;
|
|
593
|
+
try {
|
|
594
|
+
data = JSON.parse(buffer.toString("utf-8"));
|
|
595
|
+
} catch (e) {
|
|
596
|
+
return callback(/** @type {Error} */ (e));
|
|
597
|
+
}
|
|
598
|
+
callback(null, data);
|
|
599
|
+
});
|
|
600
|
+
})
|
|
601
|
+
),
|
|
602
|
+
// prettier-ignore
|
|
443
603
|
this.fileSystem.readJsonSync ||
|
|
444
604
|
(this.readFileSync &&
|
|
445
|
-
(
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
605
|
+
(
|
|
606
|
+
/**
|
|
607
|
+
* @param {string} path path
|
|
608
|
+
* @returns {any} result
|
|
609
|
+
*/
|
|
610
|
+
(path) => {
|
|
611
|
+
const buffer = this.readFileSync(path);
|
|
612
|
+
const data = JSON.parse(buffer.toString("utf-8"));
|
|
613
|
+
return data;
|
|
614
|
+
}
|
|
615
|
+
)),
|
|
450
616
|
this.fileSystem
|
|
451
617
|
);
|
|
452
618
|
const readJson = this._readJsonBackend.provide;
|
|
453
619
|
this.readJson = /** @type {FileSystem["readJson"]} */ (readJson);
|
|
454
620
|
const readJsonSync = this._readJsonBackend.provideSync;
|
|
455
|
-
this.readJsonSync = /** @type {SyncFileSystem["readJsonSync"]} */ (
|
|
621
|
+
this.readJsonSync = /** @type {SyncFileSystem["readJsonSync"]} */ (
|
|
622
|
+
readJsonSync
|
|
623
|
+
);
|
|
456
624
|
|
|
457
625
|
this._readlinkBackend = createBackend(
|
|
458
626
|
duration,
|
|
@@ -463,9 +631,27 @@ module.exports = class CachedInputFileSystem {
|
|
|
463
631
|
const readlink = this._readlinkBackend.provide;
|
|
464
632
|
this.readlink = /** @type {FileSystem["readlink"]} */ (readlink);
|
|
465
633
|
const readlinkSync = this._readlinkBackend.provideSync;
|
|
466
|
-
this.readlinkSync = /** @type {SyncFileSystem["readlinkSync"]} */ (
|
|
634
|
+
this.readlinkSync = /** @type {SyncFileSystem["readlinkSync"]} */ (
|
|
635
|
+
readlinkSync
|
|
636
|
+
);
|
|
637
|
+
|
|
638
|
+
this._realpathBackend = createBackend(
|
|
639
|
+
duration,
|
|
640
|
+
this.fileSystem.realpath,
|
|
641
|
+
this.fileSystem.realpathSync,
|
|
642
|
+
this.fileSystem
|
|
643
|
+
);
|
|
644
|
+
const realpath = this._realpathBackend.provide;
|
|
645
|
+
this.realpath = /** @type {FileSystem["realpath"]} */ (realpath);
|
|
646
|
+
const realpathSync = this._realpathBackend.provideSync;
|
|
647
|
+
this.realpathSync = /** @type {SyncFileSystem["realpathSync"]} */ (
|
|
648
|
+
realpathSync
|
|
649
|
+
);
|
|
467
650
|
}
|
|
468
651
|
|
|
652
|
+
/**
|
|
653
|
+
* @param {string | Buffer | URL | number | (string | URL | Buffer | number)[] | Set<string | URL | Buffer | number>} [what] what to purge
|
|
654
|
+
*/
|
|
469
655
|
purge(what) {
|
|
470
656
|
this._statBackend.purge(what);
|
|
471
657
|
this._lstatBackend.purge(what);
|
|
@@ -473,5 +659,6 @@ module.exports = class CachedInputFileSystem {
|
|
|
473
659
|
this._readFileBackend.purge(what);
|
|
474
660
|
this._readlinkBackend.purge(what);
|
|
475
661
|
this._readJsonBackend.purge(what);
|
|
662
|
+
this._realpathBackend.purge(what);
|
|
476
663
|
}
|
|
477
664
|
};
|