vscode-fs 0.0.5 → 0.0.7
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 +48 -26
- package/dist/index.d.cts +11 -0
- package/dist/index.d.mts +11 -0
- package/dist/index.mjs +48 -26
- package/package.json +4 -1
package/dist/index.cjs
CHANGED
|
@@ -167,11 +167,12 @@ function joinPath(basePath, ...segments) {
|
|
|
167
167
|
return vscode_uri.Utils.joinPath(vscode_uri.URI.file(basePath), ...segments).fsPath;
|
|
168
168
|
}
|
|
169
169
|
async function createNodeFileSystem() {
|
|
170
|
-
const [fs, trash, glob, watch] = await Promise.all([
|
|
170
|
+
const [fs, trash, glob, watch, stream] = await Promise.all([
|
|
171
171
|
import("node:fs"),
|
|
172
172
|
import("trash").then((m) => m.default),
|
|
173
173
|
import("tinyglobby").then((m) => m.glob),
|
|
174
|
-
import("chokidar").then((m) => m.watch)
|
|
174
|
+
import("chokidar").then((m) => m.watch),
|
|
175
|
+
import("node:stream")
|
|
175
176
|
]);
|
|
176
177
|
async function resolveFileType(path) {
|
|
177
178
|
const lstats = await fs.promises.lstat(path);
|
|
@@ -330,35 +331,56 @@ async function createNodeFileSystem() {
|
|
|
330
331
|
const watcher = watch(pattern.pattern, { cwd: pattern.baseUri.fsPath });
|
|
331
332
|
return new Promise((resolve) => {
|
|
332
333
|
watcher.on("ready", () => {
|
|
333
|
-
const
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
if (options?.
|
|
337
|
-
|
|
338
|
-
if (options?.ignoreDeleteEvents !== true) watcher.on("unlink", (path) => onDidDeleteListeners.forEach((listener) => listener(vscode_uri.URI.file(path))));
|
|
339
|
-
resolve({
|
|
340
|
-
ignoreChangeEvents: options?.ignoreChangeEvents ?? false,
|
|
341
|
-
ignoreCreateEvents: options?.ignoreCreateEvents ?? false,
|
|
342
|
-
ignoreDeleteEvents: options?.ignoreDeleteEvents ?? false,
|
|
343
|
-
onDidCreate: (listener) => {
|
|
344
|
-
onDidCreateListeners.add(listener);
|
|
345
|
-
return { dispose: () => onDidCreateListeners.delete(listener) };
|
|
346
|
-
},
|
|
347
|
-
onDidChange: (listener) => {
|
|
348
|
-
onDidChangeListeners.add(listener);
|
|
349
|
-
return { dispose: () => onDidChangeListeners.delete(listener) };
|
|
350
|
-
},
|
|
351
|
-
onDidDelete: (listener) => {
|
|
352
|
-
onDidDeleteListeners.add(listener);
|
|
353
|
-
return { dispose: () => onDidDeleteListeners.delete(listener) };
|
|
354
|
-
},
|
|
355
|
-
dispose: () => watcher.close()
|
|
356
|
-
});
|
|
334
|
+
const fileSystemWatcher = new NodeFileSystemWatcherImpl(watcher, options);
|
|
335
|
+
if (options?.ignoreChangeEvents !== true) watcher.on("add", (path) => fileSystemWatcher.onDidCreateListeners.forEach((listener) => listener(vscode_uri.URI.file(path))));
|
|
336
|
+
if (options?.ignoreChangeEvents !== true) watcher.on("change", (path) => fileSystemWatcher.onDidChangeListeners.forEach((listener) => listener(vscode_uri.URI.file(path))));
|
|
337
|
+
if (options?.ignoreDeleteEvents !== true) watcher.on("unlink", (path) => fileSystemWatcher.onDidDeleteListeners.forEach((listener) => listener(vscode_uri.URI.file(path))));
|
|
338
|
+
resolve(fileSystemWatcher);
|
|
357
339
|
});
|
|
358
340
|
});
|
|
341
|
+
},
|
|
342
|
+
createWritableStream: async (uri) => {
|
|
343
|
+
const writableStream = fs.createWriteStream(uri.fsPath);
|
|
344
|
+
return stream.Writable.toWeb(writableStream);
|
|
359
345
|
}
|
|
360
346
|
};
|
|
361
347
|
}
|
|
348
|
+
var NodeFileSystemWatcherImpl = class {
|
|
349
|
+
constructor(watcher, options) {
|
|
350
|
+
this.watcher = watcher;
|
|
351
|
+
this.options = options;
|
|
352
|
+
}
|
|
353
|
+
get ignoreChangeEvents() {
|
|
354
|
+
return this.options?.ignoreChangeEvents ?? false;
|
|
355
|
+
}
|
|
356
|
+
get ignoreCreateEvents() {
|
|
357
|
+
return this.options?.ignoreCreateEvents ?? false;
|
|
358
|
+
}
|
|
359
|
+
get ignoreDeleteEvents() {
|
|
360
|
+
return this.options?.ignoreDeleteEvents ?? false;
|
|
361
|
+
}
|
|
362
|
+
get isDisposed() {
|
|
363
|
+
return this.watcher.closed;
|
|
364
|
+
}
|
|
365
|
+
onDidCreateListeners = /* @__PURE__ */ new Set();
|
|
366
|
+
onDidChangeListeners = /* @__PURE__ */ new Set();
|
|
367
|
+
onDidDeleteListeners = /* @__PURE__ */ new Set();
|
|
368
|
+
onDidCreate(listener) {
|
|
369
|
+
this.onDidCreateListeners.add(listener);
|
|
370
|
+
return { dispose: () => this.onDidCreateListeners.delete(listener) };
|
|
371
|
+
}
|
|
372
|
+
onDidChange(listener) {
|
|
373
|
+
this.onDidChangeListeners.add(listener);
|
|
374
|
+
return { dispose: () => this.onDidChangeListeners.delete(listener) };
|
|
375
|
+
}
|
|
376
|
+
onDidDelete(listener) {
|
|
377
|
+
this.onDidDeleteListeners.add(listener);
|
|
378
|
+
return { dispose: () => this.onDidDeleteListeners.delete(listener) };
|
|
379
|
+
}
|
|
380
|
+
dispose() {
|
|
381
|
+
this.watcher.close();
|
|
382
|
+
}
|
|
383
|
+
};
|
|
362
384
|
|
|
363
385
|
//#endregion
|
|
364
386
|
Object.defineProperty(exports, 'FileSystemError', {
|
package/dist/index.d.cts
CHANGED
|
@@ -232,6 +232,13 @@ interface FileSystem {
|
|
|
232
232
|
*/
|
|
233
233
|
ignoreDeleteEvents?: boolean;
|
|
234
234
|
}): Promise<FileSystemWatcher>;
|
|
235
|
+
/**
|
|
236
|
+
* Create a writer for a file.
|
|
237
|
+
*
|
|
238
|
+
* @param uri The uri of the file to write to.
|
|
239
|
+
* @returns A writer for the file.
|
|
240
|
+
*/
|
|
241
|
+
createWritableStream(uri: URI): Promise<WritableStream<Uint8Array>>;
|
|
235
242
|
}
|
|
236
243
|
interface Disposable {
|
|
237
244
|
/** Dispose resources. */
|
|
@@ -260,6 +267,10 @@ interface FileSystemWatcher extends Disposable {
|
|
|
260
267
|
* it ignores delete file system events.
|
|
261
268
|
*/
|
|
262
269
|
readonly ignoreDeleteEvents: boolean;
|
|
270
|
+
/**
|
|
271
|
+
* true if this file system watcher has been disposed.
|
|
272
|
+
*/
|
|
273
|
+
readonly isDisposed: boolean;
|
|
263
274
|
/**
|
|
264
275
|
* An event which fires on file/folder creation.
|
|
265
276
|
*/
|
package/dist/index.d.mts
CHANGED
|
@@ -232,6 +232,13 @@ interface FileSystem {
|
|
|
232
232
|
*/
|
|
233
233
|
ignoreDeleteEvents?: boolean;
|
|
234
234
|
}): Promise<FileSystemWatcher>;
|
|
235
|
+
/**
|
|
236
|
+
* Create a writer for a file.
|
|
237
|
+
*
|
|
238
|
+
* @param uri The uri of the file to write to.
|
|
239
|
+
* @returns A writer for the file.
|
|
240
|
+
*/
|
|
241
|
+
createWritableStream(uri: URI): Promise<WritableStream<Uint8Array>>;
|
|
235
242
|
}
|
|
236
243
|
interface Disposable {
|
|
237
244
|
/** Dispose resources. */
|
|
@@ -260,6 +267,10 @@ interface FileSystemWatcher extends Disposable {
|
|
|
260
267
|
* it ignores delete file system events.
|
|
261
268
|
*/
|
|
262
269
|
readonly ignoreDeleteEvents: boolean;
|
|
270
|
+
/**
|
|
271
|
+
* true if this file system watcher has been disposed.
|
|
272
|
+
*/
|
|
273
|
+
readonly isDisposed: boolean;
|
|
263
274
|
/**
|
|
264
275
|
* An event which fires on file/folder creation.
|
|
265
276
|
*/
|
package/dist/index.mjs
CHANGED
|
@@ -166,11 +166,12 @@ function joinPath(basePath, ...segments) {
|
|
|
166
166
|
return Utils.joinPath(URI.file(basePath), ...segments).fsPath;
|
|
167
167
|
}
|
|
168
168
|
async function createNodeFileSystem() {
|
|
169
|
-
const [fs, trash, glob, watch] = await Promise.all([
|
|
169
|
+
const [fs, trash, glob, watch, stream] = await Promise.all([
|
|
170
170
|
import("node:fs"),
|
|
171
171
|
import("trash").then((m) => m.default),
|
|
172
172
|
import("tinyglobby").then((m) => m.glob),
|
|
173
|
-
import("chokidar").then((m) => m.watch)
|
|
173
|
+
import("chokidar").then((m) => m.watch),
|
|
174
|
+
import("node:stream")
|
|
174
175
|
]);
|
|
175
176
|
async function resolveFileType(path) {
|
|
176
177
|
const lstats = await fs.promises.lstat(path);
|
|
@@ -329,35 +330,56 @@ async function createNodeFileSystem() {
|
|
|
329
330
|
const watcher = watch(pattern.pattern, { cwd: pattern.baseUri.fsPath });
|
|
330
331
|
return new Promise((resolve) => {
|
|
331
332
|
watcher.on("ready", () => {
|
|
332
|
-
const
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
if (options?.
|
|
336
|
-
|
|
337
|
-
if (options?.ignoreDeleteEvents !== true) watcher.on("unlink", (path) => onDidDeleteListeners.forEach((listener) => listener(URI.file(path))));
|
|
338
|
-
resolve({
|
|
339
|
-
ignoreChangeEvents: options?.ignoreChangeEvents ?? false,
|
|
340
|
-
ignoreCreateEvents: options?.ignoreCreateEvents ?? false,
|
|
341
|
-
ignoreDeleteEvents: options?.ignoreDeleteEvents ?? false,
|
|
342
|
-
onDidCreate: (listener) => {
|
|
343
|
-
onDidCreateListeners.add(listener);
|
|
344
|
-
return { dispose: () => onDidCreateListeners.delete(listener) };
|
|
345
|
-
},
|
|
346
|
-
onDidChange: (listener) => {
|
|
347
|
-
onDidChangeListeners.add(listener);
|
|
348
|
-
return { dispose: () => onDidChangeListeners.delete(listener) };
|
|
349
|
-
},
|
|
350
|
-
onDidDelete: (listener) => {
|
|
351
|
-
onDidDeleteListeners.add(listener);
|
|
352
|
-
return { dispose: () => onDidDeleteListeners.delete(listener) };
|
|
353
|
-
},
|
|
354
|
-
dispose: () => watcher.close()
|
|
355
|
-
});
|
|
333
|
+
const fileSystemWatcher = new NodeFileSystemWatcherImpl(watcher, options);
|
|
334
|
+
if (options?.ignoreChangeEvents !== true) watcher.on("add", (path) => fileSystemWatcher.onDidCreateListeners.forEach((listener) => listener(URI.file(path))));
|
|
335
|
+
if (options?.ignoreChangeEvents !== true) watcher.on("change", (path) => fileSystemWatcher.onDidChangeListeners.forEach((listener) => listener(URI.file(path))));
|
|
336
|
+
if (options?.ignoreDeleteEvents !== true) watcher.on("unlink", (path) => fileSystemWatcher.onDidDeleteListeners.forEach((listener) => listener(URI.file(path))));
|
|
337
|
+
resolve(fileSystemWatcher);
|
|
356
338
|
});
|
|
357
339
|
});
|
|
340
|
+
},
|
|
341
|
+
createWritableStream: async (uri) => {
|
|
342
|
+
const writableStream = fs.createWriteStream(uri.fsPath);
|
|
343
|
+
return stream.Writable.toWeb(writableStream);
|
|
358
344
|
}
|
|
359
345
|
};
|
|
360
346
|
}
|
|
347
|
+
var NodeFileSystemWatcherImpl = class {
|
|
348
|
+
constructor(watcher, options) {
|
|
349
|
+
this.watcher = watcher;
|
|
350
|
+
this.options = options;
|
|
351
|
+
}
|
|
352
|
+
get ignoreChangeEvents() {
|
|
353
|
+
return this.options?.ignoreChangeEvents ?? false;
|
|
354
|
+
}
|
|
355
|
+
get ignoreCreateEvents() {
|
|
356
|
+
return this.options?.ignoreCreateEvents ?? false;
|
|
357
|
+
}
|
|
358
|
+
get ignoreDeleteEvents() {
|
|
359
|
+
return this.options?.ignoreDeleteEvents ?? false;
|
|
360
|
+
}
|
|
361
|
+
get isDisposed() {
|
|
362
|
+
return this.watcher.closed;
|
|
363
|
+
}
|
|
364
|
+
onDidCreateListeners = /* @__PURE__ */ new Set();
|
|
365
|
+
onDidChangeListeners = /* @__PURE__ */ new Set();
|
|
366
|
+
onDidDeleteListeners = /* @__PURE__ */ new Set();
|
|
367
|
+
onDidCreate(listener) {
|
|
368
|
+
this.onDidCreateListeners.add(listener);
|
|
369
|
+
return { dispose: () => this.onDidCreateListeners.delete(listener) };
|
|
370
|
+
}
|
|
371
|
+
onDidChange(listener) {
|
|
372
|
+
this.onDidChangeListeners.add(listener);
|
|
373
|
+
return { dispose: () => this.onDidChangeListeners.delete(listener) };
|
|
374
|
+
}
|
|
375
|
+
onDidDelete(listener) {
|
|
376
|
+
this.onDidDeleteListeners.add(listener);
|
|
377
|
+
return { dispose: () => this.onDidDeleteListeners.delete(listener) };
|
|
378
|
+
}
|
|
379
|
+
dispose() {
|
|
380
|
+
this.watcher.close();
|
|
381
|
+
}
|
|
382
|
+
};
|
|
361
383
|
|
|
362
384
|
//#endregion
|
|
363
385
|
export { FileSystemError, FileSystemProviderErrorCode, FileType, RelativePattern, createFileSystemError, createNodeFileSystem, toFileSystemError };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vscode-fs",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.7",
|
|
5
5
|
"description": "VSCode like simple、serializable and cross-platform file system utilities.",
|
|
6
6
|
"author": "Naily Zero <zero@naily.cc> (https://naily.cc)",
|
|
7
7
|
"license": "MIT",
|
|
@@ -41,6 +41,9 @@
|
|
|
41
41
|
"files": [
|
|
42
42
|
"dist"
|
|
43
43
|
],
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=17.0.0"
|
|
46
|
+
},
|
|
44
47
|
"peerDependencies": {
|
|
45
48
|
"vscode-uri": "^3.1.0"
|
|
46
49
|
},
|