metro 0.84.0 → 0.84.2
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 +15 -14
- package/src/Assets.d.ts +90 -0
- package/src/Bundler/util.d.ts +34 -0
- package/src/Bundler.d.ts +45 -0
- package/src/DeltaBundler/DeltaCalculator.d.ts +78 -0
- package/src/DeltaBundler/Graph.d.ts +174 -0
- package/src/DeltaBundler/Serializers/baseJSBundle.d.ts +27 -0
- package/src/DeltaBundler/Serializers/getAllFiles.d.ts +29 -0
- package/src/DeltaBundler/Serializers/getAssets.d.ts +32 -0
- package/src/DeltaBundler/Serializers/getExplodedSourceMap.d.ts +33 -0
- package/src/DeltaBundler/Serializers/getRamBundleInfo.d.ts +55 -0
- package/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.d.ts +19 -0
- package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.d.ts +40 -0
- package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.d.ts +24 -0
- package/src/DeltaBundler/Serializers/helpers/js.d.ts +37 -0
- package/src/DeltaBundler/Serializers/helpers/processModules.d.ts +32 -0
- package/src/DeltaBundler/Serializers/hmrJSBundle.d.ts +37 -0
- package/src/DeltaBundler/Serializers/sourceMapGenerator.d.ts +36 -0
- package/src/DeltaBundler/Serializers/sourceMapObject.d.ts +30 -0
- package/src/DeltaBundler/Serializers/sourceMapString.d.ts +29 -0
- package/src/DeltaBundler/Transformer.d.ts +45 -0
- package/src/DeltaBundler/Worker.d.ts +44 -0
- package/src/DeltaBundler/WorkerFarm.d.ts +77 -0
- package/src/DeltaBundler/buildSubgraph.d.ts +37 -0
- package/src/DeltaBundler/getTransformCacheKey.d.ts +25 -0
- package/src/DeltaBundler/mergeDeltas.d.ts +24 -0
- package/src/DeltaBundler/types.d.ts +170 -0
- package/src/DeltaBundler.d.ts +67 -0
- package/src/HmrServer.d.ts +86 -0
- package/src/IncrementalBundler/GraphNotFoundError.d.ts +24 -0
- package/src/IncrementalBundler/ResourceNotFoundError.d.ts +22 -0
- package/src/IncrementalBundler/RevisionNotFoundError.d.ts +24 -0
- package/src/IncrementalBundler.d.ts +103 -0
- package/src/ModuleGraph/worker/JsFileWrapping.d.ts +36 -0
- package/src/ModuleGraph/worker/collectDependencies.d.ts +138 -0
- package/src/ModuleGraph/worker/generateImportNames.d.ts +26 -0
- package/src/ModuleGraph/worker/importLocationsPlugin.d.ts +33 -0
- package/src/Server/MultipartResponse.d.ts +37 -0
- package/src/Server/symbolicate.d.ts +38 -0
- package/src/Server.d.ts +278 -0
- package/src/Server.js +10 -6
- package/src/Server.js.flow +9 -10
- package/src/cli/parseKeyValueParamArray.d.ts +21 -0
- package/src/cli-utils.d.ts +26 -0
- package/src/commands/build.d.ts +23 -0
- package/src/commands/dependencies.d.ts +23 -0
- package/src/commands/serve.d.ts +23 -0
- package/src/index.d.ts +187 -0
- package/src/index.flow.js +24 -10
- package/src/index.flow.js.flow +25 -10
- package/src/lib/BatchProcessor.d.ts +61 -0
- package/src/lib/CountingSet.d.ts +55 -0
- package/src/lib/JsonReporter.d.ts +44 -0
- package/src/lib/RamBundleParser.d.ts +36 -0
- package/src/lib/TerminalReporter.d.ts +125 -0
- package/src/lib/TerminalReporter.js +6 -7
- package/src/lib/TerminalReporter.js.flow +6 -15
- package/src/lib/bundleProgressUtils.d.ts +33 -0
- package/src/lib/bundleProgressUtils.js +19 -0
- package/src/lib/bundleProgressUtils.js.flow +35 -0
- package/src/lib/bundleToString.d.ts +26 -0
- package/src/lib/contextModule.d.ts +40 -0
- package/src/lib/contextModuleTemplates.d.ts +32 -0
- package/src/lib/countLines.d.ts +19 -0
- package/src/lib/createWebsocketServer.d.ts +50 -0
- package/src/lib/debounceAsyncQueue.d.ts +22 -0
- package/src/lib/formatBundlingError.d.ts +30 -0
- package/src/lib/getAppendScripts.d.ts +38 -0
- package/src/lib/getGraphId.d.ts +32 -0
- package/src/lib/getPreludeCode.d.ts +25 -0
- package/src/lib/getPrependedScripts.d.ts +31 -0
- package/src/lib/isResolvedDependency.d.ts +22 -0
- package/src/lib/logToConsole.d.ts +26 -0
- package/src/lib/parseBundleOptionsFromBundleRequestUrl.d.ts +24 -0
- package/src/lib/parseCustomResolverOptions.d.ts +23 -0
- package/src/lib/parseCustomTransformOptions.d.ts +23 -0
- package/src/lib/parseJsonBody.d.ts +34 -0
- package/src/lib/pathUtils.d.ts +21 -0
- package/src/lib/relativizeSourceMap.d.ts +24 -0
- package/src/lib/reporting.d.ts +135 -0
- package/src/lib/splitBundleOptions.d.ts +23 -0
- package/src/lib/transformHelpers.d.ts +42 -0
- package/src/node-haste/DependencyGraph/ModuleResolution.d.ts +133 -0
- package/src/node-haste/DependencyGraph/createFileMap.d.ts +36 -0
- package/src/node-haste/DependencyGraph.d.ts +93 -0
- package/src/node-haste/Package.d.ts +28 -0
- package/src/node-haste/PackageCache.d.ts +41 -0
- package/src/node-haste/lib/AssetPaths.d.ts +36 -0
- package/src/node-haste/lib/parsePlatformFilePath.d.ts +32 -0
- package/src/shared/output/RamBundle/as-assets.d.ts +32 -0
- package/src/shared/output/RamBundle/as-indexed-file.d.ts +45 -0
- package/src/shared/output/RamBundle/buildSourcemapWithMetadata.d.ts +30 -0
- package/src/shared/output/RamBundle/magic-number.d.ts +21 -0
- package/src/shared/output/RamBundle/util.d.ts +48 -0
- package/src/shared/output/RamBundle/write-sourcemap.d.ts +23 -0
- package/src/shared/output/RamBundle.d.ts +33 -0
- package/src/shared/output/bundle.d.ts +34 -0
- package/src/shared/output/meta.d.ts +22 -0
- package/src/shared/output/unbundle.d.ts +18 -0
- package/src/shared/output/writeFile.d.ts +23 -0
- package/src/shared/types.d.ts +152 -0
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
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
|
+
* @noformat
|
|
8
|
+
* @oncall react_native
|
|
9
|
+
* @generated SignedSource<<6246e792b8fc5f3e524f443a31921cfc>>
|
|
10
|
+
*
|
|
11
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
12
|
+
* Original file: packages/metro/src/index.flow.js
|
|
13
|
+
* To regenerate, run:
|
|
14
|
+
* js1 build metro-ts-defs (internal) OR
|
|
15
|
+
* yarn run build-ts-defs (OSS)
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type {AssetData} from './Assets';
|
|
19
|
+
import type {ReadOnlyGraph} from './DeltaBundler';
|
|
20
|
+
import type {ServerOptions} from './Server';
|
|
21
|
+
import type {BuildOptions, OutputOptions, RequestOptions} from './shared/types';
|
|
22
|
+
import type {HandleFunction} from 'connect';
|
|
23
|
+
import type {Server as HttpServer} from 'http';
|
|
24
|
+
import type {
|
|
25
|
+
Server as HttpsServer,
|
|
26
|
+
ServerOptions as HttpsServerOptions,
|
|
27
|
+
} from 'https';
|
|
28
|
+
import type {TransformProfile} from 'metro-babel-transformer';
|
|
29
|
+
import type {
|
|
30
|
+
ConfigT,
|
|
31
|
+
InputConfigT,
|
|
32
|
+
MetroConfig,
|
|
33
|
+
Middleware,
|
|
34
|
+
} from 'metro-config';
|
|
35
|
+
import type {CustomResolverOptions} from 'metro-resolver';
|
|
36
|
+
import type {CustomTransformOptions} from 'metro-transform-worker';
|
|
37
|
+
import type {Server as WebSocketServer} from 'ws';
|
|
38
|
+
import type $$IMPORT_TYPEOF_1$$ from 'yargs';
|
|
39
|
+
|
|
40
|
+
import JsonReporter from './lib/JsonReporter';
|
|
41
|
+
import TerminalReporter from './lib/TerminalReporter';
|
|
42
|
+
import MetroServer from './Server';
|
|
43
|
+
import {loadConfig, mergeConfig, resolveConfig} from 'metro-config';
|
|
44
|
+
import {Terminal} from 'metro-core';
|
|
45
|
+
|
|
46
|
+
type Yargs = typeof $$IMPORT_TYPEOF_1$$;
|
|
47
|
+
type MetroMiddleWare = {
|
|
48
|
+
attachHmrServer: (httpServer: HttpServer | HttpsServer) => void;
|
|
49
|
+
end: () => Promise<void>;
|
|
50
|
+
metroServer: MetroServer;
|
|
51
|
+
middleware: Middleware;
|
|
52
|
+
};
|
|
53
|
+
export type RunMetroOptions = Omit<
|
|
54
|
+
ServerOptions,
|
|
55
|
+
keyof {waitForBundler?: boolean}
|
|
56
|
+
> & {waitForBundler?: boolean};
|
|
57
|
+
export type RunServerOptions = Readonly<{
|
|
58
|
+
hasReducedPerformance?: boolean;
|
|
59
|
+
host?: string;
|
|
60
|
+
onError?: ($$PARAM_0$$: Error & {code?: string}) => void;
|
|
61
|
+
onReady?: (server: HttpServer | HttpsServer) => void;
|
|
62
|
+
onClose?: () => void;
|
|
63
|
+
secureServerOptions?: HttpsServerOptions;
|
|
64
|
+
secure?: boolean;
|
|
65
|
+
secureCert?: string;
|
|
66
|
+
secureKey?: string;
|
|
67
|
+
unstable_extraMiddleware?: ReadonlyArray<HandleFunction>;
|
|
68
|
+
waitForBundler?: boolean;
|
|
69
|
+
watch?: boolean;
|
|
70
|
+
websocketEndpoints?: Readonly<{[path: string]: WebSocketServer}>;
|
|
71
|
+
}>;
|
|
72
|
+
export type RunServerResult = {httpServer: HttpServer | HttpsServer};
|
|
73
|
+
type BuildGraphOptions = {
|
|
74
|
+
entries: ReadonlyArray<string>;
|
|
75
|
+
customTransformOptions?: CustomTransformOptions;
|
|
76
|
+
dev?: boolean;
|
|
77
|
+
minify?: boolean;
|
|
78
|
+
onProgress?: (transformedFileCount: number, totalFileCount: number) => void;
|
|
79
|
+
platform?: string;
|
|
80
|
+
type?: 'module' | 'script';
|
|
81
|
+
};
|
|
82
|
+
export type RunBuildOptions = {
|
|
83
|
+
entry: string;
|
|
84
|
+
assets?: boolean;
|
|
85
|
+
dev?: boolean;
|
|
86
|
+
out?: string;
|
|
87
|
+
bundleOut?: string;
|
|
88
|
+
sourceMapOut?: string;
|
|
89
|
+
onBegin?: () => void;
|
|
90
|
+
onComplete?: () => void;
|
|
91
|
+
onProgress?: (transformedFileCount: number, totalFileCount: number) => void;
|
|
92
|
+
minify?: boolean;
|
|
93
|
+
output?: Readonly<{
|
|
94
|
+
build: (
|
|
95
|
+
$$PARAM_0$$: MetroServer,
|
|
96
|
+
$$PARAM_1$$: RequestOptions,
|
|
97
|
+
$$PARAM_2$$: void | BuildOptions,
|
|
98
|
+
) => Promise<{
|
|
99
|
+
code: string;
|
|
100
|
+
map: string;
|
|
101
|
+
assets?: ReadonlyArray<AssetData>;
|
|
102
|
+
}>;
|
|
103
|
+
save: (
|
|
104
|
+
$$PARAM_0$$: {code: string; map: string},
|
|
105
|
+
$$PARAM_1$$: OutputOptions,
|
|
106
|
+
$$PARAM_2$$: (logMessage: string) => void,
|
|
107
|
+
) => Promise<unknown>;
|
|
108
|
+
}>;
|
|
109
|
+
platform?: string;
|
|
110
|
+
sourceMap?: boolean;
|
|
111
|
+
sourceMapUrl?: string;
|
|
112
|
+
customResolverOptions?: CustomResolverOptions;
|
|
113
|
+
customTransformOptions?: CustomTransformOptions;
|
|
114
|
+
unstable_transformProfile?: TransformProfile;
|
|
115
|
+
};
|
|
116
|
+
export type RunBuildResult = {
|
|
117
|
+
code: string;
|
|
118
|
+
map: string;
|
|
119
|
+
assets?: ReadonlyArray<AssetData>;
|
|
120
|
+
};
|
|
121
|
+
type BuildCommandOptions = Readonly<{[$$Key$$: string]: unknown}> | null;
|
|
122
|
+
type ServeCommandOptions = Readonly<{[$$Key$$: string]: unknown}> | null;
|
|
123
|
+
type DependenciesCommandOptions = Readonly<{
|
|
124
|
+
[$$Key$$: string]: unknown;
|
|
125
|
+
}> | null;
|
|
126
|
+
export {Terminal, JsonReporter, TerminalReporter};
|
|
127
|
+
export type {AssetData} from './Assets';
|
|
128
|
+
export type {Reporter, ReportableEvent} from './lib/reporting';
|
|
129
|
+
export type {TerminalReportableEvent} from './lib/TerminalReporter';
|
|
130
|
+
export type {MetroConfig};
|
|
131
|
+
export declare function runMetro(
|
|
132
|
+
config: InputConfigT,
|
|
133
|
+
options?: RunMetroOptions,
|
|
134
|
+
): Promise<MetroServer>;
|
|
135
|
+
export {loadConfig, mergeConfig, resolveConfig};
|
|
136
|
+
export declare const createConnectMiddleware: (
|
|
137
|
+
config: ConfigT,
|
|
138
|
+
options?: RunMetroOptions,
|
|
139
|
+
) => Promise<MetroMiddleWare>;
|
|
140
|
+
export declare type createConnectMiddleware = typeof createConnectMiddleware;
|
|
141
|
+
export declare const runServer: (
|
|
142
|
+
config: ConfigT,
|
|
143
|
+
$$PARAM_1$$?: RunServerOptions,
|
|
144
|
+
) => Promise<RunServerResult>;
|
|
145
|
+
export declare type runServer = typeof runServer;
|
|
146
|
+
export declare const runBuild: (
|
|
147
|
+
config: ConfigT,
|
|
148
|
+
$$PARAM_1$$: RunBuildOptions,
|
|
149
|
+
) => Promise<RunBuildResult>;
|
|
150
|
+
export declare type runBuild = typeof runBuild;
|
|
151
|
+
export declare const buildGraph: (
|
|
152
|
+
config: InputConfigT,
|
|
153
|
+
$$PARAM_1$$: BuildGraphOptions,
|
|
154
|
+
) => Promise<ReadOnlyGraph>;
|
|
155
|
+
export declare type buildGraph = typeof buildGraph;
|
|
156
|
+
type AttachMetroCLIOptions = {
|
|
157
|
+
build?: BuildCommandOptions;
|
|
158
|
+
serve?: ServeCommandOptions;
|
|
159
|
+
dependencies?: DependenciesCommandOptions;
|
|
160
|
+
};
|
|
161
|
+
export declare const attachMetroCli: (
|
|
162
|
+
yargs: Yargs,
|
|
163
|
+
options?: AttachMetroCLIOptions,
|
|
164
|
+
) => Yargs;
|
|
165
|
+
export declare type attachMetroCli = typeof attachMetroCli;
|
|
166
|
+
/**
|
|
167
|
+
* Backwards-compatibility with CommonJS consumers using interopRequireDefault.
|
|
168
|
+
* Do not add to this list.
|
|
169
|
+
*
|
|
170
|
+
* @deprecated Default import from 'metro' is deprecated, use named exports.
|
|
171
|
+
*/
|
|
172
|
+
declare const $$EXPORT_DEFAULT_DECLARATION$$: {
|
|
173
|
+
attachMetroCli: typeof attachMetroCli;
|
|
174
|
+
runServer: typeof runServer;
|
|
175
|
+
Terminal: typeof Terminal;
|
|
176
|
+
JsonReporter: typeof JsonReporter;
|
|
177
|
+
TerminalReporter: typeof TerminalReporter;
|
|
178
|
+
loadConfig: typeof loadConfig;
|
|
179
|
+
mergeConfig: typeof mergeConfig;
|
|
180
|
+
resolveConfig: typeof resolveConfig;
|
|
181
|
+
createConnectMiddleware: typeof createConnectMiddleware;
|
|
182
|
+
runBuild: typeof runBuild;
|
|
183
|
+
buildGraph: typeof buildGraph;
|
|
184
|
+
};
|
|
185
|
+
declare type $$EXPORT_DEFAULT_DECLARATION$$ =
|
|
186
|
+
typeof $$EXPORT_DEFAULT_DECLARATION$$;
|
|
187
|
+
export default $$EXPORT_DEFAULT_DECLARATION$$;
|
package/src/index.flow.js
CHANGED
|
@@ -204,7 +204,7 @@ const runServer = async (
|
|
|
204
204
|
_chalk.default.inverse.yellow.bold(" DEPRECATED "),
|
|
205
205
|
"The `secure`, `secureCert`, and `secureKey` options are now deprecated. " +
|
|
206
206
|
"Please use the `secureServerOptions` object instead to pass options to " +
|
|
207
|
-
"Metro's https development server.",
|
|
207
|
+
"Metro's https development server, or `config.server.tls` in Metro's configuration",
|
|
208
208
|
);
|
|
209
209
|
}
|
|
210
210
|
const connect = require("connect");
|
|
@@ -223,15 +223,29 @@ const runServer = async (
|
|
|
223
223
|
}
|
|
224
224
|
serverApp.use(middleware);
|
|
225
225
|
let httpServer;
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
226
|
+
const { tls } = config.server;
|
|
227
|
+
if (
|
|
228
|
+
secure === true ||
|
|
229
|
+
secureServerOptions != null ||
|
|
230
|
+
typeof tls === "object"
|
|
231
|
+
) {
|
|
232
|
+
const options = {
|
|
233
|
+
key:
|
|
234
|
+
typeof tls === "object"
|
|
235
|
+
? tls.key
|
|
236
|
+
: typeof secureKey === "string"
|
|
237
|
+
? _fs.default.readFileSync(secureKey)
|
|
238
|
+
: undefined,
|
|
239
|
+
cert:
|
|
240
|
+
typeof tls === "object"
|
|
241
|
+
? tls.cert
|
|
242
|
+
: typeof secureCert === "string"
|
|
243
|
+
? _fs.default.readFileSync(secureCert)
|
|
244
|
+
: undefined,
|
|
245
|
+
ca: typeof tls === "object" ? tls.ca : undefined,
|
|
246
|
+
requestCert: typeof tls === "object" ? tls.requestCert : undefined,
|
|
247
|
+
...(secureServerOptions ?? {}),
|
|
248
|
+
};
|
|
235
249
|
httpServer = _https.default.createServer(options, serverApp);
|
|
236
250
|
} else {
|
|
237
251
|
httpServer = _http.default.createServer(serverApp);
|
package/src/index.flow.js.flow
CHANGED
|
@@ -280,7 +280,7 @@ export const runServer = async (
|
|
|
280
280
|
chalk.inverse.yellow.bold(' DEPRECATED '),
|
|
281
281
|
'The `secure`, `secureCert`, and `secureKey` options are now deprecated. ' +
|
|
282
282
|
'Please use the `secureServerOptions` object instead to pass options to ' +
|
|
283
|
-
"Metro's https development server.",
|
|
283
|
+
"Metro's https development server, or `config.server.tls` in Metro's configuration",
|
|
284
284
|
);
|
|
285
285
|
}
|
|
286
286
|
// Lazy require
|
|
@@ -307,15 +307,30 @@ export const runServer = async (
|
|
|
307
307
|
|
|
308
308
|
let httpServer;
|
|
309
309
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
310
|
+
const {tls} = config.server;
|
|
311
|
+
if (
|
|
312
|
+
secure === true ||
|
|
313
|
+
secureServerOptions != null ||
|
|
314
|
+
typeof tls === 'object'
|
|
315
|
+
) {
|
|
316
|
+
const options = {
|
|
317
|
+
key:
|
|
318
|
+
typeof tls === 'object'
|
|
319
|
+
? tls.key
|
|
320
|
+
: typeof secureKey === 'string'
|
|
321
|
+
? fs.readFileSync(secureKey)
|
|
322
|
+
: undefined,
|
|
323
|
+
cert:
|
|
324
|
+
typeof tls === 'object'
|
|
325
|
+
? tls.cert
|
|
326
|
+
: typeof secureCert === 'string'
|
|
327
|
+
? fs.readFileSync(secureCert)
|
|
328
|
+
: undefined,
|
|
329
|
+
ca: typeof tls === 'object' ? tls.ca : undefined,
|
|
330
|
+
requestCert: typeof tls === 'object' ? tls.requestCert : undefined,
|
|
331
|
+
...(secureServerOptions ?? {}),
|
|
332
|
+
};
|
|
333
|
+
|
|
319
334
|
// $FlowFixMe[incompatible-type] 'http' and 'https' Flow types do not match
|
|
320
335
|
httpServer = https.createServer(options, serverApp);
|
|
321
336
|
} else {
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
* @noformat
|
|
8
|
+
* @oncall react_native
|
|
9
|
+
* @generated SignedSource<<5872ab26db1c8f4499c971170c5012c4>>
|
|
10
|
+
*
|
|
11
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
12
|
+
* Original file: packages/metro/src/lib/BatchProcessor.js
|
|
13
|
+
* To regenerate, run:
|
|
14
|
+
* js1 build metro-ts-defs (internal) OR
|
|
15
|
+
* yarn run build-ts-defs (OSS)
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import {setTimeout} from 'timers';
|
|
19
|
+
|
|
20
|
+
type ProcessBatch<TItem, TResult> = (
|
|
21
|
+
batch: Array<TItem>,
|
|
22
|
+
) => Promise<Array<TResult>>;
|
|
23
|
+
type BatchProcessorOptions = {
|
|
24
|
+
maximumDelayMs: number;
|
|
25
|
+
maximumItems: number;
|
|
26
|
+
concurrency: number;
|
|
27
|
+
};
|
|
28
|
+
type QueueItem<TItem, TResult> = {
|
|
29
|
+
item: TItem;
|
|
30
|
+
reject: (error: unknown) => unknown;
|
|
31
|
+
resolve: (result: TResult) => unknown;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* We batch items together trying to minimize their processing, for example as
|
|
35
|
+
* network queries. For that we wait a small moment before processing a batch.
|
|
36
|
+
* We limit also the number of items we try to process in a single batch so that
|
|
37
|
+
* if we have many items pending in a short amount of time, we can start
|
|
38
|
+
* processing right away.
|
|
39
|
+
*/
|
|
40
|
+
declare class BatchProcessor<TItem, TResult> {
|
|
41
|
+
_currentProcessCount: number;
|
|
42
|
+
_options: BatchProcessorOptions;
|
|
43
|
+
_processBatch: ProcessBatch<TItem, TResult>;
|
|
44
|
+
_queue: Array<QueueItem<TItem, TResult>>;
|
|
45
|
+
_timeoutHandle: null | undefined | ReturnType<typeof setTimeout>;
|
|
46
|
+
constructor(
|
|
47
|
+
options: BatchProcessorOptions,
|
|
48
|
+
processBatch: ProcessBatch<TItem, TResult>,
|
|
49
|
+
);
|
|
50
|
+
_onBatchFinished(): void;
|
|
51
|
+
_onBatchResults(
|
|
52
|
+
jobs: Array<QueueItem<TItem, TResult>>,
|
|
53
|
+
results: Array<TResult>,
|
|
54
|
+
): void;
|
|
55
|
+
_onBatchError(jobs: Array<QueueItem<TItem, TResult>>, error: unknown): void;
|
|
56
|
+
_processQueue(): void;
|
|
57
|
+
_processQueueOnceReady(): void;
|
|
58
|
+
queue(item: TItem): Promise<TResult>;
|
|
59
|
+
getQueueLength(): number;
|
|
60
|
+
}
|
|
61
|
+
export default BatchProcessor;
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
* @noformat
|
|
8
|
+
* @oncall react_native
|
|
9
|
+
* @generated SignedSource<<0fccda5d7f0eb38539316fa1fedae97b>>
|
|
10
|
+
*
|
|
11
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
12
|
+
* Original file: packages/metro/src/lib/CountingSet.js
|
|
13
|
+
* To regenerate, run:
|
|
14
|
+
* js1 build metro-ts-defs (internal) OR
|
|
15
|
+
* yarn run build-ts-defs (OSS)
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export interface ReadOnlyCountingSet<T> extends Iterable<T> {
|
|
19
|
+
has(item: T): boolean;
|
|
20
|
+
readonly size: number;
|
|
21
|
+
count(item: T): number;
|
|
22
|
+
forEach<ThisT>(
|
|
23
|
+
callbackFn: (
|
|
24
|
+
this: ThisT,
|
|
25
|
+
value: T,
|
|
26
|
+
key: T,
|
|
27
|
+
set: ReadOnlyCountingSet<T>,
|
|
28
|
+
) => unknown,
|
|
29
|
+
thisArg: ThisT,
|
|
30
|
+
): void;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A Set that only deletes a given item when the number of delete(item) calls
|
|
34
|
+
* matches the number of add(item) calls. Iteration and `size` are in terms of
|
|
35
|
+
* *unique* items.
|
|
36
|
+
*/
|
|
37
|
+
declare class CountingSet<T> implements ReadOnlyCountingSet<T> {
|
|
38
|
+
constructor(items?: Iterable<T>);
|
|
39
|
+
has(item: T): boolean;
|
|
40
|
+
add(item: T): void;
|
|
41
|
+
delete(item: T): void;
|
|
42
|
+
keys(): Iterator<T>;
|
|
43
|
+
values(): Iterator<T>;
|
|
44
|
+
entries(): Iterator<[T, T]>;
|
|
45
|
+
[Symbol.iterator](): Iterator<T>;
|
|
46
|
+
get size(): number;
|
|
47
|
+
count(item: T): number;
|
|
48
|
+
clear(): void;
|
|
49
|
+
forEach<ThisT>(
|
|
50
|
+
callbackFn: (this: ThisT, value: T, key: T, set: CountingSet<T>) => unknown,
|
|
51
|
+
thisArg: ThisT,
|
|
52
|
+
): void;
|
|
53
|
+
toJSON(): unknown;
|
|
54
|
+
}
|
|
55
|
+
export default CountingSet;
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
* @noformat
|
|
8
|
+
* @oncall react_native
|
|
9
|
+
* @generated SignedSource<<e7173f8dc5e076fd37b9a1cecd581f58>>
|
|
10
|
+
*
|
|
11
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
12
|
+
* Original file: packages/metro/src/lib/JsonReporter.js
|
|
13
|
+
* To regenerate, run:
|
|
14
|
+
* js1 build metro-ts-defs (internal) OR
|
|
15
|
+
* yarn run build-ts-defs (OSS)
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type {Writable} from 'stream';
|
|
19
|
+
|
|
20
|
+
export type SerializedError = {
|
|
21
|
+
message: string;
|
|
22
|
+
stack: string;
|
|
23
|
+
errors?: ReadonlyArray<SerializedError>;
|
|
24
|
+
cause?: SerializedError;
|
|
25
|
+
};
|
|
26
|
+
export type SerializedEvent<
|
|
27
|
+
TEvent extends {readonly [$$Key$$: string]: unknown},
|
|
28
|
+
> = TEvent extends {error: Error}
|
|
29
|
+
? Omit<Omit<TEvent, 'error'>, keyof {error: SerializedError}> & {
|
|
30
|
+
error: SerializedError;
|
|
31
|
+
}
|
|
32
|
+
: TEvent;
|
|
33
|
+
declare class JsonReporter<
|
|
34
|
+
TEvent extends {readonly [$$Key$$: string]: unknown},
|
|
35
|
+
> {
|
|
36
|
+
_stream: Writable;
|
|
37
|
+
constructor(stream: Writable);
|
|
38
|
+
/**
|
|
39
|
+
* There is a special case for errors because they have non-enumerable fields.
|
|
40
|
+
* (Perhaps we should switch in favor of plain object?)
|
|
41
|
+
*/
|
|
42
|
+
update(event: TEvent): void;
|
|
43
|
+
}
|
|
44
|
+
export default JsonReporter;
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
* @noformat
|
|
8
|
+
* @generated SignedSource<<ebddbde1dcdecbbee129fd96caaf3bb0>>
|
|
9
|
+
*
|
|
10
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
11
|
+
* Original file: packages/metro/src/lib/RamBundleParser.js
|
|
12
|
+
* To regenerate, run:
|
|
13
|
+
* js1 build metro-ts-defs (internal) OR
|
|
14
|
+
* yarn run build-ts-defs (OSS)
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Implementation of a RAM bundle parser in JS.
|
|
19
|
+
*
|
|
20
|
+
* It receives a Buffer as an input and implements two main methods, which are
|
|
21
|
+
* able to run in constant time no matter the size of the bundle:
|
|
22
|
+
*
|
|
23
|
+
* getStartupCode(): returns the runtime and the startup code of the bundle.
|
|
24
|
+
* getModule(): returns the code for the specified module.
|
|
25
|
+
*/
|
|
26
|
+
declare class RamBundleParser {
|
|
27
|
+
_buffer: Buffer;
|
|
28
|
+
_numModules: number;
|
|
29
|
+
_startupCodeLength: number;
|
|
30
|
+
_startOffset: number;
|
|
31
|
+
constructor(buffer: Buffer);
|
|
32
|
+
_readPosition(pos: number): number;
|
|
33
|
+
getStartupCode(): string;
|
|
34
|
+
getModule(id: number): string;
|
|
35
|
+
}
|
|
36
|
+
export default RamBundleParser;
|
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
* @noformat
|
|
8
|
+
* @oncall react_native
|
|
9
|
+
* @generated SignedSource<<8218e45d6b5186264c4bf9e54086708a>>
|
|
10
|
+
*
|
|
11
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
12
|
+
* Original file: packages/metro/src/lib/TerminalReporter.js
|
|
13
|
+
* To regenerate, run:
|
|
14
|
+
* js1 build metro-ts-defs (internal) OR
|
|
15
|
+
* yarn run build-ts-defs (OSS)
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type {BundleDetails, ReportableEvent} from './reporting';
|
|
19
|
+
import type {Terminal} from 'metro-core';
|
|
20
|
+
import type {HealthCheckResult, WatcherStatus} from 'metro-file-map';
|
|
21
|
+
|
|
22
|
+
type BundleProgress = {
|
|
23
|
+
bundleDetails: BundleDetails;
|
|
24
|
+
transformedFileCount: number;
|
|
25
|
+
totalFileCount: number;
|
|
26
|
+
ratio: number;
|
|
27
|
+
isPrefetch?: boolean;
|
|
28
|
+
};
|
|
29
|
+
export type TerminalReportableEvent =
|
|
30
|
+
| ReportableEvent
|
|
31
|
+
| {
|
|
32
|
+
buildID: string;
|
|
33
|
+
type: 'bundle_transform_progressed_throttled';
|
|
34
|
+
transformedFileCount: number;
|
|
35
|
+
totalFileCount: number;
|
|
36
|
+
}
|
|
37
|
+
| {
|
|
38
|
+
type: 'unstable_server_log';
|
|
39
|
+
level: 'info' | 'warn' | 'error';
|
|
40
|
+
data: string | Array<unknown>;
|
|
41
|
+
}
|
|
42
|
+
| {type: 'unstable_server_menu_updated'; message: string}
|
|
43
|
+
| {type: 'unstable_server_menu_cleared'};
|
|
44
|
+
type BuildPhase = 'in_progress' | 'done' | 'failed';
|
|
45
|
+
interface SnippetError extends Error {
|
|
46
|
+
code?: string;
|
|
47
|
+
filename?: string;
|
|
48
|
+
snippet?: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* We try to print useful information to the terminal for interactive builds.
|
|
52
|
+
* This implements the `Reporter` interface from the './reporting' module.
|
|
53
|
+
*/
|
|
54
|
+
declare class TerminalReporter {
|
|
55
|
+
/**
|
|
56
|
+
* The bundle builds for which we are actively maintaining the status on the
|
|
57
|
+
* terminal, ie. showing a progress bar. There can be several bundles being
|
|
58
|
+
* built at the same time.
|
|
59
|
+
*/
|
|
60
|
+
_activeBundles: Map<string, BundleProgress>;
|
|
61
|
+
_interactionStatus: null | undefined | string;
|
|
62
|
+
_scheduleUpdateBundleProgress: {
|
|
63
|
+
(data: {
|
|
64
|
+
buildID: string;
|
|
65
|
+
transformedFileCount: number;
|
|
66
|
+
totalFileCount: number;
|
|
67
|
+
}): void;
|
|
68
|
+
cancel(): void;
|
|
69
|
+
};
|
|
70
|
+
_prevHealthCheckResult: null | undefined | HealthCheckResult;
|
|
71
|
+
readonly terminal: Terminal;
|
|
72
|
+
constructor(terminal: Terminal);
|
|
73
|
+
/**
|
|
74
|
+
* Construct a message that represents the progress of a
|
|
75
|
+
* single bundle build, for example:
|
|
76
|
+
*
|
|
77
|
+
* BUNDLE path/to/bundle.js ▓▓▓▓▓░░░░░░░░░░░ 36.6% (4790/7922)
|
|
78
|
+
*/
|
|
79
|
+
_getBundleStatusMessage(
|
|
80
|
+
$$PARAM_0$$: BundleProgress,
|
|
81
|
+
phase: BuildPhase,
|
|
82
|
+
): string;
|
|
83
|
+
_logBundleBuildDone(buildID: string): void;
|
|
84
|
+
_logBundleBuildFailed(buildID: string): void;
|
|
85
|
+
_logInitializing(port: number, hasReducedPerformance: boolean): void;
|
|
86
|
+
_logInitializingFailed(port: number, error: SnippetError): void;
|
|
87
|
+
/**
|
|
88
|
+
* This function is only concerned with logging and should not do state
|
|
89
|
+
* or terminal status updates.
|
|
90
|
+
*/
|
|
91
|
+
_log(event: TerminalReportableEvent): void;
|
|
92
|
+
/**
|
|
93
|
+
* We do not want to log the whole stacktrace for bundling error, because
|
|
94
|
+
* these are operational errors, not programming errors, and the stacktrace
|
|
95
|
+
* is not actionable to end users.
|
|
96
|
+
*/
|
|
97
|
+
_logBundlingError(error: SnippetError): void;
|
|
98
|
+
_logWorkerChunk(origin: 'stdout' | 'stderr', chunk: string): void;
|
|
99
|
+
_updateBundleProgress($$PARAM_0$$: {
|
|
100
|
+
buildID: string;
|
|
101
|
+
transformedFileCount: number;
|
|
102
|
+
totalFileCount: number;
|
|
103
|
+
}): void;
|
|
104
|
+
/**
|
|
105
|
+
* This function is exclusively concerned with updating the internal state.
|
|
106
|
+
* No logging or status updates should be done at this point.
|
|
107
|
+
*/
|
|
108
|
+
_updateState(event: TerminalReportableEvent): void;
|
|
109
|
+
/**
|
|
110
|
+
* Return a status message that is always consistent with the current state
|
|
111
|
+
* of the application. Having this single function ensures we don't have
|
|
112
|
+
* different callsites overriding each other status messages.
|
|
113
|
+
*/
|
|
114
|
+
_getStatusMessage(): string;
|
|
115
|
+
_logHmrClientError(e: Error): void;
|
|
116
|
+
_logWarning(message: string): void;
|
|
117
|
+
_logWatcherHealthCheckResult(result: HealthCheckResult): void;
|
|
118
|
+
_logWatcherStatus(status: WatcherStatus): void;
|
|
119
|
+
/**
|
|
120
|
+
* Single entry point for reporting events. That allows us to implement the
|
|
121
|
+
* corresponding JSON reporter easily and have a consistent reporting.
|
|
122
|
+
*/
|
|
123
|
+
update(event: TerminalReportableEvent): void;
|
|
124
|
+
}
|
|
125
|
+
export default TerminalReporter;
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true,
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
var _bundleProgressUtils = require("./bundleProgressUtils");
|
|
7
8
|
var _logToConsole = _interopRequireDefault(require("./logToConsole"));
|
|
8
9
|
var reporting = _interopRequireWildcard(require("./reporting"));
|
|
9
10
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
@@ -78,7 +79,7 @@ class TerminalReporter {
|
|
|
78
79
|
_chalk.default.bgWhite.white(
|
|
79
80
|
LIGHT_BLOCK_CHAR.repeat(MAX_PROGRESS_BAR_CHAR_WIDTH - filledBar),
|
|
80
81
|
) +
|
|
81
|
-
_chalk.default.bold(` ${(100 * ratio)
|
|
82
|
+
_chalk.default.bold(` ${Math.floor(100 * ratio)}% `) +
|
|
82
83
|
_chalk.default.dim(`(${transformedFileCount}/${totalFileCount})`)
|
|
83
84
|
: "";
|
|
84
85
|
return (
|
|
@@ -287,12 +288,10 @@ class TerminalReporter {
|
|
|
287
288
|
if (currentProgress == null) {
|
|
288
289
|
return;
|
|
289
290
|
}
|
|
290
|
-
const ratio =
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
),
|
|
295
|
-
0.999,
|
|
291
|
+
const ratio = (0, _bundleProgressUtils.calculateBundleProgressRatio)(
|
|
292
|
+
transformedFileCount,
|
|
293
|
+
totalFileCount,
|
|
294
|
+
currentProgress.ratio,
|
|
296
295
|
);
|
|
297
296
|
Object.assign(currentProgress, {
|
|
298
297
|
ratio,
|
|
@@ -13,6 +13,7 @@ import type {BundleDetails, ReportableEvent} from './reporting';
|
|
|
13
13
|
import type {Terminal} from 'metro-core';
|
|
14
14
|
import type {HealthCheckResult, WatcherStatus} from 'metro-file-map';
|
|
15
15
|
|
|
16
|
+
import {calculateBundleProgressRatio} from './bundleProgressUtils';
|
|
16
17
|
import logToConsole from './logToConsole';
|
|
17
18
|
import * as reporting from './reporting';
|
|
18
19
|
import chalk from 'chalk';
|
|
@@ -132,7 +133,7 @@ export default class TerminalReporter {
|
|
|
132
133
|
chalk.bgWhite.white(
|
|
133
134
|
LIGHT_BLOCK_CHAR.repeat(MAX_PROGRESS_BAR_CHAR_WIDTH - filledBar),
|
|
134
135
|
) +
|
|
135
|
-
chalk.bold(` ${(100 * ratio)
|
|
136
|
+
chalk.bold(` ${Math.floor(100 * ratio)}% `) +
|
|
136
137
|
chalk.dim(`(${transformedFileCount}/${totalFileCount})`)
|
|
137
138
|
: '';
|
|
138
139
|
|
|
@@ -352,14 +353,6 @@ export default class TerminalReporter {
|
|
|
352
353
|
});
|
|
353
354
|
}
|
|
354
355
|
|
|
355
|
-
/**
|
|
356
|
-
* Because we know the `totalFileCount` is going to progressively increase
|
|
357
|
-
* starting with 1:
|
|
358
|
-
* - We use Math.max(totalFileCount, 10) to prevent the ratio to raise too
|
|
359
|
-
* quickly when the total file count is low. (e.g 1/2 5/6)
|
|
360
|
-
* - We prevent the ratio from going backwards.
|
|
361
|
-
* - Instead, we use Math.pow(ratio, 2) to as a conservative measure of progress.
|
|
362
|
-
*/
|
|
363
356
|
_updateBundleProgress({
|
|
364
357
|
buildID,
|
|
365
358
|
transformedFileCount,
|
|
@@ -375,12 +368,10 @@ export default class TerminalReporter {
|
|
|
375
368
|
return;
|
|
376
369
|
}
|
|
377
370
|
|
|
378
|
-
const ratio =
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
),
|
|
383
|
-
0.999, // make sure not to go above 99.9% to not get rounded to 100%,
|
|
371
|
+
const ratio = calculateBundleProgressRatio(
|
|
372
|
+
transformedFileCount,
|
|
373
|
+
totalFileCount,
|
|
374
|
+
currentProgress.ratio,
|
|
384
375
|
);
|
|
385
376
|
|
|
386
377
|
// $FlowFixMe[unsafe-object-assign]
|