vscode-fs 0.0.10 → 0.1.1

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.cjs CHANGED
@@ -1,416 +1,16 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- let vscode_uri = require("vscode-uri");
2
+ const require_node = require('./node-BV_ucnay.cjs');
3
3
 
4
- //#region src/types.ts
5
- /**
6
- * Enumeration of file types. The types `File` and `Directory` can also be
7
- * a symbolic links, in that case use `FileType.File | FileType.SymbolicLink` and
8
- * `FileType.Directory | FileType.SymbolicLink`.
9
- */
10
- let FileType = /* @__PURE__ */ function(FileType) {
11
- /**
12
- * The file type is unknown.
13
- */
14
- FileType[FileType["Unknown"] = 0] = "Unknown";
15
- /**
16
- * A regular file.
17
- */
18
- FileType[FileType["File"] = 1] = "File";
19
- /**
20
- * A directory.
21
- */
22
- FileType[FileType["Directory"] = 2] = "Directory";
23
- /**
24
- * A symbolic link to a file.
25
- */
26
- FileType[FileType["SymbolicLink"] = 64] = "SymbolicLink";
27
- return FileType;
28
- }({});
29
- /**
30
- * The flags to use for the file.
31
- */
32
- let WriteableFlags = /* @__PURE__ */ function(WriteableFlags) {
33
- /**
34
- * Append to the file.
35
- */
36
- WriteableFlags["Append"] = "a";
37
- return WriteableFlags;
38
- }({});
39
- let FileSystemError;
40
- (function(_FileSystemError) {
41
- function isFileSystemError(error) {
42
- return error instanceof FileSystemErrorImpl;
43
- }
44
- _FileSystemError.isFileSystemError = isFileSystemError;
45
- })(FileSystemError || (FileSystemError = {}));
46
- let FileSystemProviderErrorCode = /* @__PURE__ */ function(FileSystemProviderErrorCode) {
47
- FileSystemProviderErrorCode["FileExists"] = "EntryExists";
48
- FileSystemProviderErrorCode["FileNotFound"] = "EntryNotFound";
49
- FileSystemProviderErrorCode["FileNotADirectory"] = "EntryNotADirectory";
50
- FileSystemProviderErrorCode["FileIsADirectory"] = "EntryIsADirectory";
51
- FileSystemProviderErrorCode["FileExceedsStorageQuota"] = "EntryExceedsStorageQuota";
52
- FileSystemProviderErrorCode["FileTooLarge"] = "EntryTooLarge";
53
- FileSystemProviderErrorCode["FileWriteLocked"] = "EntryWriteLocked";
54
- FileSystemProviderErrorCode["NoPermissions"] = "NoPermissions";
55
- FileSystemProviderErrorCode["Unavailable"] = "Unavailable";
56
- FileSystemProviderErrorCode["Unknown"] = "Unknown";
57
- return FileSystemProviderErrorCode;
58
- }({});
59
- /**
60
- * A relative pattern is a helper to construct glob patterns that are matched
61
- * relatively to a base file path. The base path can either be an absolute file
62
- * path as string or uri or a {@link WorkspaceFolder workspace folder}, which is the
63
- * preferred way of creating the relative pattern.
64
- */
65
- var RelativePattern = class {
66
- /**
67
- * A base file path to which this pattern will be matched against relatively. The
68
- * file path must be absolute, should not have any trailing path separators and
69
- * not include any relative segments (`.` or `..`).
70
- */
71
- baseUri;
72
- /**
73
- * A file glob pattern like `*.{ts,js}` that will be matched on file paths
74
- * relative to the base path.
75
- *
76
- * Example: Given a base of `/home/work/folder` and a file path of `/home/work/folder/index.js`,
77
- * the file glob pattern will match on `index.js`.
78
- */
79
- pattern;
80
- /**
81
- * Creates a new relative pattern object with a base file path and pattern to match. This pattern
82
- * will be matched on file paths relative to the base.
83
- *
84
- * Example:
85
- * ```ts
86
- * const folder = vscode.workspace.workspaceFolders?.[0];
87
- * if (folder) {
88
- *
89
- * // Match any TypeScript file in the root of this workspace folder
90
- * const pattern1 = new vscode.RelativePattern(folder, '*.ts');
91
- *
92
- * // Match any TypeScript file in `someFolder` inside this workspace folder
93
- * const pattern2 = new vscode.RelativePattern(folder, 'someFolder/*.ts');
94
- * }
95
- * ```
96
- *
97
- * @param base A base to which this pattern will be matched against relatively. It is recommended
98
- * to pass in a {@link WorkspaceFolder workspace folder} if the pattern should match inside the workspace.
99
- * Otherwise, a uri or string should only be used if the pattern is for a file path outside the workspace.
100
- * @param pattern A file glob pattern like `*.{ts,js}` that will be matched on paths relative to the base.
101
- */
102
- constructor(base, pattern) {
103
- this.baseUri = base;
104
- this.pattern = pattern;
105
- }
106
- };
107
-
108
- //#endregion
109
- //#region src/error.ts
110
- var FileSystemErrorImpl = class FileSystemErrorImpl extends Error {
111
- static create(error, code) {
112
- const providerError = new FileSystemErrorImpl(error.toString(), code);
113
- this.markAsFileSystemProviderError(providerError, code);
114
- return providerError;
115
- }
116
- static markAsFileSystemProviderError(error, code) {
117
- error.name = code ? `${code} (FileSystemError)` : `FileSystemError`;
118
- return error;
119
- }
120
- constructor(message, code) {
121
- super(message);
122
- this.code = code;
123
- }
124
- };
125
- function createFileSystemError(error, code) {
126
- return FileSystemErrorImpl.create(error, code);
127
- }
128
- function toFileSystemError(error) {
129
- let resultError = error;
130
- let code;
131
- switch (error.code) {
132
- case "ENOENT":
133
- code = FileSystemProviderErrorCode.FileNotFound;
134
- break;
135
- case "EISDIR":
136
- code = FileSystemProviderErrorCode.FileIsADirectory;
137
- break;
138
- case "ENOTDIR":
139
- code = FileSystemProviderErrorCode.FileNotADirectory;
140
- break;
141
- case "EEXIST":
142
- code = FileSystemProviderErrorCode.FileExists;
143
- break;
144
- case "EPERM":
145
- case "EACCES":
146
- code = FileSystemProviderErrorCode.NoPermissions;
147
- break;
148
- case "ERR_UNC_HOST_NOT_ALLOWED":
149
- resultError = `${error.message}. Please update the 'security.allowedUNCHosts' setting if you want to allow this host.`;
150
- code = FileSystemProviderErrorCode.Unknown;
151
- break;
152
- default: code = FileSystemProviderErrorCode.Unknown;
153
- }
154
- return createFileSystemError(resultError, code);
155
- }
156
-
157
- //#endregion
158
- //#region src/node.ts
159
- function isErrnoException(err) {
160
- return err !== null && typeof err === "object" && "code" in err;
161
- }
162
- function toFileType(stats) {
163
- if (stats.isFile()) return FileType.File;
164
- if (stats.isDirectory()) return FileType.Directory;
165
- if (stats.isSymbolicLink()) return FileType.SymbolicLink;
166
- return FileType.Unknown;
167
- }
168
- async function wrap(fn) {
169
- try {
170
- return await fn();
171
- } catch (error) {
172
- if (FileSystemError.isFileSystemError(error)) throw error;
173
- throw toFileSystemError(error);
174
- }
175
- }
176
- function joinPath(basePath, ...segments) {
177
- return vscode_uri.Utils.joinPath(vscode_uri.URI.file(basePath), ...segments).fsPath;
178
- }
179
- async function createNodeFileSystem() {
180
- const [fs, trash, glob, watch, stream] = await Promise.all([
181
- import("node:fs"),
182
- import("trash").then((m) => m.default),
183
- import("tinyglobby").then((m) => m.glob),
184
- import("chokidar").then((m) => m.watch),
185
- import("node:stream")
186
- ]);
187
- async function resolveFileType(path) {
188
- const lstats = await fs.promises.lstat(path);
189
- if (!lstats.isSymbolicLink()) return {
190
- type: toFileType(lstats),
191
- stats: lstats
192
- };
193
- let targetStats = null;
194
- try {
195
- targetStats = await fs.promises.stat(path);
196
- } catch {}
197
- const baseType = targetStats ? toFileType(targetStats) : FileType.Unknown;
198
- const stats = targetStats ?? lstats;
199
- return {
200
- type: baseType | FileType.SymbolicLink,
201
- stats
202
- };
203
- }
204
- async function getEntryType(dirPath, entry) {
205
- if (!entry.isSymbolicLink()) return toFileType(entry);
206
- try {
207
- return toFileType(await fs.promises.stat(joinPath(dirPath, entry.name))) | FileType.SymbolicLink;
208
- } catch {
209
- return FileType.SymbolicLink;
210
- }
211
- }
212
- async function ensureTargetNotExists(path) {
213
- try {
214
- await fs.promises.access(path, fs.constants.F_OK);
215
- throw createFileSystemError(`File exists: ${path}`, FileSystemProviderErrorCode.FileExists);
216
- } catch (err) {
217
- if (isErrnoException(err) && err.code !== "ENOENT") throw err;
218
- }
219
- }
220
- async function copyRecursive(sourcePath, targetPath, overwrite) {
221
- const stats = await fs.promises.stat(sourcePath);
222
- if (stats.isFile()) {
223
- const mode = overwrite ? void 0 : fs.constants.COPYFILE_EXCL;
224
- await fs.promises.copyFile(sourcePath, targetPath, mode);
225
- return;
226
- }
227
- if (stats.isDirectory()) {
228
- if (!overwrite) await ensureTargetNotExists(targetPath);
229
- await fs.promises.mkdir(targetPath, { recursive: true });
230
- const entries = await fs.promises.readdir(sourcePath, { withFileTypes: true });
231
- for (const entry of entries) await copyRecursive(joinPath(sourcePath, entry.name), joinPath(targetPath, entry.name), overwrite);
232
- return;
233
- }
234
- throw createFileSystemError(`Unsupported file type: ${sourcePath}`, FileSystemProviderErrorCode.Unknown);
235
- }
236
- function pathToUris(pathToUris) {
237
- return pathToUris.map((path) => vscode_uri.URI.file(path));
238
- }
239
- return {
240
- stat: (uri) => wrap(async () => {
241
- const { type, stats } = await resolveFileType(uri.fsPath);
242
- return {
243
- type,
244
- ctime: stats.birthtime.getTime(),
245
- mtime: stats.mtime.getTime(),
246
- size: stats.size
247
- };
248
- }),
249
- readDirectory: (uri) => wrap(async () => {
250
- const entries = await fs.promises.readdir(uri.fsPath, { withFileTypes: true });
251
- return Promise.all(entries.map(async (entry) => [entry.name, await getEntryType(uri.fsPath, entry)]));
252
- }),
253
- createDirectory: (uri) => wrap(async () => {
254
- await fs.promises.mkdir(uri.fsPath, { recursive: true });
255
- }),
256
- readFile: (uri) => wrap(() => fs.promises.readFile(uri.fsPath)),
257
- writeFile: (uri, content) => wrap(() => fs.promises.writeFile(uri.fsPath, content)),
258
- delete: (uri, options) => wrap(async () => {
259
- if (options?.useTrash) await trash(uri.fsPath);
260
- else await fs.promises.rm(uri.fsPath, { recursive: options?.recursive ?? false });
261
- }),
262
- rename: (source, target, options) => wrap(async () => {
263
- if (options?.overwrite === false) await ensureTargetNotExists(target.fsPath);
264
- await fs.promises.rename(source.fsPath, target.fsPath);
265
- }),
266
- copy: (source, target, options) => wrap(async () => {
267
- const overwrite = options?.overwrite !== false;
268
- await copyRecursive(source.fsPath, target.fsPath, overwrite);
269
- }),
270
- isFile: async (uri) => {
271
- try {
272
- const { type, stats } = await resolveFileType(uri.fsPath);
273
- if (type !== FileType.File) return false;
274
- return {
275
- type,
276
- ctime: stats.birthtime.getTime(),
277
- mtime: stats.mtime.getTime(),
278
- size: stats.size
279
- };
280
- } catch {
281
- return false;
282
- }
283
- },
284
- isDirectory: async (uri) => {
285
- try {
286
- const { type, stats } = await resolveFileType(uri.fsPath);
287
- if (type !== FileType.Directory) return false;
288
- return {
289
- type,
290
- ctime: stats.birthtime.getTime(),
291
- mtime: stats.mtime.getTime(),
292
- size: stats.size
293
- };
294
- } catch {
295
- return false;
296
- }
297
- },
298
- isSymbolicLink: async (uri) => {
299
- try {
300
- const { type, stats } = await resolveFileType(uri.fsPath);
301
- if (type !== FileType.SymbolicLink) return false;
302
- return {
303
- type,
304
- ctime: stats.birthtime.getTime(),
305
- mtime: stats.mtime.getTime(),
306
- size: stats.size
307
- };
308
- } catch {
309
- return false;
310
- }
311
- },
312
- exists: async (uri) => {
313
- try {
314
- const { type, stats } = await resolveFileType(uri.fsPath);
315
- return {
316
- type,
317
- ctime: stats.birthtime.getTime(),
318
- mtime: stats.mtime.getTime(),
319
- size: stats.size
320
- };
321
- } catch {
322
- return false;
323
- }
324
- },
325
- glob: async (pattern, options) => {
326
- return pathToUris(await glob(pattern.pattern, {
327
- absolute: true,
328
- cwd: pattern.baseUri.fsPath,
329
- onlyFiles: options?.onlyFiles,
330
- onlyDirectories: options?.onlyDirectories,
331
- followSymbolicLinks: options?.followSymbolicLinks,
332
- ignore: options?.ignore,
333
- dot: options?.dot,
334
- expandDirectories: options?.expandDirectories,
335
- extglob: options?.extglob,
336
- deep: options?.deep,
337
- fs
338
- }));
339
- },
340
- createWatcher: async (pattern, options) => {
341
- const watcher = watch(pattern.pattern, { cwd: pattern.baseUri.fsPath });
342
- return new Promise((resolve) => {
343
- watcher.on("ready", () => {
344
- const fileSystemWatcher = new NodeFileSystemWatcherImpl(watcher, options);
345
- if (options?.ignoreChangeEvents !== true) watcher.on("add", (path) => fileSystemWatcher.onDidCreateListeners.forEach((listener) => listener(vscode_uri.URI.file(path))));
346
- if (options?.ignoreChangeEvents !== true) watcher.on("change", (path) => fileSystemWatcher.onDidChangeListeners.forEach((listener) => listener(vscode_uri.URI.file(path))));
347
- if (options?.ignoreDeleteEvents !== true) watcher.on("unlink", (path) => fileSystemWatcher.onDidDeleteListeners.forEach((listener) => listener(vscode_uri.URI.file(path))));
348
- resolve(fileSystemWatcher);
349
- });
350
- });
351
- },
352
- createWritableStream: async (uri, options) => {
353
- const writableStream = fs.createWriteStream(uri.fsPath, {
354
- ...options,
355
- encoding: options?.encoding,
356
- flags: options?.flags
357
- });
358
- return stream.Writable.toWeb(writableStream);
359
- },
360
- createReadableStream: async (uri) => {
361
- const readableStream = fs.createReadStream(uri.fsPath);
362
- return stream.Readable.toWeb(readableStream);
363
- }
364
- };
365
- }
366
- var NodeFileSystemWatcherImpl = class {
367
- constructor(watcher, options) {
368
- this.watcher = watcher;
369
- this.options = options;
370
- }
371
- get ignoreChangeEvents() {
372
- return this.options?.ignoreChangeEvents ?? false;
373
- }
374
- get ignoreCreateEvents() {
375
- return this.options?.ignoreCreateEvents ?? false;
376
- }
377
- get ignoreDeleteEvents() {
378
- return this.options?.ignoreDeleteEvents ?? false;
379
- }
380
- get isDisposed() {
381
- return this.watcher.closed;
382
- }
383
- onDidCreateListeners = /* @__PURE__ */ new Set();
384
- onDidChangeListeners = /* @__PURE__ */ new Set();
385
- onDidDeleteListeners = /* @__PURE__ */ new Set();
386
- onDidCreate(listener) {
387
- this.onDidCreateListeners.add(listener);
388
- return { dispose: () => this.onDidCreateListeners.delete(listener) };
389
- }
390
- onDidChange(listener) {
391
- this.onDidChangeListeners.add(listener);
392
- return { dispose: () => this.onDidChangeListeners.delete(listener) };
393
- }
394
- onDidDelete(listener) {
395
- this.onDidDeleteListeners.add(listener);
396
- return { dispose: () => this.onDidDeleteListeners.delete(listener) };
397
- }
398
- dispose() {
399
- this.watcher.close();
400
- }
401
- };
402
-
403
- //#endregion
404
4
  Object.defineProperty(exports, 'FileSystemError', {
405
5
  enumerable: true,
406
6
  get: function () {
407
- return FileSystemError;
7
+ return require_node.FileSystemError;
408
8
  }
409
9
  });
410
- exports.FileSystemProviderErrorCode = FileSystemProviderErrorCode;
411
- exports.FileType = FileType;
412
- exports.RelativePattern = RelativePattern;
413
- exports.WriteableFlags = WriteableFlags;
414
- exports.createFileSystemError = createFileSystemError;
415
- exports.createNodeFileSystem = createNodeFileSystem;
416
- exports.toFileSystemError = toFileSystemError;
10
+ exports.FileSystemProviderErrorCode = require_node.FileSystemProviderErrorCode;
11
+ exports.FileType = require_node.FileType;
12
+ exports.RelativePattern = require_node.RelativePattern;
13
+ exports.WriteableFlags = require_node.WriteableFlags;
14
+ exports.createFileSystemError = require_node.createFileSystemError;
15
+ exports.createNodeFileSystem = require_node.createNodeFileSystem;
16
+ exports.toFileSystemError = require_node.toFileSystemError;