cspell-io 9.6.3 → 9.7.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 +47 -43
  2. package/dist/index.js +295 -139
  3. 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
- interface Disposable {
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/VFileSystem.d.ts
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 Disposable {
393
- registerFileSystemProvider(provider: VFileSystemProvider, ...providers: VFileSystemProvider[]): Disposable;
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 Disposable {
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. Make it possible for a provider to support more capabilities for a given 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<Disposable> {
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
@@ -860,8 +860,64 @@ function getDefaultCSpellIO() {
860
860
  }
861
861
 
862
862
  //#endregion
863
- //#region src/VirtualFS.ts
864
- const debug = false;
863
+ //#region src/common/transformers.ts
864
+ function encoderTransformer(iterable, encoding) {
865
+ return isAsyncIterable(iterable) ? encoderAsyncIterable(iterable, encoding) : encoderIterable(iterable, encoding);
866
+ }
867
+ function* encoderIterable(iterable, encoding) {
868
+ let useBom = true;
869
+ for (const chunk of iterable) {
870
+ yield encodeString$1(chunk, encoding, useBom);
871
+ useBom = false;
872
+ }
873
+ }
874
+ async function* encoderAsyncIterable(iterable, encoding) {
875
+ let useBom = true;
876
+ for await (const chunk of iterable) {
877
+ yield encodeString$1(chunk, encoding, useBom);
878
+ useBom = false;
879
+ }
880
+ }
881
+ function isAsyncIterable(v) {
882
+ return v && typeof v === "object" && !!v[Symbol.asyncIterator];
883
+ }
884
+
885
+ //#endregion
886
+ //#region src/node/file/fileWriter.ts
887
+ const pipeline = promisify(Stream.pipeline);
888
+ function writeToFile(filename, data, encoding) {
889
+ return writeToFileIterable(filename, typeof data === "string" ? [data] : data, encoding);
890
+ }
891
+ function writeToFileIterable(filename, data, encoding) {
892
+ return pipeline(Stream.Readable.from(encoderTransformer(data, encoding)), /\.gz$/.test(filename) ? zlib.createGzip() : new Stream.PassThrough(), fs.createWriteStream(filename));
893
+ }
894
+
895
+ //#endregion
896
+ //#region src/file/file.ts
897
+ async function readFileText(filename, encoding) {
898
+ return (await getDefaultCSpellIO().readFile(filename, encoding)).getText();
899
+ }
900
+ function readFileTextSync(filename, encoding) {
901
+ return getDefaultCSpellIO().readFileSync(filename, encoding).getText();
902
+ }
903
+ async function getStat(filenameOrUri) {
904
+ try {
905
+ return await getDefaultCSpellIO().getStat(filenameOrUri);
906
+ } catch (e) {
907
+ return toError$1(e);
908
+ }
909
+ }
910
+ function getStatSync(filenameOrUri) {
911
+ try {
912
+ return getDefaultCSpellIO().getStatSync(filenameOrUri);
913
+ } catch (e) {
914
+ return toError$1(e);
915
+ }
916
+ }
917
+
918
+ //#endregion
919
+ //#region src/VirtualFS/constants.ts
920
+ const CSPELL_VFS_PROTOCOL = "cspell-vfs:";
865
921
 
866
922
  //#endregion
867
923
  //#region src/VirtualFS/findUpFromUrl.ts
@@ -930,7 +986,41 @@ var CVFileSystem = class {
930
986
  };
931
987
 
932
988
  //#endregion
933
- //#region src/VFileSystem.ts
989
+ //#region src/VirtualFS/errors.ts
990
+ var VFSError = class extends Error {
991
+ url;
992
+ code;
993
+ constructor(message, options) {
994
+ super(message, { cause: options?.cause });
995
+ this.name = "VFSError";
996
+ this.url = options?.url instanceof URL ? options.url.href : options?.url;
997
+ this.code = options?.code;
998
+ }
999
+ };
1000
+ var VFSNotSupported = class extends VFSError {
1001
+ constructor(methodName, url) {
1002
+ super(`Method ${methodName} is not supported for ${url.href}`, { url });
1003
+ }
1004
+ };
1005
+ var VFSNotFoundError = class extends VFSError {
1006
+ constructor(url, options) {
1007
+ super(`Not found: ${url.href}`, {
1008
+ ...options,
1009
+ url,
1010
+ code: options?.code ?? "ENOENT"
1011
+ });
1012
+ }
1013
+ };
1014
+ var VFSErrorUnsupportedRequest = class extends VFSError {
1015
+ constructor(request, url, parameters) {
1016
+ super(`Unsupported request: ${request}`, { url });
1017
+ this.request = request;
1018
+ this.parameters = parameters;
1019
+ }
1020
+ };
1021
+
1022
+ //#endregion
1023
+ //#region src/VirtualFS/VFileSystem.ts
934
1024
  let FSCapabilityFlags = /* @__PURE__ */ function(FSCapabilityFlags) {
935
1025
  FSCapabilityFlags[FSCapabilityFlags["None"] = 0] = "None";
936
1026
  FSCapabilityFlags[FSCapabilityFlags["Stat"] = 1] = "Stat";
@@ -943,6 +1033,174 @@ let FSCapabilityFlags = /* @__PURE__ */ function(FSCapabilityFlags) {
943
1033
  return FSCapabilityFlags;
944
1034
  }({});
945
1035
 
1036
+ //#endregion
1037
+ //#region src/VirtualFS/MemVfsProvider.ts
1038
+ var MemFileSystemProvider = class {
1039
+ name;
1040
+ protocol;
1041
+ #vfs;
1042
+ /**
1043
+ * @param name - the name of the provider, used for debugging and logging.
1044
+ * @param protocol - the protocol (end with a :), examples: `vfs:`, `cspell-vfs:`
1045
+ */
1046
+ constructor(name, protocol) {
1047
+ this.name = name;
1048
+ this.protocol = protocol;
1049
+ this.#vfs = new MemVFileSystem(name, protocol);
1050
+ }
1051
+ getFileSystem(url) {
1052
+ if (url.protocol !== this.protocol) return;
1053
+ return this.#vfs;
1054
+ }
1055
+ get memFS() {
1056
+ return this.#vfs;
1057
+ }
1058
+ dispose() {
1059
+ this.#vfs.dispose();
1060
+ }
1061
+ [Symbol.dispose]() {
1062
+ this.dispose();
1063
+ }
1064
+ };
1065
+ var MemVFileSystem = class {
1066
+ name;
1067
+ protocol;
1068
+ capabilities = FSCapabilityFlags.ReadWrite | FSCapabilityFlags.Stat;
1069
+ #files = /* @__PURE__ */ new Map();
1070
+ constructor(name, protocol) {
1071
+ this.name = name;
1072
+ this.protocol = protocol;
1073
+ this.providerInfo = { name };
1074
+ this.#files = /* @__PURE__ */ new Map();
1075
+ }
1076
+ /**
1077
+ * Read a file.
1078
+ * @param url - URL to read
1079
+ * @param options - options for reading the file.
1080
+ * @returns A FileResource, the content will not be decoded. Use `.getText()` to get the decoded text.
1081
+ */
1082
+ async readFile(url, _options) {
1083
+ return this.#getEntryOrThrow(url).file;
1084
+ }
1085
+ /**
1086
+ * Write a file
1087
+ * @param file - the file to write
1088
+ */
1089
+ async writeFile(file) {
1090
+ const stats = {
1091
+ size: file.content.length,
1092
+ mtimeMs: performance.now(),
1093
+ fileType: FileType.File
1094
+ };
1095
+ const u = urlOrReferenceToUrl(file);
1096
+ this.#files.set(u.href, {
1097
+ file,
1098
+ stats
1099
+ });
1100
+ return { url: file.url };
1101
+ }
1102
+ /**
1103
+ * Get the stats for a url.
1104
+ * @param url - Url to fetch stats for.
1105
+ */
1106
+ stat(url) {
1107
+ return this.#getEntryOrThrow(url).stats;
1108
+ }
1109
+ #getEntryOrThrow(url) {
1110
+ const u = urlOrReferenceToUrl(url);
1111
+ const found = this.#files.get(u.href);
1112
+ if (!found) throw new VFSNotFoundError(u);
1113
+ return found;
1114
+ }
1115
+ /**
1116
+ * Read the directory entries for a url.
1117
+ * The url should end with `/` to indicate a directory.
1118
+ * @param url - the url to read the directory entries for.
1119
+ */
1120
+ async readDirectory(url) {
1121
+ throw new VFSNotSupported("readDirectory", url);
1122
+ }
1123
+ /**
1124
+ * Information about the provider.
1125
+ * It is up to the provider to define what information is available.
1126
+ */
1127
+ providerInfo;
1128
+ dispose() {
1129
+ this.#files.clear();
1130
+ }
1131
+ [Symbol.dispose]() {
1132
+ this.dispose();
1133
+ }
1134
+ };
1135
+
1136
+ //#endregion
1137
+ //#region src/VirtualFS/VirtualFS.ts
1138
+ const debug = false;
1139
+
1140
+ //#endregion
1141
+ //#region src/VirtualFS/capabilities.ts
1142
+ var CFsCapabilities = class {
1143
+ constructor(flags) {
1144
+ this.flags = flags;
1145
+ }
1146
+ get readFile() {
1147
+ return !!(this.flags & FSCapabilityFlags.Read);
1148
+ }
1149
+ get writeFile() {
1150
+ return !!(this.flags & FSCapabilityFlags.Write);
1151
+ }
1152
+ get readDirectory() {
1153
+ return !!(this.flags & FSCapabilityFlags.ReadDir);
1154
+ }
1155
+ get writeDirectory() {
1156
+ return !!(this.flags & FSCapabilityFlags.WriteDir);
1157
+ }
1158
+ get stat() {
1159
+ return !!(this.flags & FSCapabilityFlags.Stat);
1160
+ }
1161
+ };
1162
+ function fsCapabilities(flags) {
1163
+ return new CFsCapabilities(flags);
1164
+ }
1165
+
1166
+ //#endregion
1167
+ //#region src/VirtualFS/CFileType.ts
1168
+ var CFileType = class {
1169
+ constructor(fileType) {
1170
+ this.fileType = fileType;
1171
+ }
1172
+ isFile() {
1173
+ return this.fileType === FileType.File;
1174
+ }
1175
+ isDirectory() {
1176
+ return this.fileType === FileType.Directory;
1177
+ }
1178
+ isUnknown() {
1179
+ return !this.fileType;
1180
+ }
1181
+ isSymbolicLink() {
1182
+ return !!(this.fileType & FileType.SymbolicLink);
1183
+ }
1184
+ };
1185
+
1186
+ //#endregion
1187
+ //#region src/VirtualFS/CVfsStat.ts
1188
+ var CVfsStat = class extends CFileType {
1189
+ constructor(stat) {
1190
+ super(stat.fileType || FileType.Unknown);
1191
+ this.stat = stat;
1192
+ }
1193
+ get size() {
1194
+ return this.stat.size;
1195
+ }
1196
+ get mtimeMs() {
1197
+ return this.stat.mtimeMs;
1198
+ }
1199
+ get eTag() {
1200
+ return this.stat.eTag;
1201
+ }
1202
+ };
1203
+
946
1204
  //#endregion
947
1205
  //#region src/VirtualFS/WrappedProviderFs.ts
948
1206
  function cspellIOToFsProvider(cspellIO) {
@@ -959,17 +1217,19 @@ function cspellIOToFsProvider(cspellIO) {
959
1217
  "http:",
960
1218
  "https:"
961
1219
  ]);
1220
+ const dispose = () => void 0;
962
1221
  const fs = {
963
1222
  providerInfo: { name },
964
1223
  stat: (url) => cspellIO.getStat(url),
965
1224
  readFile: (url, options) => cspellIO.readFile(url, options),
966
1225
  readDirectory: (url) => cspellIO.readDirectory(url),
967
1226
  writeFile: (file) => cspellIO.writeFile(file.url, file.content),
968
- dispose: () => void 0,
1227
+ dispose,
969
1228
  capabilities,
970
1229
  getCapabilities(url) {
971
1230
  return fsCapabilities(capMap[url.protocol] || FSCapabilityFlags.None);
972
- }
1231
+ },
1232
+ [Symbol.dispose]: dispose
973
1233
  };
974
1234
  return {
975
1235
  name,
@@ -982,43 +1242,6 @@ function wrapError(e) {
982
1242
  if (e instanceof VFSError) return e;
983
1243
  return e;
984
1244
  }
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
1245
  var WrappedProviderFs = class WrappedProviderFs {
1023
1246
  hasProvider;
1024
1247
  capabilities;
@@ -1109,38 +1332,6 @@ var WrappedProviderFs = class WrappedProviderFs {
1109
1332
  function checkCapabilityOrThrow(fs, capabilities, flag, name, url) {
1110
1333
  if (!(capabilities & flag)) throw new VFSErrorUnsupportedRequest(name, url);
1111
1334
  }
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
1335
  var CVfsDirEntry = class extends CFileType {
1145
1336
  _url;
1146
1337
  constructor(entry) {
@@ -1166,14 +1357,22 @@ var CVfsDirEntry = class extends CFileType {
1166
1357
  };
1167
1358
  }
1168
1359
  };
1169
- function chopUrl(url) {
1360
+ /**
1361
+ * Chop URL at node_modules to make it more readable in logs. If the URL contains `node_modules`, the
1362
+ * chopped URL will include the part before `node_modules`, followed by `…`, and then the last 3 parts
1363
+ * of the URL. If the URL does not contain `node_modules`, the original URL href will be returned.
1364
+ * @param url - the URL to chop.
1365
+ * @returns string - the chopped URL, if the URL contains node_modules, otherwise the original URL href.
1366
+ */
1367
+ function chopUrlAtNodeModules(url) {
1170
1368
  if (!url) return "";
1171
1369
  const href = url.href;
1172
1370
  const parts = href.split("/");
1173
1371
  const n = parts.indexOf("node_modules");
1174
1372
  if (n > 0) {
1175
- const tail = parts.slice(Math.max(parts.length - 3, n + 1));
1176
- return parts.slice(0, n + 1).join("/") + "/…/" + tail.join("/");
1373
+ const tail = parts.slice(n + 1);
1374
+ if (tail.length <= 3) return href;
1375
+ return parts.slice(0, n + 1).join("/") + "/…/" + tail.slice(-3).join("/");
1177
1376
  }
1178
1377
  return href;
1179
1378
  }
@@ -1185,7 +1384,7 @@ function toOptions(val) {
1185
1384
  }
1186
1385
 
1187
1386
  //#endregion
1188
- //#region src/CVirtualFS.ts
1387
+ //#region src/VirtualFS/CVirtualFS.ts
1189
1388
  var CVirtualFS = class {
1190
1389
  providers = /* @__PURE__ */ new Set();
1191
1390
  cachedFs = /* @__PURE__ */ new Map();
@@ -1206,19 +1405,23 @@ var CVirtualFS = class {
1206
1405
  const id = event.traceID.toFixed(13).replaceAll(/\d{4}(?=\d)/g, "$&.");
1207
1406
  const msg = event.message ? `\n\t\t${event.message}` : "";
1208
1407
  const method = rPad(`${event.method}-${event.event}`, 16);
1209
- this.log(`${method} ID:${id} ts:${event.ts.toFixed(13)} ${chopUrl(event.url)}${msg}`);
1408
+ this.log(`${method} ID:${id} ts:${event.ts.toFixed(13)} ${chopUrlAtNodeModules(event.url)}${msg}`);
1210
1409
  }
1211
1410
  };
1212
1411
  registerFileSystemProvider(...providers) {
1213
1412
  providers.forEach((provider) => this.providers.add(provider));
1214
1413
  this.reset();
1215
- return { dispose: () => {
1414
+ const dispose = () => {
1216
1415
  for (const provider of providers) {
1217
1416
  for (const key of this.revCacheFs.get(provider) || []) this.cachedFs.delete(key);
1218
1417
  this.providers.delete(provider);
1219
1418
  }
1220
1419
  this.reset();
1221
- } };
1420
+ };
1421
+ return {
1422
+ dispose,
1423
+ [Symbol.dispose]: dispose
1424
+ };
1222
1425
  }
1223
1426
  getFS(url) {
1224
1427
  return new CVFileSystem(this._getFS(url));
@@ -1269,6 +1472,9 @@ var CVirtualFS = class {
1269
1472
  provider.dispose?.();
1270
1473
  } catch {}
1271
1474
  }
1475
+ [Symbol.dispose]() {
1476
+ this.dispose();
1477
+ }
1272
1478
  };
1273
1479
  function fsPassThroughCore(fs) {
1274
1480
  function gfs(ur, name) {
@@ -1294,6 +1500,7 @@ function createVirtualFS(cspellIO) {
1294
1500
  const cspell = cspellIO || getDefaultCSpellIO();
1295
1501
  const vfs = new CVirtualFS();
1296
1502
  vfs.registerFileSystemProvider(cspellIOToFsProvider(cspell));
1503
+ vfs.registerFileSystemProvider(new MemFileSystemProvider(CSPELL_VFS_PROTOCOL + "default", CSPELL_VFS_PROTOCOL));
1297
1504
  return vfs;
1298
1505
  }
1299
1506
  let defaultVirtualFs = void 0;
@@ -1302,62 +1509,6 @@ function getDefaultVirtualFs() {
1302
1509
  return defaultVirtualFs;
1303
1510
  }
1304
1511
 
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
1512
  //#endregion
1362
1513
  //#region src/VirtualFS/redirectProvider.ts
1363
1514
  var RedirectProvider = class {
@@ -1441,6 +1592,7 @@ function remapFS(name, fs, shadowFs, publicRoot, privateRoot, options) {
1441
1592
  dir
1442
1593
  };
1443
1594
  };
1595
+ const dispose = () => fs.dispose();
1444
1596
  return fsPassThrough({
1445
1597
  stat: async (url) => {
1446
1598
  const url2 = mapUrlOrReferenceToPrivate(url);
@@ -1463,7 +1615,8 @@ function remapFS(name, fs, shadowFs, publicRoot, privateRoot, options) {
1463
1615
  name
1464
1616
  },
1465
1617
  capabilities: capabilities ?? fs.capabilities & capabilitiesMask,
1466
- dispose: () => fs.dispose()
1618
+ dispose,
1619
+ [Symbol.dispose]: dispose
1467
1620
  }, shadowFs, publicRoot);
1468
1621
  }
1469
1622
  function fsPassThrough(fs, shadowFs, root) {
@@ -1494,10 +1647,13 @@ function fsPassThrough(fs, shadowFs, root) {
1494
1647
  dispose: () => {
1495
1648
  fs.dispose();
1496
1649
  shadowFs?.dispose();
1650
+ },
1651
+ [Symbol.dispose]() {
1652
+ this.dispose();
1497
1653
  }
1498
1654
  };
1499
1655
  }
1500
1656
 
1501
1657
  //#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 };
1658
+ 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 };
1503
1659
  //# 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.6.3",
7
+ "version": "9.7.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.6.3",
60
- "@cspell/url": "9.6.3"
59
+ "@cspell/cspell-service-bus": "9.7.0",
60
+ "@cspell/url": "9.7.0"
61
61
  },
62
- "gitHead": "500b996b6c0a6ff025c42ef98db44776f43a9e72"
62
+ "gitHead": "48f64e0bd95b39011af6dc80cd8ae4d519511f73"
63
63
  }