metro 0.65.2 → 0.67.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 +27 -27
  2. package/src/Assets.js +9 -9
  3. package/src/Assets.js.flow +5 -7
  4. package/src/Bundler/util.js +17 -15
  5. package/src/Bundler/util.js.flow +12 -10
  6. package/src/Bundler.js +22 -9
  7. package/src/Bundler.js.flow +20 -7
  8. package/src/DeltaBundler/DeltaCalculator.js +17 -15
  9. package/src/DeltaBundler/DeltaCalculator.js.flow +9 -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 +18 -8
  31. package/src/DeltaBundler/Serializers/helpers/js.js.flow +19 -10
  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 +16 -14
  45. package/src/DeltaBundler/Transformer.js.flow +15 -15
  46. package/src/DeltaBundler/Worker.js +8 -11
  47. package/src/DeltaBundler/Worker.js.flow +8 -11
  48. package/src/DeltaBundler/WorkerFarm.js +15 -18
  49. package/src/DeltaBundler/WorkerFarm.js.flow +9 -11
  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 +15 -1
  61. package/src/DeltaBundler.js +5 -5
  62. package/src/DeltaBundler.js.flow +4 -4
  63. package/src/HmrServer.js +73 -55
  64. package/src/HmrServer.js.flow +42 -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 +46 -32
  72. package/src/IncrementalBundler.js.flow +32 -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 +5 -3
  76. package/src/ModuleGraph/node-haste/HasteFS.js.flow +3 -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 +41 -31
  86. package/src/ModuleGraph/node-haste/node-haste.js.flow +28 -22
  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 +61 -40
  96. package/src/ModuleGraph/output/util.js.flow +51 -28
  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 +47 -31
  102. package/src/ModuleGraph/worker/JsFileWrapping.js +16 -16
  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 +16 -18
  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 +204 -150
  118. package/src/Server.js.flow +131 -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 +19 -19
  127. package/src/commands/serve.js.flow +7 -9
  128. package/src/index.js +117 -50
  129. package/src/index.js.flow +108 -40
  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 +2 -2
  139. package/src/integration_tests/basic_bundle/TestBundle.js.flow +1 -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 +17 -17
  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 +10 -6
  166. package/src/lib/BatchProcessor.js.flow +6 -1
  167. package/src/lib/JsonReporter.js +3 -2
  168. package/src/lib/JsonReporter.js.flow +2 -1
  169. package/src/lib/RamBundleParser.js +1 -1
  170. package/src/lib/RamBundleParser.js.flow +1 -1
  171. package/src/lib/TerminalReporter.js +15 -15
  172. package/src/lib/TerminalReporter.js.flow +15 -16
  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} +13 -23
  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 +18 -20
  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 +16 -15
  196. package/src/lib/getPrependedScripts.js.flow +8 -8
  197. package/src/lib/logToConsole.js +12 -5
  198. package/src/lib/logToConsole.js.flow +19 -6
  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 +18 -4
  207. package/src/lib/splitBundleOptions.js +5 -5
  208. package/src/lib/splitBundleOptions.js.flow +1 -1
  209. package/src/lib/transformHelpers.js +11 -10
  210. package/src/lib/transformHelpers.js.flow +6 -13
  211. package/src/node-haste/DependencyGraph/ModuleResolution.js +51 -30
  212. package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +49 -48
  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 +51 -118
  218. package/src/node-haste/DependencyGraph.js.flow +38 -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 +2 -2
  224. package/src/node-haste/Package.js.flow +1 -1
  225. package/src/node-haste/lib/AssetPaths.js +5 -5
  226. package/src/node-haste/lib/AssetPaths.js.flow +7 -6
  227. package/src/node-haste/lib/parsePlatformFilePath.js +4 -4
  228. package/src/node-haste/lib/parsePlatformFilePath.js.flow +2 -2
  229. package/src/shared/output/RamBundle/as-assets.js +14 -15
  230. package/src/shared/output/RamBundle/as-assets.js.flow +9 -11
  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 +6 -4
  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.
@@ -14,11 +14,14 @@ const Module = require("./Module");
14
14
  const Package = require("./Package");
15
15
 
16
16
  class ModuleCache {
17
+ // Cache for "closest package.json" queries by module path.
18
+ // The inverse of _packagePathByModulePath.
17
19
  constructor(options) {
18
20
  this._getClosestPackage = options.getClosestPackage;
19
21
  this._moduleCache = Object.create(null);
20
22
  this._packageCache = Object.create(null);
21
- this._packageModuleMap = new WeakMap();
23
+ this._packagePathByModulePath = Object.create(null);
24
+ this._modulePathsByPackagePath = Object.create(null);
22
25
  }
23
26
 
24
27
  getModule(filePath) {
@@ -32,7 +35,7 @@ class ModuleCache {
32
35
  getPackage(filePath) {
33
36
  if (!this._packageCache[filePath]) {
34
37
  this._packageCache[filePath] = new Package({
35
- file: filePath
38
+ file: filePath,
36
39
  });
37
40
  }
38
41
 
@@ -40,24 +43,32 @@ class ModuleCache {
40
43
  }
41
44
 
42
45
  getPackageForModule(module) {
43
- let packagePath = this._packageModuleMap.get(module);
46
+ return this.getPackageOf(module.path);
47
+ }
44
48
 
45
- if (packagePath) {
46
- if (this._packageCache[packagePath]) {
47
- return this._packageCache[packagePath];
48
- } else {
49
- this._packageModuleMap.delete(module);
50
- }
49
+ getPackageOf(modulePath) {
50
+ var _this$_modulePathsByP;
51
+
52
+ let packagePath = this._packagePathByModulePath[modulePath];
53
+
54
+ if (packagePath && this._packageCache[packagePath]) {
55
+ return this._packageCache[packagePath];
51
56
  }
52
57
 
53
- packagePath = this._getClosestPackage(module.path);
58
+ packagePath = this._getClosestPackage(modulePath);
54
59
 
55
60
  if (!packagePath) {
56
61
  return null;
57
62
  }
58
63
 
59
- this._packageModuleMap.set(module, packagePath);
60
-
64
+ this._packagePathByModulePath[modulePath] = packagePath;
65
+ const modulePaths =
66
+ (_this$_modulePathsByP = this._modulePathsByPackagePath[packagePath]) !==
67
+ null && _this$_modulePathsByP !== void 0
68
+ ? _this$_modulePathsByP
69
+ : new Set();
70
+ modulePaths.add(modulePath);
71
+ this._modulePathsByPackagePath[packagePath] = modulePaths;
61
72
  return this.getPackage(packagePath);
62
73
  }
63
74
 
@@ -73,6 +84,36 @@ class ModuleCache {
73
84
 
74
85
  delete this._packageCache[filePath];
75
86
  }
87
+
88
+ if (this._packagePathByModulePath[filePath]) {
89
+ // filePath is a module inside a package.
90
+ const packagePath = this._packagePathByModulePath[filePath];
91
+ delete this._packagePathByModulePath[filePath]; // This change doesn't invalidate any cached "closest package.json"
92
+ // queries for the package's other modules. Clean up only this module.
93
+
94
+ const modulePaths = this._modulePathsByPackagePath[packagePath];
95
+
96
+ if (modulePaths) {
97
+ modulePaths.delete(filePath);
98
+
99
+ if (modulePaths.size === 0) {
100
+ delete this._modulePathsByPackagePath[packagePath];
101
+ }
102
+ }
103
+ }
104
+
105
+ if (this._modulePathsByPackagePath[filePath]) {
106
+ // filePath is a package. This change invalidates all cached "closest
107
+ // package.json" queries for modules inside this package.
108
+ const modulePaths = this._modulePathsByPackagePath[filePath];
109
+
110
+ for (const modulePath of modulePaths) {
111
+ delete this._packagePathByModulePath[modulePath];
112
+ }
113
+
114
+ modulePaths.clear();
115
+ delete this._modulePathsByPackagePath[filePath];
116
+ }
76
117
  }
77
118
  }
78
119
 
@@ -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.
@@ -27,13 +27,25 @@ class ModuleCache {
27
27
  __proto__: null,
28
28
  ...
29
29
  };
30
- _packageModuleMap: WeakMap<Module, string>;
30
+ // Cache for "closest package.json" queries by module path.
31
+ _packagePathByModulePath: {
32
+ [filePath: string]: string,
33
+ __proto__: null,
34
+ ...
35
+ };
36
+ // The inverse of _packagePathByModulePath.
37
+ _modulePathsByPackagePath: {
38
+ [filePath: string]: Set<string>,
39
+ __proto__: null,
40
+ ...
41
+ };
31
42
 
32
43
  constructor(options: {getClosestPackage: GetClosestPackageFn, ...}) {
33
44
  this._getClosestPackage = options.getClosestPackage;
34
45
  this._moduleCache = Object.create(null);
35
46
  this._packageCache = Object.create(null);
36
- this._packageModuleMap = new WeakMap();
47
+ this._packagePathByModulePath = Object.create(null);
48
+ this._modulePathsByPackagePath = Object.create(null);
37
49
  }
38
50
 
39
51
  getModule(filePath: string): Module {
@@ -53,21 +65,26 @@ class ModuleCache {
53
65
  }
54
66
 
55
67
  getPackageForModule(module: Module): ?Package {
56
- let packagePath = this._packageModuleMap.get(module);
57
- if (packagePath) {
58
- if (this._packageCache[packagePath]) {
59
- return this._packageCache[packagePath];
60
- } else {
61
- this._packageModuleMap.delete(module);
62
- }
68
+ return this.getPackageOf(module.path);
69
+ }
70
+
71
+ getPackageOf(modulePath: string): ?Package {
72
+ let packagePath = this._packagePathByModulePath[modulePath];
73
+ if (packagePath && this._packageCache[packagePath]) {
74
+ return this._packageCache[packagePath];
63
75
  }
64
76
 
65
- packagePath = this._getClosestPackage(module.path);
77
+ packagePath = this._getClosestPackage(modulePath);
66
78
  if (!packagePath) {
67
79
  return null;
68
80
  }
69
81
 
70
- this._packageModuleMap.set(module, packagePath);
82
+ this._packagePathByModulePath[modulePath] = packagePath;
83
+ const modulePaths =
84
+ this._modulePathsByPackagePath[packagePath] ?? new Set();
85
+ modulePaths.add(modulePath);
86
+ this._modulePathsByPackagePath[packagePath] = modulePaths;
87
+
71
88
  return this.getPackage(packagePath);
72
89
  }
73
90
 
@@ -80,6 +97,30 @@ class ModuleCache {
80
97
  this._packageCache[filePath].invalidate();
81
98
  delete this._packageCache[filePath];
82
99
  }
100
+ if (this._packagePathByModulePath[filePath]) {
101
+ // filePath is a module inside a package.
102
+ const packagePath = this._packagePathByModulePath[filePath];
103
+ delete this._packagePathByModulePath[filePath];
104
+ // This change doesn't invalidate any cached "closest package.json"
105
+ // queries for the package's other modules. Clean up only this module.
106
+ const modulePaths = this._modulePathsByPackagePath[packagePath];
107
+ if (modulePaths) {
108
+ modulePaths.delete(filePath);
109
+ if (modulePaths.size === 0) {
110
+ delete this._modulePathsByPackagePath[packagePath];
111
+ }
112
+ }
113
+ }
114
+ if (this._modulePathsByPackagePath[filePath]) {
115
+ // filePath is a package. This change invalidates all cached "closest
116
+ // package.json" queries for modules inside this package.
117
+ const modulePaths = this._modulePathsByPackagePath[filePath];
118
+ for (const modulePath of modulePaths) {
119
+ delete this._packagePathByModulePath[modulePath];
120
+ }
121
+ modulePaths.clear();
122
+ delete this._modulePathsByPackagePath[filePath];
123
+ }
83
124
  }
84
125
  }
85
126
 
@@ -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.
@@ -125,7 +125,7 @@ class Package {
125
125
 
126
126
  function getReplacements(pkg, mainFields) {
127
127
  const replacements = mainFields
128
- .map(name => {
128
+ .map((name) => {
129
129
  // If the field is a string, that doesn't mean we want to redirect the
130
130
  // `main` file itself to anything else. See the spec.
131
131
  if (!pkg[name] || typeof pkg[name] === "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.
@@ -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.
@@ -30,14 +30,14 @@ function parseBaseName(baseName) {
30
30
  if (!Number.isNaN(resolution)) {
31
31
  return {
32
32
  rootName,
33
- resolution
33
+ resolution,
34
34
  };
35
35
  }
36
36
  }
37
37
 
38
38
  return {
39
39
  rootName,
40
- resolution: 1
40
+ resolution: 1,
41
41
  };
42
42
  }
43
43
  /**
@@ -59,7 +59,7 @@ function tryParse(filePath, platforms) {
59
59
  name: rootName,
60
60
  platform,
61
61
  resolution,
62
- type: extension
62
+ type: extension,
63
63
  };
64
64
  }
65
65
 
@@ -75,5 +75,5 @@ function parse(filePath, platforms) {
75
75
 
76
76
  module.exports = {
77
77
  parse,
78
- tryParse
78
+ tryParse,
79
79
  };
@@ -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.
@@ -23,9 +23,7 @@ export type AssetPath = {|
23
23
 
24
24
  const ASSET_BASE_NAME_RE = /(.+?)(@([\d.]+)x)?$/;
25
25
 
26
- function parseBaseName(
27
- baseName: string,
28
- ): {
26
+ function parseBaseName(baseName: string): {
29
27
  resolution: number,
30
28
  rootName: string,
31
29
  ...
@@ -48,7 +46,10 @@ function parseBaseName(
48
46
  * Return `null` if the `filePath` doesn't have a valid extension, required
49
47
  * to describe the type of an asset.
50
48
  */
51
- function tryParse(filePath: string, platforms: Set<string>): ?AssetPath {
49
+ function tryParse(
50
+ filePath: string,
51
+ platforms: $ReadOnlySet<string>,
52
+ ): ?AssetPath {
52
53
  const result = parsePlatformFilePath(filePath, platforms);
53
54
  const {dirPath, baseName, platform, extension} = result;
54
55
  if (extension == null) {
@@ -64,7 +65,7 @@ function tryParse(filePath: string, platforms: Set<string>): ?AssetPath {
64
65
  };
65
66
  }
66
67
 
67
- function parse(filePath: string, platforms: Set<string>): AssetPath {
68
+ function parse(filePath: string, platforms: $ReadOnlySet<string>): AssetPath {
68
69
  const result = tryParse(filePath, platforms);
69
70
  if (result == null) {
70
71
  throw new Error('invalid asset file path: `${filePath}');
@@ -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.
@@ -27,7 +27,7 @@ function parsePlatformFilePath(filePath, platforms) {
27
27
  dirPath,
28
28
  baseName: fileName,
29
29
  platform: null,
30
- extension: null
30
+ extension: null,
31
31
  };
32
32
  }
33
33
 
@@ -39,7 +39,7 @@ function parsePlatformFilePath(filePath, platforms) {
39
39
  dirPath,
40
40
  baseName: match[1],
41
41
  platform,
42
- extension
42
+ extension,
43
43
  };
44
44
  }
45
45
 
@@ -48,7 +48,7 @@ function parsePlatformFilePath(filePath, platforms) {
48
48
  dirPath,
49
49
  baseName,
50
50
  platform: null,
51
- extension
51
+ extension,
52
52
  };
53
53
  }
54
54
 
@@ -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.
@@ -27,7 +27,7 @@ const PATH_RE = /^(.+?)(\.([^.]+))?\.([^.]+)$/;
27
27
  */
28
28
  function parsePlatformFilePath(
29
29
  filePath: string,
30
- platforms: Set<string>,
30
+ platforms: $ReadOnlySet<string>,
31
31
  ): PlatformFilePathParts {
32
32
  const dirPath = path.dirname(filePath);
33
33
  const fileName = path.basename(filePath);
@@ -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,22 @@
9
9
  */
10
10
  "use strict";
11
11
 
12
- const MAGIC_RAM_BUNDLE_NUMBER = require("./magic-number");
13
-
14
- const buildSourcemapWithMetadata = require("./buildSourcemapWithMetadata");
12
+ const relativizeSourceMapInline = require("../../../lib/relativizeSourceMap");
15
13
 
16
- const mkdirp = require("mkdirp");
14
+ const writeFile = require("../writeFile");
17
15
 
18
- const path = require("path");
16
+ const buildSourcemapWithMetadata = require("./buildSourcemapWithMetadata");
19
17
 
20
- const relativizeSourceMapInline = require("../../../lib/relativizeSourceMap");
18
+ const MAGIC_RAM_BUNDLE_NUMBER = require("./magic-number");
21
19
 
22
- const writeFile = require("../writeFile");
20
+ const { joinModules } = require("./util");
23
21
 
24
22
  const writeSourceMap = require("./write-sourcemap");
25
23
 
26
- const { joinModules } = require("./util");
24
+ const mkdirp = require("mkdirp");
25
+
26
+ const path = require("path"); // must not start with a dot, as that won't go into the apk
27
27
 
28
- // must not start with a dot, as that won't go into the apk
29
28
  const MAGIC_RAM_BUNDLE_FILENAME = "UNBUNDLE";
30
29
  const MODULES_DIR = "js-modules";
31
30
  /**
@@ -41,7 +40,7 @@ function saveAsAssets(bundle, options, log) {
41
40
  bundleOutput,
42
41
  bundleEncoding: encoding,
43
42
  sourcemapOutput,
44
- sourcemapSourcesRoot
43
+ sourcemapSourcesRoot,
45
44
  } = options;
46
45
  log("start");
47
46
  const { startupModules, lazyModules } = bundle;
@@ -55,7 +54,7 @@ function saveAsAssets(bundle, options, log) {
55
54
  Promise.all([
56
55
  writeModules(lazyModules, modulesDir, encoding),
57
56
  writeFile(bundleOutput, startupCode, encoding),
58
- writeMagicFlagFile(modulesDir)
57
+ writeMagicFlagFile(modulesDir),
59
58
  ])
60
59
  );
61
60
  writeUnbundle.then(() => log("Done writing unbundle output"));
@@ -65,7 +64,7 @@ function saveAsAssets(bundle, options, log) {
65
64
  fixWrapperOffset: true,
66
65
  lazyModules: lazyModules.concat(),
67
66
  moduleGroups: null,
68
- startupModules: startupModules.concat()
67
+ startupModules: startupModules.concat(),
69
68
  });
70
69
 
71
70
  if (sourcemapSourcesRoot !== undefined) {
@@ -85,7 +84,7 @@ function saveAsAssets(bundle, options, log) {
85
84
 
86
85
  function createDir(dirName) {
87
86
  return new Promise((resolve, reject) =>
88
- mkdirp(dirName, error => (error ? reject(error) : resolve()))
87
+ mkdirp(dirName, (error) => (error ? reject(error) : resolve()))
89
88
  );
90
89
  }
91
90
 
@@ -95,7 +94,7 @@ function writeModuleFile(module, modulesDir, encoding) {
95
94
  }
96
95
 
97
96
  function writeModules(modules, modulesDir, encoding) {
98
- const writeFiles = modules.map(module =>
97
+ const writeFiles = modules.map((module) =>
99
98
  writeModuleFile(module, modulesDir, encoding)
100
99
  );
101
100
  return Promise.all(writeFiles);
@@ -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,20 +10,18 @@
10
10
 
11
11
  'use strict';
12
12
 
13
- const MAGIC_RAM_BUNDLE_NUMBER = require('./magic-number');
13
+ import type {RamBundleInfo} from '../../../DeltaBundler/Serializers/getRamBundleInfo';
14
+ import type {ModuleTransportLike} from '../../../shared/types.flow';
15
+ import type {OutputOptions} from '../../types.flow';
14
16
 
15
- const buildSourcemapWithMetadata = require('./buildSourcemapWithMetadata');
16
- const mkdirp = require('mkdirp');
17
- const path = require('path');
18
17
  const relativizeSourceMapInline = require('../../../lib/relativizeSourceMap');
19
18
  const writeFile = require('../writeFile');
20
- const writeSourceMap = require('./write-sourcemap');
21
-
19
+ const buildSourcemapWithMetadata = require('./buildSourcemapWithMetadata');
20
+ const MAGIC_RAM_BUNDLE_NUMBER = require('./magic-number');
22
21
  const {joinModules} = require('./util');
23
-
24
- import type {RamBundleInfo} from '../../../DeltaBundler/Serializers/getRamBundleInfo';
25
- import type {ModuleTransportLike} from '../../../shared/types.flow';
26
- import type {OutputOptions} from '../../types.flow';
22
+ const writeSourceMap = require('./write-sourcemap');
23
+ const mkdirp = require('mkdirp');
24
+ const path = require('path');
27
25
  // must not start with a dot, as that won't go into the apk
28
26
  const MAGIC_RAM_BUNDLE_FILENAME = 'UNBUNDLE';
29
27
  const MODULES_DIR = 'js-modules';
@@ -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,17 +9,17 @@
9
9
  */
10
10
  "use strict";
11
11
 
12
- const MAGIC_UNBUNDLE_FILE_HEADER = require("./magic-number");
12
+ const relativizeSourceMapInline = require("../../../lib/relativizeSourceMap");
13
13
 
14
14
  const buildSourcemapWithMetadata = require("./buildSourcemapWithMetadata");
15
15
 
16
- const fs = require("fs");
16
+ const MAGIC_UNBUNDLE_FILE_HEADER = require("./magic-number");
17
17
 
18
- const relativizeSourceMapInline = require("../../../lib/relativizeSourceMap");
18
+ const { joinModules } = require("./util");
19
19
 
20
20
  const writeSourceMap = require("./write-sourcemap");
21
21
 
22
- const { joinModules } = require("./util");
22
+ const fs = require("fs");
23
23
 
24
24
  const SIZEOF_UINT32 = 4;
25
25
  /**
@@ -35,7 +35,7 @@ function saveAsIndexedFile(bundle, options, log) {
35
35
  bundleOutput,
36
36
  bundleEncoding: encoding,
37
37
  sourcemapOutput,
38
- sourcemapSourcesRoot
38
+ sourcemapSourcesRoot,
39
39
  } = options;
40
40
  log("start");
41
41
  const { startupModules, lazyModules, groups } = bundle;
@@ -53,7 +53,7 @@ function saveAsIndexedFile(bundle, options, log) {
53
53
  startupModules: startupModules.concat(),
54
54
  lazyModules: lazyModules.concat(),
55
55
  moduleGroups,
56
- fixWrapperOffset: true
56
+ fixWrapperOffset: true,
57
57
  });
58
58
 
59
59
  if (sourcemapSourcesRoot !== undefined) {
@@ -70,14 +70,13 @@ function saveAsIndexedFile(bundle, options, log) {
70
70
  return writeUnbundle;
71
71
  }
72
72
  }
73
- /* global Buffer: true */
74
73
 
75
74
  const fileHeader = Buffer.alloc(4);
76
75
  fileHeader.writeUInt32LE(MAGIC_UNBUNDLE_FILE_HEADER, 0);
77
76
  const nullByteBuffer = Buffer.alloc(1).fill(0);
78
77
 
79
78
  function writeBuffers(stream, buffers) {
80
- buffers.forEach(buffer => stream.write(buffer));
79
+ buffers.forEach((buffer) => stream.write(buffer));
81
80
  return new Promise((resolve, reject) => {
82
81
  stream.on("error", reject);
83
82
  stream.on("finish", () => resolve());
@@ -92,7 +91,7 @@ function nullTerminatedBuffer(contents, encoding) {
92
91
  function moduleToBuffer(id, code, encoding) {
93
92
  return {
94
93
  id,
95
- buffer: nullTerminatedBuffer(code, encoding)
94
+ buffer: nullTerminatedBuffer(code, encoding),
96
95
  };
97
96
  }
98
97
 
@@ -124,7 +123,7 @@ function buildModuleTable(startupCode, moduleBuffers, moduleGroups) {
124
123
  moduleBuffers.forEach(({ id, buffer }) => {
125
124
  const group = moduleGroups.groups.get(id);
126
125
  const idsInGroup = group ? [id].concat(Array.from(group)) : [id];
127
- idsInGroup.forEach(moduleId => {
126
+ idsInGroup.forEach((moduleId) => {
128
127
  const offset = entryOffset(moduleId); // module_offset
129
128
 
130
129
  table.writeUInt32LE(codeOffset, offset); // module_length
@@ -147,7 +146,7 @@ function groupCode(rootCode, moduleGroup, modulesById) {
147
146
  code.push(
148
147
  (
149
148
  modulesById.get(id) || {
150
- code: ""
149
+ code: "",
151
150
  }
152
151
  ).code
153
152
  );
@@ -158,7 +157,7 @@ function groupCode(rootCode, moduleGroup, modulesById) {
158
157
 
159
158
  function buildModuleBuffers(modules, moduleGroups, encoding) {
160
159
  return modules
161
- .filter(m => !moduleGroups.modulesInGroups.has(m.id))
160
+ .filter((m) => !moduleGroups.modulesInGroups.has(m.id))
162
161
  .map(({ id, code }) =>
163
162
  moduleToBuffer(
164
163
  id,
@@ -189,8 +188,8 @@ function buildTableAndContents(startupCode, modules, moduleGroups, encoding) {
189
188
  function createModuleGroups(groups, modules) {
190
189
  return {
191
190
  groups,
192
- modulesById: new Map(modules.map(m => [m.id, m])),
193
- modulesInGroups: new Set(concat(groups.values()))
191
+ modulesById: new Map(modules.map((m) => [m.id, m])),
192
+ modulesInGroups: new Set(concat(groups.values())),
194
193
  };
195
194
  }
196
195
 
@@ -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,6 @@
10
10
 
11
11
  'use strict';
12
12
 
13
- const MAGIC_UNBUNDLE_FILE_HEADER = require('./magic-number');
14
-
15
- const buildSourcemapWithMetadata = require('./buildSourcemapWithMetadata');
16
- const fs = require('fs');
17
- const relativizeSourceMapInline = require('../../../lib/relativizeSourceMap');
18
- const writeSourceMap = require('./write-sourcemap');
19
-
20
- const {joinModules} = require('./util');
21
-
22
13
  import type {RamBundleInfo} from '../../../DeltaBundler/Serializers/getRamBundleInfo';
23
14
  import type {
24
15
  ModuleGroups,
@@ -27,6 +18,13 @@ import type {
27
18
  } from '../../types.flow';
28
19
  import type {WriteStream} from 'fs';
29
20
 
21
+ const relativizeSourceMapInline = require('../../../lib/relativizeSourceMap');
22
+ const buildSourcemapWithMetadata = require('./buildSourcemapWithMetadata');
23
+ const MAGIC_UNBUNDLE_FILE_HEADER = require('./magic-number');
24
+ const {joinModules} = require('./util');
25
+ const writeSourceMap = require('./write-sourcemap');
26
+ const fs = require('fs');
27
+
30
28
  const SIZEOF_UINT32 = 4;
31
29
 
32
30
  /**
@@ -84,8 +82,6 @@ function saveAsIndexedFile(
84
82
  }
85
83
  }
86
84
 
87
- /* global Buffer: true */
88
-
89
85
  const fileHeader = Buffer.alloc(4);
90
86
  fileHeader.writeUInt32LE(MAGIC_UNBUNDLE_FILE_HEADER, 0);
91
87
  const nullByteBuffer: Buffer = Buffer.alloc(1).fill(0);
@@ -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,32 +12,32 @@
12
12
  const {
13
13
  combineSourceMaps,
14
14
  combineSourceMapsAddingOffsets,
15
- joinModules
15
+ joinModules,
16
16
  } = require("./util");
17
17
 
18
18
  module.exports = ({
19
19
  fixWrapperOffset,
20
20
  lazyModules,
21
21
  moduleGroups,
22
- startupModules
22
+ startupModules,
23
23
  }) => {
24
24
  const options = fixWrapperOffset
25
25
  ? {
26
- fixWrapperOffset: true
26
+ fixWrapperOffset: true,
27
27
  }
28
28
  : undefined;
29
29
  const startupModule = {
30
30
  code: joinModules(startupModules),
31
31
  id: Number.MIN_SAFE_INTEGER,
32
32
  map: combineSourceMaps(startupModules, undefined, options),
33
- sourcePath: ""
33
+ sourcePath: "",
34
34
  }; // Add map of module id -> source to sourcemap
35
35
 
36
36
  const module_paths = [];
37
- startupModules.forEach(m => {
37
+ startupModules.forEach((m) => {
38
38
  module_paths[m.id] = m.sourcePath;
39
39
  });
40
- lazyModules.forEach(m => {
40
+ lazyModules.forEach((m) => {
41
41
  module_paths[m.id] = m.sourcePath;
42
42
  });
43
43
  const map = combineSourceMapsAddingOffsets(