metro-file-map 0.83.3 → 0.84.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/package.json +4 -3
  2. package/src/Watcher.js +59 -52
  3. package/src/Watcher.js.flow +39 -39
  4. package/src/cache/DiskCacheManager.js.flow +3 -3
  5. package/src/constants.js +9 -8
  6. package/src/constants.js.flow +6 -18
  7. package/src/crawlers/node/index.js +27 -25
  8. package/src/crawlers/node/index.js.flow +6 -8
  9. package/src/crawlers/watchman/index.js +26 -22
  10. package/src/crawlers/watchman/index.js.flow +3 -4
  11. package/src/crawlers/watchman/planQuery.d.ts +24 -0
  12. package/src/crawlers/watchman/planQuery.js.flow +4 -4
  13. package/src/flow-types.js.flow +125 -87
  14. package/src/index.js +267 -235
  15. package/src/index.js.flow +269 -275
  16. package/src/lib/FileProcessor.js +76 -54
  17. package/src/lib/FileProcessor.js.flow +93 -72
  18. package/src/lib/RootPathUtils.js +25 -21
  19. package/src/lib/RootPathUtils.js.flow +4 -4
  20. package/src/lib/TreeFS.js +72 -77
  21. package/src/lib/TreeFS.js.flow +104 -124
  22. package/src/lib/checkWatchmanCapabilities.js.flow +4 -4
  23. package/src/lib/dependencyExtractor.d.ts +14 -0
  24. package/src/lib/normalizePathSeparatorsToPosix.js +25 -21
  25. package/src/lib/normalizePathSeparatorsToPosix.js.flow +3 -3
  26. package/src/lib/normalizePathSeparatorsToSystem.js +25 -21
  27. package/src/lib/normalizePathSeparatorsToSystem.js.flow +3 -3
  28. package/src/lib/rootRelativeCacheKeys.js +0 -20
  29. package/src/lib/rootRelativeCacheKeys.js.flow +1 -23
  30. package/src/plugins/DependencyPlugin.js +75 -0
  31. package/src/plugins/DependencyPlugin.js.flow +144 -0
  32. package/src/plugins/HastePlugin.js +83 -38
  33. package/src/plugins/HastePlugin.js.flow +105 -51
  34. package/src/plugins/MockPlugin.js +7 -4
  35. package/src/plugins/MockPlugin.js.flow +24 -15
  36. package/src/plugins/dependencies/dependencyExtractor.d.ts +14 -0
  37. package/src/{lib → plugins/dependencies}/dependencyExtractor.js.flow +3 -6
  38. package/src/plugins/dependencies/worker.d.ts +24 -0
  39. package/src/plugins/dependencies/worker.js +24 -0
  40. package/src/plugins/dependencies/worker.js.flow +53 -0
  41. package/src/plugins/haste/HasteConflictsError.js.flow +2 -2
  42. package/src/plugins/haste/computeConflicts.js +2 -1
  43. package/src/plugins/haste/computeConflicts.js.flow +11 -12
  44. package/src/plugins/haste/getPlatformExtension.js.flow +2 -2
  45. package/src/plugins/haste/worker.d.ts +24 -0
  46. package/src/plugins/haste/worker.js +35 -0
  47. package/src/plugins/haste/worker.js.flow +64 -0
  48. package/src/plugins/mocks/getMockName.js +27 -23
  49. package/src/plugins/mocks/getMockName.js.flow +2 -4
  50. package/src/watchers/AbstractWatcher.js +27 -22
  51. package/src/watchers/AbstractWatcher.js.flow +6 -5
  52. package/src/watchers/FallbackWatcher.js +88 -84
  53. package/src/watchers/FallbackWatcher.js.flow +65 -65
  54. package/src/watchers/NativeWatcher.js +25 -21
  55. package/src/watchers/NativeWatcher.js.flow +3 -3
  56. package/src/watchers/RecrawlWarning.js.flow +1 -1
  57. package/src/watchers/WatchmanWatcher.js +61 -53
  58. package/src/watchers/WatchmanWatcher.js.flow +39 -38
  59. package/src/watchers/common.js.flow +5 -5
  60. package/src/worker.d.ts +36 -0
  61. package/src/worker.js +16 -58
  62. package/src/worker.js.flow +19 -69
  63. package/src/workerExclusionList.d.ts +12 -0
  64. package/src/workerExclusionList.js.flow +1 -1
  65. package/src/Watcher.d.ts +0 -24
  66. package/src/cache/DiskCacheManager.d.ts +0 -38
  67. package/src/flow-types.d.ts +0 -353
  68. package/src/index.d.ts +0 -97
  69. package/src/lib/DuplicateHasteCandidatesError.d.ts +0 -24
  70. /package/src/{lib → plugins/dependencies}/dependencyExtractor.js +0 -0
@@ -42,32 +42,32 @@ const DELETE_EVENT = common.DELETE_EVENT;
42
42
  const DEBOUNCE_MS = 100;
43
43
 
44
44
  export default class FallbackWatcher extends AbstractWatcher {
45
- +_changeTimers: Map<string, TimeoutID> = new Map();
46
- +_dirRegistry: {
45
+ +#changeTimers: Map<string, TimeoutID> = new Map();
46
+ +#dirRegistry: {
47
47
  [directory: string]: {[file: string]: true, __proto__: null},
48
48
  __proto__: null,
49
49
  } = Object.create(null);
50
- +watched: {[key: string]: FSWatcher, __proto__: null} = Object.create(null);
50
+ +#watched: {[key: string]: FSWatcher, __proto__: null} = Object.create(null);
51
51
 
52
- async startWatching() {
53
- this._watchdir(this.root);
52
+ async startWatching(): Promise<void> {
53
+ this.#watchdir(this.root);
54
54
 
55
55
  await new Promise(resolve => {
56
56
  recReaddir(
57
57
  this.root,
58
58
  dir => {
59
- this._watchdir(dir);
59
+ this.#watchdir(dir);
60
60
  },
61
61
  filename => {
62
- this._register(filename, 'f');
62
+ this.#register(filename, 'f');
63
63
  },
64
64
  symlink => {
65
- this._register(symlink, 'l');
65
+ this.#register(symlink, 'l');
66
66
  },
67
67
  () => {
68
68
  resolve();
69
69
  },
70
- this._checkedEmitError,
70
+ this.#checkedEmitError,
71
71
  this.ignored,
72
72
  );
73
73
  });
@@ -87,10 +87,10 @@ export default class FallbackWatcher extends AbstractWatcher {
87
87
  *
88
88
  * Return false if ignored or already registered.
89
89
  */
90
- _register(filepath: string, type: ChangeEventMetadata['type']): boolean {
90
+ #register(filepath: string, type: ChangeEventMetadata['type']): boolean {
91
91
  const dir = path.dirname(filepath);
92
92
  const filename = path.basename(filepath);
93
- if (this._dirRegistry[dir] && this._dirRegistry[dir][filename]) {
93
+ if (this.#dirRegistry[dir] && this.#dirRegistry[dir][filename]) {
94
94
  return false;
95
95
  }
96
96
 
@@ -103,11 +103,11 @@ export default class FallbackWatcher extends AbstractWatcher {
103
103
  return false;
104
104
  }
105
105
 
106
- if (!this._dirRegistry[dir]) {
107
- this._dirRegistry[dir] = Object.create(null);
106
+ if (!this.#dirRegistry[dir]) {
107
+ this.#dirRegistry[dir] = Object.create(null);
108
108
  }
109
109
 
110
- this._dirRegistry[dir][filename] = true;
110
+ this.#dirRegistry[dir][filename] = true;
111
111
 
112
112
  return true;
113
113
  }
@@ -115,39 +115,39 @@ export default class FallbackWatcher extends AbstractWatcher {
115
115
  /**
116
116
  * Removes a file from the registry.
117
117
  */
118
- _unregister(filepath: string) {
118
+ #unregister(filepath: string) {
119
119
  const dir = path.dirname(filepath);
120
- if (this._dirRegistry[dir]) {
120
+ if (this.#dirRegistry[dir]) {
121
121
  const filename = path.basename(filepath);
122
- delete this._dirRegistry[dir][filename];
122
+ delete this.#dirRegistry[dir][filename];
123
123
  }
124
124
  }
125
125
 
126
126
  /**
127
127
  * Removes a dir from the registry.
128
128
  */
129
- _unregisterDir(dirpath: string): void {
130
- if (this._dirRegistry[dirpath]) {
131
- delete this._dirRegistry[dirpath];
129
+ #unregisterDir(dirpath: string): void {
130
+ if (this.#dirRegistry[dirpath]) {
131
+ delete this.#dirRegistry[dirpath];
132
132
  }
133
133
  }
134
134
 
135
135
  /**
136
136
  * Checks if a file or directory exists in the registry.
137
137
  */
138
- _registered(fullpath: string): boolean {
138
+ #registered(fullpath: string): boolean {
139
139
  const dir = path.dirname(fullpath);
140
140
  return !!(
141
- this._dirRegistry[fullpath] ||
142
- (this._dirRegistry[dir] &&
143
- this._dirRegistry[dir][path.basename(fullpath)])
141
+ this.#dirRegistry[fullpath] ||
142
+ (this.#dirRegistry[dir] &&
143
+ this.#dirRegistry[dir][path.basename(fullpath)])
144
144
  );
145
145
  }
146
146
 
147
147
  /**
148
148
  * Emit "error" event if it's not an ignorable event
149
149
  */
150
- _checkedEmitError: (error: Error) => void = error => {
150
+ #checkedEmitError: (error: Error) => void = error => {
151
151
  if (!isIgnorableFileError(error)) {
152
152
  this.emitError(error);
153
153
  }
@@ -156,19 +156,19 @@ export default class FallbackWatcher extends AbstractWatcher {
156
156
  /**
157
157
  * Watch a directory.
158
158
  */
159
- _watchdir: string => boolean = (dir: string) => {
160
- if (this.watched[dir]) {
159
+ #watchdir: (dir: string) => boolean = (dir: string) => {
160
+ if (this.#watched[dir]) {
161
161
  return false;
162
162
  }
163
163
  const watcher = fs.watch(dir, {persistent: true}, (event, filename) =>
164
- this._normalizeChange(dir, event, filename),
164
+ this.#normalizeChange(dir, event, filename),
165
165
  );
166
- this.watched[dir] = watcher;
166
+ this.#watched[dir] = watcher;
167
167
 
168
- watcher.on('error', this._checkedEmitError);
168
+ watcher.on('error', this.#checkedEmitError);
169
169
 
170
170
  if (this.root !== dir) {
171
- this._register(dir, 'd');
171
+ this.#register(dir, 'd');
172
172
  }
173
173
  return true;
174
174
  };
@@ -176,12 +176,12 @@ export default class FallbackWatcher extends AbstractWatcher {
176
176
  /**
177
177
  * Stop watching a directory.
178
178
  */
179
- async _stopWatching(dir: string): Promise<void> {
180
- if (this.watched[dir]) {
179
+ async #stopWatching(dir: string): Promise<void> {
180
+ if (this.#watched[dir]) {
181
181
  await new Promise(resolve => {
182
- this.watched[dir].once('close', () => process.nextTick(resolve));
183
- this.watched[dir].close();
184
- delete this.watched[dir];
182
+ this.#watched[dir].once('close', () => process.nextTick(resolve));
183
+ this.#watched[dir].close();
184
+ delete this.#watched[dir];
185
185
  });
186
186
  }
187
187
  }
@@ -191,8 +191,8 @@ export default class FallbackWatcher extends AbstractWatcher {
191
191
  */
192
192
  async stopWatching(): Promise<void> {
193
193
  await super.stopWatching();
194
- const promises = Object.keys(this.watched).map(dir =>
195
- this._stopWatching(dir),
194
+ const promises = Object.keys(this.#watched).map(dir =>
195
+ this.#stopWatching(dir),
196
196
  );
197
197
  await Promise.all(promises);
198
198
  }
@@ -202,19 +202,19 @@ export default class FallbackWatcher extends AbstractWatcher {
202
202
  * the file argument might be missing from the fs event. Try to detect what
203
203
  * change by detecting if something was deleted or the most recent file change.
204
204
  */
205
- _detectChangedFile(
205
+ #detectChangedFile(
206
206
  dir: string,
207
207
  event: string,
208
208
  callback: (file: string) => void,
209
209
  ) {
210
- if (!this._dirRegistry[dir]) {
210
+ if (!this.#dirRegistry[dir]) {
211
211
  return;
212
212
  }
213
213
 
214
214
  let found = false;
215
- let closest: ?$ReadOnly<{file: string, mtime: Stats['mtime']}> = null;
215
+ let closest: ?Readonly<{file: string, mtime: Stats['mtime']}> = null;
216
216
  let c = 0;
217
- Object.keys(this._dirRegistry[dir]).forEach((file, i, arr) => {
217
+ Object.keys(this.#dirRegistry[dir]).forEach((file, i, arr) => {
218
218
  fs.lstat(path.join(dir, file), (error, stat) => {
219
219
  if (found) {
220
220
  return;
@@ -242,17 +242,17 @@ export default class FallbackWatcher extends AbstractWatcher {
242
242
  /**
243
243
  * Normalize fs events and pass it on to be processed.
244
244
  */
245
- _normalizeChange(dir: string, event: string, file: string) {
245
+ #normalizeChange(dir: string, event: string, file: string) {
246
246
  if (!file) {
247
- this._detectChangedFile(dir, event, actualFile => {
247
+ this.#detectChangedFile(dir, event, actualFile => {
248
248
  if (actualFile) {
249
- this._processChange(dir, event, actualFile).catch(error =>
249
+ this.#processChange(dir, event, actualFile).catch(error =>
250
250
  this.emitError(error),
251
251
  );
252
252
  }
253
253
  });
254
254
  } else {
255
- this._processChange(dir, event, path.normalize(file)).catch(error =>
255
+ this.#processChange(dir, event, path.normalize(file)).catch(error =>
256
256
  this.emitError(error),
257
257
  );
258
258
  }
@@ -261,11 +261,11 @@ export default class FallbackWatcher extends AbstractWatcher {
261
261
  /**
262
262
  * Process changes.
263
263
  */
264
- async _processChange(dir: string, event: string, file: string) {
264
+ async #processChange(dir: string, event: string, file: string) {
265
265
  const fullPath = path.join(dir, file);
266
266
  const relativePath = path.join(path.relative(this.root, dir), file);
267
267
 
268
- const registered = this._registered(fullPath);
268
+ const registered = this.#registered(fullPath);
269
269
 
270
270
  try {
271
271
  const stat = await fsPromises.lstat(fullPath);
@@ -284,8 +284,8 @@ export default class FallbackWatcher extends AbstractWatcher {
284
284
  recReaddir(
285
285
  path.resolve(this.root, relativePath),
286
286
  (dir, stats) => {
287
- if (this._watchdir(dir)) {
288
- this._emitEvent({
287
+ if (this.#watchdir(dir)) {
288
+ this.#emitEvent({
289
289
  event: TOUCH_EVENT,
290
290
  relativePath: path.relative(this.root, dir),
291
291
  metadata: {
@@ -297,8 +297,8 @@ export default class FallbackWatcher extends AbstractWatcher {
297
297
  }
298
298
  },
299
299
  (file, stats) => {
300
- if (this._register(file, 'f')) {
301
- this._emitEvent({
300
+ if (this.#register(file, 'f')) {
301
+ this.#emitEvent({
302
302
  event: TOUCH_EVENT,
303
303
  relativePath: path.relative(this.root, file),
304
304
  metadata: {
@@ -310,7 +310,7 @@ export default class FallbackWatcher extends AbstractWatcher {
310
310
  }
311
311
  },
312
312
  (symlink, stats) => {
313
- if (this._register(symlink, 'l')) {
313
+ if (this.#register(symlink, 'l')) {
314
314
  this.emitFileEvent({
315
315
  event: TOUCH_EVENT,
316
316
  relativePath: path.relative(this.root, symlink),
@@ -323,7 +323,7 @@ export default class FallbackWatcher extends AbstractWatcher {
323
323
  }
324
324
  },
325
325
  function endCallback() {},
326
- this._checkedEmitError,
326
+ this.#checkedEmitError,
327
327
  this.ignored,
328
328
  );
329
329
  } else {
@@ -337,10 +337,10 @@ export default class FallbackWatcher extends AbstractWatcher {
337
337
  type,
338
338
  };
339
339
  if (registered) {
340
- this._emitEvent({event: TOUCH_EVENT, relativePath, metadata});
340
+ this.#emitEvent({event: TOUCH_EVENT, relativePath, metadata});
341
341
  } else {
342
- if (this._register(fullPath, type)) {
343
- this._emitEvent({event: TOUCH_EVENT, relativePath, metadata});
342
+ if (this.#register(fullPath, type)) {
343
+ this.#emitEvent({event: TOUCH_EVENT, relativePath, metadata});
344
344
  }
345
345
  }
346
346
  }
@@ -349,12 +349,12 @@ export default class FallbackWatcher extends AbstractWatcher {
349
349
  this.emitError(error);
350
350
  return;
351
351
  }
352
- this._unregister(fullPath);
353
- this._unregisterDir(fullPath);
352
+ this.#unregister(fullPath);
353
+ this.#unregisterDir(fullPath);
354
354
  if (registered) {
355
- this._emitEvent({event: DELETE_EVENT, relativePath});
355
+ this.#emitEvent({event: DELETE_EVENT, relativePath});
356
356
  }
357
- await this._stopWatching(fullPath);
357
+ await this.#stopWatching(fullPath);
358
358
  }
359
359
  }
360
360
 
@@ -365,17 +365,17 @@ export default class FallbackWatcher extends AbstractWatcher {
365
365
  *
366
366
  * See also note above for DEBOUNCE_MS.
367
367
  */
368
- _emitEvent(change: Omit<WatcherBackendChangeEvent, 'root'>) {
368
+ #emitEvent(change: Omit<WatcherBackendChangeEvent, 'root'>) {
369
369
  const {event, relativePath} = change;
370
370
  const key = event + '-' + relativePath;
371
- const existingTimer = this._changeTimers.get(key);
371
+ const existingTimer = this.#changeTimers.get(key);
372
372
  if (existingTimer) {
373
373
  clearTimeout(existingTimer);
374
374
  }
375
- this._changeTimers.set(
375
+ this.#changeTimers.set(
376
376
  key,
377
377
  setTimeout(() => {
378
- this._changeTimers.delete(key);
378
+ this.#changeTimers.delete(key);
379
379
  this.emitFileEvent(change);
380
380
  }, DEBOUNCE_MS),
381
381
  );
@@ -9,28 +9,32 @@ var _common = require("./common");
9
9
  var _fs = require("fs");
10
10
  var _os = require("os");
11
11
  var path = _interopRequireWildcard(require("path"));
12
- function _getRequireWildcardCache(e) {
13
- if ("function" != typeof WeakMap) return null;
14
- var r = new WeakMap(),
15
- t = new WeakMap();
16
- return (_getRequireWildcardCache = function (e) {
17
- return e ? t : r;
18
- })(e);
19
- }
20
- function _interopRequireWildcard(e, r) {
21
- if (!r && e && e.__esModule) return e;
22
- if (null === e || ("object" != typeof e && "function" != typeof e))
23
- return { default: e };
24
- var t = _getRequireWildcardCache(r);
25
- if (t && t.has(e)) return t.get(e);
26
- var n = { __proto__: null },
27
- a = Object.defineProperty && Object.getOwnPropertyDescriptor;
28
- for (var u in e)
29
- if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
30
- var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
31
- i && (i.get || i.set) ? Object.defineProperty(n, u, i) : (n[u] = e[u]);
12
+ function _interopRequireWildcard(e, t) {
13
+ if ("function" == typeof WeakMap)
14
+ var r = new WeakMap(),
15
+ n = new WeakMap();
16
+ return (_interopRequireWildcard = function (e, t) {
17
+ if (!t && e && e.__esModule) return e;
18
+ var o,
19
+ i,
20
+ f = { __proto__: null, default: e };
21
+ if (null === e || ("object" != typeof e && "function" != typeof e))
22
+ return f;
23
+ if ((o = t ? n : r)) {
24
+ if (o.has(e)) return o.get(e);
25
+ o.set(e, f);
32
26
  }
33
- return ((n.default = e), t && t.set(e, n), n);
27
+ for (const t in e)
28
+ "default" !== t &&
29
+ {}.hasOwnProperty.call(e, t) &&
30
+ ((i =
31
+ (o = Object.defineProperty) &&
32
+ Object.getOwnPropertyDescriptor(e, t)) &&
33
+ (i.get || i.set)
34
+ ? o(f, t, i)
35
+ : (f[t] = e[t]));
36
+ return f;
37
+ })(e, t);
34
38
  }
35
39
  const debug = require("debug")("Metro:NativeWatcher");
36
40
  const TOUCH_EVENT = "touch";
@@ -4,8 +4,8 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
- * @format
8
7
  * @flow strict-local
8
+ * @format
9
9
  */
10
10
 
11
11
  import type {FSWatcher} from 'fs';
@@ -51,9 +51,9 @@ export default class NativeWatcher extends AbstractWatcher {
51
51
 
52
52
  constructor(
53
53
  dir: string,
54
- opts: $ReadOnly<{
54
+ opts: Readonly<{
55
55
  ignored: ?RegExp,
56
- globs: $ReadOnlyArray<string>,
56
+ globs: ReadonlyArray<string>,
57
57
  dot: boolean,
58
58
  ...
59
59
  }>,
@@ -38,7 +38,7 @@ export default class RecrawlWarning {
38
38
  return undefined;
39
39
  }
40
40
 
41
- static isRecrawlWarningDupe(warningMessage: mixed): boolean {
41
+ static isRecrawlWarningDupe(warningMessage: unknown): boolean {
42
42
  if (typeof warningMessage !== 'string') {
43
43
  return false;
44
44
  }
@@ -14,28 +14,32 @@ var _assert = _interopRequireDefault(require("assert"));
14
14
  var _crypto = require("crypto");
15
15
  var _fbWatchman = _interopRequireDefault(require("fb-watchman"));
16
16
  var _invariant = _interopRequireDefault(require("invariant"));
17
- function _getRequireWildcardCache(e) {
18
- if ("function" != typeof WeakMap) return null;
19
- var r = new WeakMap(),
20
- t = new WeakMap();
21
- return (_getRequireWildcardCache = function (e) {
22
- return e ? t : r;
23
- })(e);
24
- }
25
- function _interopRequireWildcard(e, r) {
26
- if (!r && e && e.__esModule) return e;
27
- if (null === e || ("object" != typeof e && "function" != typeof e))
28
- return { default: e };
29
- var t = _getRequireWildcardCache(r);
30
- if (t && t.has(e)) return t.get(e);
31
- var n = { __proto__: null },
32
- a = Object.defineProperty && Object.getOwnPropertyDescriptor;
33
- for (var u in e)
34
- if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
35
- var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
36
- i && (i.get || i.set) ? Object.defineProperty(n, u, i) : (n[u] = e[u]);
17
+ function _interopRequireWildcard(e, t) {
18
+ if ("function" == typeof WeakMap)
19
+ var r = new WeakMap(),
20
+ n = new WeakMap();
21
+ return (_interopRequireWildcard = function (e, t) {
22
+ if (!t && e && e.__esModule) return e;
23
+ var o,
24
+ i,
25
+ f = { __proto__: null, default: e };
26
+ if (null === e || ("object" != typeof e && "function" != typeof e))
27
+ return f;
28
+ if ((o = t ? n : r)) {
29
+ if (o.has(e)) return o.get(e);
30
+ o.set(e, f);
37
31
  }
38
- return ((n.default = e), t && t.set(e, n), n);
32
+ for (const t in e)
33
+ "default" !== t &&
34
+ {}.hasOwnProperty.call(e, t) &&
35
+ ((i =
36
+ (o = Object.defineProperty) &&
37
+ Object.getOwnPropertyDescriptor(e, t)) &&
38
+ (i.get || i.set)
39
+ ? o(f, t, i)
40
+ : (f[t] = e[t]));
41
+ return f;
42
+ })(e, t);
39
43
  }
40
44
  function _interopRequireDefault(e) {
41
45
  return e && e.__esModule ? e : { default: e };
@@ -45,10 +49,14 @@ const DELETE_EVENT = common.DELETE_EVENT;
45
49
  const TOUCH_EVENT = common.TOUCH_EVENT;
46
50
  const SUB_PREFIX = "metro-file-map";
47
51
  class WatchmanWatcher extends _AbstractWatcher.AbstractWatcher {
52
+ #client;
53
+ #watchProjectInfo;
54
+ #watchmanDeferStates;
48
55
  #deferringStates = null;
49
- constructor(dir, { watchmanDeferStates, ...opts }) {
50
- super(dir, opts);
51
- this.watchmanDeferStates = watchmanDeferStates;
56
+ constructor(dir, opts) {
57
+ const { watchmanDeferStates, ...baseOpts } = opts;
58
+ super(dir, baseOpts);
59
+ this.#watchmanDeferStates = watchmanDeferStates;
52
60
  const watchKey = (0, _crypto.createHash)("md5")
53
61
  .update(this.root)
54
62
  .digest("hex");
@@ -58,32 +66,32 @@ class WatchmanWatcher extends _AbstractWatcher.AbstractWatcher {
58
66
  this.subscriptionName = `${SUB_PREFIX}-${process.pid}-${readablePath}-${watchKey}`;
59
67
  }
60
68
  async startWatching() {
61
- await new Promise((resolve, reject) => this._init(resolve, reject));
69
+ await new Promise((resolve, reject) => this.#init(resolve, reject));
62
70
  }
63
- _init(onReady, onError) {
64
- if (this.client) {
65
- this.client.removeAllListeners();
71
+ #init(onReady, onError) {
72
+ if (this.#client) {
73
+ this.#client.removeAllListeners();
66
74
  }
67
75
  const self = this;
68
- this.client = new _fbWatchman.default.Client();
69
- this.client.on("error", (error) => {
76
+ this.#client = new _fbWatchman.default.Client();
77
+ this.#client.on("error", (error) => {
70
78
  this.emitError(error);
71
79
  });
72
- this.client.on("subscription", (changeEvent) =>
73
- this._handleChangeEvent(changeEvent),
80
+ this.#client.on("subscription", (changeEvent) =>
81
+ this.#handleChangeEvent(changeEvent),
74
82
  );
75
- this.client.on("end", () => {
83
+ this.#client.on("end", () => {
76
84
  console.warn(
77
85
  "[metro-file-map] Warning: Lost connection to Watchman, reconnecting..",
78
86
  );
79
- self._init(
87
+ self.#init(
80
88
  () => {},
81
89
  (error) => self.emitError(error),
82
90
  );
83
91
  });
84
- this.watchProjectInfo = null;
92
+ this.#watchProjectInfo = null;
85
93
  function getWatchRoot() {
86
- return self.watchProjectInfo ? self.watchProjectInfo.root : self.root;
94
+ return self.#watchProjectInfo ? self.#watchProjectInfo.root : self.root;
87
95
  }
88
96
  function onWatchProject(error, resp) {
89
97
  if (error) {
@@ -92,13 +100,13 @@ class WatchmanWatcher extends _AbstractWatcher.AbstractWatcher {
92
100
  }
93
101
  debug("Received watch-project response: %s", resp.relative_path);
94
102
  handleWarning(resp);
95
- self.watchProjectInfo = {
103
+ self.#watchProjectInfo = {
96
104
  relativePath: resp.relative_path
97
105
  ? (0, _normalizePathSeparatorsToSystem.default)(resp.relative_path)
98
106
  : "",
99
107
  root: (0, _normalizePathSeparatorsToSystem.default)(resp.watch),
100
108
  };
101
- self.client.command(["clock", getWatchRoot()], onClock);
109
+ self.#client.command(["clock", getWatchRoot()], onClock);
102
110
  }
103
111
  function onClock(error, resp) {
104
112
  if (error) {
@@ -106,7 +114,7 @@ class WatchmanWatcher extends _AbstractWatcher.AbstractWatcher {
106
114
  return;
107
115
  }
108
116
  debug("Received clock response: %s", resp.clock);
109
- const watchProjectInfo = self.watchProjectInfo;
117
+ const watchProjectInfo = self.#watchProjectInfo;
110
118
  (0, _invariant.default)(
111
119
  watchProjectInfo != null,
112
120
  "watch-project response should have been set before clock response",
@@ -115,7 +123,7 @@ class WatchmanWatcher extends _AbstractWatcher.AbstractWatcher {
115
123
  const options = {
116
124
  fields: ["name", "exists", "new", "type", "size", "mtime_ms"],
117
125
  since: resp.clock,
118
- defer: self.watchmanDeferStates,
126
+ defer: self.#watchmanDeferStates,
119
127
  relative_root: watchProjectInfo.relativePath,
120
128
  };
121
129
  if (self.globs.length === 0 && !self.dot) {
@@ -128,7 +136,7 @@ class WatchmanWatcher extends _AbstractWatcher.AbstractWatcher {
128
136
  },
129
137
  ];
130
138
  }
131
- self.client.command(
139
+ self.#client.command(
132
140
  ["subscribe", getWatchRoot(), self.subscriptionName, options],
133
141
  onSubscribe,
134
142
  );
@@ -145,9 +153,9 @@ class WatchmanWatcher extends _AbstractWatcher.AbstractWatcher {
145
153
  }
146
154
  onReady();
147
155
  };
148
- self.client.command(["watch-project", getWatchRoot()], onWatchProject);
156
+ self.#client.command(["watch-project", getWatchRoot()], onWatchProject);
149
157
  }
150
- _handleChangeEvent(resp) {
158
+ #handleChangeEvent(resp) {
151
159
  debug(
152
160
  "Received subscription response: %s (fresh: %s, files: %s, enter: %s, leave: %s, clock: %s)",
153
161
  resp.subscription,
@@ -164,13 +172,13 @@ class WatchmanWatcher extends _AbstractWatcher.AbstractWatcher {
164
172
  );
165
173
  if (Array.isArray(resp.files)) {
166
174
  resp.files.forEach((change) =>
167
- this._handleFileChange(change, resp.clock),
175
+ this.#handleFileChange(change, resp.clock),
168
176
  );
169
177
  }
170
178
  const { "state-enter": stateEnter, "state-leave": stateLeave } = resp;
171
179
  if (
172
180
  stateEnter != null &&
173
- (this.watchmanDeferStates ?? []).includes(stateEnter)
181
+ (this.#watchmanDeferStates ?? []).includes(stateEnter)
174
182
  ) {
175
183
  this.#deferringStates?.add(stateEnter);
176
184
  debug(
@@ -180,7 +188,7 @@ class WatchmanWatcher extends _AbstractWatcher.AbstractWatcher {
180
188
  }
181
189
  if (
182
190
  stateLeave != null &&
183
- (this.watchmanDeferStates ?? []).includes(stateLeave)
191
+ (this.#watchmanDeferStates ?? []).includes(stateLeave)
184
192
  ) {
185
193
  this.#deferringStates?.delete(stateLeave);
186
194
  debug(
@@ -189,9 +197,9 @@ class WatchmanWatcher extends _AbstractWatcher.AbstractWatcher {
189
197
  );
190
198
  }
191
199
  }
192
- _handleFileChange(changeDescriptor, rawClock) {
200
+ #handleFileChange(changeDescriptor, rawClock) {
193
201
  const self = this;
194
- const watchProjectInfo = self.watchProjectInfo;
202
+ const watchProjectInfo = self.#watchProjectInfo;
195
203
  (0, _invariant.default)(
196
204
  watchProjectInfo != null,
197
205
  "watch-project response should have been set before receiving subscription events",
@@ -224,8 +232,8 @@ class WatchmanWatcher extends _AbstractWatcher.AbstractWatcher {
224
232
  return;
225
233
  }
226
234
  const clock =
227
- typeof rawClock === "string" && this.watchProjectInfo != null
228
- ? [this.watchProjectInfo.root, rawClock]
235
+ typeof rawClock === "string" && this.#watchProjectInfo != null
236
+ ? [this.#watchProjectInfo.root, rawClock]
229
237
  : undefined;
230
238
  if (!exists) {
231
239
  self.emitFileEvent({
@@ -260,9 +268,9 @@ class WatchmanWatcher extends _AbstractWatcher.AbstractWatcher {
260
268
  }
261
269
  async stopWatching() {
262
270
  await super.stopWatching();
263
- if (this.client) {
264
- this.client.removeAllListeners();
265
- this.client.end();
271
+ if (this.#client) {
272
+ this.#client.removeAllListeners();
273
+ this.#client.end();
266
274
  }
267
275
  this.#deferringStates = null;
268
276
  }