metro 0.66.2 → 0.69.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (255) hide show
  1. package/package.json +22 -24
  2. package/src/Assets.js +9 -9
  3. package/src/Assets.js.flow +5 -7
  4. package/src/Bundler/util.js +16 -15
  5. package/src/Bundler/util.js.flow +11 -10
  6. package/src/Bundler.js +21 -8
  7. package/src/Bundler.js.flow +19 -7
  8. package/src/DeltaBundler/DeltaCalculator.js +15 -15
  9. package/src/DeltaBundler/DeltaCalculator.js.flow +7 -7
  10. package/src/DeltaBundler/Serializers/baseBytecodeBundle.js +13 -13
  11. package/src/DeltaBundler/Serializers/baseBytecodeBundle.js.flow +6 -7
  12. package/src/DeltaBundler/Serializers/baseJSBundle.js +4 -4
  13. package/src/DeltaBundler/Serializers/baseJSBundle.js.flow +4 -4
  14. package/src/DeltaBundler/Serializers/getAllFiles.js +1 -1
  15. package/src/DeltaBundler/Serializers/getAllFiles.js.flow +3 -3
  16. package/src/DeltaBundler/Serializers/getAssets.js +3 -3
  17. package/src/DeltaBundler/Serializers/getAssets.js.flow +4 -5
  18. package/src/DeltaBundler/Serializers/getExplodedSourceMap.js +4 -4
  19. package/src/DeltaBundler/Serializers/getExplodedSourceMap.js.flow +4 -4
  20. package/src/DeltaBundler/Serializers/getRamBundleInfo.js +20 -20
  21. package/src/DeltaBundler/Serializers/getRamBundleInfo.js.flow +9 -10
  22. package/src/DeltaBundler/Serializers/helpers/bytecode.js +11 -11
  23. package/src/DeltaBundler/Serializers/helpers/bytecode.js.flow +5 -6
  24. package/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.js +1 -1
  25. package/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.js.flow +1 -1
  26. package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js +2 -2
  27. package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js.flow +4 -4
  28. package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.js +1 -1
  29. package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.js.flow +1 -1
  30. package/src/DeltaBundler/Serializers/helpers/js.js +6 -6
  31. package/src/DeltaBundler/Serializers/helpers/js.js.flow +11 -12
  32. package/src/DeltaBundler/Serializers/helpers/processBytecodeModules.js +4 -4
  33. package/src/DeltaBundler/Serializers/helpers/processBytecodeModules.js.flow +3 -3
  34. package/src/DeltaBundler/Serializers/helpers/processModules.js +4 -4
  35. package/src/DeltaBundler/Serializers/helpers/processModules.js.flow +3 -3
  36. package/src/DeltaBundler/Serializers/hmrJSBundle.js +9 -9
  37. package/src/DeltaBundler/Serializers/hmrJSBundle.js.flow +9 -8
  38. package/src/DeltaBundler/Serializers/sourceMapGenerator.js +6 -6
  39. package/src/DeltaBundler/Serializers/sourceMapGenerator.js.flow +3 -4
  40. package/src/DeltaBundler/Serializers/sourceMapObject.js +5 -5
  41. package/src/DeltaBundler/Serializers/sourceMapObject.js.flow +4 -4
  42. package/src/DeltaBundler/Serializers/sourceMapString.js +2 -2
  43. package/src/DeltaBundler/Serializers/sourceMapString.js.flow +3 -3
  44. package/src/DeltaBundler/Transformer.js +9 -9
  45. package/src/DeltaBundler/Transformer.js.flow +7 -9
  46. package/src/DeltaBundler/Worker.js +8 -11
  47. package/src/DeltaBundler/Worker.js.flow +8 -11
  48. package/src/DeltaBundler/WorkerFarm.js +14 -17
  49. package/src/DeltaBundler/WorkerFarm.js.flow +7 -10
  50. package/src/DeltaBundler/__fixtures__/hasteImpl.js +2 -2
  51. package/src/DeltaBundler/computeDelta.js +2 -2
  52. package/src/DeltaBundler/computeDelta.js.flow +2 -2
  53. package/src/DeltaBundler/getTransformCacheKey.js +4 -4
  54. package/src/DeltaBundler/getTransformCacheKey.js.flow +5 -6
  55. package/src/DeltaBundler/mergeDeltas.js +2 -2
  56. package/src/DeltaBundler/mergeDeltas.js.flow +1 -1
  57. package/src/DeltaBundler/traverseDependencies.js +22 -22
  58. package/src/DeltaBundler/traverseDependencies.js.flow +3 -3
  59. package/src/DeltaBundler/types.flow.js +1 -1
  60. package/src/DeltaBundler/types.flow.js.flow +1 -1
  61. package/src/DeltaBundler.js +5 -5
  62. package/src/DeltaBundler.js.flow +4 -4
  63. package/src/HmrServer.js +71 -55
  64. package/src/HmrServer.js.flow +40 -37
  65. package/src/IncrementalBundler/GraphNotFoundError.js +1 -1
  66. package/src/IncrementalBundler/GraphNotFoundError.js.flow +1 -1
  67. package/src/IncrementalBundler/ResourceNotFoundError.js +1 -1
  68. package/src/IncrementalBundler/ResourceNotFoundError.js.flow +1 -1
  69. package/src/IncrementalBundler/RevisionNotFoundError.js +1 -1
  70. package/src/IncrementalBundler/RevisionNotFoundError.js.flow +1 -1
  71. package/src/IncrementalBundler.js +44 -32
  72. package/src/IncrementalBundler.js.flow +30 -24
  73. package/src/ModuleGraph/module.js +3 -3
  74. package/src/ModuleGraph/module.js.flow +1 -1
  75. package/src/ModuleGraph/node-haste/HasteFS.js +2 -2
  76. package/src/ModuleGraph/node-haste/HasteFS.js.flow +1 -1
  77. package/src/ModuleGraph/node-haste/Module.js +1 -1
  78. package/src/ModuleGraph/node-haste/Module.js.flow +1 -1
  79. package/src/ModuleGraph/node-haste/ModuleCache.js +1 -1
  80. package/src/ModuleGraph/node-haste/ModuleCache.js.flow +3 -3
  81. package/src/ModuleGraph/node-haste/Package.js +3 -3
  82. package/src/ModuleGraph/node-haste/Package.js.flow +3 -3
  83. package/src/ModuleGraph/node-haste/node-haste.flow.js +1 -1
  84. package/src/ModuleGraph/node-haste/node-haste.flow.js.flow +1 -1
  85. package/src/ModuleGraph/node-haste/node-haste.js +42 -32
  86. package/src/ModuleGraph/node-haste/node-haste.js.flow +28 -23
  87. package/src/ModuleGraph/output/indexed-ram-bundle.js +17 -17
  88. package/src/ModuleGraph/output/indexed-ram-bundle.js.flow +41 -9
  89. package/src/ModuleGraph/output/multiple-files-ram-bundle.js +18 -18
  90. package/src/ModuleGraph/output/multiple-files-ram-bundle.js.flow +21 -9
  91. package/src/ModuleGraph/output/plain-bundle.js +6 -6
  92. package/src/ModuleGraph/output/plain-bundle.js.flow +7 -7
  93. package/src/ModuleGraph/output/reverse-dependency-map-references.js +3 -3
  94. package/src/ModuleGraph/output/reverse-dependency-map-references.js.flow +4 -8
  95. package/src/ModuleGraph/output/util.js +31 -30
  96. package/src/ModuleGraph/output/util.js.flow +15 -16
  97. package/src/ModuleGraph/silent-console.js +2 -2
  98. package/src/ModuleGraph/silent-console.js.flow +1 -1
  99. package/src/ModuleGraph/test-helpers.js +7 -7
  100. package/src/ModuleGraph/types.flow.js +1 -1
  101. package/src/ModuleGraph/types.flow.js.flow +7 -7
  102. package/src/ModuleGraph/worker/JsFileWrapping.js +7 -7
  103. package/src/ModuleGraph/worker/JsFileWrapping.js.flow +3 -2
  104. package/src/ModuleGraph/worker/Platforms.js +2 -2
  105. package/src/ModuleGraph/worker/Platforms.js.flow +1 -1
  106. package/src/ModuleGraph/worker/collectDependencies.js +24 -25
  107. package/src/ModuleGraph/worker/collectDependencies.js.flow +15 -17
  108. package/src/ModuleGraph/worker/generate.js +2 -2
  109. package/src/ModuleGraph/worker/generate.js.flow +3 -3
  110. package/src/ModuleGraph/worker/generateImportNames.js +5 -5
  111. package/src/ModuleGraph/worker/generateImportNames.js.flow +3 -5
  112. package/src/ModuleGraph/worker/mergeSourceMaps.js +8 -7
  113. package/src/ModuleGraph/worker/mergeSourceMaps.js.flow +3 -3
  114. package/src/Server/MultipartResponse.js +4 -8
  115. package/src/Server/symbolicate.js +8 -8
  116. package/src/Server/symbolicate.js.flow +17 -5
  117. package/src/Server.js +202 -150
  118. package/src/Server.js.flow +129 -87
  119. package/src/cli-utils.js +4 -4
  120. package/src/cli-utils.js.flow +15 -13
  121. package/src/cli.js +4 -4
  122. package/src/cli.js.flow +2 -4
  123. package/src/commands/build.js +23 -24
  124. package/src/commands/build.js.flow +6 -9
  125. package/src/commands/dependencies.js +25 -19
  126. package/src/commands/serve.js +17 -18
  127. package/src/commands/serve.js.flow +6 -9
  128. package/src/index.js +116 -51
  129. package/src/index.js.flow +107 -41
  130. package/src/integration_tests/basic_bundle/AssetRegistry.js +2 -2
  131. package/src/integration_tests/basic_bundle/AssetRegistry.js.flow +1 -1
  132. package/src/integration_tests/basic_bundle/Bar.js +2 -2
  133. package/src/integration_tests/basic_bundle/Bar.js.flow +1 -1
  134. package/src/integration_tests/basic_bundle/ErrorBundle.js +2 -2
  135. package/src/integration_tests/basic_bundle/ErrorBundle.js.flow +1 -1
  136. package/src/integration_tests/basic_bundle/Foo.js +2 -2
  137. package/src/integration_tests/basic_bundle/Foo.js.flow +1 -1
  138. package/src/integration_tests/basic_bundle/TestBundle.js +3 -2
  139. package/src/integration_tests/basic_bundle/TestBundle.js.flow +3 -1
  140. package/src/integration_tests/basic_bundle/TestPolyfill.js +1 -1
  141. package/src/integration_tests/basic_bundle/TestPolyfill.js.flow +1 -1
  142. package/src/integration_tests/basic_bundle/TypeScript.ts +1 -1
  143. package/src/integration_tests/basic_bundle/import-export/export-1.js +2 -2
  144. package/src/integration_tests/basic_bundle/import-export/export-1.js.flow +1 -1
  145. package/src/integration_tests/basic_bundle/import-export/export-2.js +2 -2
  146. package/src/integration_tests/basic_bundle/import-export/export-2.js.flow +1 -1
  147. package/src/integration_tests/basic_bundle/import-export/export-3.js +2 -2
  148. package/src/integration_tests/basic_bundle/import-export/export-3.js.flow +1 -1
  149. package/src/integration_tests/basic_bundle/import-export/export-4.js +2 -2
  150. package/src/integration_tests/basic_bundle/import-export/export-4.js.flow +1 -1
  151. package/src/integration_tests/basic_bundle/import-export/export-5.js +2 -2
  152. package/src/integration_tests/basic_bundle/import-export/export-5.js.flow +1 -1
  153. package/src/integration_tests/basic_bundle/import-export/export-6.js +2 -2
  154. package/src/integration_tests/basic_bundle/import-export/export-6.js.flow +1 -1
  155. package/src/integration_tests/basic_bundle/import-export/export-null.js +2 -2
  156. package/src/integration_tests/basic_bundle/import-export/export-null.js.flow +1 -1
  157. package/src/integration_tests/basic_bundle/import-export/export-primitive-default.js +2 -2
  158. package/src/integration_tests/basic_bundle/import-export/export-primitive-default.js.flow +1 -1
  159. package/src/integration_tests/basic_bundle/import-export/index.js +8 -8
  160. package/src/integration_tests/basic_bundle/import-export/index.js.flow +1 -1
  161. package/src/integration_tests/basic_bundle/polyfill.js +1 -1
  162. package/src/integration_tests/execBundle.js +2 -2
  163. package/src/integration_tests/execBundle.js.flow +1 -1
  164. package/src/integration_tests/metro.config.js +8 -8
  165. package/src/lib/BatchProcessor.js +3 -3
  166. package/src/lib/BatchProcessor.js.flow +1 -1
  167. package/src/lib/JsonReporter.js +2 -2
  168. package/src/lib/JsonReporter.js.flow +1 -1
  169. package/src/lib/RamBundleParser.js +1 -1
  170. package/src/lib/RamBundleParser.js.flow +1 -1
  171. package/src/lib/TerminalReporter.js +14 -14
  172. package/src/lib/TerminalReporter.js.flow +9 -10
  173. package/src/lib/bundleToBytecode.js +6 -7
  174. package/src/lib/bundleToBytecode.js.flow +8 -7
  175. package/src/lib/bundleToString.js +3 -3
  176. package/src/lib/bundleToString.js.flow +5 -4
  177. package/src/lib/countLines.js +3 -7
  178. package/src/lib/countLines.js.flow +4 -7
  179. package/src/lib/createModuleIdFactory.js +2 -2
  180. package/src/lib/createModuleIdFactory.js.flow +1 -1
  181. package/src/lib/{attachWebsocketServer.js → createWebsocketServer.js} +18 -17
  182. package/src/lib/{attachWebsocketServer.js.flow → createWebsocketServer.js.flow} +12 -21
  183. package/src/lib/debounceAsyncQueue.js +2 -2
  184. package/src/lib/debounceAsyncQueue.js.flow +1 -1
  185. package/src/lib/formatBundlingError.js +21 -21
  186. package/src/lib/formatBundlingError.js.flow +6 -8
  187. package/src/lib/getAppendScripts.js +26 -27
  188. package/src/lib/getAppendScripts.js.flow +7 -8
  189. package/src/lib/getGraphId.js +3 -3
  190. package/src/lib/getGraphId.js.flow +3 -3
  191. package/src/lib/getMaxWorkers.js +2 -2
  192. package/src/lib/getMaxWorkers.js.flow +1 -1
  193. package/src/lib/getPreludeCode.js +2 -2
  194. package/src/lib/getPreludeCode.js.flow +1 -1
  195. package/src/lib/getPrependedScripts.js +15 -15
  196. package/src/lib/getPrependedScripts.js.flow +7 -8
  197. package/src/lib/logToConsole.js +1 -1
  198. package/src/lib/logToConsole.js.flow +3 -3
  199. package/src/lib/parseCustomTransformOptions.js +2 -2
  200. package/src/lib/parseCustomTransformOptions.js.flow +3 -3
  201. package/src/lib/parseOptionsFromUrl.js +7 -7
  202. package/src/lib/parseOptionsFromUrl.js.flow +29 -9
  203. package/src/lib/relativizeSourceMap.js +1 -1
  204. package/src/lib/relativizeSourceMap.js.flow +3 -3
  205. package/src/lib/reporting.js +5 -5
  206. package/src/lib/reporting.js.flow +16 -3
  207. package/src/lib/splitBundleOptions.js +5 -5
  208. package/src/lib/splitBundleOptions.js.flow +1 -1
  209. package/src/lib/transformHelpers.js +10 -10
  210. package/src/lib/transformHelpers.js.flow +5 -5
  211. package/src/node-haste/DependencyGraph/ModuleResolution.js +51 -30
  212. package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +46 -42
  213. package/src/node-haste/DependencyGraph/createHasteMap.js +99 -0
  214. package/src/node-haste/DependencyGraph/createHasteMap.js.flow +88 -0
  215. package/src/node-haste/DependencyGraph/{assets/empty-module.js → types.js} +2 -2
  216. package/src/node-haste/DependencyGraph/types.js.flow +88 -0
  217. package/src/node-haste/DependencyGraph.js +49 -117
  218. package/src/node-haste/DependencyGraph.js.flow +36 -111
  219. package/src/node-haste/Module.js +1 -1
  220. package/src/node-haste/Module.js.flow +3 -3
  221. package/src/node-haste/ModuleCache.js +54 -13
  222. package/src/node-haste/ModuleCache.js.flow +53 -12
  223. package/src/node-haste/Package.js +7 -9
  224. package/src/node-haste/Package.js.flow +1 -8
  225. package/src/node-haste/lib/AssetPaths.js +5 -5
  226. package/src/node-haste/lib/AssetPaths.js.flow +2 -4
  227. package/src/node-haste/lib/parsePlatformFilePath.js +4 -4
  228. package/src/node-haste/lib/parsePlatformFilePath.js.flow +1 -1
  229. package/src/shared/output/RamBundle/as-assets.js +16 -17
  230. package/src/shared/output/RamBundle/as-assets.js.flow +11 -15
  231. package/src/shared/output/RamBundle/as-indexed-file.js +14 -15
  232. package/src/shared/output/RamBundle/as-indexed-file.js.flow +8 -12
  233. package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js +7 -7
  234. package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js.flow +4 -4
  235. package/src/shared/output/RamBundle/magic-number.js +1 -1
  236. package/src/shared/output/RamBundle/magic-number.js.flow +1 -1
  237. package/src/shared/output/RamBundle/util.js +21 -19
  238. package/src/shared/output/RamBundle/util.js.flow +5 -8
  239. package/src/shared/output/RamBundle/write-sourcemap.js +1 -1
  240. package/src/shared/output/RamBundle/write-sourcemap.js.flow +1 -1
  241. package/src/shared/output/RamBundle.js +2 -2
  242. package/src/shared/output/RamBundle.js.flow +4 -5
  243. package/src/shared/output/bundle.js +6 -6
  244. package/src/shared/output/bundle.js.flow +4 -5
  245. package/src/shared/output/meta.js +4 -5
  246. package/src/shared/output/meta.js.flow +2 -4
  247. package/src/shared/output/unbundle.js +1 -1
  248. package/src/shared/output/unbundle.js.flow +1 -1
  249. package/src/shared/output/writeFile.js +1 -1
  250. package/src/shared/output/writeFile.js.flow +1 -1
  251. package/src/shared/types.flow.js +1 -1
  252. package/src/shared/types.flow.js.flow +2 -2
  253. package/src/node-haste/DependencyGraph/assets/empty-module.js.flow +0 -9
  254. package/src/node-haste/types.js +0 -10
  255. package/src/node-haste/types.js.flow +0 -23
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -10,28 +10,48 @@
10
10
 
11
11
  'use strict';
12
12
 
13
- const nullthrows = require('nullthrows');
14
- const parseCustomTransformOptions = require('./parseCustomTransformOptions');
13
+ import type {BundleOptions} from '../shared/types.flow';
14
+
15
15
  const parsePlatformFilePath = require('../node-haste/lib/parsePlatformFilePath');
16
+ const parseCustomTransformOptions = require('./parseCustomTransformOptions');
17
+ const nullthrows = require('nullthrows');
16
18
  const path = require('path');
17
19
  const url = require('url');
18
20
 
19
- import type {BundleOptions} from '../shared/types.flow';
20
-
21
- const getBoolean = (query, opt, defaultValue) =>
21
+ const getBoolean = (
22
+ query: {[string]: string},
23
+ opt:
24
+ | $TEMPORARY$string<'dev'>
25
+ | $TEMPORARY$string<'excludeSource'>
26
+ | $TEMPORARY$string<'inlineSourceMap'>
27
+ | $TEMPORARY$string<'minify'>
28
+ | $TEMPORARY$string<'modulesOnly'>
29
+ | $TEMPORARY$string<'runModule'>
30
+ | $TEMPORARY$string<'shallow'>,
31
+ defaultValue: boolean,
32
+ ) =>
22
33
  query[opt] == null
23
34
  ? defaultValue
24
35
  : query[opt] === 'true' || query[opt] === '1';
25
36
 
26
- const getNumber = (query, opt, defaultValue) => {
37
+ const getNumber = (
38
+ query: {[string]: string},
39
+ opt: $TEMPORARY$string<'runtimeBytecodeVersion'>,
40
+ defaultValue: null,
41
+ ) => {
27
42
  const number = parseInt(query[opt], 10);
28
43
  return Number.isNaN(number) ? defaultValue : number;
29
44
  };
30
45
 
31
- const getBundleType = bundleType =>
46
+ const getBundleType = (bundleType: string | $TEMPORARY$string<'map'>) =>
32
47
  bundleType === 'map' ? bundleType : 'bundle';
33
48
 
34
- const getTransformProfile = transformProfile =>
49
+ const getTransformProfile = (
50
+ transformProfile:
51
+ | string
52
+ | $TEMPORARY$string<'hermes-canary'>
53
+ | $TEMPORARY$string<'hermes-stable'>,
54
+ ) =>
35
55
  transformProfile === 'hermes-stable' || transformProfile === 'hermes-canary'
36
56
  ? transformProfile
37
57
  : 'default';
@@ -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.
@@ -10,10 +10,10 @@
10
10
 
11
11
  'use strict';
12
12
 
13
- const path = require('path');
14
-
15
13
  import type {MixedSourceMap} from 'metro-source-map';
16
14
 
15
+ const path = require('path');
16
+
17
17
  function relativizeSourceMapInline(
18
18
  sourceMap: MixedSourceMap,
19
19
  sourcesRoot: 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.
@@ -11,12 +11,12 @@
11
11
 
12
12
  const chalk = require("chalk");
13
13
 
14
+ const { Terminal } = require("metro-core");
15
+
14
16
  const stripAnsi = require("strip-ansi");
15
17
 
16
18
  const util = require("util");
17
19
 
18
- const { Terminal } = require("metro-core");
19
-
20
20
  /**
21
21
  * A standard way to log a warning to the terminal. This should not be called
22
22
  * from some arbitrary Metro logic, only from the reporters. Instead of
@@ -47,10 +47,10 @@ function logError(terminal, format, ...args) {
47
47
  */
48
48
 
49
49
  const nullReporter = {
50
- update() {}
50
+ update() {},
51
51
  };
52
52
  module.exports = {
53
53
  logWarning,
54
54
  logError,
55
- nullReporter
55
+ nullReporter,
56
56
  };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -11,11 +11,10 @@
11
11
  'use strict';
12
12
 
13
13
  const chalk = require('chalk');
14
+ const {Terminal} = require('metro-core');
14
15
  const stripAnsi = require('strip-ansi');
15
16
  const util = require('util');
16
17
 
17
- const {Terminal} = require('metro-core');
18
-
19
18
  export type GlobalCacheDisabledReason = 'too_many_errors' | 'too_many_misses';
20
19
 
21
20
  export type BundleDetails = {
@@ -45,6 +44,10 @@ export type ReportableEvent =
45
44
  error: Error,
46
45
  ...
47
46
  }
47
+ | {
48
+ type: 'initialize_done',
49
+ port: number,
50
+ }
48
51
  | {
49
52
  buildID: string,
50
53
  type: 'bundle_build_done',
@@ -119,6 +122,16 @@ export type ReportableEvent =
119
122
  data: Array<mixed>,
120
123
  mode: 'BRIDGE' | 'NOBRIDGE',
121
124
  ...
125
+ }
126
+ | {
127
+ type: 'transformer_load_started',
128
+ }
129
+ | {
130
+ type: 'transformer_load_done',
131
+ }
132
+ | {
133
+ type: 'transformer_load_failed',
134
+ error: Error,
122
135
  };
123
136
 
124
137
  /**
@@ -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,7 +23,7 @@ function splitBundleOptions(options) {
23
23
  platform: options.platform,
24
24
  runtimeBytecodeVersion: options.runtimeBytecodeVersion,
25
25
  type: "module",
26
- unstable_transformProfile: options.unstable_transformProfile
26
+ unstable_transformProfile: options.unstable_transformProfile,
27
27
  },
28
28
  serializerOptions: {
29
29
  excludeSource: options.excludeSource,
@@ -31,12 +31,12 @@ function splitBundleOptions(options) {
31
31
  modulesOnly: options.modulesOnly,
32
32
  runModule: options.runModule,
33
33
  sourceMapUrl: options.sourceMapUrl,
34
- sourceUrl: options.sourceUrl
34
+ sourceUrl: options.sourceUrl,
35
35
  },
36
36
  graphOptions: {
37
- shallow: options.shallow
37
+ shallow: options.shallow,
38
38
  },
39
- onProgress: options.onProgress
39
+ onProgress: options.onProgress,
40
40
  };
41
41
  }
42
42
 
@@ -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.
@@ -29,7 +29,7 @@ async function calcTransformerOptions(
29
29
  minify: options.minify,
30
30
  platform: options.platform,
31
31
  runtimeBytecodeVersion: options.runtimeBytecodeVersion,
32
- unstable_transformProfile: options.unstable_transformProfile
32
+ unstable_transformProfile: options.unstable_transformProfile,
33
33
  }; // When we're processing scripts, we don't need to calculate any
34
34
  // inlineRequires information, since scripts by definition don't have
35
35
  // requires().
@@ -38,18 +38,18 @@ async function calcTransformerOptions(
38
38
  return { ...baseOptions, type: "script" };
39
39
  }
40
40
 
41
- const getDependencies = async path => {
41
+ const getDependencies = async (path) => {
42
42
  const dependencies = await deltaBundler.getDependencies([path], {
43
43
  resolve: await getResolveDependencyFn(bundler, options.platform),
44
44
  transform: await getTransformFn([path], bundler, deltaBundler, config, {
45
45
  ...options,
46
- minify: false
46
+ minify: false,
47
47
  }),
48
48
  transformOptions: options,
49
49
  onProgress: null,
50
50
  experimentalImportBundleSupport:
51
51
  config.transformer.experimentalImportBundleSupport,
52
- shallow: false
52
+ shallow: false,
53
53
  });
54
54
  return Array.from(dependencies.keys());
55
55
  };
@@ -59,7 +59,7 @@ async function calcTransformerOptions(
59
59
  {
60
60
  dev: options.dev,
61
61
  hot: options.hot,
62
- platform: options.platform
62
+ platform: options.platform,
63
63
  },
64
64
  getDependencies
65
65
  );
@@ -71,7 +71,7 @@ async function calcTransformerOptions(
71
71
  transform.unstable_disableES6Transforms || false,
72
72
  nonInlinedRequires:
73
73
  transform.nonInlinedRequires || baseIgnoredInlineRequires,
74
- type: "module"
74
+ type: "module",
75
75
  };
76
76
  }
77
77
 
@@ -97,14 +97,14 @@ async function getTransformFn(
97
97
  config,
98
98
  options
99
99
  );
100
- return async path => {
100
+ return async (path) => {
101
101
  return await bundler.transformFile(path, {
102
102
  ...transformOptions,
103
103
  type: getType(transformOptions.type, path, config.resolver.assetExts),
104
104
  inlineRequires: removeInlineRequiresBlockListFromOptions(
105
105
  path,
106
106
  inlineRequires
107
- )
107
+ ),
108
108
  });
109
109
  };
110
110
  }
@@ -131,5 +131,5 @@ async function getResolveDependencyFn(bundler, platform) {
131
131
 
132
132
  module.exports = {
133
133
  getTransformFn,
134
- getResolveDependencyFn
134
+ getResolveDependencyFn,
135
135
  };
@@ -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 path = require('path');
14
-
15
13
  import type Bundler from '../Bundler';
16
- import type {TransformOptions} from '../DeltaBundler/Worker';
17
- import type {TransformInputOptions} from '../DeltaBundler/types.flow';
18
14
  import type DeltaBundler, {TransformFn} from '../DeltaBundler';
15
+ import type {TransformInputOptions} from '../DeltaBundler/types.flow';
16
+ import type {TransformOptions} from '../DeltaBundler/Worker';
19
17
  import type {ConfigT} from 'metro-config/src/configTypes.flow';
20
18
  import type {Type} from 'metro-transform-worker';
21
19
 
20
+ const path = require('path');
21
+
22
22
  type InlineRequiresRaw = {+blockList: {[string]: true, ...}, ...} | boolean;
23
23
 
24
24
  type TransformOptionsWithRawInlines = {|
@@ -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,53 @@
9
9
  */
10
10
  "use strict";
11
11
 
12
- const Resolver = require("metro-resolver");
12
+ const { codeFrameColumns } = require("@babel/code-frame");
13
13
 
14
14
  const fs = require("fs");
15
15
 
16
16
  const invariant = require("invariant");
17
17
 
18
+ const Resolver = require("metro-resolver");
19
+
18
20
  const path = require("path");
19
21
 
20
22
  const util = require("util");
21
23
 
22
- const { codeFrameColumns } = require("@babel/code-frame");
23
-
24
24
  class ModuleResolver {
25
- static EMPTY_MODULE = require.resolve("./assets/empty-module.js");
26
-
25
+ // A module representing the project root, used as the origin when resolving `emptyModulePath`.
26
+ // An empty module, the result of resolving `emptyModulePath` from the project root.
27
27
  constructor(options) {
28
28
  this._options = options;
29
+ const { projectRoot, moduleCache } = this._options;
30
+ this._projectRootFakeModule = {
31
+ path: path.join(projectRoot, "_"),
32
+ getPackage: () =>
33
+ moduleCache.getPackageOf(this._projectRootFakeModule.path),
34
+
35
+ isHaste() {
36
+ throw new Error("not implemented");
37
+ },
38
+
39
+ getName() {
40
+ throw new Error("not implemented");
41
+ },
42
+ };
43
+ }
44
+
45
+ _getEmptyModule() {
46
+ let emptyModule = this._cachedEmptyModule;
47
+
48
+ if (!emptyModule) {
49
+ emptyModule = this.resolveDependency(
50
+ this._projectRootFakeModule,
51
+ this._options.emptyModulePath,
52
+ false,
53
+ null
54
+ );
55
+ this._cachedEmptyModule = emptyModule;
56
+ }
57
+
58
+ return emptyModule;
29
59
  }
30
60
 
31
61
  _redirectRequire(fromModule, modulePath) {
@@ -51,7 +81,6 @@ class ModuleResolver {
51
81
  ); // Since the redirected path is still relative to the package root,
52
82
  // we have to transform it back to be module-relative (as it
53
83
  // originally was)
54
- // $FlowFixMe[incompatible-type]
55
84
 
56
85
  if (redirectedPath !== false) {
57
86
  redirectedPath =
@@ -66,7 +95,7 @@ class ModuleResolver {
66
95
  }
67
96
  } else {
68
97
  const pck = path.isAbsolute(modulePath)
69
- ? moduleCache.getModule(modulePath).getPackage()
98
+ ? moduleCache.getPackageOf(modulePath)
70
99
  : fromModule.getPackage();
71
100
 
72
101
  if (pck) {
@@ -87,15 +116,15 @@ class ModuleResolver {
87
116
  {
88
117
  ...this._options,
89
118
  originModulePath: fromModule.path,
90
- redirectModulePath: modulePath =>
119
+ redirectModulePath: (modulePath) =>
91
120
  this._redirectRequire(fromModule, modulePath),
92
121
  allowHaste,
93
122
  platform,
94
- resolveHasteModule: name =>
123
+ resolveHasteModule: (name) =>
95
124
  this._options.moduleMap.getModule(name, platform, true),
96
- resolveHastePackage: name =>
125
+ resolveHastePackage: (name) =>
97
126
  this._options.moduleMap.getPackage(name, platform, true),
98
- getPackageMainPath: this._getPackageMainPath
127
+ getPackageMainPath: this._getPackageMainPath,
99
128
  },
100
129
  moduleName,
101
130
  platform
@@ -114,7 +143,7 @@ class ModuleResolver {
114
143
  )}`,
115
144
  ` * ${Resolver.formatFileCandidates(
116
145
  this._removeRoot(candidates.dir)
117
- )}`
146
+ )}`,
118
147
  ].join("\n")
119
148
  );
120
149
  }
@@ -122,8 +151,8 @@ class ModuleResolver {
122
151
  if (error instanceof Resolver.FailedToResolveNameError) {
123
152
  const { dirPaths, extraPaths } = error;
124
153
  const displayDirPaths = dirPaths
125
- .filter(dirPath => this._options.dirExists(dirPath))
126
- .map(dirPath => path.relative(this._options.projectRoot, dirPath))
154
+ .filter((dirPath) => this._options.dirExists(dirPath))
155
+ .map((dirPath) => path.relative(this._options.projectRoot, dirPath))
127
156
  .concat(extraPaths);
128
157
  const hint = displayDirPaths.length ? " or in these directories:" : "";
129
158
  throw new UnableToResolveError(
@@ -131,12 +160,7 @@ class ModuleResolver {
131
160
  moduleName,
132
161
  [
133
162
  `${moduleName} could not be found within the project${hint || "."}`,
134
- ...displayDirPaths.map(dirPath => ` ${dirPath}`),
135
- "\nIf you are sure the module exists, try these steps:",
136
- " 1. Clear watchman watches: watchman watch-del-all",
137
- " 2. Delete node_modules and run yarn install",
138
- " 3. Reset Metro's cache: yarn start --reset-cache",
139
- " 4. Remove the cache: rm -rf /tmp/metro-*"
163
+ ...displayDirPaths.map((dirPath) => ` ${dirPath}`),
140
164
  ].join("\n")
141
165
  );
142
166
  }
@@ -145,7 +169,7 @@ class ModuleResolver {
145
169
  }
146
170
  }
147
171
 
148
- _getPackageMainPath = packageJsonPath => {
172
+ _getPackageMainPath = (packageJsonPath) => {
149
173
  const package_ = this._options.moduleCache.getPackage(packageJsonPath);
150
174
 
151
175
  return package_.getMain(this._options.mainFields);
@@ -168,10 +192,7 @@ class ModuleResolver {
168
192
  return this._options.moduleCache.getModule(arbitrary);
169
193
 
170
194
  case "empty":
171
- const { moduleCache } = this._options;
172
- const module_ = moduleCache.getModule(ModuleResolver.EMPTY_MODULE);
173
- invariant(module_ != null, "empty module is not available");
174
- return module_;
195
+ return this._getEmptyModule();
175
196
 
176
197
  default:
177
198
  resolution.type;
@@ -266,11 +287,11 @@ class UnableToResolveError extends Error {
266
287
  {
267
288
  start: {
268
289
  column: column + 1,
269
- line: lineNumber + 1
270
- }
290
+ line: lineNumber + 1,
291
+ },
271
292
  },
272
293
  {
273
- forceColor: process.env.NODE_ENV !== "test"
294
+ forceColor: process.env.NODE_ENV !== "test",
274
295
  }
275
296
  );
276
297
  }
@@ -278,5 +299,5 @@ class UnableToResolveError extends Error {
278
299
 
279
300
  module.exports = {
280
301
  ModuleResolver,
281
- UnableToResolveError
302
+ UnableToResolveError,
282
303
  };
@@ -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,7 @@
10
10
 
11
11
  'use strict';
12
12
 
13
- const Resolver = require('metro-resolver');
14
-
15
- const fs = require('fs');
16
- const invariant = require('invariant');
17
- const path = require('path');
18
- const util = require('util');
19
-
20
- const {codeFrameColumns} = require('@babel/code-frame');
21
-
13
+ import type {ModuleMap} from './types';
22
14
  import type {
23
15
  CustomResolver,
24
16
  DoesFileExist,
@@ -28,6 +20,13 @@ import type {
28
20
  ResolveAsset,
29
21
  } from 'metro-resolver';
30
22
 
23
+ const {codeFrameColumns} = require('@babel/code-frame');
24
+ const fs = require('fs');
25
+ const invariant = require('invariant');
26
+ const Resolver = require('metro-resolver');
27
+ const path = require('path');
28
+ const util = require('util');
29
+
31
30
  export type DirExistsFn = (filePath: string) => boolean;
32
31
 
33
32
  export type Packageish = interface {
@@ -44,23 +43,6 @@ export type Moduleish = interface {
44
43
  getPackage(): ?Packageish,
45
44
  };
46
45
 
47
- /**
48
- * `jest-haste-map`'s interface for ModuleMap.
49
- */
50
- export type ModuleMap = {
51
- getModule(
52
- name: string,
53
- platform: string | null,
54
- supportsNativePlatform: ?boolean,
55
- ): ?string,
56
- getPackage(
57
- name: string,
58
- platform: string | null,
59
- supportsNativePlatform: ?boolean,
60
- ): ?string,
61
- ...
62
- };
63
-
64
46
  export type ModuleishCache<TModule, TPackage> = interface {
65
47
  getPackage(
66
48
  name: string,
@@ -68,11 +50,14 @@ export type ModuleishCache<TModule, TPackage> = interface {
68
50
  supportsNativePlatform?: boolean,
69
51
  ): TPackage,
70
52
  getModule(path: string): TModule,
53
+ getPackageOf(modulePath: string): ?TPackage,
71
54
  };
72
55
 
73
56
  type Options<TModule, TPackage> = {|
74
57
  +dirExists: DirExistsFn,
58
+ +disableHierarchicalLookup: boolean,
75
59
  +doesFileExist: DoesFileExist,
60
+ +emptyModulePath: string,
76
61
  +extraNodeModules: ?Object,
77
62
  +isAssetFile: IsAssetFile,
78
63
  +mainFields: $ReadOnlyArray<string>,
@@ -88,14 +73,42 @@ type Options<TModule, TPackage> = {|
88
73
 
89
74
  class ModuleResolver<TModule: Moduleish, TPackage: Packageish> {
90
75
  _options: Options<TModule, TPackage>;
91
-
92
- static EMPTY_MODULE: string = require.resolve('./assets/empty-module.js');
76
+ // A module representing the project root, used as the origin when resolving `emptyModulePath`.
77
+ _projectRootFakeModule: Moduleish;
78
+ // An empty module, the result of resolving `emptyModulePath` from the project root.
79
+ _cachedEmptyModule: ?TModule;
93
80
 
94
81
  constructor(options: Options<TModule, TPackage>) {
95
82
  this._options = options;
83
+ const {projectRoot, moduleCache} = this._options;
84
+ this._projectRootFakeModule = {
85
+ path: path.join(projectRoot, '_'),
86
+ getPackage: () =>
87
+ moduleCache.getPackageOf(this._projectRootFakeModule.path),
88
+ isHaste() {
89
+ throw new Error('not implemented');
90
+ },
91
+ getName() {
92
+ throw new Error('not implemented');
93
+ },
94
+ };
95
+ }
96
+
97
+ _getEmptyModule() {
98
+ let emptyModule = this._cachedEmptyModule;
99
+ if (!emptyModule) {
100
+ emptyModule = this.resolveDependency(
101
+ this._projectRootFakeModule,
102
+ this._options.emptyModulePath,
103
+ false,
104
+ null,
105
+ );
106
+ this._cachedEmptyModule = emptyModule;
107
+ }
108
+ return emptyModule;
96
109
  }
97
110
 
98
- _redirectRequire(fromModule: TModule, modulePath: string): string | false {
111
+ _redirectRequire(fromModule: Moduleish, modulePath: string): string | false {
99
112
  const moduleCache = this._options.moduleCache;
100
113
  try {
101
114
  if (modulePath.startsWith('.')) {
@@ -120,7 +133,6 @@ class ModuleResolver<TModule: Moduleish, TPackage: Packageish> {
120
133
  // Since the redirected path is still relative to the package root,
121
134
  // we have to transform it back to be module-relative (as it
122
135
  // originally was)
123
- // $FlowFixMe[incompatible-type]
124
136
  if (redirectedPath !== false) {
125
137
  redirectedPath =
126
138
  './' +
@@ -134,7 +146,7 @@ class ModuleResolver<TModule: Moduleish, TPackage: Packageish> {
134
146
  }
135
147
  } else {
136
148
  const pck = path.isAbsolute(modulePath)
137
- ? moduleCache.getModule(modulePath).getPackage()
149
+ ? moduleCache.getPackageOf(modulePath)
138
150
  : fromModule.getPackage();
139
151
 
140
152
  if (pck) {
@@ -150,7 +162,7 @@ class ModuleResolver<TModule: Moduleish, TPackage: Packageish> {
150
162
  }
151
163
 
152
164
  resolveDependency(
153
- fromModule: TModule,
165
+ fromModule: Moduleish,
154
166
  moduleName: string,
155
167
  allowHaste: boolean,
156
168
  platform: string | null,
@@ -214,11 +226,6 @@ class ModuleResolver<TModule: Moduleish, TPackage: Packageish> {
214
226
  [
215
227
  `${moduleName} could not be found within the project${hint || '.'}`,
216
228
  ...displayDirPaths.map((dirPath: string) => ` ${dirPath}`),
217
- '\nIf you are sure the module exists, try these steps:',
218
- ' 1. Clear watchman watches: watchman watch-del-all',
219
- ' 2. Delete node_modules and run yarn install',
220
- " 3. Reset Metro's cache: yarn start --reset-cache",
221
- ' 4. Remove the cache: rm -rf /tmp/metro-*',
222
229
  ].join('\n'),
223
230
  );
224
231
  }
@@ -246,10 +253,7 @@ class ModuleResolver<TModule: Moduleish, TPackage: Packageish> {
246
253
  invariant(arbitrary != null, 'invalid asset resolution');
247
254
  return this._options.moduleCache.getModule(arbitrary);
248
255
  case 'empty':
249
- const {moduleCache} = this._options;
250
- const module_ = moduleCache.getModule(ModuleResolver.EMPTY_MODULE);
251
- invariant(module_ != null, 'empty module is not available');
252
- return module_;
256
+ return this._getEmptyModule();
253
257
  default:
254
258
  (resolution.type: empty);
255
259
  throw new Error('invalid type');