metro 0.76.0 → 0.76.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.
Files changed (84) hide show
  1. package/package.json +22 -24
  2. package/src/Asset.d.ts +25 -0
  3. package/src/Bundler.d.ts +39 -0
  4. package/src/DeltaBundler/Graph.d.ts +40 -0
  5. package/src/DeltaBundler/Serializers/baseJSBundle.js +1 -0
  6. package/src/DeltaBundler/Serializers/baseJSBundle.js.flow +1 -0
  7. package/src/DeltaBundler/Serializers/getRamBundleInfo.d.ts +18 -0
  8. package/src/DeltaBundler/Serializers/helpers/js.js +22 -6
  9. package/src/DeltaBundler/Serializers/helpers/js.js.flow +24 -6
  10. package/src/DeltaBundler/Serializers/helpers/processModules.js +2 -0
  11. package/src/DeltaBundler/Serializers/helpers/processModules.js.flow +3 -0
  12. package/src/DeltaBundler/Serializers/hmrJSBundle.js +1 -0
  13. package/src/DeltaBundler/Serializers/hmrJSBundle.js.flow +1 -0
  14. package/src/DeltaBundler/Transformer.js +1 -2
  15. package/src/DeltaBundler/Transformer.js.flow +1 -2
  16. package/src/DeltaBundler/Worker.d.ts +47 -0
  17. package/src/DeltaBundler/types.d.ts +169 -0
  18. package/src/DeltaBundler.d.ts +58 -0
  19. package/src/HmrServer.js +1 -5
  20. package/src/HmrServer.js.flow +0 -5
  21. package/src/IncrementalBundler.d.ts +97 -0
  22. package/src/IncrementalBundler.js +1 -0
  23. package/src/IncrementalBundler.js.flow +1 -0
  24. package/src/ModuleGraph/worker/collectDependencies.d.ts +27 -0
  25. package/src/ModuleGraph/worker/collectDependencies.js +42 -25
  26. package/src/ModuleGraph/worker/collectDependencies.js.flow +41 -36
  27. package/src/Server/MultipartResponse.d.ts +31 -0
  28. package/src/Server/symbolicate.js +33 -5
  29. package/src/Server/symbolicate.js.flow +40 -9
  30. package/src/Server.d.ts +113 -0
  31. package/src/Server.js +16 -136
  32. package/src/Server.js.flow +16 -156
  33. package/src/cli/parseKeyValueParamArray.js +34 -0
  34. package/src/cli/parseKeyValueParamArray.js.flow +31 -0
  35. package/src/cli-utils.js.flow +2 -6
  36. package/src/cli.js +2 -0
  37. package/src/cli.js.flow +1 -0
  38. package/src/commands/build.js +34 -7
  39. package/src/commands/build.js.flow +50 -8
  40. package/src/commands/dependencies.js +11 -9
  41. package/src/commands/dependencies.js.flow +128 -0
  42. package/src/commands/serve.js +11 -4
  43. package/src/commands/serve.js.flow +26 -6
  44. package/src/index.d.ts +161 -0
  45. package/src/index.flow.js +17 -4
  46. package/src/index.flow.js.flow +41 -10
  47. package/src/lib/CountingSet.d.ts +48 -0
  48. package/src/lib/TerminalReporter.d.ts +27 -0
  49. package/src/lib/TerminalReporter.js +1 -4
  50. package/src/lib/TerminalReporter.js.flow +1 -5
  51. package/src/lib/contextModule.d.ts +22 -0
  52. package/src/lib/getGraphId.d.ts +11 -0
  53. package/src/lib/getGraphId.js +0 -1
  54. package/src/lib/getGraphId.js.flow +0 -1
  55. package/src/lib/getPrependedScripts.js +0 -9
  56. package/src/lib/getPrependedScripts.js.flow +0 -9
  57. package/src/lib/parseOptionsFromUrl.js +1 -16
  58. package/src/lib/parseOptionsFromUrl.js.flow +0 -17
  59. package/src/lib/reporting.d.ts +140 -0
  60. package/src/lib/reporting.js.flow +0 -1
  61. package/src/lib/splitBundleOptions.js +0 -1
  62. package/src/lib/splitBundleOptions.js.flow +0 -1
  63. package/src/lib/transformHelpers.js +0 -1
  64. package/src/lib/transformHelpers.js.flow +0 -1
  65. package/src/node-haste/DependencyGraph/createHasteMap.js +0 -1
  66. package/src/node-haste/DependencyGraph/createHasteMap.js.flow +0 -1
  67. package/src/node-haste/DependencyGraph.d.ts +59 -0
  68. package/src/node-haste/DependencyGraph.js +7 -1
  69. package/src/node-haste/DependencyGraph.js.flow +8 -1
  70. package/src/shared/output/RamBundle/as-assets.js +1 -0
  71. package/src/shared/output/RamBundle/as-assets.js.flow +1 -0
  72. package/src/shared/output/RamBundle/write-sourcemap.js +1 -0
  73. package/src/shared/output/RamBundle/write-sourcemap.js.flow +1 -0
  74. package/src/shared/output/bundle.d.ts +31 -0
  75. package/src/shared/types.d.ts +138 -0
  76. package/src/shared/types.flow.js.flow +2 -2
  77. package/src/DeltaBundler/Serializers/baseBytecodeBundle.js +0 -81
  78. package/src/DeltaBundler/Serializers/baseBytecodeBundle.js.flow +0 -103
  79. package/src/DeltaBundler/Serializers/helpers/bytecode.js +0 -61
  80. package/src/DeltaBundler/Serializers/helpers/bytecode.js.flow +0 -75
  81. package/src/DeltaBundler/Serializers/helpers/processBytecodeModules.js +0 -40
  82. package/src/DeltaBundler/Serializers/helpers/processBytecodeModules.js.flow +0 -51
  83. package/src/lib/bundleToBytecode.js +0 -79
  84. package/src/lib/bundleToBytecode.js.flow +0 -97
package/src/index.flow.js CHANGED
@@ -23,11 +23,17 @@ const chalk = require("chalk");
23
23
  const fs = require("fs");
24
24
  const http = require("http");
25
25
  const https = require("https");
26
- const { getDefaultConfig, loadConfig, mergeConfig } = require("metro-config");
26
+ const {
27
+ getDefaultConfig,
28
+ loadConfig,
29
+ mergeConfig,
30
+ resolveConfig,
31
+ } = require("metro-config");
32
+ const { Terminal } = require("metro-core");
27
33
  const { InspectorProxy } = require("metro-inspector-proxy");
28
34
  const net = require("net");
29
35
  const { parse } = require("url");
30
- const ws = require("ws");
36
+ exports.Terminal = Terminal;
31
37
  async function getConfig(config) {
32
38
  const defaultConfig = await getDefaultConfig(config.projectRoot);
33
39
  return mergeConfig(defaultConfig, config);
@@ -69,6 +75,8 @@ async function runMetro(config, options) {
69
75
  }
70
76
  exports.runMetro = runMetro;
71
77
  exports.loadConfig = loadConfig;
78
+ exports.mergeConfig = mergeConfig;
79
+ exports.resolveConfig = resolveConfig;
72
80
  const createConnectMiddleware = async function (config, options) {
73
81
  const metroServer = await runMetro(config, options);
74
82
  let enhancedMiddleware = metroServer.processRequest;
@@ -179,7 +187,8 @@ exports.runServer = async (
179
187
  if (onReady) {
180
188
  onReady(httpServer);
181
189
  }
182
- Object.assign(websocketEndpoints, {
190
+ websocketEndpoints = {
191
+ ...websocketEndpoints,
183
192
  ...(inspectorProxy
184
193
  ? {
185
194
  ...inspectorProxy.createWebSocketListeners(httpServer),
@@ -192,7 +201,7 @@ exports.runServer = async (
192
201
  config
193
202
  ),
194
203
  }),
195
- });
204
+ };
196
205
  httpServer.on("upgrade", (request, socket, head) => {
197
206
  const { pathname } = parse(request.url);
198
207
  if (pathname != null && websocketEndpoints[pathname]) {
@@ -230,6 +239,8 @@ exports.runServer = async (
230
239
  exports.runBuild = async (
231
240
  config,
232
241
  {
242
+ customResolverOptions,
243
+ customTransformOptions,
233
244
  dev = false,
234
245
  entry,
235
246
  onBegin,
@@ -256,6 +267,8 @@ exports.runBuild = async (
256
267
  sourceMapUrl: sourceMap === false ? undefined : sourceMapUrl,
257
268
  createModuleIdFactory: config.serializer.createModuleIdFactory,
258
269
  onProgress,
270
+ customResolverOptions,
271
+ customTransformOptions,
259
272
  };
260
273
  if (onBegin) {
261
274
  onBegin();
@@ -11,17 +11,21 @@
11
11
 
12
12
  'use strict';
13
13
 
14
+ import type {CustomResolverOptions} from 'metro-resolver';
14
15
  import type {ReadOnlyGraph} from './DeltaBundler';
15
16
  import type {ServerOptions} from './Server';
16
17
  import type {OutputOptions, RequestOptions} from './shared/types.flow.js';
17
- import type {Server as HttpServer} from 'http';
18
+ import type EventEmitter from 'events';
19
+ import type {IncomingMessage, Server as HttpServer} from 'http';
18
20
  import type {Server as HttpsServer} from 'https';
19
21
  import type {
20
22
  ConfigT,
21
23
  InputConfigT,
24
+ MetroConfig,
22
25
  Middleware,
23
26
  } from 'metro-config/src/configTypes.flow';
24
27
  import type {CustomTransformOptions} from 'metro-transform-worker';
28
+ import type {Duplex} from 'stream';
25
29
  import typeof Yargs from 'yargs';
26
30
 
27
31
  const makeBuildCommand = require('./commands/build');
@@ -36,11 +40,16 @@ const chalk = require('chalk');
36
40
  const fs = require('fs');
37
41
  const http = require('http');
38
42
  const https = require('https');
39
- const {getDefaultConfig, loadConfig, mergeConfig} = require('metro-config');
43
+ const {
44
+ getDefaultConfig,
45
+ loadConfig,
46
+ mergeConfig,
47
+ resolveConfig,
48
+ } = require('metro-config');
49
+ const {Terminal} = require('metro-core');
40
50
  const {InspectorProxy} = require('metro-inspector-proxy');
41
51
  const net = require('net');
42
52
  const {parse} = require('url');
43
- const ws = require('ws');
44
53
 
45
54
  type MetroMiddleWare = {
46
55
  attachHmrServer: (httpServer: HttpServer | HttpsServer) => void,
@@ -54,7 +63,16 @@ export type RunMetroOptions = {
54
63
  waitForBundler?: boolean,
55
64
  };
56
65
 
57
- export type RunServerOptions = {
66
+ interface WebsocketServer extends EventEmitter {
67
+ handleUpgrade<T = WebsocketServer>(
68
+ request: IncomingMessage,
69
+ socket: Duplex,
70
+ upgradeHead: Buffer,
71
+ callback: (client: T, request: IncomingMessage) => void,
72
+ ): void;
73
+ }
74
+
75
+ export type RunServerOptions = $ReadOnly<{
58
76
  hasReducedPerformance?: boolean,
59
77
  host?: string,
60
78
  onError?: (Error & {code?: string}) => void,
@@ -66,10 +84,10 @@ export type RunServerOptions = {
66
84
  secureKey?: string, // deprecated
67
85
  waitForBundler?: boolean,
68
86
  watch?: boolean,
69
- websocketEndpoints?: {
70
- [path: string]: typeof ws.Server,
71
- },
72
- };
87
+ websocketEndpoints?: $ReadOnly<{
88
+ [path: string]: WebsocketServer,
89
+ }>,
90
+ }>;
73
91
 
74
92
  type BuildGraphOptions = {
75
93
  entries: $ReadOnlyArray<string>,
@@ -112,11 +130,17 @@ export type RunBuildOptions = {
112
130
  platform?: string,
113
131
  sourceMap?: boolean,
114
132
  sourceMapUrl?: string,
133
+ customResolverOptions?: CustomResolverOptions,
134
+ customTransformOptions?: CustomTransformOptions,
115
135
  };
116
136
 
117
137
  type BuildCommandOptions = {} | null;
118
138
  type ServeCommandOptions = {} | null;
119
139
 
140
+ exports.Terminal = Terminal;
141
+
142
+ export type {MetroConfig};
143
+
120
144
  async function getConfig(config: InputConfigT): Promise<ConfigT> {
121
145
  const defaultConfig = await getDefaultConfig(config.projectRoot);
122
146
  return mergeConfig(defaultConfig, config);
@@ -167,6 +191,8 @@ async function runMetro(
167
191
 
168
192
  exports.runMetro = runMetro;
169
193
  exports.loadConfig = loadConfig;
194
+ exports.mergeConfig = mergeConfig;
195
+ exports.resolveConfig = resolveConfig;
170
196
 
171
197
  const createConnectMiddleware = async function (
172
198
  config: ConfigT,
@@ -291,7 +317,8 @@ exports.runServer = async (
291
317
  onReady(httpServer);
292
318
  }
293
319
 
294
- Object.assign(websocketEndpoints, {
320
+ websocketEndpoints = {
321
+ ...websocketEndpoints,
295
322
  ...(inspectorProxy
296
323
  ? {...inspectorProxy.createWebSocketListeners(httpServer)}
297
324
  : {}),
@@ -302,7 +329,7 @@ exports.runServer = async (
302
329
  config,
303
330
  ),
304
331
  }),
305
- });
332
+ };
306
333
 
307
334
  httpServer.on('upgrade', (request, socket, head) => {
308
335
  const {pathname} = parse(request.url);
@@ -346,6 +373,8 @@ exports.runServer = async (
346
373
  exports.runBuild = async (
347
374
  config: ConfigT,
348
375
  {
376
+ customResolverOptions,
377
+ customTransformOptions,
349
378
  dev = false,
350
379
  entry,
351
380
  onBegin,
@@ -377,6 +406,8 @@ exports.runBuild = async (
377
406
  sourceMapUrl: sourceMap === false ? undefined : sourceMapUrl,
378
407
  createModuleIdFactory: config.serializer.createModuleIdFactory,
379
408
  onProgress,
409
+ customResolverOptions,
410
+ customTransformOptions,
380
411
  };
381
412
 
382
413
  if (onBegin) {
@@ -0,0 +1,48 @@
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 interface ReadOnlyCountingSet<T> extends Iterable<T> {
12
+ has(item: T): boolean;
13
+ [Symbol.iterator](): Iterator<T>;
14
+ readonly size: number;
15
+ count(item: T): number;
16
+ forEach<ThisT>(
17
+ callbackFn: (
18
+ this: ThisT,
19
+ value: T,
20
+ key: T,
21
+ set: ReadOnlyCountingSet<T>,
22
+ ) => unknown,
23
+ thisArg: ThisT,
24
+ ): void;
25
+ }
26
+
27
+ export default class CountingSet<T> implements ReadOnlyCountingSet<T> {
28
+ constructor(items?: Iterable<T>);
29
+ get size(): number;
30
+ has(item: T): boolean;
31
+ add(item: T): void;
32
+ delete(item: T): void;
33
+ keys(): Iterator<T>;
34
+ values(): Iterator<T>;
35
+ [Symbol.iterator](): Iterator<T>;
36
+ count(item: T): number;
37
+ clear(): void;
38
+ forEach<ThisT>(
39
+ callbackFn: (
40
+ this: ThisT,
41
+ value: T,
42
+ key: T,
43
+ set: ReadOnlyCountingSet<T>,
44
+ ) => unknown,
45
+ thisArg: ThisT,
46
+ ): void;
47
+ toJSON(): unknown;
48
+ }
@@ -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
+ import {ReportableEvent} from './reporting';
12
+ import {Terminal} from 'metro-core';
13
+
14
+ export type TerminalReportableEvent =
15
+ | ReportableEvent
16
+ | {
17
+ buildID: string;
18
+ type: 'bundle_transform_progressed_throttled';
19
+ transformedFileCount: number;
20
+ totalFileCount: number;
21
+ };
22
+
23
+ export class TerminalReporter {
24
+ constructor(terminal: Terminal);
25
+ readonly terminal: Terminal;
26
+ update(event: TerminalReportableEvent): void;
27
+ }
@@ -53,7 +53,7 @@ class TerminalReporter {
53
53
  */
54
54
  _getBundleStatusMessage(
55
55
  {
56
- bundleDetails: { entryFile, bundleType, runtimeBytecodeVersion },
56
+ bundleDetails: { entryFile, bundleType },
57
57
  transformedFileCount,
58
58
  totalFileCount,
59
59
  ratio,
@@ -61,9 +61,6 @@ class TerminalReporter {
61
61
  },
62
62
  phase
63
63
  ) {
64
- if (runtimeBytecodeVersion) {
65
- bundleType = "bytecodebundle";
66
- }
67
64
  if (isPrefetch) {
68
65
  bundleType = "PREBUNDLE";
69
66
  }
@@ -101,7 +101,7 @@ class TerminalReporter {
101
101
  */
102
102
  _getBundleStatusMessage(
103
103
  {
104
- bundleDetails: {entryFile, bundleType, runtimeBytecodeVersion},
104
+ bundleDetails: {entryFile, bundleType},
105
105
  transformedFileCount,
106
106
  totalFileCount,
107
107
  ratio,
@@ -109,10 +109,6 @@ class TerminalReporter {
109
109
  }: BundleProgress,
110
110
  phase: BuildPhase,
111
111
  ): string {
112
- if (runtimeBytecodeVersion) {
113
- bundleType = 'bytecodebundle';
114
- }
115
-
116
112
  if (isPrefetch) {
117
113
  bundleType = 'PREBUNDLE';
118
114
  }
@@ -0,0 +1,22 @@
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 {ContextMode} from '../ModuleGraph/worker/collectDependencies';
12
+
13
+ export interface RequireContext {
14
+ /* Should search for files recursively. Optional, default `true` when `require.context` is used */
15
+ readonly recursive: boolean;
16
+ /* Filename filter pattern for use in `require.context`. Optional, default `.*` (any file) when `require.context` is used */
17
+ readonly filter: RegExp;
18
+ /** Mode for resolving dynamic dependencies. Defaults to `sync` */
19
+ readonly mode: ContextMode;
20
+ /** Absolute path of the directory to search in */
21
+ readonly from: string;
22
+ }
@@ -0,0 +1,11 @@
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 GraphId = string;
@@ -34,7 +34,6 @@ function getGraphId(
34
34
  minify: options.minify,
35
35
  unstable_disableES6Transforms: options.unstable_disableES6Transforms,
36
36
  platform: options.platform != null ? options.platform : null,
37
- runtimeBytecodeVersion: options.runtimeBytecodeVersion,
38
37
  type: options.type,
39
38
  experimentalImportBundleSupport,
40
39
  unstable_allowRequireContext,
@@ -45,7 +45,6 @@ function getGraphId(
45
45
  minify: options.minify,
46
46
  unstable_disableES6Transforms: options.unstable_disableES6Transforms,
47
47
  platform: options.platform != null ? options.platform : null,
48
- runtimeBytecodeVersion: options.runtimeBytecodeVersion,
49
48
  type: options.type,
50
49
  experimentalImportBundleSupport,
51
50
  unstable_allowRequireContext,
@@ -74,7 +74,6 @@ async function getPrependedScripts(
74
74
  ];
75
75
  }
76
76
  function _getPrelude({ dev, globalPrefix, requireCycleIgnorePatterns }) {
77
- const { compile } = require("metro-hermes-compiler");
78
77
  const code = getPreludeCode({
79
78
  isDev: dev,
80
79
  globalPrefix,
@@ -95,14 +94,6 @@ function _getPrelude({ dev, globalPrefix, requireCycleIgnorePatterns }) {
95
94
  map: [],
96
95
  },
97
96
  },
98
- {
99
- type: "bytecode/script/virtual",
100
- data: {
101
- bytecode: compile(code, {
102
- sourceURL: "__prelude__.virtual.js",
103
- }).bytecode,
104
- },
105
- },
106
97
  ],
107
98
  };
108
99
  }
@@ -95,8 +95,6 @@ function _getPrelude({
95
95
  requireCycleIgnorePatterns: $ReadOnlyArray<RegExp>,
96
96
  ...
97
97
  }): Module<> {
98
- const {compile} = require('metro-hermes-compiler');
99
-
100
98
  const code = getPreludeCode({
101
99
  isDev: dev,
102
100
  globalPrefix,
@@ -118,13 +116,6 @@ function _getPrelude({
118
116
  map: [],
119
117
  },
120
118
  },
121
- {
122
- type: 'bytecode/script/virtual',
123
- data: {
124
- bytecode: compile(code, {sourceURL: '__prelude__.virtual.js'})
125
- .bytecode,
126
- },
127
- },
128
119
  ],
129
120
  };
130
121
  }
@@ -21,21 +21,13 @@ const getBoolean = (query, opt, defaultValue) =>
21
21
  query[opt] == null
22
22
  ? defaultValue
23
23
  : query[opt] === "true" || query[opt] === "1";
24
- const getNumber = (query, opt, defaultValue) => {
25
- const number = parseInt(query[opt], 10);
26
- return Number.isNaN(number) ? defaultValue : number;
27
- };
28
24
  const getBundleType = (bundleType) =>
29
25
  bundleType === "map" ? bundleType : "bundle";
30
26
  const getTransformProfile = (transformProfile) =>
31
27
  transformProfile === "hermes-stable" || transformProfile === "hermes-canary"
32
28
  ? transformProfile
33
29
  : "default";
34
- module.exports = function parseOptionsFromUrl(
35
- requestUrl,
36
- platforms,
37
- bytecodeVersion
38
- ) {
30
+ module.exports = function parseOptionsFromUrl(requestUrl, platforms) {
39
31
  const parsedURL = nullthrows(url.parse(requestUrl, true)); // `true` to parse the query param as an object.
40
32
  const query = nullthrows(parsedURL.query);
41
33
  const pathname =
@@ -44,15 +36,8 @@ module.exports = function parseOptionsFromUrl(
44
36
  const platform =
45
37
  query.platform || parsePlatformFilePath(pathname, platforms).platform;
46
38
  const bundleType = getBundleType(path.extname(pathname).substr(1));
47
- const runtimeBytecodeVersion = getNumber(
48
- query,
49
- "runtimeBytecodeVersion",
50
- null
51
- );
52
39
  return {
53
40
  bundleType,
54
- runtimeBytecodeVersion:
55
- bytecodeVersion === runtimeBytecodeVersion ? bytecodeVersion : null,
56
41
  customResolverOptions: parseCustomResolverOptions(parsedURL),
57
42
  customTransformOptions: parseCustomTransformOptions(parsedURL),
58
43
  dev: getBoolean(query, "dev", true),
@@ -30,15 +30,6 @@ const getBoolean = (
30
30
  ? defaultValue
31
31
  : query[opt] === 'true' || query[opt] === '1';
32
32
 
33
- const getNumber = (
34
- query: $ReadOnly<{[opt: string]: string}>,
35
- opt: string,
36
- defaultValue: null,
37
- ) => {
38
- const number = parseInt(query[opt], 10);
39
- return Number.isNaN(number) ? defaultValue : number;
40
- };
41
-
42
33
  const getBundleType = (bundleType: string): 'map' | 'bundle' =>
43
34
  bundleType === 'map' ? bundleType : 'bundle';
44
35
 
@@ -50,7 +41,6 @@ const getTransformProfile = (transformProfile: string): TransformProfile =>
50
41
  module.exports = function parseOptionsFromUrl(
51
42
  requestUrl: string,
52
43
  platforms: Set<string>,
53
- bytecodeVersion: number,
54
44
  ): BundleOptions {
55
45
  const parsedURL = nullthrows(url.parse(requestUrl, true)); // `true` to parse the query param as an object.
56
46
  const query = nullthrows(parsedURL.query);
@@ -60,16 +50,9 @@ module.exports = function parseOptionsFromUrl(
60
50
  const platform =
61
51
  query.platform || parsePlatformFilePath(pathname, platforms).platform;
62
52
  const bundleType = getBundleType(path.extname(pathname).substr(1));
63
- const runtimeBytecodeVersion = getNumber(
64
- query,
65
- 'runtimeBytecodeVersion',
66
- null,
67
- );
68
53
 
69
54
  return {
70
55
  bundleType,
71
- runtimeBytecodeVersion:
72
- bytecodeVersion === runtimeBytecodeVersion ? bytecodeVersion : null,
73
56
  customResolverOptions: parseCustomResolverOptions(parsedURL),
74
57
  customTransformOptions: parseCustomTransformOptions(parsedURL),
75
58
  dev: getBoolean(query, 'dev', true),
@@ -0,0 +1,140 @@
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 {HealthCheckResult, WatcherStatus} from 'metro-file-map';
12
+
13
+ export type GlobalCacheDisabledReason = 'too_many_errors' | 'too_many_misses';
14
+
15
+ export interface BundleDetails {
16
+ bundleType: string;
17
+ dev: boolean;
18
+ entryFile: string;
19
+ minify: boolean;
20
+ platform?: string;
21
+ runtimeBytecodeVersion?: number;
22
+ }
23
+
24
+ /**
25
+ * A tagged union of all the actions that may happen and we may want to
26
+ * report to the tool user.
27
+ */
28
+ export type ReportableEvent =
29
+ | {
30
+ port: number;
31
+ hasReducedPerformance: boolean;
32
+ type: 'initialize_started';
33
+ }
34
+ | {
35
+ type: 'initialize_failed';
36
+ port: number;
37
+ error: Error;
38
+ }
39
+ | {
40
+ buildID: string;
41
+ type: 'bundle_build_done';
42
+ }
43
+ | {
44
+ buildID: string;
45
+ type: 'bundle_build_failed';
46
+ }
47
+ | {
48
+ buildID: string;
49
+ bundleDetails: BundleDetails;
50
+ type: 'bundle_build_started';
51
+ }
52
+ | {
53
+ error: Error;
54
+ type: 'bundling_error';
55
+ }
56
+ | {
57
+ type: 'dep_graph_loading';
58
+ hasReducedPerformance: boolean;
59
+ }
60
+ | {type: 'dep_graph_loaded'}
61
+ | {
62
+ buildID: string;
63
+ type: 'bundle_transform_progressed';
64
+ transformedFileCount: number;
65
+ totalFileCount: number;
66
+ }
67
+ | {
68
+ type: 'global_cache_error';
69
+ error: Error;
70
+ }
71
+ | {
72
+ type: 'global_cache_disabled';
73
+ reason: GlobalCacheDisabledReason;
74
+ }
75
+ | {type: 'transform_cache_reset'}
76
+ | {
77
+ type: 'worker_stdout_chunk';
78
+ chunk: string;
79
+ }
80
+ | {
81
+ type: 'worker_stderr_chunk';
82
+ chunk: string;
83
+ }
84
+ | {
85
+ type: 'hmr_client_error';
86
+ error: Error;
87
+ }
88
+ | {
89
+ type: 'client_log';
90
+ level:
91
+ | 'trace'
92
+ | 'info'
93
+ | 'warn'
94
+ | 'log'
95
+ | 'group'
96
+ | 'groupCollapsed'
97
+ | 'groupEnd'
98
+ | 'debug';
99
+ data: unknown[];
100
+ }
101
+ | {
102
+ type: 'transformer_load_started';
103
+ }
104
+ | {
105
+ type: 'transformer_load_done';
106
+ }
107
+ | {
108
+ type: 'transformer_load_failed';
109
+ error: Error;
110
+ }
111
+ | {
112
+ type: 'watcher_health_check_result';
113
+ result: HealthCheckResult;
114
+ }
115
+ | {
116
+ type: 'watcher_status';
117
+ status: WatcherStatus;
118
+ };
119
+
120
+ /**
121
+ * Code across the application takes a reporter as an option and calls the
122
+ * update whenever one of the ReportableEvent happens. Code does not directly
123
+ * write to the standard output, because a build would be:
124
+ *
125
+ * 1. ad-hoc, embedded into another tool, in which case we do not want to
126
+ * pollute that tool's own output. The tool is free to present the
127
+ * warnings/progress we generate any way they want, by specifing a custom
128
+ * reporter.
129
+ * 2. run as a background process from another tool, in which case we want
130
+ * to expose updates in a way that is easily machine-readable, for example
131
+ * a JSON-stream. We don't want to pollute it with textual messages.
132
+ *
133
+ * We centralize terminal reporting into a single place because we want the
134
+ * output to be robust and consistent. The most common reporter is
135
+ * TerminalReporter, that should be the only place in the application should
136
+ * access the `terminal` module (nor the `console`).
137
+ */
138
+ export interface Reporter {
139
+ update: (event: ReportableEvent) => void;
140
+ }
@@ -26,7 +26,6 @@ export type BundleDetails = {
26
26
  entryFile: string,
27
27
  minify: boolean,
28
28
  platform: ?string,
29
- runtimeBytecodeVersion: ?number,
30
29
  ...
31
30
  };
32
31
 
@@ -26,7 +26,6 @@ function splitBundleOptions(options) {
26
26
  hot: options.hot,
27
27
  minify: options.minify,
28
28
  platform: options.platform,
29
- runtimeBytecodeVersion: options.runtimeBytecodeVersion,
30
29
  type: "module",
31
30
  unstable_transformProfile: options.unstable_transformProfile,
32
31
  },
@@ -28,7 +28,6 @@ function splitBundleOptions(options: BundleOptions): SplitBundleOptions {
28
28
  hot: options.hot,
29
29
  minify: options.minify,
30
30
  platform: options.platform,
31
- runtimeBytecodeVersion: options.runtimeBytecodeVersion,
32
31
  type: 'module',
33
32
  unstable_transformProfile: options.unstable_transformProfile,
34
33
  },
@@ -35,7 +35,6 @@ async function calcTransformerOptions(
35
35
  inlinePlatform: true,
36
36
  minify: options.minify,
37
37
  platform: options.platform,
38
- runtimeBytecodeVersion: options.runtimeBytecodeVersion,
39
38
  unstable_transformProfile: options.unstable_transformProfile,
40
39
  };
41
40
 
@@ -52,7 +52,6 @@ async function calcTransformerOptions(
52
52
  inlinePlatform: true,
53
53
  minify: options.minify,
54
54
  platform: options.platform,
55
- runtimeBytecodeVersion: options.runtimeBytecodeVersion,
56
55
  unstable_transformProfile: options.unstable_transformProfile,
57
56
  };
58
57