@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
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2017-2018 TypeFox and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
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 { FileChangeType, FileSystemWatcherServiceClient } from '../../common/filesystem-watcher-protocol';
|
|
22
|
+
import { FileChangeCollection } from '../file-change-collection';
|
|
23
|
+
import { timeout } from '@theia/core/lib/common/promise-util';
|
|
24
|
+
import { subscribe, Options, AsyncSubscription, Event } from '@theia/core/shared/@parcel/watcher';
|
|
25
|
+
import { isOSX, isWindows } from '@theia/core';
|
|
26
|
+
import { AbstractFileSystemWatcher, AbstractWatcherProvider, ResolvedWatchOptions, WatcherLogger, WatchRequest } from '../filesystem-watcher';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The excludes of one parcel watch. Not the same as `ParcelWatcherOptions` in `parcel-options.ts`, which is
|
|
30
|
+
* the injectable token for parcel's own native options.
|
|
31
|
+
*/
|
|
32
|
+
export interface ParcelWatcherExcludes {
|
|
33
|
+
/** Compiled patterns, used to filter events after they arrive. */
|
|
34
|
+
ignored: Minimatch[]
|
|
35
|
+
/**
|
|
36
|
+
* Raw patterns, passed to the native parcel `ignore` option so excluded directories are never crawled or
|
|
37
|
+
* watched in the first place, rather than only having their events filtered out afterwards. This is what
|
|
38
|
+
* keeps the number of OS file watches bounded on large workspaces.
|
|
39
|
+
*/
|
|
40
|
+
ignorePatterns: string[]
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** @deprecated since 1.77.0 - use `ParcelWatcherExcludes`, which does not clash with the injectable token. */
|
|
44
|
+
export type ParcelWatcherOptions = ParcelWatcherExcludes;
|
|
45
|
+
|
|
46
|
+
export const ParcelFileSystemWatcherServerOptions = Symbol('ParcelFileSystemWatcherServerOptions');
|
|
47
|
+
export interface ParcelFileSystemWatcherServerOptions extends WatcherLogger {
|
|
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
|
+
/**
|
|
57
|
+
* Because URIs can be watched by different clients, we'll track
|
|
58
|
+
* how many are listening for a given URI.
|
|
59
|
+
*
|
|
60
|
+
* This component wraps the whole start/stop process given some
|
|
61
|
+
* reference count.
|
|
62
|
+
*
|
|
63
|
+
* Once there are no more references the handle
|
|
64
|
+
* will wait for some time before destroying its resources.
|
|
65
|
+
*/
|
|
66
|
+
export class ParcelWatcher extends AbstractFileSystemWatcher {
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* When this field is set, it means the watcher instance was successfully started.
|
|
70
|
+
*/
|
|
71
|
+
protected watcher: AsyncSubscription | undefined;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* When the ref count hits zero, we schedule this watch handle to be disposed.
|
|
75
|
+
*/
|
|
76
|
+
protected deferredDisposalTimer: NodeJS.Timeout | undefined;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* We count each reference made to this watcher, per client.
|
|
80
|
+
*
|
|
81
|
+
* We do this to know where to send events via the network.
|
|
82
|
+
*
|
|
83
|
+
* An entry should be removed when its value hits zero.
|
|
84
|
+
*/
|
|
85
|
+
protected readonly refsPerClient = new Map<number, { value: number }>();
|
|
86
|
+
|
|
87
|
+
/** Requests served by this watcher, so that releasing one drops the reference of the right client. */
|
|
88
|
+
private readonly requests = new Map<number, WatchRequest>();
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Ensures that events are processed in the order they are emitted,
|
|
92
|
+
* despite being processed async.
|
|
93
|
+
*/
|
|
94
|
+
protected parcelEventProcessingQueue: Promise<void> = Promise.resolve();
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Promise that resolves when the watcher is fully started, or got disposed.
|
|
98
|
+
*
|
|
99
|
+
* Will reject if an error occurred while starting.
|
|
100
|
+
*
|
|
101
|
+
* @returns `true` if successfully started, `false` if disposed early.
|
|
102
|
+
*/
|
|
103
|
+
readonly whenStarted: Promise<boolean>;
|
|
104
|
+
|
|
105
|
+
// copied from https://github.com/microsoft/vscode/blob/e3a5acfb517a443235981655413d566533107e92/src/vs/platform/files/node/watcher/parcel/parcelWatcher.ts#L158
|
|
106
|
+
private static readonly PARCEL_WATCHER_BACKEND = isWindows ? 'windows' : isOSX ? 'fs-events' : 'inotify';
|
|
107
|
+
|
|
108
|
+
constructor(
|
|
109
|
+
/**
|
|
110
|
+
* Initial reference to this handle.
|
|
111
|
+
* @deprecated since 1.77.0 - pass `undefined` and use {@link addRequest}; references follow requests.
|
|
112
|
+
*/
|
|
113
|
+
initialClientId: number | undefined,
|
|
114
|
+
/** Filesystem path to be watched. */
|
|
115
|
+
readonly fsPath: string,
|
|
116
|
+
/** Watcher-specific options */
|
|
117
|
+
readonly watcherOptions: ParcelWatcherExcludes,
|
|
118
|
+
/** Logging and parcel watcher options */
|
|
119
|
+
protected readonly parcelFileSystemWatchServerOptions: ParcelFileSystemWatcherServerOptions,
|
|
120
|
+
/** The client to forward events to. */
|
|
121
|
+
protected readonly fileSystemWatcherClient: FileSystemWatcherServiceClient,
|
|
122
|
+
/** Amount of time in ms to wait once this handle is not referenced anymore. */
|
|
123
|
+
protected readonly deferredDisposalTimeout = 10_000,
|
|
124
|
+
) {
|
|
125
|
+
super(fsPath, parcelFileSystemWatchServerOptions);
|
|
126
|
+
if (initialClientId !== undefined) {
|
|
127
|
+
this.refsPerClient.set(initialClientId, { value: 1 });
|
|
128
|
+
}
|
|
129
|
+
this.whenStarted = this.start().then(() => true, error => {
|
|
130
|
+
if (error === WatcherDisposal) {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
console.error(`Watcher failed to start at "${this.fsPath}":`, error);
|
|
134
|
+
this._dispose();
|
|
135
|
+
this.fireError();
|
|
136
|
+
throw error;
|
|
137
|
+
});
|
|
138
|
+
this.debug('NEW', `initialClientId=${initialClientId}`);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
addRequest(watcherId: number, request: WatchRequest): void {
|
|
142
|
+
this.requests.set(watcherId, request);
|
|
143
|
+
this.addRef(request.clientId);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
removeRequest(watcherId: number): void {
|
|
147
|
+
const request = this.requests.get(watcherId);
|
|
148
|
+
if (request) {
|
|
149
|
+
this.requests.delete(watcherId);
|
|
150
|
+
this.removeRef(request.clientId);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
addRef(clientId: number): void {
|
|
155
|
+
let refs = this.refsPerClient.get(clientId);
|
|
156
|
+
if (typeof refs === 'undefined') {
|
|
157
|
+
this.refsPerClient.set(clientId, refs = { value: 1 });
|
|
158
|
+
} else {
|
|
159
|
+
refs.value += 1;
|
|
160
|
+
}
|
|
161
|
+
const totalRefs = this.getTotalReferences();
|
|
162
|
+
// If it was zero before, 1 means we were revived:
|
|
163
|
+
const revived = totalRefs === 1;
|
|
164
|
+
if (revived) {
|
|
165
|
+
this.onRefsRevive();
|
|
166
|
+
}
|
|
167
|
+
this.debug('REF++', `clientId=${clientId}, clientRefs=${refs.value}, totalRefs=${totalRefs}. revived=${revived}`);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
removeRef(clientId: number): void {
|
|
171
|
+
const refs = this.refsPerClient.get(clientId);
|
|
172
|
+
if (typeof refs === 'undefined') {
|
|
173
|
+
this.info('WARN REF--', `removed one too many reference: clientId=${clientId}`);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
refs.value -= 1;
|
|
177
|
+
// We must remove the key from `this.clientReferences` because
|
|
178
|
+
// we list active clients by reading the keys of this map.
|
|
179
|
+
if (refs.value === 0) {
|
|
180
|
+
this.refsPerClient.delete(clientId);
|
|
181
|
+
}
|
|
182
|
+
const totalRefs = this.getTotalReferences();
|
|
183
|
+
const dead = totalRefs === 0;
|
|
184
|
+
if (dead) {
|
|
185
|
+
this.onRefsReachZero();
|
|
186
|
+
}
|
|
187
|
+
this.debug('REF--', `clientId=${clientId}, clientRefs=${refs.value}, totalRefs=${totalRefs}, dead=${dead}`);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* All clients with at least one active reference.
|
|
192
|
+
*/
|
|
193
|
+
getClientIds(): number[] {
|
|
194
|
+
return Array.from(this.refsPerClient.keys());
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Add the references for each client together.
|
|
199
|
+
*/
|
|
200
|
+
getTotalReferences(): number {
|
|
201
|
+
let total = 0;
|
|
202
|
+
for (const refs of this.refsPerClient.values()) {
|
|
203
|
+
total += refs.value;
|
|
204
|
+
}
|
|
205
|
+
return total;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Returns true if at least one client listens to this handle.
|
|
210
|
+
*/
|
|
211
|
+
isInUse(): boolean {
|
|
212
|
+
return this.refsPerClient.size > 0;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* @throws with {@link WatcherDisposal} if this instance is disposed.
|
|
217
|
+
*/
|
|
218
|
+
protected assertNotDisposed(): void {
|
|
219
|
+
if (this.isDisposed) {
|
|
220
|
+
throw WatcherDisposal;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* When starting a watcher, we'll first check and wait for the path to exists
|
|
226
|
+
* before running a parcel watcher.
|
|
227
|
+
*/
|
|
228
|
+
protected async start(): Promise<void> {
|
|
229
|
+
while (await fsp.stat(this.fsPath).then(() => false, () => true)) {
|
|
230
|
+
await timeout(500);
|
|
231
|
+
this.assertNotDisposed();
|
|
232
|
+
}
|
|
233
|
+
this.assertNotDisposed();
|
|
234
|
+
// This race is specific to Linux/inotify: parcel-watcher's inotify backend walks
|
|
235
|
+
// the tree and then calls inotify_add_watch on every subdirectory. If a subdirectory
|
|
236
|
+
// disappears between the walk and the add (common when watching dirs that contain
|
|
237
|
+
// auto-rotated log/temp folders), the syscall returns ENOENT and parcel-watcher fails
|
|
238
|
+
// the entire subscribe. Retry a few times: by the next walk the gone-but-not-forgotten
|
|
239
|
+
// dir is no longer present. Windows (ReadDirectoryChangesW) and macOS (FSEvents) watch
|
|
240
|
+
// the whole subtree from a single handle on the root and never register per-subdirectory
|
|
241
|
+
// watches, so they cannot hit this race; the retry is simply a no-op there.
|
|
242
|
+
let watcher: AsyncSubscription | undefined;
|
|
243
|
+
let attempt = 0;
|
|
244
|
+
while (true) {
|
|
245
|
+
try {
|
|
246
|
+
watcher = await this.createWatcher();
|
|
247
|
+
break;
|
|
248
|
+
} catch (error) {
|
|
249
|
+
const message: string = (error && error.message) || '';
|
|
250
|
+
const isTransientEnoent = message.includes('No such file or directory')
|
|
251
|
+
&& await fsp.stat(this.fsPath).then(() => true, () => false);
|
|
252
|
+
if (!isTransientEnoent || attempt >= 4) {
|
|
253
|
+
throw error;
|
|
254
|
+
}
|
|
255
|
+
attempt++;
|
|
256
|
+
this.assertNotDisposed();
|
|
257
|
+
await timeout(100 * attempt);
|
|
258
|
+
this.assertNotDisposed();
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
this.assertNotDisposed();
|
|
262
|
+
this.debug('STARTED', `disposed=${this.isDisposed}`);
|
|
263
|
+
// The watcher could be disposed while it was starting, make sure to check for this:
|
|
264
|
+
if (this.isDisposed) {
|
|
265
|
+
await this.stopWatcher(watcher);
|
|
266
|
+
throw WatcherDisposal;
|
|
267
|
+
}
|
|
268
|
+
this.watcher = watcher;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Given a started parcel watcher instance, gracefully shut it down.
|
|
273
|
+
*/
|
|
274
|
+
protected async stopWatcher(watcher: AsyncSubscription): Promise<void> {
|
|
275
|
+
await watcher.unsubscribe()
|
|
276
|
+
.then(() => 'success=true', error => error)
|
|
277
|
+
.then(status => this.debug('STOPPED', status));
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
protected async createWatcher(): Promise<AsyncSubscription> {
|
|
281
|
+
let fsPath = await fsp.realpath(this.fsPath);
|
|
282
|
+
if ((await fsp.stat(fsPath)).isFile()) {
|
|
283
|
+
fsPath = path.dirname(fsPath);
|
|
284
|
+
}
|
|
285
|
+
return subscribe(fsPath, (err, events) => {
|
|
286
|
+
if (err) {
|
|
287
|
+
if (err.message && err.message.includes('File system must be re-scanned')) {
|
|
288
|
+
console.log(`FS Events were dropped on watcher ${fsPath}`);
|
|
289
|
+
} else {
|
|
290
|
+
console.error(`Watcher service error on "${fsPath}":`, err);
|
|
291
|
+
this._dispose();
|
|
292
|
+
this.fireError();
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
if (events) {
|
|
297
|
+
this.handleWatcherEvents(events);
|
|
298
|
+
}
|
|
299
|
+
}, {
|
|
300
|
+
backend: ParcelWatcher.PARCEL_WATCHER_BACKEND,
|
|
301
|
+
...this.parcelFileSystemWatchServerOptions.parcelOptions,
|
|
302
|
+
// Pass the excludes to parcel's native `ignore` so excluded directories are pruned
|
|
303
|
+
// from the watch tree (no OS watch is placed), not merely filtered out of the event
|
|
304
|
+
// stream. Mirrors VS Code's parcel watcher (`ignore: <request excludes>`).
|
|
305
|
+
ignore: [
|
|
306
|
+
...(this.parcelFileSystemWatchServerOptions.parcelOptions.ignore ?? []),
|
|
307
|
+
...this.watcherOptions.ignorePatterns
|
|
308
|
+
]
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
protected handleWatcherEvents(events: Event[]): void {
|
|
313
|
+
// Only process events if someone is listening.
|
|
314
|
+
if (this.isInUse()) {
|
|
315
|
+
// This callback is async, but parcel won't wait for it to finish before firing the next one.
|
|
316
|
+
// We will use a lock/queue to make sure everything is processed in the order it arrives.
|
|
317
|
+
this.parcelEventProcessingQueue = this.parcelEventProcessingQueue.then(async () => {
|
|
318
|
+
const fileChangeCollection = new FileChangeCollection();
|
|
319
|
+
for (const event of events) {
|
|
320
|
+
const filePath = event.path;
|
|
321
|
+
if (event.type === 'create') {
|
|
322
|
+
this.pushFileChange(fileChangeCollection, FileChangeType.ADDED, filePath);
|
|
323
|
+
} else if (event.type === 'delete') {
|
|
324
|
+
this.pushFileChange(fileChangeCollection, FileChangeType.DELETED, filePath);
|
|
325
|
+
} else if (event.type === 'update') {
|
|
326
|
+
this.pushFileChange(fileChangeCollection, FileChangeType.UPDATED, filePath);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
const changes = fileChangeCollection.values();
|
|
330
|
+
// If all changes are part of the ignored files, the collection will be empty.
|
|
331
|
+
if (changes.length > 0) {
|
|
332
|
+
this.fileSystemWatcherClient.onDidFilesChanged({
|
|
333
|
+
clients: this.getClientIds(),
|
|
334
|
+
changes,
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
}, console.error);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
protected async resolveEventPath(directory: string, file: string): Promise<string> {
|
|
342
|
+
// parcel already resolves symlinks, the paths should be clean already:
|
|
343
|
+
return path.resolve(directory, file);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
protected pushFileChange(changes: FileChangeCollection, type: FileChangeType, filePath: string): void {
|
|
347
|
+
if (!this.isIgnored(filePath)) {
|
|
348
|
+
const uri = FileUri.create(filePath).toString();
|
|
349
|
+
changes.push({ type, uri });
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
protected fireError(): void {
|
|
354
|
+
this.fileSystemWatcherClient.onError({
|
|
355
|
+
clients: this.getClientIds(),
|
|
356
|
+
uri: this.fsPath,
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* When references hit zero, we'll schedule disposal for a bit later.
|
|
362
|
+
*
|
|
363
|
+
* This allows new references to reuse this watcher instead of creating a new one.
|
|
364
|
+
*
|
|
365
|
+
* e.g. A frontend disconnects for a few milliseconds before reconnecting again.
|
|
366
|
+
*/
|
|
367
|
+
protected onRefsReachZero(): void {
|
|
368
|
+
this.deferredDisposalTimer = setTimeout(() => this._dispose(), this.deferredDisposalTimeout);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* If we get new references after hitting zero, let's unschedule our disposal and keep watching.
|
|
373
|
+
*/
|
|
374
|
+
protected onRefsRevive(): void {
|
|
375
|
+
if (this.deferredDisposalTimer) {
|
|
376
|
+
clearTimeout(this.deferredDisposalTimer);
|
|
377
|
+
this.deferredDisposalTimer = undefined;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
protected isIgnored(filePath: string): boolean {
|
|
382
|
+
return this.watcherOptions.ignored.length > 0
|
|
383
|
+
&& this.watcherOptions.ignored.some(m => m.match(filePath));
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Internal disposal mechanism.
|
|
388
|
+
*/
|
|
389
|
+
protected async _dispose(): Promise<void> {
|
|
390
|
+
if (this.markDisposed()) {
|
|
391
|
+
if (this.watcher) {
|
|
392
|
+
this.stopWatcher(this.watcher);
|
|
393
|
+
this.watcher = undefined;
|
|
394
|
+
}
|
|
395
|
+
this.debug('DISPOSED');
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/** Serves recursive requests with `@parcel/watcher`, one subscription per path and exclude set. */
|
|
402
|
+
export class RecursiveWatcherProvider extends AbstractWatcherProvider {
|
|
403
|
+
|
|
404
|
+
constructor(
|
|
405
|
+
protected readonly options: ParcelFileSystemWatcherServerOptions,
|
|
406
|
+
protected readonly client: FileSystemWatcherServiceClient,
|
|
407
|
+
protected readonly deferredDisposalTimeout?: number
|
|
408
|
+
) {
|
|
409
|
+
super();
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
canHandle(options: ResolvedWatchOptions): boolean {
|
|
413
|
+
return options.recursive;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
async watch(watcherId: number, request: WatchRequest): Promise<void> {
|
|
417
|
+
this.serve(watcherId, this.getOrCreateWatcher(this.watcherKey(request), () => this.createWatcher(request)), request);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/** Excludes are part of the key: parcel prunes them from the crawl, so a different set is a different watch. */
|
|
421
|
+
protected watcherKey(request: WatchRequest): string {
|
|
422
|
+
return [request.path, [...request.ignored].sort().join()].join();
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
protected createWatcher(request: WatchRequest): ParcelWatcher {
|
|
426
|
+
const watcherOptions: ParcelWatcherExcludes = {
|
|
427
|
+
ignored: request.ignored.map(pattern => new Minimatch(pattern, { dot: true })),
|
|
428
|
+
ignorePatterns: [...request.ignored]
|
|
429
|
+
};
|
|
430
|
+
return new ParcelWatcher(undefined, request.path, watcherOptions, this.options, this.client, this.deferredDisposalTimeout);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2026 Ehab Younes and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import * as path from 'path';
|
|
18
|
+
import * as fs from '@theia/core/shared/fs-extra';
|
|
19
|
+
import { NodeDirectoryWatcherTimings } from '../nodejs-watcher/node-directory-watcher';
|
|
20
|
+
|
|
21
|
+
/** Scaled down so the suite stays quick; only the order of the delays matters. */
|
|
22
|
+
export const WATCHER_TIMINGS: NodeDirectoryWatcherTimings = {
|
|
23
|
+
changeDelay: 5,
|
|
24
|
+
deleteDelay: 20,
|
|
25
|
+
existencePollDelay: 20,
|
|
26
|
+
deferredDisposalTimeout: 30
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const NO_LOGGING = { verbose: false, info: () => { }, error: () => { } };
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A directory to act on, one per test, so that no test depends on what another one left behind. The root is
|
|
33
|
+
* passed in because `temp` is a root-level dev dependency, and this file is published.
|
|
34
|
+
*/
|
|
35
|
+
export class TempDir {
|
|
36
|
+
|
|
37
|
+
constructor(readonly root: string) { }
|
|
38
|
+
|
|
39
|
+
path(...segments: string[]): string {
|
|
40
|
+
return path.resolve(this.root, ...segments);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
write(...segments: string[]): string {
|
|
44
|
+
const target = this.path(...segments);
|
|
45
|
+
fs.writeFileSync(target, 'content');
|
|
46
|
+
return target;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
mkdir(...segments: string[]): string {
|
|
50
|
+
const target = this.path(...segments);
|
|
51
|
+
fs.mkdirSync(target, { recursive: true });
|
|
52
|
+
return target;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
remove(...segments: string[]): void {
|
|
56
|
+
fs.removeSync(this.path(...segments));
|
|
57
|
+
}
|
|
58
|
+
}
|