metro-file-map 0.83.4 → 0.83.5

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 (59) hide show
  1. package/package.json +3 -2
  2. package/src/Watcher.d.ts +70 -0
  3. package/src/Watcher.js +2 -9
  4. package/src/cache/DiskCacheManager.d.ts +42 -0
  5. package/src/cache/DiskCacheManager.js +1 -5
  6. package/src/constants.d.ts +15 -0
  7. package/src/crawlers/node/hasNativeFindSupport.d.ts +12 -0
  8. package/src/crawlers/node/index.d.ts +16 -0
  9. package/src/crawlers/node/index.js +2 -9
  10. package/src/crawlers/watchman/index.d.ts +23 -0
  11. package/src/crawlers/watchman/index.js +2 -9
  12. package/src/flow-types.d.ts +404 -0
  13. package/src/flow-types.js.flow +1 -1
  14. package/src/index.d.ts +175 -0
  15. package/src/index.js +12 -21
  16. package/src/index.js.flow +10 -15
  17. package/src/lib/FileProcessor.d.ts +53 -0
  18. package/src/lib/FileProcessor.js +1 -5
  19. package/src/lib/RootPathUtils.d.ts +23 -0
  20. package/src/lib/RootPathUtils.js +2 -9
  21. package/src/lib/TreeFS.d.ts +159 -0
  22. package/src/lib/TreeFS.js +1 -5
  23. package/src/lib/checkWatchmanCapabilities.d.ts +13 -0
  24. package/src/lib/normalizePathSeparatorsToPosix.d.ts +13 -0
  25. package/src/lib/normalizePathSeparatorsToPosix.js +1 -4
  26. package/src/lib/normalizePathSeparatorsToSystem.d.ts +13 -0
  27. package/src/lib/normalizePathSeparatorsToSystem.js +1 -4
  28. package/src/lib/rootRelativeCacheKeys.d.ts +17 -0
  29. package/src/lib/rootRelativeCacheKeys.js +1 -5
  30. package/src/lib/sorting.d.ts +16 -0
  31. package/src/plugins/DependencyPlugin.d.ts +56 -0
  32. package/src/plugins/DependencyPlugin.js +1 -1
  33. package/src/plugins/DependencyPlugin.js.flow +1 -1
  34. package/src/plugins/HastePlugin.d.ts +70 -0
  35. package/src/plugins/HastePlugin.js +2 -6
  36. package/src/plugins/HastePlugin.js.flow +1 -1
  37. package/src/plugins/MockPlugin.d.ts +43 -0
  38. package/src/plugins/MockPlugin.js +3 -7
  39. package/src/plugins/MockPlugin.js.flow +2 -2
  40. package/src/plugins/haste/DuplicateHasteCandidatesError.d.ts +24 -0
  41. package/src/plugins/haste/DuplicateHasteCandidatesError.js +1 -5
  42. package/src/plugins/haste/HasteConflictsError.d.ts +16 -0
  43. package/src/plugins/haste/HasteConflictsError.js +1 -5
  44. package/src/plugins/haste/computeConflicts.d.ts +27 -0
  45. package/src/plugins/haste/computeConflicts.js +1 -5
  46. package/src/plugins/haste/getPlatformExtension.d.ts +14 -0
  47. package/src/plugins/mocks/getMockName.d.ts +13 -0
  48. package/src/plugins/mocks/getMockName.js +1 -4
  49. package/src/watchers/AbstractWatcher.d.ts +34 -0
  50. package/src/watchers/AbstractWatcher.js +2 -9
  51. package/src/watchers/FallbackWatcher.d.ts +21 -0
  52. package/src/watchers/FallbackWatcher.js +2 -9
  53. package/src/watchers/NativeWatcher.d.ts +48 -0
  54. package/src/watchers/NativeWatcher.js +1 -4
  55. package/src/watchers/RecrawlWarning.d.ts +25 -0
  56. package/src/watchers/WatchmanWatcher.d.ts +27 -0
  57. package/src/watchers/WatchmanWatcher.js +2 -9
  58. package/src/watchers/common.d.ts +61 -0
  59. package/src/watchers/common.js +1 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "metro-file-map",
3
- "version": "0.83.4",
3
+ "version": "0.83.5",
4
4
  "description": "[Experimental] - 🚇 File crawling, watching and mapping for Metro",
5
5
  "main": "src/index.js",
6
6
  "exports": {
@@ -10,7 +10,8 @@
10
10
  },
11
11
  "repository": {
12
12
  "type": "git",
13
- "url": "git@github.com:facebook/metro.git"
13
+ "url": "git+https://github.com/facebook/metro.git",
14
+ "directory": "packages/metro-file-map"
14
15
  },
15
16
  "scripts": {
16
17
  "prepare-release": "test -d build && rm -rf src.real && mv src src.real && mv build src",
@@ -0,0 +1,70 @@
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
+ */
9
+
10
+ import type {
11
+ Console,
12
+ CrawlerOptions,
13
+ FileData,
14
+ Path,
15
+ PerfLogger,
16
+ WatcherBackendChangeEvent,
17
+ WatchmanClocks,
18
+ } from './flow-types';
19
+
20
+ import EventEmitter from 'events';
21
+
22
+ type CrawlResult = {
23
+ changedFiles: FileData;
24
+ clocks?: WatchmanClocks;
25
+ removedFiles: Set<Path>;
26
+ };
27
+ type WatcherOptions = {
28
+ abortSignal: AbortSignal;
29
+ computeSha1: boolean;
30
+ console: Console;
31
+ enableSymlinks: boolean;
32
+ extensions: ReadonlyArray<string>;
33
+ forceNodeFilesystemAPI: boolean;
34
+ healthCheckFilePrefix: string;
35
+ ignoreForCrawl: (filePath: string) => boolean;
36
+ ignorePatternForWatch: RegExp;
37
+ previousState: CrawlerOptions['previousState'];
38
+ perfLogger: null | undefined | PerfLogger;
39
+ roots: ReadonlyArray<string>;
40
+ rootDir: string;
41
+ useWatchman: boolean;
42
+ watch: boolean;
43
+ watchmanDeferStates: ReadonlyArray<string>;
44
+ };
45
+ export type HealthCheckResult =
46
+ | {
47
+ type: 'error';
48
+ timeout: number;
49
+ error: Error;
50
+ watcher: null | undefined | string;
51
+ }
52
+ | {
53
+ type: 'success';
54
+ timeout: number;
55
+ timeElapsed: number;
56
+ watcher: null | undefined | string;
57
+ }
58
+ | {
59
+ type: 'timeout';
60
+ timeout: number;
61
+ watcher: null | undefined | string;
62
+ pauseReason: null | undefined | string;
63
+ };
64
+ export declare class Watcher extends EventEmitter {
65
+ constructor(options: WatcherOptions);
66
+ crawl(): Promise<CrawlResult>;
67
+ watch(onChange: (change: WatcherBackendChangeEvent) => void): void;
68
+ close(): void;
69
+ checkHealth(timeout: number): Promise<HealthCheckResult>;
70
+ }
package/src/Watcher.js CHANGED
@@ -29,10 +29,7 @@ function _interopRequireWildcard(e, t) {
29
29
  if (!t && e && e.__esModule) return e;
30
30
  var o,
31
31
  i,
32
- f = {
33
- __proto__: null,
34
- default: e,
35
- };
32
+ f = { __proto__: null, default: e };
36
33
  if (null === e || ("object" != typeof e && "function" != typeof e))
37
34
  return f;
38
35
  if ((o = t ? n : r)) {
@@ -52,11 +49,7 @@ function _interopRequireWildcard(e, t) {
52
49
  })(e, t);
53
50
  }
54
51
  function _interopRequireDefault(e) {
55
- return e && e.__esModule
56
- ? e
57
- : {
58
- default: e,
59
- };
52
+ return e && e.__esModule ? e : { default: e };
60
53
  }
61
54
  const debug = require("debug")("Metro:Watcher");
62
55
  const MAX_WAIT_TIME = 240000;
@@ -0,0 +1,42 @@
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
+ CacheData,
14
+ CacheManager,
15
+ CacheManagerFactoryOptions,
16
+ CacheManagerWriteOptions,
17
+ } from '../flow-types';
18
+
19
+ type AutoSaveOptions = Readonly<{debounceMs: number}>;
20
+ type DiskCacheConfig = Readonly<{
21
+ autoSave?: Partial<AutoSaveOptions> | boolean;
22
+ cacheFilePrefix?: null | undefined | string;
23
+ cacheDirectory?: null | undefined | string;
24
+ }>;
25
+ export declare class DiskCacheManager implements CacheManager {
26
+ constructor(
27
+ $$PARAM_0$$: CacheManagerFactoryOptions,
28
+ $$PARAM_1$$: DiskCacheConfig,
29
+ );
30
+ static getCacheFilePath(
31
+ buildParameters: BuildParameters,
32
+ cacheFilePrefix?: null | undefined | string,
33
+ cacheDirectory?: null | undefined | string,
34
+ ): string;
35
+ getCacheFilePath(): string;
36
+ read(): Promise<null | undefined | CacheData>;
37
+ write(
38
+ getSnapshot: () => CacheData,
39
+ $$PARAM_1$$: CacheManagerWriteOptions,
40
+ ): Promise<void>;
41
+ end(): Promise<void>;
42
+ }
@@ -13,11 +13,7 @@ var _path = _interopRequireDefault(require("path"));
13
13
  var _timers = require("timers");
14
14
  var _v = require("v8");
15
15
  function _interopRequireDefault(e) {
16
- return e && e.__esModule
17
- ? e
18
- : {
19
- default: e,
20
- };
16
+ return e && e.__esModule ? e : { default: e };
21
17
  }
22
18
  const debug = require("debug")("Metro:FileMapCache");
23
19
  const DEFAULT_PREFIX = "metro-file-map";
@@ -0,0 +1,15 @@
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
+ */
9
+
10
+ import type {HType} from './flow-types';
11
+
12
+ declare const $$EXPORT_DEFAULT_DECLARATION$$: HType;
13
+ declare type $$EXPORT_DEFAULT_DECLARATION$$ =
14
+ typeof $$EXPORT_DEFAULT_DECLARATION$$;
15
+ export default $$EXPORT_DEFAULT_DECLARATION$$;
@@ -0,0 +1,12 @@
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
+ declare function hasNativeFindSupport(): Promise<boolean>;
12
+ export default hasNativeFindSupport;
@@ -0,0 +1,16 @@
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 {CanonicalPath, CrawlerOptions, FileData} from '../../flow-types';
12
+
13
+ declare function nodeCrawl(
14
+ options: CrawlerOptions,
15
+ ): Promise<{removedFiles: Set<CanonicalPath>; changedFiles: FileData}>;
16
+ export default nodeCrawl;
@@ -20,10 +20,7 @@ function _interopRequireWildcard(e, t) {
20
20
  if (!t && e && e.__esModule) return e;
21
21
  var o,
22
22
  i,
23
- f = {
24
- __proto__: null,
25
- default: e,
26
- };
23
+ f = { __proto__: null, default: e };
27
24
  if (null === e || ("object" != typeof e && "function" != typeof e))
28
25
  return f;
29
26
  if ((o = t ? n : r)) {
@@ -43,11 +40,7 @@ function _interopRequireWildcard(e, t) {
43
40
  })(e, t);
44
41
  }
45
42
  function _interopRequireDefault(e) {
46
- return e && e.__esModule
47
- ? e
48
- : {
49
- default: e,
50
- };
43
+ return e && e.__esModule ? e : { default: e };
51
44
  }
52
45
  const debug = require("debug")("Metro:NodeCrawler");
53
46
  function find(
@@ -0,0 +1,23 @@
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
+ CanonicalPath,
13
+ CrawlerOptions,
14
+ FileData,
15
+ WatchmanClocks,
16
+ } from '../../flow-types';
17
+
18
+ declare function watchmanCrawl($$PARAM_0$$: CrawlerOptions): Promise<{
19
+ changedFiles: FileData;
20
+ removedFiles: Set<CanonicalPath>;
21
+ clocks: WatchmanClocks;
22
+ }>;
23
+ export default watchmanCrawl;
@@ -24,10 +24,7 @@ function _interopRequireWildcard(e, t) {
24
24
  if (!t && e && e.__esModule) return e;
25
25
  var o,
26
26
  i,
27
- f = {
28
- __proto__: null,
29
- default: e,
30
- };
27
+ f = { __proto__: null, default: e };
31
28
  if (null === e || ("object" != typeof e && "function" != typeof e))
32
29
  return f;
33
30
  if ((o = t ? n : r)) {
@@ -47,11 +44,7 @@ function _interopRequireWildcard(e, t) {
47
44
  })(e, t);
48
45
  }
49
46
  function _interopRequireDefault(e) {
50
- return e && e.__esModule
51
- ? e
52
- : {
53
- default: e,
54
- };
47
+ return e && e.__esModule ? e : { default: e };
55
48
  }
56
49
  const WATCHMAN_WARNING_INITIAL_DELAY_MILLISECONDS = 10000;
57
50
  const WATCHMAN_WARNING_INTERVAL_MILLISECONDS = 20000;
@@ -0,0 +1,404 @@
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
+ export type BuildParameters = Readonly<{
15
+ computeSha1: boolean;
16
+ enableSymlinks: boolean;
17
+ extensions: ReadonlyArray<string>;
18
+ forceNodeFilesystemAPI: boolean;
19
+ ignorePattern: RegExp;
20
+ plugins: ReadonlyArray<FileMapPlugin>;
21
+ retainAllFiles: boolean;
22
+ rootDir: string;
23
+ roots: ReadonlyArray<string>;
24
+ cacheBreaker: string;
25
+ }>;
26
+ export type BuildResult = {fileSystem: FileSystem};
27
+ export type CacheData = Readonly<{
28
+ clocks: WatchmanClocks;
29
+ fileSystemData: unknown;
30
+ plugins: ReadonlyMap<string, void | V8Serializable>;
31
+ }>;
32
+ export interface CacheManager {
33
+ /**
34
+ * Called during startup to load initial state, if available. Provided to
35
+ * a crawler, which will return the delta between the initial state and the
36
+ * current file system state.
37
+ */
38
+ read(): Promise<null | undefined | CacheData>;
39
+ /**
40
+ * Called when metro-file-map `build()` has applied changes returned by the
41
+ * crawler - i.e. internal state reflects the current file system state.
42
+ *
43
+ * getSnapshot may be retained and called at any time before end(), such as
44
+ * in response to eventSource 'change' events.
45
+ */
46
+ write(
47
+ getSnapshot: () => CacheData,
48
+ opts: CacheManagerWriteOptions,
49
+ ): Promise<void>;
50
+ /**
51
+ * The last call that will be made to this CacheManager. Any handles should
52
+ * be closed by the time this settles.
53
+ */
54
+ end(): Promise<void>;
55
+ }
56
+ export interface CacheManagerEventSource {
57
+ onChange(listener: () => void): () => void;
58
+ }
59
+ export type CacheManagerFactory = (
60
+ options: CacheManagerFactoryOptions,
61
+ ) => CacheManager;
62
+ export type CacheManagerFactoryOptions = Readonly<{
63
+ buildParameters: BuildParameters;
64
+ }>;
65
+ export type CacheManagerWriteOptions = Readonly<{
66
+ changedSinceCacheRead: boolean;
67
+ eventSource: CacheManagerEventSource;
68
+ onWriteError: (error: Error) => void;
69
+ }>;
70
+ export type CanonicalPath = string;
71
+ export type ChangeEvent = {
72
+ logger: null | undefined | RootPerfLogger;
73
+ eventsQueue: EventsQueue;
74
+ };
75
+ export type ChangeEventMetadata = {
76
+ modifiedTime: null | undefined | number;
77
+ size: null | undefined | number;
78
+ type: 'f' | 'd' | 'l';
79
+ };
80
+ export type Console = typeof global.console;
81
+ export type CrawlerOptions = {
82
+ abortSignal: null | undefined | AbortSignal;
83
+ computeSha1: boolean;
84
+ console: Console;
85
+ extensions: ReadonlyArray<string>;
86
+ forceNodeFilesystemAPI: boolean;
87
+ ignore: IgnoreMatcher;
88
+ includeSymlinks: boolean;
89
+ perfLogger?: null | undefined | PerfLogger;
90
+ previousState: Readonly<{
91
+ clocks: ReadonlyMap<CanonicalPath, WatchmanClockSpec>;
92
+ fileSystem: FileSystem;
93
+ }>;
94
+ rootDir: string;
95
+ roots: ReadonlyArray<string>;
96
+ onStatus: (status: WatcherStatus) => void;
97
+ };
98
+ export type DependencyExtractor = {
99
+ extract: (
100
+ content: string,
101
+ absoluteFilePath: string,
102
+ defaultExtractor?: DependencyExtractor['extract'],
103
+ ) => Set<string>;
104
+ getCacheKey: () => string;
105
+ };
106
+ export type WatcherStatus =
107
+ | {
108
+ type: 'watchman_slow_command';
109
+ timeElapsed: number;
110
+ command: 'watch-project' | 'query';
111
+ }
112
+ | {
113
+ type: 'watchman_slow_command_complete';
114
+ timeElapsed: number;
115
+ command: 'watch-project' | 'query';
116
+ }
117
+ | {
118
+ type: 'watchman_warning';
119
+ warning: unknown;
120
+ command: 'watch-project' | 'query';
121
+ };
122
+ export type DuplicatesSet = Map<string, number>;
123
+ 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
+ export type FileMapPluginInitOptions<
134
+ SerializableState,
135
+ PerFileData = void,
136
+ > = Readonly<{
137
+ files: Readonly<{
138
+ fileIterator(
139
+ opts: Readonly<{includeNodeModules: boolean; includeSymlinks: boolean}>,
140
+ ): Iterable<{
141
+ baseName: string;
142
+ canonicalPath: string;
143
+ pluginData: null | undefined | PerFileData;
144
+ }>;
145
+ lookup(
146
+ mixedPath: string,
147
+ ):
148
+ | {exists: false}
149
+ | {exists: true; type: 'f'; pluginData: PerFileData}
150
+ | {exists: true; type: 'd'};
151
+ }>;
152
+ pluginState: null | undefined | SerializableState;
153
+ }>;
154
+ export type FileMapPluginWorker = Readonly<{
155
+ worker: Readonly<{modulePath: string; setupArgs: JsonData}>;
156
+ filter: ($$PARAM_0$$: {
157
+ normalPath: string;
158
+ isNodeModules: boolean;
159
+ }) => boolean;
160
+ }>;
161
+ export type V8Serializable =
162
+ | string
163
+ | number
164
+ | boolean
165
+ | null
166
+ | ReadonlyArray<V8Serializable>
167
+ | ReadonlySet<V8Serializable>
168
+ | ReadonlyMap<string, V8Serializable>
169
+ | Readonly<{[key: string]: V8Serializable}>;
170
+ export interface FileMapPlugin<
171
+ SerializableState extends void | V8Serializable = void | V8Serializable,
172
+ PerFileData extends void | V8Serializable = void | V8Serializable,
173
+ > {
174
+ readonly name: string;
175
+ initialize(
176
+ initOptions: FileMapPluginInitOptions<SerializableState, PerFileData>,
177
+ ): Promise<void>;
178
+ 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,
188
+ ): void;
189
+ getCacheKey(): string;
190
+ getWorker(): null | undefined | FileMapPluginWorker;
191
+ }
192
+ export interface MetadataWorker {
193
+ processFile(
194
+ $$PARAM_0$$: WorkerMessage,
195
+ $$PARAM_1$$: Readonly<{getContent: () => Buffer}>,
196
+ ): V8Serializable;
197
+ }
198
+ export type HType = {
199
+ MTIME: 0;
200
+ SIZE: 1;
201
+ VISITED: 2;
202
+ SHA1: 3;
203
+ SYMLINK: 4;
204
+ PLUGINDATA: number;
205
+ PATH: 0;
206
+ TYPE: 1;
207
+ MODULE: 0;
208
+ PACKAGE: 1;
209
+ GENERIC_PLATFORM: 'g';
210
+ NATIVE_PLATFORM: 'native';
211
+ };
212
+ export type HTypeValue = HType[keyof HType];
213
+ export type IgnoreMatcher = (item: string) => boolean;
214
+ export type FileData = Map<CanonicalPath, FileMetadata>;
215
+ export type FileMetadata = [
216
+ null | undefined | number,
217
+ number,
218
+ 0 | 1,
219
+ null | undefined | string,
220
+ 0 | 1 | string,
221
+ ...unknown[],
222
+ ];
223
+ export type FileStats = Readonly<{
224
+ fileType: 'f' | 'l';
225
+ modifiedTime: null | undefined | number;
226
+ size: null | undefined | number;
227
+ }>;
228
+ export interface FileSystem {
229
+ exists(file: Path): boolean;
230
+ getAllFiles(): Array<Path>;
231
+ getDifference(files: FileData): {
232
+ changedFiles: FileData;
233
+ removedFiles: Set<string>;
234
+ };
235
+ getSerializableSnapshot(): CacheData['fileSystemData'];
236
+ getSha1(file: Path): null | undefined | string;
237
+ getOrComputeSha1(
238
+ file: Path,
239
+ ): Promise<null | undefined | {sha1: string; content?: Buffer}>;
240
+ /**
241
+ * Given a start path (which need not exist), a subpath and type, and
242
+ * optionally a 'breakOnSegment', performs the following:
243
+ *
244
+ * X = mixedStartPath
245
+ * do
246
+ * if basename(X) === opts.breakOnSegment
247
+ * return null
248
+ * if X + subpath exists and has type opts.subpathType
249
+ * return {
250
+ * absolutePath: realpath(X + subpath)
251
+ * containerRelativePath: relative(mixedStartPath, X)
252
+ * }
253
+ * X = dirname(X)
254
+ * while X !== dirname(X)
255
+ *
256
+ * If opts.invalidatedBy is given, collects all absolute, real paths that if
257
+ * added or removed may invalidate this result.
258
+ *
259
+ * Useful for finding the closest package scope (subpath: package.json,
260
+ * type f, breakOnSegment: node_modules) or closest potential package root
261
+ * (subpath: node_modules/pkg, type: d) in Node.js resolution.
262
+ */
263
+ hierarchicalLookup(
264
+ mixedStartPath: string,
265
+ subpath: string,
266
+ opts: {
267
+ breakOnSegment: null | undefined | string;
268
+ invalidatedBy: null | undefined | Set<string>;
269
+ subpathType: 'f' | 'd';
270
+ },
271
+ ): null | undefined | {absolutePath: string; containerRelativePath: string};
272
+ /**
273
+ * Analogous to posix lstat. If the file at `file` is a symlink, return
274
+ * information about the symlink without following it.
275
+ */
276
+ linkStats(file: Path): null | undefined | FileStats;
277
+ /**
278
+ * Return information about the given path, whether a directory or file.
279
+ * Always follow symlinks, and return a real path if it exists.
280
+ */
281
+ lookup(mixedPath: Path): LookupResult;
282
+ matchFiles(opts: {
283
+ filter?: RegExp | null;
284
+ filterCompareAbsolute?: boolean;
285
+ filterComparePosix?: boolean;
286
+ follow?: boolean;
287
+ recursive?: boolean;
288
+ rootDir?: Path | null;
289
+ }): Iterable<Path>;
290
+ }
291
+ export type Glob = string;
292
+ export type JsonData =
293
+ | string
294
+ | number
295
+ | boolean
296
+ | null
297
+ | Array<JsonData>
298
+ | {[key: string]: JsonData};
299
+ export type LookupResult =
300
+ | {exists: false; links: ReadonlySet<string>; missing: string}
301
+ | {exists: true; links: ReadonlySet<string>; realPath: string; type: 'd'}
302
+ | {
303
+ exists: true;
304
+ links: ReadonlySet<string>;
305
+ realPath: string;
306
+ type: 'f';
307
+ metadata: FileMetadata;
308
+ };
309
+ export interface MockMap {
310
+ getMockModule(name: string): null | undefined | Path;
311
+ }
312
+ export type HasteConflict = {
313
+ id: string;
314
+ platform: string | null;
315
+ absolutePaths: Array<string>;
316
+ type: 'duplicate' | 'shadowing';
317
+ };
318
+ export interface HasteMap {
319
+ getModule(
320
+ name: string,
321
+ platform?: null | undefined | string,
322
+ supportsNativePlatform?: null | undefined | boolean,
323
+ type?: null | undefined | HTypeValue,
324
+ ): null | undefined | Path;
325
+ getModuleNameByPath(file: Path): null | undefined | string;
326
+ getPackage(
327
+ name: string,
328
+ platform: null | undefined | string,
329
+ _supportsNativePlatform: null | undefined | boolean,
330
+ ): null | undefined | Path;
331
+ computeConflicts(): Array<HasteConflict>;
332
+ }
333
+ export type HasteMapData = Map<string, HasteMapItem>;
334
+ export type HasteMapItem = {
335
+ [platform: string]: HasteMapItemMetadata;
336
+ };
337
+ export type HasteMapItemMetadata = [string, number];
338
+ export interface MutableFileSystem extends FileSystem {
339
+ remove(filePath: Path): null | undefined | FileMetadata;
340
+ addOrModify(filePath: Path, fileMetadata: FileMetadata): void;
341
+ bulkAddOrModify(addedOrModifiedFiles: FileData): void;
342
+ }
343
+ export type Path = string;
344
+ export type ProcessFileFunction = (
345
+ normalPath: string,
346
+ metadata: FileMetadata,
347
+ request: Readonly<{computeSha1: boolean}>,
348
+ ) => null | undefined | Buffer;
349
+ export type RawMockMap = Readonly<{
350
+ duplicates: Map<string, Set<string>>;
351
+ mocks: Map<string, Path>;
352
+ version: number;
353
+ }>;
354
+ export type ReadOnlyRawMockMap = Readonly<{
355
+ duplicates: ReadonlyMap<string, ReadonlySet<string>>;
356
+ mocks: ReadonlyMap<string, Path>;
357
+ version: number;
358
+ }>;
359
+ export interface WatcherBackend {
360
+ getPauseReason(): null | undefined | string;
361
+ onError(listener: (error: Error) => void): () => void;
362
+ onFileEvent(listener: (event: WatcherBackendChangeEvent) => void): () => void;
363
+ startWatching(): Promise<void>;
364
+ stopWatching(): Promise<void>;
365
+ }
366
+ export type ChangeEventClock = [string, string];
367
+ export type WatcherBackendChangeEvent =
368
+ | Readonly<{
369
+ event: 'touch';
370
+ clock?: ChangeEventClock;
371
+ relativePath: string;
372
+ root: string;
373
+ metadata: ChangeEventMetadata;
374
+ }>
375
+ | Readonly<{
376
+ event: 'delete';
377
+ clock?: ChangeEventClock;
378
+ relativePath: string;
379
+ root: string;
380
+ metadata?: void;
381
+ }>;
382
+ export type WatcherBackendOptions = Readonly<{
383
+ ignored: null | undefined | RegExp;
384
+ globs: ReadonlyArray<string>;
385
+ dot: boolean;
386
+ }>;
387
+ export type WatchmanClockSpec =
388
+ | string
389
+ | Readonly<{scm: Readonly<{'mergebase-with': string}>}>;
390
+ export type WatchmanClocks = Map<Path, WatchmanClockSpec>;
391
+ export type WorkerMessage = Readonly<{
392
+ computeSha1: boolean;
393
+ filePath: string;
394
+ maybeReturnContent: boolean;
395
+ pluginsToRun: ReadonlyArray<number>;
396
+ }>;
397
+ export type WorkerMetadata = Readonly<{
398
+ sha1?: null | undefined | string;
399
+ content?: null | undefined | Buffer;
400
+ pluginData?: ReadonlyArray<V8Serializable>;
401
+ }>;
402
+ export type WorkerSetupArgs = Readonly<{
403
+ plugins?: ReadonlyArray<FileMapPluginWorker['worker']>;
404
+ }>;