-
Notifications
You must be signed in to change notification settings - Fork 600
/
types.flow.js
169 lines (146 loc) Β· 4.6 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
/**
* 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
*/
'use strict';
import type {
RequireContextParams,
ContextMode,
} from '../ModuleGraph/worker/collectDependencies';
import type {PrivateState} from './graphOperations';
import type {JsTransformOptions} from 'metro-transform-worker';
import CountingSet from '../lib/CountingSet';
export type RequireContext = {
/* Should search for files recursively. Optional, default `true` when `require.context` is used */
recursive: boolean,
/* Filename filter pattern for use in `require.context`. Optional, default `.*` (any file) when `require.context` is used */
filter: RegExp,
/** Mode for resolving dynamic dependencies. Defaults to `sync` */
mode: ContextMode,
};
export type MixedOutput = {
+data: mixed,
+type: string,
};
export type AsyncDependencyType = 'async' | 'prefetch';
export type TransformResultDependency = {
/**
* The literal name provided to a require or import call. For example 'foo' in
* case of `require('foo')`.
*/
+name: string,
/**
* Extra data returned by the dependency extractor. Whatever is added here is
* blindly piped by Metro to the serializers.
*/
+data: {
/**
* If not null, this dependency is due to a dynamic `import()` or `__prefetchImport()` call.
*/
+asyncType: AsyncDependencyType | null,
/**
* The condition for splitting on this dependency edge.
*/
+splitCondition?: {
+mobileConfigName: string,
},
/**
* The dependency is enclosed in a try/catch block.
*/
+isOptional?: boolean,
+locs: $ReadOnlyArray<BabelSourceLocation>,
/** Context for requiring a collection of modules. */
+contextParams?: RequireContextParams,
},
};
export type Dependency = {
+absolutePath: string,
+data: TransformResultDependency,
};
export type Module<T = MixedOutput> = {
+contextParams?: RequireContext,
+dependencies: Map<string, Dependency>,
+inverseDependencies: CountingSet<string>,
+output: $ReadOnlyArray<T>,
+path: string,
+getSource: () => Buffer,
};
export type Dependencies<T = MixedOutput> = Map<string, Module<T>>;
export type TransformInputOptions = $Diff<
JsTransformOptions,
{
inlinePlatform: boolean,
inlineRequires: boolean,
...
},
>;
export type GraphInputOptions = $ReadOnly<{
entryPoints: $ReadOnlySet<string>,
// Unused in core but useful for custom serializers / experimentalSerializerHook
transformOptions: TransformInputOptions,
}>;
export type Graph<T = MixedOutput> = {
...$ReadOnly<GraphInputOptions>,
dependencies: Dependencies<T>,
+importBundleNames: Set<string>,
+privateState: PrivateState,
};
export type TransformResult<T = MixedOutput> = $ReadOnly<{
dependencies: $ReadOnlyArray<TransformResultDependency>,
output: $ReadOnlyArray<T>,
}>;
export type TransformResultWithSource<T = MixedOutput> = $ReadOnly<{
...TransformResult<T>,
getSource: () => Buffer,
}>;
/** Transformer for generating `require.context` virtual module. */
export type TransformContextFn<T = MixedOutput> = (
string,
RequireContext,
) => Promise<TransformResultWithSource<T>>;
export type TransformFn<T = MixedOutput> = string => Promise<
TransformResultWithSource<T>,
>;
export type AllowOptionalDependenciesWithOptions = {
+exclude: Array<string>,
};
export type AllowOptionalDependencies =
| boolean
| AllowOptionalDependenciesWithOptions;
export type Options<T = MixedOutput> = {
+resolve: (from: string, to: string, context?: ?RequireContext) => string,
+transform: TransformFn<T>,
/** Given a path and require context, return a virtual context module. */
+transformContext: TransformContextFn<T>,
+transformOptions: TransformInputOptions,
+onProgress: ?(numProcessed: number, total: number) => mixed,
+experimentalImportBundleSupport: boolean,
+unstable_allowRequireContext: boolean,
+shallow: boolean,
};
export type DeltaResult<T = MixedOutput> = {
+added: Map<string, Module<T>>,
+modified: Map<string, Module<T>>,
+deleted: Set<string>,
+reset: boolean,
};
export type SerializerOptions = {
+asyncRequireModulePath: string,
+createModuleId: string => number,
+dev: boolean,
+getRunModuleStatement: (number | string) => string,
+inlineSourceMap: ?boolean,
+modulesOnly: boolean,
+processModuleFilter: (module: Module<>) => boolean,
+projectRoot: string,
+runBeforeMainModule: $ReadOnlyArray<string>,
+runModule: boolean,
+serverRoot: string,
+sourceMapUrl: ?string,
+sourceUrl: ?string,
};