metro-file-map 0.83.5 → 0.83.6

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 (57) hide show
  1. package/package.json +1 -1
  2. package/src/Watcher.d.ts +13 -9
  3. package/src/Watcher.js +66 -39
  4. package/src/Watcher.js.flow +84 -51
  5. package/src/cache/DiskCacheManager.d.ts +8 -1
  6. package/src/constants.d.ts +8 -1
  7. package/src/crawlers/node/hasNativeFindSupport.d.ts +8 -1
  8. package/src/crawlers/node/index.d.ts +10 -5
  9. package/src/crawlers/node/index.js +4 -1
  10. package/src/crawlers/node/index.js.flow +8 -6
  11. package/src/crawlers/watchman/index.d.ts +12 -12
  12. package/src/crawlers/watchman/index.js.flow +2 -6
  13. package/src/flow-types.d.ts +88 -32
  14. package/src/flow-types.js.flow +89 -29
  15. package/src/index.d.ts +11 -4
  16. package/src/index.js +145 -120
  17. package/src/index.js.flow +199 -149
  18. package/src/lib/FileProcessor.d.ts +8 -1
  19. package/src/lib/FileSystemChangeAggregator.d.ts +40 -0
  20. package/src/lib/FileSystemChangeAggregator.js +89 -0
  21. package/src/lib/FileSystemChangeAggregator.js.flow +143 -0
  22. package/src/lib/RootPathUtils.d.ts +8 -1
  23. package/src/lib/TreeFS.d.ts +23 -8
  24. package/src/lib/TreeFS.js +67 -16
  25. package/src/lib/TreeFS.js.flow +89 -16
  26. package/src/lib/checkWatchmanCapabilities.d.ts +8 -1
  27. package/src/lib/normalizePathSeparatorsToPosix.d.ts +8 -1
  28. package/src/lib/normalizePathSeparatorsToSystem.d.ts +8 -1
  29. package/src/lib/rootRelativeCacheKeys.d.ts +8 -1
  30. package/src/lib/sorting.d.ts +8 -1
  31. package/src/plugins/DependencyPlugin.d.ts +9 -13
  32. package/src/plugins/DependencyPlugin.js +1 -3
  33. package/src/plugins/DependencyPlugin.js.flow +1 -16
  34. package/src/plugins/HastePlugin.d.ts +10 -11
  35. package/src/plugins/HastePlugin.js +11 -11
  36. package/src/plugins/HastePlugin.js.flow +12 -12
  37. package/src/plugins/MockPlugin.d.ts +10 -5
  38. package/src/plugins/MockPlugin.js +17 -20
  39. package/src/plugins/MockPlugin.js.flow +18 -22
  40. package/src/plugins/dependencies/dependencyExtractor.d.ts +1 -1
  41. package/src/plugins/haste/DuplicateHasteCandidatesError.d.ts +8 -1
  42. package/src/plugins/haste/HasteConflictsError.d.ts +8 -1
  43. package/src/plugins/haste/computeConflicts.d.ts +8 -1
  44. package/src/plugins/haste/getPlatformExtension.d.ts +8 -1
  45. package/src/plugins/mocks/getMockName.d.ts +8 -1
  46. package/src/watchers/AbstractWatcher.d.ts +8 -1
  47. package/src/watchers/FallbackWatcher.d.ts +8 -1
  48. package/src/watchers/FallbackWatcher.js +19 -3
  49. package/src/watchers/FallbackWatcher.js.flow +28 -5
  50. package/src/watchers/NativeWatcher.d.ts +9 -2
  51. package/src/watchers/NativeWatcher.js +27 -5
  52. package/src/watchers/NativeWatcher.js.flow +33 -6
  53. package/src/watchers/RecrawlWarning.d.ts +8 -1
  54. package/src/watchers/WatchmanWatcher.d.ts +8 -1
  55. package/src/watchers/common.d.ts +10 -1
  56. package/src/watchers/common.js +6 -1
  57. package/src/watchers/common.js.flow +1 -0
@@ -4,8 +4,15 @@
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
7
+ * @noformat
8
8
  * @oncall react_native
9
+ * @generated SignedSource<<b3646c81d37188726a1fc27777dcbede>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro-file-map/src/flow-types.js
13
+ * To regenerate, run:
14
+ * js1 build metro-ts-defs (internal) OR
15
+ * yarn run build-ts-defs (OSS)
9
16
  */
10
17
 
11
18
  import type {PerfLogger, PerfLoggerFactory, RootPerfLogger} from 'metro-config';
@@ -17,7 +24,7 @@ export type BuildParameters = Readonly<{
17
24
  extensions: ReadonlyArray<string>;
18
25
  forceNodeFilesystemAPI: boolean;
19
26
  ignorePattern: RegExp;
20
- plugins: ReadonlyArray<FileMapPlugin>;
27
+ plugins: ReadonlyArray<InputFileMapPlugin>;
21
28
  retainAllFiles: boolean;
22
29
  rootDir: string;
23
30
  roots: ReadonlyArray<string>;
@@ -68,10 +75,15 @@ export type CacheManagerWriteOptions = Readonly<{
68
75
  onWriteError: (error: Error) => void;
69
76
  }>;
70
77
  export type CanonicalPath = string;
71
- export type ChangeEvent = {
78
+ export type ChangedFileMetadata = Readonly<{
79
+ isSymlink: boolean;
80
+ modifiedTime?: null | undefined | number;
81
+ }>;
82
+ export type ChangeEvent = Readonly<{
72
83
  logger: null | undefined | RootPerfLogger;
73
- eventsQueue: EventsQueue;
74
- };
84
+ changes: ReadonlyFileSystemChanges<Readonly<ChangedFileMetadata>>;
85
+ rootDir: string;
86
+ }>;
75
87
  export type ChangeEventMetadata = {
76
88
  modifiedTime: null | undefined | number;
77
89
  size: null | undefined | number;
@@ -94,7 +106,11 @@ export type CrawlerOptions = {
94
106
  rootDir: string;
95
107
  roots: ReadonlyArray<string>;
96
108
  onStatus: (status: WatcherStatus) => void;
109
+ subpath?: string;
97
110
  };
111
+ export type CrawlResult =
112
+ | {changedFiles: FileData; removedFiles: Set<Path>; clocks: WatchmanClocks}
113
+ | {changedFiles: FileData; removedFiles: Set<Path>};
98
114
  export type DependencyExtractor = {
99
115
  extract: (
100
116
  content: string,
@@ -121,15 +137,6 @@ export type WatcherStatus =
121
137
  };
122
138
  export type DuplicatesSet = Map<string, number>;
123
139
  export type DuplicatesIndex = Map<string, Map<string, DuplicatesSet>>;
124
- export type EventsQueue = Array<{
125
- filePath: Path;
126
- metadata: ChangeEventMetadata;
127
- type: string;
128
- }>;
129
- export type FileMapDelta<T = null | void> = Readonly<{
130
- removed: Iterable<[CanonicalPath, T]>;
131
- addedOrModified: Iterable<[CanonicalPath, T]>;
132
- }>;
133
140
  export type FileMapPluginInitOptions<
134
141
  SerializableState,
135
142
  PerFileData = void,
@@ -140,13 +147,13 @@ export type FileMapPluginInitOptions<
140
147
  ): Iterable<{
141
148
  baseName: string;
142
149
  canonicalPath: string;
143
- pluginData: null | undefined | PerFileData;
150
+ readonly pluginData: null | undefined | PerFileData;
144
151
  }>;
145
152
  lookup(
146
153
  mixedPath: string,
147
154
  ):
148
155
  | {exists: false}
149
- | {exists: true; type: 'f'; pluginData: PerFileData}
156
+ | {exists: true; type: 'f'; readonly pluginData: PerFileData}
150
157
  | {exists: true; type: 'd'};
151
158
  }>;
152
159
  pluginState: null | undefined | SerializableState;
@@ -176,19 +183,25 @@ export interface FileMapPlugin<
176
183
  initOptions: FileMapPluginInitOptions<SerializableState, PerFileData>,
177
184
  ): Promise<void>;
178
185
  assertValid(): void;
179
- bulkUpdate(delta: FileMapDelta<null | undefined | PerFileData>): void;
180
- getSerializableSnapshot(): SerializableState;
181
- onRemovedFile(
182
- relativeFilePath: string,
183
- pluginData: null | undefined | PerFileData,
184
- ): void;
185
- onNewOrModifiedFile(
186
- relativeFilePath: string,
187
- pluginData: null | undefined | PerFileData,
186
+ onChanged(
187
+ changes: ReadonlyFileSystemChanges<null | undefined | PerFileData>,
188
188
  ): void;
189
+ getSerializableSnapshot(): void | V8Serializable;
189
190
  getCacheKey(): string;
190
191
  getWorker(): null | undefined | FileMapPluginWorker;
191
192
  }
193
+ export type InputFileMapPlugin = FileMapPlugin<
194
+ /**
195
+ * > 235 | export type InputFileMapPlugin = FileMapPlugin<empty, empty>;
196
+ * | ^^^^^ Unsupported feature: Translating "empty type" is currently not supported.
197
+ **/
198
+ any,
199
+ /**
200
+ * > 235 | export type InputFileMapPlugin = FileMapPlugin<empty, empty>;
201
+ * | ^^^^^ Unsupported feature: Translating "empty type" is currently not supported.
202
+ **/
203
+ any
204
+ >;
192
205
  export interface MetadataWorker {
193
206
  processFile(
194
207
  $$PARAM_0$$: WorkerMessage,
@@ -228,10 +241,22 @@ export type FileStats = Readonly<{
228
241
  export interface FileSystem {
229
242
  exists(file: Path): boolean;
230
243
  getAllFiles(): Array<Path>;
231
- getDifference(files: FileData): {
232
- changedFiles: FileData;
233
- removedFiles: Set<string>;
234
- };
244
+ /**
245
+ * Given a map of files, determine which of them are new or modified
246
+ * (changedFiles), and which of them are missing from the input
247
+ * (removedFiles), vs the current state of this instance of FileSystem.
248
+ */
249
+ getDifference(
250
+ files: FileData,
251
+ options?: Readonly<{
252
+ /**
253
+ * Only consider files under this subpath (which should be a directory)
254
+ * when computing removedFiles. If not provided, all files in the file
255
+ * system are considered.
256
+ */
257
+ subpath?: string;
258
+ }>,
259
+ ): {changedFiles: FileData; removedFiles: Set<string>};
235
260
  getSerializableSnapshot(): CacheData['fileSystemData'];
236
261
  getSha1(file: Path): null | undefined | string;
237
262
  getOrComputeSha1(
@@ -335,10 +360,35 @@ export type HasteMapItem = {
335
360
  [platform: string]: HasteMapItemMetadata;
336
361
  };
337
362
  export type HasteMapItemMetadata = [string, number];
363
+ export interface FileSystemListener {
364
+ directoryAdded(canonicalPath: CanonicalPath): void;
365
+ directoryRemoved(canonicalPath: CanonicalPath): void;
366
+ fileAdded(canonicalPath: CanonicalPath, data: FileMetadata): void;
367
+ fileModified(
368
+ canonicalPath: CanonicalPath,
369
+ oldData: FileMetadata,
370
+ newData: FileMetadata,
371
+ ): void;
372
+ fileRemoved(canonicalPath: CanonicalPath, data: FileMetadata): void;
373
+ }
374
+ export interface ReadonlyFileSystemChanges<T = FileMetadata> {
375
+ readonly addedDirectories: Iterable<CanonicalPath>;
376
+ readonly removedDirectories: Iterable<CanonicalPath>;
377
+ readonly addedFiles: Iterable<Readonly<[CanonicalPath, T]>>;
378
+ readonly modifiedFiles: Iterable<Readonly<[CanonicalPath, T]>>;
379
+ readonly removedFiles: Iterable<Readonly<[CanonicalPath, T]>>;
380
+ }
338
381
  export interface MutableFileSystem extends FileSystem {
339
- remove(filePath: Path): null | undefined | FileMetadata;
340
- addOrModify(filePath: Path, fileMetadata: FileMetadata): void;
341
- bulkAddOrModify(addedOrModifiedFiles: FileData): void;
382
+ remove(filePath: Path, listener?: FileSystemListener): void;
383
+ addOrModify(
384
+ filePath: Path,
385
+ fileMetadata: FileMetadata,
386
+ listener?: FileSystemListener,
387
+ ): void;
388
+ bulkAddOrModify(
389
+ addedOrModifiedFiles: FileData,
390
+ listener?: FileSystemListener,
391
+ ): void;
342
392
  }
343
393
  export type Path = string;
344
394
  export type ProcessFileFunction = (
@@ -378,6 +428,12 @@ export type WatcherBackendChangeEvent =
378
428
  relativePath: string;
379
429
  root: string;
380
430
  metadata?: void;
431
+ }>
432
+ | Readonly<{
433
+ event: 'recrawl';
434
+ clock?: ChangeEventClock;
435
+ relativePath: string;
436
+ root: string;
381
437
  }>;
382
438
  export type WatcherBackendOptions = Readonly<{
383
439
  ignored: null | undefined | RegExp;
@@ -21,7 +21,7 @@ export type BuildParameters = Readonly<{
21
21
  extensions: ReadonlyArray<string>,
22
22
  forceNodeFilesystemAPI: boolean,
23
23
  ignorePattern: RegExp,
24
- plugins: ReadonlyArray<FileMapPlugin<>>,
24
+ plugins: ReadonlyArray<InputFileMapPlugin>,
25
25
  retainAllFiles: boolean,
26
26
  rootDir: string,
27
27
  roots: ReadonlyArray<string>,
@@ -90,10 +90,16 @@ export type CacheManagerWriteOptions = Readonly<{
90
90
  // - Real (no symlinks in path, though the path itself may be a symlink)
91
91
  export type CanonicalPath = string;
92
92
 
93
- export type ChangeEvent = {
93
+ export type ChangedFileMetadata = Readonly<{
94
+ isSymlink: boolean,
95
+ modifiedTime?: ?number,
96
+ }>;
97
+
98
+ export type ChangeEvent = Readonly<{
94
99
  logger: ?RootPerfLogger,
95
- eventsQueue: EventsQueue,
96
- };
100
+ changes: ReadonlyFileSystemChanges<Readonly<ChangedFileMetadata>>,
101
+ rootDir: string,
102
+ }>;
97
103
 
98
104
  export type ChangeEventMetadata = {
99
105
  modifiedTime: ?number, // Epoch ms
@@ -119,8 +125,22 @@ export type CrawlerOptions = {
119
125
  rootDir: string,
120
126
  roots: ReadonlyArray<string>,
121
127
  onStatus: (status: WatcherStatus) => void,
128
+ // Only consider files under this normalized subdirectory when computing
129
+ // removedFiles. If not provided, all files in the file system are considered.
130
+ subpath?: string,
122
131
  };
123
132
 
133
+ export type CrawlResult =
134
+ | {
135
+ changedFiles: FileData,
136
+ removedFiles: Set<Path>,
137
+ clocks: WatchmanClocks,
138
+ }
139
+ | {
140
+ changedFiles: FileData,
141
+ removedFiles: Set<Path>,
142
+ };
143
+
124
144
  export type DependencyExtractor = {
125
145
  extract: (
126
146
  content: string,
@@ -150,20 +170,9 @@ export type WatcherStatus =
150
170
  export type DuplicatesSet = Map<string, /* type */ number>;
151
171
  export type DuplicatesIndex = Map<string, Map<string, DuplicatesSet>>;
152
172
 
153
- export type EventsQueue = Array<{
154
- filePath: Path,
155
- metadata: ChangeEventMetadata,
156
- type: string,
157
- }>;
158
-
159
- export type FileMapDelta<T = null | void> = Readonly<{
160
- removed: Iterable<[CanonicalPath, T]>,
161
- addedOrModified: Iterable<[CanonicalPath, T]>,
162
- }>;
163
-
164
173
  export type FileMapPluginInitOptions<
165
- SerializableState,
166
- PerFileData = void,
174
+ +SerializableState,
175
+ +PerFileData = void,
167
176
  > = Readonly<{
168
177
  files: Readonly<{
169
178
  fileIterator(
@@ -174,13 +183,13 @@ export type FileMapPluginInitOptions<
174
183
  ): Iterable<{
175
184
  baseName: string,
176
185
  canonicalPath: string,
177
- pluginData: ?PerFileData,
186
+ +pluginData: ?PerFileData,
178
187
  }>,
179
188
  lookup(
180
189
  mixedPath: string,
181
190
  ):
182
191
  | {exists: false}
183
- | {exists: true, type: 'f', pluginData: PerFileData}
192
+ | {exists: true, type: 'f', +pluginData: PerFileData}
184
193
  | {exists: true, type: 'd'},
185
194
  }>,
186
195
  pluginState: ?SerializableState,
@@ -205,22 +214,22 @@ export type V8Serializable =
205
214
  | Readonly<{[key: string]: V8Serializable}>;
206
215
 
207
216
  export interface FileMapPlugin<
208
- SerializableState: void | V8Serializable = void | V8Serializable,
209
- PerFileData: void | V8Serializable = void | V8Serializable,
217
+ -SerializableState extends void | V8Serializable = void | V8Serializable,
218
+ -PerFileData extends void | V8Serializable = void | V8Serializable,
210
219
  > {
211
220
  +name: string;
212
221
  initialize(
213
222
  initOptions: FileMapPluginInitOptions<SerializableState, PerFileData>,
214
223
  ): Promise<void>;
215
224
  assertValid(): void;
216
- bulkUpdate(delta: FileMapDelta<?PerFileData>): void;
217
- getSerializableSnapshot(): SerializableState;
218
- onRemovedFile(relativeFilePath: string, pluginData: ?PerFileData): void;
219
- onNewOrModifiedFile(relativeFilePath: string, pluginData: ?PerFileData): void;
225
+ onChanged(changes: ReadonlyFileSystemChanges<?PerFileData>): void;
226
+ getSerializableSnapshot(): void | V8Serializable;
220
227
  getCacheKey(): string;
221
228
  getWorker(): ?FileMapPluginWorker;
222
229
  }
223
230
 
231
+ export type InputFileMapPlugin = FileMapPlugin<empty, empty>;
232
+
224
233
  export interface MetadataWorker {
225
234
  processFile(
226
235
  WorkerMessage,
@@ -268,7 +277,23 @@ export type FileStats = Readonly<{
268
277
  export interface FileSystem {
269
278
  exists(file: Path): boolean;
270
279
  getAllFiles(): Array<Path>;
271
- getDifference(files: FileData): {
280
+
281
+ /**
282
+ * Given a map of files, determine which of them are new or modified
283
+ * (changedFiles), and which of them are missing from the input
284
+ * (removedFiles), vs the current state of this instance of FileSystem.
285
+ */
286
+ getDifference(
287
+ files: FileData,
288
+ options?: Readonly<{
289
+ /**
290
+ * Only consider files under this subpath (which should be a directory)
291
+ * when computing removedFiles. If not provided, all files in the file
292
+ * system are considered.
293
+ */
294
+ subpath?: string,
295
+ }>,
296
+ ): {
272
297
  changedFiles: FileData,
273
298
  removedFiles: Set<string>,
274
299
  };
@@ -423,10 +448,39 @@ export type HasteMapItem = {
423
448
  };
424
449
  export type HasteMapItemMetadata = [/* path */ string, /* type */ number];
425
450
 
451
+ export interface FileSystemListener {
452
+ directoryAdded(canonicalPath: CanonicalPath): void;
453
+ directoryRemoved(canonicalPath: CanonicalPath): void;
454
+
455
+ fileAdded(canonicalPath: CanonicalPath, data: FileMetadata): void;
456
+ fileModified(
457
+ canonicalPath: CanonicalPath,
458
+ oldData: FileMetadata,
459
+ newData: FileMetadata,
460
+ ): void;
461
+ fileRemoved(canonicalPath: CanonicalPath, data: FileMetadata): void;
462
+ }
463
+
464
+ export interface ReadonlyFileSystemChanges<+T = FileMetadata> {
465
+ +addedDirectories: Iterable<CanonicalPath>;
466
+ +removedDirectories: Iterable<CanonicalPath>;
467
+
468
+ +addedFiles: Iterable<Readonly<[CanonicalPath, T]>>;
469
+ +modifiedFiles: Iterable<Readonly<[CanonicalPath, T]>>;
470
+ +removedFiles: Iterable<Readonly<[CanonicalPath, T]>>;
471
+ }
472
+
426
473
  export interface MutableFileSystem extends FileSystem {
427
- remove(filePath: Path): ?FileMetadata;
428
- addOrModify(filePath: Path, fileMetadata: FileMetadata): void;
429
- bulkAddOrModify(addedOrModifiedFiles: FileData): void;
474
+ remove(filePath: Path, listener?: FileSystemListener): void;
475
+ addOrModify(
476
+ filePath: Path,
477
+ fileMetadata: FileMetadata,
478
+ listener?: FileSystemListener,
479
+ ): void;
480
+ bulkAddOrModify(
481
+ addedOrModifiedFiles: FileData,
482
+ listener?: FileSystemListener,
483
+ ): void;
430
484
  }
431
485
 
432
486
  export type Path = string;
@@ -482,6 +536,12 @@ export type WatcherBackendChangeEvent =
482
536
  relativePath: string,
483
537
  root: string,
484
538
  metadata?: void,
539
+ }>
540
+ | Readonly<{
541
+ event: 'recrawl',
542
+ clock?: ChangeEventClock,
543
+ relativePath: string,
544
+ root: string,
485
545
  }>;
486
546
 
487
547
  export type WatcherBackendOptions = Readonly<{
package/src/index.d.ts CHANGED
@@ -4,8 +4,15 @@
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
7
+ * @noformat
8
8
  * @oncall react_native
9
+ * @generated SignedSource<<806d228988308075b7a911c3dfb513d3>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro-file-map/src/index.js
13
+ * To regenerate, run:
14
+ * js1 build metro-ts-defs (internal) OR
15
+ * yarn run build-ts-defs (OSS)
9
16
  */
10
17
 
11
18
  import type {
@@ -16,11 +23,11 @@ import type {
16
23
  ChangeEventMetadata,
17
24
  Console,
18
25
  FileData,
19
- FileMapPlugin,
20
26
  FileSystem,
21
27
  HasteMapData,
22
28
  HasteMapItem,
23
29
  HType,
30
+ InputFileMapPlugin,
24
31
  PerfLoggerFactory,
25
32
  } from './flow-types';
26
33
 
@@ -36,6 +43,7 @@ export type {
36
43
  FileSystem,
37
44
  HasteMapData,
38
45
  HasteMapItem,
46
+ InputFileMapPlugin,
39
47
  };
40
48
  export type InputOptions = Readonly<{
41
49
  computeSha1?: null | undefined | boolean;
@@ -43,7 +51,7 @@ export type InputOptions = Readonly<{
43
51
  extensions: ReadonlyArray<string>;
44
52
  forceNodeFilesystemAPI?: null | undefined | boolean;
45
53
  ignorePattern?: null | undefined | RegExp;
46
- plugins?: ReadonlyArray<AnyFileMapPlugin>;
54
+ plugins?: ReadonlyArray<InputFileMapPlugin>;
47
55
  retainAllFiles: boolean;
48
56
  rootDir: string;
49
57
  roots: ReadonlyArray<string>;
@@ -64,7 +72,6 @@ type HealthCheckOptions = Readonly<{
64
72
  timeout: number;
65
73
  filePrefix: string;
66
74
  }>;
67
- type AnyFileMapPlugin = FileMapPlugin<any, any>;
68
75
  export {DiskCacheManager} from './cache/DiskCacheManager';
69
76
  export {default as DependencyPlugin} from './plugins/DependencyPlugin';
70
77
  export type {DependencyPluginOptions} from './plugins/DependencyPlugin';