cspell-io 9.6.4 → 9.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +47 -43
- package/dist/index.js +292 -199
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -171,7 +171,8 @@ interface DirEntry {
|
|
|
171
171
|
declare function compareStats(left: Stats, right: Stats): number;
|
|
172
172
|
//#endregion
|
|
173
173
|
//#region src/models/disposable.d.ts
|
|
174
|
-
|
|
174
|
+
type DisposableEx = LegacyDisposable & Disposable;
|
|
175
|
+
interface LegacyDisposable {
|
|
175
176
|
dispose(): void;
|
|
176
177
|
}
|
|
177
178
|
//#endregion
|
|
@@ -291,7 +292,41 @@ declare class CSpellIONode implements CSpellIO {
|
|
|
291
292
|
}
|
|
292
293
|
declare function getDefaultCSpellIO(): CSpellIO;
|
|
293
294
|
//#endregion
|
|
294
|
-
//#region src/
|
|
295
|
+
//#region src/common/BufferEncoding.d.ts
|
|
296
|
+
type TextEncodingExtra = "utf-16be" | "utf-16le" | "utf16be" | "utf16le";
|
|
297
|
+
type BufferEncodingExt = BufferEncoding | TextEncodingExtra;
|
|
298
|
+
//#endregion
|
|
299
|
+
//#region src/node/file/fileWriter.d.ts
|
|
300
|
+
declare function writeToFile(filename: string, data: string | Iterable<string> | AsyncIterable<string>, encoding?: BufferEncoding): Promise<void>;
|
|
301
|
+
declare function writeToFileIterable(filename: string, data: Iterable<string> | AsyncIterable<string>, encoding?: BufferEncodingExt): Promise<void>;
|
|
302
|
+
//#endregion
|
|
303
|
+
//#region src/file/file.d.ts
|
|
304
|
+
declare function readFileText(filename: string | URL, encoding?: BufferEncoding): Promise<string>;
|
|
305
|
+
declare function readFileTextSync(filename: string | URL, encoding?: BufferEncoding): string;
|
|
306
|
+
declare function getStat(filenameOrUri: string): Promise<Stats | Error>;
|
|
307
|
+
declare function getStatSync(filenameOrUri: string): Stats | Error;
|
|
308
|
+
//#endregion
|
|
309
|
+
//#region src/types.d.ts
|
|
310
|
+
type TArrayBufferView<T extends ArrayBuffer = ArrayBuffer> = ArrayBufferView<T>;
|
|
311
|
+
//#endregion
|
|
312
|
+
//#region src/node/dataUrl.d.ts
|
|
313
|
+
/**
|
|
314
|
+
* Generates a string of the following format:
|
|
315
|
+
*
|
|
316
|
+
* `data:[mediaType][;charset=<encoding>[;base64],<data>`
|
|
317
|
+
*
|
|
318
|
+
* - `encoding` - defaults to `utf8` for text data
|
|
319
|
+
* @param data
|
|
320
|
+
* @param mediaType - The mediaType is a [MIME](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types) type string
|
|
321
|
+
* @param attributes - Additional attributes
|
|
322
|
+
*/
|
|
323
|
+
declare function encodeDataUrl(data: string | TArrayBufferView | Uint8Array<ArrayBuffer>, mediaType: string, attributes?: Iterable<readonly [string, string]> | undefined): string;
|
|
324
|
+
declare function toDataUrl(data: string | TArrayBufferView, mediaType: string, attributes?: Iterable<[string, string]> | undefined): URL;
|
|
325
|
+
//#endregion
|
|
326
|
+
//#region src/VirtualFS/constants.d.ts
|
|
327
|
+
declare const CSPELL_VFS_PROTOCOL: "cspell-vfs:";
|
|
328
|
+
//#endregion
|
|
329
|
+
//#region src/VirtualFS/VFileSystem.d.ts
|
|
295
330
|
type UrlOrReference = URL | FileReference;
|
|
296
331
|
declare enum FSCapabilityFlags {
|
|
297
332
|
None = 0,
|
|
@@ -346,12 +381,12 @@ interface VFileSystemCore {
|
|
|
346
381
|
* The capabilities can be more restrictive than the general capabilities of the provider.
|
|
347
382
|
* @param url - the url to try
|
|
348
383
|
*/
|
|
349
|
-
getCapabilities(url: URL): FSCapabilities
|
|
384
|
+
getCapabilities(url: URL): Readonly<FSCapabilities>;
|
|
350
385
|
/**
|
|
351
386
|
* Information about the provider.
|
|
352
387
|
* It is up to the provider to define what information is available.
|
|
353
388
|
*/
|
|
354
|
-
providerInfo: FileSystemProviderInfo
|
|
389
|
+
providerInfo: Readonly<FileSystemProviderInfo>;
|
|
355
390
|
/**
|
|
356
391
|
* Indicates that a provider was found for the url.
|
|
357
392
|
*/
|
|
@@ -387,10 +422,10 @@ interface VFindUpURLOptions {
|
|
|
387
422
|
}
|
|
388
423
|
type VFindUpPredicate = (dir: URL) => URL | undefined | Promise<URL | undefined>;
|
|
389
424
|
//#endregion
|
|
390
|
-
//#region src/VirtualFS.d.ts
|
|
425
|
+
//#region src/VirtualFS/VirtualFS.d.ts
|
|
391
426
|
type NextProvider = (url: URL) => VProviderFileSystem | undefined;
|
|
392
|
-
interface VirtualFS extends
|
|
393
|
-
registerFileSystemProvider(provider: VFileSystemProvider, ...providers: VFileSystemProvider[]):
|
|
427
|
+
interface VirtualFS extends DisposableEx {
|
|
428
|
+
registerFileSystemProvider(provider: VFileSystemProvider, ...providers: VFileSystemProvider[]): DisposableEx;
|
|
394
429
|
/**
|
|
395
430
|
* Get the fs for a given url.
|
|
396
431
|
*/
|
|
@@ -417,7 +452,7 @@ interface OptionAbort {
|
|
|
417
452
|
signal?: AbortSignal;
|
|
418
453
|
}
|
|
419
454
|
type VProviderFileSystemReadFileOptions = OptionAbort;
|
|
420
|
-
interface VProviderFileSystem extends
|
|
455
|
+
interface VProviderFileSystem extends DisposableEx {
|
|
421
456
|
readFile(url: UrlOrReference, options?: VProviderFileSystemReadFileOptions): Promise<FileResource>;
|
|
422
457
|
writeFile(file: FileResource): Promise<FileReference>;
|
|
423
458
|
/**
|
|
@@ -433,14 +468,14 @@ interface VProviderFileSystem extends Disposable {
|
|
|
433
468
|
*/
|
|
434
469
|
capabilities: FSCapabilityFlags;
|
|
435
470
|
/**
|
|
436
|
-
* Get the capabilities for a URL.
|
|
471
|
+
* Get the capabilities for a URL. Makes it possible for a provider to support more capabilities for a given url.
|
|
437
472
|
* These capabilities should be more restrictive than the general capabilities.
|
|
438
473
|
* @param url - the url to try
|
|
439
474
|
* @returns the capabilities for the url.
|
|
440
475
|
*/
|
|
441
476
|
getCapabilities?: (url: URL) => FSCapabilities;
|
|
442
477
|
}
|
|
443
|
-
interface VFileSystemProvider extends Partial<
|
|
478
|
+
interface VFileSystemProvider extends Partial<DisposableEx> {
|
|
444
479
|
/** Name of the Provider */
|
|
445
480
|
name: string;
|
|
446
481
|
/**
|
|
@@ -451,41 +486,10 @@ interface VFileSystemProvider extends Partial<Disposable> {
|
|
|
451
486
|
getFileSystem(url: URL, next: NextProvider): VProviderFileSystem | undefined;
|
|
452
487
|
}
|
|
453
488
|
//#endregion
|
|
454
|
-
//#region src/CVirtualFS.d.ts
|
|
489
|
+
//#region src/VirtualFS/CVirtualFS.d.ts
|
|
455
490
|
declare function createVirtualFS(cspellIO?: CSpellIO): VirtualFS;
|
|
456
491
|
declare function getDefaultVirtualFs(): VirtualFS;
|
|
457
492
|
//#endregion
|
|
458
|
-
//#region src/common/BufferEncoding.d.ts
|
|
459
|
-
type TextEncodingExtra = "utf-16be" | "utf-16le" | "utf16be" | "utf16le";
|
|
460
|
-
type BufferEncodingExt = BufferEncoding | TextEncodingExtra;
|
|
461
|
-
//#endregion
|
|
462
|
-
//#region src/node/file/fileWriter.d.ts
|
|
463
|
-
declare function writeToFile(filename: string, data: string | Iterable<string> | AsyncIterable<string>, encoding?: BufferEncoding): Promise<void>;
|
|
464
|
-
declare function writeToFileIterable(filename: string, data: Iterable<string> | AsyncIterable<string>, encoding?: BufferEncodingExt): Promise<void>;
|
|
465
|
-
//#endregion
|
|
466
|
-
//#region src/file/file.d.ts
|
|
467
|
-
declare function readFileText(filename: string | URL, encoding?: BufferEncoding): Promise<string>;
|
|
468
|
-
declare function readFileTextSync(filename: string | URL, encoding?: BufferEncoding): string;
|
|
469
|
-
declare function getStat(filenameOrUri: string): Promise<Stats | Error>;
|
|
470
|
-
declare function getStatSync(filenameOrUri: string): Stats | Error;
|
|
471
|
-
//#endregion
|
|
472
|
-
//#region src/types.d.ts
|
|
473
|
-
type TArrayBufferView<T extends ArrayBuffer = ArrayBuffer> = ArrayBufferView<T>;
|
|
474
|
-
//#endregion
|
|
475
|
-
//#region src/node/dataUrl.d.ts
|
|
476
|
-
/**
|
|
477
|
-
* Generates a string of the following format:
|
|
478
|
-
*
|
|
479
|
-
* `data:[mediaType][;charset=<encoding>[;base64],<data>`
|
|
480
|
-
*
|
|
481
|
-
* - `encoding` - defaults to `utf8` for text data
|
|
482
|
-
* @param data
|
|
483
|
-
* @param mediaType - The mediaType is a [MIME](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types) type string
|
|
484
|
-
* @param attributes - Additional attributes
|
|
485
|
-
*/
|
|
486
|
-
declare function encodeDataUrl(data: string | TArrayBufferView | Uint8Array<ArrayBuffer>, mediaType: string, attributes?: Iterable<readonly [string, string]> | undefined): string;
|
|
487
|
-
declare function toDataUrl(data: string | TArrayBufferView, mediaType: string, attributes?: Iterable<[string, string]> | undefined): URL;
|
|
488
|
-
//#endregion
|
|
489
493
|
//#region src/VirtualFS/redirectProvider.d.ts
|
|
490
494
|
interface RedirectOptions {
|
|
491
495
|
/**
|
|
@@ -516,5 +520,5 @@ interface RedirectOptions {
|
|
|
516
520
|
*/
|
|
517
521
|
declare function createRedirectProvider(name: string, publicRoot: URL, privateRoot: URL, options?: RedirectOptions): VFileSystemProvider;
|
|
518
522
|
//#endregion
|
|
519
|
-
export { type BufferEncoding, CFileReference, CFileResource, type CSpellIO, CSpellIONode, FSCapabilityFlags, type FileReference, type FileResource, type Stats, type TextEncoding, type TextFileResource, type VFileSystem, type VFileSystemCore, type VFileSystemProvider, FileType as VFileType, type VFindEntryType, type VFindUpPredicate, type VFindUpURLOptions, type VProviderFileSystem, type VfsDirEntry, type VfsStat, type VirtualFS, 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 };
|
|
523
|
+
export { type BufferEncoding, CFileReference, CFileResource, CSPELL_VFS_PROTOCOL, type CSpellIO, CSpellIONode, FSCapabilityFlags, type FileReference, type FileResource, type Stats, type TextEncoding, type TextFileResource, type VFileSystem, type VFileSystemCore, type VFileSystemProvider, FileType as VFileType, type VFindEntryType, type VFindUpPredicate, type VFindUpURLOptions, type VProviderFileSystem, type VfsDirEntry, type VfsStat, type VirtualFS, 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 };
|
|
520
524
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,6 @@ import { fileURLToPath } from "node:url";
|
|
|
9
9
|
import { promisify } from "node:util";
|
|
10
10
|
import * as Stream from "node:stream";
|
|
11
11
|
import assert from "node:assert";
|
|
12
|
-
|
|
13
12
|
//#region src/async/asyncIterable.ts
|
|
14
13
|
/**
|
|
15
14
|
* Reads an entire iterable and converts it into a promise.
|
|
@@ -20,7 +19,6 @@ async function toArray(asyncIterable) {
|
|
|
20
19
|
for await (const item of asyncIterable) data.push(item);
|
|
21
20
|
return data;
|
|
22
21
|
}
|
|
23
|
-
|
|
24
22
|
//#endregion
|
|
25
23
|
//#region src/common/CFileReference.ts
|
|
26
24
|
var CFileReference = class CFileReference {
|
|
@@ -85,7 +83,6 @@ function toFileResourceRequest(file, encoding, signal) {
|
|
|
85
83
|
signal
|
|
86
84
|
};
|
|
87
85
|
}
|
|
88
|
-
|
|
89
86
|
//#endregion
|
|
90
87
|
//#region src/errors/errors.ts
|
|
91
88
|
var ErrorNotImplemented = class extends Error {
|
|
@@ -100,13 +97,11 @@ var AssertionError = class extends Error {
|
|
|
100
97
|
this.message = message;
|
|
101
98
|
}
|
|
102
99
|
};
|
|
103
|
-
|
|
104
100
|
//#endregion
|
|
105
101
|
//#region src/errors/assert.ts
|
|
106
102
|
function assert$1(value, message) {
|
|
107
103
|
if (!value) throw new AssertionError(message ?? "Assertion failed");
|
|
108
104
|
}
|
|
109
|
-
|
|
110
105
|
//#endregion
|
|
111
106
|
//#region src/common/arrayBuffers.ts
|
|
112
107
|
function toUint8Array(data) {
|
|
@@ -127,7 +122,6 @@ function swap16(data) {
|
|
|
127
122
|
function swapBytes(data) {
|
|
128
123
|
return swap16(copyArrayBufferView(data));
|
|
129
124
|
}
|
|
130
|
-
|
|
131
125
|
//#endregion
|
|
132
126
|
//#region src/common/encode-decode.ts
|
|
133
127
|
const BOM_BE = 65279;
|
|
@@ -243,7 +237,6 @@ async function decompress(data, method = "gzip") {
|
|
|
243
237
|
}
|
|
244
238
|
return result;
|
|
245
239
|
}
|
|
246
|
-
|
|
247
240
|
//#endregion
|
|
248
241
|
//#region src/common/CFileResource.ts
|
|
249
242
|
var CFileResource = class CFileResource {
|
|
@@ -330,7 +323,6 @@ function renameFileResource(fileResource, url) {
|
|
|
330
323
|
url
|
|
331
324
|
});
|
|
332
325
|
}
|
|
333
|
-
|
|
334
326
|
//#endregion
|
|
335
327
|
//#region src/common/stat.ts
|
|
336
328
|
/**
|
|
@@ -345,13 +337,11 @@ function compareStats(left, right) {
|
|
|
345
337
|
const diff = left.size - right.size || left.mtimeMs - right.mtimeMs;
|
|
346
338
|
return diff < 0 ? -1 : diff > 0 ? 1 : 0;
|
|
347
339
|
}
|
|
348
|
-
|
|
349
340
|
//#endregion
|
|
350
341
|
//#region src/common/urlOrReferenceToUrl.ts
|
|
351
342
|
function urlOrReferenceToUrl(urlOrReference) {
|
|
352
343
|
return urlOrReference instanceof URL ? urlOrReference : urlOrReference.url;
|
|
353
344
|
}
|
|
354
|
-
|
|
355
345
|
//#endregion
|
|
356
346
|
//#region src/CSpellIO.ts
|
|
357
347
|
function toReadFileOptions(options) {
|
|
@@ -359,7 +349,6 @@ function toReadFileOptions(options) {
|
|
|
359
349
|
if (typeof options === "string") return { encoding: options };
|
|
360
350
|
return options;
|
|
361
351
|
}
|
|
362
|
-
|
|
363
352
|
//#endregion
|
|
364
353
|
//#region src/errors/error.ts
|
|
365
354
|
function toError$1(e) {
|
|
@@ -367,7 +356,6 @@ function toError$1(e) {
|
|
|
367
356
|
if (typeof e === "object" && e && "message" in e && typeof e.message === "string") return new Error(e.message, { cause: e });
|
|
368
357
|
return new Error(e && e.toString());
|
|
369
358
|
}
|
|
370
|
-
|
|
371
359
|
//#endregion
|
|
372
360
|
//#region src/models/Stats.ts
|
|
373
361
|
let FileType = /* @__PURE__ */ function(FileType) {
|
|
@@ -389,7 +377,6 @@ let FileType = /* @__PURE__ */ function(FileType) {
|
|
|
389
377
|
FileType[FileType["SymbolicLink"] = 64] = "SymbolicLink";
|
|
390
378
|
return FileType;
|
|
391
379
|
}({});
|
|
392
|
-
|
|
393
380
|
//#endregion
|
|
394
381
|
//#region src/node/dataUrl.ts
|
|
395
382
|
/**
|
|
@@ -463,12 +450,10 @@ function guessMimeType(filename) {
|
|
|
463
450
|
encoding: "utf-8"
|
|
464
451
|
};
|
|
465
452
|
}
|
|
466
|
-
|
|
467
453
|
//#endregion
|
|
468
454
|
//#region src/node/file/_fetch.ts
|
|
469
455
|
/** alias of global.fetch, useful for mocking */
|
|
470
456
|
const _fetch = globalThis.fetch;
|
|
471
|
-
|
|
472
457
|
//#endregion
|
|
473
458
|
//#region src/node/file/FetchError.ts
|
|
474
459
|
var FetchUrlError = class FetchUrlError extends Error {
|
|
@@ -511,7 +496,6 @@ function toFetchUrlError(err, url) {
|
|
|
511
496
|
function toError(err) {
|
|
512
497
|
return err instanceof Error ? err : new Error("Unknown Error", { cause: err });
|
|
513
498
|
}
|
|
514
|
-
|
|
515
499
|
//#endregion
|
|
516
500
|
//#region src/node/file/fetch.ts
|
|
517
501
|
async function fetchHead(request) {
|
|
@@ -536,7 +520,6 @@ async function fetchURL(url, signal) {
|
|
|
536
520
|
function toURL$1(url) {
|
|
537
521
|
return typeof url === "string" ? new URL(url) : url;
|
|
538
522
|
}
|
|
539
|
-
|
|
540
523
|
//#endregion
|
|
541
524
|
//#region src/node/file/stat.ts
|
|
542
525
|
async function getStatHttp(url) {
|
|
@@ -549,39 +532,13 @@ async function getStatHttp(url) {
|
|
|
549
532
|
eTag
|
|
550
533
|
};
|
|
551
534
|
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
const
|
|
556
|
-
const
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
//#region src/requests/RequestFsReadFileSync.ts
|
|
560
|
-
const RequestType$3 = "fs:readFileSync";
|
|
561
|
-
const RequestFsReadFileTextSync = requestFactory(RequestType$3);
|
|
562
|
-
|
|
563
|
-
//#endregion
|
|
564
|
-
//#region src/requests/RequestFsStat.ts
|
|
565
|
-
const RequestTypeStat = "fs:stat";
|
|
566
|
-
const RequestFsStat = requestFactory(RequestTypeStat);
|
|
567
|
-
const RequestTypeStatSync = "fs:statSync";
|
|
568
|
-
const RequestFsStatSync = requestFactory(RequestTypeStatSync);
|
|
569
|
-
|
|
570
|
-
//#endregion
|
|
571
|
-
//#region src/requests/RequestFsWriteFile.ts
|
|
572
|
-
const RequestType$2 = "fs:writeFile";
|
|
573
|
-
const RequestFsWriteFile = requestFactory(RequestType$2);
|
|
574
|
-
|
|
575
|
-
//#endregion
|
|
576
|
-
//#region src/requests/RequestZlibInflate.ts
|
|
577
|
-
const RequestType$1 = "zlib:inflate";
|
|
578
|
-
const RequestZlibInflate = requestFactory(RequestType$1);
|
|
579
|
-
|
|
580
|
-
//#endregion
|
|
581
|
-
//#region src/requests/RequestFsReadDirectory.ts
|
|
582
|
-
const RequestType = "fs:readDir";
|
|
583
|
-
const RequestFsReadDirectory = requestFactory(RequestType);
|
|
584
|
-
|
|
535
|
+
const RequestFsReadFile = requestFactory("fs:readFile");
|
|
536
|
+
const RequestFsReadFileTextSync = requestFactory("fs:readFileSync");
|
|
537
|
+
const RequestFsStat = requestFactory("fs:stat");
|
|
538
|
+
const RequestFsStatSync = requestFactory("fs:statSync");
|
|
539
|
+
const RequestFsWriteFile = requestFactory("fs:writeFile");
|
|
540
|
+
const RequestZlibInflate = requestFactory("zlib:inflate");
|
|
541
|
+
const RequestFsReadDirectory = requestFactory("fs:readDir");
|
|
585
542
|
//#endregion
|
|
586
543
|
//#region src/handlers/node/file.ts
|
|
587
544
|
const isGzFileRegExp = /\.gz($|[?#])/;
|
|
@@ -784,7 +741,6 @@ function toFileType(statLike) {
|
|
|
784
741
|
const t = statLike.isFile() ? FileType.File : statLike.isDirectory() ? FileType.Directory : FileType.Unknown;
|
|
785
742
|
return statLike.isSymbolicLink() ? t | FileType.SymbolicLink : t;
|
|
786
743
|
}
|
|
787
|
-
|
|
788
744
|
//#endregion
|
|
789
745
|
//#region src/CSpellIONode.ts
|
|
790
746
|
let defaultCSpellIONode = void 0;
|
|
@@ -858,11 +814,62 @@ function getDefaultCSpellIO() {
|
|
|
858
814
|
defaultCSpellIONode = cspellIO;
|
|
859
815
|
return cspellIO;
|
|
860
816
|
}
|
|
861
|
-
|
|
862
817
|
//#endregion
|
|
863
|
-
//#region src/
|
|
864
|
-
|
|
865
|
-
|
|
818
|
+
//#region src/common/transformers.ts
|
|
819
|
+
function encoderTransformer(iterable, encoding) {
|
|
820
|
+
return isAsyncIterable(iterable) ? encoderAsyncIterable(iterable, encoding) : encoderIterable(iterable, encoding);
|
|
821
|
+
}
|
|
822
|
+
function* encoderIterable(iterable, encoding) {
|
|
823
|
+
let useBom = true;
|
|
824
|
+
for (const chunk of iterable) {
|
|
825
|
+
yield encodeString$1(chunk, encoding, useBom);
|
|
826
|
+
useBom = false;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
async function* encoderAsyncIterable(iterable, encoding) {
|
|
830
|
+
let useBom = true;
|
|
831
|
+
for await (const chunk of iterable) {
|
|
832
|
+
yield encodeString$1(chunk, encoding, useBom);
|
|
833
|
+
useBom = false;
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
function isAsyncIterable(v) {
|
|
837
|
+
return v && typeof v === "object" && !!v[Symbol.asyncIterator];
|
|
838
|
+
}
|
|
839
|
+
//#endregion
|
|
840
|
+
//#region src/node/file/fileWriter.ts
|
|
841
|
+
const pipeline = promisify(Stream.pipeline);
|
|
842
|
+
function writeToFile(filename, data, encoding) {
|
|
843
|
+
return writeToFileIterable(filename, typeof data === "string" ? [data] : data, encoding);
|
|
844
|
+
}
|
|
845
|
+
function writeToFileIterable(filename, data, encoding) {
|
|
846
|
+
return pipeline(Stream.Readable.from(encoderTransformer(data, encoding)), /\.gz$/.test(filename) ? zlib.createGzip() : new Stream.PassThrough(), fs.createWriteStream(filename));
|
|
847
|
+
}
|
|
848
|
+
//#endregion
|
|
849
|
+
//#region src/file/file.ts
|
|
850
|
+
async function readFileText(filename, encoding) {
|
|
851
|
+
return (await getDefaultCSpellIO().readFile(filename, encoding)).getText();
|
|
852
|
+
}
|
|
853
|
+
function readFileTextSync(filename, encoding) {
|
|
854
|
+
return getDefaultCSpellIO().readFileSync(filename, encoding).getText();
|
|
855
|
+
}
|
|
856
|
+
async function getStat(filenameOrUri) {
|
|
857
|
+
try {
|
|
858
|
+
return await getDefaultCSpellIO().getStat(filenameOrUri);
|
|
859
|
+
} catch (e) {
|
|
860
|
+
return toError$1(e);
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
function getStatSync(filenameOrUri) {
|
|
864
|
+
try {
|
|
865
|
+
return getDefaultCSpellIO().getStatSync(filenameOrUri);
|
|
866
|
+
} catch (e) {
|
|
867
|
+
return toError$1(e);
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
//#endregion
|
|
871
|
+
//#region src/VirtualFS/constants.ts
|
|
872
|
+
const CSPELL_VFS_PROTOCOL = "cspell-vfs:";
|
|
866
873
|
//#endregion
|
|
867
874
|
//#region src/VirtualFS/findUpFromUrl.ts
|
|
868
875
|
async function findUpFromUrl(name, from, options) {
|
|
@@ -897,7 +904,6 @@ function makePredicate(fs, name, entryType) {
|
|
|
897
904
|
}
|
|
898
905
|
};
|
|
899
906
|
}
|
|
900
|
-
|
|
901
907
|
//#endregion
|
|
902
908
|
//#region src/VirtualFS/CVFileSystem.ts
|
|
903
909
|
var CVFileSystem = class {
|
|
@@ -928,9 +934,41 @@ var CVFileSystem = class {
|
|
|
928
934
|
});
|
|
929
935
|
}
|
|
930
936
|
};
|
|
931
|
-
|
|
932
937
|
//#endregion
|
|
933
|
-
//#region src/
|
|
938
|
+
//#region src/VirtualFS/errors.ts
|
|
939
|
+
var VFSError = class extends Error {
|
|
940
|
+
url;
|
|
941
|
+
code;
|
|
942
|
+
constructor(message, options) {
|
|
943
|
+
super(message, { cause: options?.cause });
|
|
944
|
+
this.name = "VFSError";
|
|
945
|
+
this.url = options?.url instanceof URL ? options.url.href : options?.url;
|
|
946
|
+
this.code = options?.code;
|
|
947
|
+
}
|
|
948
|
+
};
|
|
949
|
+
var VFSNotSupported = class extends VFSError {
|
|
950
|
+
constructor(methodName, url) {
|
|
951
|
+
super(`Method ${methodName} is not supported for ${url.href}`, { url });
|
|
952
|
+
}
|
|
953
|
+
};
|
|
954
|
+
var VFSNotFoundError = class extends VFSError {
|
|
955
|
+
constructor(url, options) {
|
|
956
|
+
super(`Not found: ${url.href}`, {
|
|
957
|
+
...options,
|
|
958
|
+
url,
|
|
959
|
+
code: options?.code ?? "ENOENT"
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
};
|
|
963
|
+
var VFSErrorUnsupportedRequest = class extends VFSError {
|
|
964
|
+
constructor(request, url, parameters) {
|
|
965
|
+
super(`Unsupported request: ${request}`, { url });
|
|
966
|
+
this.request = request;
|
|
967
|
+
this.parameters = parameters;
|
|
968
|
+
}
|
|
969
|
+
};
|
|
970
|
+
//#endregion
|
|
971
|
+
//#region src/VirtualFS/VFileSystem.ts
|
|
934
972
|
let FSCapabilityFlags = /* @__PURE__ */ function(FSCapabilityFlags) {
|
|
935
973
|
FSCapabilityFlags[FSCapabilityFlags["None"] = 0] = "None";
|
|
936
974
|
FSCapabilityFlags[FSCapabilityFlags["Stat"] = 1] = "Stat";
|
|
@@ -942,7 +980,166 @@ let FSCapabilityFlags = /* @__PURE__ */ function(FSCapabilityFlags) {
|
|
|
942
980
|
FSCapabilityFlags[FSCapabilityFlags["ReadWriteDir"] = 24] = "ReadWriteDir";
|
|
943
981
|
return FSCapabilityFlags;
|
|
944
982
|
}({});
|
|
945
|
-
|
|
983
|
+
//#endregion
|
|
984
|
+
//#region src/VirtualFS/MemVfsProvider.ts
|
|
985
|
+
var MemFileSystemProvider = class {
|
|
986
|
+
name;
|
|
987
|
+
protocol;
|
|
988
|
+
#vfs;
|
|
989
|
+
/**
|
|
990
|
+
* @param name - the name of the provider, used for debugging and logging.
|
|
991
|
+
* @param protocol - the protocol (end with a :), examples: `vfs:`, `cspell-vfs:`
|
|
992
|
+
*/
|
|
993
|
+
constructor(name, protocol) {
|
|
994
|
+
this.name = name;
|
|
995
|
+
this.protocol = protocol;
|
|
996
|
+
this.#vfs = new MemVFileSystem(name, protocol);
|
|
997
|
+
}
|
|
998
|
+
getFileSystem(url) {
|
|
999
|
+
if (url.protocol !== this.protocol) return;
|
|
1000
|
+
return this.#vfs;
|
|
1001
|
+
}
|
|
1002
|
+
get memFS() {
|
|
1003
|
+
return this.#vfs;
|
|
1004
|
+
}
|
|
1005
|
+
dispose() {
|
|
1006
|
+
this.#vfs.dispose();
|
|
1007
|
+
}
|
|
1008
|
+
[Symbol.dispose]() {
|
|
1009
|
+
this.dispose();
|
|
1010
|
+
}
|
|
1011
|
+
};
|
|
1012
|
+
var MemVFileSystem = class {
|
|
1013
|
+
name;
|
|
1014
|
+
protocol;
|
|
1015
|
+
capabilities = FSCapabilityFlags.ReadWrite | FSCapabilityFlags.Stat;
|
|
1016
|
+
#files = /* @__PURE__ */ new Map();
|
|
1017
|
+
constructor(name, protocol) {
|
|
1018
|
+
this.name = name;
|
|
1019
|
+
this.protocol = protocol;
|
|
1020
|
+
this.providerInfo = { name };
|
|
1021
|
+
this.#files = /* @__PURE__ */ new Map();
|
|
1022
|
+
}
|
|
1023
|
+
/**
|
|
1024
|
+
* Read a file.
|
|
1025
|
+
* @param url - URL to read
|
|
1026
|
+
* @param options - options for reading the file.
|
|
1027
|
+
* @returns A FileResource, the content will not be decoded. Use `.getText()` to get the decoded text.
|
|
1028
|
+
*/
|
|
1029
|
+
async readFile(url, _options) {
|
|
1030
|
+
return this.#getEntryOrThrow(url).file;
|
|
1031
|
+
}
|
|
1032
|
+
/**
|
|
1033
|
+
* Write a file
|
|
1034
|
+
* @param file - the file to write
|
|
1035
|
+
*/
|
|
1036
|
+
async writeFile(file) {
|
|
1037
|
+
const stats = {
|
|
1038
|
+
size: file.content.length,
|
|
1039
|
+
mtimeMs: performance.now(),
|
|
1040
|
+
fileType: FileType.File
|
|
1041
|
+
};
|
|
1042
|
+
const u = urlOrReferenceToUrl(file);
|
|
1043
|
+
this.#files.set(u.href, {
|
|
1044
|
+
file,
|
|
1045
|
+
stats
|
|
1046
|
+
});
|
|
1047
|
+
return { url: file.url };
|
|
1048
|
+
}
|
|
1049
|
+
/**
|
|
1050
|
+
* Get the stats for a url.
|
|
1051
|
+
* @param url - Url to fetch stats for.
|
|
1052
|
+
*/
|
|
1053
|
+
stat(url) {
|
|
1054
|
+
return this.#getEntryOrThrow(url).stats;
|
|
1055
|
+
}
|
|
1056
|
+
#getEntryOrThrow(url) {
|
|
1057
|
+
const u = urlOrReferenceToUrl(url);
|
|
1058
|
+
const found = this.#files.get(u.href);
|
|
1059
|
+
if (!found) throw new VFSNotFoundError(u);
|
|
1060
|
+
return found;
|
|
1061
|
+
}
|
|
1062
|
+
/**
|
|
1063
|
+
* Read the directory entries for a url.
|
|
1064
|
+
* The url should end with `/` to indicate a directory.
|
|
1065
|
+
* @param url - the url to read the directory entries for.
|
|
1066
|
+
*/
|
|
1067
|
+
async readDirectory(url) {
|
|
1068
|
+
throw new VFSNotSupported("readDirectory", url);
|
|
1069
|
+
}
|
|
1070
|
+
/**
|
|
1071
|
+
* Information about the provider.
|
|
1072
|
+
* It is up to the provider to define what information is available.
|
|
1073
|
+
*/
|
|
1074
|
+
providerInfo;
|
|
1075
|
+
dispose() {
|
|
1076
|
+
this.#files.clear();
|
|
1077
|
+
}
|
|
1078
|
+
[Symbol.dispose]() {
|
|
1079
|
+
this.dispose();
|
|
1080
|
+
}
|
|
1081
|
+
};
|
|
1082
|
+
//#endregion
|
|
1083
|
+
//#region src/VirtualFS/capabilities.ts
|
|
1084
|
+
var CFsCapabilities = class {
|
|
1085
|
+
constructor(flags) {
|
|
1086
|
+
this.flags = flags;
|
|
1087
|
+
}
|
|
1088
|
+
get readFile() {
|
|
1089
|
+
return !!(this.flags & FSCapabilityFlags.Read);
|
|
1090
|
+
}
|
|
1091
|
+
get writeFile() {
|
|
1092
|
+
return !!(this.flags & FSCapabilityFlags.Write);
|
|
1093
|
+
}
|
|
1094
|
+
get readDirectory() {
|
|
1095
|
+
return !!(this.flags & FSCapabilityFlags.ReadDir);
|
|
1096
|
+
}
|
|
1097
|
+
get writeDirectory() {
|
|
1098
|
+
return !!(this.flags & FSCapabilityFlags.WriteDir);
|
|
1099
|
+
}
|
|
1100
|
+
get stat() {
|
|
1101
|
+
return !!(this.flags & FSCapabilityFlags.Stat);
|
|
1102
|
+
}
|
|
1103
|
+
};
|
|
1104
|
+
function fsCapabilities(flags) {
|
|
1105
|
+
return new CFsCapabilities(flags);
|
|
1106
|
+
}
|
|
1107
|
+
//#endregion
|
|
1108
|
+
//#region src/VirtualFS/CFileType.ts
|
|
1109
|
+
var CFileType = class {
|
|
1110
|
+
constructor(fileType) {
|
|
1111
|
+
this.fileType = fileType;
|
|
1112
|
+
}
|
|
1113
|
+
isFile() {
|
|
1114
|
+
return this.fileType === FileType.File;
|
|
1115
|
+
}
|
|
1116
|
+
isDirectory() {
|
|
1117
|
+
return this.fileType === FileType.Directory;
|
|
1118
|
+
}
|
|
1119
|
+
isUnknown() {
|
|
1120
|
+
return !this.fileType;
|
|
1121
|
+
}
|
|
1122
|
+
isSymbolicLink() {
|
|
1123
|
+
return !!(this.fileType & FileType.SymbolicLink);
|
|
1124
|
+
}
|
|
1125
|
+
};
|
|
1126
|
+
//#endregion
|
|
1127
|
+
//#region src/VirtualFS/CVfsStat.ts
|
|
1128
|
+
var CVfsStat = class extends CFileType {
|
|
1129
|
+
constructor(stat) {
|
|
1130
|
+
super(stat.fileType || FileType.Unknown);
|
|
1131
|
+
this.stat = stat;
|
|
1132
|
+
}
|
|
1133
|
+
get size() {
|
|
1134
|
+
return this.stat.size;
|
|
1135
|
+
}
|
|
1136
|
+
get mtimeMs() {
|
|
1137
|
+
return this.stat.mtimeMs;
|
|
1138
|
+
}
|
|
1139
|
+
get eTag() {
|
|
1140
|
+
return this.stat.eTag;
|
|
1141
|
+
}
|
|
1142
|
+
};
|
|
946
1143
|
//#endregion
|
|
947
1144
|
//#region src/VirtualFS/WrappedProviderFs.ts
|
|
948
1145
|
function cspellIOToFsProvider(cspellIO) {
|
|
@@ -959,17 +1156,19 @@ function cspellIOToFsProvider(cspellIO) {
|
|
|
959
1156
|
"http:",
|
|
960
1157
|
"https:"
|
|
961
1158
|
]);
|
|
1159
|
+
const dispose = () => void 0;
|
|
962
1160
|
const fs = {
|
|
963
1161
|
providerInfo: { name },
|
|
964
1162
|
stat: (url) => cspellIO.getStat(url),
|
|
965
1163
|
readFile: (url, options) => cspellIO.readFile(url, options),
|
|
966
1164
|
readDirectory: (url) => cspellIO.readDirectory(url),
|
|
967
1165
|
writeFile: (file) => cspellIO.writeFile(file.url, file.content),
|
|
968
|
-
dispose
|
|
1166
|
+
dispose,
|
|
969
1167
|
capabilities,
|
|
970
1168
|
getCapabilities(url) {
|
|
971
1169
|
return fsCapabilities(capMap[url.protocol] || FSCapabilityFlags.None);
|
|
972
|
-
}
|
|
1170
|
+
},
|
|
1171
|
+
[Symbol.dispose]: dispose
|
|
973
1172
|
};
|
|
974
1173
|
return {
|
|
975
1174
|
name,
|
|
@@ -982,43 +1181,6 @@ function wrapError(e) {
|
|
|
982
1181
|
if (e instanceof VFSError) return e;
|
|
983
1182
|
return e;
|
|
984
1183
|
}
|
|
985
|
-
var VFSError = class extends Error {
|
|
986
|
-
constructor(message, options) {
|
|
987
|
-
super(message, options);
|
|
988
|
-
}
|
|
989
|
-
};
|
|
990
|
-
var VFSErrorUnsupportedRequest = class extends VFSError {
|
|
991
|
-
url;
|
|
992
|
-
constructor(request, url, parameters) {
|
|
993
|
-
super(`Unsupported request: ${request}`);
|
|
994
|
-
this.request = request;
|
|
995
|
-
this.parameters = parameters;
|
|
996
|
-
this.url = url?.toString();
|
|
997
|
-
}
|
|
998
|
-
};
|
|
999
|
-
var CFsCapabilities = class {
|
|
1000
|
-
constructor(flags) {
|
|
1001
|
-
this.flags = flags;
|
|
1002
|
-
}
|
|
1003
|
-
get readFile() {
|
|
1004
|
-
return !!(this.flags & FSCapabilityFlags.Read);
|
|
1005
|
-
}
|
|
1006
|
-
get writeFile() {
|
|
1007
|
-
return !!(this.flags & FSCapabilityFlags.Write);
|
|
1008
|
-
}
|
|
1009
|
-
get readDirectory() {
|
|
1010
|
-
return !!(this.flags & FSCapabilityFlags.ReadDir);
|
|
1011
|
-
}
|
|
1012
|
-
get writeDirectory() {
|
|
1013
|
-
return !!(this.flags & FSCapabilityFlags.WriteDir);
|
|
1014
|
-
}
|
|
1015
|
-
get stat() {
|
|
1016
|
-
return !!(this.flags & FSCapabilityFlags.Stat);
|
|
1017
|
-
}
|
|
1018
|
-
};
|
|
1019
|
-
function fsCapabilities(flags) {
|
|
1020
|
-
return new CFsCapabilities(flags);
|
|
1021
|
-
}
|
|
1022
1184
|
var WrappedProviderFs = class WrappedProviderFs {
|
|
1023
1185
|
hasProvider;
|
|
1024
1186
|
capabilities;
|
|
@@ -1109,38 +1271,6 @@ var WrappedProviderFs = class WrappedProviderFs {
|
|
|
1109
1271
|
function checkCapabilityOrThrow(fs, capabilities, flag, name, url) {
|
|
1110
1272
|
if (!(capabilities & flag)) throw new VFSErrorUnsupportedRequest(name, url);
|
|
1111
1273
|
}
|
|
1112
|
-
var CFileType = class {
|
|
1113
|
-
constructor(fileType) {
|
|
1114
|
-
this.fileType = fileType;
|
|
1115
|
-
}
|
|
1116
|
-
isFile() {
|
|
1117
|
-
return this.fileType === FileType.File;
|
|
1118
|
-
}
|
|
1119
|
-
isDirectory() {
|
|
1120
|
-
return this.fileType === FileType.Directory;
|
|
1121
|
-
}
|
|
1122
|
-
isUnknown() {
|
|
1123
|
-
return !this.fileType;
|
|
1124
|
-
}
|
|
1125
|
-
isSymbolicLink() {
|
|
1126
|
-
return !!(this.fileType & FileType.SymbolicLink);
|
|
1127
|
-
}
|
|
1128
|
-
};
|
|
1129
|
-
var CVfsStat = class extends CFileType {
|
|
1130
|
-
constructor(stat) {
|
|
1131
|
-
super(stat.fileType || FileType.Unknown);
|
|
1132
|
-
this.stat = stat;
|
|
1133
|
-
}
|
|
1134
|
-
get size() {
|
|
1135
|
-
return this.stat.size;
|
|
1136
|
-
}
|
|
1137
|
-
get mtimeMs() {
|
|
1138
|
-
return this.stat.mtimeMs;
|
|
1139
|
-
}
|
|
1140
|
-
get eTag() {
|
|
1141
|
-
return this.stat.eTag;
|
|
1142
|
-
}
|
|
1143
|
-
};
|
|
1144
1274
|
var CVfsDirEntry = class extends CFileType {
|
|
1145
1275
|
_url;
|
|
1146
1276
|
constructor(entry) {
|
|
@@ -1166,14 +1296,22 @@ var CVfsDirEntry = class extends CFileType {
|
|
|
1166
1296
|
};
|
|
1167
1297
|
}
|
|
1168
1298
|
};
|
|
1169
|
-
|
|
1299
|
+
/**
|
|
1300
|
+
* Chop URL at node_modules to make it more readable in logs. If the URL contains `node_modules`, the
|
|
1301
|
+
* chopped URL will include the part before `node_modules`, followed by `…`, and then the last 3 parts
|
|
1302
|
+
* of the URL. If the URL does not contain `node_modules`, the original URL href will be returned.
|
|
1303
|
+
* @param url - the URL to chop.
|
|
1304
|
+
* @returns string - the chopped URL, if the URL contains node_modules, otherwise the original URL href.
|
|
1305
|
+
*/
|
|
1306
|
+
function chopUrlAtNodeModules(url) {
|
|
1170
1307
|
if (!url) return "";
|
|
1171
1308
|
const href = url.href;
|
|
1172
1309
|
const parts = href.split("/");
|
|
1173
1310
|
const n = parts.indexOf("node_modules");
|
|
1174
1311
|
if (n > 0) {
|
|
1175
|
-
const tail = parts.slice(
|
|
1176
|
-
|
|
1312
|
+
const tail = parts.slice(n + 1);
|
|
1313
|
+
if (tail.length <= 3) return href;
|
|
1314
|
+
return parts.slice(0, n + 1).join("/") + "/…/" + tail.slice(-3).join("/");
|
|
1177
1315
|
}
|
|
1178
1316
|
return href;
|
|
1179
1317
|
}
|
|
@@ -1183,16 +1321,15 @@ function rPad(str, len, ch = " ") {
|
|
|
1183
1321
|
function toOptions(val) {
|
|
1184
1322
|
return typeof val === "string" ? { encoding: val } : val;
|
|
1185
1323
|
}
|
|
1186
|
-
|
|
1187
1324
|
//#endregion
|
|
1188
|
-
//#region src/CVirtualFS.ts
|
|
1325
|
+
//#region src/VirtualFS/CVirtualFS.ts
|
|
1189
1326
|
var CVirtualFS = class {
|
|
1190
1327
|
providers = /* @__PURE__ */ new Set();
|
|
1191
1328
|
cachedFs = /* @__PURE__ */ new Map();
|
|
1192
1329
|
revCacheFs = /* @__PURE__ */ new Map();
|
|
1193
1330
|
fsc;
|
|
1194
1331
|
fs;
|
|
1195
|
-
loggingEnabled =
|
|
1332
|
+
loggingEnabled = false;
|
|
1196
1333
|
constructor() {
|
|
1197
1334
|
this.fsc = fsPassThroughCore((url) => this._getFS(url));
|
|
1198
1335
|
this.fs = new CVFileSystem(this.fsc);
|
|
@@ -1206,19 +1343,23 @@ var CVirtualFS = class {
|
|
|
1206
1343
|
const id = event.traceID.toFixed(13).replaceAll(/\d{4}(?=\d)/g, "$&.");
|
|
1207
1344
|
const msg = event.message ? `\n\t\t${event.message}` : "";
|
|
1208
1345
|
const method = rPad(`${event.method}-${event.event}`, 16);
|
|
1209
|
-
this.log(`${method} ID:${id} ts:${event.ts.toFixed(13)} ${
|
|
1346
|
+
this.log(`${method} ID:${id} ts:${event.ts.toFixed(13)} ${chopUrlAtNodeModules(event.url)}${msg}`);
|
|
1210
1347
|
}
|
|
1211
1348
|
};
|
|
1212
1349
|
registerFileSystemProvider(...providers) {
|
|
1213
1350
|
providers.forEach((provider) => this.providers.add(provider));
|
|
1214
1351
|
this.reset();
|
|
1215
|
-
|
|
1352
|
+
const dispose = () => {
|
|
1216
1353
|
for (const provider of providers) {
|
|
1217
1354
|
for (const key of this.revCacheFs.get(provider) || []) this.cachedFs.delete(key);
|
|
1218
1355
|
this.providers.delete(provider);
|
|
1219
1356
|
}
|
|
1220
1357
|
this.reset();
|
|
1221
|
-
}
|
|
1358
|
+
};
|
|
1359
|
+
return {
|
|
1360
|
+
dispose,
|
|
1361
|
+
[Symbol.dispose]: dispose
|
|
1362
|
+
};
|
|
1222
1363
|
}
|
|
1223
1364
|
getFS(url) {
|
|
1224
1365
|
return new CVFileSystem(this._getFS(url));
|
|
@@ -1269,6 +1410,9 @@ var CVirtualFS = class {
|
|
|
1269
1410
|
provider.dispose?.();
|
|
1270
1411
|
} catch {}
|
|
1271
1412
|
}
|
|
1413
|
+
[Symbol.dispose]() {
|
|
1414
|
+
this.dispose();
|
|
1415
|
+
}
|
|
1272
1416
|
};
|
|
1273
1417
|
function fsPassThroughCore(fs) {
|
|
1274
1418
|
function gfs(ur, name) {
|
|
@@ -1294,6 +1438,7 @@ function createVirtualFS(cspellIO) {
|
|
|
1294
1438
|
const cspell = cspellIO || getDefaultCSpellIO();
|
|
1295
1439
|
const vfs = new CVirtualFS();
|
|
1296
1440
|
vfs.registerFileSystemProvider(cspellIOToFsProvider(cspell));
|
|
1441
|
+
vfs.registerFileSystemProvider(new MemFileSystemProvider(CSPELL_VFS_PROTOCOL + "default", CSPELL_VFS_PROTOCOL));
|
|
1297
1442
|
return vfs;
|
|
1298
1443
|
}
|
|
1299
1444
|
let defaultVirtualFs = void 0;
|
|
@@ -1301,63 +1446,6 @@ function getDefaultVirtualFs() {
|
|
|
1301
1446
|
if (!defaultVirtualFs) defaultVirtualFs = createVirtualFS();
|
|
1302
1447
|
return defaultVirtualFs;
|
|
1303
1448
|
}
|
|
1304
|
-
|
|
1305
|
-
//#endregion
|
|
1306
|
-
//#region src/common/transformers.ts
|
|
1307
|
-
function encoderTransformer(iterable, encoding) {
|
|
1308
|
-
return isAsyncIterable(iterable) ? encoderAsyncIterable(iterable, encoding) : encoderIterable(iterable, encoding);
|
|
1309
|
-
}
|
|
1310
|
-
function* encoderIterable(iterable, encoding) {
|
|
1311
|
-
let useBom = true;
|
|
1312
|
-
for (const chunk of iterable) {
|
|
1313
|
-
yield encodeString$1(chunk, encoding, useBom);
|
|
1314
|
-
useBom = false;
|
|
1315
|
-
}
|
|
1316
|
-
}
|
|
1317
|
-
async function* encoderAsyncIterable(iterable, encoding) {
|
|
1318
|
-
let useBom = true;
|
|
1319
|
-
for await (const chunk of iterable) {
|
|
1320
|
-
yield encodeString$1(chunk, encoding, useBom);
|
|
1321
|
-
useBom = false;
|
|
1322
|
-
}
|
|
1323
|
-
}
|
|
1324
|
-
function isAsyncIterable(v) {
|
|
1325
|
-
return v && typeof v === "object" && !!v[Symbol.asyncIterator];
|
|
1326
|
-
}
|
|
1327
|
-
|
|
1328
|
-
//#endregion
|
|
1329
|
-
//#region src/node/file/fileWriter.ts
|
|
1330
|
-
const pipeline = promisify(Stream.pipeline);
|
|
1331
|
-
function writeToFile(filename, data, encoding) {
|
|
1332
|
-
return writeToFileIterable(filename, typeof data === "string" ? [data] : data, encoding);
|
|
1333
|
-
}
|
|
1334
|
-
function writeToFileIterable(filename, data, encoding) {
|
|
1335
|
-
return pipeline(Stream.Readable.from(encoderTransformer(data, encoding)), /\.gz$/.test(filename) ? zlib.createGzip() : new Stream.PassThrough(), fs.createWriteStream(filename));
|
|
1336
|
-
}
|
|
1337
|
-
|
|
1338
|
-
//#endregion
|
|
1339
|
-
//#region src/file/file.ts
|
|
1340
|
-
async function readFileText(filename, encoding) {
|
|
1341
|
-
return (await getDefaultCSpellIO().readFile(filename, encoding)).getText();
|
|
1342
|
-
}
|
|
1343
|
-
function readFileTextSync(filename, encoding) {
|
|
1344
|
-
return getDefaultCSpellIO().readFileSync(filename, encoding).getText();
|
|
1345
|
-
}
|
|
1346
|
-
async function getStat(filenameOrUri) {
|
|
1347
|
-
try {
|
|
1348
|
-
return await getDefaultCSpellIO().getStat(filenameOrUri);
|
|
1349
|
-
} catch (e) {
|
|
1350
|
-
return toError$1(e);
|
|
1351
|
-
}
|
|
1352
|
-
}
|
|
1353
|
-
function getStatSync(filenameOrUri) {
|
|
1354
|
-
try {
|
|
1355
|
-
return getDefaultCSpellIO().getStatSync(filenameOrUri);
|
|
1356
|
-
} catch (e) {
|
|
1357
|
-
return toError$1(e);
|
|
1358
|
-
}
|
|
1359
|
-
}
|
|
1360
|
-
|
|
1361
1449
|
//#endregion
|
|
1362
1450
|
//#region src/VirtualFS/redirectProvider.ts
|
|
1363
1451
|
var RedirectProvider = class {
|
|
@@ -1441,6 +1529,7 @@ function remapFS(name, fs, shadowFs, publicRoot, privateRoot, options) {
|
|
|
1441
1529
|
dir
|
|
1442
1530
|
};
|
|
1443
1531
|
};
|
|
1532
|
+
const dispose = () => fs.dispose();
|
|
1444
1533
|
return fsPassThrough({
|
|
1445
1534
|
stat: async (url) => {
|
|
1446
1535
|
const url2 = mapUrlOrReferenceToPrivate(url);
|
|
@@ -1463,7 +1552,8 @@ function remapFS(name, fs, shadowFs, publicRoot, privateRoot, options) {
|
|
|
1463
1552
|
name
|
|
1464
1553
|
},
|
|
1465
1554
|
capabilities: capabilities ?? fs.capabilities & capabilitiesMask,
|
|
1466
|
-
dispose
|
|
1555
|
+
dispose,
|
|
1556
|
+
[Symbol.dispose]: dispose
|
|
1467
1557
|
}, shadowFs, publicRoot);
|
|
1468
1558
|
}
|
|
1469
1559
|
function fsPassThrough(fs, shadowFs, root) {
|
|
@@ -1494,10 +1584,13 @@ function fsPassThrough(fs, shadowFs, root) {
|
|
|
1494
1584
|
dispose: () => {
|
|
1495
1585
|
fs.dispose();
|
|
1496
1586
|
shadowFs?.dispose();
|
|
1587
|
+
},
|
|
1588
|
+
[Symbol.dispose]() {
|
|
1589
|
+
this.dispose();
|
|
1497
1590
|
}
|
|
1498
1591
|
};
|
|
1499
1592
|
}
|
|
1500
|
-
|
|
1501
1593
|
//#endregion
|
|
1502
|
-
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 };
|
|
1594
|
+
export { CFileReference, CFileResource, CSPELL_VFS_PROTOCOL, 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 };
|
|
1595
|
+
|
|
1503
1596
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public",
|
|
5
5
|
"provenance": true
|
|
6
6
|
},
|
|
7
|
-
"version": "9.
|
|
7
|
+
"version": "9.8.0",
|
|
8
8
|
"description": "A library of useful I/O functions used across various cspell tools.",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"sideEffects": false,
|
|
@@ -56,8 +56,8 @@
|
|
|
56
56
|
"vitest-fetch-mock": "^0.4.5"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@cspell/cspell-service-bus": "9.
|
|
60
|
-
"@cspell/url": "9.
|
|
59
|
+
"@cspell/cspell-service-bus": "9.8.0",
|
|
60
|
+
"@cspell/url": "9.8.0"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "c822013ce676dffb5fa5544567c25a3ae666718f"
|
|
63
63
|
}
|