cspell-io 8.1.2 → 8.2.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/esm/CSpellIO.d.ts +19 -12
- package/dist/esm/CSpellIONode.d.ts +4 -5
- package/dist/esm/CSpellIONode.js +9 -0
- package/dist/esm/CSpellIOWeb.d.ts +5 -4
- package/dist/esm/CSpellIOWeb.js +3 -0
- package/dist/esm/VirtualFS/redirectProvider.d.ts +30 -0
- package/dist/esm/VirtualFS/redirectProvider.js +147 -0
- package/dist/esm/VirtualFS.d.ts +107 -0
- package/dist/esm/VirtualFS.js +326 -0
- package/dist/esm/common/CFileReference.d.ts +1 -0
- package/dist/esm/common/CFileReference.js +3 -0
- package/dist/esm/common/CFileResource.d.ts +7 -4
- package/dist/esm/common/CFileResource.js +12 -1
- package/dist/esm/common/index.d.ts +3 -2
- package/dist/esm/common/index.js +3 -2
- package/dist/esm/common/urlOrReferenceToUrl.d.ts +5 -0
- package/dist/esm/common/urlOrReferenceToUrl.js +4 -0
- package/dist/esm/handlers/node/file.js +38 -1
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/models/FileResource.d.ts +2 -2
- package/dist/esm/models/Stats.d.ts +23 -0
- package/dist/esm/models/Stats.js +15 -4
- package/dist/esm/models/disposable.d.ts +4 -0
- package/dist/esm/models/disposable.js +2 -0
- package/dist/esm/models/index.d.ts +5 -1
- package/dist/esm/models/index.js +1 -1
- package/dist/esm/node/file/fetch.js +3 -0
- package/dist/esm/node/file/url.d.ts +2 -0
- package/dist/esm/node/file/url.js +20 -7
- package/dist/esm/requests/RequestFsReadDirectory.d.ts +9 -0
- package/dist/esm/requests/RequestFsReadDirectory.js +4 -0
- package/dist/esm/requests/RequestFsReadFile.d.ts +2 -2
- package/dist/esm/requests/RequestFsReadFileSync.d.ts +2 -2
- package/dist/esm/test/test.helper.d.ts +15 -3
- package/dist/esm/test/test.helper.js +36 -9
- package/package.json +4 -4
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import { urlOrReferenceToUrl } from './common/index.js';
|
|
2
|
+
import { getDefaultCSpellIO } from './CSpellIONode.js';
|
|
3
|
+
import { FileType, } from './models/index.js';
|
|
4
|
+
export var FSCapabilityFlags;
|
|
5
|
+
(function (FSCapabilityFlags) {
|
|
6
|
+
FSCapabilityFlags[FSCapabilityFlags["None"] = 0] = "None";
|
|
7
|
+
FSCapabilityFlags[FSCapabilityFlags["Stat"] = 1] = "Stat";
|
|
8
|
+
FSCapabilityFlags[FSCapabilityFlags["Read"] = 2] = "Read";
|
|
9
|
+
FSCapabilityFlags[FSCapabilityFlags["Write"] = 4] = "Write";
|
|
10
|
+
FSCapabilityFlags[FSCapabilityFlags["ReadWrite"] = 6] = "ReadWrite";
|
|
11
|
+
FSCapabilityFlags[FSCapabilityFlags["ReadDir"] = 8] = "ReadDir";
|
|
12
|
+
FSCapabilityFlags[FSCapabilityFlags["WriteDir"] = 16] = "WriteDir";
|
|
13
|
+
FSCapabilityFlags[FSCapabilityFlags["ReadWriteDir"] = 24] = "ReadWriteDir";
|
|
14
|
+
})(FSCapabilityFlags || (FSCapabilityFlags = {}));
|
|
15
|
+
class CVirtualFS {
|
|
16
|
+
providers = new Set();
|
|
17
|
+
cachedFs = new Map();
|
|
18
|
+
revCacheFs = new Map();
|
|
19
|
+
fs;
|
|
20
|
+
constructor() {
|
|
21
|
+
this.fs = fsPassThrough((url) => this._getFS(url));
|
|
22
|
+
}
|
|
23
|
+
registerFileSystemProvider(...providers) {
|
|
24
|
+
providers.forEach((provider) => this.providers.add(provider));
|
|
25
|
+
this.reset();
|
|
26
|
+
return {
|
|
27
|
+
dispose: () => {
|
|
28
|
+
for (const provider of providers) {
|
|
29
|
+
for (const key of this.revCacheFs.get(provider) || []) {
|
|
30
|
+
this.cachedFs.delete(key);
|
|
31
|
+
}
|
|
32
|
+
this.providers.delete(provider) && undefined;
|
|
33
|
+
}
|
|
34
|
+
this.reset();
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
getFS(url) {
|
|
39
|
+
return this._getFS(url);
|
|
40
|
+
}
|
|
41
|
+
_getFS(url) {
|
|
42
|
+
const key = `${url.protocol}${url.hostname}`;
|
|
43
|
+
const cached = this.cachedFs.get(key);
|
|
44
|
+
if (cached) {
|
|
45
|
+
return cached;
|
|
46
|
+
}
|
|
47
|
+
const fnNext = (provider, next) => {
|
|
48
|
+
return (url) => {
|
|
49
|
+
let calledNext = false;
|
|
50
|
+
const fs = provider.getFileSystem(url, (_url) => {
|
|
51
|
+
calledNext = calledNext || url === _url;
|
|
52
|
+
return next(_url);
|
|
53
|
+
});
|
|
54
|
+
if (fs) {
|
|
55
|
+
const s = this.revCacheFs.get(provider) || new Set();
|
|
56
|
+
s.add(key);
|
|
57
|
+
this.revCacheFs.set(provider, s);
|
|
58
|
+
return fs;
|
|
59
|
+
}
|
|
60
|
+
if (!calledNext) {
|
|
61
|
+
return next(url);
|
|
62
|
+
}
|
|
63
|
+
return undefined;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
let next = (_url) => undefined;
|
|
67
|
+
for (const provider of this.providers) {
|
|
68
|
+
next = fnNext(provider, next);
|
|
69
|
+
}
|
|
70
|
+
const fs = new WrappedProviderFs(next(url));
|
|
71
|
+
this.cachedFs.set(key, fs);
|
|
72
|
+
return fs;
|
|
73
|
+
}
|
|
74
|
+
reset() {
|
|
75
|
+
this.cachedFs.clear();
|
|
76
|
+
this.revCacheFs.clear();
|
|
77
|
+
this.disposeOfCachedFs();
|
|
78
|
+
}
|
|
79
|
+
disposeOfCachedFs() {
|
|
80
|
+
for (const [key, fs] of [...this.cachedFs].reverse()) {
|
|
81
|
+
try {
|
|
82
|
+
WrappedProviderFs.disposeOf(fs);
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
// continue - we are cleaning up.
|
|
86
|
+
}
|
|
87
|
+
this.cachedFs.delete(key);
|
|
88
|
+
}
|
|
89
|
+
this.cachedFs.clear();
|
|
90
|
+
}
|
|
91
|
+
dispose() {
|
|
92
|
+
this.disposeOfCachedFs();
|
|
93
|
+
const providers = [...this.providers].reverse();
|
|
94
|
+
for (const provider of providers) {
|
|
95
|
+
try {
|
|
96
|
+
provider.dispose?.();
|
|
97
|
+
}
|
|
98
|
+
catch (e) {
|
|
99
|
+
// continue - we are cleaning up.
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function fsPassThrough(fs) {
|
|
105
|
+
function gfs(ur, name) {
|
|
106
|
+
const url = urlOrReferenceToUrl(ur);
|
|
107
|
+
const f = fs(url);
|
|
108
|
+
if (!f.hasProvider)
|
|
109
|
+
throw new VFSErrorUnsupportedRequest(name, url, ur instanceof URL ? undefined : { url: ur.url.toString(), encoding: ur.encoding });
|
|
110
|
+
return f;
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
providerInfo: { name: 'default' },
|
|
114
|
+
hasProvider: true,
|
|
115
|
+
stat: async (url) => gfs(url, 'stat').stat(url),
|
|
116
|
+
readFile: async (url) => gfs(url, 'readFile').readFile(url),
|
|
117
|
+
writeFile: async (file) => gfs(file, 'writeFile').writeFile(file),
|
|
118
|
+
readDirectory: async (url) => gfs(url, 'readDirectory')
|
|
119
|
+
.readDirectory(url)
|
|
120
|
+
.then((entries) => entries.map((e) => new CVfsDirEntry(e))),
|
|
121
|
+
getCapabilities: (url) => gfs(url, 'getCapabilities').getCapabilities(url),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
export function createVirtualFS(cspellIO) {
|
|
125
|
+
const cspell = cspellIO || getDefaultCSpellIO();
|
|
126
|
+
const vfs = new CVirtualFS();
|
|
127
|
+
vfs.registerFileSystemProvider(cspellIOToFsProvider(cspell));
|
|
128
|
+
return vfs;
|
|
129
|
+
}
|
|
130
|
+
function cspellIOToFsProvider(cspellIO) {
|
|
131
|
+
const capabilities = FSCapabilityFlags.Stat | FSCapabilityFlags.ReadWrite | FSCapabilityFlags.ReadDir;
|
|
132
|
+
const capabilitiesHttp = capabilities & ~FSCapabilityFlags.Write & ~FSCapabilityFlags.ReadDir;
|
|
133
|
+
const capMap = {
|
|
134
|
+
'file:': capabilities,
|
|
135
|
+
'http:': capabilitiesHttp,
|
|
136
|
+
'https:': capabilitiesHttp,
|
|
137
|
+
};
|
|
138
|
+
const name = 'CSpellIO';
|
|
139
|
+
const supportedProtocols = new Set(['file:', 'http:', 'https:']);
|
|
140
|
+
const fs = {
|
|
141
|
+
providerInfo: { name },
|
|
142
|
+
stat: (url) => cspellIO.getStat(url),
|
|
143
|
+
readFile: (url) => cspellIO.readFile(url),
|
|
144
|
+
readDirectory: (url) => cspellIO.readDirectory(url),
|
|
145
|
+
writeFile: (file) => cspellIO.writeFile(file.url, file.content),
|
|
146
|
+
dispose: () => undefined,
|
|
147
|
+
capabilities,
|
|
148
|
+
getCapabilities(url) {
|
|
149
|
+
return fsCapabilities(capMap[url.protocol] || FSCapabilityFlags.None);
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
return {
|
|
153
|
+
name,
|
|
154
|
+
getFileSystem: (url, _next) => {
|
|
155
|
+
return supportedProtocols.has(url.protocol) ? fs : undefined;
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
let defaultVirtualFs = undefined;
|
|
160
|
+
export function getDefaultVirtualFs() {
|
|
161
|
+
if (!defaultVirtualFs) {
|
|
162
|
+
defaultVirtualFs = createVirtualFS();
|
|
163
|
+
}
|
|
164
|
+
return defaultVirtualFs;
|
|
165
|
+
}
|
|
166
|
+
function wrapError(e) {
|
|
167
|
+
if (e instanceof VFSError)
|
|
168
|
+
return e;
|
|
169
|
+
// return new VFSError(e instanceof Error ? e.message : String(e), { cause: e });
|
|
170
|
+
return e;
|
|
171
|
+
}
|
|
172
|
+
export class VFSError extends Error {
|
|
173
|
+
constructor(message, options) {
|
|
174
|
+
super(message, options);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
export class VFSErrorUnsupportedRequest extends VFSError {
|
|
178
|
+
request;
|
|
179
|
+
parameters;
|
|
180
|
+
url;
|
|
181
|
+
constructor(request, url, parameters) {
|
|
182
|
+
super(`Unsupported request: ${request}`);
|
|
183
|
+
this.request = request;
|
|
184
|
+
this.parameters = parameters;
|
|
185
|
+
this.url = url?.toString();
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
class CFsCapabilities {
|
|
189
|
+
flags;
|
|
190
|
+
constructor(flags) {
|
|
191
|
+
this.flags = flags;
|
|
192
|
+
}
|
|
193
|
+
get readFile() {
|
|
194
|
+
return !!(this.flags & FSCapabilityFlags.Read);
|
|
195
|
+
}
|
|
196
|
+
get writeFile() {
|
|
197
|
+
return !!(this.flags & FSCapabilityFlags.Write);
|
|
198
|
+
}
|
|
199
|
+
get readDirectory() {
|
|
200
|
+
return !!(this.flags & FSCapabilityFlags.ReadDir);
|
|
201
|
+
}
|
|
202
|
+
get writeDirectory() {
|
|
203
|
+
return !!(this.flags & FSCapabilityFlags.WriteDir);
|
|
204
|
+
}
|
|
205
|
+
get stat() {
|
|
206
|
+
return !!(this.flags & FSCapabilityFlags.Stat);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
export function fsCapabilities(flags) {
|
|
210
|
+
return new CFsCapabilities(flags);
|
|
211
|
+
}
|
|
212
|
+
class WrappedProviderFs {
|
|
213
|
+
fs;
|
|
214
|
+
hasProvider;
|
|
215
|
+
capabilities;
|
|
216
|
+
providerInfo;
|
|
217
|
+
_capabilities;
|
|
218
|
+
constructor(fs) {
|
|
219
|
+
this.fs = fs;
|
|
220
|
+
this.hasProvider = !!fs;
|
|
221
|
+
this.capabilities = fs?.capabilities || FSCapabilityFlags.None;
|
|
222
|
+
this._capabilities = fsCapabilities(this.capabilities);
|
|
223
|
+
this.providerInfo = fs?.providerInfo || { name: 'unknown' };
|
|
224
|
+
}
|
|
225
|
+
getCapabilities(url) {
|
|
226
|
+
if (this.fs?.getCapabilities)
|
|
227
|
+
return this.fs.getCapabilities(url);
|
|
228
|
+
return this._capabilities;
|
|
229
|
+
}
|
|
230
|
+
async stat(url) {
|
|
231
|
+
try {
|
|
232
|
+
checkCapabilityOrThrow(this.fs, this.capabilities, FSCapabilityFlags.Stat, 'stat', urlOrReferenceToUrl(url));
|
|
233
|
+
return new CVfsStat(await this.fs.stat(url));
|
|
234
|
+
}
|
|
235
|
+
catch (e) {
|
|
236
|
+
throw wrapError(e);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
async readFile(url) {
|
|
240
|
+
try {
|
|
241
|
+
checkCapabilityOrThrow(this.fs, this.capabilities, FSCapabilityFlags.Read, 'readFile', urlOrReferenceToUrl(url));
|
|
242
|
+
return await this.fs.readFile(url);
|
|
243
|
+
}
|
|
244
|
+
catch (e) {
|
|
245
|
+
throw wrapError(e);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
async readDirectory(url) {
|
|
249
|
+
try {
|
|
250
|
+
checkCapabilityOrThrow(this.fs, this.capabilities, FSCapabilityFlags.ReadDir, 'readDirectory', url);
|
|
251
|
+
return (await this.fs.readDirectory(url)).map((e) => new CVfsDirEntry(e));
|
|
252
|
+
}
|
|
253
|
+
catch (e) {
|
|
254
|
+
throw wrapError(e);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
async writeFile(file) {
|
|
258
|
+
try {
|
|
259
|
+
checkCapabilityOrThrow(this.fs, this.capabilities, FSCapabilityFlags.Write, 'writeFile', file.url);
|
|
260
|
+
return await this.fs.writeFile(file);
|
|
261
|
+
}
|
|
262
|
+
catch (e) {
|
|
263
|
+
throw wrapError(e);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
static disposeOf(fs) {
|
|
267
|
+
fs instanceof WrappedProviderFs && fs.fs?.dispose();
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
function checkCapabilityOrThrow(fs, capabilities, flag, name, url) {
|
|
271
|
+
if (!(capabilities & flag)) {
|
|
272
|
+
throw new VFSErrorUnsupportedRequest(name, url);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
class CFileType {
|
|
276
|
+
fileType;
|
|
277
|
+
constructor(fileType) {
|
|
278
|
+
this.fileType = fileType;
|
|
279
|
+
}
|
|
280
|
+
isFile() {
|
|
281
|
+
return this.fileType === FileType.File;
|
|
282
|
+
}
|
|
283
|
+
isDirectory() {
|
|
284
|
+
return this.fileType === FileType.Directory;
|
|
285
|
+
}
|
|
286
|
+
isUnknown() {
|
|
287
|
+
return !this.fileType;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
class CVfsStat extends CFileType {
|
|
291
|
+
stat;
|
|
292
|
+
constructor(stat) {
|
|
293
|
+
super(stat.fileType || FileType.Unknown);
|
|
294
|
+
this.stat = stat;
|
|
295
|
+
}
|
|
296
|
+
get size() {
|
|
297
|
+
return this.stat.size;
|
|
298
|
+
}
|
|
299
|
+
get mtimeMs() {
|
|
300
|
+
return this.stat.mtimeMs;
|
|
301
|
+
}
|
|
302
|
+
get eTag() {
|
|
303
|
+
return this.stat.eTag;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
class CVfsDirEntry extends CFileType {
|
|
307
|
+
entry;
|
|
308
|
+
_url;
|
|
309
|
+
constructor(entry) {
|
|
310
|
+
super(entry.fileType);
|
|
311
|
+
this.entry = entry;
|
|
312
|
+
}
|
|
313
|
+
get name() {
|
|
314
|
+
return this.entry.name;
|
|
315
|
+
}
|
|
316
|
+
get dir() {
|
|
317
|
+
return this.entry.dir;
|
|
318
|
+
}
|
|
319
|
+
get url() {
|
|
320
|
+
if (this._url)
|
|
321
|
+
return this._url;
|
|
322
|
+
this._url = new URL(this.entry.name, this.entry.dir);
|
|
323
|
+
return this._url;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
//# sourceMappingURL=VirtualFS.js.map
|
|
@@ -31,4 +31,5 @@ export declare class CFileReference implements FileReference {
|
|
|
31
31
|
*/
|
|
32
32
|
export declare function toFileReference(file: UrlOrReference, encoding?: BufferEncoding, baseFilename?: string, gz?: boolean | undefined): FileReference;
|
|
33
33
|
export declare function isFileReference(ref: UrlOrReference): ref is FileReference;
|
|
34
|
+
export declare function renameFileReference(ref: FileReference, newUrl: URL): FileReference;
|
|
34
35
|
//# sourceMappingURL=CFileReference.d.ts.map
|
|
@@ -51,4 +51,7 @@ export function toFileReference(file, encoding, baseFilename, gz) {
|
|
|
51
51
|
export function isFileReference(ref) {
|
|
52
52
|
return CFileReference.isCFileReference(ref) || (!(ref instanceof URL) && typeof ref !== 'string');
|
|
53
53
|
}
|
|
54
|
+
export function renameFileReference(ref, newUrl) {
|
|
55
|
+
return new CFileReference(newUrl, ref.encoding, ref.baseFilename, ref.gz);
|
|
56
|
+
}
|
|
54
57
|
//# sourceMappingURL=CFileReference.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BufferEncoding } from '../models/BufferEncoding.js';
|
|
2
|
-
import type { FileReference, FileResource,
|
|
3
|
-
export declare class CFileResource implements
|
|
2
|
+
import type { FileReference, FileResource, TextFileResource } from '../models/FileResource.js';
|
|
3
|
+
export declare class CFileResource implements TextFileResource {
|
|
4
4
|
readonly url: URL;
|
|
5
5
|
readonly content: string | ArrayBufferView;
|
|
6
6
|
readonly encoding: BufferEncoding | undefined;
|
|
@@ -18,8 +18,11 @@ export declare class CFileResource implements FileResource {
|
|
|
18
18
|
gz: boolean;
|
|
19
19
|
};
|
|
20
20
|
static isCFileResource(obj: unknown): obj is CFileResource;
|
|
21
|
-
static from(fileResource:
|
|
21
|
+
static from(fileResource: FileResource): CFileResource;
|
|
22
22
|
static from(fileReference: FileReference, content: string | ArrayBufferView): CFileResource;
|
|
23
|
-
static from(
|
|
23
|
+
static from(fileReference: FileReference | URL, content: string | ArrayBufferView): CFileResource;
|
|
24
|
+
static from(url: URL, content: string | ArrayBufferView, encoding?: BufferEncoding | undefined, baseFilename?: string | undefined, gz?: boolean): CFileResource;
|
|
24
25
|
}
|
|
26
|
+
export declare function fromFileResource(fileResource: FileResource): TextFileResource;
|
|
27
|
+
export declare function renameFileResource(fileResource: FileResource, url: URL): FileResource;
|
|
25
28
|
//# sourceMappingURL=CFileResource.d.ts.map
|
|
@@ -43,8 +43,13 @@ export class CFileResource {
|
|
|
43
43
|
return obj instanceof CFileResource;
|
|
44
44
|
}
|
|
45
45
|
static from(urlOrFileResource, content, encoding, baseFilename, gz) {
|
|
46
|
-
if (CFileResource.isCFileResource(urlOrFileResource))
|
|
46
|
+
if (CFileResource.isCFileResource(urlOrFileResource)) {
|
|
47
|
+
if (content) {
|
|
48
|
+
const { url, encoding, baseFilename, gz } = urlOrFileResource;
|
|
49
|
+
return new CFileResource(url, content, encoding, baseFilename, gz);
|
|
50
|
+
}
|
|
47
51
|
return urlOrFileResource;
|
|
52
|
+
}
|
|
48
53
|
if (urlOrFileResource instanceof URL) {
|
|
49
54
|
assert(content !== undefined);
|
|
50
55
|
return new CFileResource(urlOrFileResource, content, encoding, baseFilename, gz);
|
|
@@ -58,4 +63,10 @@ export class CFileResource {
|
|
|
58
63
|
return new CFileResource(fileResource.url, fileResource.content, fileResource.encoding, fileResource.baseFilename, fileResource.gz);
|
|
59
64
|
}
|
|
60
65
|
}
|
|
66
|
+
export function fromFileResource(fileResource) {
|
|
67
|
+
return CFileResource.from(fileResource);
|
|
68
|
+
}
|
|
69
|
+
export function renameFileResource(fileResource, url) {
|
|
70
|
+
return CFileResource.from(url, fileResource.content, fileResource.encoding, fileResource.baseFilename, fileResource.gz);
|
|
71
|
+
}
|
|
61
72
|
//# sourceMappingURL=CFileResource.js.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export { CFileReference } from './CFileReference.js';
|
|
2
|
-
export { CFileResource } from './CFileResource.js';
|
|
1
|
+
export { CFileReference, renameFileReference } from './CFileReference.js';
|
|
2
|
+
export { CFileResource, fromFileResource as createTextFileResource, renameFileResource } from './CFileResource.js';
|
|
3
|
+
export { urlOrReferenceToUrl } from './urlOrReferenceToUrl.js';
|
|
3
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/common/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export { CFileReference } from './CFileReference.js';
|
|
2
|
-
export { CFileResource } from './CFileResource.js';
|
|
1
|
+
export { CFileReference, renameFileReference } from './CFileReference.js';
|
|
2
|
+
export { CFileResource, fromFileResource as createTextFileResource, renameFileResource } from './CFileResource.js';
|
|
3
|
+
export { urlOrReferenceToUrl } from './urlOrReferenceToUrl.js';
|
|
3
4
|
//# sourceMappingURL=index.js.map
|
|
@@ -8,11 +8,13 @@ import { encodeString, isGZipped } from '../../common/encode-decode.js';
|
|
|
8
8
|
import { CFileResource } from '../../common/index.js';
|
|
9
9
|
import { assert } from '../../errors/assert.js';
|
|
10
10
|
import { toError } from '../../errors/index.js';
|
|
11
|
+
import { FileType } from '../../models/index.js';
|
|
11
12
|
import { decodeDataUrl, guessMimeType, toDataUrl } from '../../node/dataUrl.js';
|
|
12
13
|
import { fetchURL } from '../../node/file/fetch.js';
|
|
13
14
|
import { getStatHttp } from '../../node/file/stat.js';
|
|
14
15
|
import { urlBasename } from '../../node/file/url.js';
|
|
15
16
|
import { RequestFsReadFile, RequestFsReadFileSync, RequestFsStat, RequestFsStatSync, RequestFsWriteFile, RequestZlibInflate, } from '../../requests/index.js';
|
|
17
|
+
import { RequestFsReadDirectory } from '../../requests/RequestFsReadDirectory.js';
|
|
16
18
|
const isGzFileRegExp = /\.gz($|[?#])/;
|
|
17
19
|
function isGzFile(url) {
|
|
18
20
|
return isGzFileRegExp.test(typeof url === 'string' ? url : url.pathname);
|
|
@@ -34,6 +36,14 @@ const handleRequestFsReadFile = RequestFsReadFile.createRequestHandler(({ params
|
|
|
34
36
|
* Handle Binary File Sync Reads
|
|
35
37
|
*/
|
|
36
38
|
const handleRequestFsReadFileSync = RequestFsReadFileSync.createRequestHandler(({ params }) => createResponse(CFileResource.from({ ...params, content: readFileSync(fileURLToPath(params.url)) })), undefined, 'Node: Sync Read Binary File.');
|
|
39
|
+
/**
|
|
40
|
+
* Handle Binary File Reads
|
|
41
|
+
*/
|
|
42
|
+
const handleRequestFsReadDirectory = RequestFsReadDirectory.createRequestHandler(({ params }) => {
|
|
43
|
+
return createResponse(fs
|
|
44
|
+
.readdir(fileURLToPath(params.url), { withFileTypes: true })
|
|
45
|
+
.then((entries) => direntToDirEntries(params.url, entries)));
|
|
46
|
+
}, undefined, 'Node: Read Directory.');
|
|
37
47
|
/**
|
|
38
48
|
* Handle deflating gzip data
|
|
39
49
|
*/
|
|
@@ -74,7 +84,17 @@ const handleRequestFsReadFileData = RequestFsReadFile.createRequestHandler((req,
|
|
|
74
84
|
/**
|
|
75
85
|
* Handle fs:stat
|
|
76
86
|
*/
|
|
77
|
-
const handleRequestFsStat = RequestFsStat.createRequestHandler(({ params }) => createResponse(fs.stat(fileURLToPath(params.url))), undefined, 'Node: fs.stat.');
|
|
87
|
+
const handleRequestFsStat = RequestFsStat.createRequestHandler(({ params }) => createResponse(toPromiseStats(fs.stat(fileURLToPath(params.url)))), undefined, 'Node: fs.stat.');
|
|
88
|
+
function toStats(stat) {
|
|
89
|
+
return {
|
|
90
|
+
size: stat.size,
|
|
91
|
+
mtimeMs: stat.mtimeMs,
|
|
92
|
+
fileType: toFileType(stat),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function toPromiseStats(pStat) {
|
|
96
|
+
return pStat.then(toStats);
|
|
97
|
+
}
|
|
78
98
|
/**
|
|
79
99
|
* Handle fs:statSync
|
|
80
100
|
*/
|
|
@@ -158,6 +178,7 @@ export function registerHandlers(serviceBus) {
|
|
|
158
178
|
handleRequestFsReadFileHttp,
|
|
159
179
|
handleRequestFsReadFileData,
|
|
160
180
|
handleRequestFsReadFileSyncData,
|
|
181
|
+
handleRequestFsReadDirectory,
|
|
161
182
|
handleRequestZlibInflate,
|
|
162
183
|
handleRequestFsStatSync,
|
|
163
184
|
handleRequestFsStat,
|
|
@@ -173,4 +194,20 @@ function encodeContent(ref, content) {
|
|
|
173
194
|
}
|
|
174
195
|
return arrayBufferViewToBuffer(content);
|
|
175
196
|
}
|
|
197
|
+
function mapperDirentToDirEntry(dir) {
|
|
198
|
+
return (dirent) => direntToDirEntry(dir, dirent);
|
|
199
|
+
}
|
|
200
|
+
function direntToDirEntries(dir, dirent) {
|
|
201
|
+
return dirent.map(mapperDirentToDirEntry(dir));
|
|
202
|
+
}
|
|
203
|
+
function direntToDirEntry(dir, dirent) {
|
|
204
|
+
return {
|
|
205
|
+
name: dirent.name,
|
|
206
|
+
dir,
|
|
207
|
+
fileType: toFileType(dirent),
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function toFileType(statLike) {
|
|
211
|
+
return statLike.isFile() ? FileType.File : statLike.isDirectory() ? FileType.Directory : FileType.Unknown;
|
|
212
|
+
}
|
|
176
213
|
//# sourceMappingURL=file.js.map
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
export { toArray as asyncIterableToArray } from './async/asyncIterable.js';
|
|
2
2
|
export * from './common/index.js';
|
|
3
|
+
export { createTextFileResource } from './common/index.js';
|
|
3
4
|
export type { CSpellIO } from './CSpellIO.js';
|
|
4
5
|
export { CSpellIONode, getDefaultCSpellIO } from './CSpellIONode.js';
|
|
5
6
|
export { getStat, getStatSync, readFileText, readFileTextSync, writeToFile, writeToFileIterable, writeToFileIterableP, } from './file/index.js';
|
|
6
7
|
export type { BufferEncoding, TextEncoding } from './models/BufferEncoding.js';
|
|
7
8
|
export type { Stats } from './models/Stats.js';
|
|
8
9
|
export { encodeDataUrl, toDataUrl } from './node/dataUrl.js';
|
|
10
|
+
export { isFileURL, isUrlLike, toFileURL, toURL, urlBasename, urlDirname } from './node/file/url.js';
|
|
11
|
+
export type { VFileSystem as VFileSystem, VFileSystemProvider, VfsDirEntry, VfsStat, VirtualFS } from './VirtualFS.js';
|
|
12
|
+
export { createVirtualFS, FSCapabilityFlags, getDefaultVirtualFs } from './VirtualFS.js';
|
|
13
|
+
export { createRedirectProvider } from './VirtualFS/redirectProvider.js';
|
|
9
14
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export { toArray as asyncIterableToArray } from './async/asyncIterable.js';
|
|
2
2
|
export * from './common/index.js';
|
|
3
|
+
export { createTextFileResource } from './common/index.js';
|
|
3
4
|
export { CSpellIONode, getDefaultCSpellIO } from './CSpellIONode.js';
|
|
4
5
|
export { getStat, getStatSync, readFileText, readFileTextSync, writeToFile, writeToFileIterable, writeToFileIterableP, } from './file/index.js';
|
|
5
6
|
export { encodeDataUrl, toDataUrl } from './node/dataUrl.js';
|
|
7
|
+
export { isFileURL, isUrlLike, toFileURL, toURL, urlBasename, urlDirname } from './node/file/url.js';
|
|
8
|
+
export { createVirtualFS, FSCapabilityFlags, getDefaultVirtualFs } from './VirtualFS.js';
|
|
9
|
+
export { createRedirectProvider } from './VirtualFS/redirectProvider.js';
|
|
6
10
|
//# sourceMappingURL=index.js.map
|
|
@@ -20,13 +20,13 @@ export interface FileReference {
|
|
|
20
20
|
*/
|
|
21
21
|
readonly gz?: boolean | undefined;
|
|
22
22
|
}
|
|
23
|
-
export interface
|
|
23
|
+
export interface FileResource extends FileReference {
|
|
24
24
|
/**
|
|
25
25
|
* The contents of the file
|
|
26
26
|
*/
|
|
27
27
|
readonly content: string | ArrayBufferView;
|
|
28
28
|
}
|
|
29
|
-
export interface
|
|
29
|
+
export interface TextFileResource extends FileResource {
|
|
30
30
|
getText(): string;
|
|
31
31
|
}
|
|
32
32
|
export type UrlOrFilename = string | URL;
|
|
@@ -14,5 +14,28 @@ export interface Stats {
|
|
|
14
14
|
* Used by web requests to see if a resource has changed.
|
|
15
15
|
*/
|
|
16
16
|
eTag?: string | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* The file type.
|
|
19
|
+
*/
|
|
20
|
+
fileType?: FileType | undefined;
|
|
21
|
+
}
|
|
22
|
+
export declare enum FileType {
|
|
23
|
+
/**
|
|
24
|
+
* The file type is unknown.
|
|
25
|
+
*/
|
|
26
|
+
Unknown = 0,
|
|
27
|
+
/**
|
|
28
|
+
* A regular file.
|
|
29
|
+
*/
|
|
30
|
+
File = 1,
|
|
31
|
+
/**
|
|
32
|
+
* A directory.
|
|
33
|
+
*/
|
|
34
|
+
Directory = 2
|
|
35
|
+
}
|
|
36
|
+
export interface DirEntry {
|
|
37
|
+
name: string;
|
|
38
|
+
dir: URL;
|
|
39
|
+
fileType: FileType;
|
|
17
40
|
}
|
|
18
41
|
//# sourceMappingURL=Stats.d.ts.map
|
package/dist/esm/models/Stats.js
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export var FileType;
|
|
2
|
+
(function (FileType) {
|
|
3
|
+
/**
|
|
4
|
+
* The file type is unknown.
|
|
5
|
+
*/
|
|
6
|
+
FileType[FileType["Unknown"] = 0] = "Unknown";
|
|
7
|
+
/**
|
|
8
|
+
* A regular file.
|
|
9
|
+
*/
|
|
10
|
+
FileType[FileType["File"] = 1] = "File";
|
|
11
|
+
/**
|
|
12
|
+
* A directory.
|
|
13
|
+
*/
|
|
14
|
+
FileType[FileType["Directory"] = 2] = "Directory";
|
|
15
|
+
})(FileType || (FileType = {}));
|
|
5
16
|
//# sourceMappingURL=Stats.js.map
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
export type {
|
|
1
|
+
export type { BufferEncoding, TextEncoding } from './BufferEncoding.js';
|
|
2
|
+
export type { Disposable } from './disposable.js';
|
|
3
|
+
export type { FileReference, FileResource, TextFileResource, UrlOrReference } from './FileResource.js';
|
|
4
|
+
export type { DirEntry, Stats } from './Stats.js';
|
|
5
|
+
export { FileType } from './Stats.js';
|
|
2
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/models/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export { FileType } from './Stats.js';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -26,6 +26,7 @@ export declare function toURL(filenameOrUrl: string | URL, relativeTo?: string |
|
|
|
26
26
|
export declare function urlBasename(url: string | URL): string;
|
|
27
27
|
/**
|
|
28
28
|
* Try to determine the parent directory URL of the uri.
|
|
29
|
+
* If it is not a hierarchical URL, then it will return the URL.
|
|
29
30
|
* @param url - url to extract the dirname from.
|
|
30
31
|
* @returns a URL
|
|
31
32
|
*/
|
|
@@ -36,4 +37,5 @@ export declare function urlDirname(url: string | URL): URL;
|
|
|
36
37
|
* @returns
|
|
37
38
|
*/
|
|
38
39
|
export declare function basename(path: string): string;
|
|
40
|
+
export declare function normalizePathForUrl(filePath: string): string;
|
|
39
41
|
//# sourceMappingURL=url.d.ts.map
|