metro-file-map 0.84.2 → 0.84.4

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 (40) 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 +5 -36
  22. package/src/plugins/DependencyPlugin.js +26 -48
  23. package/src/plugins/DependencyPlugin.js.flow +22 -100
  24. package/src/plugins/FileDataPlugin.d.ts +55 -0
  25. package/src/plugins/FileDataPlugin.js +41 -0
  26. package/src/plugins/FileDataPlugin.js.flow +76 -0
  27. package/src/plugins/HastePlugin.d.ts +3 -11
  28. package/src/plugins/HastePlugin.js +11 -11
  29. package/src/plugins/HastePlugin.js.flow +12 -12
  30. package/src/plugins/MockPlugin.d.ts +3 -5
  31. package/src/plugins/MockPlugin.js +17 -20
  32. package/src/plugins/MockPlugin.js.flow +18 -22
  33. package/src/watchers/FallbackWatcher.js +19 -3
  34. package/src/watchers/FallbackWatcher.js.flow +28 -5
  35. package/src/watchers/NativeWatcher.d.ts +2 -2
  36. package/src/watchers/NativeWatcher.js +27 -5
  37. package/src/watchers/NativeWatcher.js.flow +33 -6
  38. package/src/watchers/common.d.ts +3 -1
  39. package/src/watchers/common.js +6 -1
  40. package/src/watchers/common.js.flow +1 -0
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * @noformat
8
8
  * @oncall react_native
9
- * @generated SignedSource<<919ac912df195d04796dd62cb68839d2>>
9
+ * @generated SignedSource<<b3646c81d37188726a1fc27777dcbede>>
10
10
  *
11
11
  * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
12
  * Original file: packages/metro-file-map/src/flow-types.js
@@ -24,7 +24,7 @@ export type BuildParameters = Readonly<{
24
24
  extensions: ReadonlyArray<string>;
25
25
  forceNodeFilesystemAPI: boolean;
26
26
  ignorePattern: RegExp;
27
- plugins: ReadonlyArray<FileMapPlugin>;
27
+ plugins: ReadonlyArray<InputFileMapPlugin>;
28
28
  retainAllFiles: boolean;
29
29
  rootDir: string;
30
30
  roots: ReadonlyArray<string>;
@@ -75,10 +75,15 @@ export type CacheManagerWriteOptions = Readonly<{
75
75
  onWriteError: (error: Error) => void;
76
76
  }>;
77
77
  export type CanonicalPath = string;
78
- export type ChangeEvent = {
78
+ export type ChangedFileMetadata = Readonly<{
79
+ isSymlink: boolean;
80
+ modifiedTime?: null | undefined | number;
81
+ }>;
82
+ export type ChangeEvent = Readonly<{
79
83
  logger: null | undefined | RootPerfLogger;
80
- eventsQueue: EventsQueue;
81
- };
84
+ changes: ReadonlyFileSystemChanges<Readonly<ChangedFileMetadata>>;
85
+ rootDir: string;
86
+ }>;
82
87
  export type ChangeEventMetadata = {
83
88
  modifiedTime: null | undefined | number;
84
89
  size: null | undefined | number;
@@ -101,7 +106,11 @@ export type CrawlerOptions = {
101
106
  rootDir: string;
102
107
  roots: ReadonlyArray<string>;
103
108
  onStatus: (status: WatcherStatus) => void;
109
+ subpath?: string;
104
110
  };
111
+ export type CrawlResult =
112
+ | {changedFiles: FileData; removedFiles: Set<Path>; clocks: WatchmanClocks}
113
+ | {changedFiles: FileData; removedFiles: Set<Path>};
105
114
  export type DependencyExtractor = {
106
115
  extract: (
107
116
  content: string,
@@ -128,15 +137,6 @@ export type WatcherStatus =
128
137
  };
129
138
  export type DuplicatesSet = Map<string, number>;
130
139
  export type DuplicatesIndex = Map<string, Map<string, DuplicatesSet>>;
131
- export type EventsQueue = Array<{
132
- filePath: Path;
133
- metadata: ChangeEventMetadata;
134
- type: string;
135
- }>;
136
- export type FileMapDelta<T = null | void> = Readonly<{
137
- removed: Iterable<[CanonicalPath, T]>;
138
- addedOrModified: Iterable<[CanonicalPath, T]>;
139
- }>;
140
140
  export type FileMapPluginInitOptions<
141
141
  SerializableState,
142
142
  PerFileData = void,
@@ -147,13 +147,13 @@ export type FileMapPluginInitOptions<
147
147
  ): Iterable<{
148
148
  baseName: string;
149
149
  canonicalPath: string;
150
- pluginData: null | undefined | PerFileData;
150
+ readonly pluginData: null | undefined | PerFileData;
151
151
  }>;
152
152
  lookup(
153
153
  mixedPath: string,
154
154
  ):
155
155
  | {exists: false}
156
- | {exists: true; type: 'f'; pluginData: PerFileData}
156
+ | {exists: true; type: 'f'; readonly pluginData: PerFileData}
157
157
  | {exists: true; type: 'd'};
158
158
  }>;
159
159
  pluginState: null | undefined | SerializableState;
@@ -183,19 +183,25 @@ export interface FileMapPlugin<
183
183
  initOptions: FileMapPluginInitOptions<SerializableState, PerFileData>,
184
184
  ): Promise<void>;
185
185
  assertValid(): void;
186
- bulkUpdate(delta: FileMapDelta<null | undefined | PerFileData>): void;
187
- getSerializableSnapshot(): SerializableState;
188
- onRemovedFile(
189
- relativeFilePath: string,
190
- pluginData: null | undefined | PerFileData,
191
- ): void;
192
- onNewOrModifiedFile(
193
- relativeFilePath: string,
194
- pluginData: null | undefined | PerFileData,
186
+ onChanged(
187
+ changes: ReadonlyFileSystemChanges<null | undefined | PerFileData>,
195
188
  ): void;
189
+ getSerializableSnapshot(): void | V8Serializable;
196
190
  getCacheKey(): string;
197
191
  getWorker(): null | undefined | FileMapPluginWorker;
198
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
+ >;
199
205
  export interface MetadataWorker {
200
206
  processFile(
201
207
  $$PARAM_0$$: WorkerMessage,
@@ -235,10 +241,22 @@ export type FileStats = Readonly<{
235
241
  export interface FileSystem {
236
242
  exists(file: Path): boolean;
237
243
  getAllFiles(): Array<Path>;
238
- getDifference(files: FileData): {
239
- changedFiles: FileData;
240
- removedFiles: Set<string>;
241
- };
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>};
242
260
  getSerializableSnapshot(): CacheData['fileSystemData'];
243
261
  getSha1(file: Path): null | undefined | string;
244
262
  getOrComputeSha1(
@@ -342,10 +360,35 @@ export type HasteMapItem = {
342
360
  [platform: string]: HasteMapItemMetadata;
343
361
  };
344
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
+ }
345
381
  export interface MutableFileSystem extends FileSystem {
346
- remove(filePath: Path): null | undefined | FileMetadata;
347
- addOrModify(filePath: Path, fileMetadata: FileMetadata): void;
348
- 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;
349
392
  }
350
393
  export type Path = string;
351
394
  export type ProcessFileFunction = (
@@ -385,6 +428,12 @@ export type WatcherBackendChangeEvent =
385
428
  relativePath: string;
386
429
  root: string;
387
430
  metadata?: void;
431
+ }>
432
+ | Readonly<{
433
+ event: 'recrawl';
434
+ clock?: ChangeEventClock;
435
+ relativePath: string;
436
+ root: string;
388
437
  }>;
389
438
  export type WatcherBackendOptions = Readonly<{
390
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
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * @noformat
8
8
  * @oncall react_native
9
- * @generated SignedSource<<33bbe77b6d139e247ee97f706bbe485d>>
9
+ * @generated SignedSource<<806d228988308075b7a911c3dfb513d3>>
10
10
  *
11
11
  * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
12
  * Original file: packages/metro-file-map/src/index.js
@@ -23,11 +23,11 @@ import type {
23
23
  ChangeEventMetadata,
24
24
  Console,
25
25
  FileData,
26
- FileMapPlugin,
27
26
  FileSystem,
28
27
  HasteMapData,
29
28
  HasteMapItem,
30
29
  HType,
30
+ InputFileMapPlugin,
31
31
  PerfLoggerFactory,
32
32
  } from './flow-types';
33
33
 
@@ -43,6 +43,7 @@ export type {
43
43
  FileSystem,
44
44
  HasteMapData,
45
45
  HasteMapItem,
46
+ InputFileMapPlugin,
46
47
  };
47
48
  export type InputOptions = Readonly<{
48
49
  computeSha1?: null | undefined | boolean;
@@ -50,7 +51,7 @@ export type InputOptions = Readonly<{
50
51
  extensions: ReadonlyArray<string>;
51
52
  forceNodeFilesystemAPI?: null | undefined | boolean;
52
53
  ignorePattern?: null | undefined | RegExp;
53
- plugins?: ReadonlyArray<AnyFileMapPlugin>;
54
+ plugins?: ReadonlyArray<InputFileMapPlugin>;
54
55
  retainAllFiles: boolean;
55
56
  rootDir: string;
56
57
  roots: ReadonlyArray<string>;
@@ -71,7 +72,6 @@ type HealthCheckOptions = Readonly<{
71
72
  timeout: number;
72
73
  filePrefix: string;
73
74
  }>;
74
- type AnyFileMapPlugin = FileMapPlugin<any, any>;
75
75
  export {DiskCacheManager} from './cache/DiskCacheManager';
76
76
  export {default as DependencyPlugin} from './plugins/DependencyPlugin';
77
77
  export type {DependencyPluginOptions} from './plugins/DependencyPlugin';