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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "metro",
3
- "version": "0.66.2",
3
+ "version": "0.69.0",
4
4
  "description": "🚇 The JavaScript bundler for React Native.",
5
5
  "main": "src/index.js",
6
6
  "bin": "src/cli.js",
@@ -31,30 +31,28 @@
31
31
  "error-stack-parser": "^2.0.6",
32
32
  "fs-extra": "^1.0.0",
33
33
  "graceful-fs": "^4.1.3",
34
- "hermes-parser": "0.4.7",
34
+ "hermes-parser": "0.6.0",
35
35
  "image-size": "^0.6.0",
36
36
  "invariant": "^2.2.4",
37
- "jest-haste-map": "^26.5.2",
37
+ "jest-haste-map": "^27.3.1",
38
38
  "jest-worker": "^26.0.0",
39
39
  "lodash.throttle": "^4.1.1",
40
- "metro-babel-register": "0.66.2",
41
- "metro-babel-transformer": "0.66.2",
42
- "metro-cache": "0.66.2",
43
- "metro-cache-key": "0.66.2",
44
- "metro-config": "0.66.2",
45
- "metro-core": "0.66.2",
46
- "metro-hermes-compiler": "0.66.2",
47
- "metro-inspector-proxy": "0.66.2",
48
- "metro-minify-uglify": "0.66.2",
49
- "metro-react-native-babel-preset": "0.66.2",
50
- "metro-resolver": "0.66.2",
51
- "metro-runtime": "0.66.2",
52
- "metro-source-map": "0.66.2",
53
- "metro-symbolicate": "0.66.2",
54
- "metro-transform-plugins": "0.66.2",
55
- "metro-transform-worker": "0.66.2",
40
+ "metro-babel-transformer": "0.69.0",
41
+ "metro-cache": "0.69.0",
42
+ "metro-cache-key": "0.69.0",
43
+ "metro-config": "0.69.0",
44
+ "metro-core": "0.69.0",
45
+ "metro-hermes-compiler": "0.69.0",
46
+ "metro-inspector-proxy": "0.69.0",
47
+ "metro-minify-uglify": "0.69.0",
48
+ "metro-react-native-babel-preset": "0.69.0",
49
+ "metro-resolver": "0.69.0",
50
+ "metro-runtime": "0.69.0",
51
+ "metro-source-map": "0.69.0",
52
+ "metro-symbolicate": "0.69.0",
53
+ "metro-transform-plugins": "0.69.0",
54
+ "metro-transform-worker": "0.69.0",
56
55
  "mime-types": "^2.1.27",
57
- "mkdirp": "^0.5.1",
58
56
  "node-fetch": "^2.2.0",
59
57
  "nullthrows": "^1.1.1",
60
58
  "rimraf": "^2.5.4",
@@ -63,7 +61,7 @@
63
61
  "strip-ansi": "^6.0.0",
64
62
  "temp": "0.8.3",
65
63
  "throat": "^5.0.0",
66
- "ws": "^1.1.5",
64
+ "ws": "^7.5.1",
67
65
  "yargs": "^15.3.1"
68
66
  },
69
67
  "devDependencies": {
@@ -72,9 +70,9 @@
72
70
  "babel-jest": "^26.6.3",
73
71
  "dedent": "^0.7.0",
74
72
  "jest-snapshot": "^26.5.2",
75
- "metro-memory-fs": "0.66.2",
76
- "metro-react-native-babel-preset": "0.66.2",
77
- "metro-react-native-babel-transformer": "0.66.2",
73
+ "metro-memory-fs": "0.69.0",
74
+ "metro-react-native-babel-preset": "0.69.0",
75
+ "metro-react-native-babel-transformer": "0.69.0",
78
76
  "stack-trace": "^0.0.10"
79
77
  },
80
78
  "license": "MIT"
package/src/Assets.js CHANGED
@@ -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,6 +9,8 @@
9
9
  */
10
10
  "use strict";
11
11
 
12
+ const { isAssetTypeAnImage } = require("./Bundler/util");
13
+
12
14
  const AssetPaths = require("./node-haste/lib/AssetPaths");
13
15
 
14
16
  const crypto = require("crypto");
@@ -21,8 +23,6 @@ const imageSize = require("image-size");
21
23
 
22
24
  const path = require("path");
23
25
 
24
- const { isAssetTypeAnImage } = require("./Bundler/util");
25
-
26
26
  const readDir = denodeify(fs.readdir);
27
27
  const readFile = denodeify(fs.readFile);
28
28
  const hashFiles = denodeify(function hashFilesCb(files, hash, callback) {
@@ -45,9 +45,9 @@ const hashFiles = denodeify(function hashFilesCb(files, hash, callback) {
45
45
 
46
46
  function buildAssetMap(dir, files, platform) {
47
47
  const platforms = new Set(platform != null ? [platform] : []);
48
- const assets = files.map(file => AssetPaths.tryParse(file, platforms));
48
+ const assets = files.map((file) => AssetPaths.tryParse(file, platforms));
49
49
  const map = new Map();
50
- assets.forEach(function(asset, i) {
50
+ assets.forEach(function (asset, i) {
51
51
  if (asset == null) {
52
52
  return;
53
53
  }
@@ -59,7 +59,7 @@ function buildAssetMap(dir, files, platform) {
59
59
  if (!record) {
60
60
  record = {
61
61
  scales: [],
62
- files: []
62
+ files: [],
63
63
  };
64
64
  map.set(assetKey, record);
65
65
  }
@@ -134,7 +134,7 @@ async function getAbsoluteAssetInfo(assetPath, platform = null) {
134
134
  hash: hasher.digest("hex"),
135
135
  name,
136
136
  scales,
137
- type
137
+ type,
138
138
  };
139
139
  }
140
140
 
@@ -173,7 +173,7 @@ async function getAssetData(
173
173
  files: assetInfo.files,
174
174
  hash: assetInfo.hash,
175
175
  name: assetInfo.name,
176
- type: assetInfo.type
176
+ type: assetInfo.type,
177
177
  };
178
178
  return await applyAssetDataPlugins(assetDataPlugins, assetData);
179
179
  }
@@ -259,5 +259,5 @@ function pathBelongsToRoots(pathToCheck, roots) {
259
259
  module.exports = {
260
260
  getAsset,
261
261
  getAssetData,
262
- getAssetFiles
262
+ getAssetFiles,
263
263
  };
@@ -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
- const AssetPaths = require('./node-haste/lib/AssetPaths');
13
+ import type {AssetPath} from './node-haste/lib/AssetPaths';
14
14
 
15
+ const {isAssetTypeAnImage} = require('./Bundler/util');
16
+ const AssetPaths = require('./node-haste/lib/AssetPaths');
15
17
  const crypto = require('crypto');
16
18
  const denodeify = require('denodeify');
17
19
  const fs = require('fs');
18
20
  const imageSize = require('image-size');
19
21
  const path = require('path');
20
22
 
21
- const {isAssetTypeAnImage} = require('./Bundler/util');
22
-
23
23
  const readDir = denodeify(fs.readdir);
24
24
  const readFile = denodeify(fs.readFile);
25
25
 
26
- import type {AssetPath} from './node-haste/lib/AssetPaths';
27
-
28
26
  export type AssetInfo = {|
29
27
  +files: Array<string>,
30
28
  +hash: string,
@@ -92,7 +90,7 @@ function buildAssetMap(
92
90
  AssetPaths.tryParse(file, platforms),
93
91
  );
94
92
  const map = new Map();
95
- assets.forEach(function(asset: ?AssetPath, i: number) {
93
+ assets.forEach(function (asset: ?AssetPath, i: number) {
96
94
  if (asset == null) {
97
95
  return;
98
96
  }
@@ -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,14 +9,14 @@
9
9
  */
10
10
  "use strict";
11
11
 
12
- const babelTypes = require("@babel/types");
13
-
14
12
  const babylon = require("@babel/parser");
15
13
 
16
- const nullthrows = require("nullthrows");
17
-
18
14
  const template = require("@babel/template").default;
19
15
 
16
+ const babelTypes = require("@babel/types");
17
+
18
+ const nullthrows = require("nullthrows"); // Structure of the object: dir.name.scale = asset
19
+
20
20
  const assetPropertyBlockList = new Set(["files", "fileSystemLocation", "path"]);
21
21
 
22
22
  function generateAssetCodeFileAst(assetRegistryPath, assetDescriptor) {
@@ -37,8 +37,8 @@ function generateAssetCodeFileAst(assetRegistryPath, assetDescriptor) {
37
37
  t.program([
38
38
  buildRequire({
39
39
  ASSET_REGISTRY_PATH: t.stringLiteral(assetRegistryPath),
40
- DESCRIPTOR_AST: descriptorAst
41
- })
40
+ DESCRIPTOR_AST: descriptorAst,
41
+ }),
42
42
  ])
43
43
  );
44
44
  }
@@ -92,8 +92,8 @@ function generateRemoteAssetCodeFileAst(
92
92
  Object.keys(descriptor)
93
93
  .map(Number)
94
94
  .sort((a, b) => a - b)
95
- .map(scale => t.numericLiteral(scale))
96
- )
95
+ .map((scale) => t.numericLiteral(scale))
96
+ ),
97
97
  })
98
98
  );
99
99
  } // Test extension against all types supported by image-size module.
@@ -122,13 +122,13 @@ function createRamBundleGroups(ramGroups, groupableModules, subtree) {
122
122
  // by path or (numeric) module id;
123
123
  const byPath = new Map();
124
124
  const byId = new Map();
125
- groupableModules.forEach(m => {
125
+ groupableModules.forEach((m) => {
126
126
  byPath.set(m.sourcePath, m);
127
127
  byId.set(m.id, m.sourcePath);
128
128
  }); // build a map of group root IDs to an array of module IDs in the group
129
129
 
130
130
  const result = new Map(
131
- ramGroups.map(modulePath => {
131
+ ramGroups.map((modulePath) => {
132
132
  const root = byPath.get(modulePath);
133
133
 
134
134
  if (root == null) {
@@ -137,7 +137,7 @@ function createRamBundleGroups(ramGroups, groupableModules, subtree) {
137
137
 
138
138
  return [
139
139
  root.id, // `subtree` yields the IDs of all transitive dependencies of a module
140
- new Set(subtree(root, byPath))
140
+ new Set(subtree(root, byPath)),
141
141
  ];
142
142
  })
143
143
  );
@@ -159,8 +159,9 @@ function createRamBundleGroups(ramGroups, groupableModules, subtree) {
159
159
  const parentNames = parents.map(byId.get, byId);
160
160
  const lastName = parentNames.pop();
161
161
  throw new Error(
162
- `Module ${byId.get(moduleId) ||
163
- moduleId} belongs to groups ${parentNames.join(", ")}, and ${String(
162
+ `Module ${
163
+ byId.get(moduleId) || moduleId
164
+ } belongs to groups ${parentNames.join(", ")}, and ${String(
164
165
  lastName
165
166
  )}. Ensure that each module is only part of one group.`
166
167
  );
@@ -195,5 +196,5 @@ module.exports = {
195
196
  createRamBundleGroups,
196
197
  generateAssetCodeFileAst,
197
198
  generateRemoteAssetCodeFileAst,
198
- isAssetTypeAnImage
199
+ isAssetTypeAnImage,
199
200
  };
@@ -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,15 +10,15 @@
10
10
 
11
11
  'use strict';
12
12
 
13
- const babelTypes = require('@babel/types');
14
- const babylon = require('@babel/parser');
15
- const nullthrows = require('nullthrows');
16
- const template = require('@babel/template').default;
17
-
18
13
  import type {AssetDataFiltered, AssetDataWithoutFiles} from '../Assets';
19
14
  import type {ModuleTransportLike} from '../shared/types.flow';
20
15
  import type {File} from '@babel/types';
21
16
 
17
+ const babylon = require('@babel/parser');
18
+ const template = require('@babel/template').default;
19
+ const babelTypes = require('@babel/types');
20
+ const nullthrows = require('nullthrows');
21
+
22
22
  // Structure of the object: dir.name.scale = asset
23
23
  export type RemoteFileMap = {
24
24
  [string]: {
@@ -28,9 +28,9 @@ export type RemoteFileMap = {
28
28
  hash: string,
29
29
  ...
30
30
  },
31
- ...,
31
+ ...
32
32
  },
33
- ...,
33
+ ...
34
34
  },
35
35
  __proto__: null,
36
36
  ...
@@ -207,8 +207,9 @@ function createRamBundleGroups<T: ModuleTransportLike>(
207
207
  const parentNames = parents.map(byId.get, byId);
208
208
  const lastName = parentNames.pop();
209
209
  throw new Error(
210
- `Module ${byId.get(moduleId) ||
211
- moduleId} belongs to groups ${parentNames.join(', ')}, and ${String(
210
+ `Module ${
211
+ byId.get(moduleId) || moduleId
212
+ } belongs to groups ${parentNames.join(', ')}, and ${String(
212
213
  lastName,
213
214
  )}. Ensure that each module is only part of one group.`,
214
215
  );
package/src/Bundler.js CHANGED
@@ -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,23 +9,32 @@
9
9
  */
10
10
  "use strict";
11
11
 
12
- const DependencyGraph = require("./node-haste/DependencyGraph");
13
-
14
12
  const Transformer = require("./DeltaBundler/Transformer");
15
13
 
14
+ const DependencyGraph = require("./node-haste/DependencyGraph");
15
+
16
16
  class Bundler {
17
17
  constructor(config, options) {
18
18
  this._depGraphPromise = DependencyGraph.load(config, options);
19
-
20
- this._depGraphPromise
21
- .then(dependencyGraph => {
19
+ this._readyPromise = this._depGraphPromise
20
+ .then((dependencyGraph) => {
21
+ config.reporter.update({
22
+ type: "transformer_load_started",
23
+ });
22
24
  this._transformer = new Transformer(
23
25
  config, // $FlowFixMe[method-unbinding] added when improving typing for this parameters
24
26
  dependencyGraph.getSha1.bind(dependencyGraph)
25
27
  );
28
+ config.reporter.update({
29
+ type: "transformer_load_done",
30
+ });
26
31
  })
27
- .catch(error => {
32
+ .catch((error) => {
28
33
  console.error("Failed to construct transformer: ", error);
34
+ config.reporter.update({
35
+ type: "transformer_load_failed",
36
+ error,
37
+ });
29
38
  });
30
39
  }
31
40
 
@@ -34,7 +43,7 @@ class Bundler {
34
43
 
35
44
  this._transformer.end();
36
45
 
37
- dependencyGraph.getWatcher().end();
46
+ dependencyGraph.end();
38
47
  }
39
48
 
40
49
  async getDependencyGraph() {
@@ -46,6 +55,10 @@ class Bundler {
46
55
  // TODO: Remove this ugly hack!
47
56
  await this._depGraphPromise;
48
57
  return this._transformer.transformFile(filePath, transformOptions);
58
+ } // Waits for the bundler to become ready.
59
+
60
+ async ready() {
61
+ await this._readyPromise;
49
62
  }
50
63
  }
51
64
 
@@ -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,13 +10,13 @@
10
10
 
11
11
  'use strict';
12
12
 
13
- const DependencyGraph = require('./node-haste/DependencyGraph');
14
- const Transformer = require('./DeltaBundler/Transformer');
15
-
16
- import type {TransformOptions} from './DeltaBundler/Worker';
17
13
  import type {TransformResultWithSource} from './DeltaBundler';
14
+ import type {TransformOptions} from './DeltaBundler/Worker';
18
15
  import type {ConfigT} from 'metro-config/src/configTypes.flow';
19
16
 
17
+ const Transformer = require('./DeltaBundler/Transformer');
18
+ const DependencyGraph = require('./node-haste/DependencyGraph');
19
+
20
20
  export type BundlerOptions = $ReadOnly<{|
21
21
  hasReducedPerformance?: boolean,
22
22
  watch?: boolean,
@@ -24,21 +24,28 @@ export type BundlerOptions = $ReadOnly<{|
24
24
 
25
25
  class Bundler {
26
26
  _depGraphPromise: Promise<DependencyGraph>;
27
+ _readyPromise: Promise<void>;
27
28
  _transformer: Transformer;
28
29
 
29
30
  constructor(config: ConfigT, options?: BundlerOptions) {
30
31
  this._depGraphPromise = DependencyGraph.load(config, options);
31
32
 
32
- this._depGraphPromise
33
+ this._readyPromise = this._depGraphPromise
33
34
  .then((dependencyGraph: DependencyGraph) => {
35
+ config.reporter.update({type: 'transformer_load_started'});
34
36
  this._transformer = new Transformer(
35
37
  config,
36
38
  // $FlowFixMe[method-unbinding] added when improving typing for this parameters
37
39
  dependencyGraph.getSha1.bind(dependencyGraph),
38
40
  );
41
+ config.reporter.update({type: 'transformer_load_done'});
39
42
  })
40
43
  .catch(error => {
41
44
  console.error('Failed to construct transformer: ', error);
45
+ config.reporter.update({
46
+ type: 'transformer_load_failed',
47
+ error,
48
+ });
42
49
  });
43
50
  }
44
51
 
@@ -46,7 +53,7 @@ class Bundler {
46
53
  const dependencyGraph = await this._depGraphPromise;
47
54
 
48
55
  this._transformer.end();
49
- dependencyGraph.getWatcher().end();
56
+ dependencyGraph.end();
50
57
  }
51
58
 
52
59
  async getDependencyGraph(): Promise<DependencyGraph> {
@@ -63,6 +70,11 @@ class Bundler {
63
70
 
64
71
  return this._transformer.transformFile(filePath, transformOptions);
65
72
  }
73
+
74
+ // Waits for the bundler to become ready.
75
+ async ready(): Promise<void> {
76
+ await this._readyPromise;
77
+ }
66
78
  }
67
79
 
68
80
  module.exports = Bundler;
@@ -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.
@@ -12,17 +12,17 @@
12
12
  const {
13
13
  initialTraverseDependencies,
14
14
  reorderGraph,
15
- traverseDependencies
15
+ traverseDependencies,
16
16
  } = require("./traverseDependencies");
17
17
 
18
18
  const { EventEmitter } = require("events");
19
-
20
19
  /**
21
20
  * This class is in charge of calculating the delta of changed modules that
22
21
  * happen between calls. To do so, it subscribes to file changes, so it can
23
22
  * traverse the files that have been changed between calls and avoid having to
24
23
  * traverse the whole dependency tree for trivial small changes.
25
24
  */
25
+
26
26
  class DeltaCalculator extends EventEmitter {
27
27
  _deletedFiles = new Set();
28
28
  _modifiedFiles = new Set();
@@ -35,7 +35,7 @@ class DeltaCalculator extends EventEmitter {
35
35
  dependencies: new Map(),
36
36
  entryPoints,
37
37
  importBundleNames: new Set(),
38
- transformOptions: this._options.transformOptions
38
+ transformOptions: this._options.transformOptions,
39
39
  };
40
40
 
41
41
  this._dependencyGraph
@@ -57,7 +57,7 @@ class DeltaCalculator extends EventEmitter {
57
57
  dependencies: new Map(),
58
58
  entryPoints: this._graph.entryPoints,
59
59
  importBundleNames: new Set(),
60
- transformOptions: this._options.transformOptions
60
+ transformOptions: this._options.transformOptions,
61
61
  };
62
62
  this._modifiedFiles = new Set();
63
63
  this._deletedFiles = new Set();
@@ -97,8 +97,8 @@ class DeltaCalculator extends EventEmitter {
97
97
  // processed (since we haven't actually created any delta). If we do not
98
98
  // do so, asking for a delta after an error will produce an empty Delta,
99
99
  // which is not correct.
100
- modifiedFiles.forEach(file => this._modifiedFiles.add(file));
101
- deletedFiles.forEach(file => this._deletedFiles.add(file)); // If after an error the number of modules has changed, we could be in
100
+ modifiedFiles.forEach((file) => this._modifiedFiles.add(file));
101
+ deletedFiles.forEach((file) => this._deletedFiles.add(file)); // If after an error the number of modules has changed, we could be in
102
102
  // a weird state. As a safe net we clean the dependency modules to force
103
103
  // a clean traversal of the graph next time.
104
104
 
@@ -113,13 +113,13 @@ class DeltaCalculator extends EventEmitter {
113
113
 
114
114
  if (reset) {
115
115
  reorderGraph(this._graph, {
116
- shallow
116
+ shallow,
117
117
  });
118
118
  return {
119
119
  added: this._graph.dependencies,
120
120
  modified: new Map(),
121
121
  deleted: new Set(),
122
- reset: true
122
+ reset: true,
123
123
  };
124
124
  }
125
125
 
@@ -169,16 +169,16 @@ class DeltaCalculator extends EventEmitter {
169
169
  added,
170
170
  modified: new Map(),
171
171
  deleted: new Set(),
172
- reset: true
172
+ reset: true,
173
173
  };
174
174
  } // If a file has been deleted, we want to invalidate any other file that
175
175
  // depends on it, so we can process it and correctly return an error.
176
176
 
177
- deletedFiles.forEach(filePath => {
177
+ deletedFiles.forEach((filePath) => {
178
178
  const module = this._graph.dependencies.get(filePath);
179
179
 
180
180
  if (module) {
181
- module.inverseDependencies.forEach(path => {
181
+ module.inverseDependencies.forEach((path) => {
182
182
  // Only mark the inverse dependency as modified if it's not already
183
183
  // marked as deleted (in that case we can just ignore it).
184
184
  if (!deletedFiles.has(path)) {
@@ -188,7 +188,7 @@ class DeltaCalculator extends EventEmitter {
188
188
  }
189
189
  }); // We only want to process files that are in the bundle.
190
190
 
191
- const modifiedDependencies = Array.from(modifiedFiles).filter(filePath =>
191
+ const modifiedDependencies = Array.from(modifiedFiles).filter((filePath) =>
192
192
  this._graph.dependencies.has(filePath)
193
193
  ); // No changes happened. Return empty delta.
194
194
 
@@ -197,7 +197,7 @@ class DeltaCalculator extends EventEmitter {
197
197
  added: new Map(),
198
198
  modified: new Map(),
199
199
  deleted: new Set(),
200
- reset: false
200
+ reset: false,
201
201
  };
202
202
  }
203
203
 
@@ -210,7 +210,7 @@ class DeltaCalculator extends EventEmitter {
210
210
  added,
211
211
  modified,
212
212
  deleted,
213
- reset: false
213
+ reset: false,
214
214
  };
215
215
  }
216
216
  }
@@ -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,6 +10,9 @@
10
10
 
11
11
  'use strict';
12
12
 
13
+ import type DependencyGraph from '../node-haste/DependencyGraph';
14
+ import type {DeltaResult, Graph, Options} from './types.flow';
15
+
13
16
  const {
14
17
  initialTraverseDependencies,
15
18
  reorderGraph,
@@ -17,9 +20,6 @@ const {
17
20
  } = require('./traverseDependencies');
18
21
  const {EventEmitter} = require('events');
19
22
 
20
- import type DependencyGraph from '../node-haste/DependencyGraph';
21
- import type {DeltaResult, Graph, Options} from './types.flow';
22
-
23
23
  /**
24
24
  * This class is in charge of calculating the delta of changed modules that
25
25
  * happen between calls. To do so, it subscribes to file changes, so it can
@@ -228,9 +228,9 @@ class DeltaCalculator<T> extends EventEmitter {
228
228
  });
229
229
 
230
230
  // We only want to process files that are in the bundle.
231
- const modifiedDependencies = Array.from(
232
- modifiedFiles,
233
- ).filter((filePath: string) => this._graph.dependencies.has(filePath));
231
+ const modifiedDependencies = Array.from(modifiedFiles).filter(
232
+ (filePath: string) => this._graph.dependencies.has(filePath),
233
+ );
234
234
 
235
235
  // No changes happened. Return empty delta.
236
236
  if (modifiedDependencies.length === 0) {