metro 0.76.0 → 0.76.1
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.
- package/package.json +24 -24
- package/src/Asset.d.ts +25 -0
- package/src/Bundler.d.ts +39 -0
- package/src/DeltaBundler/Graph.d.ts +40 -0
- package/src/DeltaBundler/Serializers/getRamBundleInfo.d.ts +18 -0
- package/src/DeltaBundler/Transformer.js +1 -2
- package/src/DeltaBundler/Transformer.js.flow +1 -2
- package/src/DeltaBundler/Worker.d.ts +47 -0
- package/src/DeltaBundler/types.d.ts +167 -0
- package/src/DeltaBundler.d.ts +58 -0
- package/src/HmrServer.js +1 -5
- package/src/HmrServer.js.flow +0 -5
- package/src/IncrementalBundler.d.ts +97 -0
- package/src/IncrementalBundler.js +1 -0
- package/src/IncrementalBundler.js.flow +1 -0
- package/src/ModuleGraph/worker/collectDependencies.d.ts +27 -0
- package/src/ModuleGraph/worker/collectDependencies.js +42 -25
- package/src/ModuleGraph/worker/collectDependencies.js.flow +41 -36
- package/src/Server/MultipartResponse.d.ts +31 -0
- package/src/Server.d.ts +113 -0
- package/src/Server.js +11 -133
- package/src/Server.js.flow +12 -154
- package/src/cli/parseKeyValueParamArray.js +34 -0
- package/src/cli/parseKeyValueParamArray.js.flow +31 -0
- package/src/cli-utils.js.flow +2 -6
- package/src/cli.js +2 -0
- package/src/cli.js.flow +1 -0
- package/src/commands/build.js +34 -7
- package/src/commands/build.js.flow +50 -8
- package/src/commands/dependencies.js +11 -9
- package/src/commands/dependencies.js.flow +128 -0
- package/src/commands/serve.js +11 -4
- package/src/commands/serve.js.flow +26 -6
- package/src/index.d.ts +151 -0
- package/src/index.flow.js +8 -2
- package/src/index.flow.js.flow +18 -6
- package/src/lib/CountingSet.d.ts +48 -0
- package/src/lib/TerminalReporter.d.ts +27 -0
- package/src/lib/TerminalReporter.js +1 -4
- package/src/lib/TerminalReporter.js.flow +1 -5
- package/src/lib/contextModule.d.ts +22 -0
- package/src/lib/getGraphId.d.ts +11 -0
- package/src/lib/getGraphId.js +0 -1
- package/src/lib/getGraphId.js.flow +0 -1
- package/src/lib/getPrependedScripts.js +0 -9
- package/src/lib/getPrependedScripts.js.flow +0 -9
- package/src/lib/parseOptionsFromUrl.js +1 -16
- package/src/lib/parseOptionsFromUrl.js.flow +0 -17
- package/src/lib/reporting.d.ts +140 -0
- package/src/lib/reporting.js.flow +0 -1
- package/src/lib/splitBundleOptions.js +0 -1
- package/src/lib/splitBundleOptions.js.flow +0 -1
- package/src/lib/transformHelpers.js +0 -1
- package/src/lib/transformHelpers.js.flow +0 -1
- package/src/node-haste/DependencyGraph/createHasteMap.js +0 -1
- package/src/node-haste/DependencyGraph/createHasteMap.js.flow +0 -1
- package/src/node-haste/DependencyGraph.d.ts +59 -0
- package/src/node-haste/DependencyGraph.js +1 -0
- package/src/node-haste/DependencyGraph.js.flow +1 -0
- package/src/shared/output/RamBundle/as-assets.js +1 -0
- package/src/shared/output/RamBundle/as-assets.js.flow +1 -0
- package/src/shared/output/RamBundle/write-sourcemap.js +1 -0
- package/src/shared/output/RamBundle/write-sourcemap.js.flow +1 -0
- package/src/shared/output/bundle.d.ts +31 -0
- package/src/shared/types.d.ts +138 -0
- package/src/shared/types.flow.js.flow +2 -1
- package/types/Asset.d.ts +25 -0
- package/types/Bundler.d.ts +39 -0
- package/types/DeltaBundler/Graph.d.ts +40 -0
- package/types/DeltaBundler/Serializers/getRamBundleInfo.d.ts +18 -0
- package/types/DeltaBundler/Worker.d.ts +47 -0
- package/types/DeltaBundler/types.d.ts +167 -0
- package/types/DeltaBundler.d.ts +58 -0
- package/types/IncrementalBundler.d.ts +97 -0
- package/types/ModuleGraph/worker/collectDependencies.d.ts +27 -0
- package/types/Server/MultipartResponse.d.ts +31 -0
- package/types/Server.d.ts +113 -0
- package/types/index.d.ts +151 -0
- package/types/lib/CountingSet.d.ts +48 -0
- package/types/lib/TerminalReporter.d.ts +27 -0
- package/types/lib/contextModule.d.ts +22 -0
- package/types/lib/getGraphId.d.ts +11 -0
- package/types/lib/reporting.d.ts +140 -0
- package/types/node-haste/DependencyGraph.d.ts +59 -0
- package/types/shared/output/bundle.d.ts +31 -0
- package/types/shared/types.d.ts +138 -0
- package/src/DeltaBundler/Serializers/baseBytecodeBundle.js +0 -81
- package/src/DeltaBundler/Serializers/baseBytecodeBundle.js.flow +0 -103
- package/src/DeltaBundler/Serializers/helpers/bytecode.js +0 -61
- package/src/DeltaBundler/Serializers/helpers/bytecode.js.flow +0 -75
- package/src/DeltaBundler/Serializers/helpers/processBytecodeModules.js +0 -40
- package/src/DeltaBundler/Serializers/helpers/processBytecodeModules.js.flow +0 -51
- package/src/lib/bundleToBytecode.js +0 -79
- package/src/lib/bundleToBytecode.js.flow +0 -97
|
@@ -0,0 +1,39 @@
|
|
|
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 {TransformResultWithSource} from './DeltaBundler';
|
|
12
|
+
import type {TransformOptions} from './DeltaBundler/Worker';
|
|
13
|
+
import type DependencyGraph from './node-haste/DependencyGraph';
|
|
14
|
+
import type {ConfigT} from 'metro-config';
|
|
15
|
+
import type {EventEmitter} from 'events';
|
|
16
|
+
|
|
17
|
+
export interface BundlerOptions {
|
|
18
|
+
readonly hasReducedPerformance?: boolean;
|
|
19
|
+
readonly watch?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default class Bundler {
|
|
23
|
+
constructor(config: ConfigT, options?: BundlerOptions);
|
|
24
|
+
|
|
25
|
+
getWatcher(): EventEmitter;
|
|
26
|
+
|
|
27
|
+
end(): Promise<void>;
|
|
28
|
+
|
|
29
|
+
getDependencyGraph(): Promise<DependencyGraph>;
|
|
30
|
+
|
|
31
|
+
transformFile(
|
|
32
|
+
filePath: string,
|
|
33
|
+
transformOptions: TransformOptions,
|
|
34
|
+
/** Optionally provide the file contents, this can be used to provide virtual contents for a file. */
|
|
35
|
+
fileBuffer?: Buffer,
|
|
36
|
+
): Promise<TransformResultWithSource<void>>;
|
|
37
|
+
|
|
38
|
+
ready(): Promise<void>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
Dependencies,
|
|
13
|
+
GraphInputOptions,
|
|
14
|
+
MixedOutput,
|
|
15
|
+
Module,
|
|
16
|
+
Options,
|
|
17
|
+
TransformInputOptions,
|
|
18
|
+
} from './types';
|
|
19
|
+
|
|
20
|
+
export interface Result<T> {
|
|
21
|
+
added: Map<string, Module<T>>;
|
|
22
|
+
modified: Map<string, Module<T>>;
|
|
23
|
+
deleted: Set<string>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class Graph<T = MixedOutput> {
|
|
27
|
+
entryPoints: ReadonlySet<string>;
|
|
28
|
+
transformOptions: TransformInputOptions;
|
|
29
|
+
dependencies: Dependencies<T>;
|
|
30
|
+
constructor(options: GraphInputOptions);
|
|
31
|
+
traverseDependencies(
|
|
32
|
+
paths: ReadonlyArray<string>,
|
|
33
|
+
options: Options<T>,
|
|
34
|
+
): Promise<Result<T>>;
|
|
35
|
+
initialTraverseDependencies(options: Options<T>): Promise<Result<T>>;
|
|
36
|
+
markModifiedContextModules(
|
|
37
|
+
filePath: string,
|
|
38
|
+
modifiedPaths: Set<string>,
|
|
39
|
+
): void;
|
|
40
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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 {ModuleTransportLike} from '../../shared/types';
|
|
12
|
+
|
|
13
|
+
export interface RamBundleInfo {
|
|
14
|
+
getDependencies: (filePath: string) => Set<string>;
|
|
15
|
+
startupModules: Readonly<ModuleTransportLike>;
|
|
16
|
+
lazyModules: Readonly<ModuleTransportLike>;
|
|
17
|
+
groups: Map<number, Set<number>>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
JsTransformerConfig,
|
|
13
|
+
JsTransformOptions,
|
|
14
|
+
} from 'metro-transform-worker';
|
|
15
|
+
import type {TransformResult} from './types';
|
|
16
|
+
|
|
17
|
+
type LogEntry = unknown;
|
|
18
|
+
|
|
19
|
+
export type TransformOptions = JsTransformOptions;
|
|
20
|
+
|
|
21
|
+
declare function transform(
|
|
22
|
+
filename: string,
|
|
23
|
+
transformOptions: JsTransformOptions,
|
|
24
|
+
projectRoot: string,
|
|
25
|
+
transformerConfig: TransformerConfig,
|
|
26
|
+
fileBuffer?: Buffer,
|
|
27
|
+
): Promise<Data>;
|
|
28
|
+
|
|
29
|
+
export interface Worker {
|
|
30
|
+
readonly transform: typeof transform;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface TransformerConfig {
|
|
34
|
+
transformerPath: string;
|
|
35
|
+
transformerConfig: JsTransformerConfig;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface Data {
|
|
39
|
+
readonly result: TransformResult<void>;
|
|
40
|
+
readonly sha1: string;
|
|
41
|
+
readonly transformFileStartLogEntry: LogEntry;
|
|
42
|
+
readonly transformFileEndLogEntry: LogEntry;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
declare const worker: Worker;
|
|
46
|
+
|
|
47
|
+
export default worker;
|
|
@@ -0,0 +1,167 @@
|
|
|
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 {SourceLocation} from '@babel/code-frame';
|
|
12
|
+
import type {JsTransformOptions} from 'metro-transform-worker';
|
|
13
|
+
import type {RequireContextParams} from '../ModuleGraph/worker/collectDependencies';
|
|
14
|
+
import type {RequireContext} from '../lib/contextModule';
|
|
15
|
+
import type CountingSet from '../lib/CountingSet';
|
|
16
|
+
import type {Graph} from './Graph';
|
|
17
|
+
|
|
18
|
+
export interface MixedOutput {
|
|
19
|
+
readonly data: {code: string};
|
|
20
|
+
readonly type: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type AsyncDependencyType = 'async' | 'prefetch';
|
|
24
|
+
|
|
25
|
+
export interface TransformResultDependency {
|
|
26
|
+
/**
|
|
27
|
+
* The literal name provided to a require or import call. For example 'foo' in
|
|
28
|
+
* case of `require('foo')`.
|
|
29
|
+
*/
|
|
30
|
+
readonly name: string;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Extra data returned by the dependency extractor.
|
|
34
|
+
*/
|
|
35
|
+
readonly data: {
|
|
36
|
+
/**
|
|
37
|
+
* A locally unique key for this dependency within the current module.
|
|
38
|
+
*/
|
|
39
|
+
readonly key: string;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* If not null, this dependency is due to a dynamic `import()` or `__prefetchImport()` call.
|
|
43
|
+
*/
|
|
44
|
+
readonly asyncType: AsyncDependencyType | null;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The condition for splitting on this dependency edge.
|
|
48
|
+
*/
|
|
49
|
+
readonly splitCondition?: {
|
|
50
|
+
readonly mobileConfigName: string;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The dependency is enclosed in a try/catch block.
|
|
55
|
+
*/
|
|
56
|
+
readonly isOptional?: boolean;
|
|
57
|
+
|
|
58
|
+
readonly locs: ReadonlyArray<SourceLocation>;
|
|
59
|
+
|
|
60
|
+
/** Context for requiring a collection of modules. */
|
|
61
|
+
readonly contextParams?: RequireContextParams;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface Dependency {
|
|
66
|
+
readonly absolutePath: string;
|
|
67
|
+
readonly data: TransformResultDependency;
|
|
68
|
+
[key: string]: unknown;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface Module<T = MixedOutput> {
|
|
72
|
+
readonly dependencies: Map<string, Dependency>;
|
|
73
|
+
readonly inverseDependencies: CountingSet<string>;
|
|
74
|
+
readonly output: ReadonlyArray<T>;
|
|
75
|
+
readonly path: string;
|
|
76
|
+
readonly getSource: () => Buffer;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export type Dependencies<T = MixedOutput> = Map<string, Module<T>>;
|
|
80
|
+
export type ReadOnlyDependencies<T = MixedOutput> = ReadonlyMap<
|
|
81
|
+
string,
|
|
82
|
+
Module<T>
|
|
83
|
+
>;
|
|
84
|
+
|
|
85
|
+
export type TransformInputOptions = Omit<
|
|
86
|
+
JsTransformOptions,
|
|
87
|
+
'inlinePlatform' | 'inlineRequires'
|
|
88
|
+
>;
|
|
89
|
+
|
|
90
|
+
export type GraphInputOptions = Readonly<{
|
|
91
|
+
entryPoints: ReadonlySet<string>;
|
|
92
|
+
// Unused in core but useful for custom serializers / experimentalSerializerHook
|
|
93
|
+
transformOptions: TransformInputOptions;
|
|
94
|
+
}>;
|
|
95
|
+
|
|
96
|
+
export interface ReadOnlyGraph<T = MixedOutput> {
|
|
97
|
+
readonly entryPoints: ReadonlySet<string>;
|
|
98
|
+
// Unused in core but useful for custom serializers / experimentalSerializerHook
|
|
99
|
+
readonly transformOptions: Readonly<TransformInputOptions>;
|
|
100
|
+
readonly dependencies: ReadOnlyDependencies<T>;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export type {Graph};
|
|
104
|
+
|
|
105
|
+
export interface TransformResult<T = MixedOutput> {
|
|
106
|
+
dependencies: ReadonlyArray<TransformResultDependency>;
|
|
107
|
+
output: ReadonlyArray<T>;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface TransformResultWithSource<T = MixedOutput>
|
|
111
|
+
extends TransformResult<T> {
|
|
112
|
+
getSource: () => Buffer;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export type TransformFn<T = MixedOutput> = (
|
|
116
|
+
modulePath: string,
|
|
117
|
+
requireContext: RequireContext | null,
|
|
118
|
+
) => Promise<TransformResultWithSource<T>>;
|
|
119
|
+
|
|
120
|
+
export interface AllowOptionalDependenciesWithOptions {
|
|
121
|
+
readonly exclude: string[];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export type AllowOptionalDependencies =
|
|
125
|
+
| boolean
|
|
126
|
+
| AllowOptionalDependenciesWithOptions;
|
|
127
|
+
|
|
128
|
+
export interface BundlerResolution {
|
|
129
|
+
readonly type: 'sourceFile';
|
|
130
|
+
readonly filePath: string;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export interface Options<T = MixedOutput> {
|
|
134
|
+
readonly resolve: (from: string, to: string) => string;
|
|
135
|
+
readonly transform: TransformFn<T>;
|
|
136
|
+
readonly transformOptions: TransformInputOptions;
|
|
137
|
+
readonly onProgress:
|
|
138
|
+
| ((numProcessed: number, total: number) => unknown)
|
|
139
|
+
| null;
|
|
140
|
+
readonly experimentalImportBundleSupport: boolean;
|
|
141
|
+
readonly unstable_allowRequireContext: boolean;
|
|
142
|
+
readonly shallow: boolean;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export interface DeltaResult<T = MixedOutput> {
|
|
146
|
+
readonly added: Map<string, Module<T>>;
|
|
147
|
+
readonly modified: Map<string, Module<T>>;
|
|
148
|
+
readonly deleted: Set<string>;
|
|
149
|
+
readonly reset: boolean;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export interface SerializerOptions<T = MixedOutput> {
|
|
153
|
+
readonly asyncRequireModulePath: string;
|
|
154
|
+
readonly createModuleId: (filePath: string) => number;
|
|
155
|
+
readonly dev: boolean;
|
|
156
|
+
readonly getRunModuleStatement: (moduleId: string | number) => string;
|
|
157
|
+
readonly includeAsyncPaths: boolean;
|
|
158
|
+
readonly inlineSourceMap?: boolean;
|
|
159
|
+
readonly modulesOnly: boolean;
|
|
160
|
+
readonly processModuleFilter: (module: Module<T>) => boolean;
|
|
161
|
+
readonly projectRoot: string;
|
|
162
|
+
readonly runBeforeMainModule: ReadonlyArray<string>;
|
|
163
|
+
readonly runModule: boolean;
|
|
164
|
+
readonly serverRoot: string;
|
|
165
|
+
readonly sourceMapUrl?: string;
|
|
166
|
+
readonly sourceUrl?: string;
|
|
167
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
DeltaResult,
|
|
13
|
+
Graph,
|
|
14
|
+
MixedOutput,
|
|
15
|
+
Options,
|
|
16
|
+
ReadOnlyGraph,
|
|
17
|
+
} from './DeltaBundler/types';
|
|
18
|
+
import type {EventEmitter} from 'events';
|
|
19
|
+
|
|
20
|
+
export type {
|
|
21
|
+
DeltaResult,
|
|
22
|
+
Graph,
|
|
23
|
+
Dependencies,
|
|
24
|
+
MixedOutput,
|
|
25
|
+
Module,
|
|
26
|
+
ReadOnlyGraph,
|
|
27
|
+
TransformFn,
|
|
28
|
+
TransformResult,
|
|
29
|
+
TransformResultDependency,
|
|
30
|
+
TransformResultWithSource,
|
|
31
|
+
} from './DeltaBundler/types';
|
|
32
|
+
|
|
33
|
+
export default class DeltaBundler<T = MixedOutput> {
|
|
34
|
+
constructor(changeEventSource: EventEmitter);
|
|
35
|
+
end(): void;
|
|
36
|
+
getDependencies(
|
|
37
|
+
entryPoints: ReadonlyArray<string>,
|
|
38
|
+
options: Options<T>,
|
|
39
|
+
): Promise<ReadOnlyGraph<T>['dependencies']>;
|
|
40
|
+
buildGraph(
|
|
41
|
+
entryPoints: ReadonlyArray<string>,
|
|
42
|
+
options: Options<T>,
|
|
43
|
+
): Promise<Graph<T>>;
|
|
44
|
+
|
|
45
|
+
getDelta(
|
|
46
|
+
graph: Graph<T>,
|
|
47
|
+
{
|
|
48
|
+
reset,
|
|
49
|
+
shallow,
|
|
50
|
+
}: {
|
|
51
|
+
reset: boolean;
|
|
52
|
+
shallow: boolean;
|
|
53
|
+
},
|
|
54
|
+
): Promise<DeltaResult<T>>;
|
|
55
|
+
|
|
56
|
+
listen(graph: Graph<T>, callback: () => Promise<void>): () => void;
|
|
57
|
+
endGraph(graph: Graph<T>): void;
|
|
58
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
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
|
+
Options as DeltaBundlerOptions,
|
|
13
|
+
ReadOnlyDependencies,
|
|
14
|
+
TransformInputOptions,
|
|
15
|
+
} from './DeltaBundler/types';
|
|
16
|
+
import {ResolverInputOptions} from './shared/types';
|
|
17
|
+
import type {ConfigT} from 'metro-config';
|
|
18
|
+
import type {GraphId} from './lib/getGraphId';
|
|
19
|
+
import DeltaBundler, {DeltaResult, Graph, Module} from './DeltaBundler';
|
|
20
|
+
import type Bundler from './Bundler';
|
|
21
|
+
|
|
22
|
+
export type RevisionId = string;
|
|
23
|
+
|
|
24
|
+
export type OutputGraph = Graph<void>;
|
|
25
|
+
|
|
26
|
+
export interface OtherOptions {
|
|
27
|
+
readonly onProgress: DeltaBundlerOptions<void>['onProgress'];
|
|
28
|
+
readonly shallow: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface GraphRevision {
|
|
32
|
+
readonly id: RevisionId;
|
|
33
|
+
readonly date: Date;
|
|
34
|
+
readonly graphId: GraphId;
|
|
35
|
+
readonly graph: OutputGraph;
|
|
36
|
+
readonly prepend: ReadonlyArray<Module<void>>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface IncrementalBundlerOptions {
|
|
40
|
+
readonly hasReducedPerformance?: boolean;
|
|
41
|
+
readonly watch?: boolean;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export default class IncrementalBundler {
|
|
45
|
+
static revisionIdFromString: (str: string) => RevisionId;
|
|
46
|
+
constructor(config: ConfigT, options?: IncrementalBundlerOptions);
|
|
47
|
+
|
|
48
|
+
end(): void;
|
|
49
|
+
getBundler(): Bundler;
|
|
50
|
+
getDeltaBundler(): DeltaBundler<void>;
|
|
51
|
+
getRevision(revisionId: RevisionId): Promise<GraphRevision> | null;
|
|
52
|
+
getRevisionByGraphId(graphId: GraphId): Promise<GraphRevision> | null;
|
|
53
|
+
|
|
54
|
+
buildGraphForEntries(
|
|
55
|
+
entryFiles: ReadonlyArray<string>,
|
|
56
|
+
transformOptions: TransformInputOptions,
|
|
57
|
+
resolverOptions: ResolverInputOptions,
|
|
58
|
+
otherOptions?: OtherOptions,
|
|
59
|
+
): Promise<OutputGraph>;
|
|
60
|
+
|
|
61
|
+
getDependencies(
|
|
62
|
+
entryFiles: ReadonlyArray<string>,
|
|
63
|
+
transformOptions: TransformInputOptions,
|
|
64
|
+
resolverOptions: ResolverInputOptions,
|
|
65
|
+
otherOptions?: OtherOptions,
|
|
66
|
+
): Promise<ReadOnlyDependencies<void>>;
|
|
67
|
+
|
|
68
|
+
buildGraph(
|
|
69
|
+
entryFile: string,
|
|
70
|
+
transformOptions: TransformInputOptions,
|
|
71
|
+
resolverOptions: ResolverInputOptions,
|
|
72
|
+
otherOptions?: OtherOptions,
|
|
73
|
+
): Promise<
|
|
74
|
+
Readonly<{graph: OutputGraph; prepend: ReadonlyArray<Module<void>>}>
|
|
75
|
+
>;
|
|
76
|
+
|
|
77
|
+
initializeGraph(
|
|
78
|
+
entryFile: string,
|
|
79
|
+
transformOptions: TransformInputOptions,
|
|
80
|
+
resolverOptions: ResolverInputOptions,
|
|
81
|
+
otherOptions?: OtherOptions,
|
|
82
|
+
): Promise<{
|
|
83
|
+
delta: DeltaResult<void>;
|
|
84
|
+
revision: GraphRevision;
|
|
85
|
+
}>;
|
|
86
|
+
|
|
87
|
+
updateGraph(
|
|
88
|
+
revision: GraphRevision,
|
|
89
|
+
reset: boolean,
|
|
90
|
+
): Promise<{
|
|
91
|
+
delta: DeltaResult<void>;
|
|
92
|
+
revision: GraphRevision;
|
|
93
|
+
}>;
|
|
94
|
+
|
|
95
|
+
endGraph(graphId: GraphId): Promise<void>;
|
|
96
|
+
ready(): Promise<void>;
|
|
97
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
export type ContextMode = 'sync' | 'eager' | 'lazy' | 'lazy-once';
|
|
12
|
+
|
|
13
|
+
export interface ContextFilter {
|
|
14
|
+
pattern: string;
|
|
15
|
+
flags: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface RequireContextParams {
|
|
19
|
+
/* Should search for files recursively. Optional, default `true` when `require.context` is used */
|
|
20
|
+
readonly recursive: boolean;
|
|
21
|
+
/* Filename filter pattern for use in `require.context`. Optional, default `.*` (any file) when `require.context` is used */
|
|
22
|
+
readonly filter: Readonly<ContextFilter>;
|
|
23
|
+
/** Mode for resolving dynamic dependencies. Defaults to `sync` */
|
|
24
|
+
readonly mode: ContextMode;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type DynamicRequiresBehavior = 'throwAtRuntime' | 'reject';
|
|
@@ -0,0 +1,31 @@
|
|
|
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 {IncomingMessage, ServerResponse} from 'http';
|
|
12
|
+
|
|
13
|
+
export type Data = string | Buffer | Uint8Array;
|
|
14
|
+
export interface Headers {
|
|
15
|
+
[name: string]: string | number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default class MultipartResponse {
|
|
19
|
+
static wrapIfSupported(
|
|
20
|
+
req: IncomingMessage,
|
|
21
|
+
res: ServerResponse,
|
|
22
|
+
): MultipartResponse | ServerResponse;
|
|
23
|
+
static serializeHeaders(headers: Headers): string;
|
|
24
|
+
res: ServerResponse;
|
|
25
|
+
headers: Headers;
|
|
26
|
+
constructor(res: ServerResponse);
|
|
27
|
+
writeChunk(headers: Headers | null, data?: Data, isLast?: boolean): void;
|
|
28
|
+
writeHead(status: number, headers?: Headers): void;
|
|
29
|
+
setHeader(name: string, value: string | number): void;
|
|
30
|
+
end(data?: Data): void;
|
|
31
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
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 {AssetData} from './Asset';
|
|
12
|
+
import type {RamBundleInfo} from './DeltaBundler/Serializers/getRamBundleInfo';
|
|
13
|
+
import IncrementalBundler, {RevisionId} from './IncrementalBundler';
|
|
14
|
+
import type {GraphId} from './lib/getGraphId';
|
|
15
|
+
import type MultipartResponse from './Server/MultipartResponse';
|
|
16
|
+
import type {
|
|
17
|
+
BundleOptions,
|
|
18
|
+
GraphOptions,
|
|
19
|
+
SplitBundleOptions,
|
|
20
|
+
} from './shared/types';
|
|
21
|
+
import type {IncomingMessage, ServerResponse} from 'http';
|
|
22
|
+
import type {
|
|
23
|
+
CustomTransformOptions,
|
|
24
|
+
TransformProfile,
|
|
25
|
+
} from 'metro-babel-transformer';
|
|
26
|
+
import type {ConfigT, RootPerfLogger} from 'metro-config';
|
|
27
|
+
import type {CustomResolverOptions} from 'metro-resolver';
|
|
28
|
+
|
|
29
|
+
export interface SegmentLoadData {
|
|
30
|
+
[index: number]: [number[], number | null];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface BundleMetadata {
|
|
34
|
+
hash: string;
|
|
35
|
+
otaBuildNumber: string | null;
|
|
36
|
+
mobileConfigs: string[];
|
|
37
|
+
segmentHashes: string[];
|
|
38
|
+
segmentLoadData: SegmentLoadData;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ProcessStartContext extends SplitBundleOptions {
|
|
42
|
+
readonly buildNumber: number;
|
|
43
|
+
readonly bundleOptions: BundleOptions;
|
|
44
|
+
readonly graphId: GraphId;
|
|
45
|
+
readonly graphOptions: GraphOptions;
|
|
46
|
+
readonly mres: MultipartResponse | ServerResponse;
|
|
47
|
+
readonly req: IncomingMessage;
|
|
48
|
+
readonly revisionId?: RevisionId | null;
|
|
49
|
+
readonly bundlePerfLogger: RootPerfLogger;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface ProcessDeleteContext {
|
|
53
|
+
readonly graphId: GraphId;
|
|
54
|
+
readonly req: IncomingMessage;
|
|
55
|
+
readonly res: ServerResponse;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface ProcessEndContext<T> extends ProcessStartContext {
|
|
59
|
+
readonly result: T;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export type ServerOptions = Readonly<{
|
|
63
|
+
hasReducedPerformance?: boolean;
|
|
64
|
+
onBundleBuilt?: (bundlePath: string) => void;
|
|
65
|
+
watch?: boolean;
|
|
66
|
+
}>;
|
|
67
|
+
|
|
68
|
+
export interface DefaultGraphOptions {
|
|
69
|
+
customResolverOptions: CustomResolverOptions;
|
|
70
|
+
customTransformOptions: CustomTransformOptions;
|
|
71
|
+
dev: boolean;
|
|
72
|
+
hot: boolean;
|
|
73
|
+
minify: boolean;
|
|
74
|
+
runtimeBytecodeVersion?: number;
|
|
75
|
+
unstable_transformProfile: TransformProfile;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface DefaultBundleOptions extends DefaultGraphOptions {
|
|
79
|
+
excludeSource: false;
|
|
80
|
+
inlineSourceMap: false;
|
|
81
|
+
modulesOnly: false;
|
|
82
|
+
onProgress: null;
|
|
83
|
+
runModule: true;
|
|
84
|
+
shallow: false;
|
|
85
|
+
sourceMapUrl: null;
|
|
86
|
+
sourceUrl: null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export default class Server {
|
|
90
|
+
static DEFAULT_GRAPH_OPTIONS: DefaultGraphOptions;
|
|
91
|
+
static DEFAULT_BUNDLE_OPTIONS: BundleOptions;
|
|
92
|
+
constructor(config: ConfigT, options?: ServerOptions);
|
|
93
|
+
end(): void;
|
|
94
|
+
getBundler(): IncrementalBundler;
|
|
95
|
+
getCreateModuleId(): (path: string) => number;
|
|
96
|
+
build(options: BundleOptions): Promise<{
|
|
97
|
+
code: string;
|
|
98
|
+
map: string;
|
|
99
|
+
}>;
|
|
100
|
+
getRamBundleInfo(options: BundleOptions): Promise<RamBundleInfo>;
|
|
101
|
+
getAssets(options: BundleOptions): Promise<ReadonlyArray<AssetData>>;
|
|
102
|
+
getOrderedDependencyPaths(options: {
|
|
103
|
+
readonly dev: boolean;
|
|
104
|
+
readonly entryFile: string;
|
|
105
|
+
readonly minify: boolean;
|
|
106
|
+
readonly platform: string;
|
|
107
|
+
}): Promise<string[]>;
|
|
108
|
+
processRequest(
|
|
109
|
+
IncomingMessage: IncomingMessage,
|
|
110
|
+
ServerResponse: ServerResponse,
|
|
111
|
+
next: (e: Error | null) => unknown,
|
|
112
|
+
): void;
|
|
113
|
+
}
|