metro-file-map 0.84.2 → 0.84.3

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 (37) hide show
  1. package/package.json +1 -1
  2. package/src/Watcher.d.ts +6 -9
  3. package/src/Watcher.js +66 -39
  4. package/src/Watcher.js.flow +84 -51
  5. package/src/crawlers/node/index.d.ts +3 -5
  6. package/src/crawlers/node/index.js +4 -1
  7. package/src/crawlers/node/index.js.flow +8 -6
  8. package/src/crawlers/watchman/index.d.ts +5 -12
  9. package/src/crawlers/watchman/index.js.flow +2 -6
  10. package/src/flow-types.d.ts +81 -32
  11. package/src/flow-types.js.flow +89 -29
  12. package/src/index.d.ts +4 -4
  13. package/src/index.js +145 -120
  14. package/src/index.js.flow +199 -149
  15. package/src/lib/FileSystemChangeAggregator.d.ts +40 -0
  16. package/src/lib/FileSystemChangeAggregator.js +89 -0
  17. package/src/lib/FileSystemChangeAggregator.js.flow +143 -0
  18. package/src/lib/TreeFS.d.ts +16 -8
  19. package/src/lib/TreeFS.js +67 -16
  20. package/src/lib/TreeFS.js.flow +89 -16
  21. package/src/plugins/DependencyPlugin.d.ts +2 -13
  22. package/src/plugins/DependencyPlugin.js +1 -3
  23. package/src/plugins/DependencyPlugin.js.flow +1 -16
  24. package/src/plugins/HastePlugin.d.ts +3 -11
  25. package/src/plugins/HastePlugin.js +11 -11
  26. package/src/plugins/HastePlugin.js.flow +12 -12
  27. package/src/plugins/MockPlugin.d.ts +3 -5
  28. package/src/plugins/MockPlugin.js +17 -20
  29. package/src/plugins/MockPlugin.js.flow +18 -22
  30. package/src/watchers/FallbackWatcher.js +19 -3
  31. package/src/watchers/FallbackWatcher.js.flow +28 -5
  32. package/src/watchers/NativeWatcher.d.ts +2 -2
  33. package/src/watchers/NativeWatcher.js +27 -5
  34. package/src/watchers/NativeWatcher.js.flow +33 -6
  35. package/src/watchers/common.d.ts +3 -1
  36. package/src/watchers/common.js +6 -1
  37. package/src/watchers/common.js.flow +1 -0
@@ -10,7 +10,6 @@
10
10
  */
11
11
 
12
12
  import type {
13
- FileMapDelta,
14
13
  FileMapPlugin,
15
14
  FileMapPluginInitOptions,
16
15
  FileMapPluginWorker,
@@ -64,25 +63,11 @@ export default class DependencyPlugin
64
63
  return null;
65
64
  }
66
65
 
67
- bulkUpdate(delta: FileMapDelta<?ReadonlyArray<string>>): void {
66
+ onChanged(): void {
68
67
  // No-op: Worker already populated plugin data
69
68
  // Plugin data is write-only from worker
70
69
  }
71
70
 
72
- onNewOrModifiedFile(
73
- relativeFilePath: string,
74
- pluginData: ?ReadonlyArray<string>,
75
- ): void {
76
- // No-op: Dependencies already in plugin data
77
- }
78
-
79
- onRemovedFile(
80
- relativeFilePath: string,
81
- pluginData: ?ReadonlyArray<string>,
82
- ): void {
83
- // No-op
84
- }
85
-
86
71
  assertValid(): void {
87
72
  // No validation needed
88
73
  }
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * @noformat
8
8
  * @oncall react_native
9
- * @generated SignedSource<<c8bc637264c4155765c375a0f0971803>>
9
+ * @generated SignedSource<<3d1462ab2325a09553e02b69b5de84eb>>
10
10
  *
11
11
  * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
12
  * Original file: packages/metro-file-map/src/plugins/HastePlugin.js
@@ -17,7 +17,6 @@
17
17
 
18
18
  import type {
19
19
  Console,
20
- FileMapDelta,
21
20
  FileMapPlugin,
22
21
  FileMapPluginInitOptions,
23
22
  FileMapPluginWorker,
@@ -27,6 +26,7 @@ import type {
27
26
  HTypeValue,
28
27
  Path,
29
28
  PerfLogger,
29
+ ReadonlyFileSystemChanges,
30
30
  } from '../flow-types';
31
31
 
32
32
  export type HasteMapOptions = Readonly<{
@@ -59,16 +59,8 @@ declare class HastePlugin
59
59
  platform: null | undefined | string,
60
60
  _supportsNativePlatform?: null | undefined | boolean,
61
61
  ): null | undefined | Path;
62
- bulkUpdate(delta: FileMapDelta<null | undefined | string>): void;
63
- onNewOrModifiedFile(
64
- relativeFilePath: string,
65
- id: null | undefined | string,
66
- ): void;
62
+ onChanged(delta: ReadonlyFileSystemChanges<null | undefined | string>): void;
67
63
  setModule(id: string, module: HasteMapItemMetadata): void;
68
- onRemovedFile(
69
- relativeFilePath: string,
70
- moduleName: null | undefined | string,
71
- ): void;
72
64
  assertValid(): void;
73
65
  computeConflicts(): Array<HasteConflict>;
74
66
  getCacheKey(): string;
@@ -163,22 +163,22 @@ class HastePlugin {
163
163
  duplicates,
164
164
  );
165
165
  }
166
- bulkUpdate(delta) {
167
- for (const [normalPath, maybeHasteId] of delta.removed) {
168
- this.onRemovedFile(normalPath, maybeHasteId);
166
+ onChanged(delta) {
167
+ for (const [canonicalPath, maybeHasteId] of delta.removedFiles) {
168
+ this.#onRemovedFile(canonicalPath, maybeHasteId);
169
169
  }
170
- for (const [normalPath, maybeHasteId] of delta.addedOrModified) {
171
- this.onNewOrModifiedFile(normalPath, maybeHasteId);
170
+ for (const [canonicalPath, maybeHasteId] of delta.addedFiles) {
171
+ this.#onNewFile(canonicalPath, maybeHasteId);
172
172
  }
173
173
  }
174
- onNewOrModifiedFile(relativeFilePath, id) {
174
+ #onNewFile(canonicalPath, id) {
175
175
  if (id == null) {
176
176
  return;
177
177
  }
178
178
  const module = [
179
- relativeFilePath,
179
+ canonicalPath,
180
180
  this.#enableHastePackages &&
181
- _path.default.basename(relativeFilePath) === "package.json"
181
+ _path.default.basename(canonicalPath) === "package.json"
182
182
  ? _constants.default.PACKAGE
183
183
  : _constants.default.MODULE,
184
184
  ];
@@ -248,12 +248,12 @@ class HastePlugin {
248
248
  }
249
249
  hasteMapItem[platform] = module;
250
250
  }
251
- onRemovedFile(relativeFilePath, moduleName) {
251
+ #onRemovedFile(canonicalPath, moduleName) {
252
252
  if (moduleName == null) {
253
253
  return;
254
254
  }
255
255
  const platform =
256
- (0, _getPlatformExtension.default)(relativeFilePath, this.#platforms) ||
256
+ (0, _getPlatformExtension.default)(canonicalPath, this.#platforms) ||
257
257
  _constants.default.GENERIC_PLATFORM;
258
258
  const hasteMapItem = this.#map.get(moduleName);
259
259
  if (hasteMapItem != null) {
@@ -264,7 +264,7 @@ class HastePlugin {
264
264
  this.#map.set(moduleName, hasteMapItem);
265
265
  }
266
266
  }
267
- this.#recoverDuplicates(moduleName, relativeFilePath);
267
+ this.#recoverDuplicates(moduleName, canonicalPath);
268
268
  }
269
269
  assertValid() {
270
270
  if (!this.#failValidationOnConflicts) {
@@ -13,7 +13,6 @@ import type {
13
13
  Console,
14
14
  DuplicatesIndex,
15
15
  DuplicatesSet,
16
- FileMapDelta,
17
16
  FileMapPlugin,
18
17
  FileMapPluginInitOptions,
19
18
  FileMapPluginWorker,
@@ -24,6 +23,7 @@ import type {
24
23
  HTypeValue,
25
24
  Path,
26
25
  PerfLogger,
26
+ ReadonlyFileSystemChanges,
27
27
  } from '../flow-types';
28
28
 
29
29
  import H from '../constants';
@@ -237,26 +237,26 @@ export default class HastePlugin
237
237
  );
238
238
  }
239
239
 
240
- bulkUpdate(delta: FileMapDelta<?string>): void {
240
+ onChanged(delta: ReadonlyFileSystemChanges<?string>): void {
241
241
  // Process removals first so that moves aren't treated as duplicates.
242
- for (const [normalPath, maybeHasteId] of delta.removed) {
243
- this.onRemovedFile(normalPath, maybeHasteId);
242
+ for (const [canonicalPath, maybeHasteId] of delta.removedFiles) {
243
+ this.#onRemovedFile(canonicalPath, maybeHasteId);
244
244
  }
245
- for (const [normalPath, maybeHasteId] of delta.addedOrModified) {
246
- this.onNewOrModifiedFile(normalPath, maybeHasteId);
245
+ for (const [canonicalPath, maybeHasteId] of delta.addedFiles) {
246
+ this.#onNewFile(canonicalPath, maybeHasteId);
247
247
  }
248
248
  }
249
249
 
250
- onNewOrModifiedFile(relativeFilePath: string, id: ?string) {
250
+ #onNewFile(canonicalPath: string, id: ?string) {
251
251
  if (id == null) {
252
252
  // Not a Haste module or package
253
253
  return;
254
254
  }
255
255
 
256
256
  const module: HasteMapItemMetadata = [
257
- relativeFilePath,
257
+ canonicalPath,
258
258
  this.#enableHastePackages &&
259
- path.basename(relativeFilePath) === 'package.json'
259
+ path.basename(canonicalPath) === 'package.json'
260
260
  ? H.PACKAGE
261
261
  : H.MODULE,
262
262
  ];
@@ -324,14 +324,14 @@ export default class HastePlugin
324
324
  hasteMapItem[platform] = module;
325
325
  }
326
326
 
327
- onRemovedFile(relativeFilePath: string, moduleName: ?string) {
327
+ #onRemovedFile(canonicalPath: string, moduleName: ?string) {
328
328
  if (moduleName == null) {
329
329
  // Not a Haste module or package
330
330
  return;
331
331
  }
332
332
 
333
333
  const platform =
334
- getPlatformExtension(relativeFilePath, this.#platforms) ||
334
+ getPlatformExtension(canonicalPath, this.#platforms) ||
335
335
  H.GENERIC_PLATFORM;
336
336
 
337
337
  const hasteMapItem = this.#map.get(moduleName);
@@ -344,7 +344,7 @@ export default class HastePlugin
344
344
  }
345
345
  }
346
346
 
347
- this.#recoverDuplicates(moduleName, relativeFilePath);
347
+ this.#recoverDuplicates(moduleName, canonicalPath);
348
348
  }
349
349
 
350
350
  assertValid(): void {
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * @noformat
8
8
  * @oncall react_native
9
- * @generated SignedSource<<81805d051693b746e75928fe6ed3dbca>>
9
+ * @generated SignedSource<<d9402d4670982b1e675e1edd9201cf75>>
10
10
  *
11
11
  * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
12
  * Original file: packages/metro-file-map/src/plugins/MockPlugin.js
@@ -16,13 +16,13 @@
16
16
  */
17
17
 
18
18
  import type {
19
- FileMapDelta,
20
19
  FileMapPlugin,
21
20
  FileMapPluginInitOptions,
22
21
  FileMapPluginWorker,
23
22
  MockMap as IMockMap,
24
23
  Path,
25
24
  RawMockMap,
25
+ ReadonlyFileSystemChanges,
26
26
  } from '../flow-types';
27
27
 
28
28
  export declare const CACHE_VERSION: 2;
@@ -39,9 +39,7 @@ declare class MockPlugin implements FileMapPlugin<RawMockMap, void>, IMockMap {
39
39
  constructor($$PARAM_0$$: MockMapOptions);
40
40
  initialize($$PARAM_0$$: FileMapPluginInitOptions<RawMockMap>): Promise<void>;
41
41
  getMockModule(name: string): null | undefined | Path;
42
- bulkUpdate(delta: FileMapDelta): void;
43
- onNewOrModifiedFile(relativeFilePath: Path): void;
44
- onRemovedFile(relativeFilePath: Path): void;
42
+ onChanged(delta: ReadonlyFileSystemChanges<null | undefined | void>): void;
45
43
  getSerializableSnapshot(): RawMockMap;
46
44
  assertValid(): void;
47
45
  getCacheKey(): string;
@@ -51,15 +51,12 @@ class MockPlugin {
51
51
  if (pluginState != null && pluginState.version === this.#raw.version) {
52
52
  this.#raw = pluginState;
53
53
  } else {
54
- this.bulkUpdate({
55
- addedOrModified: [
56
- ...files.fileIterator({
57
- includeNodeModules: false,
58
- includeSymlinks: false,
59
- }),
60
- ].map(({ canonicalPath }) => [canonicalPath, null]),
61
- removed: [],
62
- });
54
+ for (const { canonicalPath } of files.fileIterator({
55
+ includeNodeModules: false,
56
+ includeSymlinks: false,
57
+ })) {
58
+ this.#onFileAdded(canonicalPath);
59
+ }
63
60
  }
64
61
  }
65
62
  getMockModule(name) {
@@ -72,22 +69,22 @@ class MockPlugin {
72
69
  (0, _normalizePathSeparatorsToSystem.default)(mockPosixRelativePath),
73
70
  );
74
71
  }
75
- bulkUpdate(delta) {
76
- for (const [relativeFilePath] of delta.removed) {
77
- this.onRemovedFile(relativeFilePath);
72
+ onChanged(delta) {
73
+ for (const [canonicalPath] of delta.removedFiles) {
74
+ this.#onFileRemoved(canonicalPath);
78
75
  }
79
- for (const [relativeFilePath] of delta.addedOrModified) {
80
- this.onNewOrModifiedFile(relativeFilePath);
76
+ for (const [canonicalPath] of delta.addedFiles) {
77
+ this.#onFileAdded(canonicalPath);
81
78
  }
82
79
  }
83
- onNewOrModifiedFile(relativeFilePath) {
84
- const absoluteFilePath = this.#pathUtils.normalToAbsolute(relativeFilePath);
80
+ #onFileAdded(canonicalPath) {
81
+ const absoluteFilePath = this.#pathUtils.normalToAbsolute(canonicalPath);
85
82
  if (!this.#mocksPattern.test(absoluteFilePath)) {
86
83
  return;
87
84
  }
88
85
  const mockName = (0, _getMockName.default)(absoluteFilePath);
89
86
  const posixRelativePath = (0, _normalizePathSeparatorsToPosix.default)(
90
- relativeFilePath,
87
+ canonicalPath,
91
88
  );
92
89
  const existingMockPosixPath = this.#raw.mocks.get(mockName);
93
90
  if (existingMockPosixPath != null) {
@@ -104,8 +101,8 @@ class MockPlugin {
104
101
  }
105
102
  this.#raw.mocks.set(mockName, posixRelativePath);
106
103
  }
107
- onRemovedFile(relativeFilePath) {
108
- const absoluteFilePath = this.#pathUtils.normalToAbsolute(relativeFilePath);
104
+ #onFileRemoved(canonicalPath) {
105
+ const absoluteFilePath = this.#pathUtils.normalToAbsolute(canonicalPath);
109
106
  if (!this.#mocksPattern.test(absoluteFilePath)) {
110
107
  return;
111
108
  }
@@ -113,7 +110,7 @@ class MockPlugin {
113
110
  const duplicates = this.#raw.duplicates.get(mockName);
114
111
  if (duplicates != null) {
115
112
  const posixRelativePath = (0, _normalizePathSeparatorsToPosix.default)(
116
- relativeFilePath,
113
+ canonicalPath,
117
114
  );
118
115
  duplicates.delete(posixRelativePath);
119
116
  if (duplicates.size === 1) {
@@ -10,13 +10,13 @@
10
10
  */
11
11
 
12
12
  import type {
13
- FileMapDelta,
14
13
  FileMapPlugin,
15
14
  FileMapPluginInitOptions,
16
15
  FileMapPluginWorker,
17
16
  MockMap as IMockMap,
18
17
  Path,
19
18
  RawMockMap,
19
+ ReadonlyFileSystemChanges,
20
20
  } from '../flow-types';
21
21
 
22
22
  import normalizePathSeparatorsToPosix from '../lib/normalizePathSeparatorsToPosix';
@@ -79,15 +79,12 @@ export default class MockPlugin
79
79
  this.#raw = pluginState;
80
80
  } else {
81
81
  // Otherwise, traverse all files to rebuild
82
- this.bulkUpdate({
83
- addedOrModified: [
84
- ...files.fileIterator({
85
- includeNodeModules: false,
86
- includeSymlinks: false,
87
- }),
88
- ].map(({canonicalPath}) => [canonicalPath, null]),
89
- removed: [],
90
- });
82
+ for (const {canonicalPath} of files.fileIterator({
83
+ includeNodeModules: false,
84
+ includeSymlinks: false,
85
+ })) {
86
+ this.#onFileAdded(canonicalPath);
87
+ }
91
88
  }
92
89
  }
93
90
 
@@ -102,24 +99,24 @@ export default class MockPlugin
102
99
  );
103
100
  }
104
101
 
105
- bulkUpdate(delta: FileMapDelta<>): void {
102
+ onChanged(delta: ReadonlyFileSystemChanges<?void>): void {
106
103
  // Process removals first so that moves aren't treated as duplicates.
107
- for (const [relativeFilePath] of delta.removed) {
108
- this.onRemovedFile(relativeFilePath);
104
+ for (const [canonicalPath] of delta.removedFiles) {
105
+ this.#onFileRemoved(canonicalPath);
109
106
  }
110
- for (const [relativeFilePath] of delta.addedOrModified) {
111
- this.onNewOrModifiedFile(relativeFilePath);
107
+ for (const [canonicalPath] of delta.addedFiles) {
108
+ this.#onFileAdded(canonicalPath);
112
109
  }
113
110
  }
114
111
 
115
- onNewOrModifiedFile(relativeFilePath: Path): void {
116
- const absoluteFilePath = this.#pathUtils.normalToAbsolute(relativeFilePath);
112
+ #onFileAdded(canonicalPath: Path): void {
113
+ const absoluteFilePath = this.#pathUtils.normalToAbsolute(canonicalPath);
117
114
  if (!this.#mocksPattern.test(absoluteFilePath)) {
118
115
  return;
119
116
  }
120
117
 
121
118
  const mockName = getMockName(absoluteFilePath);
122
- const posixRelativePath = normalizePathSeparatorsToPosix(relativeFilePath);
119
+ const posixRelativePath = normalizePathSeparatorsToPosix(canonicalPath);
123
120
 
124
121
  const existingMockPosixPath = this.#raw.mocks.get(mockName);
125
122
  if (existingMockPosixPath != null) {
@@ -141,16 +138,15 @@ export default class MockPlugin
141
138
  this.#raw.mocks.set(mockName, posixRelativePath);
142
139
  }
143
140
 
144
- onRemovedFile(relativeFilePath: Path): void {
145
- const absoluteFilePath = this.#pathUtils.normalToAbsolute(relativeFilePath);
141
+ #onFileRemoved(canonicalPath: Path): void {
142
+ const absoluteFilePath = this.#pathUtils.normalToAbsolute(canonicalPath);
146
143
  if (!this.#mocksPattern.test(absoluteFilePath)) {
147
144
  return;
148
145
  }
149
146
  const mockName = getMockName(absoluteFilePath);
150
147
  const duplicates = this.#raw.duplicates.get(mockName);
151
148
  if (duplicates != null) {
152
- const posixRelativePath =
153
- normalizePathSeparatorsToPosix(relativeFilePath);
149
+ const posixRelativePath = normalizePathSeparatorsToPosix(canonicalPath);
154
150
  duplicates.delete(posixRelativePath);
155
151
  if (duplicates.size === 1) {
156
152
  this.#raw.duplicates.delete(mockName);
@@ -99,9 +99,19 @@ class FallbackWatcher extends _AbstractWatcher.AbstractWatcher {
99
99
  }
100
100
  }
101
101
  #unregisterDir(dirpath) {
102
- if (this.#dirRegistry[dirpath]) {
103
- delete this.#dirRegistry[dirpath];
102
+ const removedFiles = [];
103
+ for (const registeredDir of Object.keys(this.#dirRegistry)) {
104
+ if (
105
+ registeredDir === dirpath ||
106
+ registeredDir.startsWith(dirpath + _path.default.sep)
107
+ ) {
108
+ for (const filename of Object.keys(this.#dirRegistry[registeredDir])) {
109
+ removedFiles.push(_path.default.join(registeredDir, filename));
110
+ }
111
+ delete this.#dirRegistry[registeredDir];
112
+ }
104
113
  }
114
+ return removedFiles;
105
115
  }
106
116
  #registered(fullpath) {
107
117
  const dir = _path.default.dirname(fullpath);
@@ -294,7 +304,13 @@ class FallbackWatcher extends _AbstractWatcher.AbstractWatcher {
294
304
  return;
295
305
  }
296
306
  this.#unregister(fullPath);
297
- this.#unregisterDir(fullPath);
307
+ const removedFiles = this.#unregisterDir(fullPath);
308
+ for (const removedFile of removedFiles) {
309
+ this.#emitEvent({
310
+ event: DELETE_EVENT,
311
+ relativePath: _path.default.relative(this.root, removedFile),
312
+ });
313
+ }
298
314
  if (registered) {
299
315
  this.#emitEvent({
300
316
  event: DELETE_EVENT,
@@ -124,12 +124,27 @@ export default class FallbackWatcher extends AbstractWatcher {
124
124
  }
125
125
 
126
126
  /**
127
- * Removes a dir from the registry.
127
+ * Removes a dir from the registry, returning all files that were registered
128
+ * under it (recursively).
128
129
  */
129
- #unregisterDir(dirpath: string): void {
130
- if (this.#dirRegistry[dirpath]) {
131
- delete this.#dirRegistry[dirpath];
130
+ #unregisterDir(dirpath: string): Array<string> {
131
+ const removedFiles: Array<string> = [];
132
+
133
+ // Find and remove all entries under this directory
134
+ for (const registeredDir of Object.keys(this.#dirRegistry)) {
135
+ if (
136
+ registeredDir === dirpath ||
137
+ registeredDir.startsWith(dirpath + path.sep)
138
+ ) {
139
+ // Collect all files in this directory
140
+ for (const filename of Object.keys(this.#dirRegistry[registeredDir])) {
141
+ removedFiles.push(path.join(registeredDir, filename));
142
+ }
143
+ delete this.#dirRegistry[registeredDir];
144
+ }
132
145
  }
146
+
147
+ return removedFiles;
133
148
  }
134
149
 
135
150
  /**
@@ -350,7 +365,15 @@ export default class FallbackWatcher extends AbstractWatcher {
350
365
  return;
351
366
  }
352
367
  this.#unregister(fullPath);
353
- this.#unregisterDir(fullPath);
368
+ // When a directory is deleted, emit delete events for all files we
369
+ // knew about under that directory
370
+ const removedFiles = this.#unregisterDir(fullPath);
371
+ for (const removedFile of removedFiles) {
372
+ this.#emitEvent({
373
+ event: DELETE_EVENT,
374
+ relativePath: path.relative(this.root, removedFile),
375
+ });
376
+ }
354
377
  if (registered) {
355
378
  this.#emitEvent({event: DELETE_EVENT, relativePath});
356
379
  }
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  * @noformat
8
- * @generated SignedSource<<8239479487abff6df70ee54f9e05f352>>
8
+ * @generated SignedSource<<b68c5620efd3f5bec83279059d0d1b4e>>
9
9
  *
10
10
  * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
11
11
  * Original file: packages/metro-file-map/src/watchers/NativeWatcher.js
@@ -50,6 +50,6 @@ declare class NativeWatcher extends AbstractWatcher {
50
50
  * End watching.
51
51
  */
52
52
  stopWatching(): Promise<void>;
53
- _handleEvent(relativePath: string): void;
53
+ _handleEvent(event: string, relativePath: string): void;
54
54
  }
55
55
  export default NativeWatcher;
@@ -39,6 +39,7 @@ function _interopRequireWildcard(e, t) {
39
39
  const debug = require("debug")("Metro:NativeWatcher");
40
40
  const TOUCH_EVENT = "touch";
41
41
  const DELETE_EVENT = "delete";
42
+ const RECRAWL_EVENT = "recrawl";
42
43
  class NativeWatcher extends _AbstractWatcher.AbstractWatcher {
43
44
  #fsWatcher;
44
45
  static isSupported() {
@@ -57,8 +58,8 @@ class NativeWatcher extends _AbstractWatcher.AbstractWatcher {
57
58
  persistent: false,
58
59
  recursive: true,
59
60
  },
60
- (_event, relativePath) => {
61
- this._handleEvent(relativePath).catch((error) => {
61
+ (event, relativePath) => {
62
+ this._handleEvent(event, relativePath).catch((error) => {
62
63
  this.emitError(error);
63
64
  });
64
65
  },
@@ -71,13 +72,23 @@ class NativeWatcher extends _AbstractWatcher.AbstractWatcher {
71
72
  this.#fsWatcher.close();
72
73
  }
73
74
  }
74
- async _handleEvent(relativePath) {
75
+ async _handleEvent(event, relativePath) {
75
76
  const absolutePath = path.resolve(this.root, relativePath);
76
77
  if (this.doIgnore(relativePath)) {
77
- debug("Ignoring event on %s (root: %s)", relativePath, this.root);
78
+ debug(
79
+ 'Ignoring event "%s" on %s (root: %s)',
80
+ event,
81
+ relativePath,
82
+ this.root,
83
+ );
78
84
  return;
79
85
  }
80
- debug("Handling event on %s (root: %s)", relativePath, this.root);
86
+ debug(
87
+ 'Handling event "%s" on %s (root: %s)',
88
+ event,
89
+ relativePath,
90
+ this.root,
91
+ );
81
92
  try {
82
93
  const stat = await _fs.promises.lstat(absolutePath);
83
94
  const type = (0, _common.typeFromStat)(stat);
@@ -89,6 +100,17 @@ class NativeWatcher extends _AbstractWatcher.AbstractWatcher {
89
100
  ) {
90
101
  return;
91
102
  }
103
+ if (type === "d" && event === "rename") {
104
+ debug(
105
+ "Directory rename detected on %s, requesting recrawl",
106
+ relativePath,
107
+ );
108
+ this.emitFileEvent({
109
+ event: RECRAWL_EVENT,
110
+ relativePath,
111
+ });
112
+ return;
113
+ }
92
114
  this.emitFileEvent({
93
115
  event: TOUCH_EVENT,
94
116
  relativePath,
@@ -21,6 +21,7 @@ const debug = require('debug')('Metro:NativeWatcher');
21
21
 
22
22
  const TOUCH_EVENT = 'touch';
23
23
  const DELETE_EVENT = 'delete';
24
+ const RECRAWL_EVENT = 'recrawl';
24
25
 
25
26
  /**
26
27
  * NativeWatcher uses Node's native fs.watch API with recursive: true.
@@ -74,9 +75,8 @@ export default class NativeWatcher extends AbstractWatcher {
74
75
  // ~instant on macOS or Windows.
75
76
  recursive: true,
76
77
  },
77
- (_event, relativePath) => {
78
- // _event is always 'rename' on macOS, so we don't use it.
79
- this._handleEvent(relativePath).catch(error => {
78
+ (event, relativePath) => {
79
+ this._handleEvent(event, relativePath).catch(error => {
80
80
  this.emitError(error);
81
81
  });
82
82
  },
@@ -95,13 +95,23 @@ export default class NativeWatcher extends AbstractWatcher {
95
95
  }
96
96
  }
97
97
 
98
- async _handleEvent(relativePath: string) {
98
+ async _handleEvent(event: string, relativePath: string) {
99
99
  const absolutePath = path.resolve(this.root, relativePath);
100
100
  if (this.doIgnore(relativePath)) {
101
- debug('Ignoring event on %s (root: %s)', relativePath, this.root);
101
+ debug(
102
+ 'Ignoring event "%s" on %s (root: %s)',
103
+ event,
104
+ relativePath,
105
+ this.root,
106
+ );
102
107
  return;
103
108
  }
104
- debug('Handling event on %s (root: %s)', relativePath, this.root);
109
+ debug(
110
+ 'Handling event "%s" on %s (root: %s)',
111
+ event,
112
+ relativePath,
113
+ this.root,
114
+ );
105
115
 
106
116
  try {
107
117
  const stat = await fsPromises.lstat(absolutePath);
@@ -116,6 +126,23 @@ export default class NativeWatcher extends AbstractWatcher {
116
126
  return;
117
127
  }
118
128
 
129
+ // For directory "rename" events, notify that we need a recrawl since we
130
+ // wont' receive events for unmodified files underneath a moved (or
131
+ // cloned) directory. Renames are fired by the OS on moves, clones, and
132
+ // creations. We ignore "change" events because they indiciate a change
133
+ // to directory metadata, rather than its path or existence.
134
+ if (type === 'd' && event === 'rename') {
135
+ debug(
136
+ 'Directory rename detected on %s, requesting recrawl',
137
+ relativePath,
138
+ );
139
+ this.emitFileEvent({
140
+ event: RECRAWL_EVENT,
141
+ relativePath,
142
+ });
143
+ return;
144
+ }
145
+
119
146
  this.emitFileEvent({
120
147
  event: TOUCH_EVENT,
121
148
  relativePath,
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * @noformat
8
8
  * @oncall react_native
9
- * @generated SignedSource<<4f8f87abcb055b965a90e994a55ed177>>
9
+ * @generated SignedSource<<ebebfbca9d43e034fde8489e1d9f2dbb>>
10
10
  *
11
11
  * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
12
  * Original file: packages/metro-file-map/src/watchers/common.js
@@ -29,6 +29,8 @@ export declare const DELETE_EVENT: 'delete';
29
29
  export declare type DELETE_EVENT = typeof DELETE_EVENT;
30
30
  export declare const TOUCH_EVENT: 'touch';
31
31
  export declare type TOUCH_EVENT = typeof TOUCH_EVENT;
32
+ export declare const RECRAWL_EVENT: 'recrawl';
33
+ export declare type RECRAWL_EVENT = typeof RECRAWL_EVENT;
32
34
  export declare const ALL_EVENT: 'all';
33
35
  export declare type ALL_EVENT = typeof ALL_EVENT;
34
36
  export type WatcherOptions = Readonly<{