-
Notifications
You must be signed in to change notification settings - Fork 598
/
types.flow.js
301 lines (262 loc) Β· 7.7 KB
/
types.flow.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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
'use strict';
import type {
MixedSourceMap,
FBSourceFunctionMap,
BasicSourceMap,
} from 'metro-source-map';
import type {TransformResultDependency} from 'metro/src/DeltaBundler';
export type BuildResult = GraphResult;
export type Callback<A = void, B = void> = (Error => void) &
((null | void, A, B) => void);
export type Dependency = {|
// The module name or path used to require the dependency
id: string,
+isAsync: boolean,
+isPrefetchOnly: boolean,
+splitCondition: ?{|
+mobileConfigName: string,
|},
path: string,
+locs: $ReadOnlyArray<BabelSourceLocation>,
|};
export type File = {|
code: string,
map: ?BasicSourceMap,
functionMap: ?FBSourceFunctionMap,
path: string,
type: CodeFileTypes,
libraryIdx: ?number,
soundResources?: ?Array<string>,
|};
type CodeFileTypes = 'module' | 'script';
export type GraphFn = (
entryPoints: Iterable<string>,
// platform: string,
) => GraphResult;
export type GraphResult = {|
modules: Array<Module>,
|};
export type ModuleIds = {|
/**
* The module ID is global across all segments and identifies the module
* uniquely. This is useful to cache modules that has been loaded already at
* the app level.
*/
+moduleId: number,
/**
* The local ID is local to each segment. For example segment zero may have a
* module with local ID 1, and segment one a module with the same local ID.
* This is useful so that RAM segments tables start at zero, but the `moduleId`
* will be used otherwise.
* Some bundle formats allow a module to be repeated in multiple segments, in which
* case this property does not apply and will be omitted.
*/
+localId?: number,
|};
/**
* Indempotent function that gets us the IDs corresponding to a particular
* module identified by path.
*/
export type IdsForPathFn = ({path: string, ...}) => ModuleIds;
export type LoadResult = {
file: File,
dependencies: $ReadOnlyArray<TransformResultDependency>,
...
};
export type LoadFn = (file: string) => LoadResult;
export type Module = {|
dependencies: Array<Dependency>,
file: File,
|};
export type PostProcessModules = (
modules: $ReadOnlyArray<Module>,
entryPoints: Array<string>,
) => $ReadOnlyArray<Module>;
export type OutputFnArg = {|
dependencyMapReservedName?: ?string,
filename: string,
globalPrefix: string,
idsForPath: IdsForPathFn,
modules: Iterable<Module>,
requireCalls: Iterable<Module>,
sourceMapPath?: ?string,
enableIDInlining: boolean,
segmentID: number,
|};
export type OutputFn<
M: MixedSourceMap = MixedSourceMap,
> = OutputFnArg => OutputResult<M>;
export type OutputResult<M: MixedSourceMap> = {|
code: string | Buffer,
extraFiles?: Iterable<[string, string | Buffer]>,
map: M,
|};
export type PackageData = {|
browser?: Object | string,
main?: string,
name?: string,
'react-native'?: Object | string,
|};
export type ResolveFn = (id: string, source: ?string) => string;
export type TransformResult = ConcreteTransformResult | LinkedTransformResult;
export type ImportNames = {
all: string,
default: string,
};
export type ConcreteTransformResult = {
type: 'concrete',
code: string,
dependencies: $ReadOnlyArray<TransformResultDependency>,
map: ?BasicSourceMap,
soundResources?: ?Array<string>,
// NOTE: requireName, importNames and dependencyMapName are only used by the
// optimizer. They are deleted when the transform result is serialized to
// JSON.
dependencyMapName?: string,
requireName?: string,
importNames?: ImportNames,
};
export type LinkedTransformResult = $ReadOnly<{
type: 'linked',
sourceVariantName: string,
}>;
export type TransformResults = {
+[string]: TransformResult,
};
export type TransformVariants = {+[name: string]: {...}};
export type TransformedCodeFile = {|
+file: string,
+functionMap: ?FBSourceFunctionMap,
+hasteID: ?string,
+package?: PackageData,
+transformed: TransformResults,
+type: CodeFileTypes,
|};
export type ImageSize = {|+width: number, +height: number|};
export type AssetFileVariant = $ReadOnly<{
/**
* The content is encoded in Base64 so that it can be stored in JSON files,
* that are used to communicate between different commands of a Buck
* build worker, for example.
*/
contentBase64: string,
/**
* Hash of the asset file content.
*/
hash: string,
/**
* The path of the original file for this asset. For example
* `foo/bar@3x.ios.png`. This is most useful for reporting purposes, such as
* error messages.
*/
filePath: string,
/**
* If the asset is an image, this contain the size in physical pixels (ie.
* scale * logical pixels).
*/
physicalSize: ?ImageSize,
/**
* The platform this asset is designed for, for example `ios` if the file name
* is `foo.ios.js`. `null` if the asset is not platform-specific.
*/
platform: ?string,
/**
* The scale this asset is designed for, for example `2`
* if the file name is `foo@2x.png`.
*/
scale: number,
}>;
// A *virtual* asset file ( = one generated JS module in the bundle)
// representing one or more asset variants ( = physical input files).
export type AssetFile = $ReadOnly<{
/**
* The path of the asset that is shared by all potential variants
* of this asset. For example `foo/bar@3x.png` would have the
* asset path `foo/bar.png`.
*/
assetPath: string,
/**
* Guessed from the file extension, for example `png` or `html`.
*/
contentType: string,
/**
* The source files for this asset.
* TODO(moti): Guarantee that an AssetFile has *all* the source files for a
* given asset.
*/
variants: $ReadOnlyArray<AssetFileVariant>,
}>;
export type TransformedSourceFile =
| {|
+type: 'code',
+details: TransformedCodeFile,
|}
| {|
+type: 'asset',
+details: AssetFile,
|}
| {|
+type: 'unknown',
|};
export type LibraryOptions = {|
dependencies?: Array<string>,
optimize: boolean,
platform?: string,
rebasePath: string => string,
|};
export type Base64Content = string;
export type AssetContents = {
+data: Base64Content,
+outputPath: string,
...
};
export type AssetContentsByPath = {
+[moduleFilePath: string]: $ReadOnlyArray<AssetContents>,
...,
};
export type ResolvedCodeFile = {|
+codeFile: TransformedCodeFile,
/**
* Imagine we have a source file that contains a `require('foo')`. The library
* will resolve the path of the module `foo` and store it in this field along
* all the other dependencies. For example, it could be
* `{'foo': 'bar/foo.js', 'bar': 'node_modules/bar/index.js'}`.
*/
+filePathsByDependencyName: {[dependencyName: string]: string, ...},
|};
export type LibraryBoundCodeFile = {|
...ResolvedCodeFile,
/**
* Index of the library that this code file has been exported from.
*/
+libraryIdx: number,
|};
/**
* Describe a set of JavaScript files and the associated assets. It could be
* depending on modules from other libraries. To be able to resolve these
* dependencies, these libraries need to be provided by callsites (ex. Buck).
*/
export type Library = {|
+files: Array<TransformedCodeFile>,
/* cannot be a Map because it's JSONified later on */
+assets: AssetContentsByPath,
|};
/**
* Just like a `Library`, but it also contains module resolutions. For example
* if there is a `require('foo')` in some JavaScript file, we keep track of the
* path it resolves to, ex. `beep/glo/foo.js`.
*/
export type ResolvedLibrary = {|
+files: $ReadOnlyArray<ResolvedCodeFile>,
/* cannot be a Map because it's JSONified later on */
+assets: AssetContentsByPath,
|};