metro 0.66.2 → 0.69.0

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 (255) hide show
  1. package/package.json +22 -24
  2. package/src/Assets.js +9 -9
  3. package/src/Assets.js.flow +5 -7
  4. package/src/Bundler/util.js +16 -15
  5. package/src/Bundler/util.js.flow +11 -10
  6. package/src/Bundler.js +21 -8
  7. package/src/Bundler.js.flow +19 -7
  8. package/src/DeltaBundler/DeltaCalculator.js +15 -15
  9. package/src/DeltaBundler/DeltaCalculator.js.flow +7 -7
  10. package/src/DeltaBundler/Serializers/baseBytecodeBundle.js +13 -13
  11. package/src/DeltaBundler/Serializers/baseBytecodeBundle.js.flow +6 -7
  12. package/src/DeltaBundler/Serializers/baseJSBundle.js +4 -4
  13. package/src/DeltaBundler/Serializers/baseJSBundle.js.flow +4 -4
  14. package/src/DeltaBundler/Serializers/getAllFiles.js +1 -1
  15. package/src/DeltaBundler/Serializers/getAllFiles.js.flow +3 -3
  16. package/src/DeltaBundler/Serializers/getAssets.js +3 -3
  17. package/src/DeltaBundler/Serializers/getAssets.js.flow +4 -5
  18. package/src/DeltaBundler/Serializers/getExplodedSourceMap.js +4 -4
  19. package/src/DeltaBundler/Serializers/getExplodedSourceMap.js.flow +4 -4
  20. package/src/DeltaBundler/Serializers/getRamBundleInfo.js +20 -20
  21. package/src/DeltaBundler/Serializers/getRamBundleInfo.js.flow +9 -10
  22. package/src/DeltaBundler/Serializers/helpers/bytecode.js +11 -11
  23. package/src/DeltaBundler/Serializers/helpers/bytecode.js.flow +5 -6
  24. package/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.js +1 -1
  25. package/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.js.flow +1 -1
  26. package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js +2 -2
  27. package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js.flow +4 -4
  28. package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.js +1 -1
  29. package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.js.flow +1 -1
  30. package/src/DeltaBundler/Serializers/helpers/js.js +6 -6
  31. package/src/DeltaBundler/Serializers/helpers/js.js.flow +11 -12
  32. package/src/DeltaBundler/Serializers/helpers/processBytecodeModules.js +4 -4
  33. package/src/DeltaBundler/Serializers/helpers/processBytecodeModules.js.flow +3 -3
  34. package/src/DeltaBundler/Serializers/helpers/processModules.js +4 -4
  35. package/src/DeltaBundler/Serializers/helpers/processModules.js.flow +3 -3
  36. package/src/DeltaBundler/Serializers/hmrJSBundle.js +9 -9
  37. package/src/DeltaBundler/Serializers/hmrJSBundle.js.flow +9 -8
  38. package/src/DeltaBundler/Serializers/sourceMapGenerator.js +6 -6
  39. package/src/DeltaBundler/Serializers/sourceMapGenerator.js.flow +3 -4
  40. package/src/DeltaBundler/Serializers/sourceMapObject.js +5 -5
  41. package/src/DeltaBundler/Serializers/sourceMapObject.js.flow +4 -4
  42. package/src/DeltaBundler/Serializers/sourceMapString.js +2 -2
  43. package/src/DeltaBundler/Serializers/sourceMapString.js.flow +3 -3
  44. package/src/DeltaBundler/Transformer.js +9 -9
  45. package/src/DeltaBundler/Transformer.js.flow +7 -9
  46. package/src/DeltaBundler/Worker.js +8 -11
  47. package/src/DeltaBundler/Worker.js.flow +8 -11
  48. package/src/DeltaBundler/WorkerFarm.js +14 -17
  49. package/src/DeltaBundler/WorkerFarm.js.flow +7 -10
  50. package/src/DeltaBundler/__fixtures__/hasteImpl.js +2 -2
  51. package/src/DeltaBundler/computeDelta.js +2 -2
  52. package/src/DeltaBundler/computeDelta.js.flow +2 -2
  53. package/src/DeltaBundler/getTransformCacheKey.js +4 -4
  54. package/src/DeltaBundler/getTransformCacheKey.js.flow +5 -6
  55. package/src/DeltaBundler/mergeDeltas.js +2 -2
  56. package/src/DeltaBundler/mergeDeltas.js.flow +1 -1
  57. package/src/DeltaBundler/traverseDependencies.js +22 -22
  58. package/src/DeltaBundler/traverseDependencies.js.flow +3 -3
  59. package/src/DeltaBundler/types.flow.js +1 -1
  60. package/src/DeltaBundler/types.flow.js.flow +1 -1
  61. package/src/DeltaBundler.js +5 -5
  62. package/src/DeltaBundler.js.flow +4 -4
  63. package/src/HmrServer.js +71 -55
  64. package/src/HmrServer.js.flow +40 -37
  65. package/src/IncrementalBundler/GraphNotFoundError.js +1 -1
  66. package/src/IncrementalBundler/GraphNotFoundError.js.flow +1 -1
  67. package/src/IncrementalBundler/ResourceNotFoundError.js +1 -1
  68. package/src/IncrementalBundler/ResourceNotFoundError.js.flow +1 -1
  69. package/src/IncrementalBundler/RevisionNotFoundError.js +1 -1
  70. package/src/IncrementalBundler/RevisionNotFoundError.js.flow +1 -1
  71. package/src/IncrementalBundler.js +44 -32
  72. package/src/IncrementalBundler.js.flow +30 -24
  73. package/src/ModuleGraph/module.js +3 -3
  74. package/src/ModuleGraph/module.js.flow +1 -1
  75. package/src/ModuleGraph/node-haste/HasteFS.js +2 -2
  76. package/src/ModuleGraph/node-haste/HasteFS.js.flow +1 -1
  77. package/src/ModuleGraph/node-haste/Module.js +1 -1
  78. package/src/ModuleGraph/node-haste/Module.js.flow +1 -1
  79. package/src/ModuleGraph/node-haste/ModuleCache.js +1 -1
  80. package/src/ModuleGraph/node-haste/ModuleCache.js.flow +3 -3
  81. package/src/ModuleGraph/node-haste/Package.js +3 -3
  82. package/src/ModuleGraph/node-haste/Package.js.flow +3 -3
  83. package/src/ModuleGraph/node-haste/node-haste.flow.js +1 -1
  84. package/src/ModuleGraph/node-haste/node-haste.flow.js.flow +1 -1
  85. package/src/ModuleGraph/node-haste/node-haste.js +42 -32
  86. package/src/ModuleGraph/node-haste/node-haste.js.flow +28 -23
  87. package/src/ModuleGraph/output/indexed-ram-bundle.js +17 -17
  88. package/src/ModuleGraph/output/indexed-ram-bundle.js.flow +41 -9
  89. package/src/ModuleGraph/output/multiple-files-ram-bundle.js +18 -18
  90. package/src/ModuleGraph/output/multiple-files-ram-bundle.js.flow +21 -9
  91. package/src/ModuleGraph/output/plain-bundle.js +6 -6
  92. package/src/ModuleGraph/output/plain-bundle.js.flow +7 -7
  93. package/src/ModuleGraph/output/reverse-dependency-map-references.js +3 -3
  94. package/src/ModuleGraph/output/reverse-dependency-map-references.js.flow +4 -8
  95. package/src/ModuleGraph/output/util.js +31 -30
  96. package/src/ModuleGraph/output/util.js.flow +15 -16
  97. package/src/ModuleGraph/silent-console.js +2 -2
  98. package/src/ModuleGraph/silent-console.js.flow +1 -1
  99. package/src/ModuleGraph/test-helpers.js +7 -7
  100. package/src/ModuleGraph/types.flow.js +1 -1
  101. package/src/ModuleGraph/types.flow.js.flow +7 -7
  102. package/src/ModuleGraph/worker/JsFileWrapping.js +7 -7
  103. package/src/ModuleGraph/worker/JsFileWrapping.js.flow +3 -2
  104. package/src/ModuleGraph/worker/Platforms.js +2 -2
  105. package/src/ModuleGraph/worker/Platforms.js.flow +1 -1
  106. package/src/ModuleGraph/worker/collectDependencies.js +24 -25
  107. package/src/ModuleGraph/worker/collectDependencies.js.flow +15 -17
  108. package/src/ModuleGraph/worker/generate.js +2 -2
  109. package/src/ModuleGraph/worker/generate.js.flow +3 -3
  110. package/src/ModuleGraph/worker/generateImportNames.js +5 -5
  111. package/src/ModuleGraph/worker/generateImportNames.js.flow +3 -5
  112. package/src/ModuleGraph/worker/mergeSourceMaps.js +8 -7
  113. package/src/ModuleGraph/worker/mergeSourceMaps.js.flow +3 -3
  114. package/src/Server/MultipartResponse.js +4 -8
  115. package/src/Server/symbolicate.js +8 -8
  116. package/src/Server/symbolicate.js.flow +17 -5
  117. package/src/Server.js +202 -150
  118. package/src/Server.js.flow +129 -87
  119. package/src/cli-utils.js +4 -4
  120. package/src/cli-utils.js.flow +15 -13
  121. package/src/cli.js +4 -4
  122. package/src/cli.js.flow +2 -4
  123. package/src/commands/build.js +23 -24
  124. package/src/commands/build.js.flow +6 -9
  125. package/src/commands/dependencies.js +25 -19
  126. package/src/commands/serve.js +17 -18
  127. package/src/commands/serve.js.flow +6 -9
  128. package/src/index.js +116 -51
  129. package/src/index.js.flow +107 -41
  130. package/src/integration_tests/basic_bundle/AssetRegistry.js +2 -2
  131. package/src/integration_tests/basic_bundle/AssetRegistry.js.flow +1 -1
  132. package/src/integration_tests/basic_bundle/Bar.js +2 -2
  133. package/src/integration_tests/basic_bundle/Bar.js.flow +1 -1
  134. package/src/integration_tests/basic_bundle/ErrorBundle.js +2 -2
  135. package/src/integration_tests/basic_bundle/ErrorBundle.js.flow +1 -1
  136. package/src/integration_tests/basic_bundle/Foo.js +2 -2
  137. package/src/integration_tests/basic_bundle/Foo.js.flow +1 -1
  138. package/src/integration_tests/basic_bundle/TestBundle.js +3 -2
  139. package/src/integration_tests/basic_bundle/TestBundle.js.flow +3 -1
  140. package/src/integration_tests/basic_bundle/TestPolyfill.js +1 -1
  141. package/src/integration_tests/basic_bundle/TestPolyfill.js.flow +1 -1
  142. package/src/integration_tests/basic_bundle/TypeScript.ts +1 -1
  143. package/src/integration_tests/basic_bundle/import-export/export-1.js +2 -2
  144. package/src/integration_tests/basic_bundle/import-export/export-1.js.flow +1 -1
  145. package/src/integration_tests/basic_bundle/import-export/export-2.js +2 -2
  146. package/src/integration_tests/basic_bundle/import-export/export-2.js.flow +1 -1
  147. package/src/integration_tests/basic_bundle/import-export/export-3.js +2 -2
  148. package/src/integration_tests/basic_bundle/import-export/export-3.js.flow +1 -1
  149. package/src/integration_tests/basic_bundle/import-export/export-4.js +2 -2
  150. package/src/integration_tests/basic_bundle/import-export/export-4.js.flow +1 -1
  151. package/src/integration_tests/basic_bundle/import-export/export-5.js +2 -2
  152. package/src/integration_tests/basic_bundle/import-export/export-5.js.flow +1 -1
  153. package/src/integration_tests/basic_bundle/import-export/export-6.js +2 -2
  154. package/src/integration_tests/basic_bundle/import-export/export-6.js.flow +1 -1
  155. package/src/integration_tests/basic_bundle/import-export/export-null.js +2 -2
  156. package/src/integration_tests/basic_bundle/import-export/export-null.js.flow +1 -1
  157. package/src/integration_tests/basic_bundle/import-export/export-primitive-default.js +2 -2
  158. package/src/integration_tests/basic_bundle/import-export/export-primitive-default.js.flow +1 -1
  159. package/src/integration_tests/basic_bundle/import-export/index.js +8 -8
  160. package/src/integration_tests/basic_bundle/import-export/index.js.flow +1 -1
  161. package/src/integration_tests/basic_bundle/polyfill.js +1 -1
  162. package/src/integration_tests/execBundle.js +2 -2
  163. package/src/integration_tests/execBundle.js.flow +1 -1
  164. package/src/integration_tests/metro.config.js +8 -8
  165. package/src/lib/BatchProcessor.js +3 -3
  166. package/src/lib/BatchProcessor.js.flow +1 -1
  167. package/src/lib/JsonReporter.js +2 -2
  168. package/src/lib/JsonReporter.js.flow +1 -1
  169. package/src/lib/RamBundleParser.js +1 -1
  170. package/src/lib/RamBundleParser.js.flow +1 -1
  171. package/src/lib/TerminalReporter.js +14 -14
  172. package/src/lib/TerminalReporter.js.flow +9 -10
  173. package/src/lib/bundleToBytecode.js +6 -7
  174. package/src/lib/bundleToBytecode.js.flow +8 -7
  175. package/src/lib/bundleToString.js +3 -3
  176. package/src/lib/bundleToString.js.flow +5 -4
  177. package/src/lib/countLines.js +3 -7
  178. package/src/lib/countLines.js.flow +4 -7
  179. package/src/lib/createModuleIdFactory.js +2 -2
  180. package/src/lib/createModuleIdFactory.js.flow +1 -1
  181. package/src/lib/{attachWebsocketServer.js → createWebsocketServer.js} +18 -17
  182. package/src/lib/{attachWebsocketServer.js.flow → createWebsocketServer.js.flow} +12 -21
  183. package/src/lib/debounceAsyncQueue.js +2 -2
  184. package/src/lib/debounceAsyncQueue.js.flow +1 -1
  185. package/src/lib/formatBundlingError.js +21 -21
  186. package/src/lib/formatBundlingError.js.flow +6 -8
  187. package/src/lib/getAppendScripts.js +26 -27
  188. package/src/lib/getAppendScripts.js.flow +7 -8
  189. package/src/lib/getGraphId.js +3 -3
  190. package/src/lib/getGraphId.js.flow +3 -3
  191. package/src/lib/getMaxWorkers.js +2 -2
  192. package/src/lib/getMaxWorkers.js.flow +1 -1
  193. package/src/lib/getPreludeCode.js +2 -2
  194. package/src/lib/getPreludeCode.js.flow +1 -1
  195. package/src/lib/getPrependedScripts.js +15 -15
  196. package/src/lib/getPrependedScripts.js.flow +7 -8
  197. package/src/lib/logToConsole.js +1 -1
  198. package/src/lib/logToConsole.js.flow +3 -3
  199. package/src/lib/parseCustomTransformOptions.js +2 -2
  200. package/src/lib/parseCustomTransformOptions.js.flow +3 -3
  201. package/src/lib/parseOptionsFromUrl.js +7 -7
  202. package/src/lib/parseOptionsFromUrl.js.flow +29 -9
  203. package/src/lib/relativizeSourceMap.js +1 -1
  204. package/src/lib/relativizeSourceMap.js.flow +3 -3
  205. package/src/lib/reporting.js +5 -5
  206. package/src/lib/reporting.js.flow +16 -3
  207. package/src/lib/splitBundleOptions.js +5 -5
  208. package/src/lib/splitBundleOptions.js.flow +1 -1
  209. package/src/lib/transformHelpers.js +10 -10
  210. package/src/lib/transformHelpers.js.flow +5 -5
  211. package/src/node-haste/DependencyGraph/ModuleResolution.js +51 -30
  212. package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +46 -42
  213. package/src/node-haste/DependencyGraph/createHasteMap.js +99 -0
  214. package/src/node-haste/DependencyGraph/createHasteMap.js.flow +88 -0
  215. package/src/node-haste/DependencyGraph/{assets/empty-module.js → types.js} +2 -2
  216. package/src/node-haste/DependencyGraph/types.js.flow +88 -0
  217. package/src/node-haste/DependencyGraph.js +49 -117
  218. package/src/node-haste/DependencyGraph.js.flow +36 -111
  219. package/src/node-haste/Module.js +1 -1
  220. package/src/node-haste/Module.js.flow +3 -3
  221. package/src/node-haste/ModuleCache.js +54 -13
  222. package/src/node-haste/ModuleCache.js.flow +53 -12
  223. package/src/node-haste/Package.js +7 -9
  224. package/src/node-haste/Package.js.flow +1 -8
  225. package/src/node-haste/lib/AssetPaths.js +5 -5
  226. package/src/node-haste/lib/AssetPaths.js.flow +2 -4
  227. package/src/node-haste/lib/parsePlatformFilePath.js +4 -4
  228. package/src/node-haste/lib/parsePlatformFilePath.js.flow +1 -1
  229. package/src/shared/output/RamBundle/as-assets.js +16 -17
  230. package/src/shared/output/RamBundle/as-assets.js.flow +11 -15
  231. package/src/shared/output/RamBundle/as-indexed-file.js +14 -15
  232. package/src/shared/output/RamBundle/as-indexed-file.js.flow +8 -12
  233. package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js +7 -7
  234. package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js.flow +4 -4
  235. package/src/shared/output/RamBundle/magic-number.js +1 -1
  236. package/src/shared/output/RamBundle/magic-number.js.flow +1 -1
  237. package/src/shared/output/RamBundle/util.js +21 -19
  238. package/src/shared/output/RamBundle/util.js.flow +5 -8
  239. package/src/shared/output/RamBundle/write-sourcemap.js +1 -1
  240. package/src/shared/output/RamBundle/write-sourcemap.js.flow +1 -1
  241. package/src/shared/output/RamBundle.js +2 -2
  242. package/src/shared/output/RamBundle.js.flow +4 -5
  243. package/src/shared/output/bundle.js +6 -6
  244. package/src/shared/output/bundle.js.flow +4 -5
  245. package/src/shared/output/meta.js +4 -5
  246. package/src/shared/output/meta.js.flow +2 -4
  247. package/src/shared/output/unbundle.js +1 -1
  248. package/src/shared/output/unbundle.js.flow +1 -1
  249. package/src/shared/output/writeFile.js +1 -1
  250. package/src/shared/output/writeFile.js.flow +1 -1
  251. package/src/shared/types.flow.js +1 -1
  252. package/src/shared/types.flow.js.flow +2 -2
  253. package/src/node-haste/DependencyGraph/assets/empty-module.js.flow +0 -9
  254. package/src/node-haste/types.js +0 -10
  255. package/src/node-haste/types.js.flow +0 -23
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
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.
@@ -9,31 +9,30 @@
9
9
  */
10
10
  "use strict";
11
11
 
12
+ const virtualModule = require("../module").virtual;
13
+
12
14
  const generate = require("../worker/generate");
13
15
 
14
16
  const mergeSourceMaps = require("../worker/mergeSourceMaps");
15
17
 
16
- const nullthrows = require("nullthrows");
17
-
18
18
  const reverseDependencyMapReferences = require("./reverse-dependency-map-references");
19
19
 
20
- const { addParamsToDefineCall } = require("metro-transform-plugins");
20
+ const { parseSync, transformFromAstSync } = require("@babel/core");
21
21
 
22
- const virtualModule = require("../module").virtual; // flowlint-next-line untyped-import:off
22
+ const HermesParser = require("hermes-parser"); // flowlint-next-line untyped-import:off
23
23
 
24
24
  const { passthroughSyntaxPlugins } = require("metro-react-native-babel-preset");
25
25
 
26
- const { parseSync, transformFromAstSync } = require("@babel/core");
27
-
28
- const HermesParser = require("hermes-parser");
26
+ const { addParamsToDefineCall } = require("metro-transform-plugins");
29
27
 
30
- // Transformed modules have the form
28
+ const nullthrows = require("nullthrows"); // Transformed modules have the form
31
29
  // __d(function(require, module, global, exports, dependencyMap) {
32
30
  // /* code */
33
31
  // });
34
32
  //
35
33
  // This function adds the numeric module ID, and an array with dependencies of
36
34
  // the dependencies of the module before the closing parenthesis.
35
+
37
36
  function addModuleIdsToModuleWrapper(module, idForPath) {
38
37
  const { dependencies, file } = module;
39
38
  const { code } = file; // calling `idForPath` on the module itself first gives us a lower module id
@@ -68,7 +67,7 @@ function inlineModuleIds(
68
67
  dependencyMapReservedName,
69
68
  globalPrefix,
70
69
  ignoreMissingDependencyMapReference = false,
71
- hermesParser = false
70
+ hermesParser = false,
72
71
  }
73
72
  ) {
74
73
  const { dependencies, file } = module;
@@ -84,7 +83,7 @@ function inlineModuleIds(
84
83
  return {
85
84
  fileId,
86
85
  moduleCode: code,
87
- moduleMap: map
86
+ moduleMap: map,
88
87
  };
89
88
  }
90
89
 
@@ -119,7 +118,7 @@ function inlineModuleIds(
119
118
  return {
120
119
  fileId,
121
120
  moduleCode: code,
122
- moduleMap: map
121
+ moduleMap: map,
123
122
  };
124
123
  } // If we're here, the module was probably generated by some code that
125
124
  // doesn't make the dependency map name externally configurable, or a
@@ -144,8 +143,9 @@ function inlineModuleIds(
144
143
  if (idStr.length > match.length) {
145
144
  // Stop the build rather than silently emit an incorrect source map.
146
145
  throw new Error(
147
- `Module ID doesn't fit in available space; add ${idStr.length -
148
- match.length} more characters to 'dependencyMapReservedName'.`
146
+ `Module ID doesn't fit in available space; add ${
147
+ idStr.length - match.length
148
+ } more characters to 'dependencyMapReservedName'.`
149
149
  );
150
150
  }
151
151
 
@@ -155,7 +155,7 @@ function inlineModuleIds(
155
155
  return {
156
156
  fileId,
157
157
  moduleCode: inlinedCode,
158
- moduleMap: map
158
+ moduleMap: map,
159
159
  };
160
160
  }
161
161
 
@@ -171,17 +171,17 @@ function inlineModuleIds(
171
171
  reverseDependencyMapReferences,
172
172
  {
173
173
  dependencyIds,
174
- globalPrefix
175
- }
176
- ]
177
- ]
174
+ globalPrefix,
175
+ },
176
+ ],
177
+ ],
178
178
  };
179
179
  const sourceAst =
180
180
  isTypeScriptSource(path) || isTSXSource(path) || !hermesParser
181
181
  ? parseSync(code, babelConfig)
182
182
  : HermesParser.parse(code, {
183
183
  babel: true,
184
- sourceType: babelConfig.sourceType
184
+ sourceType: babelConfig.sourceType,
185
185
  });
186
186
  const ast = nullthrows(
187
187
  transformFromAstSync(sourceAst, code, babelConfig).ast
@@ -190,7 +190,7 @@ function inlineModuleIds(
190
190
  return {
191
191
  fileId,
192
192
  moduleCode: generatedCode,
193
- moduleMap: map && generatedMap && mergeSourceMaps(path, map, generatedMap)
193
+ moduleMap: map && generatedMap && mergeSourceMaps(path, map, generatedMap),
194
194
  };
195
195
  }
196
196
 
@@ -202,12 +202,13 @@ function inlineModuleIdsAndAddParamsToDefineCall(module, idForPath, options) {
202
202
  );
203
203
  return {
204
204
  moduleCode: addParamsToDefineCall(moduleCode, fileId),
205
- moduleMap
205
+ moduleMap,
206
206
  };
207
207
  }
208
208
 
209
209
  exports.inlineModuleIds = inlineModuleIds;
210
- exports.inlineModuleIdsAndAddParamsToDefineCall = inlineModuleIdsAndAddParamsToDefineCall;
210
+ exports.inlineModuleIdsAndAddParamsToDefineCall =
211
+ inlineModuleIdsAndAddParamsToDefineCall;
211
212
 
212
213
  function escapeRegex(str) {
213
214
  // From http://stackoverflow.com/questions/14076210/
@@ -235,7 +236,7 @@ function getModuleCodeAndMap(module, idForPath, options) {
235
236
  idForPath,
236
237
  {
237
238
  dependencyMapReservedName: options.dependencyMapReservedName,
238
- globalPrefix: options.globalPrefix
239
+ globalPrefix: options.globalPrefix,
239
240
  }
240
241
  ));
241
242
  }
@@ -248,11 +249,11 @@ function getModuleCodeAndMap(module, idForPath, options) {
248
249
  }
249
250
 
250
251
  moduleMap = { ...moduleMap, x_facebook_sources };
251
- } // $FlowFixMe[incompatible-return]
252
+ }
252
253
 
253
254
  return {
254
255
  moduleCode,
255
- moduleMap
256
+ moduleMap,
256
257
  };
257
258
  }
258
259
 
@@ -281,7 +282,7 @@ exports.createIdForPathFn = () => {
281
282
  }; // creates a series of virtual modules with require calls to the passed-in
282
283
  // modules.
283
284
 
284
- exports.requireCallsTo = function*(modules, idForPath, getRunModuleStatement) {
285
+ exports.requireCallsTo = function* (modules, idForPath, getRunModuleStatement) {
285
286
  for (const module of modules) {
286
287
  const id = idForPath(module.file);
287
288
  yield virtualModule(
@@ -313,11 +314,11 @@ function toModuleTransport(
313
314
  const { dependencies, file } = module;
314
315
  const { moduleCode, moduleMap } = getModuleCodeAndMap(
315
316
  module,
316
- x => idsForPath(x).moduleId,
317
+ (x) => idsForPath(x).moduleId,
317
318
  {
318
319
  dependencyMapReservedName,
319
320
  enableIDInlining: true,
320
- globalPrefix
321
+ globalPrefix,
321
322
  }
322
323
  );
323
324
  return {
@@ -327,7 +328,7 @@ function toModuleTransport(
327
328
  id: file.type === "module" ? nullthrows(idsForPath(file).localId) : -1,
328
329
  map: moduleMap,
329
330
  name: file.path,
330
- sourcePath: file.path
331
+ sourcePath: file.path,
331
332
  };
332
333
  }
333
334
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
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.
@@ -10,21 +10,19 @@
10
10
 
11
11
  'use strict';
12
12
 
13
+ import type {Dependency, IdsForPathFn, Module} from '../types.flow';
14
+ import type {BasicSourceMap} from 'metro-source-map';
15
+
16
+ const virtualModule = require('../module').virtual;
13
17
  const generate = require('../worker/generate');
14
18
  const mergeSourceMaps = require('../worker/mergeSourceMaps');
15
- const nullthrows = require('nullthrows');
16
19
  const reverseDependencyMapReferences = require('./reverse-dependency-map-references');
17
-
18
- const {addParamsToDefineCall} = require('metro-transform-plugins');
19
- const virtualModule = require('../module').virtual;
20
-
21
- // flowlint-next-line untyped-import:off
22
- const {passthroughSyntaxPlugins} = require('metro-react-native-babel-preset');
23
20
  const {parseSync, transformFromAstSync} = require('@babel/core');
24
21
  const HermesParser = require('hermes-parser');
25
-
26
- import type {Dependency, IdsForPathFn, Module} from '../types.flow';
27
- import type {BasicSourceMap} from 'metro-source-map';
22
+ // flowlint-next-line untyped-import:off
23
+ const {passthroughSyntaxPlugins} = require('metro-react-native-babel-preset');
24
+ const {addParamsToDefineCall} = require('metro-transform-plugins');
25
+ const nullthrows = require('nullthrows');
28
26
 
29
27
  // Transformed modules have the form
30
28
  // __d(function(require, module, global, exports, dependencyMap) {
@@ -151,8 +149,9 @@ function inlineModuleIds(
151
149
  if (idStr.length > match.length) {
152
150
  // Stop the build rather than silently emit an incorrect source map.
153
151
  throw new Error(
154
- `Module ID doesn't fit in available space; add ${idStr.length -
155
- match.length} more characters to 'dependencyMapReservedName'.`,
152
+ `Module ID doesn't fit in available space; add ${
153
+ idStr.length - match.length
154
+ } more characters to 'dependencyMapReservedName'.`,
156
155
  );
157
156
  }
158
157
  return idStr.padEnd(match.length);
@@ -216,7 +215,8 @@ function inlineModuleIdsAndAddParamsToDefineCall(
216
215
  }
217
216
 
218
217
  exports.inlineModuleIds = inlineModuleIds;
219
- exports.inlineModuleIdsAndAddParamsToDefineCall = inlineModuleIdsAndAddParamsToDefineCall;
218
+ exports.inlineModuleIdsAndAddParamsToDefineCall =
219
+ inlineModuleIdsAndAddParamsToDefineCall;
220
220
 
221
221
  function escapeRegex(str: string): string {
222
222
  // From http://stackoverflow.com/questions/14076210/
@@ -268,7 +268,6 @@ function getModuleCodeAndMap(
268
268
  }
269
269
  moduleMap = {...moduleMap, x_facebook_sources};
270
270
  }
271
- // $FlowFixMe[incompatible-return]
272
271
  return {moduleCode, moduleMap};
273
272
  }
274
273
 
@@ -300,7 +299,7 @@ exports.createIdForPathFn = (): (({path: string, ...}) => number) => {
300
299
 
301
300
  // creates a series of virtual modules with require calls to the passed-in
302
301
  // modules.
303
- exports.requireCallsTo = function*(
302
+ exports.requireCallsTo = function* (
304
303
  modules: Iterable<Module>,
305
304
  idForPath: IdForPathFn,
306
305
  getRunModuleStatement: (id: number | string) => string,
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
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.
@@ -21,6 +21,6 @@ const write = (_, __, callback) => callback();
21
21
  module.exports = new Console(
22
22
  new Writable({
23
23
  write,
24
- writev: write
24
+ writev: write,
25
25
  })
26
26
  );
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
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.
@@ -14,19 +14,19 @@ const { toMatchSnapshot } = require("jest-snapshot");
14
14
 
15
15
  const generateOptions = {
16
16
  concise: true,
17
- sourceType: "module"
17
+ sourceType: "module",
18
18
  };
19
19
 
20
- const codeFromAst = ast => generate(ast, generateOptions).code;
20
+ const codeFromAst = (ast) => generate(ast, generateOptions).code;
21
21
 
22
- const comparableCode = code => code.trim().replace(/\s+/g, " ");
22
+ const comparableCode = (code) => code.trim().replace(/\s+/g, " ");
23
23
 
24
24
  function toEqualComparableCode(received, expected) {
25
25
  const comparableExpected = comparableCode(expected);
26
26
  const pass = received === comparableExpected;
27
27
  const options = {
28
28
  isNot: this.isNot,
29
- promise: this.promise
29
+ promise: this.promise,
30
30
  };
31
31
  const message = pass
32
32
  ? () =>
@@ -61,7 +61,7 @@ function toEqualComparableCode(received, expected) {
61
61
  return {
62
62
  actual: received,
63
63
  message,
64
- pass
64
+ pass,
65
65
  };
66
66
  } // See https://superuser.com/questions/380772/removing-ansi-color-codes-from-text-stream
67
67
 
@@ -87,5 +87,5 @@ module.exports = {
87
87
  codeFromAst,
88
88
  comparableCode,
89
89
  toEqualComparableCode,
90
- toMatchCodeFrameSnapshot
90
+ toMatchCodeFrameSnapshot,
91
91
  };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
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.
@@ -11,9 +11,9 @@
11
11
  'use strict';
12
12
 
13
13
  import type {
14
- MixedSourceMap,
15
- FBSourceFunctionMap,
16
14
  BasicSourceMap,
15
+ FBSourceFunctionMap,
16
+ MixedSourceMap,
17
17
  } from 'metro-source-map';
18
18
  import type {TransformResultDependency} from 'metro/src/DeltaBundler';
19
19
 
@@ -108,9 +108,8 @@ export type OutputFnArg = {|
108
108
  enableIDInlining: boolean,
109
109
  segmentID: number,
110
110
  |};
111
- export type OutputFn<
112
- M: MixedSourceMap = MixedSourceMap,
113
- > = OutputFnArg => OutputResult<M>;
111
+ export type OutputFn<M: MixedSourceMap = MixedSourceMap> =
112
+ OutputFnArg => OutputResult<M>;
114
113
 
115
114
  export type OutputResult<M: MixedSourceMap> = {|
116
115
  code: string | Buffer,
@@ -256,7 +255,7 @@ export type AssetContents = {
256
255
  };
257
256
  export type AssetContentsByPath = {
258
257
  +[moduleFilePath: string]: $ReadOnlyArray<AssetContents>,
259
- ...,
258
+ ...
260
259
  };
261
260
 
262
261
  export type ResolvedCodeFile = {|
@@ -298,4 +297,5 @@ export type ResolvedLibrary = {|
298
297
  +files: $ReadOnlyArray<ResolvedCodeFile>,
299
298
  /* cannot be a Map because it's JSONified later on */
300
299
  +assets: AssetContentsByPath,
300
+ +isPartiallyResolved?: boolean,
301
301
  |};
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
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.
@@ -21,7 +21,7 @@ function _getRequireWildcardCache(nodeInterop) {
21
21
  if (typeof WeakMap !== "function") return null;
22
22
  var cacheBabelInterop = new WeakMap();
23
23
  var cacheNodeInterop = new WeakMap();
24
- return (_getRequireWildcardCache = function(nodeInterop) {
24
+ return (_getRequireWildcardCache = function (nodeInterop) {
25
25
  return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
26
26
  })(nodeInterop);
27
27
  }
@@ -90,7 +90,7 @@ function wrapModule(
90
90
  const requireName = renameRequires(ast);
91
91
  return {
92
92
  ast,
93
- requireName
93
+ requireName,
94
94
  };
95
95
  }
96
96
 
@@ -114,7 +114,7 @@ function wrapJson(source, globalPrefix) {
114
114
  return [
115
115
  `${globalPrefix}__d(function(${moduleFactoryParameters.join(", ")}) {`,
116
116
  ` ${jsonToCommonJS(source)}`,
117
- "});"
117
+ "});",
118
118
  ].join("\n");
119
119
  }
120
120
 
@@ -138,7 +138,7 @@ function buildParameters(importDefaultName, importAllName, dependencyMapName) {
138
138
  importAllName,
139
139
  "module",
140
140
  "exports",
141
- dependencyMapName
141
+ dependencyMapName,
142
142
  ];
143
143
  } // Renaming requires should ideally only be done when generating for the target
144
144
  // that expects the custom require name in the optimize step.
@@ -157,7 +157,7 @@ function renameRequires(ast) {
157
157
  );
158
158
  newRequireName = body.scope.generateUid(WRAP_NAME);
159
159
  body.scope.rename("require", newRequireName);
160
- }
160
+ },
161
161
  });
162
162
  return newRequireName;
163
163
  }
@@ -167,5 +167,5 @@ module.exports = {
167
167
  wrapJson,
168
168
  jsonToCommonJS,
169
169
  wrapModule,
170
- wrapPolyfill
170
+ wrapPolyfill,
171
171
  };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
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.
@@ -10,10 +10,11 @@
10
10
 
11
11
  'use strict';
12
12
 
13
+ import type {FunctionExpression, Identifier, Program} from '@babel/types';
14
+
13
15
  import template from '@babel/template';
14
16
  import traverse from '@babel/traverse';
15
17
  import * as t from '@babel/types';
16
- import type {Program, FunctionExpression, Identifier} from '@babel/types';
17
18
  import invariant from 'invariant';
18
19
 
19
20
  const WRAP_NAME = '$$_REQUIRE'; // note: babel will prefix this with _
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
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.
@@ -17,5 +17,5 @@
17
17
 
18
18
  const VALID_PLATFORMS = new Set(["ios", "android", "web"]);
19
19
  module.exports = {
20
- VALID_PLATFORMS
20
+ VALID_PLATFORMS,
21
21
  };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
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.
@@ -9,10 +9,6 @@
9
9
  */
10
10
  "use strict";
11
11
 
12
- const invariant = require("invariant");
13
-
14
- const nullthrows = require("nullthrows");
15
-
16
12
  const generate = require("@babel/generator").default;
17
13
 
18
14
  const template = require("@babel/template").default;
@@ -21,6 +17,10 @@ const traverse = require("@babel/traverse").default;
21
17
 
22
18
  const types = require("@babel/types");
23
19
 
20
+ const invariant = require("invariant");
21
+
22
+ const nullthrows = require("nullthrows");
23
+
24
24
  const { isImport } = types;
25
25
 
26
26
  /**
@@ -52,7 +52,7 @@ function collectDependencies(ast, options) {
52
52
  dependencyMapIdentifier: null,
53
53
  dynamicRequires: options.dynamicRequires,
54
54
  keepRequireNames: options.keepRequireNames,
55
- allowOptionalDependencies: options.allowOptionalDependencies
55
+ allowOptionalDependencies: options.allowOptionalDependencies,
56
56
  };
57
57
  const visitor = {
58
58
  CallExpression(path, state) {
@@ -65,14 +65,14 @@ function collectDependencies(ast, options) {
65
65
 
66
66
  if (isImport(callee)) {
67
67
  processImportCall(path, state, {
68
- asyncType: "async"
68
+ asyncType: "async",
69
69
  });
70
70
  return;
71
71
  }
72
72
 
73
73
  if (name === "__prefetchImport" && !path.scope.getBinding(name)) {
74
74
  processImportCall(path, state, {
75
- asyncType: "prefetch"
75
+ asyncType: "prefetch",
76
76
  });
77
77
  return;
78
78
  }
@@ -80,7 +80,7 @@ function collectDependencies(ast, options) {
80
80
  if (name === "__jsResource" && !path.scope.getBinding(name)) {
81
81
  processImportCall(path, state, {
82
82
  asyncType: "async",
83
- jsResource: true
83
+ jsResource: true,
84
84
  });
85
85
  return;
86
86
  }
@@ -94,7 +94,7 @@ function collectDependencies(ast, options) {
94
94
  processImportCall(path, state, {
95
95
  asyncType: "async",
96
96
  jsResource: true,
97
- splitCondition: args[1]
97
+ splitCondition: args[1],
98
98
  });
99
99
  return;
100
100
  }
@@ -123,13 +123,12 @@ function collectDependencies(ast, options) {
123
123
  options.dependencyMapName
124
124
  );
125
125
  } else {
126
- state.dependencyMapIdentifier = path.scope.generateUidIdentifier(
127
- "dependencyMap"
128
- );
126
+ state.dependencyMapIdentifier =
127
+ path.scope.generateUidIdentifier("dependencyMap");
129
128
  }
130
129
 
131
130
  state.dependencyCalls = new Set(["require", ...options.inlineableCalls]);
132
- }
131
+ },
133
132
  };
134
133
  traverse(ast, visitor, null, state);
135
134
  const collectedDependencies = state.dependencyRegistry.getDependencies(); // Compute the list of dependencies.
@@ -139,14 +138,14 @@ function collectDependencies(ast, options) {
139
138
  for (const { index, name, ...dependencyData } of collectedDependencies) {
140
139
  dependencies[index] = {
141
140
  name,
142
- data: dependencyData
141
+ data: dependencyData,
143
142
  };
144
143
  }
145
144
 
146
145
  return {
147
146
  ast,
148
147
  dependencies,
149
- dependencyMapName: nullthrows(state.dependencyMapIdentifier).name
148
+ dependencyMapName: nullthrows(state.dependencyMapIdentifier).name,
150
149
  };
151
150
  }
152
151
 
@@ -157,7 +156,7 @@ function collectImports(path, state) {
157
156
  {
158
157
  name: path.node.source.value,
159
158
  asyncType: null,
160
- optional: false
159
+ optional: false,
161
160
  },
162
161
  path
163
162
  );
@@ -177,7 +176,7 @@ function processImportCall(path, state, options) {
177
176
  name,
178
177
  asyncType: options.asyncType,
179
178
  splitCondition: options.splitCondition,
180
- optional: isOptionalDependency(name, path, state)
179
+ optional: isOptionalDependency(name, path, state),
181
180
  },
182
181
  path
183
182
  );
@@ -210,7 +209,7 @@ function processRequireCall(path, state) {
210
209
  {
211
210
  name,
212
211
  asyncType: null,
213
- optional: isOptionalDependency(name, path, state)
212
+ optional: isOptionalDependency(name, path, state),
214
213
  },
215
214
  path
216
215
  );
@@ -361,7 +360,7 @@ const DefaultDependencyTransformer = {
361
360
  state.asyncRequireModulePathStringLiteral
362
361
  ),
363
362
  MODULE_ID: createModuleIDExpression(dependency, state),
364
- MODULE_NAME: createModuleNameLiteral(dependency)
363
+ MODULE_NAME: createModuleNameLiteral(dependency),
365
364
  })
366
365
  );
367
366
  },
@@ -373,7 +372,7 @@ const DefaultDependencyTransformer = {
373
372
  state.asyncRequireModulePathStringLiteral
374
373
  ),
375
374
  MODULE_ID: createModuleIDExpression(dependency, state),
376
- MODULE_NAME: createModuleNameLiteral(dependency)
375
+ MODULE_NAME: createModuleNameLiteral(dependency),
377
376
  })
378
377
  );
379
378
  },
@@ -385,7 +384,7 @@ const DefaultDependencyTransformer = {
385
384
  state.asyncRequireModulePathStringLiteral
386
385
  ),
387
386
  MODULE_ID: createModuleIDExpression(dependency, state),
388
- MODULE_NAME: createModuleNameLiteral(dependency)
387
+ MODULE_NAME: createModuleNameLiteral(dependency),
389
388
  })
390
389
  );
391
390
  },
@@ -404,10 +403,10 @@ const DefaultDependencyTransformer = {
404
403
  _path$node$loc$start$ !== void 0
405
404
  ? _path$node$loc$start$
406
405
  : 0
407
- )
406
+ ),
408
407
  })
409
408
  );
410
- }
409
+ },
411
410
  };
412
411
 
413
412
  function createModuleIDExpression(dependency, state) {
@@ -433,7 +432,7 @@ class DefaultModuleDependencyRegistry {
433
432
  name: qualifier.name,
434
433
  asyncType: qualifier.asyncType,
435
434
  locs: [],
436
- index: this._dependencies.size
435
+ index: this._dependencies.size,
437
436
  };
438
437
 
439
438
  if (qualifier.optional) {