@batijs/core 0.0.503 → 0.0.504
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/dist/chunk-3TAKLMXD.js +56 -0
- package/dist/chunk-JVQRSLU3.js +56 -0
- package/dist/chunk-RBCZH3S6.js +9 -0
- package/dist/index.js +1 -1
- package/dist/jiti-47QGSKUN.js +478 -0
- package/dist/jiti-4VHEHEJ6.js +478 -0
- package/dist/jiti-D5GFFX4C.js +478 -0
- package/dist/jiti-EM3N2G3P.js +483 -0
- package/dist/jiti-GY3WFVF7.js +478 -0
- package/dist/jiti-HOWX5ILP.js +478 -0
- package/dist/jiti-M7FFFMJY.js +478 -0
- package/dist/jiti-PTT4ZTBB.js +31390 -0
- package/dist/jiti-QYPC42DC.js +478 -0
- package/dist/jiti-UD6PBW7S.js +31390 -0
- package/dist/jiti-W5Y5D52V.js +483 -0
- package/dist/lib-NAFETZUN.js +450 -0
- package/dist/src-C44KL7DE.js +9 -0
- package/dist/src-CE4VNZ74.js +1127 -0
- package/dist/src-UAKFXUB2.js +9 -0
- package/dist/src-UC4KONXL.js +9 -0
- package/dist/src-YD6KR7KC.js +1127 -0
- package/dist/src-ZXRHWERC.js +9 -0
- package/package.json +2 -2
|
@@ -0,0 +1,1127 @@
|
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
import { fileURLToPath as BATI_fileURLToPath } from "node:url";
|
|
3
|
+
import { dirname as BATI_dirname } from "node:path";
|
|
4
|
+
const require = createRequire(import.meta.url);
|
|
5
|
+
|
|
6
|
+
const __filename = BATI_fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = BATI_dirname(__filename);
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
__esm
|
|
11
|
+
} from "./chunk-JVQRSLU3.js";
|
|
12
|
+
|
|
13
|
+
// ../../node_modules/.pnpm/@humanfs+core@0.19.1/node_modules/@humanfs/core/src/hfs.js
|
|
14
|
+
function assertValidFileOrDirPath(fileOrDirPath) {
|
|
15
|
+
if (!fileOrDirPath || !(fileOrDirPath instanceof URL) && typeof fileOrDirPath !== "string") {
|
|
16
|
+
throw new TypeError("Path must be a non-empty string or URL.");
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function assertValidFileContents(contents) {
|
|
20
|
+
if (typeof contents !== "string" && !(contents instanceof ArrayBuffer) && !ArrayBuffer.isView(contents)) {
|
|
21
|
+
throw new TypeError(
|
|
22
|
+
"File contents must be a string, ArrayBuffer, or ArrayBuffer view."
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function toUint8Array(contents) {
|
|
27
|
+
if (contents instanceof Uint8Array) {
|
|
28
|
+
return contents;
|
|
29
|
+
}
|
|
30
|
+
if (typeof contents === "string") {
|
|
31
|
+
return encoder.encode(contents);
|
|
32
|
+
}
|
|
33
|
+
if (contents instanceof ArrayBuffer) {
|
|
34
|
+
return new Uint8Array(contents);
|
|
35
|
+
}
|
|
36
|
+
if (ArrayBuffer.isView(contents)) {
|
|
37
|
+
const bytes = contents.buffer.slice(
|
|
38
|
+
contents.byteOffset,
|
|
39
|
+
contents.byteOffset + contents.byteLength
|
|
40
|
+
);
|
|
41
|
+
return new Uint8Array(bytes);
|
|
42
|
+
}
|
|
43
|
+
throw new TypeError(
|
|
44
|
+
"Invalid contents type. Expected string or ArrayBuffer."
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
var decoder, encoder, NoSuchMethodError, MethodNotSupportedError, ImplAlreadySetError, LogEntry, Hfs;
|
|
48
|
+
var init_hfs = __esm({
|
|
49
|
+
"../../node_modules/.pnpm/@humanfs+core@0.19.1/node_modules/@humanfs/core/src/hfs.js"() {
|
|
50
|
+
"use strict";
|
|
51
|
+
decoder = new TextDecoder();
|
|
52
|
+
encoder = new TextEncoder();
|
|
53
|
+
NoSuchMethodError = class extends Error {
|
|
54
|
+
/**
|
|
55
|
+
* Creates a new instance.
|
|
56
|
+
* @param {string} methodName The name of the method that was missing.
|
|
57
|
+
*/
|
|
58
|
+
constructor(methodName) {
|
|
59
|
+
super(`Method "${methodName}" does not exist on impl.`);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
MethodNotSupportedError = class extends Error {
|
|
63
|
+
/**
|
|
64
|
+
* Creates a new instance.
|
|
65
|
+
* @param {string} methodName The name of the method that was missing.
|
|
66
|
+
*/
|
|
67
|
+
constructor(methodName) {
|
|
68
|
+
super(`Method "${methodName}" is not supported on this impl.`);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
ImplAlreadySetError = class extends Error {
|
|
72
|
+
/**
|
|
73
|
+
* Creates a new instance.
|
|
74
|
+
*/
|
|
75
|
+
constructor() {
|
|
76
|
+
super(`Implementation already set.`);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
LogEntry = class {
|
|
80
|
+
/**
|
|
81
|
+
* The type of log entry.
|
|
82
|
+
* @type {string}
|
|
83
|
+
*/
|
|
84
|
+
type;
|
|
85
|
+
/**
|
|
86
|
+
* The data associated with the log entry.
|
|
87
|
+
* @type {any}
|
|
88
|
+
*/
|
|
89
|
+
data;
|
|
90
|
+
/**
|
|
91
|
+
* The time at which the log entry was created.
|
|
92
|
+
* @type {number}
|
|
93
|
+
*/
|
|
94
|
+
timestamp = Date.now();
|
|
95
|
+
/**
|
|
96
|
+
* Creates a new instance.
|
|
97
|
+
* @param {string} type The type of log entry.
|
|
98
|
+
* @param {any} [data] The data associated with the log entry.
|
|
99
|
+
*/
|
|
100
|
+
constructor(type, data) {
|
|
101
|
+
this.type = type;
|
|
102
|
+
this.data = data;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
Hfs = class {
|
|
106
|
+
/**
|
|
107
|
+
* The base implementation for this instance.
|
|
108
|
+
* @type {HfsImpl}
|
|
109
|
+
*/
|
|
110
|
+
#baseImpl;
|
|
111
|
+
/**
|
|
112
|
+
* The current implementation for this instance.
|
|
113
|
+
* @type {HfsImpl}
|
|
114
|
+
*/
|
|
115
|
+
#impl;
|
|
116
|
+
/**
|
|
117
|
+
* A map of log names to their corresponding entries.
|
|
118
|
+
* @type {Map<string,Array<LogEntry>>}
|
|
119
|
+
*/
|
|
120
|
+
#logs = /* @__PURE__ */ new Map();
|
|
121
|
+
/**
|
|
122
|
+
* Creates a new instance.
|
|
123
|
+
* @param {object} options The options for the instance.
|
|
124
|
+
* @param {HfsImpl} options.impl The implementation to use.
|
|
125
|
+
*/
|
|
126
|
+
constructor({ impl }) {
|
|
127
|
+
this.#baseImpl = impl;
|
|
128
|
+
this.#impl = impl;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Logs an entry onto all currently open logs.
|
|
132
|
+
* @param {string} methodName The name of the method being called.
|
|
133
|
+
* @param {...*} args The arguments to the method.
|
|
134
|
+
* @returns {void}
|
|
135
|
+
*/
|
|
136
|
+
#log(methodName, ...args) {
|
|
137
|
+
for (const logs of this.#logs.values()) {
|
|
138
|
+
logs.push(new LogEntry("call", { methodName, args }));
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Starts a new log with the given name.
|
|
143
|
+
* @param {string} name The name of the log to start;
|
|
144
|
+
* @returns {void}
|
|
145
|
+
* @throws {Error} When the log already exists.
|
|
146
|
+
* @throws {TypeError} When the name is not a non-empty string.
|
|
147
|
+
*/
|
|
148
|
+
logStart(name) {
|
|
149
|
+
if (!name || typeof name !== "string") {
|
|
150
|
+
throw new TypeError("Log name must be a non-empty string.");
|
|
151
|
+
}
|
|
152
|
+
if (this.#logs.has(name)) {
|
|
153
|
+
throw new Error(`Log "${name}" already exists.`);
|
|
154
|
+
}
|
|
155
|
+
this.#logs.set(name, []);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Ends a log with the given name and returns the entries.
|
|
159
|
+
* @param {string} name The name of the log to end.
|
|
160
|
+
* @returns {Array<LogEntry>} The entries in the log.
|
|
161
|
+
* @throws {Error} When the log does not exist.
|
|
162
|
+
*/
|
|
163
|
+
logEnd(name) {
|
|
164
|
+
if (this.#logs.has(name)) {
|
|
165
|
+
const logs = this.#logs.get(name);
|
|
166
|
+
this.#logs.delete(name);
|
|
167
|
+
return logs;
|
|
168
|
+
}
|
|
169
|
+
throw new Error(`Log "${name}" does not exist.`);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Determines if the current implementation is the base implementation.
|
|
173
|
+
* @returns {boolean} True if the current implementation is the base implementation.
|
|
174
|
+
*/
|
|
175
|
+
isBaseImpl() {
|
|
176
|
+
return this.#impl === this.#baseImpl;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Sets the implementation for this instance.
|
|
180
|
+
* @param {object} impl The implementation to use.
|
|
181
|
+
* @returns {void}
|
|
182
|
+
*/
|
|
183
|
+
setImpl(impl) {
|
|
184
|
+
this.#log("implSet", impl);
|
|
185
|
+
if (this.#impl !== this.#baseImpl) {
|
|
186
|
+
throw new ImplAlreadySetError();
|
|
187
|
+
}
|
|
188
|
+
this.#impl = impl;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Resets the implementation for this instance back to its original.
|
|
192
|
+
* @returns {void}
|
|
193
|
+
*/
|
|
194
|
+
resetImpl() {
|
|
195
|
+
this.#log("implReset");
|
|
196
|
+
this.#impl = this.#baseImpl;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Asserts that the given method exists on the current implementation.
|
|
200
|
+
* @param {string} methodName The name of the method to check.
|
|
201
|
+
* @returns {void}
|
|
202
|
+
* @throws {NoSuchMethodError} When the method does not exist on the current implementation.
|
|
203
|
+
*/
|
|
204
|
+
#assertImplMethod(methodName) {
|
|
205
|
+
if (typeof this.#impl[methodName] !== "function") {
|
|
206
|
+
throw new NoSuchMethodError(methodName);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Asserts that the given method exists on the current implementation, and if not,
|
|
211
|
+
* throws an error with a different method name.
|
|
212
|
+
* @param {string} methodName The name of the method to check.
|
|
213
|
+
* @param {string} targetMethodName The name of the method that should be reported
|
|
214
|
+
* as an error when methodName does not exist.
|
|
215
|
+
* @returns {void}
|
|
216
|
+
* @throws {NoSuchMethodError} When the method does not exist on the current implementation.
|
|
217
|
+
*/
|
|
218
|
+
#assertImplMethodAlt(methodName, targetMethodName) {
|
|
219
|
+
if (typeof this.#impl[methodName] !== "function") {
|
|
220
|
+
throw new MethodNotSupportedError(targetMethodName);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Calls the given method on the current implementation.
|
|
225
|
+
* @param {string} methodName The name of the method to call.
|
|
226
|
+
* @param {...any} args The arguments to the method.
|
|
227
|
+
* @returns {any} The return value from the method.
|
|
228
|
+
* @throws {NoSuchMethodError} When the method does not exist on the current implementation.
|
|
229
|
+
*/
|
|
230
|
+
#callImplMethod(methodName, ...args) {
|
|
231
|
+
this.#log(methodName, ...args);
|
|
232
|
+
this.#assertImplMethod(methodName);
|
|
233
|
+
return this.#impl[methodName](...args);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Calls the given method on the current implementation and doesn't log the call.
|
|
237
|
+
* @param {string} methodName The name of the method to call.
|
|
238
|
+
* @param {...any} args The arguments to the method.
|
|
239
|
+
* @returns {any} The return value from the method.
|
|
240
|
+
* @throws {NoSuchMethodError} When the method does not exist on the current implementation.
|
|
241
|
+
*/
|
|
242
|
+
#callImplMethodWithoutLog(methodName, ...args) {
|
|
243
|
+
this.#assertImplMethod(methodName);
|
|
244
|
+
return this.#impl[methodName](...args);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Calls the given method on the current implementation but logs a different method name.
|
|
248
|
+
* @param {string} methodName The name of the method to call.
|
|
249
|
+
* @param {string} targetMethodName The name of the method to log.
|
|
250
|
+
* @param {...any} args The arguments to the method.
|
|
251
|
+
* @returns {any} The return value from the method.
|
|
252
|
+
* @throws {NoSuchMethodError} When the method does not exist on the current implementation.
|
|
253
|
+
*/
|
|
254
|
+
#callImplMethodAlt(methodName, targetMethodName, ...args) {
|
|
255
|
+
this.#log(targetMethodName, ...args);
|
|
256
|
+
this.#assertImplMethodAlt(methodName, targetMethodName);
|
|
257
|
+
return this.#impl[methodName](...args);
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Reads the given file and returns the contents as text. Assumes UTF-8 encoding.
|
|
261
|
+
* @param {string|URL} filePath The file to read.
|
|
262
|
+
* @returns {Promise<string|undefined>} The contents of the file.
|
|
263
|
+
* @throws {NoSuchMethodError} When the method does not exist on the current implementation.
|
|
264
|
+
* @throws {TypeError} When the file path is not a non-empty string.
|
|
265
|
+
*/
|
|
266
|
+
async text(filePath) {
|
|
267
|
+
assertValidFileOrDirPath(filePath);
|
|
268
|
+
const result = await this.#callImplMethodAlt("bytes", "text", filePath);
|
|
269
|
+
return result ? decoder.decode(result) : void 0;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Reads the given file and returns the contents as JSON. Assumes UTF-8 encoding.
|
|
273
|
+
* @param {string|URL} filePath The file to read.
|
|
274
|
+
* @returns {Promise<any|undefined>} The contents of the file as JSON.
|
|
275
|
+
* @throws {NoSuchMethodError} When the method does not exist on the current implementation.
|
|
276
|
+
* @throws {SyntaxError} When the file contents are not valid JSON.
|
|
277
|
+
* @throws {TypeError} When the file path is not a non-empty string.
|
|
278
|
+
*/
|
|
279
|
+
async json(filePath) {
|
|
280
|
+
assertValidFileOrDirPath(filePath);
|
|
281
|
+
const result = await this.#callImplMethodAlt("bytes", "json", filePath);
|
|
282
|
+
return result ? JSON.parse(decoder.decode(result)) : void 0;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Reads the given file and returns the contents as an ArrayBuffer.
|
|
286
|
+
* @param {string|URL} filePath The file to read.
|
|
287
|
+
* @returns {Promise<ArrayBuffer|undefined>} The contents of the file as an ArrayBuffer.
|
|
288
|
+
* @throws {NoSuchMethodError} When the method does not exist on the current implementation.
|
|
289
|
+
* @throws {TypeError} When the file path is not a non-empty string.
|
|
290
|
+
* @deprecated Use bytes() instead.
|
|
291
|
+
*/
|
|
292
|
+
async arrayBuffer(filePath) {
|
|
293
|
+
assertValidFileOrDirPath(filePath);
|
|
294
|
+
const result = await this.#callImplMethodAlt(
|
|
295
|
+
"bytes",
|
|
296
|
+
"arrayBuffer",
|
|
297
|
+
filePath
|
|
298
|
+
);
|
|
299
|
+
return result?.buffer;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Reads the given file and returns the contents as an Uint8Array.
|
|
303
|
+
* @param {string|URL} filePath The file to read.
|
|
304
|
+
* @returns {Promise<Uint8Array|undefined>} The contents of the file as an Uint8Array.
|
|
305
|
+
* @throws {NoSuchMethodError} When the method does not exist on the current implementation.
|
|
306
|
+
* @throws {TypeError} When the file path is not a non-empty string.
|
|
307
|
+
*/
|
|
308
|
+
async bytes(filePath) {
|
|
309
|
+
assertValidFileOrDirPath(filePath);
|
|
310
|
+
return this.#callImplMethod("bytes", filePath);
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Writes the given data to the given file. Creates any necessary directories along the way.
|
|
314
|
+
* If the data is a string, UTF-8 encoding is used.
|
|
315
|
+
* @param {string|URL} filePath The file to write.
|
|
316
|
+
* @param {string|ArrayBuffer|ArrayBufferView} contents The data to write.
|
|
317
|
+
* @returns {Promise<void>} A promise that resolves when the file is written.
|
|
318
|
+
* @throws {NoSuchMethodError} When the method does not exist on the current implementation.
|
|
319
|
+
* @throws {TypeError} When the file path is not a non-empty string.
|
|
320
|
+
*/
|
|
321
|
+
async write(filePath, contents) {
|
|
322
|
+
assertValidFileOrDirPath(filePath);
|
|
323
|
+
assertValidFileContents(contents);
|
|
324
|
+
this.#log("write", filePath, contents);
|
|
325
|
+
let value = toUint8Array(contents);
|
|
326
|
+
return this.#callImplMethodWithoutLog("write", filePath, value);
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Appends the given data to the given file. Creates any necessary directories along the way.
|
|
330
|
+
* If the data is a string, UTF-8 encoding is used.
|
|
331
|
+
* @param {string|URL} filePath The file to append to.
|
|
332
|
+
* @param {string|ArrayBuffer|ArrayBufferView} contents The data to append.
|
|
333
|
+
* @returns {Promise<void>} A promise that resolves when the file is appended to.
|
|
334
|
+
* @throws {NoSuchMethodError} When the method does not exist on the current implementation.
|
|
335
|
+
* @throws {TypeError} When the file path is not a non-empty string.
|
|
336
|
+
* @throws {TypeError} When the file contents are not a string or ArrayBuffer.
|
|
337
|
+
* @throws {Error} When the file cannot be appended to.
|
|
338
|
+
*/
|
|
339
|
+
async append(filePath, contents) {
|
|
340
|
+
assertValidFileOrDirPath(filePath);
|
|
341
|
+
assertValidFileContents(contents);
|
|
342
|
+
this.#log("append", filePath, contents);
|
|
343
|
+
let value = toUint8Array(contents);
|
|
344
|
+
return this.#callImplMethodWithoutLog("append", filePath, value);
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Determines if the given file exists.
|
|
348
|
+
* @param {string|URL} filePath The file to check.
|
|
349
|
+
* @returns {Promise<boolean>} True if the file exists.
|
|
350
|
+
* @throws {NoSuchMethodError} When the method does not exist on the current implementation.
|
|
351
|
+
* @throws {TypeError} When the file path is not a non-empty string.
|
|
352
|
+
*/
|
|
353
|
+
async isFile(filePath) {
|
|
354
|
+
assertValidFileOrDirPath(filePath);
|
|
355
|
+
return this.#callImplMethod("isFile", filePath);
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Determines if the given directory exists.
|
|
359
|
+
* @param {string|URL} dirPath The directory to check.
|
|
360
|
+
* @returns {Promise<boolean>} True if the directory exists.
|
|
361
|
+
* @throws {NoSuchMethodError} When the method does not exist on the current implementation.
|
|
362
|
+
* @throws {TypeError} When the directory path is not a non-empty string.
|
|
363
|
+
*/
|
|
364
|
+
async isDirectory(dirPath) {
|
|
365
|
+
assertValidFileOrDirPath(dirPath);
|
|
366
|
+
return this.#callImplMethod("isDirectory", dirPath);
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Creates the given directory.
|
|
370
|
+
* @param {string|URL} dirPath The directory to create.
|
|
371
|
+
* @returns {Promise<void>} A promise that resolves when the directory is created.
|
|
372
|
+
* @throws {NoSuchMethodError} When the method does not exist on the current implementation.
|
|
373
|
+
* @throws {TypeError} When the directory path is not a non-empty string.
|
|
374
|
+
*/
|
|
375
|
+
async createDirectory(dirPath) {
|
|
376
|
+
assertValidFileOrDirPath(dirPath);
|
|
377
|
+
return this.#callImplMethod("createDirectory", dirPath);
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Deletes the given file or empty directory.
|
|
381
|
+
* @param {string|URL} filePath The file to delete.
|
|
382
|
+
* @returns {Promise<boolean>} A promise that resolves when the file or
|
|
383
|
+
* directory is deleted, true if the file or directory is deleted, false
|
|
384
|
+
* if the file or directory does not exist.
|
|
385
|
+
* @throws {NoSuchMethodError} When the method does not exist on the current implementation.
|
|
386
|
+
* @throws {TypeError} When the file path is not a non-empty string.
|
|
387
|
+
*/
|
|
388
|
+
async delete(filePath) {
|
|
389
|
+
assertValidFileOrDirPath(filePath);
|
|
390
|
+
return this.#callImplMethod("delete", filePath);
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Deletes the given file or directory recursively.
|
|
394
|
+
* @param {string|URL} dirPath The directory to delete.
|
|
395
|
+
* @returns {Promise<boolean>} A promise that resolves when the file or
|
|
396
|
+
* directory is deleted, true if the file or directory is deleted, false
|
|
397
|
+
* if the file or directory does not exist.
|
|
398
|
+
* @throws {NoSuchMethodError} When the method does not exist on the current implementation.
|
|
399
|
+
* @throws {TypeError} When the directory path is not a non-empty string.
|
|
400
|
+
*/
|
|
401
|
+
async deleteAll(dirPath) {
|
|
402
|
+
assertValidFileOrDirPath(dirPath);
|
|
403
|
+
return this.#callImplMethod("deleteAll", dirPath);
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Returns a list of directory entries for the given path.
|
|
407
|
+
* @param {string|URL} dirPath The path to the directory to read.
|
|
408
|
+
* @returns {AsyncIterable<HfsDirectoryEntry>} A promise that resolves with the
|
|
409
|
+
* directory entries.
|
|
410
|
+
* @throws {TypeError} If the directory path is not a string or URL.
|
|
411
|
+
* @throws {Error} If the directory cannot be read.
|
|
412
|
+
*/
|
|
413
|
+
async *list(dirPath) {
|
|
414
|
+
assertValidFileOrDirPath(dirPath);
|
|
415
|
+
yield* await this.#callImplMethod("list", dirPath);
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Walks a directory using a depth-first traversal and returns the entries
|
|
419
|
+
* from the traversal.
|
|
420
|
+
* @param {string|URL} dirPath The path to the directory to walk.
|
|
421
|
+
* @param {Object} [options] The options for the walk.
|
|
422
|
+
* @param {(entry:HfsWalkEntry) => Promise<boolean>|boolean} [options.directoryFilter] A filter function to determine
|
|
423
|
+
* if a directory's entries should be included in the walk.
|
|
424
|
+
* @param {(entry:HfsWalkEntry) => Promise<boolean>|boolean} [options.entryFilter] A filter function to determine if
|
|
425
|
+
* an entry should be included in the walk.
|
|
426
|
+
* @returns {AsyncIterable<HfsWalkEntry>} A promise that resolves with the
|
|
427
|
+
* directory entries.
|
|
428
|
+
* @throws {TypeError} If the directory path is not a string or URL.
|
|
429
|
+
* @throws {Error} If the directory cannot be read.
|
|
430
|
+
*/
|
|
431
|
+
async *walk(dirPath, { directoryFilter = () => true, entryFilter = () => true } = {}) {
|
|
432
|
+
assertValidFileOrDirPath(dirPath);
|
|
433
|
+
this.#log("walk", dirPath, { directoryFilter, entryFilter });
|
|
434
|
+
const walk = async function* (dirPath2, { directoryFilter: directoryFilter2, entryFilter: entryFilter2, parentPath = "", depth = 1 }) {
|
|
435
|
+
let dirEntries;
|
|
436
|
+
try {
|
|
437
|
+
dirEntries = await this.#callImplMethodWithoutLog(
|
|
438
|
+
"list",
|
|
439
|
+
dirPath2
|
|
440
|
+
);
|
|
441
|
+
} catch (error) {
|
|
442
|
+
if (error.code === "ENOENT") {
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
throw error;
|
|
446
|
+
}
|
|
447
|
+
for await (const listEntry of dirEntries) {
|
|
448
|
+
const walkEntry = {
|
|
449
|
+
path: listEntry.name,
|
|
450
|
+
depth,
|
|
451
|
+
...listEntry
|
|
452
|
+
};
|
|
453
|
+
if (parentPath) {
|
|
454
|
+
walkEntry.path = `${parentPath}/${walkEntry.path}`;
|
|
455
|
+
}
|
|
456
|
+
let shouldEmitEntry = entryFilter2(walkEntry);
|
|
457
|
+
if (shouldEmitEntry.then) {
|
|
458
|
+
shouldEmitEntry = await shouldEmitEntry;
|
|
459
|
+
}
|
|
460
|
+
if (shouldEmitEntry) {
|
|
461
|
+
yield walkEntry;
|
|
462
|
+
}
|
|
463
|
+
if (listEntry.isDirectory) {
|
|
464
|
+
let shouldWalkDirectory = directoryFilter2(walkEntry);
|
|
465
|
+
if (shouldWalkDirectory.then) {
|
|
466
|
+
shouldWalkDirectory = await shouldWalkDirectory;
|
|
467
|
+
}
|
|
468
|
+
if (!shouldWalkDirectory) {
|
|
469
|
+
continue;
|
|
470
|
+
}
|
|
471
|
+
const directoryPath = dirPath2 instanceof URL ? new URL(
|
|
472
|
+
listEntry.name,
|
|
473
|
+
dirPath2.href.endsWith("/") ? dirPath2.href : `${dirPath2.href}/`
|
|
474
|
+
) : `${dirPath2.endsWith("/") ? dirPath2 : `${dirPath2}/`}${listEntry.name}`;
|
|
475
|
+
yield* walk(directoryPath, {
|
|
476
|
+
directoryFilter: directoryFilter2,
|
|
477
|
+
entryFilter: entryFilter2,
|
|
478
|
+
parentPath: walkEntry.path,
|
|
479
|
+
depth: depth + 1
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}.bind(this);
|
|
484
|
+
yield* walk(dirPath, { directoryFilter, entryFilter });
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Returns the size of the given file.
|
|
488
|
+
* @param {string|URL} filePath The path to the file to read.
|
|
489
|
+
* @returns {Promise<number>} A promise that resolves with the size of the file.
|
|
490
|
+
* @throws {TypeError} If the file path is not a string or URL.
|
|
491
|
+
* @throws {Error} If the file cannot be read.
|
|
492
|
+
*/
|
|
493
|
+
async size(filePath) {
|
|
494
|
+
assertValidFileOrDirPath(filePath);
|
|
495
|
+
return this.#callImplMethod("size", filePath);
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Returns the last modified timestamp of the given file or directory.
|
|
499
|
+
* @param {string|URL} fileOrDirPath The path to the file or directory.
|
|
500
|
+
* @returns {Promise<Date|undefined>} A promise that resolves with the last modified date
|
|
501
|
+
* or undefined if the file or directory does not exist.
|
|
502
|
+
* @throws {TypeError} If the path is not a string or URL.
|
|
503
|
+
*/
|
|
504
|
+
async lastModified(fileOrDirPath) {
|
|
505
|
+
assertValidFileOrDirPath(fileOrDirPath);
|
|
506
|
+
return this.#callImplMethod("lastModified", fileOrDirPath);
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Copys a file from one location to another.
|
|
510
|
+
* @param {string|URL} source The path to the file to copy.
|
|
511
|
+
* @param {string|URL} destination The path to the new file.
|
|
512
|
+
* @returns {Promise<void>} A promise that resolves when the file is copied.
|
|
513
|
+
* @throws {TypeError} If the file path is not a string or URL.
|
|
514
|
+
* @throws {Error} If the file cannot be copied.
|
|
515
|
+
*/
|
|
516
|
+
async copy(source, destination) {
|
|
517
|
+
assertValidFileOrDirPath(source);
|
|
518
|
+
assertValidFileOrDirPath(destination);
|
|
519
|
+
return this.#callImplMethod("copy", source, destination);
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* Copies a file or directory from one location to another.
|
|
523
|
+
* @param {string|URL} source The path to the file or directory to copy.
|
|
524
|
+
* @param {string|URL} destination The path to copy the file or directory to.
|
|
525
|
+
* @returns {Promise<void>} A promise that resolves when the file or directory is
|
|
526
|
+
* copied.
|
|
527
|
+
* @throws {TypeError} If the directory path is not a string or URL.
|
|
528
|
+
* @throws {Error} If the directory cannot be copied.
|
|
529
|
+
*/
|
|
530
|
+
async copyAll(source, destination) {
|
|
531
|
+
assertValidFileOrDirPath(source);
|
|
532
|
+
assertValidFileOrDirPath(destination);
|
|
533
|
+
return this.#callImplMethod("copyAll", source, destination);
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Moves a file from the source path to the destination path.
|
|
537
|
+
* @param {string|URL} source The location of the file to move.
|
|
538
|
+
* @param {string|URL} destination The destination of the file to move.
|
|
539
|
+
* @returns {Promise<void>} A promise that resolves when the move is complete.
|
|
540
|
+
* @throws {TypeError} If the file or directory paths are not strings.
|
|
541
|
+
* @throws {Error} If the file or directory cannot be moved.
|
|
542
|
+
*/
|
|
543
|
+
async move(source, destination) {
|
|
544
|
+
assertValidFileOrDirPath(source);
|
|
545
|
+
assertValidFileOrDirPath(destination);
|
|
546
|
+
return this.#callImplMethod("move", source, destination);
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* Moves a file or directory from one location to another.
|
|
550
|
+
* @param {string|URL} source The path to the file or directory to move.
|
|
551
|
+
* @param {string|URL} destination The path to move the file or directory to.
|
|
552
|
+
* @returns {Promise<void>} A promise that resolves when the file or directory is
|
|
553
|
+
* moved.
|
|
554
|
+
* @throws {TypeError} If the source is not a string or URL.
|
|
555
|
+
* @throws {TypeError} If the destination is not a string or URL.
|
|
556
|
+
* @throws {Error} If the file or directory cannot be moved.
|
|
557
|
+
*/
|
|
558
|
+
async moveAll(source, destination) {
|
|
559
|
+
assertValidFileOrDirPath(source);
|
|
560
|
+
assertValidFileOrDirPath(destination);
|
|
561
|
+
return this.#callImplMethod("moveAll", source, destination);
|
|
562
|
+
}
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
});
|
|
566
|
+
|
|
567
|
+
// ../../node_modules/.pnpm/@humanfs+core@0.19.1/node_modules/@humanfs/core/src/path.js
|
|
568
|
+
var init_path = __esm({
|
|
569
|
+
"../../node_modules/.pnpm/@humanfs+core@0.19.1/node_modules/@humanfs/core/src/path.js"() {
|
|
570
|
+
"use strict";
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
// ../../node_modules/.pnpm/@humanfs+core@0.19.1/node_modules/@humanfs/core/src/errors.js
|
|
575
|
+
var init_errors = __esm({
|
|
576
|
+
"../../node_modules/.pnpm/@humanfs+core@0.19.1/node_modules/@humanfs/core/src/errors.js"() {
|
|
577
|
+
"use strict";
|
|
578
|
+
}
|
|
579
|
+
});
|
|
580
|
+
|
|
581
|
+
// ../../node_modules/.pnpm/@humanfs+core@0.19.1/node_modules/@humanfs/core/src/index.js
|
|
582
|
+
var init_src = __esm({
|
|
583
|
+
"../../node_modules/.pnpm/@humanfs+core@0.19.1/node_modules/@humanfs/core/src/index.js"() {
|
|
584
|
+
"use strict";
|
|
585
|
+
init_hfs();
|
|
586
|
+
init_path();
|
|
587
|
+
init_errors();
|
|
588
|
+
}
|
|
589
|
+
});
|
|
590
|
+
|
|
591
|
+
// ../../node_modules/.pnpm/@humanwhocodes+retry@0.3.1/node_modules/@humanwhocodes/retry/dist/retrier.js
|
|
592
|
+
function isTimeToRetry(task, maxDelay) {
|
|
593
|
+
const timeSinceLastAttempt = Date.now() - task.lastAttempt;
|
|
594
|
+
const timeSinceStart = Math.max(task.lastAttempt - task.timestamp, 1);
|
|
595
|
+
const desiredDelay = Math.min(timeSinceStart * 1.2, maxDelay);
|
|
596
|
+
return timeSinceLastAttempt >= desiredDelay;
|
|
597
|
+
}
|
|
598
|
+
function isTimeToBail(task, timeout) {
|
|
599
|
+
return task.age > timeout;
|
|
600
|
+
}
|
|
601
|
+
var MAX_TASK_TIMEOUT, MAX_TASK_DELAY, RetryTask, Retrier;
|
|
602
|
+
var init_retrier = __esm({
|
|
603
|
+
"../../node_modules/.pnpm/@humanwhocodes+retry@0.3.1/node_modules/@humanwhocodes/retry/dist/retrier.js"() {
|
|
604
|
+
"use strict";
|
|
605
|
+
MAX_TASK_TIMEOUT = 6e4;
|
|
606
|
+
MAX_TASK_DELAY = 100;
|
|
607
|
+
RetryTask = class {
|
|
608
|
+
/**
|
|
609
|
+
* The unique ID for the task.
|
|
610
|
+
* @type {string}
|
|
611
|
+
*/
|
|
612
|
+
id = Math.random().toString(36).slice(2);
|
|
613
|
+
/**
|
|
614
|
+
* The function to call.
|
|
615
|
+
* @type {Function}
|
|
616
|
+
*/
|
|
617
|
+
fn;
|
|
618
|
+
/**
|
|
619
|
+
* The error that was thrown.
|
|
620
|
+
* @type {Error}
|
|
621
|
+
*/
|
|
622
|
+
error;
|
|
623
|
+
/**
|
|
624
|
+
* The timestamp of the task.
|
|
625
|
+
* @type {number}
|
|
626
|
+
*/
|
|
627
|
+
timestamp = Date.now();
|
|
628
|
+
/**
|
|
629
|
+
* The timestamp of the last attempt.
|
|
630
|
+
* @type {number}
|
|
631
|
+
*/
|
|
632
|
+
lastAttempt = this.timestamp;
|
|
633
|
+
/**
|
|
634
|
+
* The resolve function for the promise.
|
|
635
|
+
* @type {Function}
|
|
636
|
+
*/
|
|
637
|
+
resolve;
|
|
638
|
+
/**
|
|
639
|
+
* The reject function for the promise.
|
|
640
|
+
* @type {Function}
|
|
641
|
+
*/
|
|
642
|
+
reject;
|
|
643
|
+
/**
|
|
644
|
+
* The AbortSignal to monitor for cancellation.
|
|
645
|
+
* @type {AbortSignal|undefined}
|
|
646
|
+
*/
|
|
647
|
+
signal;
|
|
648
|
+
/**
|
|
649
|
+
* Creates a new instance.
|
|
650
|
+
* @param {Function} fn The function to call.
|
|
651
|
+
* @param {Error} error The error that was thrown.
|
|
652
|
+
* @param {Function} resolve The resolve function for the promise.
|
|
653
|
+
* @param {Function} reject The reject function for the promise.
|
|
654
|
+
* @param {AbortSignal|undefined} signal The AbortSignal to monitor for cancellation.
|
|
655
|
+
*/
|
|
656
|
+
constructor(fn, error, resolve, reject, signal) {
|
|
657
|
+
this.fn = fn;
|
|
658
|
+
this.error = error;
|
|
659
|
+
this.timestamp = Date.now();
|
|
660
|
+
this.lastAttempt = Date.now();
|
|
661
|
+
this.resolve = resolve;
|
|
662
|
+
this.reject = reject;
|
|
663
|
+
this.signal = signal;
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* Gets the age of the task.
|
|
667
|
+
* @returns {number} The age of the task in milliseconds.
|
|
668
|
+
* @readonly
|
|
669
|
+
*/
|
|
670
|
+
get age() {
|
|
671
|
+
return Date.now() - this.timestamp;
|
|
672
|
+
}
|
|
673
|
+
};
|
|
674
|
+
Retrier = class {
|
|
675
|
+
/**
|
|
676
|
+
* Represents the queue for processing tasks.
|
|
677
|
+
* @type {Array<RetryTask>}
|
|
678
|
+
*/
|
|
679
|
+
#queue = [];
|
|
680
|
+
/**
|
|
681
|
+
* The timeout for the queue.
|
|
682
|
+
* @type {number}
|
|
683
|
+
*/
|
|
684
|
+
#timeout;
|
|
685
|
+
/**
|
|
686
|
+
* The maximum delay for the queue.
|
|
687
|
+
* @type {number}
|
|
688
|
+
*/
|
|
689
|
+
#maxDelay;
|
|
690
|
+
/**
|
|
691
|
+
* The setTimeout() timer ID.
|
|
692
|
+
* @type {NodeJS.Timeout|undefined}
|
|
693
|
+
*/
|
|
694
|
+
#timerId;
|
|
695
|
+
/**
|
|
696
|
+
* The function to call.
|
|
697
|
+
* @type {Function}
|
|
698
|
+
*/
|
|
699
|
+
#check;
|
|
700
|
+
/**
|
|
701
|
+
* Creates a new instance.
|
|
702
|
+
* @param {Function} check The function to call.
|
|
703
|
+
* @param {object} [options] The options for the instance.
|
|
704
|
+
* @param {number} [options.timeout] The timeout for the queue.
|
|
705
|
+
* @param {number} [options.maxDelay] The maximum delay for the queue.
|
|
706
|
+
*/
|
|
707
|
+
constructor(check, { timeout = MAX_TASK_TIMEOUT, maxDelay = MAX_TASK_DELAY } = {}) {
|
|
708
|
+
if (typeof check !== "function") {
|
|
709
|
+
throw new Error("Missing function to check errors");
|
|
710
|
+
}
|
|
711
|
+
this.#check = check;
|
|
712
|
+
this.#timeout = timeout;
|
|
713
|
+
this.#maxDelay = maxDelay;
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* Adds a new retry job to the queue.
|
|
717
|
+
* @param {Function} fn The function to call.
|
|
718
|
+
* @param {object} [options] The options for the job.
|
|
719
|
+
* @param {AbortSignal} [options.signal] The AbortSignal to monitor for cancellation.
|
|
720
|
+
* @returns {Promise<any>} A promise that resolves when the queue is
|
|
721
|
+
* processed.
|
|
722
|
+
*/
|
|
723
|
+
retry(fn, { signal } = {}) {
|
|
724
|
+
signal?.throwIfAborted();
|
|
725
|
+
let result;
|
|
726
|
+
try {
|
|
727
|
+
result = fn();
|
|
728
|
+
} catch (error) {
|
|
729
|
+
return Promise.reject(new Error(`Synchronous error: ${error.message}`, { cause: error }));
|
|
730
|
+
}
|
|
731
|
+
if (!result || typeof result.then !== "function") {
|
|
732
|
+
return Promise.reject(new Error("Result is not a promise."));
|
|
733
|
+
}
|
|
734
|
+
return Promise.resolve(result).catch((error) => {
|
|
735
|
+
if (!this.#check(error)) {
|
|
736
|
+
throw error;
|
|
737
|
+
}
|
|
738
|
+
return new Promise((resolve, reject) => {
|
|
739
|
+
this.#queue.push(new RetryTask(fn, error, resolve, reject, signal));
|
|
740
|
+
signal?.addEventListener("abort", () => {
|
|
741
|
+
reject(signal.reason);
|
|
742
|
+
});
|
|
743
|
+
this.#processQueue();
|
|
744
|
+
});
|
|
745
|
+
});
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* Processes the queue.
|
|
749
|
+
* @returns {void}
|
|
750
|
+
*/
|
|
751
|
+
#processQueue() {
|
|
752
|
+
clearTimeout(this.#timerId);
|
|
753
|
+
this.#timerId = void 0;
|
|
754
|
+
const task = this.#queue.shift();
|
|
755
|
+
if (!task) {
|
|
756
|
+
return;
|
|
757
|
+
}
|
|
758
|
+
const processAgain = () => {
|
|
759
|
+
this.#timerId = setTimeout(() => this.#processQueue(), 0);
|
|
760
|
+
};
|
|
761
|
+
if (isTimeToBail(task, this.#timeout)) {
|
|
762
|
+
task.reject(task.error);
|
|
763
|
+
processAgain();
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
if (!isTimeToRetry(task, this.#maxDelay)) {
|
|
767
|
+
this.#queue.push(task);
|
|
768
|
+
processAgain();
|
|
769
|
+
return;
|
|
770
|
+
}
|
|
771
|
+
task.lastAttempt = Date.now();
|
|
772
|
+
Promise.resolve(task.fn()).then((result) => task.resolve(result)).catch((error) => {
|
|
773
|
+
if (!this.#check(error)) {
|
|
774
|
+
task.reject(error);
|
|
775
|
+
return;
|
|
776
|
+
}
|
|
777
|
+
task.lastAttempt = Date.now();
|
|
778
|
+
this.#queue.push(task);
|
|
779
|
+
}).finally(() => this.#processQueue());
|
|
780
|
+
}
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
});
|
|
784
|
+
|
|
785
|
+
// ../../node_modules/.pnpm/@humanfs+node@0.16.6/node_modules/@humanfs/node/src/node-hfs.js
|
|
786
|
+
import path from "path";
|
|
787
|
+
import nativeFsp from "fs/promises";
|
|
788
|
+
import { fileURLToPath } from "url";
|
|
789
|
+
var RETRY_ERROR_CODES, NodeHfsDirectoryEntry, NodeHfsImpl, NodeHfs, hfs;
|
|
790
|
+
var init_node_hfs = __esm({
|
|
791
|
+
"../../node_modules/.pnpm/@humanfs+node@0.16.6/node_modules/@humanfs/node/src/node-hfs.js"() {
|
|
792
|
+
"use strict";
|
|
793
|
+
init_src();
|
|
794
|
+
init_retrier();
|
|
795
|
+
RETRY_ERROR_CODES = /* @__PURE__ */ new Set(["ENFILE", "EMFILE"]);
|
|
796
|
+
NodeHfsDirectoryEntry = class {
|
|
797
|
+
/**
|
|
798
|
+
* The name of the directory entry.
|
|
799
|
+
* @type {string}
|
|
800
|
+
*/
|
|
801
|
+
name;
|
|
802
|
+
/**
|
|
803
|
+
* True if the entry is a file.
|
|
804
|
+
* @type {boolean}
|
|
805
|
+
*/
|
|
806
|
+
isFile;
|
|
807
|
+
/**
|
|
808
|
+
* True if the entry is a directory.
|
|
809
|
+
* @type {boolean}
|
|
810
|
+
*/
|
|
811
|
+
isDirectory;
|
|
812
|
+
/**
|
|
813
|
+
* True if the entry is a symbolic link.
|
|
814
|
+
* @type {boolean}
|
|
815
|
+
*/
|
|
816
|
+
isSymlink;
|
|
817
|
+
/**
|
|
818
|
+
* Creates a new instance.
|
|
819
|
+
* @param {Dirent} dirent The directory entry to wrap.
|
|
820
|
+
*/
|
|
821
|
+
constructor(dirent) {
|
|
822
|
+
this.name = dirent.name;
|
|
823
|
+
this.isFile = dirent.isFile();
|
|
824
|
+
this.isDirectory = dirent.isDirectory();
|
|
825
|
+
this.isSymlink = dirent.isSymbolicLink();
|
|
826
|
+
}
|
|
827
|
+
};
|
|
828
|
+
NodeHfsImpl = class {
|
|
829
|
+
/**
|
|
830
|
+
* The file system module to use.
|
|
831
|
+
* @type {Fsp}
|
|
832
|
+
*/
|
|
833
|
+
#fsp;
|
|
834
|
+
/**
|
|
835
|
+
* The retryer object used for retrying operations.
|
|
836
|
+
* @type {Retrier}
|
|
837
|
+
*/
|
|
838
|
+
#retrier;
|
|
839
|
+
/**
|
|
840
|
+
* Creates a new instance.
|
|
841
|
+
* @param {object} [options] The options for the instance.
|
|
842
|
+
* @param {Fsp} [options.fsp] The file system module to use.
|
|
843
|
+
*/
|
|
844
|
+
constructor({ fsp = nativeFsp } = {}) {
|
|
845
|
+
this.#fsp = fsp;
|
|
846
|
+
this.#retrier = new Retrier((error) => RETRY_ERROR_CODES.has(error.code));
|
|
847
|
+
}
|
|
848
|
+
/**
|
|
849
|
+
* Reads a file and returns the contents as an Uint8Array.
|
|
850
|
+
* @param {string|URL} filePath The path to the file to read.
|
|
851
|
+
* @returns {Promise<Uint8Array|undefined>} A promise that resolves with the contents
|
|
852
|
+
* of the file or undefined if the file doesn't exist.
|
|
853
|
+
* @throws {Error} If the file cannot be read.
|
|
854
|
+
* @throws {TypeError} If the file path is not a string.
|
|
855
|
+
*/
|
|
856
|
+
bytes(filePath) {
|
|
857
|
+
return this.#retrier.retry(() => this.#fsp.readFile(filePath)).then((buffer) => new Uint8Array(buffer.buffer)).catch((error) => {
|
|
858
|
+
if (error.code === "ENOENT") {
|
|
859
|
+
return void 0;
|
|
860
|
+
}
|
|
861
|
+
throw error;
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
/**
|
|
865
|
+
* Writes a value to a file. If the value is a string, UTF-8 encoding is used.
|
|
866
|
+
* @param {string|URL} filePath The path to the file to write.
|
|
867
|
+
* @param {Uint8Array} contents The contents to write to the
|
|
868
|
+
* file.
|
|
869
|
+
* @returns {Promise<void>} A promise that resolves when the file is
|
|
870
|
+
* written.
|
|
871
|
+
* @throws {TypeError} If the file path is not a string.
|
|
872
|
+
* @throws {Error} If the file cannot be written.
|
|
873
|
+
*/
|
|
874
|
+
async write(filePath, contents) {
|
|
875
|
+
const value = Buffer.from(contents);
|
|
876
|
+
return this.#retrier.retry(() => this.#fsp.writeFile(filePath, value)).catch((error) => {
|
|
877
|
+
if (error.code === "ENOENT") {
|
|
878
|
+
const dirPath = path.dirname(
|
|
879
|
+
filePath instanceof URL ? fileURLToPath(filePath) : filePath
|
|
880
|
+
);
|
|
881
|
+
return this.#fsp.mkdir(dirPath, { recursive: true }).then(() => this.#fsp.writeFile(filePath, value));
|
|
882
|
+
}
|
|
883
|
+
throw error;
|
|
884
|
+
});
|
|
885
|
+
}
|
|
886
|
+
/**
|
|
887
|
+
* Appends a value to a file. If the value is a string, UTF-8 encoding is used.
|
|
888
|
+
* @param {string|URL} filePath The path to the file to append to.
|
|
889
|
+
* @param {Uint8Array} contents The contents to append to the
|
|
890
|
+
* file.
|
|
891
|
+
* @returns {Promise<void>} A promise that resolves when the file is
|
|
892
|
+
* written.
|
|
893
|
+
* @throws {TypeError} If the file path is not a string.
|
|
894
|
+
* @throws {Error} If the file cannot be appended to.
|
|
895
|
+
*/
|
|
896
|
+
async append(filePath, contents) {
|
|
897
|
+
const value = Buffer.from(contents);
|
|
898
|
+
return this.#retrier.retry(() => this.#fsp.appendFile(filePath, value)).catch((error) => {
|
|
899
|
+
if (error.code === "ENOENT") {
|
|
900
|
+
const dirPath = path.dirname(
|
|
901
|
+
filePath instanceof URL ? fileURLToPath(filePath) : filePath
|
|
902
|
+
);
|
|
903
|
+
return this.#fsp.mkdir(dirPath, { recursive: true }).then(() => this.#fsp.appendFile(filePath, value));
|
|
904
|
+
}
|
|
905
|
+
throw error;
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
/**
|
|
909
|
+
* Checks if a file exists.
|
|
910
|
+
* @param {string|URL} filePath The path to the file to check.
|
|
911
|
+
* @returns {Promise<boolean>} A promise that resolves with true if the
|
|
912
|
+
* file exists or false if it does not.
|
|
913
|
+
* @throws {Error} If the operation fails with a code other than ENOENT.
|
|
914
|
+
*/
|
|
915
|
+
isFile(filePath) {
|
|
916
|
+
return this.#fsp.stat(filePath).then((stat) => stat.isFile()).catch((error) => {
|
|
917
|
+
if (error.code === "ENOENT") {
|
|
918
|
+
return false;
|
|
919
|
+
}
|
|
920
|
+
throw error;
|
|
921
|
+
});
|
|
922
|
+
}
|
|
923
|
+
/**
|
|
924
|
+
* Checks if a directory exists.
|
|
925
|
+
* @param {string|URL} dirPath The path to the directory to check.
|
|
926
|
+
* @returns {Promise<boolean>} A promise that resolves with true if the
|
|
927
|
+
* directory exists or false if it does not.
|
|
928
|
+
* @throws {Error} If the operation fails with a code other than ENOENT.
|
|
929
|
+
*/
|
|
930
|
+
isDirectory(dirPath) {
|
|
931
|
+
return this.#fsp.stat(dirPath).then((stat) => stat.isDirectory()).catch((error) => {
|
|
932
|
+
if (error.code === "ENOENT") {
|
|
933
|
+
return false;
|
|
934
|
+
}
|
|
935
|
+
throw error;
|
|
936
|
+
});
|
|
937
|
+
}
|
|
938
|
+
/**
|
|
939
|
+
* Creates a directory recursively.
|
|
940
|
+
* @param {string|URL} dirPath The path to the directory to create.
|
|
941
|
+
* @returns {Promise<void>} A promise that resolves when the directory is
|
|
942
|
+
* created.
|
|
943
|
+
*/
|
|
944
|
+
async createDirectory(dirPath) {
|
|
945
|
+
await this.#fsp.mkdir(dirPath, { recursive: true });
|
|
946
|
+
}
|
|
947
|
+
/**
|
|
948
|
+
* Deletes a file or empty directory.
|
|
949
|
+
* @param {string|URL} fileOrDirPath The path to the file or directory to
|
|
950
|
+
* delete.
|
|
951
|
+
* @returns {Promise<boolean>} A promise that resolves when the file or
|
|
952
|
+
* directory is deleted, true if the file or directory is deleted, false
|
|
953
|
+
* if the file or directory does not exist.
|
|
954
|
+
* @throws {TypeError} If the file or directory path is not a string.
|
|
955
|
+
* @throws {Error} If the file or directory cannot be deleted.
|
|
956
|
+
*/
|
|
957
|
+
delete(fileOrDirPath) {
|
|
958
|
+
return this.#fsp.rm(fileOrDirPath).then(() => true).catch((error) => {
|
|
959
|
+
if (error.code === "ERR_FS_EISDIR") {
|
|
960
|
+
return this.#fsp.rmdir(fileOrDirPath).then(() => true);
|
|
961
|
+
}
|
|
962
|
+
if (error.code === "ENOENT") {
|
|
963
|
+
return false;
|
|
964
|
+
}
|
|
965
|
+
throw error;
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
/**
|
|
969
|
+
* Deletes a file or directory recursively.
|
|
970
|
+
* @param {string|URL} fileOrDirPath The path to the file or directory to
|
|
971
|
+
* delete.
|
|
972
|
+
* @returns {Promise<boolean>} A promise that resolves when the file or
|
|
973
|
+
* directory is deleted, true if the file or directory is deleted, false
|
|
974
|
+
* if the file or directory does not exist.
|
|
975
|
+
* @throws {TypeError} If the file or directory path is not a string.
|
|
976
|
+
* @throws {Error} If the file or directory cannot be deleted.
|
|
977
|
+
*/
|
|
978
|
+
deleteAll(fileOrDirPath) {
|
|
979
|
+
return this.#fsp.rm(fileOrDirPath, { recursive: true }).then(() => true).catch((error) => {
|
|
980
|
+
if (error.code === "ENOENT") {
|
|
981
|
+
return false;
|
|
982
|
+
}
|
|
983
|
+
throw error;
|
|
984
|
+
});
|
|
985
|
+
}
|
|
986
|
+
/**
|
|
987
|
+
* Returns a list of directory entries for the given path.
|
|
988
|
+
* @param {string|URL} dirPath The path to the directory to read.
|
|
989
|
+
* @returns {AsyncIterable<HfsDirectoryEntry>} A promise that resolves with the
|
|
990
|
+
* directory entries.
|
|
991
|
+
* @throws {TypeError} If the directory path is not a string.
|
|
992
|
+
* @throws {Error} If the directory cannot be read.
|
|
993
|
+
*/
|
|
994
|
+
async *list(dirPath) {
|
|
995
|
+
const entries = await this.#fsp.readdir(dirPath, {
|
|
996
|
+
withFileTypes: true
|
|
997
|
+
});
|
|
998
|
+
for (const entry of entries) {
|
|
999
|
+
yield new NodeHfsDirectoryEntry(entry);
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
/**
|
|
1003
|
+
* Returns the size of a file. This method handles ENOENT errors
|
|
1004
|
+
* and returns undefined in that case.
|
|
1005
|
+
* @param {string|URL} filePath The path to the file to read.
|
|
1006
|
+
* @returns {Promise<number|undefined>} A promise that resolves with the size of the
|
|
1007
|
+
* file in bytes or undefined if the file doesn't exist.
|
|
1008
|
+
*/
|
|
1009
|
+
size(filePath) {
|
|
1010
|
+
return this.#fsp.stat(filePath).then((stat) => stat.size).catch((error) => {
|
|
1011
|
+
if (error.code === "ENOENT") {
|
|
1012
|
+
return void 0;
|
|
1013
|
+
}
|
|
1014
|
+
throw error;
|
|
1015
|
+
});
|
|
1016
|
+
}
|
|
1017
|
+
/**
|
|
1018
|
+
* Returns the last modified date of a file or directory. This method handles ENOENT errors
|
|
1019
|
+
* and returns undefined in that case.
|
|
1020
|
+
* @param {string|URL} fileOrDirPath The path to the file to read.
|
|
1021
|
+
* @returns {Promise<Date|undefined>} A promise that resolves with the last modified
|
|
1022
|
+
* date of the file or directory, or undefined if the file doesn't exist.
|
|
1023
|
+
*/
|
|
1024
|
+
lastModified(fileOrDirPath) {
|
|
1025
|
+
return this.#fsp.stat(fileOrDirPath).then((stat) => stat.mtime).catch((error) => {
|
|
1026
|
+
if (error.code === "ENOENT") {
|
|
1027
|
+
return void 0;
|
|
1028
|
+
}
|
|
1029
|
+
throw error;
|
|
1030
|
+
});
|
|
1031
|
+
}
|
|
1032
|
+
/**
|
|
1033
|
+
* Copies a file from one location to another.
|
|
1034
|
+
* @param {string|URL} source The path to the file to copy.
|
|
1035
|
+
* @param {string|URL} destination The path to copy the file to.
|
|
1036
|
+
* @returns {Promise<void>} A promise that resolves when the file is copied.
|
|
1037
|
+
* @throws {Error} If the source file does not exist.
|
|
1038
|
+
* @throws {Error} If the source file is a directory.
|
|
1039
|
+
* @throws {Error} If the destination file is a directory.
|
|
1040
|
+
*/
|
|
1041
|
+
copy(source, destination) {
|
|
1042
|
+
return this.#fsp.copyFile(source, destination);
|
|
1043
|
+
}
|
|
1044
|
+
/**
|
|
1045
|
+
* Copies a file or directory from one location to another.
|
|
1046
|
+
* @param {string|URL} source The path to the file or directory to copy.
|
|
1047
|
+
* @param {string|URL} destination The path to copy the file or directory to.
|
|
1048
|
+
* @returns {Promise<void>} A promise that resolves when the file or directory is
|
|
1049
|
+
* copied.
|
|
1050
|
+
* @throws {Error} If the source file or directory does not exist.
|
|
1051
|
+
* @throws {Error} If the destination file or directory is a directory.
|
|
1052
|
+
*/
|
|
1053
|
+
async copyAll(source, destination) {
|
|
1054
|
+
if (await this.isFile(source)) {
|
|
1055
|
+
return this.copy(source, destination);
|
|
1056
|
+
}
|
|
1057
|
+
const sourceStr = source instanceof URL ? fileURLToPath(source) : source;
|
|
1058
|
+
const destinationStr = destination instanceof URL ? fileURLToPath(destination) : destination;
|
|
1059
|
+
await this.createDirectory(destination);
|
|
1060
|
+
for await (const entry of this.list(source)) {
|
|
1061
|
+
const fromEntryPath = path.join(sourceStr, entry.name);
|
|
1062
|
+
const toEntryPath = path.join(destinationStr, entry.name);
|
|
1063
|
+
if (entry.isDirectory) {
|
|
1064
|
+
await this.copyAll(fromEntryPath, toEntryPath);
|
|
1065
|
+
} else {
|
|
1066
|
+
await this.copy(fromEntryPath, toEntryPath);
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
/**
|
|
1071
|
+
* Moves a file from the source path to the destination path.
|
|
1072
|
+
* @param {string|URL} source The location of the file to move.
|
|
1073
|
+
* @param {string|URL} destination The destination of the file to move.
|
|
1074
|
+
* @returns {Promise<void>} A promise that resolves when the move is complete.
|
|
1075
|
+
* @throws {TypeError} If the file paths are not strings.
|
|
1076
|
+
* @throws {Error} If the file cannot be moved.
|
|
1077
|
+
*/
|
|
1078
|
+
move(source, destination) {
|
|
1079
|
+
return this.#fsp.stat(source).then((stat) => {
|
|
1080
|
+
if (stat.isDirectory()) {
|
|
1081
|
+
throw new Error(
|
|
1082
|
+
`EISDIR: illegal operation on a directory, move '${source}' -> '${destination}'`
|
|
1083
|
+
);
|
|
1084
|
+
}
|
|
1085
|
+
return this.#fsp.rename(source, destination);
|
|
1086
|
+
});
|
|
1087
|
+
}
|
|
1088
|
+
/**
|
|
1089
|
+
* Moves a file or directory from the source path to the destination path.
|
|
1090
|
+
* @param {string|URL} source The location of the file or directory to move.
|
|
1091
|
+
* @param {string|URL} destination The destination of the file or directory to move.
|
|
1092
|
+
* @returns {Promise<void>} A promise that resolves when the move is complete.
|
|
1093
|
+
* @throws {TypeError} If the file paths are not strings.
|
|
1094
|
+
* @throws {Error} If the file or directory cannot be moved.
|
|
1095
|
+
*/
|
|
1096
|
+
async moveAll(source, destination) {
|
|
1097
|
+
return this.#fsp.rename(source, destination);
|
|
1098
|
+
}
|
|
1099
|
+
};
|
|
1100
|
+
NodeHfs = class extends Hfs {
|
|
1101
|
+
/**
|
|
1102
|
+
* Creates a new instance.
|
|
1103
|
+
* @param {object} [options] The options for the instance.
|
|
1104
|
+
* @param {Fsp} [options.fsp] The file system module to use.
|
|
1105
|
+
*/
|
|
1106
|
+
constructor({ fsp } = {}) {
|
|
1107
|
+
super({ impl: new NodeHfsImpl({ fsp }) });
|
|
1108
|
+
}
|
|
1109
|
+
};
|
|
1110
|
+
hfs = new NodeHfs();
|
|
1111
|
+
}
|
|
1112
|
+
});
|
|
1113
|
+
|
|
1114
|
+
// ../../node_modules/.pnpm/@humanfs+node@0.16.6/node_modules/@humanfs/node/src/index.js
|
|
1115
|
+
var init_src2 = __esm({
|
|
1116
|
+
"../../node_modules/.pnpm/@humanfs+node@0.16.6/node_modules/@humanfs/node/src/index.js"() {
|
|
1117
|
+
init_node_hfs();
|
|
1118
|
+
init_src();
|
|
1119
|
+
}
|
|
1120
|
+
});
|
|
1121
|
+
init_src2();
|
|
1122
|
+
export {
|
|
1123
|
+
Hfs,
|
|
1124
|
+
NodeHfs,
|
|
1125
|
+
NodeHfsImpl,
|
|
1126
|
+
hfs
|
|
1127
|
+
};
|