@theia/filesystem 1.77.0-next.6 → 1.77.0-next.63
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/download/file-download-service.d.ts.map +1 -1
- package/lib/browser/download/file-download-service.js +0 -1
- package/lib/browser/download/file-download-service.js.map +1 -1
- package/lib/browser/file-dialog/file-dialog.js +1 -1
- package/lib/browser/file-dialog/file-dialog.js.map +1 -1
- package/lib/browser/file-resource.spec.js +2 -1
- package/lib/browser/file-resource.spec.js.map +1 -1
- package/lib/browser/file-service-watcher.spec.js +2 -1
- package/lib/browser/file-service-watcher.spec.js.map +1 -1
- package/lib/browser/file-service.d.ts +1 -1
- package/lib/browser/file-service.js +1 -1
- package/lib/browser/file-service.js.map +1 -1
- package/lib/browser/file-tree/file-tree-decorator-adapter.js +1 -1
- package/lib/browser/file-tree/file-tree-decorator-adapter.js.map +1 -1
- package/lib/browser/file-tree/file-tree-decorator-adapter.spec.js +2 -1
- package/lib/browser/file-tree/file-tree-decorator-adapter.spec.js.map +1 -1
- package/lib/browser/file-tree/file-tree-model.js +1 -1
- package/lib/browser/file-tree/file-tree-model.js.map +1 -1
- package/lib/browser/file-tree/file-tree-widget.js +1 -1
- package/lib/browser/file-tree/file-tree-widget.js.map +1 -1
- package/lib/browser/filesystem-frontend-contribution.js +1 -1
- package/lib/browser/filesystem-frontend-contribution.js.map +1 -1
- package/lib/browser/location/location-renderer.js +1 -1
- package/lib/browser/location/location-renderer.js.map +1 -1
- package/lib/browser/location/location-renderer.spec.js +2 -1
- package/lib/browser/location/location-renderer.spec.js.map +1 -1
- package/lib/browser/upload/file-upload-service-impl.js +1 -1
- package/lib/browser/upload/file-upload-service-impl.js.map +1 -1
- package/lib/browser-only/download/file-download-service.js +1 -1
- package/lib/browser-only/download/file-download-service.js.map +1 -1
- package/lib/browser-only/file-search.js +2 -1
- package/lib/browser-only/file-search.js.map +1 -1
- package/lib/browser-only/upload/file-upload-service-impl.js +1 -1
- package/lib/browser-only/upload/file-upload-service-impl.js.map +1 -1
- package/lib/common/files.js +2 -1
- package/lib/common/files.js.map +1 -1
- package/lib/common/files.spec.js +2 -1
- package/lib/common/files.spec.js.map +1 -1
- package/lib/common/filesystem-watcher-protocol.d.ts +4 -0
- package/lib/common/filesystem-watcher-protocol.d.ts.map +1 -1
- package/lib/common/remote-file-system-provider.d.ts +4 -4
- package/lib/common/remote-file-system-provider.d.ts.map +1 -1
- package/lib/common/remote-file-system-provider.js +1 -1
- package/lib/common/remote-file-system-provider.js.map +1 -1
- package/lib/node/disk-file-system-provider.d.ts.map +1 -1
- package/lib/node/disk-file-system-provider.js +8 -5
- package/lib/node/disk-file-system-provider.js.map +1 -1
- package/lib/node/disk-file-system-provider.spec.js +28 -2
- package/lib/node/disk-file-system-provider.spec.js.map +1 -1
- package/lib/node/download/directory-archiver.js +2 -2
- package/lib/node/download/directory-archiver.js.map +1 -1
- package/lib/node/download/directory-archiver.spec.js +5 -4
- package/lib/node/download/directory-archiver.spec.js.map +1 -1
- package/lib/node/download/file-download-handler.d.ts.map +1 -1
- package/lib/node/download/file-download-handler.js +4 -5
- package/lib/node/download/file-download-handler.js.map +1 -1
- package/lib/node/file-change-collection.spec.js +2 -1
- package/lib/node/file-change-collection.spec.js.map +1 -1
- package/lib/node/filesystem-backend-module.d.ts +2 -2
- package/lib/node/filesystem-backend-module.d.ts.map +1 -1
- package/lib/node/filesystem-backend-module.js +7 -5
- package/lib/node/filesystem-backend-module.js.map +1 -1
- package/lib/node/filesystem-watcher-service-impl.d.ts +30 -0
- package/lib/node/filesystem-watcher-service-impl.d.ts.map +1 -0
- package/lib/node/filesystem-watcher-service-impl.js +92 -0
- package/lib/node/filesystem-watcher-service-impl.js.map +1 -0
- package/lib/node/filesystem-watcher-service-impl.spec.d.ts +2 -0
- package/lib/node/filesystem-watcher-service-impl.spec.d.ts.map +1 -0
- package/lib/node/filesystem-watcher-service-impl.spec.js +202 -0
- package/lib/node/filesystem-watcher-service-impl.spec.js.map +1 -0
- package/lib/node/filesystem-watcher.d.ts +93 -0
- package/lib/node/filesystem-watcher.d.ts.map +1 -0
- package/lib/node/filesystem-watcher.js +134 -0
- package/lib/node/filesystem-watcher.js.map +1 -0
- package/lib/node/nodejs-watcher/node-directory-watcher.d.ts +175 -0
- package/lib/node/nodejs-watcher/node-directory-watcher.d.ts.map +1 -0
- package/lib/node/nodejs-watcher/node-directory-watcher.js +580 -0
- package/lib/node/nodejs-watcher/node-directory-watcher.js.map +1 -0
- package/lib/node/nodejs-watcher/node-directory-watcher.spec.d.ts +2 -0
- package/lib/node/nodejs-watcher/node-directory-watcher.spec.d.ts.map +1 -0
- package/lib/node/nodejs-watcher/node-directory-watcher.spec.js +1284 -0
- package/lib/node/nodejs-watcher/node-directory-watcher.spec.js.map +1 -0
- package/lib/node/nodejs-watcher/watch-request-router.d.ts +63 -0
- package/lib/node/nodejs-watcher/watch-request-router.d.ts.map +1 -0
- package/lib/node/nodejs-watcher/watch-request-router.js +183 -0
- package/lib/node/nodejs-watcher/watch-request-router.js.map +1 -0
- package/lib/node/nodejs-watcher/watcher-host.d.ts +50 -0
- package/lib/node/nodejs-watcher/watcher-host.d.ts.map +1 -0
- package/lib/node/nodejs-watcher/watcher-host.js +99 -0
- package/lib/node/nodejs-watcher/watcher-host.js.map +1 -0
- package/lib/node/parcel-watcher/index.js +4 -3
- package/lib/node/parcel-watcher/index.js.map +1 -1
- package/lib/node/parcel-watcher/parcel-filesystem-service.d.ts +14 -194
- package/lib/node/parcel-watcher/parcel-filesystem-service.d.ts.map +1 -1
- package/lib/node/parcel-watcher/parcel-filesystem-service.js +7 -424
- package/lib/node/parcel-watcher/parcel-filesystem-service.js.map +1 -1
- package/lib/node/parcel-watcher/parcel-filesystem-watcher.spec.js +8 -7
- package/lib/node/parcel-watcher/parcel-filesystem-watcher.spec.js.map +1 -1
- package/lib/node/parcel-watcher/parcel-watcher-exclude.spec.js +8 -7
- package/lib/node/parcel-watcher/parcel-watcher-exclude.spec.js.map +1 -1
- package/lib/node/parcel-watcher/parcel-watcher-retry.spec.js +7 -6
- package/lib/node/parcel-watcher/parcel-watcher-retry.spec.js.map +1 -1
- package/lib/node/parcel-watcher/parcel-watcher.d.ts +165 -0
- package/lib/node/parcel-watcher/parcel-watcher.d.ts.map +1 -0
- package/lib/node/parcel-watcher/parcel-watcher.js +370 -0
- package/lib/node/parcel-watcher/parcel-watcher.js.map +1 -0
- package/lib/node/test/watcher-test-helper.d.ts +21 -0
- package/lib/node/test/watcher-test-helper.d.ts.map +1 -0
- package/lib/node/test/watcher-test-helper.js +56 -0
- package/lib/node/test/watcher-test-helper.js.map +1 -0
- package/lib/node/upload/node-file-upload-service.spec.js +4 -3
- package/lib/node/upload/node-file-upload-service.spec.js.map +1 -1
- package/package.json +7 -7
- package/src/browser/download/file-download-service.ts +0 -1
- package/src/browser/file-service.ts +3 -3
- package/src/common/filesystem-watcher-protocol.ts +4 -0
- package/src/node/disk-file-system-provider.spec.ts +29 -0
- package/src/node/disk-file-system-provider.ts +5 -2
- package/src/node/download/file-download-handler.ts +0 -1
- package/src/node/filesystem-backend-module.ts +5 -4
- package/src/node/filesystem-watcher-service-impl.spec.ts +272 -0
- package/src/node/filesystem-watcher-service-impl.ts +109 -0
- package/src/node/filesystem-watcher.ts +197 -0
- package/src/node/nodejs-watcher/node-directory-watcher.spec.ts +1594 -0
- package/src/node/nodejs-watcher/node-directory-watcher.ts +664 -0
- package/src/node/nodejs-watcher/watch-request-router.ts +224 -0
- package/src/node/nodejs-watcher/watcher-host.ts +126 -0
- package/src/node/parcel-watcher/index.ts +2 -2
- package/src/node/parcel-watcher/parcel-filesystem-service.ts +14 -500
- package/src/node/parcel-watcher/parcel-filesystem-watcher.spec.ts +4 -4
- package/src/node/parcel-watcher/parcel-watcher-exclude.spec.ts +4 -4
- package/src/node/parcel-watcher/parcel-watcher-retry.spec.ts +3 -3
- package/src/node/parcel-watcher/parcel-watcher.ts +432 -0
- package/src/node/test/watcher-test-helper.ts +58 -0
|
@@ -14,512 +14,26 @@
|
|
|
14
14
|
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
15
|
// *****************************************************************************
|
|
16
16
|
|
|
17
|
-
import path = require('path');
|
|
18
|
-
import { promises as fsp } from 'fs';
|
|
19
|
-
import { Minimatch } from 'minimatch';
|
|
20
|
-
import { FileUri } from '@theia/core/lib/common/file-uri';
|
|
21
|
-
import {
|
|
22
|
-
FileChangeType, FileSystemWatcherService, FileSystemWatcherServiceClient, WatchOptions
|
|
23
|
-
} from '../../common/filesystem-watcher-protocol';
|
|
24
|
-
import { FileChangeCollection } from '../file-change-collection';
|
|
25
|
-
import { Deferred, timeout } from '@theia/core/lib/common/promise-util';
|
|
26
|
-
import { subscribe, Options, AsyncSubscription, Event } from '@theia/core/shared/@parcel/watcher';
|
|
27
|
-
import { isOSX, isWindows } from '@theia/core';
|
|
28
|
-
|
|
29
|
-
export interface ParcelWatcherOptions {
|
|
30
|
-
/** Compiled exclude patterns, used to filter events after they arrive. */
|
|
31
|
-
ignored: Minimatch[]
|
|
32
|
-
/**
|
|
33
|
-
* Raw exclude patterns, passed to the native parcel `ignore` option so that excluded
|
|
34
|
-
* directories are never crawled or watched in the first place (rather than only having
|
|
35
|
-
* their events filtered out afterwards). This is what actually keeps the number of OS
|
|
36
|
-
* file watches (e.g. inotify watches on Linux) bounded on large workspaces.
|
|
37
|
-
*/
|
|
38
|
-
ignorePatterns: string[]
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export const ParcelFileSystemWatcherServerOptions = Symbol('ParcelFileSystemWatcherServerOptions');
|
|
42
|
-
export interface ParcelFileSystemWatcherServerOptions {
|
|
43
|
-
verbose: boolean;
|
|
44
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
45
|
-
info: (message: string, ...args: any[]) => void;
|
|
46
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
|
-
error: (message: string, ...args: any[]) => void;
|
|
48
|
-
parcelOptions: Options;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* This is a flag value passed around upon disposal.
|
|
53
|
-
*/
|
|
54
|
-
export const WatcherDisposal = Symbol('WatcherDisposal');
|
|
55
|
-
|
|
56
17
|
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* reference count.
|
|
62
|
-
*
|
|
63
|
-
* Once there are no more references the handle
|
|
64
|
-
* will wait for some time before destroying its resources.
|
|
18
|
+
* Kept so that the names this module published keep resolving. The service moved to
|
|
19
|
+
* `filesystem-watcher-service-impl`, next to both watchers it routes to rather than only the parcel one, and
|
|
20
|
+
* `ParcelWatcher` moved to `parcel-watcher`. Delete this file once the deprecated names below can go, which
|
|
21
|
+
* per `doc/api-management.md` is a major release.
|
|
65
22
|
*/
|
|
66
|
-
export class ParcelWatcher {
|
|
67
|
-
|
|
68
|
-
protected static debugIdSequence = 0;
|
|
69
|
-
|
|
70
|
-
protected disposed = false;
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Used for debugging to keep track of the watchers.
|
|
74
|
-
*/
|
|
75
|
-
protected debugId = ParcelWatcher.debugIdSequence++;
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* When this field is set, it means the watcher instance was successfully started.
|
|
79
|
-
*/
|
|
80
|
-
protected watcher: AsyncSubscription | undefined;
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* When the ref count hits zero, we schedule this watch handle to be disposed.
|
|
84
|
-
*/
|
|
85
|
-
protected deferredDisposalTimer: NodeJS.Timeout | undefined;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* This deferred only rejects with `WatcherDisposal` and never resolves.
|
|
89
|
-
*/
|
|
90
|
-
protected readonly deferredDisposalDeferred = new Deferred<never>();
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* We count each reference made to this watcher, per client.
|
|
94
|
-
*
|
|
95
|
-
* We do this to know where to send events via the network.
|
|
96
|
-
*
|
|
97
|
-
* An entry should be removed when its value hits zero.
|
|
98
|
-
*/
|
|
99
|
-
protected readonly refsPerClient = new Map<number, { value: number }>();
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Ensures that events are processed in the order they are emitted,
|
|
103
|
-
* despite being processed async.
|
|
104
|
-
*/
|
|
105
|
-
protected parcelEventProcessingQueue: Promise<void> = Promise.resolve();
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Resolves once this handle disposed itself and its resources. Never throws.
|
|
109
|
-
*/
|
|
110
|
-
readonly whenDisposed: Promise<void> = this.deferredDisposalDeferred.promise.catch(() => undefined);
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Promise that resolves when the watcher is fully started, or got disposed.
|
|
114
|
-
*
|
|
115
|
-
* Will reject if an error occurred while starting.
|
|
116
|
-
*
|
|
117
|
-
* @returns `true` if successfully started, `false` if disposed early.
|
|
118
|
-
*/
|
|
119
|
-
readonly whenStarted: Promise<boolean>;
|
|
120
|
-
|
|
121
|
-
// copied from https://github.com/microsoft/vscode/blob/e3a5acfb517a443235981655413d566533107e92/src/vs/platform/files/node/watcher/parcel/parcelWatcher.ts#L158
|
|
122
|
-
private static readonly PARCEL_WATCHER_BACKEND = isWindows ? 'windows' : isOSX ? 'fs-events' : 'inotify';
|
|
123
|
-
|
|
124
|
-
constructor(
|
|
125
|
-
/** Initial reference to this handle. */
|
|
126
|
-
initialClientId: number,
|
|
127
|
-
/** Filesystem path to be watched. */
|
|
128
|
-
readonly fsPath: string,
|
|
129
|
-
/** Watcher-specific options */
|
|
130
|
-
readonly watcherOptions: ParcelWatcherOptions,
|
|
131
|
-
/** Logging and parcel watcher options */
|
|
132
|
-
protected readonly parcelFileSystemWatchServerOptions: ParcelFileSystemWatcherServerOptions,
|
|
133
|
-
/** The client to forward events to. */
|
|
134
|
-
protected readonly fileSystemWatcherClient: FileSystemWatcherServiceClient,
|
|
135
|
-
/** Amount of time in ms to wait once this handle is not referenced anymore. */
|
|
136
|
-
protected readonly deferredDisposalTimeout = 10_000,
|
|
137
|
-
) {
|
|
138
|
-
this.refsPerClient.set(initialClientId, { value: 1 });
|
|
139
|
-
this.whenStarted = this.start().then(() => true, error => {
|
|
140
|
-
if (error === WatcherDisposal) {
|
|
141
|
-
return false;
|
|
142
|
-
}
|
|
143
|
-
console.error(`Watcher failed to start at "${this.fsPath}":`, error);
|
|
144
|
-
this._dispose();
|
|
145
|
-
this.fireError();
|
|
146
|
-
throw error;
|
|
147
|
-
});
|
|
148
|
-
this.debug('NEW', `initialClientId=${initialClientId}`);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
addRef(clientId: number): void {
|
|
152
|
-
let refs = this.refsPerClient.get(clientId);
|
|
153
|
-
if (typeof refs === 'undefined') {
|
|
154
|
-
this.refsPerClient.set(clientId, refs = { value: 1 });
|
|
155
|
-
} else {
|
|
156
|
-
refs.value += 1;
|
|
157
|
-
}
|
|
158
|
-
const totalRefs = this.getTotalReferences();
|
|
159
|
-
// If it was zero before, 1 means we were revived:
|
|
160
|
-
const revived = totalRefs === 1;
|
|
161
|
-
if (revived) {
|
|
162
|
-
this.onRefsRevive();
|
|
163
|
-
}
|
|
164
|
-
this.debug('REF++', `clientId=${clientId}, clientRefs=${refs.value}, totalRefs=${totalRefs}. revived=${revived}`);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
removeRef(clientId: number): void {
|
|
168
|
-
const refs = this.refsPerClient.get(clientId);
|
|
169
|
-
if (typeof refs === 'undefined') {
|
|
170
|
-
this.info('WARN REF--', `removed one too many reference: clientId=${clientId}`);
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
refs.value -= 1;
|
|
174
|
-
// We must remove the key from `this.clientReferences` because
|
|
175
|
-
// we list active clients by reading the keys of this map.
|
|
176
|
-
if (refs.value === 0) {
|
|
177
|
-
this.refsPerClient.delete(clientId);
|
|
178
|
-
}
|
|
179
|
-
const totalRefs = this.getTotalReferences();
|
|
180
|
-
const dead = totalRefs === 0;
|
|
181
|
-
if (dead) {
|
|
182
|
-
this.onRefsReachZero();
|
|
183
|
-
}
|
|
184
|
-
this.debug('REF--', `clientId=${clientId}, clientRefs=${refs.value}, totalRefs=${totalRefs}, dead=${dead}`);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* All clients with at least one active reference.
|
|
189
|
-
*/
|
|
190
|
-
getClientIds(): number[] {
|
|
191
|
-
return Array.from(this.refsPerClient.keys());
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Add the references for each client together.
|
|
196
|
-
*/
|
|
197
|
-
getTotalReferences(): number {
|
|
198
|
-
let total = 0;
|
|
199
|
-
for (const refs of this.refsPerClient.values()) {
|
|
200
|
-
total += refs.value;
|
|
201
|
-
}
|
|
202
|
-
return total;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* Returns true if at least one client listens to this handle.
|
|
207
|
-
*/
|
|
208
|
-
isInUse(): boolean {
|
|
209
|
-
return this.refsPerClient.size > 0;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* @throws with {@link WatcherDisposal} if this instance is disposed.
|
|
214
|
-
*/
|
|
215
|
-
protected assertNotDisposed(): void {
|
|
216
|
-
if (this.disposed) {
|
|
217
|
-
throw WatcherDisposal;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* When starting a watcher, we'll first check and wait for the path to exists
|
|
223
|
-
* before running a parcel watcher.
|
|
224
|
-
*/
|
|
225
|
-
protected async start(): Promise<void> {
|
|
226
|
-
while (await fsp.stat(this.fsPath).then(() => false, () => true)) {
|
|
227
|
-
await timeout(500);
|
|
228
|
-
this.assertNotDisposed();
|
|
229
|
-
}
|
|
230
|
-
this.assertNotDisposed();
|
|
231
|
-
// This race is specific to Linux/inotify: parcel-watcher's inotify backend walks
|
|
232
|
-
// the tree and then calls inotify_add_watch on every subdirectory. If a subdirectory
|
|
233
|
-
// disappears between the walk and the add (common when watching dirs that contain
|
|
234
|
-
// auto-rotated log/temp folders), the syscall returns ENOENT and parcel-watcher fails
|
|
235
|
-
// the entire subscribe. Retry a few times: by the next walk the gone-but-not-forgotten
|
|
236
|
-
// dir is no longer present. Windows (ReadDirectoryChangesW) and macOS (FSEvents) watch
|
|
237
|
-
// the whole subtree from a single handle on the root and never register per-subdirectory
|
|
238
|
-
// watches, so they cannot hit this race; the retry is simply a no-op there.
|
|
239
|
-
let watcher: AsyncSubscription | undefined;
|
|
240
|
-
let attempt = 0;
|
|
241
|
-
while (true) {
|
|
242
|
-
try {
|
|
243
|
-
watcher = await this.createWatcher();
|
|
244
|
-
break;
|
|
245
|
-
} catch (error) {
|
|
246
|
-
const message: string = (error && error.message) || '';
|
|
247
|
-
const isTransientEnoent = message.includes('No such file or directory')
|
|
248
|
-
&& await fsp.stat(this.fsPath).then(() => true, () => false);
|
|
249
|
-
if (!isTransientEnoent || attempt >= 4) {
|
|
250
|
-
throw error;
|
|
251
|
-
}
|
|
252
|
-
attempt++;
|
|
253
|
-
this.assertNotDisposed();
|
|
254
|
-
await timeout(100 * attempt);
|
|
255
|
-
this.assertNotDisposed();
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
this.assertNotDisposed();
|
|
259
|
-
this.debug('STARTED', `disposed=${this.disposed}`);
|
|
260
|
-
// The watcher could be disposed while it was starting, make sure to check for this:
|
|
261
|
-
if (this.disposed) {
|
|
262
|
-
await this.stopWatcher(watcher);
|
|
263
|
-
throw WatcherDisposal;
|
|
264
|
-
}
|
|
265
|
-
this.watcher = watcher;
|
|
266
|
-
}
|
|
267
23
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
*/
|
|
271
|
-
protected async stopWatcher(watcher: AsyncSubscription): Promise<void> {
|
|
272
|
-
await watcher.unsubscribe()
|
|
273
|
-
.then(() => 'success=true', error => error)
|
|
274
|
-
.then(status => this.debug('STOPPED', status));
|
|
275
|
-
}
|
|
24
|
+
import { FileSystemWatcher } from '../filesystem-watcher';
|
|
25
|
+
import { FileSystemWatcherServiceImpl } from '../filesystem-watcher-service-impl';
|
|
276
26
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
if ((await fsp.stat(fsPath)).isFile()) {
|
|
280
|
-
fsPath = path.dirname(fsPath);
|
|
281
|
-
}
|
|
282
|
-
return subscribe(fsPath, (err, events) => {
|
|
283
|
-
if (err) {
|
|
284
|
-
if (err.message && err.message.includes('File system must be re-scanned')) {
|
|
285
|
-
console.log(`FS Events were dropped on watcher ${fsp}`);
|
|
286
|
-
} else {
|
|
287
|
-
console.error(`Watcher service error on "${fsPath}":`, err);
|
|
288
|
-
this._dispose();
|
|
289
|
-
this.fireError();
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
if (events) {
|
|
294
|
-
this.handleWatcherEvents(events);
|
|
295
|
-
}
|
|
296
|
-
}, {
|
|
297
|
-
backend: ParcelWatcher.PARCEL_WATCHER_BACKEND,
|
|
298
|
-
...this.parcelFileSystemWatchServerOptions.parcelOptions,
|
|
299
|
-
// Pass the excludes to parcel's native `ignore` so excluded directories are pruned
|
|
300
|
-
// from the watch tree (no OS watch is placed), not merely filtered out of the event
|
|
301
|
-
// stream. Mirrors VS Code's parcel watcher (`ignore: <request excludes>`).
|
|
302
|
-
ignore: [
|
|
303
|
-
...(this.parcelFileSystemWatchServerOptions.parcelOptions.ignore ?? []),
|
|
304
|
-
...this.watcherOptions.ignorePatterns
|
|
305
|
-
]
|
|
306
|
-
});
|
|
307
|
-
}
|
|
27
|
+
export * from './parcel-watcher';
|
|
28
|
+
export * from '../filesystem-watcher-service-impl';
|
|
308
29
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
// We will use a lock/queue to make sure everything is processed in the order it arrives.
|
|
314
|
-
this.parcelEventProcessingQueue = this.parcelEventProcessingQueue.then(async () => {
|
|
315
|
-
const fileChangeCollection = new FileChangeCollection();
|
|
316
|
-
for (const event of events) {
|
|
317
|
-
const filePath = event.path;
|
|
318
|
-
if (event.type === 'create') {
|
|
319
|
-
this.pushFileChange(fileChangeCollection, FileChangeType.ADDED, filePath);
|
|
320
|
-
} else if (event.type === 'delete') {
|
|
321
|
-
this.pushFileChange(fileChangeCollection, FileChangeType.DELETED, filePath);
|
|
322
|
-
} else if (event.type === 'update') {
|
|
323
|
-
this.pushFileChange(fileChangeCollection, FileChangeType.UPDATED, filePath);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
const changes = fileChangeCollection.values();
|
|
327
|
-
// If all changes are part of the ignored files, the collection will be empty.
|
|
328
|
-
if (changes.length > 0) {
|
|
329
|
-
this.fileSystemWatcherClient.onDidFilesChanged({
|
|
330
|
-
clients: this.getClientIds(),
|
|
331
|
-
changes,
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
}, console.error);
|
|
335
|
-
}
|
|
336
|
-
}
|
|
30
|
+
/** @deprecated since 1.77.0 - use `FileSystemWatcherServiceImpl`, which also serves non-recursive requests. */
|
|
31
|
+
export const ParcelFileSystemWatcherService = FileSystemWatcherServiceImpl;
|
|
32
|
+
/** @deprecated since 1.77.0 - use `FileSystemWatcherServiceImpl`, which also serves non-recursive requests. */
|
|
33
|
+
export type ParcelFileSystemWatcherService = FileSystemWatcherServiceImpl;
|
|
337
34
|
|
|
338
|
-
|
|
339
|
-
// parcel already resolves symlinks, the paths should be clean already:
|
|
340
|
-
return path.resolve(directory, file);
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
protected pushFileChange(changes: FileChangeCollection, type: FileChangeType, filePath: string): void {
|
|
344
|
-
if (!this.isIgnored(filePath)) {
|
|
345
|
-
const uri = FileUri.create(filePath).toString();
|
|
346
|
-
changes.push({ type, uri });
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
protected fireError(): void {
|
|
351
|
-
this.fileSystemWatcherClient.onError({
|
|
352
|
-
clients: this.getClientIds(),
|
|
353
|
-
uri: this.fsPath,
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
/**
|
|
358
|
-
* When references hit zero, we'll schedule disposal for a bit later.
|
|
359
|
-
*
|
|
360
|
-
* This allows new references to reuse this watcher instead of creating a new one.
|
|
361
|
-
*
|
|
362
|
-
* e.g. A frontend disconnects for a few milliseconds before reconnecting again.
|
|
363
|
-
*/
|
|
364
|
-
protected onRefsReachZero(): void {
|
|
365
|
-
this.deferredDisposalTimer = setTimeout(() => this._dispose(), this.deferredDisposalTimeout);
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
/**
|
|
369
|
-
* If we get new references after hitting zero, let's unschedule our disposal and keep watching.
|
|
370
|
-
*/
|
|
371
|
-
protected onRefsRevive(): void {
|
|
372
|
-
if (this.deferredDisposalTimer) {
|
|
373
|
-
clearTimeout(this.deferredDisposalTimer);
|
|
374
|
-
this.deferredDisposalTimer = undefined;
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
protected isIgnored(filePath: string): boolean {
|
|
379
|
-
return this.watcherOptions.ignored.length > 0
|
|
380
|
-
&& this.watcherOptions.ignored.some(m => m.match(filePath));
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
/**
|
|
384
|
-
* Internal disposal mechanism.
|
|
385
|
-
*/
|
|
386
|
-
protected async _dispose(): Promise<void> {
|
|
387
|
-
if (!this.disposed) {
|
|
388
|
-
this.disposed = true;
|
|
389
|
-
this.deferredDisposalDeferred.reject(WatcherDisposal);
|
|
390
|
-
if (this.watcher) {
|
|
391
|
-
this.stopWatcher(this.watcher);
|
|
392
|
-
this.watcher = undefined;
|
|
393
|
-
}
|
|
394
|
-
this.debug('DISPOSED');
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
399
|
-
protected info(prefix: string, ...params: any[]): void {
|
|
400
|
-
this.parcelFileSystemWatchServerOptions.info(`${prefix} ParcelWatcher(${this.debugId} at "${this.fsPath}"):`, ...params);
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
404
|
-
protected debug(prefix: string, ...params: any[]): void {
|
|
405
|
-
if (this.parcelFileSystemWatchServerOptions.verbose) {
|
|
406
|
-
this.info(prefix, ...params);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
/**
|
|
412
|
-
* Each time a client makes a watchRequest, we generate a unique watcherId for it.
|
|
413
|
-
*
|
|
414
|
-
* This watcherId will map to this handle type which keeps track of the clientId that made the request.
|
|
415
|
-
*/
|
|
35
|
+
/** @deprecated since 1.77.0 - a watcher id now maps straight to the {@link FileSystemWatcher} serving it. */
|
|
416
36
|
export interface PacelWatcherHandle {
|
|
417
37
|
clientId: number;
|
|
418
|
-
watcher:
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
export class ParcelFileSystemWatcherService implements FileSystemWatcherService {
|
|
422
|
-
|
|
423
|
-
protected client: FileSystemWatcherServiceClient | undefined;
|
|
424
|
-
|
|
425
|
-
protected watcherId = 0;
|
|
426
|
-
protected readonly watchers = new Map<string, ParcelWatcher>();
|
|
427
|
-
protected readonly watcherHandles = new Map<number, PacelWatcherHandle>();
|
|
428
|
-
|
|
429
|
-
protected readonly options: ParcelFileSystemWatcherServerOptions;
|
|
430
|
-
|
|
431
|
-
/**
|
|
432
|
-
* `this.client` is undefined until someone sets it.
|
|
433
|
-
*/
|
|
434
|
-
protected readonly maybeClient: FileSystemWatcherServiceClient = {
|
|
435
|
-
onDidFilesChanged: event => this.client?.onDidFilesChanged(event),
|
|
436
|
-
onError: event => this.client?.onError(event),
|
|
437
|
-
};
|
|
438
|
-
|
|
439
|
-
constructor(options?: Partial<ParcelFileSystemWatcherServerOptions>) {
|
|
440
|
-
this.options = {
|
|
441
|
-
parcelOptions: {},
|
|
442
|
-
verbose: false,
|
|
443
|
-
info: (message, ...args) => console.info(message, ...args),
|
|
444
|
-
error: (message, ...args) => console.error(message, ...args),
|
|
445
|
-
...options
|
|
446
|
-
};
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
setClient(client: FileSystemWatcherServiceClient | undefined): void {
|
|
450
|
-
this.client = client;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
/**
|
|
454
|
-
* A specific client requests us to watch a given `uri` according to some `options`.
|
|
455
|
-
*
|
|
456
|
-
* We internally re-use all the same `(uri, options)` pairs.
|
|
457
|
-
*/
|
|
458
|
-
async watchFileChanges(clientId: number, uri: string, options?: WatchOptions): Promise<number> {
|
|
459
|
-
const resolvedOptions = this.resolveWatchOptions(options);
|
|
460
|
-
const watcherKey = this.getWatcherKey(uri, resolvedOptions);
|
|
461
|
-
let watcher = this.watchers.get(watcherKey);
|
|
462
|
-
if (watcher === undefined) {
|
|
463
|
-
const fsPath = FileUri.fsPath(uri);
|
|
464
|
-
watcher = this.createWatcher(clientId, fsPath, resolvedOptions);
|
|
465
|
-
watcher.whenDisposed.then(() => this.watchers.delete(watcherKey));
|
|
466
|
-
this.watchers.set(watcherKey, watcher);
|
|
467
|
-
} else {
|
|
468
|
-
watcher.addRef(clientId);
|
|
469
|
-
}
|
|
470
|
-
const watcherId = this.watcherId++;
|
|
471
|
-
this.watcherHandles.set(watcherId, { clientId, watcher });
|
|
472
|
-
watcher.whenDisposed.then(() => this.watcherHandles.delete(watcherId));
|
|
473
|
-
return watcherId;
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
protected createWatcher(clientId: number, fsPath: string, options: WatchOptions): ParcelWatcher {
|
|
477
|
-
const watcherOptions: ParcelWatcherOptions = {
|
|
478
|
-
ignored: options.ignored
|
|
479
|
-
.map(pattern => new Minimatch(pattern, { dot: true })),
|
|
480
|
-
ignorePatterns: options.ignored,
|
|
481
|
-
};
|
|
482
|
-
return new ParcelWatcher(clientId, fsPath, watcherOptions, this.options, this.maybeClient);
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
async unwatchFileChanges(watcherId: number): Promise<void> {
|
|
486
|
-
const handle = this.watcherHandles.get(watcherId);
|
|
487
|
-
if (handle === undefined) {
|
|
488
|
-
console.warn(`tried to de-allocate a disposed watcher: watcherId=${watcherId}`);
|
|
489
|
-
} else {
|
|
490
|
-
this.watcherHandles.delete(watcherId);
|
|
491
|
-
handle.watcher.removeRef(handle.clientId);
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
/**
|
|
496
|
-
* Given some `URI` and some `WatchOptions`, generate a unique key.
|
|
497
|
-
*/
|
|
498
|
-
protected getWatcherKey(uri: string, options: WatchOptions): string {
|
|
499
|
-
return [
|
|
500
|
-
uri,
|
|
501
|
-
options.ignored.slice(0).sort().join() // use a **sorted copy** of `ignored` as part of the key
|
|
502
|
-
].join();
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
/**
|
|
506
|
-
* Return fully qualified options.
|
|
507
|
-
*/
|
|
508
|
-
protected resolveWatchOptions(options?: WatchOptions): WatchOptions {
|
|
509
|
-
return {
|
|
510
|
-
ignored: [],
|
|
511
|
-
...options,
|
|
512
|
-
};
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
516
|
-
protected debug(message: string, ...params: any[]): void {
|
|
517
|
-
if (this.options.verbose) {
|
|
518
|
-
this.options.info(message, ...params);
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
dispose(): void {
|
|
523
|
-
// Singletons shouldn't be disposed...
|
|
524
|
-
}
|
|
38
|
+
watcher: FileSystemWatcher;
|
|
525
39
|
}
|
|
@@ -21,7 +21,7 @@ import * as fs from '@theia/core/shared/fs-extra';
|
|
|
21
21
|
import * as assert from 'assert';
|
|
22
22
|
import URI from '@theia/core/lib/common/uri';
|
|
23
23
|
import { FileUri } from '@theia/core/lib/node';
|
|
24
|
-
import {
|
|
24
|
+
import { FileSystemWatcherServiceImpl } from '../filesystem-watcher-service-impl';
|
|
25
25
|
import { DidFilesChangedParams, FileChange, FileChangeType } from '../../common/filesystem-watcher-protocol';
|
|
26
26
|
|
|
27
27
|
const expect = chai.expect;
|
|
@@ -30,7 +30,7 @@ const track = temp.track();
|
|
|
30
30
|
describe('parcel-filesystem-watcher', function (): void {
|
|
31
31
|
|
|
32
32
|
let root: URI;
|
|
33
|
-
let watcherService:
|
|
33
|
+
let watcherService: FileSystemWatcherServiceImpl;
|
|
34
34
|
let watcherId: number;
|
|
35
35
|
|
|
36
36
|
this.timeout(100000);
|
|
@@ -163,8 +163,8 @@ describe('parcel-filesystem-watcher', function (): void {
|
|
|
163
163
|
}
|
|
164
164
|
});
|
|
165
165
|
|
|
166
|
-
function createParcelFileSystemWatcherService():
|
|
167
|
-
return new
|
|
166
|
+
function createParcelFileSystemWatcherService(): FileSystemWatcherServiceImpl {
|
|
167
|
+
return new FileSystemWatcherServiceImpl({
|
|
168
168
|
verbose: true
|
|
169
169
|
});
|
|
170
170
|
}
|
|
@@ -21,7 +21,7 @@ import * as fs from '@theia/core/shared/fs-extra';
|
|
|
21
21
|
import URI from '@theia/core/lib/common/uri';
|
|
22
22
|
import { FileUri } from '@theia/core/lib/node';
|
|
23
23
|
import { Options } from '@theia/core/shared/@parcel/watcher';
|
|
24
|
-
import {
|
|
24
|
+
import { FileSystemWatcherServiceImpl } from '../filesystem-watcher-service-impl';
|
|
25
25
|
|
|
26
26
|
// We require the *same* module object that the production code imports from, so that
|
|
27
27
|
// stubbing its `subscribe` export is observed by `ParcelWatcher`. The `@theia/core/shared`
|
|
@@ -36,7 +36,7 @@ const track = temp.track();
|
|
|
36
36
|
* Reproduces the `files.watcherExclude` / exclude leak:
|
|
37
37
|
*
|
|
38
38
|
* Excludes flow `files.watcherExclude` -> `WatchOptions.excludes`
|
|
39
|
-
* -> `disk-file-system-provider` (`{ ignored }`) -> `
|
|
39
|
+
* -> `disk-file-system-provider` (`{ ignored }`) -> `ParcelWatcherExcludes.ignored`.
|
|
40
40
|
* However `ParcelWatcher.createWatcher()` only uses `ignored` to *filter events after they
|
|
41
41
|
* arrive* (`isIgnored`/`pushFileChange`). It never passes them to the native `@parcel/watcher`
|
|
42
42
|
* `subscribe(..., { ignore })` option, so excluded directories are STILL crawled and given
|
|
@@ -49,7 +49,7 @@ describe('parcel-filesystem-watcher exclude handling', function (): void {
|
|
|
49
49
|
this.timeout(20000);
|
|
50
50
|
|
|
51
51
|
let root: URI;
|
|
52
|
-
let service:
|
|
52
|
+
let service: FileSystemWatcherServiceImpl;
|
|
53
53
|
let subscribeStub: sinon.SinonStub;
|
|
54
54
|
let capturedOptions: Options[];
|
|
55
55
|
|
|
@@ -65,7 +65,7 @@ describe('parcel-filesystem-watcher exclude handling', function (): void {
|
|
|
65
65
|
capturedOptions.push(opts);
|
|
66
66
|
return { unsubscribe: async () => undefined };
|
|
67
67
|
});
|
|
68
|
-
service = new
|
|
68
|
+
service = new FileSystemWatcherServiceImpl({ verbose: false });
|
|
69
69
|
});
|
|
70
70
|
|
|
71
71
|
afterEach(() => {
|
|
@@ -20,7 +20,7 @@ import * as temp from 'temp';
|
|
|
20
20
|
import * as fs from '@theia/core/shared/fs-extra';
|
|
21
21
|
import URI from '@theia/core/lib/common/uri';
|
|
22
22
|
import { FileUri } from '@theia/core/lib/node';
|
|
23
|
-
import {
|
|
23
|
+
import { FileSystemWatcherServiceImpl } from '../filesystem-watcher-service-impl';
|
|
24
24
|
|
|
25
25
|
// We require the *same* module object that the production code imports from, so that
|
|
26
26
|
// stubbing its `subscribe` export is observed by `ParcelWatcher`. The `@theia/core/shared`
|
|
@@ -46,7 +46,7 @@ describe('parcel-filesystem-watcher transient ENOENT handling', function (): voi
|
|
|
46
46
|
this.timeout(20000);
|
|
47
47
|
|
|
48
48
|
let root: URI;
|
|
49
|
-
let service:
|
|
49
|
+
let service: FileSystemWatcherServiceImpl;
|
|
50
50
|
let subscribeStub: sinon.SinonStub | undefined;
|
|
51
51
|
let consoleErrorStub: sinon.SinonStub;
|
|
52
52
|
let onError: sinon.SinonStub;
|
|
@@ -57,7 +57,7 @@ describe('parcel-filesystem-watcher transient ENOENT handling', function (): voi
|
|
|
57
57
|
// start() now logs the underlying error to stderr on failure; silence it
|
|
58
58
|
// so the test output stays readable.
|
|
59
59
|
consoleErrorStub = sinon.stub(console, 'error');
|
|
60
|
-
service = new
|
|
60
|
+
service = new FileSystemWatcherServiceImpl({ verbose: false });
|
|
61
61
|
onError = sinon.stub();
|
|
62
62
|
service.setClient({
|
|
63
63
|
onDidFilesChanged: () => undefined,
|