/
flow-types.js
271 lines (230 loc) Β· 6.43 KB
/
flow-types.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
* @oncall react_native
*/
'use strict';
import type ModuleMap from './ModuleMap';
import type {PerfLoggerFactory, RootPerfLogger, PerfLogger} from 'metro-config';
export type {PerfLoggerFactory, PerfLogger};
// These inputs affect the internal data collected for a given filesystem
// state, and changes may invalidate a cache.
export type BuildParameters = $ReadOnly<{
computeDependencies: boolean,
computeSha1: boolean,
enableSymlinks: boolean,
extensions: $ReadOnlyArray<string>,
forceNodeFilesystemAPI: boolean,
ignorePattern: RegExp,
mocksPattern: ?RegExp,
platforms: $ReadOnlyArray<string>,
retainAllFiles: boolean,
rootDir: string,
roots: $ReadOnlyArray<string>,
skipPackageJson: boolean,
// Module paths that should export a 'getCacheKey' method
dependencyExtractor: ?string,
hasteImplModulePath: ?string,
cacheBreaker: string,
}>;
export type BuildResult = {
fileSystem: FileSystem,
hasteModuleMap: ModuleMap,
};
export type CacheData = $ReadOnly<{
clocks: WatchmanClocks,
map: RawModuleMap['map'],
mocks: RawModuleMap['mocks'],
duplicates: RawModuleMap['duplicates'],
files: FileData,
}>;
export interface CacheManager {
read(): Promise<?CacheData>;
write(
dataSnapshot: CacheData,
delta: $ReadOnly<{changed: FileData, removed: FileData}>,
): Promise<void>;
}
export type CacheManagerFactory = (
buildParameters: BuildParameters,
) => CacheManager;
export type ChangeEvent = {
logger: ?RootPerfLogger,
eventsQueue: EventsQueue,
};
export type ChangeEventMetadata = {
modifiedTime: ?number, // Epoch ms
size: ?number, // Bytes
type: 'f' | 'd' | 'l', // Regular file / Directory / Symlink
};
export type Console = typeof global.console;
export type CrawlerOptions = {
abortSignal: ?AbortSignal,
computeSha1: boolean,
extensions: $ReadOnlyArray<string>,
forceNodeFilesystemAPI: boolean,
ignore: IgnoreMatcher,
includeSymlinks: boolean,
perfLogger?: ?PerfLogger,
previousState: $ReadOnly<{
clocks: $ReadOnlyMap<Path, WatchmanClockSpec>,
files: $ReadOnlyMap<Path, FileMetaData>,
}>,
rootDir: string,
roots: $ReadOnlyArray<string>,
onStatus: (status: WatcherStatus) => void,
};
export type WatcherStatus =
| {
type: 'watchman_slow_command',
timeElapsed: number,
command: 'watch-project' | 'query',
}
| {
type: 'watchman_slow_command_complete',
timeElapsed: number,
command: 'watch-project' | 'query',
}
| {
type: 'watchman_warning',
warning: mixed,
command: 'watch-project' | 'query',
};
export type DuplicatesSet = Map<string, /* type */ number>;
export type DuplicatesIndex = Map<string, Map<string, DuplicatesSet>>;
export type EventsQueue = Array<{
filePath: Path,
metadata?: ?ChangeEventMetadata,
type: string,
}>;
export type HType = {
ID: 0,
MTIME: 1,
SIZE: 2,
VISITED: 3,
DEPENDENCIES: 4,
SHA1: 5,
SYMLINK: 6,
PATH: 0,
TYPE: 1,
MODULE: 0,
PACKAGE: 1,
GENERIC_PLATFORM: 'g',
NATIVE_PLATFORM: 'native',
DEPENDENCY_DELIM: '\0',
};
export type HTypeValue = $Values<HType>;
export type IgnoreMatcher = (item: string) => boolean;
export type FileData = Map<Path, FileMetaData>;
export type FileMetaData = [
/* id */ string,
/* mtime */ number,
/* size */ number,
/* visited */ 0 | 1,
/* dependencies */ string,
/* sha1 */ ?string,
/* symlink */ 0 | 1 | string, // string specifies target, if known
];
export type FileStats = $ReadOnly<{
fileType: 'f' | 'l',
modifiedTime: number,
}>;
export interface FileSystem {
exists(file: Path): boolean;
getAllFiles(): Array<Path>;
getDependencies(file: Path): ?Array<string>;
getModuleName(file: Path): ?string;
getRealPath(file: Path): ?string;
getSerializableSnapshot(): FileData;
getSha1(file: Path): ?string;
/**
* Analogous to posix lstat. If the file at `file` is a symlink, return
* information about the symlink without following it.
*/
linkStats(file: Path): ?FileStats;
matchFiles(pattern: RegExp | string): Array<Path>;
/**
* Given a search context, return a list of file paths matching the query.
* The query matches against normalized paths which start with `./`,
* for example: `a/b.js` -> `./a/b.js`
*/
matchFilesWithContext(
root: Path,
context: $ReadOnly<{
/* Should search for files recursively. */
recursive: boolean,
/* Filter relative paths against a pattern. */
filter: RegExp,
}>,
): Array<Path>;
}
export type Glob = string;
export interface IModuleMap {
getModule(
name: string,
platform?: ?string,
supportsNativePlatform?: ?boolean,
type?: ?HTypeValue,
): ?Path;
getPackage(
name: string,
platform: ?string,
_supportsNativePlatform: ?boolean,
): ?Path;
getMockModule(name: string): ?Path;
getRawModuleMap(): ReadOnlyRawModuleMap;
}
export type MockData = Map<string, Path>;
export type ModuleMapData = Map<string, ModuleMapItem>;
export type ModuleMapItem = {
[platform: string]: ModuleMetaData,
__proto__: null,
};
export type ModuleMetaData = [/* path */ string, /* type */ number];
export interface MutableFileSystem extends FileSystem {
remove(filePath: Path): void;
addOrModify(filePath: Path, fileMetadata: FileMetaData): void;
bulkAddOrModify(addedOrModifiedFiles: FileData): void;
}
export type Path = string;
export type RawModuleMap = {
rootDir: Path,
duplicates: DuplicatesIndex,
map: ModuleMapData,
mocks: MockData,
};
export type ReadOnlyRawModuleMap = $ReadOnly<{
rootDir: Path,
duplicates: $ReadOnlyMap<
string,
$ReadOnlyMap<string, $ReadOnlyMap<string, number>>,
>,
map: $ReadOnlyMap<string, ModuleMapItem>,
mocks: $ReadOnlyMap<string, Path>,
}>;
export type WatchmanClockSpec =
| string
| $ReadOnly<{scm: $ReadOnly<{'mergebase-with': string}>}>;
export type WatchmanClocks = Map<Path, WatchmanClockSpec>;
export type WorkerMessage = $ReadOnly<{
computeDependencies: boolean,
computeSha1: boolean,
dependencyExtractor?: ?string,
enableHastePackages: boolean,
readLink: boolean,
rootDir: string,
filePath: string,
hasteImplModulePath?: ?string,
}>;
export type WorkerMetadata = $ReadOnly<{
dependencies?: ?$ReadOnlyArray<string>,
id?: ?string,
module?: ?ModuleMetaData,
sha1?: ?string,
symlinkTarget?: ?string,
}>;