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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "metro",
3
- "version": "0.83.3",
3
+ "version": "0.83.5",
4
4
  "description": "🚇 The JavaScript bundler for React Native.",
5
5
  "main": "src/index.js",
6
6
  "bin": "src/cli.js",
@@ -11,21 +11,22 @@
11
11
  },
12
12
  "repository": {
13
13
  "type": "git",
14
- "url": "git@github.com:facebook/metro.git"
14
+ "url": "git+https://github.com/facebook/metro.git",
15
+ "directory": "packages/metro"
15
16
  },
16
17
  "scripts": {
17
18
  "prepare-release": "test -d build && rm -rf src.real && mv src src.real && mv build src",
18
19
  "cleanup-release": "test ! -e build && mv src build && mv src.real src"
19
20
  },
20
21
  "dependencies": {
21
- "@babel/code-frame": "^7.24.7",
22
+ "@babel/code-frame": "^7.29.0",
22
23
  "@babel/core": "^7.25.2",
23
- "@babel/generator": "^7.25.0",
24
- "@babel/parser": "^7.25.3",
25
- "@babel/template": "^7.25.0",
26
- "@babel/traverse": "^7.25.3",
27
- "@babel/types": "^7.25.2",
28
- "accepts": "^1.3.7",
24
+ "@babel/generator": "^7.29.1",
25
+ "@babel/parser": "^7.29.0",
26
+ "@babel/template": "^7.28.6",
27
+ "@babel/traverse": "^7.29.0",
28
+ "@babel/types": "^7.29.0",
29
+ "accepts": "^2.0.0",
29
30
  "chalk": "^4.0.0",
30
31
  "ci-info": "^2.0.0",
31
32
  "connect": "^3.6.5",
@@ -33,25 +34,25 @@
33
34
  "error-stack-parser": "^2.0.6",
34
35
  "flow-enums-runtime": "^0.0.6",
35
36
  "graceful-fs": "^4.2.4",
36
- "hermes-parser": "0.32.0",
37
+ "hermes-parser": "0.33.3",
37
38
  "image-size": "^1.0.2",
38
39
  "invariant": "^2.2.4",
39
40
  "jest-worker": "^29.7.0",
40
41
  "jsc-safe-url": "^0.2.2",
41
42
  "lodash.throttle": "^4.1.1",
42
- "metro-babel-transformer": "0.83.3",
43
- "metro-cache": "0.83.3",
44
- "metro-cache-key": "0.83.3",
45
- "metro-config": "0.83.3",
46
- "metro-core": "0.83.3",
47
- "metro-file-map": "0.83.3",
48
- "metro-resolver": "0.83.3",
49
- "metro-runtime": "0.83.3",
50
- "metro-source-map": "0.83.3",
51
- "metro-symbolicate": "0.83.3",
52
- "metro-transform-plugins": "0.83.3",
53
- "metro-transform-worker": "0.83.3",
54
- "mime-types": "^2.1.27",
43
+ "metro-babel-transformer": "0.83.5",
44
+ "metro-cache": "0.83.5",
45
+ "metro-cache-key": "0.83.5",
46
+ "metro-config": "0.83.5",
47
+ "metro-core": "0.83.5",
48
+ "metro-file-map": "0.83.5",
49
+ "metro-resolver": "0.83.5",
50
+ "metro-runtime": "0.83.5",
51
+ "metro-source-map": "0.83.5",
52
+ "metro-symbolicate": "0.83.5",
53
+ "metro-transform-plugins": "0.83.5",
54
+ "metro-transform-worker": "0.83.5",
55
+ "mime-types": "^3.0.1",
55
56
  "nullthrows": "^1.1.1",
56
57
  "serialize-error": "^2.1.0",
57
58
  "source-map": "^0.5.6",
@@ -65,14 +66,17 @@
65
66
  "@babel/plugin-transform-runtime": "^7.24.7",
66
67
  "@react-native/babel-preset": "0.78.0",
67
68
  "@react-native/metro-babel-transformer": "0.78.0",
69
+ "@types/ws": "^7.4.7",
70
+ "@types/yargs": "^17.0.35",
68
71
  "babel-jest": "^29.7.0",
69
72
  "dedent": "^0.7.0",
70
73
  "jest-snapshot": "^29.7.0",
71
74
  "jest-snapshot-serializer-raw": "^1.2.0",
72
- "metro-babel-register": "0.83.3",
75
+ "metro-babel-register": "0.83.5",
73
76
  "metro-memory-fs": "*",
74
77
  "mock-req": "^0.2.0",
75
78
  "mock-res": "^0.6.0",
79
+ "selfsigned": "^5.5.0",
76
80
  "stack-trace": "^0.0.10"
77
81
  },
78
82
  "license": "MIT",
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @oncall react_native
9
+ */
10
+
11
+ export type AssetInfo = {
12
+ readonly files: Array<string>;
13
+ readonly hash: string;
14
+ readonly name: string;
15
+ readonly scales: Array<number>;
16
+ readonly type: string;
17
+ };
18
+ export type AssetDataWithoutFiles = {
19
+ readonly __packager_asset: boolean;
20
+ readonly fileSystemLocation: string;
21
+ readonly hash: string;
22
+ readonly height: null | undefined | number;
23
+ readonly httpServerLocation: string;
24
+ readonly name: string;
25
+ readonly scales: Array<number>;
26
+ readonly type: string;
27
+ readonly width: null | undefined | number;
28
+ };
29
+ export type AssetDataFiltered = {
30
+ readonly __packager_asset: boolean;
31
+ readonly hash: string;
32
+ readonly height: null | undefined | number;
33
+ readonly httpServerLocation: string;
34
+ readonly name: string;
35
+ readonly scales: Array<number>;
36
+ readonly type: string;
37
+ readonly width: null | undefined | number;
38
+ };
39
+ export declare function isAssetTypeAnImage(type: string): boolean;
40
+ export declare function getAssetSize(
41
+ type: string,
42
+ content: Buffer,
43
+ filePath: string,
44
+ ): null | undefined | {readonly width: number; readonly height: number};
45
+ export type AssetData = AssetDataWithoutFiles & {
46
+ readonly files: Array<string>;
47
+ };
48
+ export type AssetDataPlugin = (
49
+ assetData: AssetData,
50
+ ) => AssetData | Promise<AssetData>;
51
+ export declare function getAssetData(
52
+ assetPath: string,
53
+ localPath: string,
54
+ assetDataPlugins: ReadonlyArray<string>,
55
+ platform: null | undefined | string,
56
+ publicPath: string,
57
+ ): Promise<AssetData>;
58
+ /**
59
+ * Returns all the associated files (for different resolutions) of an asset.
60
+ **/
61
+ export declare function getAssetFiles(
62
+ assetPath: string,
63
+ platform?: null | undefined | string,
64
+ ): Promise<Array<string>>;
65
+ /**
66
+ * Return a buffer with the actual image given a request for an image by path.
67
+ * The relativePath can contain a resolution postfix, in this case we need to
68
+ * find that image (or the closest one to it's resolution) in one of the
69
+ * project roots:
70
+ *
71
+ * 1. We first parse the directory of the asset
72
+ * 2. We then build a map of all assets and their scales in this directory
73
+ * 3. Then try to pick platform-specific asset records
74
+ * 4. Then pick the closest resolution (rounding up) to the requested one
75
+ */
76
+ export declare function getAsset(
77
+ relativePath: string,
78
+ projectRoot: string,
79
+ watchFolders: ReadonlyArray<string>,
80
+ platform: null | undefined | string,
81
+ assetExts: ReadonlyArray<string>,
82
+ fileExistsInFileMap?: (absolutePath: string) => boolean,
83
+ ): Promise<Buffer>;
package/src/Assets.js CHANGED
@@ -19,28 +19,32 @@ var _path = _interopRequireDefault(require("path"));
19
19
  function _interopRequireDefault(e) {
20
20
  return e && e.__esModule ? e : { default: e };
21
21
  }
22
- function _getRequireWildcardCache(e) {
23
- if ("function" != typeof WeakMap) return null;
24
- var r = new WeakMap(),
25
- t = new WeakMap();
26
- return (_getRequireWildcardCache = function (e) {
27
- return e ? t : r;
28
- })(e);
29
- }
30
- function _interopRequireWildcard(e, r) {
31
- if (!r && e && e.__esModule) return e;
32
- if (null === e || ("object" != typeof e && "function" != typeof e))
33
- return { default: e };
34
- var t = _getRequireWildcardCache(r);
35
- if (t && t.has(e)) return t.get(e);
36
- var n = { __proto__: null },
37
- a = Object.defineProperty && Object.getOwnPropertyDescriptor;
38
- for (var u in e)
39
- if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
40
- var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
41
- i && (i.get || i.set) ? Object.defineProperty(n, u, i) : (n[u] = e[u]);
22
+ function _interopRequireWildcard(e, t) {
23
+ if ("function" == typeof WeakMap)
24
+ var r = new WeakMap(),
25
+ n = new WeakMap();
26
+ return (_interopRequireWildcard = function (e, t) {
27
+ if (!t && e && e.__esModule) return e;
28
+ var o,
29
+ i,
30
+ f = { __proto__: null, default: e };
31
+ if (null === e || ("object" != typeof e && "function" != typeof e))
32
+ return f;
33
+ if ((o = t ? n : r)) {
34
+ if (o.has(e)) return o.get(e);
35
+ o.set(e, f);
42
36
  }
43
- return ((n.default = e), t && t.set(e, n), n);
37
+ for (const t in e)
38
+ "default" !== t &&
39
+ {}.hasOwnProperty.call(e, t) &&
40
+ ((i =
41
+ (o = Object.defineProperty) &&
42
+ Object.getOwnPropertyDescriptor(e, t)) &&
43
+ (i.get || i.set)
44
+ ? o(f, t, i)
45
+ : (f[t] = e[t]));
46
+ return f;
47
+ })(e, t);
44
48
  }
45
49
  function isAssetTypeAnImage(type) {
46
50
  return (
@@ -158,7 +162,7 @@ async function getAssetData(
158
162
  assetPath,
159
163
  localPath,
160
164
  assetDataPlugins,
161
- platform = null,
165
+ platform,
162
166
  publicPath,
163
167
  ) {
164
168
  let assetUrlPath = localPath.startsWith("..")
@@ -166,7 +170,7 @@ async function getAssetData(
166
170
  : _path.default.join(publicPath, _path.default.dirname(localPath));
167
171
  assetUrlPath = (0, _pathUtils.normalizePathSeparatorsToPosix)(assetUrlPath);
168
172
  const isImage = isAssetTypeAnImage(_path.default.extname(assetPath).slice(1));
169
- const assetInfo = await getAbsoluteAssetInfo(assetPath, platform);
173
+ const assetInfo = await getAbsoluteAssetInfo(assetPath, platform ?? null);
170
174
  const isImageInput = assetInfo.files[0].includes(".zip/")
171
175
  ? _fs.default.readFileSync(assetInfo.files[0])
172
176
  : assetInfo.files[0];
@@ -203,8 +207,9 @@ async function getAsset(
203
207
  relativePath,
204
208
  projectRoot,
205
209
  watchFolders,
206
- platform = null,
210
+ platform,
207
211
  assetExts,
212
+ fileExistsInFileMap,
208
213
  ) {
209
214
  const assetData = AssetPaths.parse(
210
215
  relativePath,
@@ -216,12 +221,20 @@ async function getAsset(
216
221
  `'${relativePath}' cannot be loaded as its extension is not registered in assetExts`,
217
222
  );
218
223
  }
219
- if (!pathBelongsToRoots(absolutePath, [projectRoot, ...watchFolders])) {
220
- throw new Error(
221
- `'${relativePath}' could not be found, because it cannot be found in the project root or any watch folder`,
222
- );
224
+ if (fileExistsInFileMap != null) {
225
+ if (!fileExistsInFileMap(absolutePath)) {
226
+ throw new Error(
227
+ `'${relativePath}' could not be found, because it is not within the projectRoot or watchFolders, or it is blocked via the resolver.blockList config`,
228
+ );
229
+ }
230
+ } else {
231
+ if (!pathBelongsToRoots(absolutePath, [projectRoot, ...watchFolders])) {
232
+ throw new Error(
233
+ `'${relativePath}' could not be found, because it cannot be found in the project root or any watch folder`,
234
+ );
235
+ }
223
236
  }
224
- const record = await getAbsoluteAssetRecord(absolutePath, platform);
237
+ const record = await getAbsoluteAssetRecord(absolutePath, platform ?? null);
225
238
  for (let i = 0; i < record.scales.length; i++) {
226
239
  if (record.scales[i] >= assetData.resolution) {
227
240
  return _fs.default.promises.readFile(record.files[i]);
@@ -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,6 +15,7 @@ import {normalizePathSeparatorsToPosix} from './lib/pathUtils';
15
15
  import * as AssetPaths from './node-haste/lib/AssetPaths';
16
16
  import crypto from 'crypto';
17
17
  import fs from 'fs';
18
+ // $FlowFixMe[untyped-import] image-size
18
19
  import getImageSize from 'image-size';
19
20
  import path from 'path';
20
21
 
@@ -92,7 +93,7 @@ export type AssetDataPlugin = (
92
93
 
93
94
  function buildAssetMap(
94
95
  dir: string,
95
- files: $ReadOnlyArray<string>,
96
+ files: ReadonlyArray<string>,
96
97
  platform: ?string,
97
98
  ): Map<string, {files: Array<string>, scales: Array<number>}> {
98
99
  const platforms = new Set(platform != null ? [platform] : []);
@@ -200,8 +201,8 @@ async function getAbsoluteAssetInfo(
200
201
  export async function getAssetData(
201
202
  assetPath: string,
202
203
  localPath: string,
203
- assetDataPlugins: $ReadOnlyArray<string>,
204
- platform: ?string = null,
204
+ assetDataPlugins: ReadonlyArray<string>,
205
+ platform: ?string,
205
206
  publicPath: string,
206
207
  ): Promise<AssetData> {
207
208
  // If the path of the asset is outside of the projectRoot, we don't want to
@@ -215,7 +216,7 @@ export async function getAssetData(
215
216
  assetUrlPath = normalizePathSeparatorsToPosix(assetUrlPath);
216
217
 
217
218
  const isImage = isAssetTypeAnImage(path.extname(assetPath).slice(1));
218
- const assetInfo = await getAbsoluteAssetInfo(assetPath, platform);
219
+ const assetInfo = await getAbsoluteAssetInfo(assetPath, platform ?? null);
219
220
 
220
221
  const isImageInput = assetInfo.files[0].includes('.zip/')
221
222
  ? fs.readFileSync(assetInfo.files[0])
@@ -239,7 +240,7 @@ export async function getAssetData(
239
240
  }
240
241
 
241
242
  async function applyAssetDataPlugins(
242
- assetDataPlugins: $ReadOnlyArray<string>,
243
+ assetDataPlugins: ReadonlyArray<string>,
243
244
  assetData: AssetData,
244
245
  ): Promise<AssetData> {
245
246
  if (!assetDataPlugins.length) {
@@ -279,9 +280,10 @@ export async function getAssetFiles(
279
280
  export async function getAsset(
280
281
  relativePath: string,
281
282
  projectRoot: string,
282
- watchFolders: $ReadOnlyArray<string>,
283
- platform: ?string = null,
284
- assetExts: $ReadOnlyArray<string>,
283
+ watchFolders: ReadonlyArray<string>,
284
+ platform: ?string,
285
+ assetExts: ReadonlyArray<string>,
286
+ fileExistsInFileMap?: (absolutePath: string) => boolean,
285
287
  ): Promise<Buffer> {
286
288
  const assetData = AssetPaths.parse(
287
289
  relativePath,
@@ -296,13 +298,22 @@ export async function getAsset(
296
298
  );
297
299
  }
298
300
 
299
- if (!pathBelongsToRoots(absolutePath, [projectRoot, ...watchFolders])) {
300
- throw new Error(
301
- `'${relativePath}' could not be found, because it cannot be found in the project root or any watch folder`,
302
- );
301
+ // NOTE: If fileExistsInFileMap is not provided, we fall back to pathBelongsToRoots for backward compatibility, as getAsset is part of the public API.
302
+ if (fileExistsInFileMap != null) {
303
+ if (!fileExistsInFileMap(absolutePath)) {
304
+ throw new Error(
305
+ `'${relativePath}' could not be found, because it is not within the projectRoot or watchFolders, or it is blocked via the resolver.blockList config`,
306
+ );
307
+ }
308
+ } else {
309
+ if (!pathBelongsToRoots(absolutePath, [projectRoot, ...watchFolders])) {
310
+ throw new Error(
311
+ `'${relativePath}' could not be found, because it cannot be found in the project root or any watch folder`,
312
+ );
313
+ }
303
314
  }
304
315
 
305
- const record = await getAbsoluteAssetRecord(absolutePath, platform);
316
+ const record = await getAbsoluteAssetRecord(absolutePath, platform ?? null);
306
317
 
307
318
  for (let i = 0; i < record.scales.length; i++) {
308
319
  if (record.scales[i] >= assetData.resolution) {
@@ -315,7 +326,7 @@ export async function getAsset(
315
326
 
316
327
  function pathBelongsToRoots(
317
328
  pathToCheck: string,
318
- roots: $ReadOnlyArray<string>,
329
+ roots: ReadonlyArray<string>,
319
330
  ): boolean {
320
331
  for (const rootFolder of roots) {
321
332
  if (pathToCheck.startsWith(path.resolve(rootFolder))) {
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @oncall react_native
9
+ */
10
+
11
+ import type {AssetDataWithoutFiles} from '../Assets';
12
+ import type {ModuleTransportLike} from '../shared/types';
13
+ import type {File} from '@babel/types';
14
+
15
+ type SubTree<T extends ModuleTransportLike> = (
16
+ moduleTransport: T,
17
+ moduleTransportsByPath: Map<string, T>,
18
+ ) => Iterable<number>;
19
+ export declare function generateAssetCodeFileAst(
20
+ assetRegistryPath: string,
21
+ assetDescriptor: AssetDataWithoutFiles,
22
+ ): File;
23
+ export declare function createRamBundleGroups<T extends ModuleTransportLike>(
24
+ ramGroups: ReadonlyArray<string>,
25
+ groupableModules: ReadonlyArray<T>,
26
+ subtree: SubTree<T>,
27
+ ): Map<number, Set<number>>;
@@ -11,28 +11,32 @@ var babelTypes = _interopRequireWildcard(require("@babel/types"));
11
11
  function _interopRequireDefault(e) {
12
12
  return e && e.__esModule ? e : { default: e };
13
13
  }
14
- function _getRequireWildcardCache(e) {
15
- if ("function" != typeof WeakMap) return null;
16
- var r = new WeakMap(),
17
- t = new WeakMap();
18
- return (_getRequireWildcardCache = function (e) {
19
- return e ? t : r;
20
- })(e);
21
- }
22
- function _interopRequireWildcard(e, r) {
23
- if (!r && e && e.__esModule) return e;
24
- if (null === e || ("object" != typeof e && "function" != typeof e))
25
- return { default: e };
26
- var t = _getRequireWildcardCache(r);
27
- if (t && t.has(e)) return t.get(e);
28
- var n = { __proto__: null },
29
- a = Object.defineProperty && Object.getOwnPropertyDescriptor;
30
- for (var u in e)
31
- if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
32
- var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
33
- i && (i.get || i.set) ? Object.defineProperty(n, u, i) : (n[u] = e[u]);
14
+ function _interopRequireWildcard(e, t) {
15
+ if ("function" == typeof WeakMap)
16
+ var r = new WeakMap(),
17
+ n = new WeakMap();
18
+ return (_interopRequireWildcard = function (e, t) {
19
+ if (!t && e && e.__esModule) return e;
20
+ var o,
21
+ i,
22
+ f = { __proto__: null, default: e };
23
+ if (null === e || ("object" != typeof e && "function" != typeof e))
24
+ return f;
25
+ if ((o = t ? n : r)) {
26
+ if (o.has(e)) return o.get(e);
27
+ o.set(e, f);
34
28
  }
35
- return ((n.default = e), t && t.set(e, n), n);
29
+ for (const t in e)
30
+ "default" !== t &&
31
+ {}.hasOwnProperty.call(e, t) &&
32
+ ((i =
33
+ (o = Object.defineProperty) &&
34
+ Object.getOwnPropertyDescriptor(e, t)) &&
35
+ (i.get || i.set)
36
+ ? o(f, t, i)
37
+ : (f[t] = e[t]));
38
+ return f;
39
+ })(e, t);
36
40
  }
37
41
  const assetPropertyBlockList = new Set(["files", "fileSystemLocation", "path"]);
38
42
  function generateAssetCodeFileAst(assetRegistryPath, assetDescriptor) {
@@ -67,8 +67,8 @@ function filterObject(
67
67
  }
68
68
 
69
69
  export function createRamBundleGroups<T: ModuleTransportLike>(
70
- ramGroups: $ReadOnlyArray<string>,
71
- groupableModules: $ReadOnlyArray<T>,
70
+ ramGroups: ReadonlyArray<string>,
71
+ groupableModules: ReadonlyArray<T>,
72
72
  subtree: SubTree<T>,
73
73
  ): Map<number, Set<number>> {
74
74
  // build two maps that allow to lookup module data
package/src/Bundler.d.ts CHANGED
@@ -10,30 +10,29 @@
10
10
 
11
11
  import type {TransformResultWithSource} from './DeltaBundler';
12
12
  import type {TransformOptions} from './DeltaBundler/Worker';
13
- import type DependencyGraph from './node-haste/DependencyGraph';
14
- import type {EventEmitter} from 'events';
13
+ import type EventEmitter from 'events';
15
14
  import type {ConfigT} from 'metro-config';
16
15
 
17
- export interface BundlerOptions {
18
- readonly hasReducedPerformance?: boolean;
19
- readonly watch?: boolean;
20
- }
21
-
22
- export default class Bundler {
16
+ import Transformer from './DeltaBundler/Transformer';
17
+ import DependencyGraph from './node-haste/DependencyGraph';
18
+
19
+ export type BundlerOptions = Readonly<{
20
+ hasReducedPerformance?: boolean;
21
+ watch?: boolean;
22
+ }>;
23
+ declare class Bundler {
24
+ _depGraph: DependencyGraph;
25
+ _initializedPromise: Promise<void>;
26
+ _transformer: Transformer;
23
27
  constructor(config: ConfigT, options?: BundlerOptions);
24
-
25
28
  getWatcher(): EventEmitter;
26
-
27
29
  end(): Promise<void>;
28
-
29
30
  getDependencyGraph(): Promise<DependencyGraph>;
30
-
31
31
  transformFile(
32
32
  filePath: string,
33
33
  transformOptions: TransformOptions,
34
- /** Optionally provide the file contents, this can be used to provide virtual contents for a file. */
35
34
  fileBuffer?: Buffer,
36
- ): Promise<TransformResultWithSource<void>>;
37
-
35
+ ): Promise<TransformResultWithSource>;
38
36
  ready(): Promise<void>;
39
37
  }
38
+ export default Bundler;
@@ -17,7 +17,7 @@ import type {ConfigT} from 'metro-config';
17
17
  import Transformer from './DeltaBundler/Transformer';
18
18
  import DependencyGraph from './node-haste/DependencyGraph';
19
19
 
20
- export type BundlerOptions = $ReadOnly<{
20
+ export type BundlerOptions = Readonly<{
21
21
  hasReducedPerformance?: boolean,
22
22
  watch?: boolean,
23
23
  }>;
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @oncall react_native
9
+ */
10
+
11
+ import type {DeltaResult, Options} from './types';
12
+ import type {RootPerfLogger} from 'metro-config';
13
+ import type {ChangeEvent} from 'metro-file-map';
14
+
15
+ import {Graph} from './Graph';
16
+ import EventEmitter from 'events';
17
+ /**
18
+ * This class is in charge of calculating the delta of changed modules that
19
+ * happen between calls. To do so, it subscribes to file changes, so it can
20
+ * traverse the files that have been changed between calls and avoid having to
21
+ * traverse the whole dependency tree for trivial small changes.
22
+ */
23
+ declare class DeltaCalculator<T> extends EventEmitter {
24
+ _changeEventSource: EventEmitter;
25
+ _options: Options<T>;
26
+ _currentBuildPromise: null | undefined | Promise<DeltaResult<T>>;
27
+ _deletedFiles: Set<string>;
28
+ _modifiedFiles: Set<string>;
29
+ _addedFiles: Set<string>;
30
+ _requiresReset: boolean;
31
+ _graph: Graph<T>;
32
+ constructor(
33
+ entryPoints: ReadonlySet<string>,
34
+ changeEventSource: EventEmitter,
35
+ options: Options<T>,
36
+ );
37
+ /**
38
+ * Stops listening for file changes and clears all the caches.
39
+ */
40
+ end(): void;
41
+ /**
42
+ * Main method to calculate the delta of modules. It returns a DeltaResult,
43
+ * which contain the modified/added modules and the removed modules.
44
+ */
45
+ getDelta($$PARAM_0$$: {
46
+ reset: boolean;
47
+ shallow: boolean;
48
+ }): Promise<DeltaResult<T>>;
49
+ /**
50
+ * Returns the graph with all the dependencies. Each module contains the
51
+ * needed information to do the traversing (dependencies, inverseDependencies)
52
+ * plus some metadata.
53
+ */
54
+ getGraph(): Graph<T>;
55
+ _handleMultipleFileChanges: (changeEvent: ChangeEvent) => void;
56
+ /**
57
+ * Handles a single file change. To avoid doing any work before it's needed,
58
+ * the listener only stores the modified file, which will then be used later
59
+ * when the delta needs to be calculated.
60
+ */
61
+ _handleFileChange: (
62
+ $$PARAM_0$$: ChangeEvent['eventsQueue'][number],
63
+ logger: null | undefined | RootPerfLogger,
64
+ ) => unknown;
65
+ _getChangedDependencies(
66
+ modifiedFiles: Set<string>,
67
+ deletedFiles: Set<string>,
68
+ addedFiles: Set<string>,
69
+ ): Promise<DeltaResult<T>>;
70
+ }
71
+ export default DeltaCalculator;
@@ -84,8 +84,8 @@ class DeltaCalculator extends _events.default {
84
84
  });
85
85
  return {
86
86
  added: this._graph.dependencies,
87
- modified: new Map(),
88
87
  deleted: new Set(),
88
+ modified: new Map(),
89
89
  reset: true,
90
90
  };
91
91
  }
@@ -157,8 +157,8 @@ class DeltaCalculator extends _events.default {
157
157
  );
158
158
  return {
159
159
  added,
160
- modified: new Map(),
161
160
  deleted: new Set(),
161
+ modified: new Map(),
162
162
  reset: true,
163
163
  };
164
164
  }
@@ -182,8 +182,8 @@ class DeltaCalculator extends _events.default {
182
182
  if (modifiedDependencies.length === 0) {
183
183
  return {
184
184
  added: new Map(),
185
- modified: new Map(),
186
185
  deleted: new Set(),
186
+ modified: new Map(),
187
187
  reset: false,
188
188
  };
189
189
  }
@@ -200,8 +200,8 @@ class DeltaCalculator extends _events.default {
200
200
  );
201
201
  return {
202
202
  added,
203
- modified,
204
203
  deleted,
204
+ modified,
205
205
  reset: false,
206
206
  };
207
207
  }