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