metro 0.83.3 → 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 (229) hide show
  1. package/package.json +28 -24
  2. package/src/Assets.d.ts +83 -0
  3. package/src/Assets.js +42 -29
  4. package/src/Assets.js.flow +26 -15
  5. package/src/Bundler/util.d.ts +27 -0
  6. package/src/Bundler/util.js +25 -21
  7. package/src/Bundler/util.js.flow +2 -2
  8. package/src/Bundler.d.ts +14 -15
  9. package/src/Bundler.js.flow +1 -1
  10. package/src/DeltaBundler/DeltaCalculator.d.ts +71 -0
  11. package/src/DeltaBundler/DeltaCalculator.js +4 -4
  12. package/src/DeltaBundler/DeltaCalculator.js.flow +8 -8
  13. package/src/DeltaBundler/Graph.d.ts +135 -8
  14. package/src/DeltaBundler/Graph.js +16 -16
  15. package/src/DeltaBundler/Graph.js.flow +30 -30
  16. package/src/DeltaBundler/Serializers/baseJSBundle.d.ts +20 -0
  17. package/src/DeltaBundler/Serializers/baseJSBundle.js.flow +1 -1
  18. package/src/DeltaBundler/Serializers/getAllFiles.d.ts +22 -0
  19. package/src/DeltaBundler/Serializers/getAllFiles.js.flow +2 -2
  20. package/src/DeltaBundler/Serializers/getAssets.d.ts +25 -0
  21. package/src/DeltaBundler/Serializers/getAssets.js.flow +2 -2
  22. package/src/DeltaBundler/Serializers/getExplodedSourceMap.js.flow +2 -2
  23. package/src/DeltaBundler/Serializers/getRamBundleInfo.d.ts +36 -6
  24. package/src/DeltaBundler/Serializers/getRamBundleInfo.js.flow +8 -8
  25. package/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.d.ts +12 -0
  26. package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.d.ts +33 -0
  27. package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.d.ts +17 -0
  28. package/src/DeltaBundler/Serializers/helpers/js.d.ts +30 -0
  29. package/src/DeltaBundler/Serializers/helpers/js.js +25 -21
  30. package/src/DeltaBundler/Serializers/helpers/js.js.flow +6 -6
  31. package/src/DeltaBundler/Serializers/helpers/processModules.d.ts +25 -0
  32. package/src/DeltaBundler/Serializers/helpers/processModules.js.flow +3 -3
  33. package/src/DeltaBundler/Serializers/hmrJSBundle.d.ts +30 -0
  34. package/src/DeltaBundler/Serializers/hmrJSBundle.js +25 -21
  35. package/src/DeltaBundler/Serializers/hmrJSBundle.js.flow +5 -5
  36. package/src/DeltaBundler/Serializers/sourceMapGenerator.d.ts +29 -0
  37. package/src/DeltaBundler/Serializers/sourceMapGenerator.js.flow +6 -6
  38. package/src/DeltaBundler/Serializers/sourceMapObject.d.ts +23 -0
  39. package/src/DeltaBundler/Serializers/sourceMapObject.js.flow +2 -2
  40. package/src/DeltaBundler/Serializers/sourceMapString.d.ts +22 -0
  41. package/src/DeltaBundler/Serializers/sourceMapString.js.flow +2 -2
  42. package/src/DeltaBundler/Transformer.d.ts +38 -0
  43. package/src/DeltaBundler/Transformer.js.flow +3 -3
  44. package/src/DeltaBundler/Worker.d.ts +19 -27
  45. package/src/DeltaBundler/Worker.flow.js.flow +1 -1
  46. package/src/DeltaBundler/WorkerFarm.d.ts +70 -0
  47. package/src/DeltaBundler/WorkerFarm.js +1 -1
  48. package/src/DeltaBundler/WorkerFarm.js.flow +26 -13
  49. package/src/DeltaBundler/buildSubgraph.d.ts +30 -0
  50. package/src/DeltaBundler/buildSubgraph.js +4 -4
  51. package/src/DeltaBundler/buildSubgraph.js.flow +8 -8
  52. package/src/DeltaBundler/getTransformCacheKey.d.ts +18 -0
  53. package/src/DeltaBundler/mergeDeltas.d.ts +17 -0
  54. package/src/DeltaBundler/types.d.ts +97 -100
  55. package/src/DeltaBundler/types.js.flow +36 -34
  56. package/src/DeltaBundler.d.ts +14 -12
  57. package/src/DeltaBundler.js.flow +2 -2
  58. package/src/HmrServer.d.ts +79 -0
  59. package/src/HmrServer.js +34 -29
  60. package/src/HmrServer.js.flow +17 -12
  61. package/src/IncrementalBundler/GraphNotFoundError.d.ts +17 -0
  62. package/src/IncrementalBundler/ResourceNotFoundError.d.ts +15 -0
  63. package/src/IncrementalBundler/RevisionNotFoundError.d.ts +17 -0
  64. package/src/IncrementalBundler.d.ts +43 -45
  65. package/src/IncrementalBundler.js +29 -21
  66. package/src/IncrementalBundler.js.flow +13 -9
  67. package/src/ModuleGraph/worker/JsFileWrapping.d.ts +29 -0
  68. package/src/ModuleGraph/worker/JsFileWrapping.js +25 -21
  69. package/src/ModuleGraph/worker/JsFileWrapping.js.flow +10 -5
  70. package/src/ModuleGraph/worker/collectDependencies.d.ts +118 -14
  71. package/src/ModuleGraph/worker/collectDependencies.js +25 -21
  72. package/src/ModuleGraph/worker/collectDependencies.js.flow +27 -21
  73. package/src/ModuleGraph/worker/generateImportNames.d.ts +19 -0
  74. package/src/ModuleGraph/worker/generateImportNames.js.flow +4 -2
  75. package/src/ModuleGraph/worker/importLocationsPlugin.d.ts +26 -0
  76. package/src/ModuleGraph/worker/importLocationsPlugin.js.flow +7 -3
  77. package/src/Server/MultipartResponse.d.ts +5 -6
  78. package/src/Server/MultipartResponse.js.flow +1 -1
  79. package/src/Server/symbolicate.js.flow +4 -4
  80. package/src/Server.d.ts +220 -67
  81. package/src/Server.js +149 -45
  82. package/src/Server.js.flow +167 -57
  83. package/src/cli/parseKeyValueParamArray.d.ts +14 -0
  84. package/src/cli/parseKeyValueParamArray.js.flow +1 -1
  85. package/src/cli-utils.d.ts +19 -0
  86. package/src/cli-utils.js.flow +2 -2
  87. package/src/commands/build.d.ts +16 -0
  88. package/src/commands/build.js.flow +11 -10
  89. package/src/commands/dependencies.d.ts +16 -0
  90. package/src/commands/dependencies.js.flow +8 -4
  91. package/src/commands/serve.d.ts +16 -0
  92. package/src/commands/serve.js +2 -0
  93. package/src/commands/serve.js.flow +14 -9
  94. package/src/index.d.ts +97 -110
  95. package/src/index.flow.js +53 -35
  96. package/src/index.flow.js.flow +49 -29
  97. package/src/integration_tests/basic_bundle/AssetRegistry.js.flow +1 -1
  98. package/src/integration_tests/basic_bundle/ErrorBundle.js.flow +1 -1
  99. package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-import.js.flow +1 -1
  100. package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-multi-line-import-with-escapes.js.flow +1 -1
  101. package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-multi-line-import.js.flow +1 -1
  102. package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-require-with-embedded-comment.js.flow +1 -1
  103. package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-require.js.flow +1 -1
  104. package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-specifier-with-escapes.js.flow +1 -1
  105. package/src/integration_tests/basic_bundle/build-errors/inline-requires-cannot-resolve-import.js.flow +1 -1
  106. package/src/integration_tests/basic_bundle/build-errors/inline-requires-cannot-resolve-require.js.flow +1 -1
  107. package/src/integration_tests/basic_bundle/import-export/index.js +25 -21
  108. package/src/integration_tests/basic_bundle/import-export/index.js.flow +3 -3
  109. package/src/integration_tests/basic_bundle/import-export/utils.js.flow +2 -2
  110. package/src/integration_tests/basic_bundle/loadBundleAsyncForTest.js.flow +1 -1
  111. package/src/integration_tests/basic_bundle/optional-dependencies/index.js.flow +1 -1
  112. package/src/integration_tests/basic_bundle/require-context/conflict.js.flow +1 -1
  113. package/src/integration_tests/basic_bundle/require-context/empty.js.flow +1 -1
  114. package/src/integration_tests/basic_bundle/require-context/matching.js.flow +1 -1
  115. package/src/integration_tests/basic_bundle/require-context/mode-eager.js.flow +1 -1
  116. package/src/integration_tests/basic_bundle/require-context/mode-lazy-once.js.flow +1 -1
  117. package/src/integration_tests/basic_bundle/require-context/mode-lazy.js.flow +1 -1
  118. package/src/integration_tests/basic_bundle/require-context/mode-sync.js.flow +2 -2
  119. package/src/integration_tests/basic_bundle/require-context/utils.js.flow +1 -1
  120. package/src/integration_tests/basic_bundle/require-resolveWeak/import-and-resolveWeak.js.flow +1 -1
  121. package/src/integration_tests/basic_bundle/require-resolveWeak/multiple.js.flow +1 -1
  122. package/src/integration_tests/basic_bundle/require-resolveWeak/never-required.js.flow +1 -1
  123. package/src/integration_tests/basic_bundle/require-resolveWeak/require-and-resolveWeak.js.flow +1 -1
  124. package/src/integration_tests/execBundle.js.flow +1 -1
  125. package/src/lib/BatchProcessor.d.ts +54 -0
  126. package/src/lib/BatchProcessor.js +5 -2
  127. package/src/lib/BatchProcessor.js.flow +10 -7
  128. package/src/lib/CountingSet.d.ts +10 -10
  129. package/src/lib/CountingSet.js.flow +4 -4
  130. package/src/lib/JsonReporter.d.ts +37 -0
  131. package/src/lib/JsonReporter.js +5 -3
  132. package/src/lib/JsonReporter.js.flow +19 -17
  133. package/src/lib/RamBundleParser.d.ts +29 -0
  134. package/src/lib/RamBundleParser.js.flow +1 -1
  135. package/src/lib/TerminalReporter.d.ts +97 -6
  136. package/src/lib/TerminalReporter.js +37 -34
  137. package/src/lib/TerminalReporter.js.flow +21 -30
  138. package/src/lib/bundleProgressUtils.d.ts +26 -0
  139. package/src/lib/bundleProgressUtils.js +19 -0
  140. package/src/lib/bundleProgressUtils.js.flow +35 -0
  141. package/src/lib/bundleToString.d.ts +19 -0
  142. package/src/lib/contextModule.d.ts +20 -9
  143. package/src/lib/contextModule.js.flow +1 -1
  144. package/src/lib/contextModuleTemplates.d.ts +25 -0
  145. package/src/lib/contextModuleTemplates.js +25 -21
  146. package/src/lib/countLines.d.ts +12 -0
  147. package/src/lib/countLines.js +4 -3
  148. package/src/lib/countLines.js.flow +3 -4
  149. package/src/lib/createWebsocketServer.d.ts +43 -0
  150. package/src/lib/createWebsocketServer.js +9 -2
  151. package/src/lib/createWebsocketServer.js.flow +16 -9
  152. package/src/lib/debounceAsyncQueue.d.ts +15 -0
  153. package/src/lib/debounceAsyncQueue.js.flow +1 -1
  154. package/src/lib/formatBundlingError.d.ts +23 -0
  155. package/src/lib/formatBundlingError.js.flow +1 -1
  156. package/src/lib/getAppendScripts.d.ts +31 -0
  157. package/src/lib/getAppendScripts.js.flow +4 -4
  158. package/src/lib/getGraphId.d.ts +15 -1
  159. package/src/lib/getGraphId.js.flow +1 -1
  160. package/src/lib/getPreludeCode.d.ts +18 -0
  161. package/src/lib/getPreludeCode.js +4 -0
  162. package/src/lib/getPreludeCode.js.flow +10 -3
  163. package/src/lib/getPrependedScripts.d.ts +24 -0
  164. package/src/lib/getPrependedScripts.js +36 -22
  165. package/src/lib/getPrependedScripts.js.flow +10 -3
  166. package/src/lib/isResolvedDependency.d.ts +15 -0
  167. package/src/lib/logToConsole.d.ts +19 -0
  168. package/src/lib/logToConsole.js.flow +2 -2
  169. package/src/lib/parseBundleOptionsFromBundleRequestUrl.d.ts +17 -0
  170. package/src/lib/parseBundleOptionsFromBundleRequestUrl.js +25 -21
  171. package/src/lib/parseCustomResolverOptions.d.ts +16 -0
  172. package/src/lib/parseCustomResolverOptions.js.flow +2 -2
  173. package/src/lib/parseCustomTransformOptions.d.ts +16 -0
  174. package/src/lib/parseCustomTransformOptions.js.flow +1 -1
  175. package/src/lib/parseJsonBody.d.ts +27 -0
  176. package/src/lib/parseJsonBody.js.flow +11 -1
  177. package/src/lib/pathUtils.d.ts +14 -0
  178. package/src/lib/pathUtils.js +25 -21
  179. package/src/lib/pathUtils.js.flow +1 -1
  180. package/src/lib/relativizeSourceMap.d.ts +17 -0
  181. package/src/lib/reporting.d.ts +65 -81
  182. package/src/lib/reporting.js.flow +4 -4
  183. package/src/lib/splitBundleOptions.d.ts +16 -0
  184. package/src/lib/transformHelpers.d.ts +35 -0
  185. package/src/lib/transformHelpers.js +11 -9
  186. package/src/lib/transformHelpers.js.flow +17 -15
  187. package/src/node-haste/DependencyGraph/ModuleResolution.d.ts +126 -0
  188. package/src/node-haste/DependencyGraph/ModuleResolution.js +48 -42
  189. package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +35 -32
  190. package/src/node-haste/DependencyGraph/createFileMap.d.ts +29 -0
  191. package/src/node-haste/DependencyGraph/createFileMap.js +56 -38
  192. package/src/node-haste/DependencyGraph/createFileMap.js.flow +44 -18
  193. package/src/node-haste/DependencyGraph.d.ts +57 -33
  194. package/src/node-haste/DependencyGraph.js +40 -31
  195. package/src/node-haste/DependencyGraph.js.flow +35 -37
  196. package/src/node-haste/Package.d.ts +21 -0
  197. package/src/node-haste/PackageCache.d.ts +34 -0
  198. package/src/node-haste/lib/AssetPaths.d.ts +29 -0
  199. package/src/node-haste/lib/AssetPaths.js +2 -2
  200. package/src/node-haste/lib/AssetPaths.js.flow +4 -4
  201. package/src/node-haste/lib/parsePlatformFilePath.d.ts +25 -0
  202. package/src/node-haste/lib/parsePlatformFilePath.js +6 -6
  203. package/src/node-haste/lib/parsePlatformFilePath.js.flow +4 -4
  204. package/src/shared/output/RamBundle/as-assets.d.ts +25 -0
  205. package/src/shared/output/RamBundle/as-assets.js.flow +6 -6
  206. package/src/shared/output/RamBundle/as-indexed-file.d.ts +38 -0
  207. package/src/shared/output/RamBundle/as-indexed-file.js.flow +5 -5
  208. package/src/shared/output/RamBundle/buildSourcemapWithMetadata.d.ts +23 -0
  209. package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js.flow +5 -5
  210. package/src/shared/output/RamBundle/magic-number.d.ts +14 -0
  211. package/src/shared/output/RamBundle/util.d.ts +41 -0
  212. package/src/shared/output/RamBundle/util.js.flow +5 -5
  213. package/src/shared/output/RamBundle/write-sourcemap.d.ts +16 -0
  214. package/src/shared/output/RamBundle/write-sourcemap.js.flow +1 -1
  215. package/src/shared/output/RamBundle.d.ts +26 -0
  216. package/src/shared/output/RamBundle.js.flow +1 -1
  217. package/src/shared/output/bundle.d.ts +9 -17
  218. package/src/shared/output/bundle.flow.js.flow +3 -3
  219. package/src/shared/output/meta.d.ts +15 -0
  220. package/src/shared/output/meta.js +2 -2
  221. package/src/shared/output/meta.js.flow +1 -1
  222. package/src/shared/output/unbundle.d.ts +11 -0
  223. package/src/shared/output/writeFile.d.ts +16 -0
  224. package/src/shared/output/writeFile.js +8 -3
  225. package/src/shared/output/writeFile.js.flow +8 -2
  226. package/src/shared/types.d.ts +81 -66
  227. package/src/shared/types.js.flow +20 -5
  228. package/src/Asset.d.ts +0 -25
  229. package/src/ModuleGraph/test-helpers.js +0 -75
@@ -4,7 +4,7 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
- * @flow
7
+ * @flow strict-local
8
8
  * @format
9
9
  * @oncall react_native
10
10
  */
@@ -15,7 +15,10 @@ import type {ServerOptions} from './Server';
15
15
  import type {BuildOptions, OutputOptions, RequestOptions} from './shared/types';
16
16
  import type {HandleFunction} from 'connect';
17
17
  import type {Server as HttpServer} from 'http';
18
- import type {Server as HttpsServer} from 'https';
18
+ import type {
19
+ Server as HttpsServer,
20
+ ServerOptions as HttpsServerOptions,
21
+ } from 'https';
19
22
  import type {TransformProfile} from 'metro-babel-transformer';
20
23
  import type {
21
24
  ConfigT,
@@ -25,6 +28,7 @@ import type {
25
28
  } from 'metro-config';
26
29
  import type {CustomResolverOptions} from 'metro-resolver';
27
30
  import type {CustomTransformOptions} from 'metro-transform-worker';
31
+ import type {Server as WebSocketServer} from 'ws';
28
32
  import typeof Yargs from 'yargs';
29
33
 
30
34
  import makeBuildCommand from './commands/build';
@@ -65,21 +69,21 @@ export type RunMetroOptions = {
65
69
  waitForBundler?: boolean,
66
70
  };
67
71
 
68
- export type RunServerOptions = $ReadOnly<{
72
+ export type RunServerOptions = Readonly<{
69
73
  hasReducedPerformance?: boolean,
70
74
  host?: string,
71
75
  onError?: (Error & {code?: string}) => void,
72
76
  onReady?: (server: HttpServer | HttpsServer) => void,
73
77
  onClose?: () => void,
74
- secureServerOptions?: Object,
78
+ secureServerOptions?: HttpsServerOptions,
75
79
  secure?: boolean, // deprecated
76
80
  secureCert?: string, // deprecated
77
81
  secureKey?: string, // deprecated
78
- unstable_extraMiddleware?: $ReadOnlyArray<HandleFunction>,
82
+ unstable_extraMiddleware?: ReadonlyArray<HandleFunction>,
79
83
  waitForBundler?: boolean,
80
84
  watch?: boolean,
81
- websocketEndpoints?: $ReadOnly<{
82
- [path: string]: ws$WebSocketServer,
85
+ websocketEndpoints?: Readonly<{
86
+ [path: string]: WebSocketServer,
83
87
  }>,
84
88
  }>;
85
89
 
@@ -88,7 +92,7 @@ export type RunServerResult = {
88
92
  };
89
93
 
90
94
  type BuildGraphOptions = {
91
- entries: $ReadOnlyArray<string>,
95
+ entries: ReadonlyArray<string>,
92
96
  customTransformOptions?: CustomTransformOptions,
93
97
  dev?: boolean,
94
98
  minify?: boolean,
@@ -108,7 +112,7 @@ export type RunBuildOptions = {
108
112
  onComplete?: () => void,
109
113
  onProgress?: (transformedFileCount: number, totalFileCount: number) => void,
110
114
  minify?: boolean,
111
- output?: $ReadOnly<{
115
+ output?: Readonly<{
112
116
  build: (
113
117
  MetroServer,
114
118
  RequestOptions,
@@ -116,7 +120,7 @@ export type RunBuildOptions = {
116
120
  ) => Promise<{
117
121
  code: string,
118
122
  map: string,
119
- assets?: $ReadOnlyArray<AssetData>,
123
+ assets?: ReadonlyArray<AssetData>,
120
124
  ...
121
125
  }>,
122
126
  save: (
@@ -127,7 +131,7 @@ export type RunBuildOptions = {
127
131
  },
128
132
  OutputOptions,
129
133
  (logMessage: string) => void,
130
- ) => Promise<mixed>,
134
+ ) => Promise<unknown>,
131
135
  ...
132
136
  }>,
133
137
  platform?: string,
@@ -141,12 +145,13 @@ export type RunBuildOptions = {
141
145
  export type RunBuildResult = {
142
146
  code: string,
143
147
  map: string,
144
- assets?: $ReadOnlyArray<AssetData>,
148
+ assets?: ReadonlyArray<AssetData>,
145
149
  ...
146
150
  };
147
151
 
148
- type BuildCommandOptions = {} | null;
149
- type ServeCommandOptions = {} | null;
152
+ type BuildCommandOptions = Readonly<{[string]: unknown}> | null;
153
+ type ServeCommandOptions = Readonly<{[string]: unknown}> | null;
154
+ type DependenciesCommandOptions = Readonly<{[string]: unknown}> | null;
150
155
 
151
156
  export {Terminal, JsonReporter, TerminalReporter};
152
157
 
@@ -263,7 +268,7 @@ export const runServer = async (
263
268
  secureKey, // deprecated
264
269
  unstable_extraMiddleware,
265
270
  waitForBundler = false,
266
- websocketEndpoints = {},
271
+ websocketEndpoints: userWebsocketEndpoints = {},
267
272
  watch,
268
273
  }: RunServerOptions = {},
269
274
  ): Promise<RunServerResult> => {
@@ -275,7 +280,7 @@ export const runServer = async (
275
280
  chalk.inverse.yellow.bold(' DEPRECATED '),
276
281
  'The `secure`, `secureCert`, and `secureKey` options are now deprecated. ' +
277
282
  'Please use the `secureServerOptions` object instead to pass options to ' +
278
- "Metro's https development server.",
283
+ "Metro's https development server, or `config.server.tls` in Metro's configuration",
279
284
  );
280
285
  }
281
286
  // Lazy require
@@ -302,15 +307,30 @@ export const runServer = async (
302
307
 
303
308
  let httpServer;
304
309
 
305
- if (secure || secureServerOptions != null) {
306
- let options = secureServerOptions;
307
- if (typeof secureKey === 'string' && typeof secureCert === 'string') {
308
- options = {
309
- key: fs.readFileSync(secureKey),
310
- cert: fs.readFileSync(secureCert),
311
- ...secureServerOptions,
312
- };
313
- }
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
+
314
334
  // $FlowFixMe[incompatible-type] 'http' and 'https' Flow types do not match
315
335
  httpServer = https.createServer(options, serverApp);
316
336
  } else {
@@ -333,8 +353,8 @@ export const runServer = async (
333
353
  family,
334
354
  });
335
355
 
336
- websocketEndpoints = {
337
- ...websocketEndpoints,
356
+ const websocketEndpoints = {
357
+ ...userWebsocketEndpoints,
338
358
  '/hot': createWebsocketServer({
339
359
  websocketServer: new MetroHmrServer(
340
360
  metroServer.getBundler(),
@@ -441,7 +461,7 @@ export const runBuild = async (
441
461
  onComplete();
442
462
  }
443
463
 
444
- if (out || bundleOut) {
464
+ if (out != null || bundleOut != null) {
445
465
  const bundleOutput =
446
466
  bundleOut ?? nullthrows(out).replace(/(\.js)?$/, '.js');
447
467
 
@@ -510,7 +530,7 @@ export const buildGraph = async function (
510
530
  type AttachMetroCLIOptions = {
511
531
  build?: BuildCommandOptions,
512
532
  serve?: ServeCommandOptions,
513
- dependencies?: any,
533
+ dependencies?: DependenciesCommandOptions,
514
534
  ...
515
535
  };
516
536
 
@@ -11,7 +11,7 @@
11
11
  'use strict';
12
12
 
13
13
  module.exports = {
14
- registerAsset(data: mixed): mixed {
14
+ registerAsset(data: unknown): unknown {
15
15
  return data;
16
16
  },
17
17
  };
@@ -20,4 +20,4 @@ const calcSum = (value: string) => {
20
20
  return error;
21
21
  };
22
22
 
23
- module.exports = (calcSum('anything'): Error);
23
+ module.exports = calcSum('anything') as Error;
@@ -14,4 +14,4 @@ import type DoesNotExistT from './does-not-exist';
14
14
  // $FlowExpectedError[cannot-resolve-module]
15
15
  import DoesNotExist from './does-not-exist';
16
16
 
17
- global.x = (DoesNotExist: DoesNotExistT);
17
+ global.x = DoesNotExist as DoesNotExistT;
@@ -26,4 +26,4 @@ import {
26
26
  // $FlowExpectedError[cannot-resolve-module]
27
27
  } from './does-not\'"-exist';
28
28
 
29
- global.x = (aaaaaaaaaa: DoesNotExistT);
29
+ global.x = aaaaaaaaaa as DoesNotExistT;
@@ -26,4 +26,4 @@ import {
26
26
  // $FlowExpectedError[cannot-resolve-module]
27
27
  } from './does-not-exist';
28
28
 
29
- global.x = (aaaaaaaaaa: DoesNotExistT);
29
+ global.x = aaaaaaaaaa as DoesNotExistT;
@@ -14,4 +14,4 @@ import type DoesNotExistT from './foo';
14
14
  // $FlowExpectedError[cannot-resolve-module]
15
15
  const DoesNotExist = require('./foo' /* ./foo */);
16
16
 
17
- global.x = (DoesNotExist: DoesNotExistT);
17
+ global.x = DoesNotExist as DoesNotExistT;
@@ -14,4 +14,4 @@ import type DoesNotExistT from './does-not-exist';
14
14
  // $FlowExpectedError[cannot-resolve-module]
15
15
  const DoesNotExist = require('./does-not-exist');
16
16
 
17
- global.x = (DoesNotExist: DoesNotExistT);
17
+ global.x = DoesNotExist as DoesNotExistT;
@@ -16,4 +16,4 @@ import type DoesNotExistT from './does-not\'"-exist';
16
16
  // $FlowExpectedError[cannot-resolve-module]
17
17
  import {DoesNotExist} from './does-not\'"-exist';
18
18
 
19
- global.x = (DoesNotExist: DoesNotExistT);
19
+ global.x = DoesNotExist as DoesNotExistT;
@@ -14,4 +14,4 @@ import type DoesNotExistT from './does-not-exist';
14
14
  // $FlowExpectedError[cannot-resolve-module]
15
15
  import DoesNotExist from './does-not-exist';
16
16
 
17
- global.x = (DoesNotExist: DoesNotExistT);
17
+ global.x = DoesNotExist as DoesNotExistT;
@@ -14,4 +14,4 @@ import type DoesNotExistT from './does-not-exist';
14
14
  // $FlowExpectedError[cannot-resolve-module]
15
15
  const DoesNotExist = require('./does-not-exist');
16
16
 
17
- global.x = (DoesNotExist: DoesNotExistT);
17
+ global.x = DoesNotExist as DoesNotExistT;
@@ -32,28 +32,32 @@ var _export4 = require("./export-4");
32
32
  function _interopRequireDefault(e) {
33
33
  return e && e.__esModule ? e : { default: e };
34
34
  }
35
- function _getRequireWildcardCache(e) {
36
- if ("function" != typeof WeakMap) return null;
37
- var r = new WeakMap(),
38
- t = new WeakMap();
39
- return (_getRequireWildcardCache = function (e) {
40
- return e ? t : r;
41
- })(e);
42
- }
43
- function _interopRequireWildcard(e, r) {
44
- if (!r && e && e.__esModule) return e;
45
- if (null === e || ("object" != typeof e && "function" != typeof e))
46
- return { default: e };
47
- var t = _getRequireWildcardCache(r);
48
- if (t && t.has(e)) return t.get(e);
49
- var n = { __proto__: null },
50
- a = Object.defineProperty && Object.getOwnPropertyDescriptor;
51
- for (var u in e)
52
- if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
53
- var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
54
- i && (i.get || i.set) ? Object.defineProperty(n, u, i) : (n[u] = e[u]);
35
+ function _interopRequireWildcard(e, t) {
36
+ if ("function" == typeof WeakMap)
37
+ var r = new WeakMap(),
38
+ n = new WeakMap();
39
+ return (_interopRequireWildcard = function (e, t) {
40
+ if (!t && e && e.__esModule) return e;
41
+ var o,
42
+ i,
43
+ f = { __proto__: null, default: e };
44
+ if (null === e || ("object" != typeof e && "function" != typeof e))
45
+ return f;
46
+ if ((o = t ? n : r)) {
47
+ if (o.has(e)) return o.get(e);
48
+ o.set(e, f);
55
49
  }
56
- return ((n.default = e), t && t.set(e, n), n);
50
+ for (const t in e)
51
+ "default" !== t &&
52
+ {}.hasOwnProperty.call(e, t) &&
53
+ ((i =
54
+ (o = Object.defineProperty) &&
55
+ Object.getOwnPropertyDescriptor(e, t)) &&
56
+ (i.get || i.set)
57
+ ? o(f, t, i)
58
+ : (f[t] = e[t]));
59
+ return f;
60
+ })(e, t);
57
61
  }
58
62
  const extraData = (exports.extraData = {
59
63
  foo: _exportNull.foo,
@@ -29,7 +29,7 @@ export const extraData = {
29
29
  importStar,
30
30
  myDefault,
31
31
  myFoo,
32
- myFunction: (myFunction(): string),
32
+ myFunction: myFunction() as string,
33
33
  primitiveDefault,
34
34
  primitiveFoo,
35
35
  };
@@ -37,7 +37,7 @@ export const extraData = {
37
37
  export const asyncImportCJS = import('./export-5');
38
38
  export const asyncImportESM = import('./export-6');
39
39
 
40
- export const asyncImportMaybeSyncCJS: mixed =
40
+ export const asyncImportMaybeSyncCJS: unknown =
41
41
  require.unstable_importMaybeSync('./export-7');
42
- export const asyncImportMaybeSyncESM: mixed =
42
+ export const asyncImportMaybeSyncESM: unknown =
43
43
  require.unstable_importMaybeSync('./export-8');
@@ -9,6 +9,6 @@
9
9
  */
10
10
 
11
11
  export type RequireWithUnstableImportMaybeSync = {
12
- (id: string | number): mixed,
13
- unstable_importMaybeSync: (id: string) => mixed,
12
+ (id: string | number): unknown,
13
+ unstable_importMaybeSync: (id: string) => unknown,
14
14
  };
@@ -11,7 +11,7 @@
11
11
  'use strict';
12
12
 
13
13
  declare var __METRO_GLOBAL_PREFIX__: string;
14
- declare var __DOWNLOAD_AND_EXEC_FOR_TESTS__: (path: string) => Promise<mixed>;
14
+ declare var __DOWNLOAD_AND_EXEC_FOR_TESTS__: (path: string) => Promise<unknown>;
15
15
 
16
16
  const key = `${global.__METRO_GLOBAL_PREFIX__ ?? ''}__loadBundleAsync`;
17
17
 
@@ -10,7 +10,7 @@
10
10
 
11
11
  'use strict';
12
12
 
13
- let shouldBeB: mixed, shouldBeC: mixed;
13
+ let shouldBeB: unknown, shouldBeC: unknown;
14
14
  try {
15
15
  // $FlowExpectedError[cannot-resolve-module]
16
16
  shouldBeB = require('./not-exists');
@@ -24,4 +24,4 @@ function main() {
24
24
  };
25
25
  }
26
26
 
27
- module.exports = (main(): mixed);
27
+ module.exports = main() as unknown;
@@ -23,4 +23,4 @@ function main() {
23
23
  return null;
24
24
  }
25
25
 
26
- module.exports = (main(): mixed);
26
+ module.exports = main() as unknown;
@@ -24,4 +24,4 @@ function main() {
24
24
  };
25
25
  }
26
26
 
27
- module.exports = (main(): mixed);
27
+ module.exports = main() as unknown;
@@ -22,4 +22,4 @@ function main() {
22
22
  );
23
23
  }
24
24
 
25
- module.exports = (main(): mixed);
25
+ module.exports = main() as unknown;
@@ -22,4 +22,4 @@ function main() {
22
22
  );
23
23
  }
24
24
 
25
- module.exports = (main(): mixed);
25
+ module.exports = main() as unknown;
@@ -22,4 +22,4 @@ function main() {
22
22
  );
23
23
  }
24
24
 
25
- module.exports = (main(): mixed);
25
+ module.exports = main() as unknown;
@@ -14,11 +14,11 @@ import {copyContextToObject} from './utils';
14
14
 
15
15
  declare var require: RequireWithContext;
16
16
 
17
- function main(): mixed {
17
+ function main(): unknown {
18
18
  return copyContextToObject(
19
19
  // $FlowFixMe[underconstrained-implicit-instantiation]
20
20
  require.context('./subdir', undefined, undefined, 'sync'),
21
21
  );
22
22
  }
23
23
 
24
- module.exports = (main(): mixed);
24
+ module.exports = main() as unknown;
@@ -33,7 +33,7 @@ export function copyContextToObject<T>(ctx: ContextModule<T>): {
33
33
  }
34
34
 
35
35
  export function awaitProperties<T>(
36
- obj: $ReadOnly<{[key: string]: Promise<T>}>,
36
+ obj: Readonly<{[key: string]: Promise<T>}>,
37
37
  ): Promise<{[key: string]: T}> {
38
38
  const result: {[string]: T} = {};
39
39
  return Promise.all(
@@ -30,4 +30,4 @@ async function main() {
30
30
  };
31
31
  }
32
32
 
33
- module.exports = (main(): mixed);
33
+ module.exports = main() as unknown;
@@ -20,4 +20,4 @@ async function main() {
20
20
  };
21
21
  }
22
22
 
23
- module.exports = (main(): mixed);
23
+ module.exports = main() as unknown;
@@ -18,4 +18,4 @@ function main() {
18
18
  };
19
19
  }
20
20
 
21
- module.exports = (main(): mixed);
21
+ module.exports = main() as unknown;
@@ -30,4 +30,4 @@ function main() {
30
30
  };
31
31
  }
32
32
 
33
- module.exports = (main(): mixed);
33
+ module.exports = main() as unknown;
@@ -11,7 +11,7 @@
11
11
 
12
12
  import vm from 'vm';
13
13
 
14
- module.exports = function execBundle(code: string, context: any = {}): mixed {
14
+ module.exports = function execBundle(code: string, context: any = {}): unknown {
15
15
  if (vm.isContext(context)) {
16
16
  return vm.runInContext(code, context);
17
17
  }
@@ -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;
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _invariant = _interopRequireDefault(require("invariant"));
8
+ var _timers = require("timers");
8
9
  function _interopRequireDefault(e) {
9
10
  return e && e.__esModule ? e : { default: e };
10
11
  }
@@ -50,12 +51,14 @@ class BatchProcessor {
50
51
  }
51
52
  _processQueueOnceReady() {
52
53
  if (this._queue.length >= this._options.maximumItems) {
53
- clearTimeout(this._timeoutHandle);
54
+ if (this._timeoutHandle != null) {
55
+ (0, _timers.clearTimeout)(this._timeoutHandle);
56
+ }
54
57
  process.nextTick(() => this._processQueue());
55
58
  return;
56
59
  }
57
60
  if (this._timeoutHandle == null) {
58
- this._timeoutHandle = setTimeout(
61
+ this._timeoutHandle = (0, _timers.setTimeout)(
59
62
  () => this._processQueue(),
60
63
  this._options.maximumDelayMs,
61
64
  );
@@ -10,6 +10,7 @@
10
10
  */
11
11
 
12
12
  import invariant from 'invariant';
13
+ import {clearTimeout, setTimeout} from 'timers';
13
14
 
14
15
  type ProcessBatch<TItem, TResult> = (
15
16
  batch: Array<TItem>,
@@ -24,8 +25,8 @@ type BatchProcessorOptions = {
24
25
 
25
26
  type QueueItem<TItem, TResult> = {
26
27
  item: TItem,
27
- reject: (error: mixed) => mixed,
28
- resolve: (result: TResult) => mixed,
28
+ reject: (error: unknown) => unknown,
29
+ resolve: (result: TResult) => unknown,
29
30
  ...
30
31
  };
31
32
 
@@ -41,7 +42,7 @@ export default class BatchProcessor<TItem, TResult> {
41
42
  _options: BatchProcessorOptions;
42
43
  _processBatch: ProcessBatch<TItem, TResult>;
43
44
  _queue: Array<QueueItem<TItem, TResult>>;
44
- _timeoutHandle: ?TimeoutID;
45
+ _timeoutHandle: ?ReturnType<typeof setTimeout>;
45
46
 
46
47
  constructor(
47
48
  options: BatchProcessorOptions,
@@ -70,7 +71,7 @@ export default class BatchProcessor<TItem, TResult> {
70
71
  this._onBatchFinished();
71
72
  }
72
73
 
73
- _onBatchError(jobs: Array<QueueItem<TItem, TResult>>, error: mixed): void {
74
+ _onBatchError(jobs: Array<QueueItem<TItem, TResult>>, error: unknown): void {
74
75
  for (let i = 0; i < jobs.length; ++i) {
75
76
  jobs[i].reject(error);
76
77
  }
@@ -94,7 +95,9 @@ export default class BatchProcessor<TItem, TResult> {
94
95
 
95
96
  _processQueueOnceReady(): void {
96
97
  if (this._queue.length >= this._options.maximumItems) {
97
- clearTimeout(this._timeoutHandle);
98
+ if (this._timeoutHandle != null) {
99
+ clearTimeout(this._timeoutHandle);
100
+ }
98
101
  process.nextTick(() => this._processQueue());
99
102
  return;
100
103
  }
@@ -109,8 +112,8 @@ export default class BatchProcessor<TItem, TResult> {
109
112
  queue(item: TItem): Promise<TResult> {
110
113
  return new Promise(
111
114
  (
112
- resolve: (result: TResult) => mixed,
113
- reject: (error: mixed) => mixed,
115
+ resolve: (result: TResult) => unknown,
116
+ reject: (error: unknown) => unknown,
114
117
  ) => {
115
118
  this._queue.push({item, resolve, reject});
116
119
  this._processQueueOnceReady();