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
@@ -1,353 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @format
8
- * @oncall react_native
9
- */
10
-
11
- import type {PerfLogger, PerfLoggerFactory, RootPerfLogger} from 'metro-config';
12
-
13
- export type {PerfLoggerFactory, PerfLogger};
14
-
15
- /**
16
- * These inputs affect the internal data collected for a given filesystem
17
- * state, and changes may invalidate a cache.
18
- */
19
- export type BuildParameters = Readonly<{
20
- computeDependencies: boolean;
21
- computeSha1: boolean;
22
- enableHastePackages: boolean;
23
- enableSymlinks: boolean;
24
- extensions: ReadonlyArray<string>;
25
- forceNodeFilesystemAPI: boolean;
26
- ignorePattern: RegExp;
27
- mocksPattern: RegExp | null;
28
- platforms: ReadonlyArray<string>;
29
- retainAllFiles: boolean;
30
- rootDir: string;
31
- roots: ReadonlyArray<string>;
32
- skipPackageJson: boolean;
33
- dependencyExtractor: string | null;
34
- hasteImplModulePath: string | null;
35
- cacheBreaker: string;
36
- }>;
37
-
38
- export interface BuildResult {
39
- fileSystem: FileSystem;
40
- hasteMap: HasteMap;
41
- }
42
-
43
- export interface CacheData {
44
- readonly clocks: WatchmanClocks;
45
- readonly fileSystemData: unknown;
46
- readonly plugins: ReadonlyMap<string, unknown>;
47
- }
48
-
49
- export interface CacheManager {
50
- /**
51
- * Called during startup to load initial state, if available. Provided to
52
- * a crawler, which will return the delta between the initial state and the
53
- * current file system state.
54
- */
55
- read(): Promise<CacheData | null>;
56
-
57
- /**
58
- * Called when metro-file-map `build()` has applied changes returned by the
59
- * crawler - i.e. internal state reflects the current file system state.
60
- *
61
- * getSnapshot may be retained and called at any time before end(), such as
62
- * in response to eventSource 'change' events.
63
- */
64
- write(
65
- getSnapshot: () => CacheData,
66
- opts: CacheManagerWriteOptions,
67
- ): Promise<void>;
68
-
69
- /**
70
- * The last call that will be made to this CacheManager. Any handles should
71
- * be closed by the time this settles.
72
- */
73
- end(): Promise<void>;
74
- }
75
-
76
- export interface CacheManagerEventSource {
77
- onChange(listener: () => void): () => void /* unsubscribe */;
78
- }
79
-
80
- export type CacheManagerFactory = (
81
- options: CacheManagerFactoryOptions,
82
- ) => CacheManager;
83
-
84
- export type CacheManagerFactoryOptions = {
85
- buildParameters: BuildParameters;
86
- };
87
-
88
- export type CacheManagerWriteOptions = {
89
- changedSinceCacheRead: boolean;
90
- eventSource: CacheManagerEventSource;
91
- onWriteError: (e: Error) => void;
92
- };
93
-
94
- export interface ChangeEvent {
95
- logger: RootPerfLogger | null;
96
- eventsQueue: EventsQueue;
97
- }
98
-
99
- export interface ChangeEventMetadata {
100
- /** Epoch ms */
101
- modifiedTime: number | null;
102
- /** Bytes */
103
- size: number | null;
104
- /** Regular file / Directory / Symlink */
105
- type: 'f' | 'd' | 'l';
106
- }
107
-
108
- export type Console = typeof global.console;
109
-
110
- export interface CrawlerOptions {
111
- abortSignal: AbortSignal | null;
112
- computeSha1: boolean;
113
- extensions: ReadonlyArray<string>;
114
- forceNodeFilesystemAPI: boolean;
115
- ignore: IgnoreMatcher;
116
- includeSymlinks: boolean;
117
- perfLogger?: PerfLogger | null;
118
- previousState: Readonly<{
119
- clocks: ReadonlyMap<Path, WatchmanClockSpec>;
120
- files: ReadonlyMap<Path, FileMetadata>;
121
- }>;
122
- rootDir: string;
123
- roots: ReadonlyArray<string>;
124
- onStatus: (status: WatcherStatus) => void;
125
- }
126
-
127
- export type WatcherStatus =
128
- | {
129
- type: 'watchman_slow_command';
130
- timeElapsed: number;
131
- command: 'watch-project' | 'query';
132
- }
133
- | {
134
- type: 'watchman_slow_command_complete';
135
- timeElapsed: number;
136
- command: 'watch-project' | 'query';
137
- }
138
- | {
139
- type: 'watchman_warning';
140
- warning: unknown;
141
- command: 'watch-project' | 'query';
142
- };
143
-
144
- export type DuplicatesSet = Map<string, /* type */ number>;
145
- export type DuplicatesIndex = Map<string, Map<string, DuplicatesSet>>;
146
-
147
- export type EventsQueue = Array<{
148
- filePath: Path;
149
- metadata?: ChangeEventMetadata | null;
150
- type: string;
151
- }>;
152
-
153
- export interface HType {
154
- ID: 0;
155
- MTIME: 1;
156
- SIZE: 2;
157
- VISITED: 3;
158
- DEPENDENCIES: 4;
159
- SHA1: 5;
160
- SYMLINK: 6;
161
- PATH: 0;
162
- TYPE: 1;
163
- MODULE: 0;
164
- PACKAGE: 1;
165
- GENERIC_PLATFORM: 'g';
166
- NATIVE_PLATFORM: 'native';
167
- DEPENDENCY_DELIM: '\0';
168
- }
169
-
170
- type Values<T> = T[keyof T];
171
- export type HTypeValue = Values<HType>;
172
-
173
- export type IgnoreMatcher = (item: string) => boolean;
174
-
175
- export type FileData = Map<Path, FileMetadata>;
176
-
177
- export type FileMetadata = [
178
- /* id */ string,
179
- /* mtime */ number,
180
- /* size */ number,
181
- /* visited */ 0 | 1,
182
- /* dependencies */ string,
183
- /* sha1 */ string | null,
184
- /* symlink */ 0 | 1 | string, // string specifies target, if known
185
- ];
186
-
187
- export type FileStats = Readonly<{
188
- fileType: 'f' | 'l';
189
- modifiedTime: number;
190
- }>;
191
-
192
- export interface FileSystem {
193
- exists(file: Path): boolean;
194
- getAllFiles(): Path[];
195
- getDependencies(file: Path): string[] | null;
196
- getModuleName(file: Path): string | null;
197
- getSerializableSnapshot(): FileData;
198
- getSha1(file: Path): string | null;
199
-
200
- /**
201
- * Given a start path (which need not exist), a subpath and type, and
202
- * optionally a 'breakOnSegment', performs the following:
203
- *
204
- * X = mixedStartPath
205
- * do
206
- * if basename(X) === opts.breakOnSegment
207
- * return null
208
- * if X + subpath exists and has type opts.subpathType
209
- * return {
210
- * absolutePath: realpath(X + subpath)
211
- * containerRelativePath: relative(mixedStartPath, X)
212
- * }
213
- * X = dirname(X)
214
- * while X !== dirname(X)
215
- *
216
- * If opts.invalidatedBy is given, collects all absolute, real paths that if
217
- * added or removed may invalidate this result.
218
- *
219
- * Useful for finding the closest package scope (subpath: package.json,
220
- * type f, breakOnSegment: node_modules) or closest potential package root
221
- * (subpath: node_modules/pkg, type: d) in Node.js resolution.
222
- */
223
- hierarchicalLookup(
224
- mixedStartPath: string,
225
- subpath: string,
226
- opts: {
227
- breakOnSegment: string | null | undefined;
228
- invalidatedBy: Set<string> | null | undefined;
229
- subpathType: 'f' | 'd';
230
- },
231
- ): {
232
- absolutePath: string;
233
- containerRelativePath: string;
234
- } | null;
235
-
236
- /**
237
- * Analogous to posix lstat. If the file at `file` is a symlink, return
238
- * information about the symlink without following it.
239
- */
240
- linkStats(file: Path): FileStats | null;
241
-
242
- /**
243
- * Return information about the given path, whether a directory or file.
244
- * Always follow symlinks, and return a real path if it exists.
245
- */
246
- lookup(mixedPath: Path): LookupResult;
247
-
248
- matchFiles(opts: {
249
- /* Filter relative paths against a pattern. */
250
- filter?: RegExp | null;
251
- /* `filter` is applied against absolute paths, vs rootDir-relative. (default: false) */
252
- filterCompareAbsolute?: boolean;
253
- /* `filter` is applied against posix-delimited paths, even on Windows. (default: false) */
254
- filterComparePosix?: boolean;
255
- /* Follow symlinks when enumerating paths. (default: false) */
256
- follow?: boolean;
257
- /* Should search for files recursively. (default: true) */
258
- recursive?: boolean;
259
- /* Match files under a given root, or null for all files */
260
- rootDir?: Path | null;
261
- }): Iterable<Path>;
262
- }
263
-
264
- export type Glob = string;
265
-
266
- export type LookupResult =
267
- | {
268
- // The node is missing from the FileSystem implementation (note this
269
- // could indicate an unwatched path, or a directory containing no watched
270
- // files).
271
- exists: false;
272
- // The real, normal, absolute paths of any symlinks traversed.
273
- links: ReadonlySet<string>;
274
- // The real, normal, absolute path of the first path segment
275
- // encountered that does not exist, or cannot be navigated through.
276
- missing: string;
277
- }
278
- | {
279
- exists: true;
280
- // The real, normal, absolute paths of any symlinks traversed.
281
- links: ReadonlySet<string>;
282
- // The real, normal, absolute path of the file or directory.
283
- realPath: string;
284
- // Currently lookup always follows symlinks, so can only return
285
- // directories or regular files, but this may be extended.
286
- type: 'd' | 'f';
287
- };
288
-
289
- export type HasteConflict = {
290
- id: string;
291
- platform: string | null;
292
- absolutePaths: Array<string>;
293
- type: 'duplicate' | 'shadowing';
294
- };
295
-
296
- export interface HasteMap {
297
- getModule(
298
- name: string,
299
- platform?: string | null,
300
- supportsNativePlatform?: boolean | null,
301
- type?: HTypeValue | null,
302
- ): Path | null;
303
-
304
- getPackage(
305
- name: string,
306
- platform: string | null,
307
- _supportsNativePlatform: boolean | null,
308
- ): Path | null;
309
-
310
- computeConflicts(): Array<HasteConflict>;
311
- }
312
-
313
- export type RawMockMap = {
314
- readonly mocks: Map<string, string>;
315
- readonly duplicates: Map<string, Set<string>>;
316
- };
317
-
318
- export type HasteMapData = Map<string, HasteMapItem>;
319
-
320
- export interface HasteMapItem {
321
- [platform: string]: HasteMapItemMetadata;
322
- }
323
- export type HasteMapItemMetadata = [/* path */ string, /* type */ number];
324
-
325
- export interface MutableFileSystem extends FileSystem {
326
- remove(filePath: Path): void;
327
- addOrModify(filePath: Path, fileMetadata: FileMetadata): void;
328
- bulkAddOrModify(addedOrModifiedFiles: FileData): void;
329
- }
330
-
331
- export type Path = string;
332
-
333
- export type WatchmanClockSpec =
334
- | string
335
- | Readonly<{scm: Readonly<{'mergebase-with': string}>}>;
336
- export type WatchmanClocks = Map<Path, WatchmanClockSpec>;
337
-
338
- export type WorkerMessage = Readonly<{
339
- computeDependencies: boolean;
340
- computeSha1: boolean;
341
- dependencyExtractor?: string | null;
342
- enableHastePackages: boolean;
343
- rootDir: string;
344
- filePath: string;
345
- hasteImplModulePath?: string | null;
346
- }>;
347
-
348
- export type WorkerMetadata = Readonly<{
349
- dependencies?: ReadonlyArray<string>;
350
- id?: string | null;
351
- module?: HasteMapItemMetadata | null;
352
- sha1?: string | null;
353
- }>;
package/src/index.d.ts DELETED
@@ -1,97 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @format
8
- * @oncall react_native
9
- */
10
-
11
- import type {
12
- BuildParameters,
13
- BuildResult,
14
- CacheData,
15
- CacheManagerFactory,
16
- ChangeEventMetadata,
17
- Console,
18
- FileData,
19
- FileSystem,
20
- HasteConflict,
21
- HasteMapData,
22
- HasteMapItem,
23
- PerfLoggerFactory,
24
- } from './flow-types';
25
- import type {EventEmitter} from 'events';
26
-
27
- export type {
28
- BuildParameters,
29
- CacheData,
30
- ChangeEventMetadata,
31
- FileData,
32
- FileMap,
33
- FileSystem,
34
- HasteMapData,
35
- HasteMapItem,
36
- };
37
-
38
- export type InputOptions = Readonly<{
39
- computeDependencies?: boolean | null;
40
- computeSha1?: boolean | null;
41
- enableSymlinks?: boolean | null;
42
- extensions: ReadonlyArray<string>;
43
- forceNodeFilesystemAPI?: boolean | null;
44
- ignorePattern?: RegExp | null;
45
- mocksPattern?: string | null;
46
- platforms: ReadonlyArray<string>;
47
- retainAllFiles: boolean;
48
- rootDir: string;
49
- roots: ReadonlyArray<string>;
50
- skipPackageJson?: boolean | null;
51
-
52
- /** Module paths that should export a 'getCacheKey' method */
53
- dependencyExtractor?: string | null;
54
- hasteImplModulePath?: string | null;
55
-
56
- perfLoggerFactory?: PerfLoggerFactory | null;
57
- resetCache?: boolean | null;
58
- maxWorkers: number;
59
- throwOnModuleCollision?: boolean | null;
60
- useWatchman?: boolean | null;
61
- watchmanDeferStates?: ReadonlyArray<string>;
62
- watch?: boolean | null;
63
- console?: Console;
64
- cacheManagerFactory?: CacheManagerFactory | null;
65
-
66
- healthCheck: HealthCheckOptions;
67
- }>;
68
-
69
- type HealthCheckOptions = Readonly<{
70
- enabled: boolean;
71
- interval: number;
72
- timeout: number;
73
- filePrefix: string;
74
- }>;
75
-
76
- export {DiskCacheManager} from './cache/DiskCacheManager';
77
- export {DuplicateHasteCandidatesError} from './lib/DuplicateHasteCandidatesError';
78
- export type {HasteMap} from './flow-types';
79
- export type {HealthCheckResult} from './Watcher';
80
- export type {
81
- CacheManager,
82
- CacheManagerFactory,
83
- ChangeEvent,
84
- WatcherStatus,
85
- } from './flow-types';
86
-
87
- export default class FileMap extends EventEmitter {
88
- static create(options: InputOptions): FileMap;
89
- constructor(options: InputOptions);
90
- build(): Promise<BuildResult>;
91
- read(): Promise<CacheData | null>;
92
- }
93
-
94
- export class HasteConflictsError extends Error {
95
- constructor(conflicts: ReadonlyArray<HasteConflict>);
96
- getDetailedMessage(pathsRelativeToRoot?: string): string;
97
- }
@@ -1,24 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @format
8
- * @oncall react_native
9
- */
10
-
11
- import type {DuplicatesSet} from '../flow-types';
12
-
13
- export class DuplicateHasteCandidatesError extends Error {
14
- hasteName: string;
15
- platform: string | null;
16
- supportsNativePlatform: boolean;
17
- duplicatesSet: DuplicatesSet;
18
- constructor(
19
- name: string,
20
- platform: string,
21
- supportsNativePlatform: boolean,
22
- duplicatesSet: DuplicatesSet,
23
- );
24
- }