metro 0.83.4 → 0.83.5

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 (161) hide show
  1. package/package.json +17 -15
  2. package/src/Assets.d.ts +83 -0
  3. package/src/Assets.js +2 -9
  4. package/src/Bundler/util.d.ts +27 -0
  5. package/src/Bundler/util.js +2 -9
  6. package/src/Bundler.d.ts +38 -0
  7. package/src/Bundler.js +1 -5
  8. package/src/DeltaBundler/DeltaCalculator.d.ts +71 -0
  9. package/src/DeltaBundler/DeltaCalculator.js +1 -5
  10. package/src/DeltaBundler/Graph.d.ts +167 -0
  11. package/src/DeltaBundler/Graph.js +1 -5
  12. package/src/DeltaBundler/Serializers/baseJSBundle.d.ts +20 -0
  13. package/src/DeltaBundler/Serializers/baseJSBundle.js +1 -5
  14. package/src/DeltaBundler/Serializers/getAllFiles.d.ts +22 -0
  15. package/src/DeltaBundler/Serializers/getAssets.d.ts +25 -0
  16. package/src/DeltaBundler/Serializers/getAssets.js +1 -5
  17. package/src/DeltaBundler/Serializers/getExplodedSourceMap.d.ts +26 -0
  18. package/src/DeltaBundler/Serializers/getRamBundleInfo.d.ts +48 -0
  19. package/src/DeltaBundler/Serializers/getRamBundleInfo.js +1 -5
  20. package/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.d.ts +12 -0
  21. package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.d.ts +33 -0
  22. package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.d.ts +17 -0
  23. package/src/DeltaBundler/Serializers/helpers/js.d.ts +30 -0
  24. package/src/DeltaBundler/Serializers/helpers/js.js +2 -9
  25. package/src/DeltaBundler/Serializers/helpers/processModules.d.ts +25 -0
  26. package/src/DeltaBundler/Serializers/hmrJSBundle.d.ts +30 -0
  27. package/src/DeltaBundler/Serializers/hmrJSBundle.js +2 -9
  28. package/src/DeltaBundler/Serializers/sourceMapGenerator.d.ts +29 -0
  29. package/src/DeltaBundler/Serializers/sourceMapGenerator.js +1 -5
  30. package/src/DeltaBundler/Serializers/sourceMapObject.d.ts +23 -0
  31. package/src/DeltaBundler/Serializers/sourceMapString.d.ts +22 -0
  32. package/src/DeltaBundler/Transformer.d.ts +38 -0
  33. package/src/DeltaBundler/Transformer.js +1 -5
  34. package/src/DeltaBundler/Worker.d.ts +37 -0
  35. package/src/DeltaBundler/Worker.flow.js +1 -5
  36. package/src/DeltaBundler/WorkerFarm.d.ts +70 -0
  37. package/src/DeltaBundler/buildSubgraph.d.ts +30 -0
  38. package/src/DeltaBundler/buildSubgraph.js +1 -5
  39. package/src/DeltaBundler/getTransformCacheKey.d.ts +18 -0
  40. package/src/DeltaBundler/getTransformCacheKey.js +1 -5
  41. package/src/DeltaBundler/mergeDeltas.d.ts +17 -0
  42. package/src/DeltaBundler/types.d.ts +163 -0
  43. package/src/DeltaBundler/types.js +1 -5
  44. package/src/DeltaBundler.d.ts +60 -0
  45. package/src/DeltaBundler.js +1 -5
  46. package/src/HmrServer.d.ts +79 -0
  47. package/src/HmrServer.js +2 -9
  48. package/src/IncrementalBundler/GraphNotFoundError.d.ts +17 -0
  49. package/src/IncrementalBundler/ResourceNotFoundError.d.ts +15 -0
  50. package/src/IncrementalBundler/RevisionNotFoundError.d.ts +17 -0
  51. package/src/IncrementalBundler.d.ts +96 -0
  52. package/src/IncrementalBundler.js +2 -9
  53. package/src/ModuleGraph/worker/JsFileWrapping.d.ts +29 -0
  54. package/src/ModuleGraph/worker/JsFileWrapping.js +2 -9
  55. package/src/ModuleGraph/worker/collectDependencies.d.ts +131 -0
  56. package/src/ModuleGraph/worker/collectDependencies.js +2 -9
  57. package/src/ModuleGraph/worker/generateImportNames.d.ts +19 -0
  58. package/src/ModuleGraph/worker/generateImportNames.js +1 -5
  59. package/src/ModuleGraph/worker/importLocationsPlugin.d.ts +26 -0
  60. package/src/Server/MultipartResponse.d.ts +30 -0
  61. package/src/Server/MultipartResponse.js +1 -5
  62. package/src/Server/symbolicate.d.ts +31 -0
  63. package/src/Server.d.ts +271 -0
  64. package/src/Server.js +47 -15
  65. package/src/Server.js.flow +57 -10
  66. package/src/cli/parseKeyValueParamArray.d.ts +14 -0
  67. package/src/cli-utils.d.ts +19 -0
  68. package/src/cli-utils.js +1 -5
  69. package/src/commands/build.d.ts +16 -0
  70. package/src/commands/build.js +1 -5
  71. package/src/commands/dependencies.d.ts +16 -0
  72. package/src/commands/dependencies.js +1 -5
  73. package/src/commands/serve.d.ts +16 -0
  74. package/src/index.d.ts +180 -0
  75. package/src/index.flow.js +26 -19
  76. package/src/index.flow.js.flow +25 -10
  77. package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-import.js +1 -5
  78. package/src/integration_tests/basic_bundle/build-errors/inline-requires-cannot-resolve-import.js +1 -5
  79. package/src/integration_tests/basic_bundle/import-export/index.js +2 -9
  80. package/src/integration_tests/execBundle.js +1 -5
  81. package/src/lib/BatchProcessor.d.ts +54 -0
  82. package/src/lib/BatchProcessor.js +1 -5
  83. package/src/lib/CountingSet.d.ts +48 -0
  84. package/src/lib/JsonReporter.d.ts +37 -0
  85. package/src/lib/RamBundleParser.d.ts +29 -0
  86. package/src/lib/RamBundleParser.js +1 -5
  87. package/src/lib/TerminalReporter.d.ts +118 -0
  88. package/src/lib/TerminalReporter.js +8 -16
  89. package/src/lib/TerminalReporter.js.flow +6 -15
  90. package/src/lib/bundleProgressUtils.d.ts +26 -0
  91. package/src/lib/bundleProgressUtils.js +19 -0
  92. package/src/lib/bundleProgressUtils.js.flow +35 -0
  93. package/src/lib/bundleToString.d.ts +19 -0
  94. package/src/lib/contextModule.d.ts +33 -0
  95. package/src/lib/contextModule.js +1 -5
  96. package/src/lib/contextModuleTemplates.d.ts +25 -0
  97. package/src/lib/contextModuleTemplates.js +1 -4
  98. package/src/lib/countLines.d.ts +12 -0
  99. package/src/lib/createWebsocketServer.d.ts +43 -0
  100. package/src/lib/createWebsocketServer.js +1 -5
  101. package/src/lib/debounceAsyncQueue.d.ts +15 -0
  102. package/src/lib/formatBundlingError.d.ts +23 -0
  103. package/src/lib/formatBundlingError.js +1 -5
  104. package/src/lib/getAppendScripts.d.ts +31 -0
  105. package/src/lib/getAppendScripts.js +1 -5
  106. package/src/lib/getGraphId.d.ts +25 -0
  107. package/src/lib/getGraphId.js +1 -5
  108. package/src/lib/getPreludeCode.d.ts +18 -0
  109. package/src/lib/getPrependedScripts.d.ts +24 -0
  110. package/src/lib/getPrependedScripts.js +2 -9
  111. package/src/lib/isResolvedDependency.d.ts +15 -0
  112. package/src/lib/logToConsole.d.ts +19 -0
  113. package/src/lib/logToConsole.js +1 -5
  114. package/src/lib/parseBundleOptionsFromBundleRequestUrl.d.ts +17 -0
  115. package/src/lib/parseBundleOptionsFromBundleRequestUrl.js +2 -9
  116. package/src/lib/parseCustomResolverOptions.d.ts +16 -0
  117. package/src/lib/parseCustomTransformOptions.d.ts +16 -0
  118. package/src/lib/parseJsonBody.d.ts +27 -0
  119. package/src/lib/pathUtils.d.ts +14 -0
  120. package/src/lib/pathUtils.js +1 -4
  121. package/src/lib/relativizeSourceMap.d.ts +17 -0
  122. package/src/lib/relativizeSourceMap.js +1 -5
  123. package/src/lib/reporting.d.ts +128 -0
  124. package/src/lib/reporting.js +1 -5
  125. package/src/lib/splitBundleOptions.d.ts +16 -0
  126. package/src/lib/transformHelpers.d.ts +35 -0
  127. package/src/lib/transformHelpers.js +1 -5
  128. package/src/node-haste/DependencyGraph/ModuleResolution.d.ts +126 -0
  129. package/src/node-haste/DependencyGraph/ModuleResolution.js +2 -9
  130. package/src/node-haste/DependencyGraph/createFileMap.d.ts +29 -0
  131. package/src/node-haste/DependencyGraph/createFileMap.js +2 -9
  132. package/src/node-haste/DependencyGraph.d.ts +86 -0
  133. package/src/node-haste/DependencyGraph.js +1 -5
  134. package/src/node-haste/Package.d.ts +21 -0
  135. package/src/node-haste/Package.js +1 -5
  136. package/src/node-haste/PackageCache.d.ts +34 -0
  137. package/src/node-haste/PackageCache.js +1 -5
  138. package/src/node-haste/lib/AssetPaths.d.ts +29 -0
  139. package/src/node-haste/lib/AssetPaths.js +1 -5
  140. package/src/node-haste/lib/parsePlatformFilePath.d.ts +25 -0
  141. package/src/node-haste/lib/parsePlatformFilePath.js +1 -5
  142. package/src/shared/output/RamBundle/as-assets.d.ts +25 -0
  143. package/src/shared/output/RamBundle/as-assets.js +1 -5
  144. package/src/shared/output/RamBundle/as-indexed-file.d.ts +38 -0
  145. package/src/shared/output/RamBundle/as-indexed-file.js +1 -5
  146. package/src/shared/output/RamBundle/buildSourcemapWithMetadata.d.ts +23 -0
  147. package/src/shared/output/RamBundle/magic-number.d.ts +14 -0
  148. package/src/shared/output/RamBundle/util.d.ts +41 -0
  149. package/src/shared/output/RamBundle/util.js +1 -5
  150. package/src/shared/output/RamBundle/write-sourcemap.d.ts +16 -0
  151. package/src/shared/output/RamBundle/write-sourcemap.js +1 -5
  152. package/src/shared/output/RamBundle.d.ts +26 -0
  153. package/src/shared/output/RamBundle.js +1 -5
  154. package/src/shared/output/bundle.d.ts +27 -0
  155. package/src/shared/output/bundle.flow.js +1 -5
  156. package/src/shared/output/meta.d.ts +15 -0
  157. package/src/shared/output/meta.js +1 -5
  158. package/src/shared/output/unbundle.d.ts +11 -0
  159. package/src/shared/output/writeFile.d.ts +16 -0
  160. package/src/shared/output/writeFile.js +1 -5
  161. package/src/shared/types.d.ts +145 -0
@@ -52,6 +52,7 @@ import getRamBundleInfo from './DeltaBundler/Serializers/getRamBundleInfo';
52
52
  import {sourceMapStringNonBlocking} from './DeltaBundler/Serializers/sourceMapString';
53
53
  import IncrementalBundler from './IncrementalBundler';
54
54
  import ResourceNotFoundError from './IncrementalBundler/ResourceNotFoundError';
55
+ import {calculateBundleProgressRatio} from './lib/bundleProgressUtils';
55
56
  import bundleToString from './lib/bundleToString';
56
57
  import formatBundlingError from './lib/formatBundlingError';
57
58
  import getGraphId from './lib/getGraphId';
@@ -130,6 +131,13 @@ export type ServerOptions = Readonly<{
130
131
  const DELTA_ID_HEADER = 'X-Metro-Delta-ID';
131
132
  const FILES_CHANGED_COUNT_HEADER = 'X-Metro-Files-Changed-Count';
132
133
 
134
+ type FetchTiming = {
135
+ graphId: GraphId,
136
+ startTime: number,
137
+ endTime: number | null,
138
+ isPrefetch: boolean,
139
+ };
140
+
133
141
  export default class Server {
134
142
  _bundler: IncrementalBundler;
135
143
  _config: ConfigT;
@@ -144,6 +152,8 @@ export default class Server {
144
152
  _sourceRequestRoutingMap: ReadonlyArray<
145
153
  [pathnamePrefix: string, normalizedRootDir: string],
146
154
  >;
155
+ _fetchTimings: Array<FetchTiming>;
156
+ _activeFetchCount: number;
147
157
 
148
158
  constructor(config: ConfigT, options?: ServerOptions) {
149
159
  this._config = config;
@@ -176,6 +186,8 @@ export default class Server {
176
186
  ]),
177
187
  ];
178
188
  this._isEnded = false;
189
+ this._fetchTimings = [];
190
+ this._activeFetchCount = 0;
179
191
 
180
192
  // TODO(T34760917): These two properties should eventually be instantiated
181
193
  // elsewhere and passed as parameters, since they are also needed by
@@ -846,25 +858,23 @@ export default class Server {
846
858
  const mres = MultipartResponse.wrapIfSupported(req, res);
847
859
 
848
860
  let onProgress = null;
849
- let lastProgress = -1;
861
+ let lastRatio = -1;
850
862
  if (this._config.reporter) {
851
863
  onProgress = (transformedFileCount: number, totalFileCount: number) => {
852
- const currentProgress = parseInt(
853
- (transformedFileCount / totalFileCount) * 100,
854
- 10,
864
+ const newRatio = calculateBundleProgressRatio(
865
+ transformedFileCount,
866
+ totalFileCount,
867
+ lastRatio,
855
868
  );
856
869
 
857
- // We want to throttle the updates so that we only show meaningful
858
- // UI updates slow enough for the client to actually handle them. For
859
- // that, we check the percentage, and only send percentages that are
860
- // actually different and that have increased from the last one we sent.
861
- if (currentProgress > lastProgress || totalFileCount < 10) {
870
+ if (newRatio > lastRatio) {
862
871
  if (mres instanceof MultipartResponse) {
863
872
  mres.writeChunk(
864
873
  {'Content-Type': 'application/json'},
865
874
  JSON.stringify({
866
875
  done: transformedFileCount,
867
876
  total: totalFileCount,
877
+ percent: Math.floor(newRatio * 100),
868
878
  }),
869
879
  );
870
880
  }
@@ -880,7 +890,7 @@ export default class Server {
880
890
  res.socket.uncork();
881
891
  }
882
892
 
883
- lastProgress = currentProgress;
893
+ lastRatio = newRatio;
884
894
  }
885
895
 
886
896
  this._reporter.update({
@@ -926,8 +936,18 @@ export default class Server {
926
936
  createActionStartEntry(createStartEntry(startContext)),
927
937
  );
928
938
 
939
+ const fetchTiming: FetchTiming = {
940
+ graphId,
941
+ startTime: requestStartTimestamp,
942
+ endTime: null,
943
+ isPrefetch: req.method === 'HEAD',
944
+ };
945
+
929
946
  let result;
930
947
  try {
948
+ this._fetchTimings.push(fetchTiming);
949
+ this._activeFetchCount++;
950
+
931
951
  result = await build(startContext);
932
952
  } catch (error) {
933
953
  const formattedError = formatBundlingError(error);
@@ -960,6 +980,33 @@ export default class Server {
960
980
  buildContext.bundlePerfLogger.end('FAIL');
961
981
 
962
982
  return;
983
+ } finally {
984
+ fetchTiming.endTime = performance.timeOrigin + performance.now();
985
+
986
+ if (!fetchTiming.isPrefetch) {
987
+ buildContext.bundlePerfLogger.annotate({
988
+ bool: {
989
+ had_competing_prefetch: this._fetchTimings
990
+ // fetching the same bundle as a prefetch don't compete, since they resolve a shared promise for the same graph id
991
+ .filter(t => t.isPrefetch && t.graphId !== graphId)
992
+ .some(prefetch => {
993
+ const prefetchEndTime =
994
+ prefetch.endTime ?? Number.MAX_SAFE_INTEGER;
995
+ const fetchEndTime =
996
+ fetchTiming.endTime ?? Number.MAX_SAFE_INTEGER;
997
+ return (
998
+ prefetch.startTime < fetchEndTime &&
999
+ prefetchEndTime > fetchTiming.startTime
1000
+ );
1001
+ }),
1002
+ },
1003
+ });
1004
+ }
1005
+
1006
+ this._activeFetchCount--;
1007
+ if (this._activeFetchCount === 0) {
1008
+ this._fetchTimings = [];
1009
+ }
963
1010
  }
964
1011
 
965
1012
  const endContext: ProcessEndContext<T> = {
@@ -0,0 +1,14 @@
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
+ declare function coerceKeyValueArray(keyValueArray: ReadonlyArray<string>): {
12
+ [key: string]: string;
13
+ };
14
+ export default coerceKeyValueArray;
@@ -0,0 +1,19 @@
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 declare const watchFile: (
12
+ filename: string,
13
+ callback: () => unknown,
14
+ ) => Promise<void>;
15
+ export declare type watchFile = typeof watchFile;
16
+ export declare const makeAsyncCommand: <T>(
17
+ command: (argv: T) => Promise<void>,
18
+ ) => (argv: T) => void;
19
+ export declare type makeAsyncCommand = typeof makeAsyncCommand;
package/src/cli-utils.js CHANGED
@@ -6,11 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.watchFile = exports.makeAsyncCommand = void 0;
7
7
  var _fs = _interopRequireDefault(require("fs"));
8
8
  function _interopRequireDefault(e) {
9
- return e && e.__esModule
10
- ? e
11
- : {
12
- default: e,
13
- };
9
+ return e && e.__esModule ? e : { default: e };
14
10
  }
15
11
  const watchFile = async function (filename, callback) {
16
12
  _fs.default.watchFile(filename, () => {
@@ -0,0 +1,16 @@
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 {CommandModule} from 'yargs';
12
+
13
+ declare const $$EXPORT_DEFAULT_DECLARATION$$: () => CommandModule;
14
+ declare type $$EXPORT_DEFAULT_DECLARATION$$ =
15
+ typeof $$EXPORT_DEFAULT_DECLARATION$$;
16
+ export default $$EXPORT_DEFAULT_DECLARATION$$;
@@ -14,11 +14,7 @@ var _TerminalReporter = _interopRequireDefault(
14
14
  var _metroConfig = require("metro-config");
15
15
  var _metroCore = require("metro-core");
16
16
  function _interopRequireDefault(e) {
17
- return e && e.__esModule
18
- ? e
19
- : {
20
- default: e,
21
- };
17
+ return e && e.__esModule ? e : { default: e };
22
18
  }
23
19
  const term = new _metroCore.Terminal(process.stdout);
24
20
  const updateReporter = new _TerminalReporter.default(term);
@@ -0,0 +1,16 @@
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 {CommandModule} from 'yargs';
12
+
13
+ declare const $$EXPORT_DEFAULT_DECLARATION$$: () => CommandModule;
14
+ declare type $$EXPORT_DEFAULT_DECLARATION$$ =
15
+ typeof $$EXPORT_DEFAULT_DECLARATION$$;
16
+ export default $$EXPORT_DEFAULT_DECLARATION$$;
@@ -11,11 +11,7 @@ var _metroConfig = require("metro-config");
11
11
  var _path = _interopRequireDefault(require("path"));
12
12
  var _util = require("util");
13
13
  function _interopRequireDefault(e) {
14
- return e && e.__esModule
15
- ? e
16
- : {
17
- default: e,
18
- };
14
+ return e && e.__esModule ? e : { default: e };
19
15
  }
20
16
  async function dependencies(args, config) {
21
17
  const rootModuleAbsolutePath = args.entryFile;
@@ -0,0 +1,16 @@
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 {CommandModule} from 'yargs';
12
+
13
+ declare const $$EXPORT_DEFAULT_DECLARATION$$: () => CommandModule;
14
+ declare type $$EXPORT_DEFAULT_DECLARATION$$ =
15
+ typeof $$EXPORT_DEFAULT_DECLARATION$$;
16
+ export default $$EXPORT_DEFAULT_DECLARATION$$;
package/src/index.d.ts ADDED
@@ -0,0 +1,180 @@
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 './Assets';
12
+ import type {ReadOnlyGraph} from './DeltaBundler';
13
+ import type {ServerOptions} from './Server';
14
+ import type {BuildOptions, OutputOptions, RequestOptions} from './shared/types';
15
+ import type {HandleFunction} from 'connect';
16
+ import type {Server as HttpServer} from 'http';
17
+ import type {
18
+ Server as HttpsServer,
19
+ ServerOptions as HttpsServerOptions,
20
+ } from 'https';
21
+ import type {TransformProfile} from 'metro-babel-transformer';
22
+ import type {
23
+ ConfigT,
24
+ InputConfigT,
25
+ MetroConfig,
26
+ Middleware,
27
+ } from 'metro-config';
28
+ import type {CustomResolverOptions} from 'metro-resolver';
29
+ import type {CustomTransformOptions} from 'metro-transform-worker';
30
+ import type {Server as WebSocketServer} from 'ws';
31
+ import type $$IMPORT_TYPEOF_1$$ from 'yargs';
32
+
33
+ import JsonReporter from './lib/JsonReporter';
34
+ import TerminalReporter from './lib/TerminalReporter';
35
+ import MetroServer from './Server';
36
+ import {loadConfig, mergeConfig, resolveConfig} from 'metro-config';
37
+ import {Terminal} from 'metro-core';
38
+
39
+ type Yargs = typeof $$IMPORT_TYPEOF_1$$;
40
+ type MetroMiddleWare = {
41
+ attachHmrServer: (httpServer: HttpServer | HttpsServer) => void;
42
+ end: () => Promise<void>;
43
+ metroServer: MetroServer;
44
+ middleware: Middleware;
45
+ };
46
+ export type RunMetroOptions = Omit<
47
+ ServerOptions,
48
+ keyof {waitForBundler?: boolean}
49
+ > & {waitForBundler?: boolean};
50
+ export type RunServerOptions = Readonly<{
51
+ hasReducedPerformance?: boolean;
52
+ host?: string;
53
+ onError?: ($$PARAM_0$$: Error & {code?: string}) => void;
54
+ onReady?: (server: HttpServer | HttpsServer) => void;
55
+ onClose?: () => void;
56
+ secureServerOptions?: HttpsServerOptions;
57
+ secure?: boolean;
58
+ secureCert?: string;
59
+ secureKey?: string;
60
+ unstable_extraMiddleware?: ReadonlyArray<HandleFunction>;
61
+ waitForBundler?: boolean;
62
+ watch?: boolean;
63
+ websocketEndpoints?: Readonly<{[path: string]: WebSocketServer}>;
64
+ }>;
65
+ export type RunServerResult = {httpServer: HttpServer | HttpsServer};
66
+ type BuildGraphOptions = {
67
+ entries: ReadonlyArray<string>;
68
+ customTransformOptions?: CustomTransformOptions;
69
+ dev?: boolean;
70
+ minify?: boolean;
71
+ onProgress?: (transformedFileCount: number, totalFileCount: number) => void;
72
+ platform?: string;
73
+ type?: 'module' | 'script';
74
+ };
75
+ export type RunBuildOptions = {
76
+ entry: string;
77
+ assets?: boolean;
78
+ dev?: boolean;
79
+ out?: string;
80
+ bundleOut?: string;
81
+ sourceMapOut?: string;
82
+ onBegin?: () => void;
83
+ onComplete?: () => void;
84
+ onProgress?: (transformedFileCount: number, totalFileCount: number) => void;
85
+ minify?: boolean;
86
+ output?: Readonly<{
87
+ build: (
88
+ $$PARAM_0$$: MetroServer,
89
+ $$PARAM_1$$: RequestOptions,
90
+ $$PARAM_2$$: void | BuildOptions,
91
+ ) => Promise<{
92
+ code: string;
93
+ map: string;
94
+ assets?: ReadonlyArray<AssetData>;
95
+ }>;
96
+ save: (
97
+ $$PARAM_0$$: {code: string; map: string},
98
+ $$PARAM_1$$: OutputOptions,
99
+ $$PARAM_2$$: (logMessage: string) => void,
100
+ ) => Promise<unknown>;
101
+ }>;
102
+ platform?: string;
103
+ sourceMap?: boolean;
104
+ sourceMapUrl?: string;
105
+ customResolverOptions?: CustomResolverOptions;
106
+ customTransformOptions?: CustomTransformOptions;
107
+ unstable_transformProfile?: TransformProfile;
108
+ };
109
+ export type RunBuildResult = {
110
+ code: string;
111
+ map: string;
112
+ assets?: ReadonlyArray<AssetData>;
113
+ };
114
+ type BuildCommandOptions = Readonly<{[$$Key$$: string]: unknown}> | null;
115
+ type ServeCommandOptions = Readonly<{[$$Key$$: string]: unknown}> | null;
116
+ type DependenciesCommandOptions = Readonly<{
117
+ [$$Key$$: string]: unknown;
118
+ }> | null;
119
+ export {Terminal, JsonReporter, TerminalReporter};
120
+ export type {AssetData} from './Assets';
121
+ export type {Reporter, ReportableEvent} from './lib/reporting';
122
+ export type {TerminalReportableEvent} from './lib/TerminalReporter';
123
+ export type {MetroConfig};
124
+ export declare function runMetro(
125
+ config: InputConfigT,
126
+ options?: RunMetroOptions,
127
+ ): Promise<MetroServer>;
128
+ export {loadConfig, mergeConfig, resolveConfig};
129
+ export declare const createConnectMiddleware: (
130
+ config: ConfigT,
131
+ options?: RunMetroOptions,
132
+ ) => Promise<MetroMiddleWare>;
133
+ export declare type createConnectMiddleware = typeof createConnectMiddleware;
134
+ export declare const runServer: (
135
+ config: ConfigT,
136
+ $$PARAM_1$$?: RunServerOptions,
137
+ ) => Promise<RunServerResult>;
138
+ export declare type runServer = typeof runServer;
139
+ export declare const runBuild: (
140
+ config: ConfigT,
141
+ $$PARAM_1$$: RunBuildOptions,
142
+ ) => Promise<RunBuildResult>;
143
+ export declare type runBuild = typeof runBuild;
144
+ export declare const buildGraph: (
145
+ config: InputConfigT,
146
+ $$PARAM_1$$: BuildGraphOptions,
147
+ ) => Promise<ReadOnlyGraph>;
148
+ export declare type buildGraph = typeof buildGraph;
149
+ type AttachMetroCLIOptions = {
150
+ build?: BuildCommandOptions;
151
+ serve?: ServeCommandOptions;
152
+ dependencies?: DependenciesCommandOptions;
153
+ };
154
+ export declare const attachMetroCli: (
155
+ yargs: Yargs,
156
+ options?: AttachMetroCLIOptions,
157
+ ) => Yargs;
158
+ export declare type attachMetroCli = typeof attachMetroCli;
159
+ /**
160
+ * Backwards-compatibility with CommonJS consumers using interopRequireDefault.
161
+ * Do not add to this list.
162
+ *
163
+ * @deprecated Default import from 'metro' is deprecated, use named exports.
164
+ */
165
+ declare const $$EXPORT_DEFAULT_DECLARATION$$: {
166
+ attachMetroCli: typeof attachMetroCli;
167
+ runServer: typeof runServer;
168
+ Terminal: typeof Terminal;
169
+ JsonReporter: typeof JsonReporter;
170
+ TerminalReporter: typeof TerminalReporter;
171
+ loadConfig: typeof loadConfig;
172
+ mergeConfig: typeof mergeConfig;
173
+ resolveConfig: typeof resolveConfig;
174
+ createConnectMiddleware: typeof createConnectMiddleware;
175
+ runBuild: typeof runBuild;
176
+ buildGraph: typeof buildGraph;
177
+ };
178
+ declare type $$EXPORT_DEFAULT_DECLARATION$$ =
179
+ typeof $$EXPORT_DEFAULT_DECLARATION$$;
180
+ export default $$EXPORT_DEFAULT_DECLARATION$$;
package/src/index.flow.js CHANGED
@@ -79,10 +79,7 @@ function _interopRequireWildcard(e, t) {
79
79
  if (!t && e && e.__esModule) return e;
80
80
  var o,
81
81
  i,
82
- f = {
83
- __proto__: null,
84
- default: e,
85
- };
82
+ f = { __proto__: null, default: e };
86
83
  if (null === e || ("object" != typeof e && "function" != typeof e))
87
84
  return f;
88
85
  if ((o = t ? n : r)) {
@@ -102,11 +99,7 @@ function _interopRequireWildcard(e, t) {
102
99
  })(e, t);
103
100
  }
104
101
  function _interopRequireDefault(e) {
105
- return e && e.__esModule
106
- ? e
107
- : {
108
- default: e,
109
- };
102
+ return e && e.__esModule ? e : { default: e };
110
103
  }
111
104
  const DEFAULTS = _Server.default.DEFAULT_BUNDLE_OPTIONS;
112
105
  async function getConfig(config) {
@@ -211,7 +204,7 @@ const runServer = async (
211
204
  _chalk.default.inverse.yellow.bold(" DEPRECATED "),
212
205
  "The `secure`, `secureCert`, and `secureKey` options are now deprecated. " +
213
206
  "Please use the `secureServerOptions` object instead to pass options to " +
214
- "Metro's https development server.",
207
+ "Metro's https development server, or `config.server.tls` in Metro's configuration",
215
208
  );
216
209
  }
217
210
  const connect = require("connect");
@@ -230,15 +223,29 @@ const runServer = async (
230
223
  }
231
224
  serverApp.use(middleware);
232
225
  let httpServer;
233
- if (secure === true || secureServerOptions != null) {
234
- let options = secureServerOptions;
235
- if (typeof secureKey === "string" && typeof secureCert === "string") {
236
- options = {
237
- key: _fs.default.readFileSync(secureKey),
238
- cert: _fs.default.readFileSync(secureCert),
239
- ...secureServerOptions,
240
- };
241
- }
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
+ };
242
249
  httpServer = _https.default.createServer(options, serverApp);
243
250
  } else {
244
251
  httpServer = _http.default.createServer(serverApp);
@@ -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
- if (secure === true || secureServerOptions != null) {
311
- let options = secureServerOptions;
312
- if (typeof secureKey === 'string' && typeof secureCert === 'string') {
313
- options = {
314
- key: fs.readFileSync(secureKey),
315
- cert: fs.readFileSync(secureCert),
316
- ...secureServerOptions,
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 {
@@ -2,10 +2,6 @@
2
2
 
3
3
  var _doesNotExist = _interopRequireDefault(require("./does-not-exist"));
4
4
  function _interopRequireDefault(e) {
5
- return e && e.__esModule
6
- ? e
7
- : {
8
- default: e,
9
- };
5
+ return e && e.__esModule ? e : { default: e };
10
6
  }
11
7
  global.x = _doesNotExist.default;
@@ -2,10 +2,6 @@
2
2
 
3
3
  var _doesNotExist = _interopRequireDefault(require("./does-not-exist"));
4
4
  function _interopRequireDefault(e) {
5
- return e && e.__esModule
6
- ? e
7
- : {
8
- default: e,
9
- };
5
+ return e && e.__esModule ? e : { default: e };
10
6
  }
11
7
  global.x = _doesNotExist.default;
@@ -30,11 +30,7 @@ var _exportPrimitiveDefault = _interopRequireWildcard(
30
30
  var _export3 = _interopRequireDefault(require("./export-3"));
31
31
  var _export4 = require("./export-4");
32
32
  function _interopRequireDefault(e) {
33
- return e && e.__esModule
34
- ? e
35
- : {
36
- default: e,
37
- };
33
+ return e && e.__esModule ? e : { default: e };
38
34
  }
39
35
  function _interopRequireWildcard(e, t) {
40
36
  if ("function" == typeof WeakMap)
@@ -44,10 +40,7 @@ function _interopRequireWildcard(e, t) {
44
40
  if (!t && e && e.__esModule) return e;
45
41
  var o,
46
42
  i,
47
- f = {
48
- __proto__: null,
49
- default: e,
50
- };
43
+ f = { __proto__: null, default: e };
51
44
  if (null === e || ("object" != typeof e && "function" != typeof e))
52
45
  return f;
53
46
  if ((o = t ? n : r)) {
@@ -2,11 +2,7 @@
2
2
 
3
3
  var _vm = _interopRequireDefault(require("vm"));
4
4
  function _interopRequireDefault(e) {
5
- return e && e.__esModule
6
- ? e
7
- : {
8
- default: e,
9
- };
5
+ return e && e.__esModule ? e : { default: e };
10
6
  }
11
7
  module.exports = function execBundle(code, context = {}) {
12
8
  if (_vm.default.isContext(context)) {
@@ -0,0 +1,54 @@
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 {setTimeout} from 'timers';
12
+
13
+ type ProcessBatch<TItem, TResult> = (
14
+ batch: Array<TItem>,
15
+ ) => Promise<Array<TResult>>;
16
+ type BatchProcessorOptions = {
17
+ maximumDelayMs: number;
18
+ maximumItems: number;
19
+ concurrency: number;
20
+ };
21
+ type QueueItem<TItem, TResult> = {
22
+ item: TItem;
23
+ reject: (error: unknown) => unknown;
24
+ resolve: (result: TResult) => unknown;
25
+ };
26
+ /**
27
+ * We batch items together trying to minimize their processing, for example as
28
+ * network queries. For that we wait a small moment before processing a batch.
29
+ * We limit also the number of items we try to process in a single batch so that
30
+ * if we have many items pending in a short amount of time, we can start
31
+ * processing right away.
32
+ */
33
+ declare class BatchProcessor<TItem, TResult> {
34
+ _currentProcessCount: number;
35
+ _options: BatchProcessorOptions;
36
+ _processBatch: ProcessBatch<TItem, TResult>;
37
+ _queue: Array<QueueItem<TItem, TResult>>;
38
+ _timeoutHandle: null | undefined | ReturnType<typeof setTimeout>;
39
+ constructor(
40
+ options: BatchProcessorOptions,
41
+ processBatch: ProcessBatch<TItem, TResult>,
42
+ );
43
+ _onBatchFinished(): void;
44
+ _onBatchResults(
45
+ jobs: Array<QueueItem<TItem, TResult>>,
46
+ results: Array<TResult>,
47
+ ): void;
48
+ _onBatchError(jobs: Array<QueueItem<TItem, TResult>>, error: unknown): void;
49
+ _processQueue(): void;
50
+ _processQueueOnceReady(): void;
51
+ queue(item: TItem): Promise<TResult>;
52
+ getQueueLength(): number;
53
+ }
54
+ export default BatchProcessor;