vscode-fs 0.0.4 → 0.0.6
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 +51 -2
- package/dist/index.d.cts +65 -1
- package/dist/index.d.mts +65 -1
- package/dist/index.mjs +51 -2
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -167,10 +167,11 @@ 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] = await Promise.all([
|
|
170
|
+
const [fs, trash, glob, watch] = await Promise.all([
|
|
171
171
|
import("node:fs"),
|
|
172
172
|
import("trash").then((m) => m.default),
|
|
173
|
-
import("tinyglobby").then((m) => m.glob)
|
|
173
|
+
import("tinyglobby").then((m) => m.glob),
|
|
174
|
+
import("chokidar").then((m) => m.watch)
|
|
174
175
|
]);
|
|
175
176
|
async function resolveFileType(path) {
|
|
176
177
|
const lstats = await fs.promises.lstat(path);
|
|
@@ -324,9 +325,57 @@ async function createNodeFileSystem() {
|
|
|
324
325
|
deep: options?.deep,
|
|
325
326
|
fs
|
|
326
327
|
}));
|
|
328
|
+
},
|
|
329
|
+
createWatcher: async (pattern, options) => {
|
|
330
|
+
const watcher = watch(pattern.pattern, { cwd: pattern.baseUri.fsPath });
|
|
331
|
+
return new Promise((resolve) => {
|
|
332
|
+
watcher.on("ready", () => {
|
|
333
|
+
const fileSystemWatcher = new NodeFileSystemWatcherImpl(watcher, options);
|
|
334
|
+
if (options?.ignoreChangeEvents !== true) watcher.on("add", (path) => fileSystemWatcher.onDidCreateListeners.forEach((listener) => listener(vscode_uri.URI.file(path))));
|
|
335
|
+
if (options?.ignoreChangeEvents !== true) watcher.on("change", (path) => fileSystemWatcher.onDidChangeListeners.forEach((listener) => listener(vscode_uri.URI.file(path))));
|
|
336
|
+
if (options?.ignoreDeleteEvents !== true) watcher.on("unlink", (path) => fileSystemWatcher.onDidDeleteListeners.forEach((listener) => listener(vscode_uri.URI.file(path))));
|
|
337
|
+
resolve(fileSystemWatcher);
|
|
338
|
+
});
|
|
339
|
+
});
|
|
327
340
|
}
|
|
328
341
|
};
|
|
329
342
|
}
|
|
343
|
+
var NodeFileSystemWatcherImpl = class {
|
|
344
|
+
constructor(watcher, options) {
|
|
345
|
+
this.watcher = watcher;
|
|
346
|
+
this.options = options;
|
|
347
|
+
}
|
|
348
|
+
get ignoreChangeEvents() {
|
|
349
|
+
return this.options?.ignoreChangeEvents ?? false;
|
|
350
|
+
}
|
|
351
|
+
get ignoreCreateEvents() {
|
|
352
|
+
return this.options?.ignoreCreateEvents ?? false;
|
|
353
|
+
}
|
|
354
|
+
get ignoreDeleteEvents() {
|
|
355
|
+
return this.options?.ignoreDeleteEvents ?? false;
|
|
356
|
+
}
|
|
357
|
+
get isDisposed() {
|
|
358
|
+
return this.watcher.closed;
|
|
359
|
+
}
|
|
360
|
+
onDidCreateListeners = /* @__PURE__ */ new Set();
|
|
361
|
+
onDidChangeListeners = /* @__PURE__ */ new Set();
|
|
362
|
+
onDidDeleteListeners = /* @__PURE__ */ new Set();
|
|
363
|
+
onDidCreate(listener) {
|
|
364
|
+
this.onDidCreateListeners.add(listener);
|
|
365
|
+
return { dispose: () => this.onDidCreateListeners.delete(listener) };
|
|
366
|
+
}
|
|
367
|
+
onDidChange(listener) {
|
|
368
|
+
this.onDidChangeListeners.add(listener);
|
|
369
|
+
return { dispose: () => this.onDidChangeListeners.delete(listener) };
|
|
370
|
+
}
|
|
371
|
+
onDidDelete(listener) {
|
|
372
|
+
this.onDidDeleteListeners.add(listener);
|
|
373
|
+
return { dispose: () => this.onDidDeleteListeners.delete(listener) };
|
|
374
|
+
}
|
|
375
|
+
dispose() {
|
|
376
|
+
this.watcher.close();
|
|
377
|
+
}
|
|
378
|
+
};
|
|
330
379
|
|
|
331
380
|
//#endregion
|
|
332
381
|
Object.defineProperty(exports, 'FileSystemError', {
|
package/dist/index.d.cts
CHANGED
|
@@ -212,6 +212,70 @@ interface FileSystem {
|
|
|
212
212
|
*/
|
|
213
213
|
deep?: number;
|
|
214
214
|
}): Promise<URI[]>;
|
|
215
|
+
createWatcher(pattern: RelativePattern, options?: {
|
|
216
|
+
/**
|
|
217
|
+
* Ignore create events.
|
|
218
|
+
*
|
|
219
|
+
* @default false
|
|
220
|
+
*/
|
|
221
|
+
ignoreCreateEvents?: boolean;
|
|
222
|
+
/**
|
|
223
|
+
* Ignore change events.
|
|
224
|
+
*
|
|
225
|
+
* @default false
|
|
226
|
+
*/
|
|
227
|
+
ignoreChangeEvents?: boolean;
|
|
228
|
+
/**
|
|
229
|
+
* Ignore delete events.
|
|
230
|
+
*
|
|
231
|
+
* @default false
|
|
232
|
+
*/
|
|
233
|
+
ignoreDeleteEvents?: boolean;
|
|
234
|
+
}): Promise<FileSystemWatcher>;
|
|
235
|
+
}
|
|
236
|
+
interface Disposable {
|
|
237
|
+
/** Dispose resources. */
|
|
238
|
+
dispose(): unknown;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* A file system watcher notifies about changes to files and folders
|
|
242
|
+
* on disk or from other {@link FileSystemProvider FileSystemProviders}.
|
|
243
|
+
*
|
|
244
|
+
* To get an instance of a `FileSystemWatcher` use
|
|
245
|
+
* {@link workspace.createFileSystemWatcher createFileSystemWatcher}.
|
|
246
|
+
*/
|
|
247
|
+
interface FileSystemWatcher extends Disposable {
|
|
248
|
+
/**
|
|
249
|
+
* true if this file system watcher has been created such that
|
|
250
|
+
* it ignores creation file system events.
|
|
251
|
+
*/
|
|
252
|
+
readonly ignoreCreateEvents: boolean;
|
|
253
|
+
/**
|
|
254
|
+
* true if this file system watcher has been created such that
|
|
255
|
+
* it ignores change file system events.
|
|
256
|
+
*/
|
|
257
|
+
readonly ignoreChangeEvents: boolean;
|
|
258
|
+
/**
|
|
259
|
+
* true if this file system watcher has been created such that
|
|
260
|
+
* it ignores delete file system events.
|
|
261
|
+
*/
|
|
262
|
+
readonly ignoreDeleteEvents: boolean;
|
|
263
|
+
/**
|
|
264
|
+
* true if this file system watcher has been disposed.
|
|
265
|
+
*/
|
|
266
|
+
readonly isDisposed: boolean;
|
|
267
|
+
/**
|
|
268
|
+
* An event which fires on file/folder creation.
|
|
269
|
+
*/
|
|
270
|
+
onDidCreate(listener: (e: URI) => unknown): Disposable;
|
|
271
|
+
/**
|
|
272
|
+
* An event which fires on file/folder change.
|
|
273
|
+
*/
|
|
274
|
+
onDidChange(listener: (e: URI) => unknown): Disposable;
|
|
275
|
+
/**
|
|
276
|
+
* An event which fires on file/folder deletion.
|
|
277
|
+
*/
|
|
278
|
+
onDidDelete(listener: (e: URI) => unknown): Disposable;
|
|
215
279
|
}
|
|
216
280
|
/**
|
|
217
281
|
* The `FileStat`-type represents metadata about a file
|
|
@@ -337,4 +401,4 @@ declare function toFileSystemError(error: NodeJS.ErrnoException): FileSystemErro
|
|
|
337
401
|
//#region src/node.d.ts
|
|
338
402
|
declare function createNodeFileSystem(): Promise<FileSystem>;
|
|
339
403
|
//#endregion
|
|
340
|
-
export { FileStat, FileSystem, FileSystemError, FileSystemProviderErrorCode, FileType, IsDirectory, IsFile, IsSymbolicLink, RelativePattern, createFileSystemError, createNodeFileSystem, toFileSystemError };
|
|
404
|
+
export { Disposable, FileStat, FileSystem, FileSystemError, FileSystemProviderErrorCode, FileSystemWatcher, FileType, IsDirectory, IsFile, IsSymbolicLink, RelativePattern, createFileSystemError, createNodeFileSystem, toFileSystemError };
|
package/dist/index.d.mts
CHANGED
|
@@ -212,6 +212,70 @@ interface FileSystem {
|
|
|
212
212
|
*/
|
|
213
213
|
deep?: number;
|
|
214
214
|
}): Promise<URI[]>;
|
|
215
|
+
createWatcher(pattern: RelativePattern, options?: {
|
|
216
|
+
/**
|
|
217
|
+
* Ignore create events.
|
|
218
|
+
*
|
|
219
|
+
* @default false
|
|
220
|
+
*/
|
|
221
|
+
ignoreCreateEvents?: boolean;
|
|
222
|
+
/**
|
|
223
|
+
* Ignore change events.
|
|
224
|
+
*
|
|
225
|
+
* @default false
|
|
226
|
+
*/
|
|
227
|
+
ignoreChangeEvents?: boolean;
|
|
228
|
+
/**
|
|
229
|
+
* Ignore delete events.
|
|
230
|
+
*
|
|
231
|
+
* @default false
|
|
232
|
+
*/
|
|
233
|
+
ignoreDeleteEvents?: boolean;
|
|
234
|
+
}): Promise<FileSystemWatcher>;
|
|
235
|
+
}
|
|
236
|
+
interface Disposable {
|
|
237
|
+
/** Dispose resources. */
|
|
238
|
+
dispose(): unknown;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* A file system watcher notifies about changes to files and folders
|
|
242
|
+
* on disk or from other {@link FileSystemProvider FileSystemProviders}.
|
|
243
|
+
*
|
|
244
|
+
* To get an instance of a `FileSystemWatcher` use
|
|
245
|
+
* {@link workspace.createFileSystemWatcher createFileSystemWatcher}.
|
|
246
|
+
*/
|
|
247
|
+
interface FileSystemWatcher extends Disposable {
|
|
248
|
+
/**
|
|
249
|
+
* true if this file system watcher has been created such that
|
|
250
|
+
* it ignores creation file system events.
|
|
251
|
+
*/
|
|
252
|
+
readonly ignoreCreateEvents: boolean;
|
|
253
|
+
/**
|
|
254
|
+
* true if this file system watcher has been created such that
|
|
255
|
+
* it ignores change file system events.
|
|
256
|
+
*/
|
|
257
|
+
readonly ignoreChangeEvents: boolean;
|
|
258
|
+
/**
|
|
259
|
+
* true if this file system watcher has been created such that
|
|
260
|
+
* it ignores delete file system events.
|
|
261
|
+
*/
|
|
262
|
+
readonly ignoreDeleteEvents: boolean;
|
|
263
|
+
/**
|
|
264
|
+
* true if this file system watcher has been disposed.
|
|
265
|
+
*/
|
|
266
|
+
readonly isDisposed: boolean;
|
|
267
|
+
/**
|
|
268
|
+
* An event which fires on file/folder creation.
|
|
269
|
+
*/
|
|
270
|
+
onDidCreate(listener: (e: URI) => unknown): Disposable;
|
|
271
|
+
/**
|
|
272
|
+
* An event which fires on file/folder change.
|
|
273
|
+
*/
|
|
274
|
+
onDidChange(listener: (e: URI) => unknown): Disposable;
|
|
275
|
+
/**
|
|
276
|
+
* An event which fires on file/folder deletion.
|
|
277
|
+
*/
|
|
278
|
+
onDidDelete(listener: (e: URI) => unknown): Disposable;
|
|
215
279
|
}
|
|
216
280
|
/**
|
|
217
281
|
* The `FileStat`-type represents metadata about a file
|
|
@@ -337,4 +401,4 @@ declare function toFileSystemError(error: NodeJS.ErrnoException): FileSystemErro
|
|
|
337
401
|
//#region src/node.d.ts
|
|
338
402
|
declare function createNodeFileSystem(): Promise<FileSystem>;
|
|
339
403
|
//#endregion
|
|
340
|
-
export { FileStat, FileSystem, FileSystemError, FileSystemProviderErrorCode, FileType, IsDirectory, IsFile, IsSymbolicLink, RelativePattern, createFileSystemError, createNodeFileSystem, toFileSystemError };
|
|
404
|
+
export { Disposable, FileStat, FileSystem, FileSystemError, FileSystemProviderErrorCode, FileSystemWatcher, FileType, IsDirectory, IsFile, IsSymbolicLink, RelativePattern, createFileSystemError, createNodeFileSystem, toFileSystemError };
|
package/dist/index.mjs
CHANGED
|
@@ -166,10 +166,11 @@ 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] = await Promise.all([
|
|
169
|
+
const [fs, trash, glob, watch] = await Promise.all([
|
|
170
170
|
import("node:fs"),
|
|
171
171
|
import("trash").then((m) => m.default),
|
|
172
|
-
import("tinyglobby").then((m) => m.glob)
|
|
172
|
+
import("tinyglobby").then((m) => m.glob),
|
|
173
|
+
import("chokidar").then((m) => m.watch)
|
|
173
174
|
]);
|
|
174
175
|
async function resolveFileType(path) {
|
|
175
176
|
const lstats = await fs.promises.lstat(path);
|
|
@@ -323,9 +324,57 @@ async function createNodeFileSystem() {
|
|
|
323
324
|
deep: options?.deep,
|
|
324
325
|
fs
|
|
325
326
|
}));
|
|
327
|
+
},
|
|
328
|
+
createWatcher: async (pattern, options) => {
|
|
329
|
+
const watcher = watch(pattern.pattern, { cwd: pattern.baseUri.fsPath });
|
|
330
|
+
return new Promise((resolve) => {
|
|
331
|
+
watcher.on("ready", () => {
|
|
332
|
+
const fileSystemWatcher = new NodeFileSystemWatcherImpl(watcher, options);
|
|
333
|
+
if (options?.ignoreChangeEvents !== true) watcher.on("add", (path) => fileSystemWatcher.onDidCreateListeners.forEach((listener) => listener(URI.file(path))));
|
|
334
|
+
if (options?.ignoreChangeEvents !== true) watcher.on("change", (path) => fileSystemWatcher.onDidChangeListeners.forEach((listener) => listener(URI.file(path))));
|
|
335
|
+
if (options?.ignoreDeleteEvents !== true) watcher.on("unlink", (path) => fileSystemWatcher.onDidDeleteListeners.forEach((listener) => listener(URI.file(path))));
|
|
336
|
+
resolve(fileSystemWatcher);
|
|
337
|
+
});
|
|
338
|
+
});
|
|
326
339
|
}
|
|
327
340
|
};
|
|
328
341
|
}
|
|
342
|
+
var NodeFileSystemWatcherImpl = class {
|
|
343
|
+
constructor(watcher, options) {
|
|
344
|
+
this.watcher = watcher;
|
|
345
|
+
this.options = options;
|
|
346
|
+
}
|
|
347
|
+
get ignoreChangeEvents() {
|
|
348
|
+
return this.options?.ignoreChangeEvents ?? false;
|
|
349
|
+
}
|
|
350
|
+
get ignoreCreateEvents() {
|
|
351
|
+
return this.options?.ignoreCreateEvents ?? false;
|
|
352
|
+
}
|
|
353
|
+
get ignoreDeleteEvents() {
|
|
354
|
+
return this.options?.ignoreDeleteEvents ?? false;
|
|
355
|
+
}
|
|
356
|
+
get isDisposed() {
|
|
357
|
+
return this.watcher.closed;
|
|
358
|
+
}
|
|
359
|
+
onDidCreateListeners = /* @__PURE__ */ new Set();
|
|
360
|
+
onDidChangeListeners = /* @__PURE__ */ new Set();
|
|
361
|
+
onDidDeleteListeners = /* @__PURE__ */ new Set();
|
|
362
|
+
onDidCreate(listener) {
|
|
363
|
+
this.onDidCreateListeners.add(listener);
|
|
364
|
+
return { dispose: () => this.onDidCreateListeners.delete(listener) };
|
|
365
|
+
}
|
|
366
|
+
onDidChange(listener) {
|
|
367
|
+
this.onDidChangeListeners.add(listener);
|
|
368
|
+
return { dispose: () => this.onDidChangeListeners.delete(listener) };
|
|
369
|
+
}
|
|
370
|
+
onDidDelete(listener) {
|
|
371
|
+
this.onDidDeleteListeners.add(listener);
|
|
372
|
+
return { dispose: () => this.onDidDeleteListeners.delete(listener) };
|
|
373
|
+
}
|
|
374
|
+
dispose() {
|
|
375
|
+
this.watcher.close();
|
|
376
|
+
}
|
|
377
|
+
};
|
|
329
378
|
|
|
330
379
|
//#endregion
|
|
331
380
|
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.6",
|
|
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",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"vscode-uri": "^3.1.0"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
+
"chokidar": "^5.0.0",
|
|
48
49
|
"tinyglobby": "^0.2.15",
|
|
49
50
|
"trash": "^10.1.1"
|
|
50
51
|
},
|