vscode-fs 0.0.4 → 0.0.5
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 +34 -2
- package/dist/index.d.cts +61 -1
- package/dist/index.d.mts +61 -1
- package/dist/index.mjs +34 -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,6 +325,37 @@ 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 onDidCreateListeners = /* @__PURE__ */ new Set();
|
|
334
|
+
const onDidChangeListeners = /* @__PURE__ */ new Set();
|
|
335
|
+
const onDidDeleteListeners = /* @__PURE__ */ new Set();
|
|
336
|
+
if (options?.ignoreChangeEvents !== true) watcher.on("add", (path) => onDidCreateListeners.forEach((listener) => listener(vscode_uri.URI.file(path))));
|
|
337
|
+
if (options?.ignoreChangeEvents !== true) watcher.on("change", (path) => onDidChangeListeners.forEach((listener) => listener(vscode_uri.URI.file(path))));
|
|
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
|
+
});
|
|
357
|
+
});
|
|
358
|
+
});
|
|
327
359
|
}
|
|
328
360
|
};
|
|
329
361
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -212,6 +212,66 @@ 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
|
+
* An event which fires on file/folder creation.
|
|
265
|
+
*/
|
|
266
|
+
onDidCreate(listener: (e: URI) => unknown): Disposable;
|
|
267
|
+
/**
|
|
268
|
+
* An event which fires on file/folder change.
|
|
269
|
+
*/
|
|
270
|
+
onDidChange(listener: (e: URI) => unknown): Disposable;
|
|
271
|
+
/**
|
|
272
|
+
* An event which fires on file/folder deletion.
|
|
273
|
+
*/
|
|
274
|
+
onDidDelete(listener: (e: URI) => unknown): Disposable;
|
|
215
275
|
}
|
|
216
276
|
/**
|
|
217
277
|
* The `FileStat`-type represents metadata about a file
|
|
@@ -337,4 +397,4 @@ declare function toFileSystemError(error: NodeJS.ErrnoException): FileSystemErro
|
|
|
337
397
|
//#region src/node.d.ts
|
|
338
398
|
declare function createNodeFileSystem(): Promise<FileSystem>;
|
|
339
399
|
//#endregion
|
|
340
|
-
export { FileStat, FileSystem, FileSystemError, FileSystemProviderErrorCode, FileType, IsDirectory, IsFile, IsSymbolicLink, RelativePattern, createFileSystemError, createNodeFileSystem, toFileSystemError };
|
|
400
|
+
export { Disposable, FileStat, FileSystem, FileSystemError, FileSystemProviderErrorCode, FileSystemWatcher, FileType, IsDirectory, IsFile, IsSymbolicLink, RelativePattern, createFileSystemError, createNodeFileSystem, toFileSystemError };
|
package/dist/index.d.mts
CHANGED
|
@@ -212,6 +212,66 @@ 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
|
+
* An event which fires on file/folder creation.
|
|
265
|
+
*/
|
|
266
|
+
onDidCreate(listener: (e: URI) => unknown): Disposable;
|
|
267
|
+
/**
|
|
268
|
+
* An event which fires on file/folder change.
|
|
269
|
+
*/
|
|
270
|
+
onDidChange(listener: (e: URI) => unknown): Disposable;
|
|
271
|
+
/**
|
|
272
|
+
* An event which fires on file/folder deletion.
|
|
273
|
+
*/
|
|
274
|
+
onDidDelete(listener: (e: URI) => unknown): Disposable;
|
|
215
275
|
}
|
|
216
276
|
/**
|
|
217
277
|
* The `FileStat`-type represents metadata about a file
|
|
@@ -337,4 +397,4 @@ declare function toFileSystemError(error: NodeJS.ErrnoException): FileSystemErro
|
|
|
337
397
|
//#region src/node.d.ts
|
|
338
398
|
declare function createNodeFileSystem(): Promise<FileSystem>;
|
|
339
399
|
//#endregion
|
|
340
|
-
export { FileStat, FileSystem, FileSystemError, FileSystemProviderErrorCode, FileType, IsDirectory, IsFile, IsSymbolicLink, RelativePattern, createFileSystemError, createNodeFileSystem, toFileSystemError };
|
|
400
|
+
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,6 +324,37 @@ 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 onDidCreateListeners = /* @__PURE__ */ new Set();
|
|
333
|
+
const onDidChangeListeners = /* @__PURE__ */ new Set();
|
|
334
|
+
const onDidDeleteListeners = /* @__PURE__ */ new Set();
|
|
335
|
+
if (options?.ignoreChangeEvents !== true) watcher.on("add", (path) => onDidCreateListeners.forEach((listener) => listener(URI.file(path))));
|
|
336
|
+
if (options?.ignoreChangeEvents !== true) watcher.on("change", (path) => onDidChangeListeners.forEach((listener) => listener(URI.file(path))));
|
|
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
|
+
});
|
|
356
|
+
});
|
|
357
|
+
});
|
|
326
358
|
}
|
|
327
359
|
};
|
|
328
360
|
}
|
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.5",
|
|
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
|
},
|