@opensumi/ide-file-service 3.7.1-next-1736826301.0 → 3.7.1-next-1736846464.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/lib/browser/file-service-client.js +4 -4
- package/lib/browser/file-service-client.js.map +1 -1
- package/lib/browser/file-service-provider-client.d.ts +2 -2
- package/lib/browser/file-service-provider-client.d.ts.map +1 -1
- package/lib/browser/file-service-provider-client.js +2 -2
- package/lib/browser/file-service-provider-client.js.map +1 -1
- package/lib/common/files.d.ts +2 -2
- package/lib/common/files.d.ts.map +1 -1
- package/lib/common/watcher.d.ts +3 -2
- package/lib/common/watcher.d.ts.map +1 -1
- package/lib/common/watcher.js.map +1 -1
- package/lib/node/disk-file-system.provider.d.ts +3 -2
- package/lib/node/disk-file-system.provider.d.ts.map +1 -1
- package/lib/node/disk-file-system.provider.js +3 -2
- package/lib/node/disk-file-system.provider.js.map +1 -1
- package/lib/node/hosted/recursive/file-service-watcher.d.ts +13 -13
- package/lib/node/hosted/recursive/file-service-watcher.d.ts.map +1 -1
- package/lib/node/hosted/recursive/file-service-watcher.js +146 -95
- package/lib/node/hosted/recursive/file-service-watcher.js.map +1 -1
- package/lib/node/hosted/un-recursive/file-service-watcher.d.ts +5 -11
- package/lib/node/hosted/un-recursive/file-service-watcher.d.ts.map +1 -1
- package/lib/node/hosted/un-recursive/file-service-watcher.js +28 -40
- package/lib/node/hosted/un-recursive/file-service-watcher.js.map +1 -1
- package/lib/node/hosted/watcher.host.service.d.ts +7 -2
- package/lib/node/hosted/watcher.host.service.d.ts.map +1 -1
- package/lib/node/hosted/watcher.host.service.js +55 -28
- package/lib/node/hosted/watcher.host.service.js.map +1 -1
- package/lib/node/hosted/watcher.process.js +1 -1
- package/lib/node/hosted/watcher.process.js.map +1 -1
- package/lib/node/watcher-process-manager.d.ts +3 -2
- package/lib/node/watcher-process-manager.d.ts.map +1 -1
- package/lib/node/watcher-process-manager.js +4 -3
- package/lib/node/watcher-process-manager.js.map +1 -1
- package/package.json +9 -9
- package/src/browser/file-service-client.ts +4 -4
- package/src/browser/file-service-provider-client.ts +3 -2
- package/src/common/files.ts +2 -2
- package/src/common/watcher.ts +10 -3
- package/src/node/disk-file-system.provider.ts +8 -3
- package/src/node/hosted/recursive/file-service-watcher.ts +179 -106
- package/src/node/hosted/un-recursive/file-service-watcher.ts +36 -55
- package/src/node/hosted/watcher.host.service.ts +95 -33
- package/src/node/hosted/watcher.process.ts +1 -1
- package/src/node/watcher-process-manager.ts +13 -5
package/src/common/watcher.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { ProxyIdentifier } from '@opensumi/ide-connection/lib/common/rpc/multiplexer';
|
|
2
2
|
import { Event, FileChange, IRelativePattern, URI, UriComponents } from '@opensumi/ide-core-common';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
DidFilesChangedParams,
|
|
5
|
+
FileSystemWatcherClient,
|
|
6
|
+
RecursiveWatcherBackend,
|
|
7
|
+
} from '@opensumi/ide-core-common/lib/types/file-watch';
|
|
4
8
|
|
|
5
9
|
import { IFileServiceClient } from './file-service-client';
|
|
6
10
|
|
|
@@ -75,11 +79,14 @@ export const WatcherProcessManagerProxy = new ProxyIdentifier('WatcherProcessMan
|
|
|
75
79
|
export interface IWatcherProcessManager {
|
|
76
80
|
whenReady: Promise<void>;
|
|
77
81
|
|
|
78
|
-
createProcess(clientId: string): Promise<number | undefined>;
|
|
82
|
+
createProcess(clientId: string, backend?: RecursiveWatcherBackend): Promise<number | undefined>;
|
|
79
83
|
setClient(client: FileSystemWatcherClient): void;
|
|
80
84
|
dispose(): Promise<void>;
|
|
81
85
|
|
|
82
|
-
watch(
|
|
86
|
+
watch(
|
|
87
|
+
uri: UriComponents,
|
|
88
|
+
options?: { excludes?: string[]; recursive?: boolean; pollingWatch?: boolean },
|
|
89
|
+
): Promise<number>;
|
|
83
90
|
unWatch(watcherId: number): Promise<void>;
|
|
84
91
|
setWatcherFileExcludes(excludes: string[]): Promise<void>;
|
|
85
92
|
|
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
FileType,
|
|
39
39
|
IDiskFileProvider,
|
|
40
40
|
IWatcherProcessManager,
|
|
41
|
+
RecursiveWatcherBackend,
|
|
41
42
|
handleError,
|
|
42
43
|
isErrnoException,
|
|
43
44
|
notEmpty,
|
|
@@ -105,8 +106,8 @@ export class DiskFileSystemProvider extends RPCService<IRPCDiskFileSystemProvide
|
|
|
105
106
|
});
|
|
106
107
|
}
|
|
107
108
|
|
|
108
|
-
async initialize(clientId: string) {
|
|
109
|
-
await this.watcherProcessManager.createProcess(clientId);
|
|
109
|
+
async initialize(clientId: string, backend?: RecursiveWatcherBackend) {
|
|
110
|
+
await this.watcherProcessManager.createProcess(clientId, backend);
|
|
110
111
|
}
|
|
111
112
|
|
|
112
113
|
get whenReady() {
|
|
@@ -143,13 +144,17 @@ export class DiskFileSystemProvider extends RPCService<IRPCDiskFileSystemProvide
|
|
|
143
144
|
* @param {{ excludes: string[] }}
|
|
144
145
|
* @memberof DiskFileSystemProvider
|
|
145
146
|
*/
|
|
146
|
-
async watch(
|
|
147
|
+
async watch(
|
|
148
|
+
uri: UriComponents,
|
|
149
|
+
options?: { excludes?: string[]; recursive?: boolean; pollingWatch?: boolean },
|
|
150
|
+
): Promise<number> {
|
|
147
151
|
await this.whenReady;
|
|
148
152
|
const _uri = Uri.revive(uri);
|
|
149
153
|
|
|
150
154
|
const id = await this.watcherProcessManager.watch(_uri, {
|
|
151
155
|
excludes: options?.excludes ?? [],
|
|
152
156
|
recursive: options?.recursive ?? this.recursive,
|
|
157
|
+
pollingWatch: options?.pollingWatch,
|
|
153
158
|
});
|
|
154
159
|
|
|
155
160
|
return id;
|
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { tmpdir } from 'os';
|
|
2
|
+
import paths, { join } from 'path';
|
|
2
3
|
|
|
3
4
|
import ParcelWatcher from '@parcel/watcher';
|
|
4
5
|
import fs from 'fs-extra';
|
|
5
6
|
import debounce from 'lodash/debounce';
|
|
6
7
|
import uniqBy from 'lodash/uniqBy';
|
|
7
8
|
|
|
9
|
+
import {
|
|
10
|
+
FileChangeType,
|
|
11
|
+
FileSystemWatcherClient,
|
|
12
|
+
IWatcher,
|
|
13
|
+
RecursiveWatcherBackend,
|
|
14
|
+
WatchOptions,
|
|
15
|
+
} from '@opensumi/ide-core-common';
|
|
8
16
|
import { ILogService } from '@opensumi/ide-core-common/lib/log';
|
|
9
17
|
import {
|
|
10
18
|
Disposable,
|
|
@@ -12,18 +20,13 @@ import {
|
|
|
12
20
|
FileUri,
|
|
13
21
|
IDisposable,
|
|
14
22
|
ParsedPattern,
|
|
23
|
+
RunOnceScheduler,
|
|
15
24
|
isLinux,
|
|
16
25
|
isWindows,
|
|
17
26
|
parseGlob,
|
|
18
27
|
} from '@opensumi/ide-core-common/lib/utils';
|
|
19
28
|
|
|
20
|
-
import {
|
|
21
|
-
FileChangeType,
|
|
22
|
-
FileSystemWatcherClient,
|
|
23
|
-
IFileSystemWatcherServer,
|
|
24
|
-
INsfw,
|
|
25
|
-
WatchOptions,
|
|
26
|
-
} from '../../../common';
|
|
29
|
+
import { INsfw } from '../../../common/watcher';
|
|
27
30
|
import { FileChangeCollection } from '../../file-change-collection';
|
|
28
31
|
import { shouldIgnorePath } from '../shared';
|
|
29
32
|
|
|
@@ -32,13 +35,6 @@ export interface WatcherOptions {
|
|
|
32
35
|
excludes: string[];
|
|
33
36
|
}
|
|
34
37
|
|
|
35
|
-
const watcherPlaceHolder = {
|
|
36
|
-
disposable: {
|
|
37
|
-
dispose: () => {},
|
|
38
|
-
},
|
|
39
|
-
handlers: [],
|
|
40
|
-
};
|
|
41
|
-
|
|
42
38
|
/**
|
|
43
39
|
* @deprecated
|
|
44
40
|
*/
|
|
@@ -48,21 +44,27 @@ export interface NsfwFileSystemWatcherOption {
|
|
|
48
44
|
error?: (message: string, ...args: any[]) => void;
|
|
49
45
|
}
|
|
50
46
|
|
|
51
|
-
export class
|
|
47
|
+
export class RecursiveFileSystemWatcher extends Disposable implements IWatcher {
|
|
52
48
|
private static readonly PARCEL_WATCHER_BACKEND = isWindows ? 'windows' : isLinux ? 'inotify' : 'fs-events';
|
|
53
49
|
|
|
50
|
+
private static DEFAULT_POLLING_INTERVAL = 100;
|
|
51
|
+
|
|
54
52
|
private WATCHER_HANDLERS = new Map<
|
|
55
|
-
|
|
53
|
+
string,
|
|
56
54
|
{ path: string; handlers: ParcelWatcher.SubscribeCallback[]; disposable: IDisposable }
|
|
57
55
|
>();
|
|
58
|
-
|
|
59
|
-
protected watcherOptions = new Map<
|
|
56
|
+
|
|
57
|
+
protected watcherOptions = new Map<string, WatcherOptions>();
|
|
60
58
|
|
|
61
59
|
protected client: FileSystemWatcherClient | undefined;
|
|
62
60
|
|
|
63
61
|
protected changes = new FileChangeCollection();
|
|
64
62
|
|
|
65
|
-
constructor(
|
|
63
|
+
constructor(
|
|
64
|
+
private excludes: string[] = [],
|
|
65
|
+
private readonly logger: ILogService,
|
|
66
|
+
private backend: RecursiveWatcherBackend = RecursiveWatcherBackend.NSFW,
|
|
67
|
+
) {
|
|
66
68
|
super();
|
|
67
69
|
this.addDispose(
|
|
68
70
|
Disposable.create(() => {
|
|
@@ -71,37 +73,41 @@ export class FileSystemWatcherServer extends Disposable implements IFileSystemWa
|
|
|
71
73
|
);
|
|
72
74
|
}
|
|
73
75
|
|
|
74
|
-
/**
|
|
75
|
-
* 查找某个路径是否已被监听
|
|
76
|
-
* @param watcherPath
|
|
77
|
-
*/
|
|
78
|
-
checkIsAlreadyWatched(watcherPath: string): number | undefined {
|
|
79
|
-
for (const [watcherId, watcher] of this.WATCHER_HANDLERS) {
|
|
80
|
-
if (watcherPath.indexOf(watcher.path) === 0) {
|
|
81
|
-
return watcherId;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
76
|
/**
|
|
87
77
|
* 如果监听路径不存在,则会监听父目录
|
|
88
78
|
* @param uri 要监听的路径
|
|
89
79
|
* @param options
|
|
90
80
|
* @returns
|
|
91
81
|
*/
|
|
92
|
-
async watchFileChanges(uri: string, options?: WatchOptions)
|
|
93
|
-
|
|
82
|
+
async watchFileChanges(uri: string, options?: WatchOptions) {
|
|
83
|
+
return new Promise<void>((resolve, rej) => {
|
|
84
|
+
const timer = setTimeout(() => {
|
|
85
|
+
rej(`Watch ${uri} Timeout`);
|
|
86
|
+
// FIXME:暂时写死3秒
|
|
87
|
+
}, 3000);
|
|
88
|
+
|
|
89
|
+
if (options?.excludes) {
|
|
90
|
+
this.updateWatcherFileExcludes(options.excludes);
|
|
91
|
+
}
|
|
94
92
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
93
|
+
this.doWatchFileChange(uri, options).then(() => {
|
|
94
|
+
resolve(void 0);
|
|
95
|
+
if (timer) {
|
|
96
|
+
clearTimeout(timer);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private async doWatchFileChange(uri: string, options?: WatchOptions) {
|
|
103
|
+
if (this.WATCHER_HANDLERS.has(uri)) {
|
|
104
|
+
const handler = this.WATCHER_HANDLERS.get(uri);
|
|
105
|
+
handler?.disposable.dispose();
|
|
106
|
+
this.WATCHER_HANDLERS.delete(uri);
|
|
98
107
|
}
|
|
99
108
|
|
|
100
|
-
|
|
101
|
-
this.
|
|
102
|
-
...watcherPlaceHolder,
|
|
103
|
-
path: basePath,
|
|
104
|
-
});
|
|
109
|
+
const basePath = FileUri.fsPath(uri);
|
|
110
|
+
this.logger.log('[Recursive] watch file changes: ', uri);
|
|
105
111
|
|
|
106
112
|
const toDisposeWatcher = new DisposableCollection();
|
|
107
113
|
let watchPath: string;
|
|
@@ -117,10 +123,10 @@ export class FileSystemWatcherServer extends Disposable implements IFileSystemWa
|
|
|
117
123
|
} else {
|
|
118
124
|
watchPath = await this.lookup(basePath);
|
|
119
125
|
}
|
|
120
|
-
|
|
126
|
+
|
|
121
127
|
const handler = (err, events: ParcelWatcher.Event[]) => {
|
|
122
128
|
if (err) {
|
|
123
|
-
this.logger.error(`Watching ${watchPath} error: `, err);
|
|
129
|
+
this.logger.error(`[Recursive] Watching ${watchPath} error: `, err);
|
|
124
130
|
return;
|
|
125
131
|
}
|
|
126
132
|
events = this.trimChangeEvent(events);
|
|
@@ -139,15 +145,15 @@ export class FileSystemWatcherServer extends Disposable implements IFileSystemWa
|
|
|
139
145
|
}
|
|
140
146
|
};
|
|
141
147
|
|
|
142
|
-
this.WATCHER_HANDLERS.set(
|
|
148
|
+
this.WATCHER_HANDLERS.set(uri, {
|
|
143
149
|
path: watchPath,
|
|
144
150
|
disposable: toDisposeWatcher,
|
|
145
151
|
handlers: [handler],
|
|
146
152
|
});
|
|
147
|
-
|
|
148
|
-
toDisposeWatcher.push(
|
|
153
|
+
|
|
154
|
+
toDisposeWatcher.push(Disposable.create(() => this.WATCHER_HANDLERS.delete(uri)));
|
|
155
|
+
toDisposeWatcher.push(await this.start(watchPath, options));
|
|
149
156
|
this.addDispose(toDisposeWatcher);
|
|
150
|
-
return watcherId;
|
|
151
157
|
}
|
|
152
158
|
|
|
153
159
|
/**
|
|
@@ -184,16 +190,63 @@ export class FileSystemWatcherServer extends Disposable implements IFileSystemWa
|
|
|
184
190
|
this.excludes = excludes;
|
|
185
191
|
}
|
|
186
192
|
|
|
187
|
-
protected async start(
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
rawOptions: WatchOptions | undefined,
|
|
191
|
-
): Promise<DisposableCollection> {
|
|
192
|
-
const disposables = new DisposableCollection();
|
|
193
|
+
protected async start(basePath: string, rawOptions: WatchOptions | undefined): Promise<DisposableCollection> {
|
|
194
|
+
this.logger.log('[Recursive] Start watching', basePath);
|
|
195
|
+
|
|
193
196
|
if (!(await fs.pathExists(basePath))) {
|
|
194
|
-
return
|
|
197
|
+
return new DisposableCollection();
|
|
195
198
|
}
|
|
199
|
+
|
|
196
200
|
const realPath = await fs.realpath(basePath);
|
|
201
|
+
|
|
202
|
+
if (this.isEnableNSFW()) {
|
|
203
|
+
return this.watchWithNsfw(realPath, rawOptions);
|
|
204
|
+
} else {
|
|
205
|
+
// polling
|
|
206
|
+
if (rawOptions?.pollingWatch) {
|
|
207
|
+
this.logger.log('[Recursive] Start polling watch:', realPath);
|
|
208
|
+
return this.pollingWatch(realPath, rawOptions);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return this.watchWithParcel(realPath, rawOptions);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
private async watchWithNsfw(realPath: string, rawOptions?: WatchOptions | undefined) {
|
|
216
|
+
const disposables = new DisposableCollection();
|
|
217
|
+
const nsfw = await this.withNSFWModule();
|
|
218
|
+
const watcher: INsfw.NSFW = await nsfw(
|
|
219
|
+
realPath,
|
|
220
|
+
(events: INsfw.ChangeEvent[]) => this.handleNSFWEvents(events, realPath),
|
|
221
|
+
{
|
|
222
|
+
errorCallback: (err) => {
|
|
223
|
+
this.logger.error('[Recursive] NSFW watcher encountered an error and will stop watching.', err);
|
|
224
|
+
// see https://github.com/atom/github/issues/342
|
|
225
|
+
this.unwatchFileChanges(realPath);
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
await watcher.start();
|
|
231
|
+
|
|
232
|
+
disposables.push(
|
|
233
|
+
Disposable.create(async () => {
|
|
234
|
+
this.watcherOptions.delete(realPath);
|
|
235
|
+
await watcher.stop();
|
|
236
|
+
}),
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
const excludes = this.excludes.concat(rawOptions?.excludes || []);
|
|
240
|
+
|
|
241
|
+
this.watcherOptions.set(realPath, {
|
|
242
|
+
excludesPattern: excludes.map((pattern) => parseGlob(pattern)),
|
|
243
|
+
excludes,
|
|
244
|
+
});
|
|
245
|
+
return disposables;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
private async watchWithParcel(realPath: string, rawOptions?: WatchOptions | undefined) {
|
|
249
|
+
const disposables = new DisposableCollection();
|
|
197
250
|
const tryWatchDir = async (maxRetries = 3, retryDelay = 1000) => {
|
|
198
251
|
for (let times = 0; times < maxRetries; times++) {
|
|
199
252
|
try {
|
|
@@ -205,23 +258,30 @@ export class FileSystemWatcherServer extends Disposable implements IFileSystemWa
|
|
|
205
258
|
// FIXME: 研究此处屏蔽的影响,考虑下阈值应该设置多少,或者更加优雅的方式
|
|
206
259
|
return;
|
|
207
260
|
}
|
|
208
|
-
const handlers = this.WATCHER_HANDLERS.get(
|
|
261
|
+
const handlers = this.WATCHER_HANDLERS.get(realPath)?.handlers;
|
|
209
262
|
|
|
210
263
|
if (!handlers) {
|
|
264
|
+
this.logger.log('[Recursive] No handler found for watcher', realPath);
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
this.logger.log('[Recursive] Received events:', events);
|
|
269
|
+
if (events.length === 0) {
|
|
211
270
|
return;
|
|
212
271
|
}
|
|
272
|
+
|
|
213
273
|
for (const handler of handlers) {
|
|
214
274
|
(handler as ParcelWatcher.SubscribeCallback)(err, events);
|
|
215
275
|
}
|
|
216
276
|
},
|
|
217
277
|
{
|
|
218
|
-
backend:
|
|
278
|
+
backend: RecursiveFileSystemWatcher.PARCEL_WATCHER_BACKEND,
|
|
219
279
|
ignore: this.excludes.concat(rawOptions?.excludes ?? []),
|
|
220
280
|
},
|
|
221
281
|
);
|
|
222
282
|
} catch (e) {
|
|
223
283
|
// Watcher 启动失败,尝试重试
|
|
224
|
-
this.logger.error('watcher subscribe failed ', e, ' try times ', times);
|
|
284
|
+
this.logger.error('[Recursive] watcher subscribe failed ', e, ' try times ', times);
|
|
225
285
|
await new Promise((resolve) => {
|
|
226
286
|
setTimeout(resolve, retryDelay);
|
|
227
287
|
});
|
|
@@ -229,61 +289,72 @@ export class FileSystemWatcherServer extends Disposable implements IFileSystemWa
|
|
|
229
289
|
}
|
|
230
290
|
|
|
231
291
|
// 经过若干次的尝试后,Parcel Watcher 依然启动失败,此时就不再尝试重试
|
|
232
|
-
this.logger.error(`watcher subscribe finally failed after ${maxRetries} times`);
|
|
292
|
+
this.logger.error(`[Recursive] watcher subscribe finally failed after ${maxRetries} times`);
|
|
233
293
|
return undefined; // watch 失败则返回 undefined
|
|
234
294
|
};
|
|
235
295
|
|
|
236
|
-
|
|
237
|
-
const nsfw = await this.withNSFWModule();
|
|
238
|
-
const watcher: INsfw.NSFW = await nsfw(
|
|
239
|
-
realPath,
|
|
240
|
-
(events: INsfw.ChangeEvent[]) => this.handleNSFWEvents(events, watcherId),
|
|
241
|
-
{
|
|
242
|
-
errorCallback: (err) => {
|
|
243
|
-
this.logger.error('NSFW watcher encountered an error and will stop watching.', err);
|
|
244
|
-
// see https://github.com/atom/github/issues/342
|
|
245
|
-
this.unwatchFileChanges(watcherId);
|
|
246
|
-
},
|
|
247
|
-
},
|
|
248
|
-
);
|
|
249
|
-
|
|
250
|
-
await watcher.start();
|
|
296
|
+
const hanlder: ParcelWatcher.AsyncSubscription | undefined = await tryWatchDir();
|
|
251
297
|
|
|
298
|
+
if (hanlder) {
|
|
299
|
+
// watch 成功才加入 disposables,否则也就无需 dispose
|
|
252
300
|
disposables.push(
|
|
253
301
|
Disposable.create(async () => {
|
|
254
|
-
|
|
255
|
-
|
|
302
|
+
if (hanlder) {
|
|
303
|
+
await hanlder.unsubscribe();
|
|
304
|
+
}
|
|
256
305
|
}),
|
|
257
306
|
);
|
|
307
|
+
}
|
|
258
308
|
|
|
259
|
-
|
|
309
|
+
return disposables;
|
|
310
|
+
}
|
|
260
311
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
if (
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
)
|
|
312
|
+
private async pollingWatch(realPath: string, rawOptions?: WatchOptions | undefined) {
|
|
313
|
+
const disposables = new DisposableCollection();
|
|
314
|
+
const snapshotFile = join(tmpdir(), `watcher-snapshot-${realPath}`);
|
|
315
|
+
let counter = 0;
|
|
316
|
+
|
|
317
|
+
const pollingWatcher = new RunOnceScheduler(async () => {
|
|
318
|
+
counter++;
|
|
319
|
+
if (counter > 1) {
|
|
320
|
+
const parcelEvents = await ParcelWatcher.getEventsSince(realPath, snapshotFile, {
|
|
321
|
+
ignore: rawOptions?.excludes,
|
|
322
|
+
backend: RecursiveFileSystemWatcher.PARCEL_WATCHER_BACKEND,
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
const handlers = this.WATCHER_HANDLERS.get(realPath)?.handlers;
|
|
326
|
+
|
|
327
|
+
if (!handlers) {
|
|
328
|
+
this.logger.log('[Recursive] No handler found for watcher', realPath);
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
this.logger.log('[Recursive] Received events:', parcelEvents);
|
|
333
|
+
for (const handler of handlers) {
|
|
334
|
+
(handler as ParcelWatcher.SubscribeCallback)(null, parcelEvents);
|
|
335
|
+
}
|
|
277
336
|
}
|
|
278
|
-
|
|
337
|
+
|
|
338
|
+
await ParcelWatcher.writeSnapshot(realPath, snapshotFile, {
|
|
339
|
+
ignore: rawOptions?.excludes,
|
|
340
|
+
backend: RecursiveFileSystemWatcher.PARCEL_WATCHER_BACKEND,
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
pollingWatcher.schedule();
|
|
344
|
+
}, RecursiveFileSystemWatcher.DEFAULT_POLLING_INTERVAL);
|
|
345
|
+
|
|
346
|
+
pollingWatcher.schedule(0);
|
|
347
|
+
|
|
348
|
+
disposables.push(pollingWatcher);
|
|
279
349
|
|
|
280
350
|
return disposables;
|
|
281
351
|
}
|
|
282
352
|
|
|
283
|
-
unwatchFileChanges(
|
|
284
|
-
|
|
353
|
+
unwatchFileChanges(uri: string): Promise<void> {
|
|
354
|
+
this.logger.log('[Recursive] Un watch: ', uri);
|
|
355
|
+
const watcher = this.WATCHER_HANDLERS.get(uri);
|
|
285
356
|
if (watcher) {
|
|
286
|
-
this.WATCHER_HANDLERS.delete(
|
|
357
|
+
this.WATCHER_HANDLERS.delete(uri);
|
|
287
358
|
watcher.disposable.dispose();
|
|
288
359
|
}
|
|
289
360
|
return Promise.resolve();
|
|
@@ -301,20 +372,22 @@ export class FileSystemWatcherServer extends Disposable implements IFileSystemWa
|
|
|
301
372
|
* 社区相关 issue: https://github.com/parcel-bundler/watcher/issues/49
|
|
302
373
|
*/
|
|
303
374
|
private isEnableNSFW(): boolean {
|
|
304
|
-
return isLinux;
|
|
375
|
+
return this.backend === RecursiveWatcherBackend.NSFW || isLinux;
|
|
305
376
|
}
|
|
306
377
|
|
|
307
|
-
private async handleNSFWEvents(events: INsfw.ChangeEvent[],
|
|
378
|
+
private async handleNSFWEvents(events: INsfw.ChangeEvent[], realPath: string): Promise<void> {
|
|
308
379
|
if (events.length > 5000) {
|
|
309
380
|
return;
|
|
310
381
|
}
|
|
311
382
|
|
|
312
|
-
const isIgnored = (
|
|
313
|
-
const options = this.watcherOptions.get(
|
|
383
|
+
const isIgnored = (realPath: string, path: string): boolean => {
|
|
384
|
+
const options = this.watcherOptions.get(realPath);
|
|
314
385
|
if (!options || !options.excludes || options.excludes.length < 1) {
|
|
315
386
|
return false;
|
|
316
387
|
}
|
|
317
|
-
|
|
388
|
+
|
|
389
|
+
const excludesPattern = [...this.excludes.map((pattern) => parseGlob(pattern)), ...options.excludesPattern];
|
|
390
|
+
return excludesPattern.some((match) => match(path));
|
|
318
391
|
};
|
|
319
392
|
|
|
320
393
|
const filterEvents = events.filter((event) => {
|
|
@@ -342,7 +415,7 @@ export class FileSystemWatcherServer extends Disposable implements IFileSystemWa
|
|
|
342
415
|
case INsfw.actions.RENAMED:
|
|
343
416
|
{
|
|
344
417
|
const deletedPath = await this.resolvePath(event.directory, event.oldFile!);
|
|
345
|
-
if (isIgnored(
|
|
418
|
+
if (isIgnored(realPath, deletedPath)) {
|
|
346
419
|
return;
|
|
347
420
|
}
|
|
348
421
|
|
|
@@ -350,14 +423,14 @@ export class FileSystemWatcherServer extends Disposable implements IFileSystemWa
|
|
|
350
423
|
|
|
351
424
|
if (event.newDirectory) {
|
|
352
425
|
const path = await this.resolvePath(event.newDirectory, event.newFile!);
|
|
353
|
-
if (isIgnored(
|
|
426
|
+
if (isIgnored(realPath, path)) {
|
|
354
427
|
return;
|
|
355
428
|
}
|
|
356
429
|
|
|
357
430
|
this.pushAdded(path);
|
|
358
431
|
} else {
|
|
359
432
|
const path = await this.resolvePath(event.directory, event.newFile!);
|
|
360
|
-
if (isIgnored(
|
|
433
|
+
if (isIgnored(realPath, path)) {
|
|
361
434
|
return;
|
|
362
435
|
}
|
|
363
436
|
|
|
@@ -368,7 +441,7 @@ export class FileSystemWatcherServer extends Disposable implements IFileSystemWa
|
|
|
368
441
|
default:
|
|
369
442
|
{
|
|
370
443
|
const path = await this.resolvePath(event.directory, event.file!);
|
|
371
|
-
if (isIgnored(
|
|
444
|
+
if (isIgnored(realPath, path)) {
|
|
372
445
|
return;
|
|
373
446
|
}
|
|
374
447
|
|