cspell-io 9.0.2 → 9.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.
Files changed (3) hide show
  1. package/dist/index.d.ts +440 -408
  2. package/dist/index.js +1316 -1290
  3. package/package.json +6 -6
package/dist/index.js CHANGED
@@ -1,1498 +1,1524 @@
1
- // src/async/asyncIterable.ts
1
+ import { isFileURL, isUrlLike, toFileURL, toURL, urlBasename, urlParent as urlDirname } from "@cspell/url";
2
+ import * as zlib from "node:zlib";
3
+ import { gunzipSync, gzip } from "node:zlib";
4
+ import { ServiceBus, createResponse, createResponseFail, isServiceResponseSuccess, requestFactory } from "@cspell/cspell-service-bus";
5
+ import * as fs from "node:fs";
6
+ import { promises, readFileSync, statSync } from "node:fs";
7
+ import { fileURLToPath } from "node:url";
8
+ import { promisify } from "node:util";
9
+ import * as Stream from "node:stream";
10
+ import assert from "node:assert";
11
+
12
+ //#region src/async/asyncIterable.ts
13
+ /**
14
+ * Reads an entire iterable and converts it into a promise.
15
+ * @param asyncIterable the async iterable to wait for.
16
+ */
2
17
  async function toArray(asyncIterable) {
3
- const data = [];
4
- for await (const item of asyncIterable) {
5
- data.push(item);
6
- }
7
- return data;
18
+ const data = [];
19
+ for await (const item of asyncIterable) data.push(item);
20
+ return data;
8
21
  }
9
22
 
10
- // src/node/file/url.ts
11
- import { basenameOfUrlPathname } from "@cspell/url";
12
- import {
13
- basenameOfUrlPathname as basenameOfUrlPathname2,
14
- isFileURL,
15
- isURL,
16
- isUrlLike,
17
- toFileURL,
18
- toURL,
19
- urlBasename,
20
- urlParent
21
- } from "@cspell/url";
22
-
23
- // src/common/CFileReference.ts
24
- var CFileReference = class _CFileReference {
25
- constructor(url, encoding, baseFilename, gz) {
26
- this.url = url;
27
- this.encoding = encoding;
28
- this.baseFilename = baseFilename;
29
- this.gz = gz ?? (baseFilename?.endsWith(".gz") || void 0) ?? (url.pathname.endsWith(".gz") || void 0);
30
- }
31
- /**
32
- * Use to ensure the nominal type separation between CFileReference and FileReference
33
- * See: https://github.com/microsoft/TypeScript/wiki/FAQ#when-and-why-are-classes-nominal
34
- */
35
- _;
36
- gz;
37
- static isCFileReference(obj) {
38
- return obj instanceof _CFileReference;
39
- }
40
- static from(fileReference, encoding, baseFilename, gz) {
41
- if (_CFileReference.isCFileReference(fileReference)) return fileReference;
42
- if (fileReference instanceof URL) return new _CFileReference(fileReference, encoding, baseFilename, gz);
43
- return new _CFileReference(
44
- fileReference.url,
45
- fileReference.encoding,
46
- fileReference.baseFilename,
47
- fileReference.gz
48
- );
49
- }
50
- toJson() {
51
- return {
52
- url: this.url.href,
53
- encoding: this.encoding,
54
- baseFilename: this.baseFilename,
55
- gz: this.gz
56
- };
57
- }
23
+ //#endregion
24
+ //#region src/common/CFileReference.ts
25
+ var CFileReference = class CFileReference {
26
+ /**
27
+ * Use to ensure the nominal type separation between CFileReference and FileReference
28
+ * See: https://github.com/microsoft/TypeScript/wiki/FAQ#when-and-why-are-classes-nominal
29
+ */
30
+ _;
31
+ gz;
32
+ constructor(url, encoding, baseFilename, gz) {
33
+ this.url = url;
34
+ this.encoding = encoding;
35
+ this.baseFilename = baseFilename;
36
+ this.gz = gz ?? (baseFilename?.endsWith(".gz") || void 0) ?? (url.pathname.endsWith(".gz") || void 0);
37
+ }
38
+ static isCFileReference(obj) {
39
+ return obj instanceof CFileReference;
40
+ }
41
+ static from(fileReference, encoding, baseFilename, gz) {
42
+ if (CFileReference.isCFileReference(fileReference)) return fileReference;
43
+ if (fileReference instanceof URL) return new CFileReference(fileReference, encoding, baseFilename, gz);
44
+ return new CFileReference(fileReference.url, fileReference.encoding, fileReference.baseFilename, fileReference.gz);
45
+ }
46
+ toJson() {
47
+ return {
48
+ url: this.url.href,
49
+ encoding: this.encoding,
50
+ baseFilename: this.baseFilename,
51
+ gz: this.gz
52
+ };
53
+ }
58
54
  };
55
+ /**
56
+ *
57
+ * @param file - a URL, file path, or FileReference
58
+ * @param encoding - optional encoding used to decode the file.
59
+ * @param baseFilename - optional base filename used with data URLs.
60
+ * @param gz - optional flag to indicate if the file is gzipped.
61
+ * @returns a FileReference
62
+ */
59
63
  function toFileReference(file, encoding, baseFilename, gz) {
60
- const fileReference = typeof file === "string" ? toFileURL(file) : file;
61
- if (fileReference instanceof URL) return new CFileReference(fileReference, encoding, baseFilename, gz);
62
- return CFileReference.from(fileReference);
64
+ const fileReference = typeof file === "string" ? toFileURL(file) : file;
65
+ if (fileReference instanceof URL) return new CFileReference(fileReference, encoding, baseFilename, gz);
66
+ return CFileReference.from(fileReference);
63
67
  }
64
68
  function isFileReference(ref) {
65
- return CFileReference.isCFileReference(ref) || !(ref instanceof URL) && typeof ref !== "string";
69
+ return CFileReference.isCFileReference(ref) || !(ref instanceof URL) && typeof ref !== "string";
66
70
  }
67
71
  function renameFileReference(ref, newUrl) {
68
- return new CFileReference(newUrl, ref.encoding, ref.baseFilename, ref.gz);
72
+ return new CFileReference(newUrl, ref.encoding, ref.baseFilename, ref.gz);
69
73
  }
70
74
  function toFileResourceRequest(file, encoding, signal) {
71
- const fileReference = typeof file === "string" ? toFileURL(file) : file;
72
- if (fileReference instanceof URL) return { url: fileReference, encoding, signal };
73
- return { url: fileReference.url, encoding: encoding ?? fileReference.encoding, signal };
75
+ const fileReference = typeof file === "string" ? toFileURL(file) : file;
76
+ if (fileReference instanceof URL) return {
77
+ url: fileReference,
78
+ encoding,
79
+ signal
80
+ };
81
+ return {
82
+ url: fileReference.url,
83
+ encoding: encoding ?? fileReference.encoding,
84
+ signal
85
+ };
74
86
  }
75
87
 
76
- // src/errors/errors.ts
88
+ //#endregion
89
+ //#region src/errors/errors.ts
77
90
  var ErrorNotImplemented = class extends Error {
78
- constructor(method, options) {
79
- super(`Method ${method} is not supported.`, options);
80
- this.method = method;
81
- }
91
+ constructor(method, options) {
92
+ super(`Method ${method} is not supported.`, options);
93
+ this.method = method;
94
+ }
82
95
  };
83
96
  var AssertionError = class extends Error {
84
- constructor(message, options) {
85
- super(message, options);
86
- this.message = message;
87
- }
97
+ constructor(message, options) {
98
+ super(message, options);
99
+ this.message = message;
100
+ }
88
101
  };
89
102
 
90
- // src/errors/assert.ts
91
- function assert(value, message) {
92
- if (!value) {
93
- throw new AssertionError(message ?? "Assertion failed");
94
- }
103
+ //#endregion
104
+ //#region src/errors/assert.ts
105
+ function assert$1(value, message) {
106
+ if (!value) throw new AssertionError(message ?? "Assertion failed");
95
107
  }
96
108
 
97
- // src/common/encode-decode.ts
98
- import { gunzipSync } from "zlib";
99
-
100
- // src/common/arrayBuffers.ts
109
+ //#endregion
110
+ //#region src/common/arrayBuffers.ts
111
+ /**
112
+ * Treat a ArrayBufferView as a Uint8Array.
113
+ * The Uint8Array will share the same underlying ArrayBuffer.
114
+ * @param data - source data
115
+ * @returns Uint8Array
116
+ */
101
117
  function asUint8Array(data) {
102
- return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
118
+ return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
103
119
  }
104
120
  function arrayBufferViewToBuffer(data) {
105
- if (data instanceof Buffer) {
106
- return data;
107
- }
108
- const buf = Buffer.from(data.buffer);
109
- if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {
110
- return buf;
111
- }
112
- return buf.subarray(data.byteOffset, data.byteOffset + data.byteLength);
113
- }
121
+ if (data instanceof Buffer) return data;
122
+ const buf = Buffer.from(data.buffer);
123
+ if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) return buf;
124
+ return buf.subarray(data.byteOffset, data.byteOffset + data.byteLength);
125
+ }
126
+ /**
127
+ * Copy the data buffer.
128
+ * @param data - source data
129
+ * @returns A copy of the data
130
+ */
114
131
  function copyArrayBufferView(data) {
115
- return new Uint8Array(data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength));
132
+ return new Uint8Array(data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength));
116
133
  }
134
+ /**
135
+ * Swap the bytes in a buffer.
136
+ * @param data - data to swap
137
+ * @returns data
138
+ */
117
139
  function swap16Poly(data) {
118
- const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
119
- for (let i = 0; i < view.byteLength; i += 2) {
120
- view.setUint16(i, view.getUint16(i, false), true);
121
- }
122
- return data;
123
- }
140
+ const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
141
+ for (let i = 0; i < view.byteLength; i += 2) view.setUint16(i, view.getUint16(i, false), true);
142
+ return data;
143
+ }
144
+ /**
145
+ * Swap the bytes in a buffer.
146
+ * @param data - data to swap
147
+ * @returns data
148
+ */
124
149
  function swap16(data) {
125
- if (typeof Buffer !== "undefined") {
126
- return arrayBufferViewToBuffer(data).swap16();
127
- }
128
- return swap16Poly(data);
150
+ if (typeof Buffer !== "undefined") return arrayBufferViewToBuffer(data).swap16();
151
+ return swap16Poly(data);
129
152
  }
130
153
  function swapBytes(data) {
131
- const buf = copyArrayBufferView(data);
132
- return swap16(buf);
154
+ const buf = copyArrayBufferView(data);
155
+ return swap16(buf);
133
156
  }
134
157
 
135
- // src/common/encode-decode.ts
136
- var BOM_BE = 65279;
137
- var BOM_LE = 65534;
138
- var decoderUTF8 = new TextDecoder("utf8");
139
- var decoderUTF16LE = new TextDecoder("utf-16le");
140
- var decoderUTF16BE = createTextDecoderUtf16BE();
141
- var encoderUTF8 = new TextEncoder();
158
+ //#endregion
159
+ //#region src/common/encode-decode.ts
160
+ const BOM_BE = 65279;
161
+ const BOM_LE = 65534;
162
+ const decoderUTF8 = new TextDecoder("utf8");
163
+ const decoderUTF16LE = new TextDecoder("utf-16le");
164
+ const decoderUTF16BE = createTextDecoderUtf16BE();
165
+ const encoderUTF8 = new TextEncoder();
142
166
  function decodeUtf16LE(data) {
143
- const buf = asUint8Array(data);
144
- const bom = buf[0] << 8 | buf[1];
145
- return decoderUTF16LE.decode(bom === BOM_LE ? buf.subarray(2) : buf);
167
+ const buf = asUint8Array(data);
168
+ const bom = buf[0] << 8 | buf[1];
169
+ return decoderUTF16LE.decode(bom === BOM_LE ? buf.subarray(2) : buf);
146
170
  }
147
171
  function decodeUtf16BE(data) {
148
- const buf = asUint8Array(data);
149
- const bom = buf[0] << 8 | buf[1];
150
- return decoderUTF16BE.decode(bom === BOM_BE ? buf.subarray(2) : buf);
172
+ const buf = asUint8Array(data);
173
+ const bom = buf[0] << 8 | buf[1];
174
+ return decoderUTF16BE.decode(bom === BOM_BE ? buf.subarray(2) : buf);
151
175
  }
152
176
  function decodeToString(data, encoding) {
153
- if (isGZipped(data)) {
154
- return decodeToString(decompressBuffer(data), encoding);
155
- }
156
- const buf = asUint8Array(data);
157
- const bom = buf[0] << 8 | buf[1];
158
- if (bom === BOM_BE || buf[0] === 0 && buf[1] !== 0) return decodeUtf16BE(buf);
159
- if (bom === BOM_LE || buf[0] !== 0 && buf[1] === 0) return decodeUtf16LE(buf);
160
- if (!encoding) return decoderUTF8.decode(buf);
161
- switch (encoding) {
162
- case "utf-16be":
163
- case "utf16be": {
164
- return decodeUtf16BE(buf);
165
- }
166
- case "utf-16le":
167
- case "utf16le": {
168
- return decodeUtf16LE(buf);
169
- }
170
- case "utf-8":
171
- case "utf8": {
172
- return decoderUTF8.decode(buf);
173
- }
174
- }
175
- throw new UnsupportedEncodingError(encoding);
177
+ if (isGZipped(data)) return decodeToString(decompressBuffer(data), encoding);
178
+ const buf = asUint8Array(data);
179
+ const bom = buf[0] << 8 | buf[1];
180
+ if (bom === BOM_BE || buf[0] === 0 && buf[1] !== 0) return decodeUtf16BE(buf);
181
+ if (bom === BOM_LE || buf[0] !== 0 && buf[1] === 0) return decodeUtf16LE(buf);
182
+ if (!encoding) return decoderUTF8.decode(buf);
183
+ switch (encoding) {
184
+ case "utf-16be":
185
+ case "utf16be": return decodeUtf16BE(buf);
186
+ case "utf-16le":
187
+ case "utf16le": return decodeUtf16LE(buf);
188
+ case "utf-8":
189
+ case "utf8": return decoderUTF8.decode(buf);
190
+ }
191
+ throw new UnsupportedEncodingError(encoding);
176
192
  }
177
193
  function decode(data, encoding) {
178
- switch (encoding) {
179
- case "base64":
180
- case "base64url":
181
- case "hex": {
182
- return arrayBufferViewToBuffer(data).toString(encoding);
183
- }
184
- }
185
- const result = decodeToString(data, encoding);
186
- return result;
194
+ switch (encoding) {
195
+ case "base64":
196
+ case "base64url":
197
+ case "hex": return arrayBufferViewToBuffer(data).toString(encoding);
198
+ }
199
+ const result = decodeToString(data, encoding);
200
+ return result;
187
201
  }
188
202
  function encodeString(str, encoding, bom) {
189
- switch (encoding) {
190
- case void 0:
191
- case "utf-8":
192
- case "utf8": {
193
- return encoderUTF8.encode(str);
194
- }
195
- case "utf-16be":
196
- case "utf16be": {
197
- return encodeUtf16BE(str, bom);
198
- }
199
- case "utf-16le":
200
- case "utf16le": {
201
- return encodeUtf16LE(str, bom);
202
- }
203
- }
204
- return Buffer.from(str, encoding);
203
+ switch (encoding) {
204
+ case void 0:
205
+ case "utf-8":
206
+ case "utf8": return encoderUTF8.encode(str);
207
+ case "utf-16be":
208
+ case "utf16be": return encodeUtf16BE(str, bom);
209
+ case "utf-16le":
210
+ case "utf16le": return encodeUtf16LE(str, bom);
211
+ }
212
+ return Buffer.from(str, encoding);
205
213
  }
206
214
  function encodeUtf16LE(str, bom = true) {
207
- const buf = Buffer.from(str, "utf16le");
208
- if (bom) {
209
- const target = Buffer.alloc(buf.length + 2);
210
- target.writeUint16LE(BOM_BE);
211
- buf.copy(target, 2);
212
- return target;
213
- }
214
- return buf;
215
+ const buf = Buffer.from(str, "utf16le");
216
+ if (bom) {
217
+ const target = Buffer.alloc(buf.length + 2);
218
+ target.writeUint16LE(BOM_BE);
219
+ buf.copy(target, 2);
220
+ return target;
221
+ }
222
+ return buf;
215
223
  }
216
224
  function encodeUtf16BE(str, bom = true) {
217
- return swap16(encodeUtf16LE(str, bom));
225
+ return swap16(encodeUtf16LE(str, bom));
218
226
  }
219
227
  function createTextDecoderUtf16BE() {
220
- try {
221
- const decoder = new TextDecoder("utf-16be");
222
- return decoder;
223
- } catch {
224
- return {
225
- encoding: "utf-16be",
226
- fatal: false,
227
- ignoreBOM: false,
228
- decode: (input) => decoderUTF16LE.decode(swapBytes(input))
229
- };
230
- }
228
+ try {
229
+ const decoder = new TextDecoder("utf-16be");
230
+ return decoder;
231
+ } catch {
232
+ return {
233
+ encoding: "utf-16be",
234
+ fatal: false,
235
+ ignoreBOM: false,
236
+ decode: (input) => decoderUTF16LE.decode(swapBytes(input))
237
+ };
238
+ }
231
239
  }
232
240
  var UnsupportedEncodingError = class extends Error {
233
- constructor(encoding) {
234
- super(`Unsupported encoding: ${encoding}`);
235
- }
241
+ constructor(encoding) {
242
+ super(`Unsupported encoding: ${encoding}`);
243
+ }
236
244
  };
237
245
  function isGZipped(data) {
238
- if (typeof data === "string") return false;
239
- const buf = asUint8Array(data);
240
- return buf[0] === 31 && buf[1] === 139;
246
+ if (typeof data === "string") return false;
247
+ const buf = asUint8Array(data);
248
+ return buf[0] === 31 && buf[1] === 139;
241
249
  }
242
250
  function decompressBuffer(data) {
243
- if (!isGZipped(data)) return data;
244
- const buf = arrayBufferViewToBuffer(data);
245
- return gunzipSync(buf);
251
+ if (!isGZipped(data)) return data;
252
+ const buf = arrayBufferViewToBuffer(data);
253
+ return gunzipSync(buf);
246
254
  }
247
255
 
248
- // src/common/CFileResource.ts
249
- var CFileResource = class _CFileResource {
250
- constructor(url, content, encoding, baseFilename, gz) {
251
- this.url = url;
252
- this.content = content;
253
- this.encoding = encoding;
254
- this.baseFilename = baseFilename ?? (url.protocol !== "data:" && url.pathname.split("/").pop() || void 0);
255
- this._gz = gz;
256
- }
257
- _text;
258
- baseFilename;
259
- _gz;
260
- get gz() {
261
- if (this._gz !== void 0) return this._gz;
262
- if (this.url.pathname.endsWith(".gz")) return true;
263
- if (typeof this.content === "string") return false;
264
- return isGZipped(this.content);
265
- }
266
- getText(encoding) {
267
- if (this._text !== void 0) return this._text;
268
- const text = typeof this.content === "string" ? this.content : decode(this.content, encoding ?? this.encoding);
269
- this._text = text;
270
- return text;
271
- }
272
- getBytes() {
273
- const arrayBufferview = typeof this.content === "string" ? encodeString(this.content, this.encoding) : this.content;
274
- return arrayBufferview instanceof Uint8Array ? arrayBufferview : new Uint8Array(arrayBufferview.buffer, arrayBufferview.byteOffset, arrayBufferview.byteLength);
275
- }
276
- toJson() {
277
- return {
278
- url: this.url.href,
279
- content: this.getText(),
280
- encoding: this.encoding,
281
- baseFilename: this.baseFilename,
282
- gz: this.gz
283
- };
284
- }
285
- static isCFileResource(obj) {
286
- return obj instanceof _CFileResource;
287
- }
288
- static from(urlOrFileResource, content, encoding, baseFilename, gz) {
289
- if (_CFileResource.isCFileResource(urlOrFileResource)) {
290
- if (content) {
291
- const { url, encoding: encoding2, baseFilename: baseFilename2, gz: gz2 } = urlOrFileResource;
292
- return new _CFileResource(url, content, encoding2, baseFilename2, gz2);
293
- }
294
- return urlOrFileResource;
295
- }
296
- if (urlOrFileResource instanceof URL) {
297
- assert(content !== void 0);
298
- return new _CFileResource(urlOrFileResource, content, encoding, baseFilename, gz);
299
- }
300
- if (content !== void 0) {
301
- const fileRef = urlOrFileResource;
302
- return new _CFileResource(fileRef.url, content, fileRef.encoding, fileRef.baseFilename, fileRef.gz);
303
- }
304
- assert("content" in urlOrFileResource && urlOrFileResource.content !== void 0);
305
- const fileResource = urlOrFileResource;
306
- return new _CFileResource(
307
- fileResource.url,
308
- fileResource.content,
309
- fileResource.encoding,
310
- fileResource.baseFilename,
311
- fileResource.gz
312
- );
313
- }
256
+ //#endregion
257
+ //#region src/common/CFileResource.ts
258
+ var CFileResource = class CFileResource {
259
+ _text;
260
+ baseFilename;
261
+ _gz;
262
+ constructor(url, content, encoding, baseFilename, gz) {
263
+ this.url = url;
264
+ this.content = content;
265
+ this.encoding = encoding;
266
+ this.baseFilename = baseFilename ?? (url.protocol !== "data:" && url.pathname.split("/").pop() || void 0);
267
+ this._gz = gz;
268
+ }
269
+ get gz() {
270
+ if (this._gz !== void 0) return this._gz;
271
+ if (this.url.pathname.endsWith(".gz")) return true;
272
+ if (typeof this.content === "string") return false;
273
+ return isGZipped(this.content);
274
+ }
275
+ getText(encoding) {
276
+ if (this._text !== void 0) return this._text;
277
+ const text = typeof this.content === "string" ? this.content : decode(this.content, encoding ?? this.encoding);
278
+ this._text = text;
279
+ return text;
280
+ }
281
+ getBytes() {
282
+ const arrayBufferview = typeof this.content === "string" ? encodeString(this.content, this.encoding) : this.content;
283
+ return arrayBufferview instanceof Uint8Array ? arrayBufferview : new Uint8Array(arrayBufferview.buffer, arrayBufferview.byteOffset, arrayBufferview.byteLength);
284
+ }
285
+ toJson() {
286
+ return {
287
+ url: this.url.href,
288
+ content: this.getText(),
289
+ encoding: this.encoding,
290
+ baseFilename: this.baseFilename,
291
+ gz: this.gz
292
+ };
293
+ }
294
+ static isCFileResource(obj) {
295
+ return obj instanceof CFileResource;
296
+ }
297
+ static from(urlOrFileResource, content, encoding, baseFilename, gz) {
298
+ if (CFileResource.isCFileResource(urlOrFileResource)) {
299
+ if (content) {
300
+ const { url, encoding: encoding$1, baseFilename: baseFilename$1, gz: gz$1 } = urlOrFileResource;
301
+ return new CFileResource(url, content, encoding$1, baseFilename$1, gz$1);
302
+ }
303
+ return urlOrFileResource;
304
+ }
305
+ if (urlOrFileResource instanceof URL) {
306
+ assert$1(content !== void 0);
307
+ return new CFileResource(urlOrFileResource, content, encoding, baseFilename, gz);
308
+ }
309
+ if (content !== void 0) {
310
+ const fileRef = urlOrFileResource;
311
+ return new CFileResource(fileRef.url, content, fileRef.encoding, fileRef.baseFilename, fileRef.gz);
312
+ }
313
+ assert$1("content" in urlOrFileResource && urlOrFileResource.content !== void 0);
314
+ const fileResource = urlOrFileResource;
315
+ return new CFileResource(fileResource.url, fileResource.content, fileResource.encoding, fileResource.baseFilename, fileResource.gz);
316
+ }
314
317
  };
315
318
  function fromFileResource(fileResource, encoding) {
316
- return CFileResource.from(encoding ? { ...fileResource, encoding } : fileResource);
319
+ return CFileResource.from(encoding ? {
320
+ ...fileResource,
321
+ encoding
322
+ } : fileResource);
317
323
  }
318
324
  function renameFileResource(fileResource, url) {
319
- return CFileResource.from({ ...fileResource, url });
325
+ return CFileResource.from({
326
+ ...fileResource,
327
+ url
328
+ });
320
329
  }
321
330
 
322
- // src/common/stat.ts
331
+ //#endregion
332
+ //#region src/common/stat.ts
333
+ /**
334
+ * Compare two Stats to see if they have the same value.
335
+ * @param left - Stats
336
+ * @param right - Stats
337
+ * @returns 0 - equal; 1 - left > right; -1 left < right
338
+ */
323
339
  function compareStats(left, right) {
324
- if (left === right) return 0;
325
- if (left.eTag || right.eTag) return left.eTag === right.eTag ? 0 : (left.eTag || "") < (right.eTag || "") ? -1 : 1;
326
- const diff = left.size - right.size || left.mtimeMs - right.mtimeMs;
327
- return diff < 0 ? -1 : diff > 0 ? 1 : 0;
340
+ if (left === right) return 0;
341
+ if (left.eTag || right.eTag) return left.eTag === right.eTag ? 0 : (left.eTag || "") < (right.eTag || "") ? -1 : 1;
342
+ const diff = left.size - right.size || left.mtimeMs - right.mtimeMs;
343
+ return diff < 0 ? -1 : diff > 0 ? 1 : 0;
328
344
  }
329
345
 
330
- // src/common/urlOrReferenceToUrl.ts
346
+ //#endregion
347
+ //#region src/common/urlOrReferenceToUrl.ts
331
348
  function urlOrReferenceToUrl(urlOrReference) {
332
- return urlOrReference instanceof URL ? urlOrReference : urlOrReference.url;
349
+ return urlOrReference instanceof URL ? urlOrReference : urlOrReference.url;
333
350
  }
334
351
 
335
- // src/CSpellIONode.ts
336
- import { isServiceResponseSuccess as isServiceResponseSuccess2, ServiceBus } from "@cspell/cspell-service-bus";
337
-
338
- // src/CSpellIO.ts
352
+ //#endregion
353
+ //#region src/CSpellIO.ts
339
354
  function toReadFileOptions(options) {
340
- if (!options) return options;
341
- if (typeof options === "string") {
342
- return { encoding: options };
343
- }
344
- return options;
355
+ if (!options) return options;
356
+ if (typeof options === "string") return { encoding: options };
357
+ return options;
345
358
  }
346
359
 
347
- // src/handlers/node/file.ts
348
- import { promises as fs3, readFileSync, statSync as statSync2 } from "fs";
349
- import { fileURLToPath } from "url";
350
- import { promisify } from "util";
351
- import { gunzipSync as gunzipSync2, gzip } from "zlib";
352
- import { createResponse, createResponseFail, isServiceResponseSuccess } from "@cspell/cspell-service-bus";
353
-
354
- // src/errors/error.ts
360
+ //#endregion
361
+ //#region src/errors/error.ts
355
362
  function toError(e) {
356
- if (e instanceof Error) return e;
357
- if (typeof e === "object" && e && "message" in e && typeof e.message === "string") {
358
- return new Error(e.message, { cause: e });
359
- }
360
- return new Error(e && e.toString());
363
+ if (e instanceof Error) return e;
364
+ if (typeof e === "object" && e && "message" in e && typeof e.message === "string") return new Error(e.message, { cause: e });
365
+ return new Error(e && e.toString());
361
366
  }
362
367
 
363
- // src/models/Stats.ts
364
- var FileType = /* @__PURE__ */ ((FileType2) => {
365
- FileType2[FileType2["Unknown"] = 0] = "Unknown";
366
- FileType2[FileType2["File"] = 1] = "File";
367
- FileType2[FileType2["Directory"] = 2] = "Directory";
368
- FileType2[FileType2["SymbolicLink"] = 64] = "SymbolicLink";
369
- return FileType2;
370
- })(FileType || {});
368
+ //#endregion
369
+ //#region src/models/Stats.ts
370
+ let FileType = /* @__PURE__ */ function(FileType$1) {
371
+ /**
372
+ * The file type is unknown.
373
+ */
374
+ FileType$1[FileType$1["Unknown"] = 0] = "Unknown";
375
+ /**
376
+ * A regular file.
377
+ */
378
+ FileType$1[FileType$1["File"] = 1] = "File";
379
+ /**
380
+ * A directory.
381
+ */
382
+ FileType$1[FileType$1["Directory"] = 2] = "Directory";
383
+ /**
384
+ * A symbolic link.
385
+ */
386
+ FileType$1[FileType$1["SymbolicLink"] = 64] = "SymbolicLink";
387
+ return FileType$1;
388
+ }({});
371
389
 
372
- // src/node/dataUrl.ts
373
- import { promises as fs } from "fs";
374
- import * as fsPath from "path";
390
+ //#endregion
391
+ //#region src/node/dataUrl.ts
392
+ /**
393
+ * Generates a string of the following format:
394
+ *
395
+ * `data:[mediaType][;charset=<encoding>[;base64],<data>`
396
+ *
397
+ * - `encoding` - defaults to `utf8` for text data
398
+ * @param data
399
+ * @param mediaType - The mediaType is a [MIME](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types) type string
400
+ * @param attributes - Additional attributes
401
+ */
375
402
  function encodeDataUrl(data, mediaType, attributes) {
376
- if (typeof data === "string") return encodeString2(data, mediaType, attributes);
377
- const attribs = encodeAttributes(attributes || []);
378
- const buf = arrayBufferViewToBuffer(data);
379
- return `data:${mediaType}${attribs};base64,${buf.toString("base64url")}`;
403
+ if (typeof data === "string") return encodeString$1(data, mediaType, attributes);
404
+ const attribs = encodeAttributes(attributes || []);
405
+ const buf = arrayBufferViewToBuffer(data);
406
+ return `data:${mediaType}${attribs};base64,${buf.toString("base64url")}`;
380
407
  }
381
408
  function toDataUrl(data, mediaType, attributes) {
382
- return new URL(encodeDataUrl(data, mediaType, attributes));
383
- }
384
- function encodeString2(data, mediaType, attributes) {
385
- mediaType = mediaType || "text/plain";
386
- attributes = attributes || [];
387
- const asUrlComp = encodeURIComponent(data);
388
- const asBase64 = Buffer.from(data).toString("base64url");
389
- const useBase64 = asBase64.length < asUrlComp.length - 7;
390
- const encoded = useBase64 ? asBase64 : asUrlComp;
391
- const attribMap = new Map([["charset", "utf-8"], ...attributes]);
392
- attribMap.set("charset", "utf-8");
393
- const attribs = encodeAttributes(attribMap);
394
- return `data:${mediaType}${attribs}${useBase64 ? ";base64" : ""},${encoded}`;
409
+ return new URL(encodeDataUrl(data, mediaType, attributes));
410
+ }
411
+ function encodeString$1(data, mediaType, attributes) {
412
+ mediaType = mediaType || "text/plain";
413
+ attributes = attributes || [];
414
+ const asUrlComp = encodeURIComponent(data);
415
+ const asBase64 = Buffer.from(data).toString("base64url");
416
+ const useBase64 = asBase64.length < asUrlComp.length - 7;
417
+ const encoded = useBase64 ? asBase64 : asUrlComp;
418
+ const attribMap = new Map([["charset", "utf-8"], ...attributes]);
419
+ attribMap.set("charset", "utf-8");
420
+ const attribs = encodeAttributes(attribMap);
421
+ return `data:${mediaType}${attribs}${useBase64 ? ";base64" : ""},${encoded}`;
395
422
  }
396
423
  function encodeAttributes(attributes) {
397
- return [...attributes].map(([key, value]) => `;${key}=${encodeURIComponent(value)}`).join("");
424
+ return [...attributes].map(([key, value]) => `;${key}=${encodeURIComponent(value)}`).join("");
398
425
  }
399
- var dataUrlRegExHead = /^data:(?<mediaType>[^;,]*)(?<attributes>(?:;[^=]+=[^;,]*)*)(?<base64>;base64)?$/;
426
+ const dataUrlRegExHead = /^data:(?<mediaType>[^;,]*)(?<attributes>(?:;[^=]+=[^;,]*)*)(?<base64>;base64)?$/;
400
427
  function decodeDataUrl(url) {
401
- url = url.toString();
402
- const [head, encodedData] = url.split(",", 2);
403
- if (!head || encodedData === void 0) throw new Error("Not a data url");
404
- const match = head.match(dataUrlRegExHead);
405
- if (!match || !match.groups) throw new Error("Not a data url");
406
- const mediaType = match.groups["mediaType"] || "";
407
- const rawAttributes = (match.groups["attributes"] || "").split(";").filter((a) => !!a).map((entry) => entry.split("=", 2)).map(([key, value]) => [key, decodeURIComponent(value)]);
408
- const attributes = new Map(rawAttributes);
409
- const encoding = attributes.get("charset");
410
- const isBase64 = !!match.groups["base64"];
411
- const data = isBase64 ? Buffer.from(encodedData, "base64url") : Buffer.from(decodeURIComponent(encodedData));
412
- return { mediaType, data, encoding, attributes };
428
+ url = url.toString();
429
+ const [head, encodedData] = url.split(",", 2);
430
+ if (!head || encodedData === void 0) throw new Error("Not a data url");
431
+ const match = head.match(dataUrlRegExHead);
432
+ if (!match || !match.groups) throw new Error("Not a data url");
433
+ const mediaType = match.groups["mediaType"] || "";
434
+ const rawAttributes = (match.groups["attributes"] || "").split(";").filter((a) => !!a).map((entry) => entry.split("=", 2)).map(([key, value]) => [key, decodeURIComponent(value)]);
435
+ const attributes = new Map(rawAttributes);
436
+ const encoding = attributes.get("charset");
437
+ const isBase64 = !!match.groups["base64"];
438
+ const data = isBase64 ? Buffer.from(encodedData, "base64url") : Buffer.from(decodeURIComponent(encodedData));
439
+ return {
440
+ mediaType,
441
+ data,
442
+ encoding,
443
+ attributes
444
+ };
413
445
  }
414
446
  function guessMimeType(filename) {
415
- if (filename.endsWith(".trie")) return { mimeType: "application/vnd.cspell.dictionary+trie", encoding: "utf-8" };
416
- if (filename.endsWith(".trie.gz")) return { mimeType: "application/vnd.cspell.dictionary+trie.gz" };
417
- if (filename.endsWith(".txt")) return { mimeType: "text/plain", encoding: "utf-8" };
418
- if (filename.endsWith(".txt.gz")) return { mimeType: "application/gzip" };
419
- if (filename.endsWith(".gz")) return { mimeType: "application/gzip" };
420
- if (filename.endsWith(".json")) return { mimeType: "application/json", encoding: "utf-8" };
421
- if (filename.endsWith(".yaml") || filename.endsWith(".yml"))
422
- return { mimeType: "application/x-yaml", encoding: "utf-8" };
423
- return void 0;
447
+ if (filename.endsWith(".trie")) return {
448
+ mimeType: "application/vnd.cspell.dictionary+trie",
449
+ encoding: "utf-8"
450
+ };
451
+ if (filename.endsWith(".trie.gz")) return { mimeType: "application/vnd.cspell.dictionary+trie.gz" };
452
+ if (filename.endsWith(".txt")) return {
453
+ mimeType: "text/plain",
454
+ encoding: "utf-8"
455
+ };
456
+ if (filename.endsWith(".txt.gz")) return { mimeType: "application/gzip" };
457
+ if (filename.endsWith(".gz")) return { mimeType: "application/gzip" };
458
+ if (filename.endsWith(".json")) return {
459
+ mimeType: "application/json",
460
+ encoding: "utf-8"
461
+ };
462
+ if (filename.endsWith(".yaml") || filename.endsWith(".yml")) return {
463
+ mimeType: "application/x-yaml",
464
+ encoding: "utf-8"
465
+ };
466
+ return void 0;
424
467
  }
425
468
 
426
- // src/node/file/_fetch.ts
427
- var _fetch = global.fetch;
469
+ //#endregion
470
+ //#region src/node/file/_fetch.ts
471
+ /** alias of global.fetch, useful for mocking */
472
+ const _fetch = global.fetch;
428
473
 
429
- // src/node/file/FetchError.ts
430
- var FetchUrlError = class _FetchUrlError extends Error {
431
- constructor(message, code, status, url) {
432
- super(message);
433
- this.code = code;
434
- this.status = status;
435
- this.url = url;
436
- this.name = "FetchUrlError";
437
- }
438
- static create(url, status, message) {
439
- if (status === 404) return new _FetchUrlError(message || "URL not found.", "ENOENT", status, url);
440
- if (status >= 400 && status < 500)
441
- return new _FetchUrlError(message || "Permission denied.", "EACCES", status, url);
442
- return new _FetchUrlError(message || "Fatal Error", "ECONNREFUSED", status, url);
443
- }
444
- static fromError(url, e) {
445
- const cause = getCause(e);
446
- if (cause) {
447
- return new _FetchUrlError(cause.message, cause.code, void 0, url);
448
- }
449
- if (isNodeError(e)) {
450
- return new _FetchUrlError(e.message, e.code, void 0, url);
451
- }
452
- return new _FetchUrlError(e.message, void 0, void 0, url);
453
- }
474
+ //#endregion
475
+ //#region src/node/file/FetchError.ts
476
+ var FetchUrlError = class FetchUrlError extends Error {
477
+ constructor(message, code, status, url) {
478
+ super(message);
479
+ this.code = code;
480
+ this.status = status;
481
+ this.url = url;
482
+ this.name = "FetchUrlError";
483
+ }
484
+ static create(url, status, message) {
485
+ if (status === 404) return new FetchUrlError(message || "URL not found.", "ENOENT", status, url);
486
+ if (status >= 400 && status < 500) return new FetchUrlError(message || "Permission denied.", "EACCES", status, url);
487
+ return new FetchUrlError(message || "Fatal Error", "ECONNREFUSED", status, url);
488
+ }
489
+ static fromError(url, e) {
490
+ const cause = getCause(e);
491
+ if (cause) return new FetchUrlError(cause.message, cause.code, void 0, url);
492
+ if (isNodeError(e)) return new FetchUrlError(e.message, e.code, void 0, url);
493
+ return new FetchUrlError(e.message, void 0, void 0, url);
494
+ }
454
495
  };
455
496
  function isNodeError(e) {
456
- if (e instanceof Error && "code" in e && typeof e.code === "string") return true;
457
- if (e && typeof e === "object" && "code" in e && typeof e.code === "string") return true;
458
- return false;
497
+ if (e instanceof Error && "code" in e && typeof e.code === "string") return true;
498
+ if (e && typeof e === "object" && "code" in e && typeof e.code === "string") return true;
499
+ return false;
459
500
  }
460
501
  function isError(e) {
461
- return e instanceof Error;
502
+ return e instanceof Error;
462
503
  }
463
504
  function isErrorWithOptionalCause(e) {
464
- return isError(e) && (!("cause" in e) || isNodeError(e.cause) || isNodeError(e));
505
+ return isError(e) && (!("cause" in e) || isNodeError(e.cause) || isNodeError(e));
465
506
  }
466
507
  function getCause(e) {
467
- return isErrorWithOptionalCause(e) ? e.cause : void 0;
508
+ return isErrorWithOptionalCause(e) ? e.cause : void 0;
468
509
  }
469
510
  function toFetchUrlError(err, url) {
470
- return err instanceof FetchUrlError ? err : FetchUrlError.fromError(url, toError2(err));
511
+ return err instanceof FetchUrlError ? err : FetchUrlError.fromError(url, toError$1(err));
471
512
  }
472
- function toError2(err) {
473
- return err instanceof Error ? err : new Error("Unknown Error", { cause: err });
513
+ function toError$1(err) {
514
+ return err instanceof Error ? err : new Error("Unknown Error", { cause: err });
474
515
  }
475
516
 
476
- // src/node/file/fetch.ts
517
+ //#endregion
518
+ //#region src/node/file/fetch.ts
477
519
  async function fetchHead(request) {
478
- const url = toURL2(request);
479
- try {
480
- const r = await _fetch(url, { method: "HEAD" });
481
- if (!r.ok) {
482
- throw FetchUrlError.create(url, r.status);
483
- }
484
- return r.headers;
485
- } catch (e) {
486
- throw toFetchUrlError(e, url);
487
- }
520
+ const url = toURL$1(request);
521
+ try {
522
+ const r = await _fetch(url, { method: "HEAD" });
523
+ if (!r.ok) throw FetchUrlError.create(url, r.status);
524
+ return r.headers;
525
+ } catch (e) {
526
+ throw toFetchUrlError(e, url);
527
+ }
488
528
  }
489
529
  async function fetchURL(url, signal) {
490
- try {
491
- const request = signal ? new Request(url, { signal }) : url;
492
- const response = await _fetch(request);
493
- if (!response.ok) {
494
- throw FetchUrlError.create(url, response.status);
495
- }
496
- return Buffer.from(await response.arrayBuffer());
497
- } catch (e) {
498
- throw toFetchUrlError(e, url);
499
- }
500
- }
501
- function toURL2(url) {
502
- return typeof url === "string" ? new URL(url) : url;
530
+ try {
531
+ const request = signal ? new Request(url, { signal }) : url;
532
+ const response = await _fetch(request);
533
+ if (!response.ok) throw FetchUrlError.create(url, response.status);
534
+ return Buffer.from(await response.arrayBuffer());
535
+ } catch (e) {
536
+ throw toFetchUrlError(e, url);
537
+ }
538
+ }
539
+ function toURL$1(url) {
540
+ return typeof url === "string" ? new URL(url) : url;
503
541
  }
504
542
 
505
- // src/node/file/stat.ts
506
- import { promises as fs2, statSync } from "fs";
507
- import { format } from "util";
543
+ //#endregion
544
+ //#region src/node/file/stat.ts
508
545
  async function getStatHttp(url) {
509
- const headers = await fetchHead(url);
510
- const eTag = headers.get("etag") || void 0;
511
- const guessSize = Number.parseInt(headers.get("content-length") || "0", 10);
512
- return {
513
- size: eTag ? -1 : guessSize,
514
- mtimeMs: 0,
515
- eTag
516
- };
546
+ const headers = await fetchHead(url);
547
+ const eTag = headers.get("etag") || void 0;
548
+ const guessSize = Number.parseInt(headers.get("content-length") || "0", 10);
549
+ return {
550
+ size: eTag ? -1 : guessSize,
551
+ mtimeMs: 0,
552
+ eTag
553
+ };
517
554
  }
518
555
 
519
- // src/requests/RequestFsReadFile.ts
520
- import { requestFactory } from "@cspell/cspell-service-bus";
521
- var RequestType = "fs:readFile";
522
- var RequestFsReadFile = requestFactory(
523
- RequestType
524
- );
556
+ //#endregion
557
+ //#region src/requests/RequestFsReadFile.ts
558
+ const RequestType$4 = "fs:readFile";
559
+ const RequestFsReadFile = requestFactory(RequestType$4);
525
560
 
526
- // src/requests/RequestFsReadFileSync.ts
527
- import { requestFactory as requestFactory2 } from "@cspell/cspell-service-bus";
528
- var RequestType2 = "fs:readFileSync";
529
- var RequestFsReadFileTextSync = requestFactory2(
530
- RequestType2
531
- );
561
+ //#endregion
562
+ //#region src/requests/RequestFsReadFileSync.ts
563
+ const RequestType$3 = "fs:readFileSync";
564
+ const RequestFsReadFileTextSync = requestFactory(RequestType$3);
532
565
 
533
- // src/requests/RequestFsStat.ts
534
- import { requestFactory as requestFactory3 } from "@cspell/cspell-service-bus";
535
- var RequestTypeStat = "fs:stat";
536
- var RequestFsStat = requestFactory3(RequestTypeStat);
537
- var RequestTypeStatSync = "fs:statSync";
538
- var RequestFsStatSync = requestFactory3(
539
- RequestTypeStatSync
540
- );
566
+ //#endregion
567
+ //#region src/requests/RequestFsStat.ts
568
+ const RequestTypeStat = "fs:stat";
569
+ const RequestFsStat = requestFactory(RequestTypeStat);
570
+ const RequestTypeStatSync = "fs:statSync";
571
+ const RequestFsStatSync = requestFactory(RequestTypeStatSync);
541
572
 
542
- // src/requests/RequestFsWriteFile.ts
543
- import { requestFactory as requestFactory4 } from "@cspell/cspell-service-bus";
544
- var RequestType3 = "fs:writeFile";
545
- var RequestFsWriteFile = requestFactory4(
546
- RequestType3
547
- );
573
+ //#endregion
574
+ //#region src/requests/RequestFsWriteFile.ts
575
+ const RequestType$2 = "fs:writeFile";
576
+ const RequestFsWriteFile = requestFactory(RequestType$2);
548
577
 
549
- // src/requests/RequestZlibInflate.ts
550
- import { requestFactory as requestFactory5 } from "@cspell/cspell-service-bus";
551
- var RequestType4 = "zlib:inflate";
552
- var RequestZlibInflate = requestFactory5(RequestType4);
578
+ //#endregion
579
+ //#region src/requests/RequestZlibInflate.ts
580
+ const RequestType$1 = "zlib:inflate";
581
+ const RequestZlibInflate = requestFactory(RequestType$1);
553
582
 
554
- // src/requests/RequestFsReadDirectory.ts
555
- import { requestFactory as requestFactory6 } from "@cspell/cspell-service-bus";
556
- var RequestType5 = "fs:readDir";
557
- var RequestFsReadDirectory = requestFactory6(
558
- RequestType5
559
- );
583
+ //#endregion
584
+ //#region src/requests/RequestFsReadDirectory.ts
585
+ const RequestType = "fs:readDir";
586
+ const RequestFsReadDirectory = requestFactory(RequestType);
560
587
 
561
- // src/handlers/node/file.ts
562
- var isGzFileRegExp = /\.gz($|[?#])/;
588
+ //#endregion
589
+ //#region src/handlers/node/file.ts
590
+ const isGzFileRegExp = /\.gz($|[?#])/;
563
591
  function isGzFile(url) {
564
- return isGzFileRegExp.test(typeof url === "string" ? url : url.pathname);
565
- }
566
- var pGzip = promisify(gzip);
567
- var handleRequestFsReadFile = RequestFsReadFile.createRequestHandler(
568
- ({ params }) => {
569
- const baseFilename = urlBasename(params.url);
570
- return createResponse(
571
- fs3.readFile(fileURLToPath(params.url)).then((content) => CFileResource.from(params.url, content, params.encoding, baseFilename))
572
- );
573
- },
574
- void 0,
575
- "Node: Read Binary File."
576
- );
577
- var handleRequestFsReadFileSync = RequestFsReadFileTextSync.createRequestHandler(
578
- ({ params }) => createResponse(CFileResource.from({ ...params, content: readFileSync(fileURLToPath(params.url)) })),
579
- void 0,
580
- "Node: Sync Read Binary File."
581
- );
582
- var handleRequestFsReadDirectory = RequestFsReadDirectory.createRequestHandler(
583
- ({ params }) => {
584
- return createResponse(
585
- fs3.readdir(fileURLToPath(params.url), { withFileTypes: true }).then((entries) => direntToDirEntries(params.url, entries))
586
- );
587
- },
588
- void 0,
589
- "Node: Read Directory."
590
- );
591
- var handleRequestZlibInflate = RequestZlibInflate.createRequestHandler(
592
- ({ params }) => createResponse(gunzipSync2(arrayBufferViewToBuffer(params.data))),
593
- void 0,
594
- "Node: gz deflate."
595
- );
596
- var supportedFetchProtocols = { "http:": true, "https:": true };
597
- var handleRequestFsReadFileHttp = RequestFsReadFile.createRequestHandler(
598
- (req, next) => {
599
- const { url, signal, encoding } = req.params;
600
- if (!(url.protocol in supportedFetchProtocols)) return next(req);
601
- return createResponse(fetchURL(url, signal).then((content) => CFileResource.from({ url, encoding, content })));
602
- },
603
- void 0,
604
- "Node: Read Http(s) file."
605
- );
606
- var handleRequestFsReadFileSyncData = RequestFsReadFileTextSync.createRequestHandler(
607
- (req, next) => {
608
- const { url, encoding } = req.params;
609
- if (url.protocol !== "data:") return next(req);
610
- const data = decodeDataUrl(url);
611
- return createResponse(
612
- CFileResource.from({ url, content: data.data, encoding, baseFilename: data.attributes.get("filename") })
613
- );
614
- },
615
- void 0,
616
- "Node: Read data: urls."
617
- );
618
- var handleRequestFsReadFileData = RequestFsReadFile.createRequestHandler(
619
- (req, next, dispatcher) => {
620
- const { url } = req.params;
621
- if (url.protocol !== "data:") return next(req);
622
- const res = dispatcher.dispatch(RequestFsReadFileTextSync.create(req.params));
623
- if (!isServiceResponseSuccess(res)) return res;
624
- return createResponse(Promise.resolve(res.value));
625
- },
626
- void 0,
627
- "Node: Read data: urls."
628
- );
629
- var handleRequestFsStat = RequestFsStat.createRequestHandler(
630
- ({ params }) => createResponse(toPromiseStats(fs3.stat(fileURLToPath(params.url)))),
631
- void 0,
632
- "Node: fs.stat."
633
- );
592
+ return isGzFileRegExp.test(typeof url === "string" ? url : url.pathname);
593
+ }
594
+ const pGzip = promisify(gzip);
595
+ /**
596
+ * Handle Binary File Reads
597
+ */
598
+ const handleRequestFsReadFile = RequestFsReadFile.createRequestHandler(({ params }) => {
599
+ const baseFilename = urlBasename(params.url);
600
+ return createResponse(promises.readFile(fileURLToPath(params.url)).then((content) => CFileResource.from(params.url, content, params.encoding, baseFilename)));
601
+ }, void 0, "Node: Read Binary File.");
602
+ /**
603
+ * Handle Binary File Sync Reads
604
+ */
605
+ const handleRequestFsReadFileSync = RequestFsReadFileTextSync.createRequestHandler(({ params }) => createResponse(CFileResource.from({
606
+ ...params,
607
+ content: readFileSync(fileURLToPath(params.url))
608
+ })), void 0, "Node: Sync Read Binary File.");
609
+ /**
610
+ * Handle Binary File Reads
611
+ */
612
+ const handleRequestFsReadDirectory = RequestFsReadDirectory.createRequestHandler(({ params }) => {
613
+ return createResponse(promises.readdir(fileURLToPath(params.url), { withFileTypes: true }).then((entries) => direntToDirEntries(params.url, entries)));
614
+ }, void 0, "Node: Read Directory.");
615
+ /**
616
+ * Handle deflating gzip data
617
+ */
618
+ const handleRequestZlibInflate = RequestZlibInflate.createRequestHandler(({ params }) => createResponse(gunzipSync(arrayBufferViewToBuffer(params.data))), void 0, "Node: gz deflate.");
619
+ const supportedFetchProtocols = {
620
+ "http:": true,
621
+ "https:": true
622
+ };
623
+ /**
624
+ * Handle fetching a file from http
625
+ */
626
+ const handleRequestFsReadFileHttp = RequestFsReadFile.createRequestHandler((req, next) => {
627
+ const { url, signal, encoding } = req.params;
628
+ if (!(url.protocol in supportedFetchProtocols)) return next(req);
629
+ return createResponse(fetchURL(url, signal).then((content) => CFileResource.from({
630
+ url,
631
+ encoding,
632
+ content
633
+ })));
634
+ }, void 0, "Node: Read Http(s) file.");
635
+ /**
636
+ * Handle decoding a data url
637
+ */
638
+ const handleRequestFsReadFileSyncData = RequestFsReadFileTextSync.createRequestHandler((req, next) => {
639
+ const { url, encoding } = req.params;
640
+ if (url.protocol !== "data:") return next(req);
641
+ const data = decodeDataUrl(url);
642
+ return createResponse(CFileResource.from({
643
+ url,
644
+ content: data.data,
645
+ encoding,
646
+ baseFilename: data.attributes.get("filename")
647
+ }));
648
+ }, void 0, "Node: Read data: urls.");
649
+ /**
650
+ * Handle decoding a data url
651
+ */
652
+ const handleRequestFsReadFileData = RequestFsReadFile.createRequestHandler((req, next, dispatcher) => {
653
+ const { url } = req.params;
654
+ if (url.protocol !== "data:") return next(req);
655
+ const res = dispatcher.dispatch(RequestFsReadFileTextSync.create(req.params));
656
+ if (!isServiceResponseSuccess(res)) return res;
657
+ return createResponse(Promise.resolve(res.value));
658
+ }, void 0, "Node: Read data: urls.");
659
+ /**
660
+ * Handle fs:stat
661
+ */
662
+ const handleRequestFsStat = RequestFsStat.createRequestHandler(({ params }) => createResponse(toPromiseStats(promises.stat(fileURLToPath(params.url)))), void 0, "Node: fs.stat.");
634
663
  function toStats(stat) {
635
- return {
636
- size: stat.size,
637
- mtimeMs: stat.mtimeMs,
638
- fileType: toFileType(stat)
639
- };
664
+ return {
665
+ size: stat.size,
666
+ mtimeMs: stat.mtimeMs,
667
+ fileType: toFileType(stat)
668
+ };
640
669
  }
641
670
  function toPromiseStats(pStat) {
642
- return pStat.then(toStats);
643
- }
644
- var handleRequestFsStatSync = RequestFsStatSync.createRequestHandler(
645
- (req) => {
646
- const { params } = req;
647
- try {
648
- return createResponse(statSync2(fileURLToPath(params.url)));
649
- } catch (e) {
650
- return createResponseFail(req, toError(e));
651
- }
652
- },
653
- void 0,
654
- "Node: fs.stat."
655
- );
656
- var handleRequestFsStatHttp = RequestFsStat.createRequestHandler(
657
- (req, next) => {
658
- const { url } = req.params;
659
- if (!(url.protocol in supportedFetchProtocols)) return next(req);
660
- return createResponse(getStatHttp(url));
661
- },
662
- void 0,
663
- "Node: http get stat"
664
- );
665
- var handleRequestFsWriteFile = RequestFsWriteFile.createRequestHandler(
666
- ({ params }) => createResponse(writeFile(params, params.content)),
667
- void 0,
668
- "Node: fs.writeFile"
669
- );
671
+ return pStat.then(toStats);
672
+ }
673
+ /**
674
+ * Handle fs:statSync
675
+ */
676
+ const handleRequestFsStatSync = RequestFsStatSync.createRequestHandler((req) => {
677
+ const { params } = req;
678
+ try {
679
+ return createResponse(statSync(fileURLToPath(params.url)));
680
+ } catch (e) {
681
+ return createResponseFail(req, toError(e));
682
+ }
683
+ }, void 0, "Node: fs.stat.");
684
+ /**
685
+ * Handle deflating gzip data
686
+ */
687
+ const handleRequestFsStatHttp = RequestFsStat.createRequestHandler((req, next) => {
688
+ const { url } = req.params;
689
+ if (!(url.protocol in supportedFetchProtocols)) return next(req);
690
+ return createResponse(getStatHttp(url));
691
+ }, void 0, "Node: http get stat");
692
+ /**
693
+ * Handle fs:writeFile
694
+ */
695
+ const handleRequestFsWriteFile = RequestFsWriteFile.createRequestHandler(({ params }) => createResponse(writeFile(params, params.content)), void 0, "Node: fs.writeFile");
670
696
  async function writeFile(fileRef, content) {
671
- const gz = isGZipped(content);
672
- const { url, encoding, baseFilename } = fileRef;
673
- const resultRef = { url, encoding, baseFilename, gz };
674
- await fs3.writeFile(fileURLToPath(fileRef.url), encodeContent(fileRef, content));
675
- return resultRef;
676
- }
677
- var handleRequestFsWriteFileDataUrl = RequestFsWriteFile.createRequestHandler(
678
- (req, next) => {
679
- const fileResource = req.params;
680
- const { url } = req.params;
681
- if (url.protocol !== "data:") return next(req);
682
- const gz = isGZipped(fileResource.content);
683
- const baseFilename = fileResource.baseFilename || "file.txt" + (gz ? ".gz" : "");
684
- const mt = guessMimeType(baseFilename);
685
- const mediaType = mt?.mimeType || "text/plain";
686
- const dataUrl = toDataUrl(fileResource.content, mediaType, [["filename", baseFilename]]);
687
- return createResponse(Promise.resolve({ url: dataUrl, baseFilename, gz, encoding: mt?.encoding }));
688
- },
689
- void 0,
690
- "Node: fs.writeFile DataUrl"
691
- );
692
- var handleRequestFsWriteFileGz = RequestFsWriteFile.createRequestHandler(
693
- (req, next, dispatcher) => {
694
- const fileResource = req.params;
695
- if (!fileResource.gz && !isGzFile(fileResource.url) && (!fileResource.baseFilename || !isGzFile(fileResource.baseFilename))) {
696
- return next(req);
697
- }
698
- if (typeof fileResource.content !== "string" && isGZipped(fileResource.content)) {
699
- return next(req);
700
- }
701
- return createResponse(compressAndChainWriteRequest(dispatcher, fileResource, fileResource.content));
702
- },
703
- void 0,
704
- "Node: fs.writeFile compressed"
705
- );
697
+ const gz = isGZipped(content);
698
+ const { url, encoding, baseFilename } = fileRef;
699
+ const resultRef = {
700
+ url,
701
+ encoding,
702
+ baseFilename,
703
+ gz
704
+ };
705
+ await promises.writeFile(fileURLToPath(fileRef.url), encodeContent(fileRef, content));
706
+ return resultRef;
707
+ }
708
+ /**
709
+ * Handle fs:writeFile
710
+ */
711
+ const handleRequestFsWriteFileDataUrl = RequestFsWriteFile.createRequestHandler((req, next) => {
712
+ const fileResource = req.params;
713
+ const { url } = req.params;
714
+ if (url.protocol !== "data:") return next(req);
715
+ const gz = isGZipped(fileResource.content);
716
+ const baseFilename = fileResource.baseFilename || "file.txt" + (gz ? ".gz" : "");
717
+ const mt = guessMimeType(baseFilename);
718
+ const mediaType = mt?.mimeType || "text/plain";
719
+ const dataUrl = toDataUrl(fileResource.content, mediaType, [["filename", baseFilename]]);
720
+ return createResponse(Promise.resolve({
721
+ url: dataUrl,
722
+ baseFilename,
723
+ gz,
724
+ encoding: mt?.encoding
725
+ }));
726
+ }, void 0, "Node: fs.writeFile DataUrl");
727
+ /**
728
+ * Handle fs:writeFile compressed
729
+ */
730
+ const handleRequestFsWriteFileGz = RequestFsWriteFile.createRequestHandler((req, next, dispatcher) => {
731
+ const fileResource = req.params;
732
+ if (!fileResource.gz && !isGzFile(fileResource.url) && (!fileResource.baseFilename || !isGzFile(fileResource.baseFilename))) return next(req);
733
+ if (typeof fileResource.content !== "string" && isGZipped(fileResource.content)) return next(req);
734
+ return createResponse(compressAndChainWriteRequest(dispatcher, fileResource, fileResource.content));
735
+ }, void 0, "Node: fs.writeFile compressed");
706
736
  async function compressAndChainWriteRequest(dispatcher, fileRef, content) {
707
- const buf = await pGzip(encodeContent(fileRef, content));
708
- const res = dispatcher.dispatch(RequestFsWriteFile.create({ ...fileRef, content: buf }));
709
- assert(isServiceResponseSuccess(res));
710
- return res.value;
737
+ const buf = await pGzip(encodeContent(fileRef, content));
738
+ const res = dispatcher.dispatch(RequestFsWriteFile.create({
739
+ ...fileRef,
740
+ content: buf
741
+ }));
742
+ assert$1(isServiceResponseSuccess(res));
743
+ return res.value;
711
744
  }
712
745
  function registerHandlers(serviceBus) {
713
- const handlers = [
714
- handleRequestFsReadFile,
715
- handleRequestFsReadFileSync,
716
- handleRequestFsWriteFile,
717
- handleRequestFsWriteFileDataUrl,
718
- handleRequestFsWriteFileGz,
719
- handleRequestFsReadFileHttp,
720
- handleRequestFsReadFileData,
721
- handleRequestFsReadFileSyncData,
722
- handleRequestFsReadDirectory,
723
- handleRequestZlibInflate,
724
- handleRequestFsStatSync,
725
- handleRequestFsStat,
726
- handleRequestFsStatHttp
727
- ];
728
- handlers.forEach((handler) => serviceBus.addHandler(handler));
746
+ /**
747
+ * Handlers are in order of low to high level
748
+ * Order is VERY important.
749
+ */
750
+ const handlers = [
751
+ handleRequestFsReadFile,
752
+ handleRequestFsReadFileSync,
753
+ handleRequestFsWriteFile,
754
+ handleRequestFsWriteFileDataUrl,
755
+ handleRequestFsWriteFileGz,
756
+ handleRequestFsReadFileHttp,
757
+ handleRequestFsReadFileData,
758
+ handleRequestFsReadFileSyncData,
759
+ handleRequestFsReadDirectory,
760
+ handleRequestZlibInflate,
761
+ handleRequestFsStatSync,
762
+ handleRequestFsStat,
763
+ handleRequestFsStatHttp
764
+ ];
765
+ handlers.forEach((handler) => serviceBus.addHandler(handler));
729
766
  }
730
767
  function encodeContent(ref, content) {
731
- if (typeof content === "string") {
732
- if ([void 0, "utf8", "utf-8"].includes(ref.encoding)) return content;
733
- return arrayBufferViewToBuffer(encodeString(content, ref.encoding));
734
- }
735
- return arrayBufferViewToBuffer(content);
768
+ if (typeof content === "string") {
769
+ if ([
770
+ void 0,
771
+ "utf8",
772
+ "utf-8"
773
+ ].includes(ref.encoding)) return content;
774
+ return arrayBufferViewToBuffer(encodeString(content, ref.encoding));
775
+ }
776
+ return arrayBufferViewToBuffer(content);
736
777
  }
737
778
  function mapperDirentToDirEntry(dir) {
738
- return (dirent) => direntToDirEntry(dir, dirent);
779
+ return (dirent) => direntToDirEntry(dir, dirent);
739
780
  }
740
781
  function direntToDirEntries(dir, dirent) {
741
- return dirent.map(mapperDirentToDirEntry(dir));
782
+ return dirent.map(mapperDirentToDirEntry(dir));
742
783
  }
743
784
  function direntToDirEntry(dir, dirent) {
744
- return {
745
- name: dirent.name,
746
- dir,
747
- fileType: toFileType(dirent)
748
- };
785
+ return {
786
+ name: dirent.name,
787
+ dir,
788
+ fileType: toFileType(dirent)
789
+ };
749
790
  }
750
791
  function toFileType(statLike) {
751
- const t = statLike.isFile() ? 1 /* File */ : statLike.isDirectory() ? 2 /* Directory */ : 0 /* Unknown */;
752
- return statLike.isSymbolicLink() ? t | 64 /* SymbolicLink */ : t;
792
+ const t = statLike.isFile() ? FileType.File : statLike.isDirectory() ? FileType.Directory : FileType.Unknown;
793
+ return statLike.isSymbolicLink() ? t | FileType.SymbolicLink : t;
753
794
  }
754
795
 
755
- // src/CSpellIONode.ts
756
- var defaultCSpellIONode = void 0;
796
+ //#endregion
797
+ //#region src/CSpellIONode.ts
798
+ let defaultCSpellIONode = void 0;
757
799
  var CSpellIONode = class {
758
- constructor(serviceBus = new ServiceBus()) {
759
- this.serviceBus = serviceBus;
760
- registerHandlers(serviceBus);
761
- }
762
- readFile(urlOrFilename, options) {
763
- const readOptions = toReadFileOptions(options);
764
- const ref = toFileResourceRequest(urlOrFilename, readOptions?.encoding, readOptions?.signal);
765
- const res = this.serviceBus.dispatch(RequestFsReadFile.create(ref));
766
- if (!isServiceResponseSuccess2(res)) {
767
- throw genError(res.error, "readFile");
768
- }
769
- return res.value;
770
- }
771
- readDirectory(urlOrFilename) {
772
- const ref = toFileReference(urlOrFilename);
773
- const res = this.serviceBus.dispatch(RequestFsReadDirectory.create(ref));
774
- if (!isServiceResponseSuccess2(res)) {
775
- throw genError(res.error, "readDirectory");
776
- }
777
- return res.value;
778
- }
779
- readFileSync(urlOrFilename, encoding) {
780
- const ref = toFileReference(urlOrFilename, encoding);
781
- const res = this.serviceBus.dispatch(RequestFsReadFileTextSync.create(ref));
782
- if (!isServiceResponseSuccess2(res)) {
783
- throw genError(res.error, "readFileSync");
784
- }
785
- return res.value;
786
- }
787
- writeFile(urlOrFilename, content) {
788
- const ref = toFileReference(urlOrFilename);
789
- const fileResource = CFileResource.from(ref, content);
790
- const res = this.serviceBus.dispatch(RequestFsWriteFile.create(fileResource));
791
- if (!isServiceResponseSuccess2(res)) {
792
- throw genError(res.error, "writeFile");
793
- }
794
- return res.value;
795
- }
796
- getStat(urlOrFilename) {
797
- const ref = toFileReference(urlOrFilename);
798
- const res = this.serviceBus.dispatch(RequestFsStat.create(ref));
799
- if (!isServiceResponseSuccess2(res)) {
800
- throw genError(res.error, "getStat");
801
- }
802
- return res.value;
803
- }
804
- getStatSync(urlOrFilename) {
805
- const ref = toFileReference(urlOrFilename);
806
- const res = this.serviceBus.dispatch(RequestFsStatSync.create(ref));
807
- if (!isServiceResponseSuccess2(res)) {
808
- throw genError(res.error, "getStatSync");
809
- }
810
- return res.value;
811
- }
812
- compareStats(left, right) {
813
- return compareStats(left, right);
814
- }
815
- toURL(urlOrFilename, relativeTo) {
816
- if (isFileReference(urlOrFilename)) return urlOrFilename.url;
817
- return toURL(urlOrFilename, relativeTo);
818
- }
819
- toFileURL(urlOrFilename, relativeTo) {
820
- if (isFileReference(urlOrFilename)) return urlOrFilename.url;
821
- return toFileURL(urlOrFilename, relativeTo);
822
- }
823
- urlBasename(urlOrFilename) {
824
- return urlBasename(this.toURL(urlOrFilename));
825
- }
826
- urlDirname(urlOrFilename) {
827
- return urlParent(this.toURL(urlOrFilename));
828
- }
800
+ constructor(serviceBus = new ServiceBus()) {
801
+ this.serviceBus = serviceBus;
802
+ registerHandlers(serviceBus);
803
+ }
804
+ readFile(urlOrFilename, options) {
805
+ const readOptions = toReadFileOptions(options);
806
+ const ref = toFileResourceRequest(urlOrFilename, readOptions?.encoding, readOptions?.signal);
807
+ const res = this.serviceBus.dispatch(RequestFsReadFile.create(ref));
808
+ if (!isServiceResponseSuccess(res)) throw genError(res.error, "readFile");
809
+ return res.value;
810
+ }
811
+ readDirectory(urlOrFilename) {
812
+ const ref = toFileReference(urlOrFilename);
813
+ const res = this.serviceBus.dispatch(RequestFsReadDirectory.create(ref));
814
+ if (!isServiceResponseSuccess(res)) throw genError(res.error, "readDirectory");
815
+ return res.value;
816
+ }
817
+ readFileSync(urlOrFilename, encoding) {
818
+ const ref = toFileReference(urlOrFilename, encoding);
819
+ const res = this.serviceBus.dispatch(RequestFsReadFileTextSync.create(ref));
820
+ if (!isServiceResponseSuccess(res)) throw genError(res.error, "readFileSync");
821
+ return res.value;
822
+ }
823
+ writeFile(urlOrFilename, content) {
824
+ const ref = toFileReference(urlOrFilename);
825
+ const fileResource = CFileResource.from(ref, content);
826
+ const res = this.serviceBus.dispatch(RequestFsWriteFile.create(fileResource));
827
+ if (!isServiceResponseSuccess(res)) throw genError(res.error, "writeFile");
828
+ return res.value;
829
+ }
830
+ getStat(urlOrFilename) {
831
+ const ref = toFileReference(urlOrFilename);
832
+ const res = this.serviceBus.dispatch(RequestFsStat.create(ref));
833
+ if (!isServiceResponseSuccess(res)) throw genError(res.error, "getStat");
834
+ return res.value;
835
+ }
836
+ getStatSync(urlOrFilename) {
837
+ const ref = toFileReference(urlOrFilename);
838
+ const res = this.serviceBus.dispatch(RequestFsStatSync.create(ref));
839
+ if (!isServiceResponseSuccess(res)) throw genError(res.error, "getStatSync");
840
+ return res.value;
841
+ }
842
+ compareStats(left, right) {
843
+ return compareStats(left, right);
844
+ }
845
+ toURL(urlOrFilename, relativeTo) {
846
+ if (isFileReference(urlOrFilename)) return urlOrFilename.url;
847
+ return toURL(urlOrFilename, relativeTo);
848
+ }
849
+ toFileURL(urlOrFilename, relativeTo) {
850
+ if (isFileReference(urlOrFilename)) return urlOrFilename.url;
851
+ return toFileURL(urlOrFilename, relativeTo);
852
+ }
853
+ urlBasename(urlOrFilename) {
854
+ return urlBasename(this.toURL(urlOrFilename));
855
+ }
856
+ urlDirname(urlOrFilename) {
857
+ return urlDirname(this.toURL(urlOrFilename));
858
+ }
829
859
  };
830
860
  function genError(err, alt) {
831
- return err || new ErrorNotImplemented(alt);
861
+ return err || new ErrorNotImplemented(alt);
832
862
  }
833
863
  function getDefaultCSpellIO() {
834
- if (defaultCSpellIONode) return defaultCSpellIONode;
835
- const cspellIO = new CSpellIONode();
836
- defaultCSpellIONode = cspellIO;
837
- return cspellIO;
864
+ if (defaultCSpellIONode) return defaultCSpellIONode;
865
+ const cspellIO = new CSpellIONode();
866
+ defaultCSpellIONode = cspellIO;
867
+ return cspellIO;
838
868
  }
839
869
 
840
- // src/VirtualFS.ts
841
- var debug = false;
870
+ //#endregion
871
+ //#region src/VirtualFS.ts
872
+ const debug = false;
842
873
 
843
- // src/VirtualFS/findUpFromUrl.ts
874
+ //#endregion
875
+ //#region src/VirtualFS/findUpFromUrl.ts
844
876
  async function findUpFromUrl(name, from, options) {
845
- const { type: entryType = "file", stopAt, fs: fs5 } = options;
846
- let dir = new URL(".", from);
847
- const root = new URL("/", dir);
848
- const predicate = makePredicate(fs5, name, entryType);
849
- const stopAtDir = stopAt || root;
850
- let last = "";
851
- while (dir.href !== last) {
852
- const found = await predicate(dir);
853
- if (found !== void 0) return found;
854
- last = dir.href;
855
- if (dir.href === root.href || dir.href === stopAtDir.href) break;
856
- dir = new URL("..", dir);
857
- }
858
- return void 0;
859
- }
860
- function makePredicate(fs5, name, entryType) {
861
- if (typeof name === "function") return name;
862
- const checkStat = entryType === "file" || entryType === "!file" ? "isFile" : "isDirectory";
863
- const checkValue = entryType.startsWith("!") ? false : true;
864
- function checkName(dir, name2) {
865
- const f = new URL(name2, dir);
866
- return fs5.stat(f).then((stats) => (stats.isUnknown() || stats[checkStat]() === checkValue) && f || void 0).catch(() => void 0);
867
- }
868
- if (!Array.isArray(name)) return (dir) => checkName(dir, name);
869
- return async (dir) => {
870
- const pending = name.map((n) => checkName(dir, n));
871
- for (const p of pending) {
872
- const found = await p;
873
- if (found) return found;
874
- }
875
- return void 0;
876
- };
877
+ const { type: entryType = "file", stopAt, fs: fs$1 } = options;
878
+ let dir = new URL(".", from);
879
+ const root = new URL("/", dir);
880
+ const predicate = makePredicate(fs$1, name, entryType);
881
+ const stopAtHrefs = new Set((Array.isArray(stopAt) ? stopAt : [stopAt || root]).map((p) => new URL(".", p).href));
882
+ let last = "";
883
+ while (dir.href !== last) {
884
+ const found = await predicate(dir);
885
+ if (found !== void 0) return found;
886
+ last = dir.href;
887
+ if (dir.href === root.href || stopAtHrefs.has(dir.href)) break;
888
+ dir = new URL("..", dir);
889
+ }
890
+ return void 0;
891
+ }
892
+ function makePredicate(fs$1, name, entryType) {
893
+ if (typeof name === "function") return name;
894
+ const checkStat = entryType === "file" || entryType === "!file" ? "isFile" : "isDirectory";
895
+ const checkValue = entryType.startsWith("!") ? false : true;
896
+ function checkName(dir, name$1) {
897
+ const f = new URL(name$1, dir);
898
+ return fs$1.stat(f).then((stats) => (stats.isUnknown() || stats[checkStat]() === checkValue) && f || void 0).catch(() => void 0);
899
+ }
900
+ if (!Array.isArray(name)) return (dir) => checkName(dir, name);
901
+ return async (dir) => {
902
+ const pending = name.map((n) => checkName(dir, n));
903
+ for (const p of pending) {
904
+ const found = await p;
905
+ if (found) return found;
906
+ }
907
+ return void 0;
908
+ };
877
909
  }
878
910
 
879
- // src/VirtualFS/CVFileSystem.ts
911
+ //#endregion
912
+ //#region src/VirtualFS/CVFileSystem.ts
880
913
  var CVFileSystem = class {
881
- #core;
882
- readFile;
883
- writeFile;
884
- stat;
885
- readDirectory;
886
- getCapabilities;
887
- constructor(core) {
888
- this.#core = core;
889
- this.readFile = this.#core.readFile.bind(this.#core);
890
- this.writeFile = this.#core.writeFile.bind(this.#core);
891
- this.stat = this.#core.stat.bind(this.#core);
892
- this.readDirectory = this.#core.readDirectory.bind(this.#core);
893
- this.getCapabilities = this.#core.getCapabilities.bind(this.#core);
894
- }
895
- get providerInfo() {
896
- return this.#core.providerInfo;
897
- }
898
- get hasProvider() {
899
- return this.#core.hasProvider;
900
- }
901
- findUp(name, from, options = {}) {
902
- const opts = { ...options, fs: this.#core };
903
- return findUpFromUrl(name, from, opts);
904
- }
914
+ #core;
915
+ readFile;
916
+ writeFile;
917
+ stat;
918
+ readDirectory;
919
+ getCapabilities;
920
+ constructor(core) {
921
+ this.#core = core;
922
+ this.readFile = this.#core.readFile.bind(this.#core);
923
+ this.writeFile = this.#core.writeFile.bind(this.#core);
924
+ this.stat = this.#core.stat.bind(this.#core);
925
+ this.readDirectory = this.#core.readDirectory.bind(this.#core);
926
+ this.getCapabilities = this.#core.getCapabilities.bind(this.#core);
927
+ }
928
+ get providerInfo() {
929
+ return this.#core.providerInfo;
930
+ }
931
+ get hasProvider() {
932
+ return this.#core.hasProvider;
933
+ }
934
+ findUp(name, from, options = {}) {
935
+ const opts = {
936
+ ...options,
937
+ fs: this.#core
938
+ };
939
+ return findUpFromUrl(name, from, opts);
940
+ }
905
941
  };
906
942
 
907
- // src/VFileSystem.ts
908
- var FSCapabilityFlags = /* @__PURE__ */ ((FSCapabilityFlags2) => {
909
- FSCapabilityFlags2[FSCapabilityFlags2["None"] = 0] = "None";
910
- FSCapabilityFlags2[FSCapabilityFlags2["Stat"] = 1] = "Stat";
911
- FSCapabilityFlags2[FSCapabilityFlags2["Read"] = 2] = "Read";
912
- FSCapabilityFlags2[FSCapabilityFlags2["Write"] = 4] = "Write";
913
- FSCapabilityFlags2[FSCapabilityFlags2["ReadWrite"] = 6] = "ReadWrite";
914
- FSCapabilityFlags2[FSCapabilityFlags2["ReadDir"] = 8] = "ReadDir";
915
- FSCapabilityFlags2[FSCapabilityFlags2["WriteDir"] = 16] = "WriteDir";
916
- FSCapabilityFlags2[FSCapabilityFlags2["ReadWriteDir"] = 24] = "ReadWriteDir";
917
- return FSCapabilityFlags2;
918
- })(FSCapabilityFlags || {});
943
+ //#endregion
944
+ //#region src/VFileSystem.ts
945
+ let FSCapabilityFlags = /* @__PURE__ */ function(FSCapabilityFlags$1) {
946
+ FSCapabilityFlags$1[FSCapabilityFlags$1["None"] = 0] = "None";
947
+ FSCapabilityFlags$1[FSCapabilityFlags$1["Stat"] = 1] = "Stat";
948
+ FSCapabilityFlags$1[FSCapabilityFlags$1["Read"] = 2] = "Read";
949
+ FSCapabilityFlags$1[FSCapabilityFlags$1["Write"] = 4] = "Write";
950
+ FSCapabilityFlags$1[FSCapabilityFlags$1["ReadWrite"] = 6] = "ReadWrite";
951
+ FSCapabilityFlags$1[FSCapabilityFlags$1["ReadDir"] = 8] = "ReadDir";
952
+ FSCapabilityFlags$1[FSCapabilityFlags$1["WriteDir"] = 16] = "WriteDir";
953
+ FSCapabilityFlags$1[FSCapabilityFlags$1["ReadWriteDir"] = 24] = "ReadWriteDir";
954
+ return FSCapabilityFlags$1;
955
+ }({});
919
956
 
920
- // src/VirtualFS/WrappedProviderFs.ts
957
+ //#endregion
958
+ //#region src/VirtualFS/WrappedProviderFs.ts
921
959
  function cspellIOToFsProvider(cspellIO) {
922
- const capabilities = 1 /* Stat */ | 6 /* ReadWrite */ | 8 /* ReadDir */;
923
- const capabilitiesHttp = capabilities & ~4 /* Write */ & ~8 /* ReadDir */;
924
- const capMap = {
925
- "file:": capabilities,
926
- "http:": capabilitiesHttp,
927
- "https:": capabilitiesHttp
928
- };
929
- const name = "CSpellIO";
930
- const supportedProtocols = /* @__PURE__ */ new Set(["file:", "http:", "https:"]);
931
- const fs5 = {
932
- providerInfo: { name },
933
- stat: (url) => cspellIO.getStat(url),
934
- readFile: (url, options) => cspellIO.readFile(url, options),
935
- readDirectory: (url) => cspellIO.readDirectory(url),
936
- writeFile: (file) => cspellIO.writeFile(file.url, file.content),
937
- dispose: () => void 0,
938
- capabilities,
939
- getCapabilities(url) {
940
- return fsCapabilities(capMap[url.protocol] || 0 /* None */);
941
- }
942
- };
943
- return {
944
- name,
945
- getFileSystem: (url, _next) => {
946
- return supportedProtocols.has(url.protocol) ? fs5 : void 0;
947
- }
948
- };
960
+ const capabilities = FSCapabilityFlags.Stat | FSCapabilityFlags.ReadWrite | FSCapabilityFlags.ReadDir;
961
+ const capabilitiesHttp = capabilities & ~FSCapabilityFlags.Write & ~FSCapabilityFlags.ReadDir;
962
+ const capMap = {
963
+ "file:": capabilities,
964
+ "http:": capabilitiesHttp,
965
+ "https:": capabilitiesHttp
966
+ };
967
+ const name = "CSpellIO";
968
+ const supportedProtocols = new Set([
969
+ "file:",
970
+ "http:",
971
+ "https:"
972
+ ]);
973
+ const fs$1 = {
974
+ providerInfo: { name },
975
+ stat: (url) => cspellIO.getStat(url),
976
+ readFile: (url, options) => cspellIO.readFile(url, options),
977
+ readDirectory: (url) => cspellIO.readDirectory(url),
978
+ writeFile: (file) => cspellIO.writeFile(file.url, file.content),
979
+ dispose: () => void 0,
980
+ capabilities,
981
+ getCapabilities(url) {
982
+ return fsCapabilities(capMap[url.protocol] || FSCapabilityFlags.None);
983
+ }
984
+ };
985
+ return {
986
+ name,
987
+ getFileSystem: (url, _next) => {
988
+ return supportedProtocols.has(url.protocol) ? fs$1 : void 0;
989
+ }
990
+ };
949
991
  }
950
992
  function wrapError(e) {
951
- if (e instanceof VFSError) return e;
952
- return e;
993
+ if (e instanceof VFSError) return e;
994
+ return e;
953
995
  }
954
996
  var VFSError = class extends Error {
955
- constructor(message, options) {
956
- super(message, options);
957
- }
997
+ constructor(message, options) {
998
+ super(message, options);
999
+ }
958
1000
  };
959
1001
  var VFSErrorUnsupportedRequest = class extends VFSError {
960
- constructor(request, url, parameters) {
961
- super(`Unsupported request: ${request}`);
962
- this.request = request;
963
- this.parameters = parameters;
964
- this.url = url?.toString();
965
- }
966
- url;
1002
+ url;
1003
+ constructor(request, url, parameters) {
1004
+ super(`Unsupported request: ${request}`);
1005
+ this.request = request;
1006
+ this.parameters = parameters;
1007
+ this.url = url?.toString();
1008
+ }
967
1009
  };
968
1010
  var CFsCapabilities = class {
969
- constructor(flags) {
970
- this.flags = flags;
971
- }
972
- get readFile() {
973
- return !!(this.flags & 2 /* Read */);
974
- }
975
- get writeFile() {
976
- return !!(this.flags & 4 /* Write */);
977
- }
978
- get readDirectory() {
979
- return !!(this.flags & 8 /* ReadDir */);
980
- }
981
- get writeDirectory() {
982
- return !!(this.flags & 16 /* WriteDir */);
983
- }
984
- get stat() {
985
- return !!(this.flags & 1 /* Stat */);
986
- }
1011
+ constructor(flags) {
1012
+ this.flags = flags;
1013
+ }
1014
+ get readFile() {
1015
+ return !!(this.flags & FSCapabilityFlags.Read);
1016
+ }
1017
+ get writeFile() {
1018
+ return !!(this.flags & FSCapabilityFlags.Write);
1019
+ }
1020
+ get readDirectory() {
1021
+ return !!(this.flags & FSCapabilityFlags.ReadDir);
1022
+ }
1023
+ get writeDirectory() {
1024
+ return !!(this.flags & FSCapabilityFlags.WriteDir);
1025
+ }
1026
+ get stat() {
1027
+ return !!(this.flags & FSCapabilityFlags.Stat);
1028
+ }
987
1029
  };
988
1030
  function fsCapabilities(flags) {
989
- return new CFsCapabilities(flags);
990
- }
991
- var WrappedProviderFs = class _WrappedProviderFs {
992
- constructor(fs5, eventLogger) {
993
- this.fs = fs5;
994
- this.eventLogger = eventLogger;
995
- this.hasProvider = !!fs5;
996
- this.capabilities = fs5?.capabilities || 0 /* None */;
997
- this._capabilities = fsCapabilities(this.capabilities);
998
- this.providerInfo = fs5?.providerInfo || { name: "unknown" };
999
- }
1000
- hasProvider;
1001
- capabilities;
1002
- providerInfo;
1003
- _capabilities;
1004
- logEvent(method, event, traceID, url, message) {
1005
- this.eventLogger({ method, event, url, traceID, ts: performance.now(), message });
1006
- }
1007
- getCapabilities(url) {
1008
- if (this.fs?.getCapabilities) return this.fs.getCapabilities(url);
1009
- return this._capabilities;
1010
- }
1011
- async stat(urlRef) {
1012
- const traceID = performance.now();
1013
- const url = urlOrReferenceToUrl(urlRef);
1014
- this.logEvent("stat", "start", traceID, url);
1015
- try {
1016
- checkCapabilityOrThrow(this.fs, this.capabilities, 1 /* Stat */, "stat", url);
1017
- return new CVfsStat(await this.fs.stat(urlRef));
1018
- } catch (e) {
1019
- this.logEvent("stat", "error", traceID, url, e instanceof Error ? e.message : "");
1020
- throw wrapError(e);
1021
- } finally {
1022
- this.logEvent("stat", "end", traceID, url);
1023
- }
1024
- }
1025
- async readFile(urlRef, optionsOrEncoding) {
1026
- const traceID = performance.now();
1027
- const url = urlOrReferenceToUrl(urlRef);
1028
- this.logEvent("readFile", "start", traceID, url);
1029
- try {
1030
- checkCapabilityOrThrow(this.fs, this.capabilities, 2 /* Read */, "readFile", url);
1031
- const readOptions = toOptions(optionsOrEncoding);
1032
- return fromFileResource(await this.fs.readFile(urlRef, readOptions), readOptions?.encoding);
1033
- } catch (e) {
1034
- this.logEvent("readFile", "error", traceID, url, e instanceof Error ? e.message : "");
1035
- throw wrapError(e);
1036
- } finally {
1037
- this.logEvent("readFile", "end", traceID, url);
1038
- }
1039
- }
1040
- async readDirectory(url) {
1041
- const traceID = performance.now();
1042
- this.logEvent("readDir", "start", traceID, url);
1043
- try {
1044
- checkCapabilityOrThrow(this.fs, this.capabilities, 8 /* ReadDir */, "readDirectory", url);
1045
- return (await this.fs.readDirectory(url)).map((e) => new CVfsDirEntry(e));
1046
- } catch (e) {
1047
- this.logEvent("readDir", "error", traceID, url, e instanceof Error ? e.message : "");
1048
- throw wrapError(e);
1049
- } finally {
1050
- this.logEvent("readDir", "end", traceID, url);
1051
- }
1052
- }
1053
- async writeFile(file) {
1054
- const traceID = performance.now();
1055
- const url = file.url;
1056
- this.logEvent("writeFile", "start", traceID, url);
1057
- try {
1058
- checkCapabilityOrThrow(this.fs, this.capabilities, 4 /* Write */, "writeFile", file.url);
1059
- return await this.fs.writeFile(file);
1060
- } catch (e) {
1061
- this.logEvent("writeFile", "error", traceID, url, e instanceof Error ? e.message : "");
1062
- throw wrapError(e);
1063
- } finally {
1064
- this.logEvent("writeFile", "end", traceID, url);
1065
- }
1066
- }
1067
- static disposeOf(fs5) {
1068
- fs5 instanceof _WrappedProviderFs && fs5.fs?.dispose();
1069
- }
1031
+ return new CFsCapabilities(flags);
1032
+ }
1033
+ var WrappedProviderFs = class WrappedProviderFs {
1034
+ hasProvider;
1035
+ capabilities;
1036
+ providerInfo;
1037
+ _capabilities;
1038
+ constructor(fs$1, eventLogger) {
1039
+ this.fs = fs$1;
1040
+ this.eventLogger = eventLogger;
1041
+ this.hasProvider = !!fs$1;
1042
+ this.capabilities = fs$1?.capabilities || FSCapabilityFlags.None;
1043
+ this._capabilities = fsCapabilities(this.capabilities);
1044
+ this.providerInfo = fs$1?.providerInfo || { name: "unknown" };
1045
+ }
1046
+ logEvent(method, event, traceID, url, message) {
1047
+ this.eventLogger({
1048
+ method,
1049
+ event,
1050
+ url,
1051
+ traceID,
1052
+ ts: performance.now(),
1053
+ message
1054
+ });
1055
+ }
1056
+ getCapabilities(url) {
1057
+ if (this.fs?.getCapabilities) return this.fs.getCapabilities(url);
1058
+ return this._capabilities;
1059
+ }
1060
+ async stat(urlRef) {
1061
+ const traceID = performance.now();
1062
+ const url = urlOrReferenceToUrl(urlRef);
1063
+ this.logEvent("stat", "start", traceID, url);
1064
+ try {
1065
+ checkCapabilityOrThrow(this.fs, this.capabilities, FSCapabilityFlags.Stat, "stat", url);
1066
+ return new CVfsStat(await this.fs.stat(urlRef));
1067
+ } catch (e) {
1068
+ this.logEvent("stat", "error", traceID, url, e instanceof Error ? e.message : "");
1069
+ throw wrapError(e);
1070
+ } finally {
1071
+ this.logEvent("stat", "end", traceID, url);
1072
+ }
1073
+ }
1074
+ async readFile(urlRef, optionsOrEncoding) {
1075
+ const traceID = performance.now();
1076
+ const url = urlOrReferenceToUrl(urlRef);
1077
+ this.logEvent("readFile", "start", traceID, url);
1078
+ try {
1079
+ checkCapabilityOrThrow(this.fs, this.capabilities, FSCapabilityFlags.Read, "readFile", url);
1080
+ const readOptions = toOptions(optionsOrEncoding);
1081
+ return fromFileResource(await this.fs.readFile(urlRef, readOptions), readOptions?.encoding);
1082
+ } catch (e) {
1083
+ this.logEvent("readFile", "error", traceID, url, e instanceof Error ? e.message : "");
1084
+ throw wrapError(e);
1085
+ } finally {
1086
+ this.logEvent("readFile", "end", traceID, url);
1087
+ }
1088
+ }
1089
+ async readDirectory(url) {
1090
+ const traceID = performance.now();
1091
+ this.logEvent("readDir", "start", traceID, url);
1092
+ try {
1093
+ checkCapabilityOrThrow(this.fs, this.capabilities, FSCapabilityFlags.ReadDir, "readDirectory", url);
1094
+ return (await this.fs.readDirectory(url)).map((e) => new CVfsDirEntry(e));
1095
+ } catch (e) {
1096
+ this.logEvent("readDir", "error", traceID, url, e instanceof Error ? e.message : "");
1097
+ throw wrapError(e);
1098
+ } finally {
1099
+ this.logEvent("readDir", "end", traceID, url);
1100
+ }
1101
+ }
1102
+ async writeFile(file) {
1103
+ const traceID = performance.now();
1104
+ const url = file.url;
1105
+ this.logEvent("writeFile", "start", traceID, url);
1106
+ try {
1107
+ checkCapabilityOrThrow(this.fs, this.capabilities, FSCapabilityFlags.Write, "writeFile", file.url);
1108
+ return await this.fs.writeFile(file);
1109
+ } catch (e) {
1110
+ this.logEvent("writeFile", "error", traceID, url, e instanceof Error ? e.message : "");
1111
+ throw wrapError(e);
1112
+ } finally {
1113
+ this.logEvent("writeFile", "end", traceID, url);
1114
+ }
1115
+ }
1116
+ static disposeOf(fs$1) {
1117
+ fs$1 instanceof WrappedProviderFs && fs$1.fs?.dispose();
1118
+ }
1070
1119
  };
1071
- function checkCapabilityOrThrow(fs5, capabilities, flag, name, url) {
1072
- if (!(capabilities & flag)) {
1073
- throw new VFSErrorUnsupportedRequest(name, url);
1074
- }
1120
+ function checkCapabilityOrThrow(fs$1, capabilities, flag, name, url) {
1121
+ if (!(capabilities & flag)) throw new VFSErrorUnsupportedRequest(name, url);
1075
1122
  }
1076
1123
  var CFileType = class {
1077
- constructor(fileType) {
1078
- this.fileType = fileType;
1079
- }
1080
- isFile() {
1081
- return this.fileType === 1 /* File */;
1082
- }
1083
- isDirectory() {
1084
- return this.fileType === 2 /* Directory */;
1085
- }
1086
- isUnknown() {
1087
- return !this.fileType;
1088
- }
1089
- isSymbolicLink() {
1090
- return !!(this.fileType & 64 /* SymbolicLink */);
1091
- }
1124
+ constructor(fileType) {
1125
+ this.fileType = fileType;
1126
+ }
1127
+ isFile() {
1128
+ return this.fileType === FileType.File;
1129
+ }
1130
+ isDirectory() {
1131
+ return this.fileType === FileType.Directory;
1132
+ }
1133
+ isUnknown() {
1134
+ return !this.fileType;
1135
+ }
1136
+ isSymbolicLink() {
1137
+ return !!(this.fileType & FileType.SymbolicLink);
1138
+ }
1092
1139
  };
1093
1140
  var CVfsStat = class extends CFileType {
1094
- constructor(stat) {
1095
- super(stat.fileType || 0 /* Unknown */);
1096
- this.stat = stat;
1097
- }
1098
- get size() {
1099
- return this.stat.size;
1100
- }
1101
- get mtimeMs() {
1102
- return this.stat.mtimeMs;
1103
- }
1104
- get eTag() {
1105
- return this.stat.eTag;
1106
- }
1141
+ constructor(stat) {
1142
+ super(stat.fileType || FileType.Unknown);
1143
+ this.stat = stat;
1144
+ }
1145
+ get size() {
1146
+ return this.stat.size;
1147
+ }
1148
+ get mtimeMs() {
1149
+ return this.stat.mtimeMs;
1150
+ }
1151
+ get eTag() {
1152
+ return this.stat.eTag;
1153
+ }
1107
1154
  };
1108
1155
  var CVfsDirEntry = class extends CFileType {
1109
- constructor(entry) {
1110
- super(entry.fileType);
1111
- this.entry = entry;
1112
- }
1113
- _url;
1114
- get name() {
1115
- return this.entry.name;
1116
- }
1117
- get dir() {
1118
- return this.entry.dir;
1119
- }
1120
- get url() {
1121
- if (this._url) return this._url;
1122
- this._url = new URL(this.entry.name, this.entry.dir);
1123
- return this._url;
1124
- }
1125
- toJSON() {
1126
- return {
1127
- name: this.name,
1128
- dir: this.dir,
1129
- fileType: this.fileType
1130
- };
1131
- }
1156
+ _url;
1157
+ constructor(entry) {
1158
+ super(entry.fileType);
1159
+ this.entry = entry;
1160
+ }
1161
+ get name() {
1162
+ return this.entry.name;
1163
+ }
1164
+ get dir() {
1165
+ return this.entry.dir;
1166
+ }
1167
+ get url() {
1168
+ if (this._url) return this._url;
1169
+ this._url = new URL(this.entry.name, this.entry.dir);
1170
+ return this._url;
1171
+ }
1172
+ toJSON() {
1173
+ return {
1174
+ name: this.name,
1175
+ dir: this.dir,
1176
+ fileType: this.fileType
1177
+ };
1178
+ }
1132
1179
  };
1133
1180
  function chopUrl(url) {
1134
- if (!url) return "";
1135
- const href = url.href;
1136
- const parts = href.split("/");
1137
- const n = parts.indexOf("node_modules");
1138
- if (n > 0) {
1139
- const tail = parts.slice(Math.max(parts.length - 3, n + 1));
1140
- return parts.slice(0, n + 1).join("/") + "/\u2026/" + tail.join("/");
1141
- }
1142
- return href;
1181
+ if (!url) return "";
1182
+ const href = url.href;
1183
+ const parts = href.split("/");
1184
+ const n = parts.indexOf("node_modules");
1185
+ if (n > 0) {
1186
+ const tail = parts.slice(Math.max(parts.length - 3, n + 1));
1187
+ return parts.slice(0, n + 1).join("/") + "/…/" + tail.join("/");
1188
+ }
1189
+ return href;
1143
1190
  }
1144
1191
  function rPad(str, len, ch = " ") {
1145
- return str.padEnd(len, ch);
1192
+ return str.padEnd(len, ch);
1146
1193
  }
1147
1194
  function toOptions(val) {
1148
- return typeof val === "string" ? { encoding: val } : val;
1195
+ return typeof val === "string" ? { encoding: val } : val;
1149
1196
  }
1150
1197
 
1151
- // src/CVirtualFS.ts
1198
+ //#endregion
1199
+ //#region src/CVirtualFS.ts
1152
1200
  var CVirtualFS = class {
1153
- providers = /* @__PURE__ */ new Set();
1154
- cachedFs = /* @__PURE__ */ new Map();
1155
- revCacheFs = /* @__PURE__ */ new Map();
1156
- fsc;
1157
- fs;
1158
- loggingEnabled = debug;
1159
- constructor() {
1160
- this.fsc = fsPassThroughCore((url) => this._getFS(url));
1161
- this.fs = new CVFileSystem(this.fsc);
1162
- }
1163
- enableLogging(value) {
1164
- this.loggingEnabled = value ?? true;
1165
- }
1166
- log = console.log;
1167
- logEvent = (event) => {
1168
- if (this.loggingEnabled) {
1169
- const id = event.traceID.toFixed(13).replaceAll(/\d{4}(?=\d)/g, "$&.");
1170
- const msg = event.message ? `
1171
- ${event.message}` : "";
1172
- const method = rPad(`${event.method}-${event.event}`, 16);
1173
- this.log(`${method} ID:${id} ts:${event.ts.toFixed(13)} ${chopUrl(event.url)}${msg}`);
1174
- }
1175
- };
1176
- registerFileSystemProvider(...providers) {
1177
- providers.forEach((provider) => this.providers.add(provider));
1178
- this.reset();
1179
- return {
1180
- dispose: () => {
1181
- for (const provider of providers) {
1182
- for (const key of this.revCacheFs.get(provider) || []) {
1183
- this.cachedFs.delete(key);
1184
- }
1185
- this.providers.delete(provider) && void 0;
1186
- }
1187
- this.reset();
1188
- }
1189
- };
1190
- }
1191
- getFS(url) {
1192
- return new CVFileSystem(this._getFS(url));
1193
- }
1194
- _getFS(url) {
1195
- const key = `${url.protocol}${url.hostname}`;
1196
- const cached = this.cachedFs.get(key);
1197
- if (cached) {
1198
- return cached;
1199
- }
1200
- const fnNext = (provider, next2) => {
1201
- return (url2) => {
1202
- let calledNext = false;
1203
- const fs6 = provider.getFileSystem(url2, (_url) => {
1204
- calledNext = calledNext || url2 === _url;
1205
- return next2(_url);
1206
- });
1207
- if (fs6) {
1208
- const s = this.revCacheFs.get(provider) || /* @__PURE__ */ new Set();
1209
- s.add(key);
1210
- this.revCacheFs.set(provider, s);
1211
- return fs6;
1212
- }
1213
- if (!calledNext) {
1214
- return next2(url2);
1215
- }
1216
- return void 0;
1217
- };
1218
- };
1219
- let next = (_url) => void 0;
1220
- for (const provider of this.providers) {
1221
- next = fnNext(provider, next);
1222
- }
1223
- const fs5 = new WrappedProviderFs(next(url), this.logEvent);
1224
- this.cachedFs.set(key, fs5);
1225
- return fs5;
1226
- }
1227
- reset() {
1228
- this.disposeOfCachedFs();
1229
- }
1230
- disposeOfCachedFs() {
1231
- for (const [key, fs5] of [...this.cachedFs].reverse()) {
1232
- try {
1233
- WrappedProviderFs.disposeOf(fs5);
1234
- } catch {
1235
- }
1236
- this.cachedFs.delete(key);
1237
- }
1238
- this.cachedFs.clear();
1239
- this.revCacheFs.clear();
1240
- }
1241
- dispose() {
1242
- this.disposeOfCachedFs();
1243
- const providers = [...this.providers].reverse();
1244
- for (const provider of providers) {
1245
- try {
1246
- provider.dispose?.();
1247
- } catch {
1248
- }
1249
- }
1250
- }
1201
+ providers = /* @__PURE__ */ new Set();
1202
+ cachedFs = /* @__PURE__ */ new Map();
1203
+ revCacheFs = /* @__PURE__ */ new Map();
1204
+ fsc;
1205
+ fs;
1206
+ loggingEnabled = debug;
1207
+ constructor() {
1208
+ this.fsc = fsPassThroughCore((url) => this._getFS(url));
1209
+ this.fs = new CVFileSystem(this.fsc);
1210
+ }
1211
+ enableLogging(value) {
1212
+ this.loggingEnabled = value ?? true;
1213
+ }
1214
+ log = console.log;
1215
+ logEvent = (event) => {
1216
+ if (this.loggingEnabled) {
1217
+ const id = event.traceID.toFixed(13).replaceAll(/\d{4}(?=\d)/g, "$&.");
1218
+ const msg = event.message ? `\n\t\t${event.message}` : "";
1219
+ const method = rPad(`${event.method}-${event.event}`, 16);
1220
+ this.log(`${method} ID:${id} ts:${event.ts.toFixed(13)} ${chopUrl(event.url)}${msg}`);
1221
+ }
1222
+ };
1223
+ registerFileSystemProvider(...providers) {
1224
+ providers.forEach((provider) => this.providers.add(provider));
1225
+ this.reset();
1226
+ return { dispose: () => {
1227
+ for (const provider of providers) {
1228
+ for (const key of this.revCacheFs.get(provider) || []) this.cachedFs.delete(key);
1229
+ this.providers.delete(provider);
1230
+ }
1231
+ this.reset();
1232
+ } };
1233
+ }
1234
+ getFS(url) {
1235
+ return new CVFileSystem(this._getFS(url));
1236
+ }
1237
+ _getFS(url) {
1238
+ const key = `${url.protocol}${url.hostname}`;
1239
+ const cached = this.cachedFs.get(key);
1240
+ if (cached) return cached;
1241
+ const fnNext = (provider, next$1) => {
1242
+ return (url$1) => {
1243
+ let calledNext = false;
1244
+ const fs$2 = provider.getFileSystem(url$1, (_url) => {
1245
+ calledNext = calledNext || url$1 === _url;
1246
+ return next$1(_url);
1247
+ });
1248
+ if (fs$2) {
1249
+ const s = this.revCacheFs.get(provider) || /* @__PURE__ */ new Set();
1250
+ s.add(key);
1251
+ this.revCacheFs.set(provider, s);
1252
+ return fs$2;
1253
+ }
1254
+ if (!calledNext) return next$1(url$1);
1255
+ return void 0;
1256
+ };
1257
+ };
1258
+ let next = (_url) => void 0;
1259
+ for (const provider of this.providers) next = fnNext(provider, next);
1260
+ const fs$1 = new WrappedProviderFs(next(url), this.logEvent);
1261
+ this.cachedFs.set(key, fs$1);
1262
+ return fs$1;
1263
+ }
1264
+ reset() {
1265
+ this.disposeOfCachedFs();
1266
+ }
1267
+ disposeOfCachedFs() {
1268
+ for (const [key, fs$1] of [...this.cachedFs].reverse()) {
1269
+ try {
1270
+ WrappedProviderFs.disposeOf(fs$1);
1271
+ } catch {}
1272
+ this.cachedFs.delete(key);
1273
+ }
1274
+ this.cachedFs.clear();
1275
+ this.revCacheFs.clear();
1276
+ }
1277
+ dispose() {
1278
+ this.disposeOfCachedFs();
1279
+ const providers = [...this.providers].reverse();
1280
+ for (const provider of providers) try {
1281
+ provider.dispose?.();
1282
+ } catch {}
1283
+ }
1251
1284
  };
1252
- function fsPassThroughCore(fs5) {
1253
- function gfs(ur, name) {
1254
- const url = urlOrReferenceToUrl(ur);
1255
- const f = fs5(url);
1256
- if (!f.hasProvider)
1257
- throw new VFSErrorUnsupportedRequest(
1258
- name,
1259
- url,
1260
- ur instanceof URL ? void 0 : { url: ur.url.toString(), encoding: ur.encoding }
1261
- );
1262
- return f;
1263
- }
1264
- return {
1265
- providerInfo: { name: "default" },
1266
- hasProvider: true,
1267
- stat: async (url) => gfs(url, "stat").stat(url),
1268
- readFile: async (url, options) => gfs(url, "readFile").readFile(url, options),
1269
- writeFile: async (file) => gfs(file, "writeFile").writeFile(file),
1270
- readDirectory: async (url) => gfs(url, "readDirectory").readDirectory(url).then((entries) => entries.map((e) => new CVfsDirEntry(e))),
1271
- getCapabilities: (url) => gfs(url, "getCapabilities").getCapabilities(url)
1272
- };
1285
+ function fsPassThroughCore(fs$1) {
1286
+ function gfs(ur, name) {
1287
+ const url = urlOrReferenceToUrl(ur);
1288
+ const f = fs$1(url);
1289
+ if (!f.hasProvider) throw new VFSErrorUnsupportedRequest(name, url, ur instanceof URL ? void 0 : {
1290
+ url: ur.url.toString(),
1291
+ encoding: ur.encoding
1292
+ });
1293
+ return f;
1294
+ }
1295
+ return {
1296
+ providerInfo: { name: "default" },
1297
+ hasProvider: true,
1298
+ stat: async (url) => gfs(url, "stat").stat(url),
1299
+ readFile: async (url, options) => gfs(url, "readFile").readFile(url, options),
1300
+ writeFile: async (file) => gfs(file, "writeFile").writeFile(file),
1301
+ readDirectory: async (url) => gfs(url, "readDirectory").readDirectory(url).then((entries) => entries.map((e) => new CVfsDirEntry(e))),
1302
+ getCapabilities: (url) => gfs(url, "getCapabilities").getCapabilities(url)
1303
+ };
1273
1304
  }
1274
1305
  function createVirtualFS(cspellIO) {
1275
- const cspell = cspellIO || getDefaultCSpellIO();
1276
- const vfs = new CVirtualFS();
1277
- vfs.registerFileSystemProvider(cspellIOToFsProvider(cspell));
1278
- return vfs;
1306
+ const cspell = cspellIO || getDefaultCSpellIO();
1307
+ const vfs = new CVirtualFS();
1308
+ vfs.registerFileSystemProvider(cspellIOToFsProvider(cspell));
1309
+ return vfs;
1279
1310
  }
1280
- var defaultVirtualFs = void 0;
1311
+ let defaultVirtualFs = void 0;
1281
1312
  function getDefaultVirtualFs() {
1282
- if (!defaultVirtualFs) {
1283
- defaultVirtualFs = createVirtualFS();
1284
- }
1285
- return defaultVirtualFs;
1313
+ if (!defaultVirtualFs) defaultVirtualFs = createVirtualFS();
1314
+ return defaultVirtualFs;
1286
1315
  }
1287
1316
 
1288
- // src/node/file/fileWriter.ts
1289
- import * as fs4 from "fs";
1290
- import * as Stream from "stream";
1291
- import { promisify as promisify2 } from "util";
1292
- import * as zlib from "zlib";
1293
-
1294
- // src/common/transformers.ts
1317
+ //#endregion
1318
+ //#region src/common/transformers.ts
1295
1319
  function encoderTransformer(iterable, encoding) {
1296
- return isAsyncIterable(iterable) ? encoderAsyncIterable(iterable, encoding) : encoderIterable(iterable, encoding);
1320
+ return isAsyncIterable(iterable) ? encoderAsyncIterable(iterable, encoding) : encoderIterable(iterable, encoding);
1297
1321
  }
1298
1322
  function* encoderIterable(iterable, encoding) {
1299
- let useBom = true;
1300
- for (const chunk of iterable) {
1301
- yield encodeString(chunk, encoding, useBom);
1302
- useBom = false;
1303
- }
1323
+ let useBom = true;
1324
+ for (const chunk of iterable) {
1325
+ yield encodeString(chunk, encoding, useBom);
1326
+ useBom = false;
1327
+ }
1304
1328
  }
1305
1329
  async function* encoderAsyncIterable(iterable, encoding) {
1306
- let useBom = true;
1307
- for await (const chunk of iterable) {
1308
- yield encodeString(chunk, encoding, useBom);
1309
- useBom = false;
1310
- }
1330
+ let useBom = true;
1331
+ for await (const chunk of iterable) {
1332
+ yield encodeString(chunk, encoding, useBom);
1333
+ useBom = false;
1334
+ }
1311
1335
  }
1312
1336
  function isAsyncIterable(v) {
1313
- return v && typeof v === "object" && !!v[Symbol.asyncIterator];
1337
+ return v && typeof v === "object" && !!v[Symbol.asyncIterator];
1314
1338
  }
1315
1339
 
1316
- // src/node/file/fileWriter.ts
1317
- var pipeline2 = promisify2(Stream.pipeline);
1340
+ //#endregion
1341
+ //#region src/node/file/fileWriter.ts
1342
+ const pipeline = promisify(Stream.pipeline);
1318
1343
  function writeToFile(filename, data, encoding) {
1319
- return writeToFileIterable(filename, typeof data === "string" ? [data] : data, encoding);
1344
+ return writeToFileIterable(filename, typeof data === "string" ? [data] : data, encoding);
1320
1345
  }
1321
1346
  function writeToFileIterable(filename, data, encoding) {
1322
- const stream = Stream.Readable.from(encoderTransformer(data, encoding));
1323
- const zip = /\.gz$/.test(filename) ? zlib.createGzip() : new Stream.PassThrough();
1324
- return pipeline2(stream, zip, fs4.createWriteStream(filename));
1347
+ const stream = Stream.Readable.from(encoderTransformer(data, encoding));
1348
+ const zip = /\.gz$/.test(filename) ? zlib.createGzip() : new Stream.PassThrough();
1349
+ return pipeline(stream, zip, fs.createWriteStream(filename));
1325
1350
  }
1326
1351
 
1327
- // src/file/file.ts
1352
+ //#endregion
1353
+ //#region src/file/file.ts
1328
1354
  async function readFileText(filename, encoding) {
1329
- const fr = await getDefaultCSpellIO().readFile(filename, encoding);
1330
- return fr.getText();
1355
+ const fr = await getDefaultCSpellIO().readFile(filename, encoding);
1356
+ return fr.getText();
1331
1357
  }
1332
1358
  function readFileTextSync(filename, encoding) {
1333
- return getDefaultCSpellIO().readFileSync(filename, encoding).getText();
1359
+ return getDefaultCSpellIO().readFileSync(filename, encoding).getText();
1334
1360
  }
1335
1361
  async function getStat(filenameOrUri) {
1336
- try {
1337
- return await getDefaultCSpellIO().getStat(filenameOrUri);
1338
- } catch (e) {
1339
- return toError(e);
1340
- }
1362
+ try {
1363
+ return await getDefaultCSpellIO().getStat(filenameOrUri);
1364
+ } catch (e) {
1365
+ return toError(e);
1366
+ }
1341
1367
  }
1342
1368
  function getStatSync(filenameOrUri) {
1343
- try {
1344
- return getDefaultCSpellIO().getStatSync(filenameOrUri);
1345
- } catch (e) {
1346
- return toError(e);
1347
- }
1369
+ try {
1370
+ return getDefaultCSpellIO().getStatSync(filenameOrUri);
1371
+ } catch (e) {
1372
+ return toError(e);
1373
+ }
1348
1374
  }
1349
1375
 
1350
- // src/VirtualFS/redirectProvider.ts
1351
- import assert2 from "assert";
1376
+ //#endregion
1377
+ //#region src/VirtualFS/redirectProvider.ts
1352
1378
  var RedirectProvider = class {
1353
- constructor(name, publicRoot, privateRoot, options = { capabilitiesMask: -1 }) {
1354
- this.name = name;
1355
- this.publicRoot = publicRoot;
1356
- this.privateRoot = privateRoot;
1357
- this.options = options;
1358
- }
1359
- getFileSystem(url, next) {
1360
- if (url.protocol !== this.publicRoot.protocol || url.host !== this.publicRoot.host) {
1361
- return void 0;
1362
- }
1363
- const privateFs = next(this.privateRoot);
1364
- if (!privateFs) {
1365
- return void 0;
1366
- }
1367
- const shadowFS = next(url);
1368
- return remapFS(this.name, privateFs, shadowFS, this.publicRoot, this.privateRoot, this.options);
1369
- }
1379
+ constructor(name, publicRoot, privateRoot, options = { capabilitiesMask: -1 }) {
1380
+ this.name = name;
1381
+ this.publicRoot = publicRoot;
1382
+ this.privateRoot = privateRoot;
1383
+ this.options = options;
1384
+ }
1385
+ getFileSystem(url, next) {
1386
+ if (url.protocol !== this.publicRoot.protocol || url.host !== this.publicRoot.host) return void 0;
1387
+ const privateFs = next(this.privateRoot);
1388
+ if (!privateFs) return void 0;
1389
+ const shadowFS = next(url);
1390
+ return remapFS(this.name, privateFs, shadowFS, this.publicRoot, this.privateRoot, this.options);
1391
+ }
1370
1392
  };
1393
+ /**
1394
+ * Create a provider that will redirect requests from the publicRoot to the privateRoot.
1395
+ * This is useful for creating a virtual file system that is a subset of another file system.
1396
+ *
1397
+ * Example:
1398
+ * ```ts
1399
+ * const vfs = createVirtualFS();
1400
+ * const provider = createRedirectProvider('test', new URL('file:///public/'), new URL('file:///private/'))
1401
+ * vfs.registerFileSystemProvider(provider);
1402
+ * // Read the content of `file:///private/file.txt`
1403
+ * const file = vfs.fs.readFile(new URL('file:///public/file.txt');
1404
+ * ```
1405
+ *
1406
+ * @param name - name of the provider
1407
+ * @param publicRoot - the root of the public file system.
1408
+ * @param privateRoot - the root of the private file system.
1409
+ * @param options - options for the provider.
1410
+ * @returns FileSystemProvider
1411
+ */
1371
1412
  function createRedirectProvider(name, publicRoot, privateRoot, options) {
1372
- assert2(publicRoot.pathname.endsWith("/"), "publicRoot must end with a slash");
1373
- assert2(privateRoot.pathname.endsWith("/"), "privateRoot must end with a slash");
1374
- return new RedirectProvider(name, publicRoot, privateRoot, options);
1375
- }
1376
- function remapFS(name, fs5, shadowFs, publicRoot, privateRoot, options) {
1377
- const { capabilitiesMask = -1, capabilities } = options;
1378
- function mapToPrivate(url) {
1379
- const relativePath = url.pathname.slice(publicRoot.pathname.length);
1380
- return new URL(relativePath, privateRoot);
1381
- }
1382
- function mapToPublic(url) {
1383
- const relativePath = url.pathname.slice(privateRoot.pathname.length);
1384
- return new URL(relativePath, publicRoot);
1385
- }
1386
- const mapFileReferenceToPrivate = (ref) => {
1387
- return renameFileReference(ref, mapToPrivate(ref.url));
1388
- };
1389
- const mapFileReferenceToPublic = (ref) => {
1390
- return renameFileReference(ref, mapToPublic(ref.url));
1391
- };
1392
- const mapUrlOrReferenceToPrivate = (urlOrRef) => {
1393
- return urlOrRef instanceof URL ? mapToPrivate(urlOrRef) : mapFileReferenceToPrivate(urlOrRef);
1394
- };
1395
- const mapFileResourceToPublic = (res) => {
1396
- return renameFileResource(res, mapToPublic(res.url));
1397
- };
1398
- const mapFileResourceToPrivate = (res) => {
1399
- return renameFileResource(res, mapToPrivate(res.url));
1400
- };
1401
- const mapDirEntryToPublic = (de) => {
1402
- const dir = mapToPublic(de.dir);
1403
- return { ...de, dir };
1404
- };
1405
- const fs22 = {
1406
- stat: async (url) => {
1407
- const url2 = mapUrlOrReferenceToPrivate(url);
1408
- const stat = await fs5.stat(url2);
1409
- return stat;
1410
- },
1411
- readFile: async (url, options2) => {
1412
- const url2 = mapUrlOrReferenceToPrivate(url);
1413
- const file = await fs5.readFile(url2, options2);
1414
- return mapFileResourceToPublic(file);
1415
- },
1416
- readDirectory: async (url) => {
1417
- const url2 = mapToPrivate(url);
1418
- const dir = await fs5.readDirectory(url2);
1419
- return dir.map(mapDirEntryToPublic);
1420
- },
1421
- writeFile: async (file) => {
1422
- const fileRef2 = mapFileResourceToPrivate(file);
1423
- const fileRef3 = await fs5.writeFile(fileRef2);
1424
- return mapFileReferenceToPublic(fileRef3);
1425
- },
1426
- providerInfo: { ...fs5.providerInfo, name },
1427
- capabilities: capabilities ?? fs5.capabilities & capabilitiesMask,
1428
- dispose: () => fs5.dispose()
1429
- };
1430
- return fsPassThrough(fs22, shadowFs, publicRoot);
1431
- }
1432
- function fsPassThrough(fs5, shadowFs, root) {
1433
- function gfs(ur, name) {
1434
- const url = urlOrReferenceToUrl(ur);
1435
- const f = url.href.startsWith(root.href) ? fs5 : shadowFs;
1436
- if (!f)
1437
- throw new VFSErrorUnsupportedRequest(
1438
- name,
1439
- url,
1440
- ur instanceof URL ? void 0 : { url: ur.url.toString(), encoding: ur.encoding }
1441
- );
1442
- return f;
1443
- }
1444
- const passThroughFs = {
1445
- get providerInfo() {
1446
- return fs5.providerInfo;
1447
- },
1448
- get capabilities() {
1449
- return fs5.capabilities;
1450
- },
1451
- stat: async (url) => gfs(url, "stat").stat(url),
1452
- readFile: async (url) => gfs(url, "readFile").readFile(url),
1453
- writeFile: async (file) => gfs(file, "writeFile").writeFile(file),
1454
- readDirectory: async (url) => gfs(url, "readDirectory").readDirectory(url),
1455
- getCapabilities(url) {
1456
- const f = gfs(url, "getCapabilities");
1457
- return f.getCapabilities ? f.getCapabilities(url) : fsCapabilities(f.capabilities);
1458
- },
1459
- dispose: () => {
1460
- fs5.dispose();
1461
- shadowFs?.dispose();
1462
- }
1463
- };
1464
- return passThroughFs;
1465
- }
1466
- export {
1467
- CFileReference,
1468
- CFileResource,
1469
- CSpellIONode,
1470
- FSCapabilityFlags,
1471
- FileType as VFileType,
1472
- toArray as asyncIterableToArray,
1473
- compareStats,
1474
- createRedirectProvider,
1475
- fromFileResource as createTextFileResource,
1476
- createVirtualFS,
1477
- encodeDataUrl,
1478
- getDefaultCSpellIO,
1479
- getDefaultVirtualFs,
1480
- getStat,
1481
- getStatSync,
1482
- isFileURL,
1483
- isUrlLike,
1484
- readFileText,
1485
- readFileTextSync,
1486
- renameFileReference,
1487
- renameFileResource,
1488
- toDataUrl,
1489
- toFileURL,
1490
- toURL,
1491
- urlBasename,
1492
- urlParent as urlDirname,
1493
- urlOrReferenceToUrl,
1494
- writeToFile,
1495
- writeToFileIterable,
1496
- writeToFileIterable as writeToFileIterableP
1497
- };
1413
+ assert(publicRoot.pathname.endsWith("/"), "publicRoot must end with a slash");
1414
+ assert(privateRoot.pathname.endsWith("/"), "privateRoot must end with a slash");
1415
+ return new RedirectProvider(name, publicRoot, privateRoot, options);
1416
+ }
1417
+ /**
1418
+ * Create a Remapped file system that will redirect requests from the publicRoot to the privateRoot.
1419
+ * Requests that do not match the publicRoot will be passed to the shadowFs.
1420
+ * @param name - name of the provider
1421
+ * @param fs - the private file system
1422
+ * @param shadowFs - the file system that is obscured by the redirect.
1423
+ * @param publicRoot - the root of the public file system.
1424
+ * @param privateRoot - the root of the private file system.
1425
+ * @returns ProviderFileSystem
1426
+ */
1427
+ function remapFS(name, fs$1, shadowFs, publicRoot, privateRoot, options) {
1428
+ const { capabilitiesMask = -1, capabilities } = options;
1429
+ function mapToPrivate(url) {
1430
+ const relativePath = url.pathname.slice(publicRoot.pathname.length);
1431
+ return new URL(relativePath, privateRoot);
1432
+ }
1433
+ function mapToPublic(url) {
1434
+ const relativePath = url.pathname.slice(privateRoot.pathname.length);
1435
+ return new URL(relativePath, publicRoot);
1436
+ }
1437
+ const mapFileReferenceToPrivate = (ref) => {
1438
+ return renameFileReference(ref, mapToPrivate(ref.url));
1439
+ };
1440
+ const mapFileReferenceToPublic = (ref) => {
1441
+ return renameFileReference(ref, mapToPublic(ref.url));
1442
+ };
1443
+ const mapUrlOrReferenceToPrivate = (urlOrRef) => {
1444
+ return urlOrRef instanceof URL ? mapToPrivate(urlOrRef) : mapFileReferenceToPrivate(urlOrRef);
1445
+ };
1446
+ const mapFileResourceToPublic = (res) => {
1447
+ return renameFileResource(res, mapToPublic(res.url));
1448
+ };
1449
+ const mapFileResourceToPrivate = (res) => {
1450
+ return renameFileResource(res, mapToPrivate(res.url));
1451
+ };
1452
+ const mapDirEntryToPublic = (de) => {
1453
+ const dir = mapToPublic(de.dir);
1454
+ return {
1455
+ ...de,
1456
+ dir
1457
+ };
1458
+ };
1459
+ const fs2 = {
1460
+ stat: async (url) => {
1461
+ const url2 = mapUrlOrReferenceToPrivate(url);
1462
+ const stat = await fs$1.stat(url2);
1463
+ return stat;
1464
+ },
1465
+ readFile: async (url, options$1) => {
1466
+ const url2 = mapUrlOrReferenceToPrivate(url);
1467
+ const file = await fs$1.readFile(url2, options$1);
1468
+ return mapFileResourceToPublic(file);
1469
+ },
1470
+ readDirectory: async (url) => {
1471
+ const url2 = mapToPrivate(url);
1472
+ const dir = await fs$1.readDirectory(url2);
1473
+ return dir.map(mapDirEntryToPublic);
1474
+ },
1475
+ writeFile: async (file) => {
1476
+ const fileRef2 = mapFileResourceToPrivate(file);
1477
+ const fileRef3 = await fs$1.writeFile(fileRef2);
1478
+ return mapFileReferenceToPublic(fileRef3);
1479
+ },
1480
+ providerInfo: {
1481
+ ...fs$1.providerInfo,
1482
+ name
1483
+ },
1484
+ capabilities: capabilities ?? fs$1.capabilities & capabilitiesMask,
1485
+ dispose: () => fs$1.dispose()
1486
+ };
1487
+ return fsPassThrough(fs2, shadowFs, publicRoot);
1488
+ }
1489
+ function fsPassThrough(fs$1, shadowFs, root) {
1490
+ function gfs(ur, name) {
1491
+ const url = urlOrReferenceToUrl(ur);
1492
+ const f = url.href.startsWith(root.href) ? fs$1 : shadowFs;
1493
+ if (!f) throw new VFSErrorUnsupportedRequest(name, url, ur instanceof URL ? void 0 : {
1494
+ url: ur.url.toString(),
1495
+ encoding: ur.encoding
1496
+ });
1497
+ return f;
1498
+ }
1499
+ const passThroughFs = {
1500
+ get providerInfo() {
1501
+ return fs$1.providerInfo;
1502
+ },
1503
+ get capabilities() {
1504
+ return fs$1.capabilities;
1505
+ },
1506
+ stat: async (url) => gfs(url, "stat").stat(url),
1507
+ readFile: async (url) => gfs(url, "readFile").readFile(url),
1508
+ writeFile: async (file) => gfs(file, "writeFile").writeFile(file),
1509
+ readDirectory: async (url) => gfs(url, "readDirectory").readDirectory(url),
1510
+ getCapabilities(url) {
1511
+ const f = gfs(url, "getCapabilities");
1512
+ return f.getCapabilities ? f.getCapabilities(url) : fsCapabilities(f.capabilities);
1513
+ },
1514
+ dispose: () => {
1515
+ fs$1.dispose();
1516
+ shadowFs?.dispose();
1517
+ }
1518
+ };
1519
+ return passThroughFs;
1520
+ }
1521
+
1522
+ //#endregion
1523
+ export { CFileReference, CFileResource, CSpellIONode, FSCapabilityFlags, FileType as VFileType, toArray as asyncIterableToArray, compareStats, createRedirectProvider, fromFileResource as createTextFileResource, createVirtualFS, encodeDataUrl, getDefaultCSpellIO, getDefaultVirtualFs, getStat, getStatSync, isFileURL, isUrlLike, readFileText, readFileTextSync, renameFileReference, renameFileResource, toDataUrl, toFileURL, toURL, urlBasename, urlDirname, urlOrReferenceToUrl, writeToFile, writeToFileIterable, writeToFileIterable as writeToFileIterableP };
1498
1524
  //# sourceMappingURL=index.js.map