metro 0.83.4 → 0.83.6

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 (171) hide show
  1. package/package.json +18 -16
  2. package/src/Assets.d.ts +90 -0
  3. package/src/Assets.js +2 -9
  4. package/src/Bundler/util.d.ts +34 -0
  5. package/src/Bundler/util.js +2 -9
  6. package/src/Bundler/util.js.flow +3 -3
  7. package/src/Bundler.d.ts +45 -0
  8. package/src/Bundler.js +1 -5
  9. package/src/DeltaBundler/DeltaCalculator.d.ts +68 -0
  10. package/src/DeltaBundler/DeltaCalculator.js +56 -51
  11. package/src/DeltaBundler/DeltaCalculator.js.flow +72 -61
  12. package/src/DeltaBundler/Graph.d.ts +174 -0
  13. package/src/DeltaBundler/Graph.js +1 -5
  14. package/src/DeltaBundler/Serializers/baseJSBundle.d.ts +27 -0
  15. package/src/DeltaBundler/Serializers/baseJSBundle.js +1 -5
  16. package/src/DeltaBundler/Serializers/getAllFiles.d.ts +29 -0
  17. package/src/DeltaBundler/Serializers/getAssets.d.ts +32 -0
  18. package/src/DeltaBundler/Serializers/getAssets.js +1 -5
  19. package/src/DeltaBundler/Serializers/getExplodedSourceMap.d.ts +33 -0
  20. package/src/DeltaBundler/Serializers/getRamBundleInfo.d.ts +55 -0
  21. package/src/DeltaBundler/Serializers/getRamBundleInfo.js +1 -5
  22. package/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.d.ts +19 -0
  23. package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.d.ts +40 -0
  24. package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.d.ts +24 -0
  25. package/src/DeltaBundler/Serializers/helpers/js.d.ts +37 -0
  26. package/src/DeltaBundler/Serializers/helpers/js.js +2 -9
  27. package/src/DeltaBundler/Serializers/helpers/processModules.d.ts +32 -0
  28. package/src/DeltaBundler/Serializers/hmrJSBundle.d.ts +37 -0
  29. package/src/DeltaBundler/Serializers/hmrJSBundle.js +2 -9
  30. package/src/DeltaBundler/Serializers/sourceMapGenerator.d.ts +36 -0
  31. package/src/DeltaBundler/Serializers/sourceMapGenerator.js +1 -5
  32. package/src/DeltaBundler/Serializers/sourceMapObject.d.ts +30 -0
  33. package/src/DeltaBundler/Serializers/sourceMapString.d.ts +29 -0
  34. package/src/DeltaBundler/Transformer.d.ts +45 -0
  35. package/src/DeltaBundler/Transformer.js +1 -5
  36. package/src/DeltaBundler/Worker.d.ts +44 -0
  37. package/src/DeltaBundler/Worker.flow.js +1 -5
  38. package/src/DeltaBundler/WorkerFarm.d.ts +77 -0
  39. package/src/DeltaBundler/buildSubgraph.d.ts +37 -0
  40. package/src/DeltaBundler/buildSubgraph.js +1 -5
  41. package/src/DeltaBundler/getTransformCacheKey.d.ts +25 -0
  42. package/src/DeltaBundler/getTransformCacheKey.js +4 -6
  43. package/src/DeltaBundler/getTransformCacheKey.js.flow +7 -2
  44. package/src/DeltaBundler/mergeDeltas.d.ts +24 -0
  45. package/src/DeltaBundler/types.d.ts +170 -0
  46. package/src/DeltaBundler/types.js +1 -5
  47. package/src/DeltaBundler.d.ts +67 -0
  48. package/src/DeltaBundler.js +1 -5
  49. package/src/HmrServer.d.ts +98 -0
  50. package/src/HmrServer.js +9 -9
  51. package/src/HmrServer.js.flow +15 -5
  52. package/src/IncrementalBundler/GraphNotFoundError.d.ts +24 -0
  53. package/src/IncrementalBundler/ResourceNotFoundError.d.ts +22 -0
  54. package/src/IncrementalBundler/RevisionNotFoundError.d.ts +24 -0
  55. package/src/IncrementalBundler.d.ts +103 -0
  56. package/src/IncrementalBundler.js +2 -9
  57. package/src/ModuleGraph/worker/JsFileWrapping.d.ts +36 -0
  58. package/src/ModuleGraph/worker/JsFileWrapping.js +2 -9
  59. package/src/ModuleGraph/worker/collectDependencies.d.ts +138 -0
  60. package/src/ModuleGraph/worker/collectDependencies.js +2 -9
  61. package/src/ModuleGraph/worker/generateImportNames.d.ts +26 -0
  62. package/src/ModuleGraph/worker/generateImportNames.js +1 -5
  63. package/src/ModuleGraph/worker/importLocationsPlugin.d.ts +33 -0
  64. package/src/Server/MultipartResponse.d.ts +37 -0
  65. package/src/Server/MultipartResponse.js +1 -5
  66. package/src/Server/symbolicate.d.ts +38 -0
  67. package/src/Server.d.ts +278 -0
  68. package/src/Server.js +47 -15
  69. package/src/Server.js.flow +57 -10
  70. package/src/cli/parseKeyValueParamArray.d.ts +21 -0
  71. package/src/cli-utils.d.ts +26 -0
  72. package/src/cli-utils.js +1 -5
  73. package/src/commands/build.d.ts +23 -0
  74. package/src/commands/build.js +1 -5
  75. package/src/commands/dependencies.d.ts +23 -0
  76. package/src/commands/dependencies.js +1 -5
  77. package/src/commands/serve.d.ts +23 -0
  78. package/src/index.d.ts +206 -0
  79. package/src/index.flow.js +26 -19
  80. package/src/index.flow.js.flow +46 -12
  81. package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-import.js +1 -5
  82. package/src/integration_tests/basic_bundle/build-errors/inline-requires-cannot-resolve-import.js +1 -5
  83. package/src/integration_tests/basic_bundle/import-export/index.js +2 -9
  84. package/src/integration_tests/execBundle.js +1 -5
  85. package/src/lib/BatchProcessor.d.ts +61 -0
  86. package/src/lib/BatchProcessor.js +1 -5
  87. package/src/lib/CountingSet.d.ts +55 -0
  88. package/src/lib/JsonReporter.d.ts +44 -0
  89. package/src/lib/JsonReporter.js.flow +2 -2
  90. package/src/lib/RamBundleParser.d.ts +36 -0
  91. package/src/lib/RamBundleParser.js +1 -5
  92. package/src/lib/TerminalReporter.d.ts +125 -0
  93. package/src/lib/TerminalReporter.js +8 -16
  94. package/src/lib/TerminalReporter.js.flow +6 -15
  95. package/src/lib/bundleProgressUtils.d.ts +33 -0
  96. package/src/lib/bundleProgressUtils.js +19 -0
  97. package/src/lib/bundleProgressUtils.js.flow +35 -0
  98. package/src/lib/bundleToString.d.ts +26 -0
  99. package/src/lib/contextModule.d.ts +40 -0
  100. package/src/lib/contextModule.js +1 -5
  101. package/src/lib/contextModuleTemplates.d.ts +32 -0
  102. package/src/lib/contextModuleTemplates.js +1 -4
  103. package/src/lib/countLines.d.ts +19 -0
  104. package/src/lib/createWebsocketServer.d.ts +50 -0
  105. package/src/lib/createWebsocketServer.js +1 -5
  106. package/src/lib/debounceAsyncQueue.d.ts +22 -0
  107. package/src/lib/formatBundlingError.d.ts +30 -0
  108. package/src/lib/formatBundlingError.js +1 -5
  109. package/src/lib/getAppendScripts.d.ts +38 -0
  110. package/src/lib/getAppendScripts.js +1 -5
  111. package/src/lib/getAppendScripts.js.flow +2 -2
  112. package/src/lib/getGraphId.d.ts +32 -0
  113. package/src/lib/getGraphId.js +1 -5
  114. package/src/lib/getPreludeCode.d.ts +25 -0
  115. package/src/lib/getPrependedScripts.d.ts +31 -0
  116. package/src/lib/getPrependedScripts.js +2 -9
  117. package/src/lib/isResolvedDependency.d.ts +22 -0
  118. package/src/lib/logToConsole.d.ts +26 -0
  119. package/src/lib/logToConsole.js +1 -5
  120. package/src/lib/parseBundleOptionsFromBundleRequestUrl.d.ts +24 -0
  121. package/src/lib/parseBundleOptionsFromBundleRequestUrl.js +2 -9
  122. package/src/lib/parseCustomResolverOptions.d.ts +23 -0
  123. package/src/lib/parseCustomTransformOptions.d.ts +23 -0
  124. package/src/lib/parseJsonBody.d.ts +34 -0
  125. package/src/lib/pathUtils.d.ts +21 -0
  126. package/src/lib/pathUtils.js +1 -4
  127. package/src/lib/relativizeSourceMap.d.ts +24 -0
  128. package/src/lib/relativizeSourceMap.js +1 -5
  129. package/src/lib/reporting.d.ts +135 -0
  130. package/src/lib/reporting.js +1 -5
  131. package/src/lib/splitBundleOptions.d.ts +23 -0
  132. package/src/lib/transformHelpers.d.ts +42 -0
  133. package/src/lib/transformHelpers.js +1 -5
  134. package/src/node-haste/DependencyGraph/ModuleResolution.d.ts +120 -0
  135. package/src/node-haste/DependencyGraph/ModuleResolution.js +6 -31
  136. package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +10 -59
  137. package/src/node-haste/DependencyGraph/createFileMap.d.ts +36 -0
  138. package/src/node-haste/DependencyGraph/createFileMap.js +3 -10
  139. package/src/node-haste/DependencyGraph/createFileMap.js.flow +4 -2
  140. package/src/node-haste/DependencyGraph.d.ts +90 -0
  141. package/src/node-haste/DependencyGraph.js +23 -16
  142. package/src/node-haste/DependencyGraph.js.flow +24 -13
  143. package/src/node-haste/PackageCache.d.ts +37 -0
  144. package/src/node-haste/PackageCache.js +65 -58
  145. package/src/node-haste/PackageCache.js.flow +103 -79
  146. package/src/node-haste/lib/AssetPaths.d.ts +36 -0
  147. package/src/node-haste/lib/AssetPaths.js +1 -5
  148. package/src/node-haste/lib/parsePlatformFilePath.d.ts +32 -0
  149. package/src/node-haste/lib/parsePlatformFilePath.js +1 -5
  150. package/src/shared/output/RamBundle/as-assets.d.ts +32 -0
  151. package/src/shared/output/RamBundle/as-assets.js +1 -5
  152. package/src/shared/output/RamBundle/as-indexed-file.d.ts +45 -0
  153. package/src/shared/output/RamBundle/as-indexed-file.js +1 -5
  154. package/src/shared/output/RamBundle/buildSourcemapWithMetadata.d.ts +30 -0
  155. package/src/shared/output/RamBundle/magic-number.d.ts +21 -0
  156. package/src/shared/output/RamBundle/util.d.ts +48 -0
  157. package/src/shared/output/RamBundle/util.js +1 -5
  158. package/src/shared/output/RamBundle/write-sourcemap.d.ts +23 -0
  159. package/src/shared/output/RamBundle/write-sourcemap.js +1 -5
  160. package/src/shared/output/RamBundle.d.ts +33 -0
  161. package/src/shared/output/RamBundle.js +1 -5
  162. package/src/shared/output/bundle.d.ts +34 -0
  163. package/src/shared/output/bundle.flow.js +1 -5
  164. package/src/shared/output/meta.d.ts +22 -0
  165. package/src/shared/output/meta.js +1 -5
  166. package/src/shared/output/unbundle.d.ts +18 -0
  167. package/src/shared/output/writeFile.d.ts +23 -0
  168. package/src/shared/output/writeFile.js +1 -5
  169. package/src/shared/types.d.ts +152 -0
  170. package/src/node-haste/Package.js +0 -32
  171. package/src/node-haste/Package.js.flow +0 -39
package/src/Server.js CHANGED
@@ -25,6 +25,7 @@ var _IncrementalBundler = _interopRequireDefault(
25
25
  var _ResourceNotFoundError = _interopRequireDefault(
26
26
  require("./IncrementalBundler/ResourceNotFoundError"),
27
27
  );
28
+ var _bundleProgressUtils = require("./lib/bundleProgressUtils");
28
29
  var _bundleToString = _interopRequireDefault(require("./lib/bundleToString"));
29
30
  var _formatBundlingError = _interopRequireDefault(
30
31
  require("./lib/formatBundlingError"),
@@ -66,10 +67,7 @@ function _interopRequireWildcard(e, t) {
66
67
  if (!t && e && e.__esModule) return e;
67
68
  var o,
68
69
  i,
69
- f = {
70
- __proto__: null,
71
- default: e,
72
- };
70
+ f = { __proto__: null, default: e };
73
71
  if (null === e || ("object" != typeof e && "function" != typeof e))
74
72
  return f;
75
73
  if ((o = t ? n : r)) {
@@ -89,11 +87,7 @@ function _interopRequireWildcard(e, t) {
89
87
  })(e, t);
90
88
  }
91
89
  function _interopRequireDefault(e) {
92
- return e && e.__esModule
93
- ? e
94
- : {
95
- default: e,
96
- };
90
+ return e && e.__esModule ? e : { default: e };
97
91
  }
98
92
  const debug = require("debug")("Metro:Server");
99
93
  const { createActionStartEntry, createActionEndEntry, log } = _metroCore.Logger;
@@ -136,6 +130,8 @@ class Server {
136
130
  ]),
137
131
  ];
138
132
  this._isEnded = false;
133
+ this._fetchTimings = [];
134
+ this._activeFetchCount = 0;
139
135
  this._createModuleId = config.serializer.createModuleIdFactory();
140
136
  this._bundler = new _IncrementalBundler.default(config, {
141
137
  hasReducedPerformance: options && options.hasReducedPerformance,
@@ -684,14 +680,16 @@ class Server {
684
680
  }
685
681
  const mres = _MultipartResponse.default.wrapIfSupported(req, res);
686
682
  let onProgress = null;
687
- let lastProgress = -1;
683
+ let lastRatio = -1;
688
684
  if (this._config.reporter) {
689
685
  onProgress = (transformedFileCount, totalFileCount) => {
690
- const currentProgress = parseInt(
691
- (transformedFileCount / totalFileCount) * 100,
692
- 10,
686
+ const newRatio = (0,
687
+ _bundleProgressUtils.calculateBundleProgressRatio)(
688
+ transformedFileCount,
689
+ totalFileCount,
690
+ lastRatio,
693
691
  );
694
- if (currentProgress > lastProgress || totalFileCount < 10) {
692
+ if (newRatio > lastRatio) {
695
693
  if (mres instanceof _MultipartResponse.default) {
696
694
  mres.writeChunk(
697
695
  {
@@ -700,13 +698,14 @@ class Server {
700
698
  JSON.stringify({
701
699
  done: transformedFileCount,
702
700
  total: totalFileCount,
701
+ percent: Math.floor(newRatio * 100),
703
702
  }),
704
703
  );
705
704
  }
706
705
  if (res.socket != null && res.socket.uncork != null) {
707
706
  res.socket.uncork();
708
707
  }
709
- lastProgress = currentProgress;
708
+ lastRatio = newRatio;
710
709
  }
711
710
  this._reporter.update({
712
711
  buildID: getBuildID(buildNumber),
@@ -748,8 +747,16 @@ class Server {
748
747
  const logEntry = log(
749
748
  createActionStartEntry(createStartEntry(startContext)),
750
749
  );
750
+ const fetchTiming = {
751
+ graphId,
752
+ startTime: requestStartTimestamp,
753
+ endTime: null,
754
+ isPrefetch: req.method === "HEAD",
755
+ };
751
756
  let result;
752
757
  try {
758
+ this._fetchTimings.push(fetchTiming);
759
+ this._activeFetchCount++;
753
760
  result = await build(startContext);
754
761
  } catch (error) {
755
762
  const formattedError = (0, _formatBundlingError.default)(error);
@@ -779,6 +786,31 @@ class Server {
779
786
  debug("Bundling error", error);
780
787
  buildContext.bundlePerfLogger.end("FAIL");
781
788
  return;
789
+ } finally {
790
+ fetchTiming.endTime =
791
+ _perf_hooks.performance.timeOrigin + _perf_hooks.performance.now();
792
+ if (!fetchTiming.isPrefetch) {
793
+ buildContext.bundlePerfLogger.annotate({
794
+ bool: {
795
+ had_competing_prefetch: this._fetchTimings
796
+ .filter((t) => t.isPrefetch && t.graphId !== graphId)
797
+ .some((prefetch) => {
798
+ const prefetchEndTime =
799
+ prefetch.endTime ?? Number.MAX_SAFE_INTEGER;
800
+ const fetchEndTime =
801
+ fetchTiming.endTime ?? Number.MAX_SAFE_INTEGER;
802
+ return (
803
+ prefetch.startTime < fetchEndTime &&
804
+ prefetchEndTime > fetchTiming.startTime
805
+ );
806
+ }),
807
+ },
808
+ });
809
+ }
810
+ this._activeFetchCount--;
811
+ if (this._activeFetchCount === 0) {
812
+ this._fetchTimings = [];
813
+ }
782
814
  }
783
815
  const endContext = {
784
816
  ...startContext,
@@ -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,21 @@
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<<ece5a9f14463102dc54489fe7db6b3c8>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro/src/cli/parseKeyValueParamArray.js
13
+ * To regenerate, run:
14
+ * js1 build metro-ts-defs (internal) OR
15
+ * yarn run build-ts-defs (OSS)
16
+ */
17
+
18
+ declare function coerceKeyValueArray(keyValueArray: ReadonlyArray<string>): {
19
+ [key: string]: string;
20
+ };
21
+ export default coerceKeyValueArray;
@@ -0,0 +1,26 @@
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<<b5035a5d26a55e608aca030ee9ee6afa>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro/src/cli-utils.js
13
+ * To regenerate, run:
14
+ * js1 build metro-ts-defs (internal) OR
15
+ * yarn run build-ts-defs (OSS)
16
+ */
17
+
18
+ export declare const watchFile: (
19
+ filename: string,
20
+ callback: () => unknown,
21
+ ) => Promise<void>;
22
+ export declare type watchFile = typeof watchFile;
23
+ export declare const makeAsyncCommand: <T>(
24
+ command: (argv: T) => Promise<void>,
25
+ ) => (argv: T) => void;
26
+ 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,23 @@
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<<10c41709fa9779dd0e12ef411eaef8eb>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro/src/commands/build.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 {CommandModule} from 'yargs';
19
+
20
+ declare const $$EXPORT_DEFAULT_DECLARATION$$: () => CommandModule;
21
+ declare type $$EXPORT_DEFAULT_DECLARATION$$ =
22
+ typeof $$EXPORT_DEFAULT_DECLARATION$$;
23
+ 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,23 @@
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<<a73d915901dde7a679972b78a1e08a3e>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro/src/commands/dependencies.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 {CommandModule} from 'yargs';
19
+
20
+ declare const $$EXPORT_DEFAULT_DECLARATION$$: () => CommandModule;
21
+ declare type $$EXPORT_DEFAULT_DECLARATION$$ =
22
+ typeof $$EXPORT_DEFAULT_DECLARATION$$;
23
+ 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,23 @@
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<<367f11c0b6933f8c8c58718c7dd41e78>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro/src/commands/serve.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 {CommandModule} from 'yargs';
19
+
20
+ declare const $$EXPORT_DEFAULT_DECLARATION$$: () => CommandModule;
21
+ declare type $$EXPORT_DEFAULT_DECLARATION$$ =
22
+ typeof $$EXPORT_DEFAULT_DECLARATION$$;
23
+ export default $$EXPORT_DEFAULT_DECLARATION$$;
package/src/index.d.ts ADDED
@@ -0,0 +1,206 @@
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<<3c6460427c6760887187d6b16151c609>>
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 {
129
+ AsyncDependencyType,
130
+ DeltaResult,
131
+ Dependency,
132
+ MixedOutput,
133
+ Module,
134
+ ReadOnlyDependencies,
135
+ ReadOnlyGraph,
136
+ SerializerOptions,
137
+ TransformInputOptions,
138
+ TransformResult,
139
+ TransformResultDependency,
140
+ } from './DeltaBundler/types';
141
+ export type {default as DependencyGraph} from './node-haste/DependencyGraph';
142
+ export type {BundleDetails, Reporter, ReportableEvent} from './lib/reporting';
143
+ export type {TerminalReportableEvent} from './lib/TerminalReporter';
144
+ export type {
145
+ ContextMode,
146
+ RequireContextParams,
147
+ } from './ModuleGraph/worker/collectDependencies';
148
+ export type {ServerOptions} from './Server';
149
+ export type {MetroConfig, MetroServer};
150
+ export declare function runMetro(
151
+ config: InputConfigT,
152
+ options?: RunMetroOptions,
153
+ ): Promise<MetroServer>;
154
+ export {loadConfig, mergeConfig, resolveConfig};
155
+ export declare const createConnectMiddleware: (
156
+ config: ConfigT,
157
+ options?: RunMetroOptions,
158
+ ) => Promise<MetroMiddleWare>;
159
+ export declare type createConnectMiddleware = typeof createConnectMiddleware;
160
+ export declare const runServer: (
161
+ config: ConfigT,
162
+ $$PARAM_1$$?: RunServerOptions,
163
+ ) => Promise<RunServerResult>;
164
+ export declare type runServer = typeof runServer;
165
+ export declare const runBuild: (
166
+ config: ConfigT,
167
+ $$PARAM_1$$: RunBuildOptions,
168
+ ) => Promise<RunBuildResult>;
169
+ export declare type runBuild = typeof runBuild;
170
+ export declare const buildGraph: (
171
+ config: InputConfigT,
172
+ $$PARAM_1$$: BuildGraphOptions,
173
+ ) => Promise<ReadOnlyGraph>;
174
+ export declare type buildGraph = typeof buildGraph;
175
+ type AttachMetroCLIOptions = {
176
+ build?: BuildCommandOptions;
177
+ serve?: ServeCommandOptions;
178
+ dependencies?: DependenciesCommandOptions;
179
+ };
180
+ export declare const attachMetroCli: (
181
+ yargs: Yargs,
182
+ options?: AttachMetroCLIOptions,
183
+ ) => Yargs;
184
+ export declare type attachMetroCli = typeof attachMetroCli;
185
+ /**
186
+ * Backwards-compatibility with CommonJS consumers using interopRequireDefault.
187
+ * Do not add to this list.
188
+ *
189
+ * @deprecated Default import from 'metro' is deprecated, use named exports.
190
+ */
191
+ declare const $$EXPORT_DEFAULT_DECLARATION$$: {
192
+ attachMetroCli: typeof attachMetroCli;
193
+ runServer: typeof runServer;
194
+ Terminal: typeof Terminal;
195
+ JsonReporter: typeof JsonReporter;
196
+ TerminalReporter: typeof TerminalReporter;
197
+ loadConfig: typeof loadConfig;
198
+ mergeConfig: typeof mergeConfig;
199
+ resolveConfig: typeof resolveConfig;
200
+ createConnectMiddleware: typeof createConnectMiddleware;
201
+ runBuild: typeof runBuild;
202
+ buildGraph: typeof buildGraph;
203
+ };
204
+ declare type $$EXPORT_DEFAULT_DECLARATION$$ =
205
+ typeof $$EXPORT_DEFAULT_DECLARATION$$;
206
+ export default $$EXPORT_DEFAULT_DECLARATION$$;