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
@@ -4,12 +4,18 @@
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
- * @format
8
7
  * @flow
8
+ * @format
9
9
  */
10
10
 
11
+ import type {ReadonlySourceLocation} from '../../shared/types';
11
12
  import type {NodePath} from '@babel/traverse';
12
- import type {CallExpression, Identifier, StringLiteral} from '@babel/types';
13
+ import type {
14
+ CallExpression,
15
+ File as BabelNodeFile,
16
+ Identifier,
17
+ StringLiteral,
18
+ } from '@babel/types';
13
19
  import type {
14
20
  AllowOptionalDependencies,
15
21
  AsyncDependencyType,
@@ -24,12 +30,12 @@ import crypto from 'crypto';
24
30
  import invariant from 'invariant';
25
31
  import nullthrows from 'nullthrows';
26
32
 
27
- type ImportDependencyOptions = $ReadOnly<{
33
+ type ImportDependencyOptions = Readonly<{
28
34
  asyncType: AsyncDependencyType,
29
35
  isESMImport: boolean,
30
36
  }>;
31
37
 
32
- export type Dependency = $ReadOnly<{
38
+ export type Dependency = Readonly<{
33
39
  data: DependencyData,
34
40
  name: string,
35
41
  }>;
@@ -37,18 +43,18 @@ export type Dependency = $ReadOnly<{
37
43
  // TODO: Convert to a Flow enum
38
44
  export type ContextMode = 'sync' | 'eager' | 'lazy' | 'lazy-once';
39
45
 
40
- type ContextFilter = $ReadOnly<{pattern: string, flags: string}>;
46
+ type ContextFilter = Readonly<{pattern: string, flags: string}>;
41
47
 
42
- export type RequireContextParams = $ReadOnly<{
48
+ export type RequireContextParams = Readonly<{
43
49
  /* Should search for files recursively. Optional, default `true` when `require.context` is used */
44
50
  recursive: boolean,
45
51
  /* Filename filter pattern for use in `require.context`. Optional, default `.*` (any file) when `require.context` is used */
46
- filter: $ReadOnly<ContextFilter>,
52
+ filter: Readonly<ContextFilter>,
47
53
  /** Mode for resolving dynamic dependencies. Defaults to `sync` */
48
54
  mode: ContextMode,
49
55
  }>;
50
56
 
51
- type DependencyData = $ReadOnly<{
57
+ type DependencyData = Readonly<{
52
58
  // A locally unique key for this dependency within the current module.
53
59
  key: string,
54
60
  // If null, then the dependency is synchronous.
@@ -60,19 +66,19 @@ type DependencyData = $ReadOnly<{
60
66
  // and subpath imports.
61
67
  isESMImport: boolean,
62
68
  isOptional?: boolean,
63
- locs: $ReadOnlyArray<BabelSourceLocation>,
69
+ locs: ReadonlyArray<ReadonlySourceLocation>,
64
70
  /** Context for requiring a collection of modules. */
65
71
  contextParams?: RequireContextParams,
66
72
  }>;
67
73
 
68
74
  export type MutableInternalDependency = {
69
75
  ...DependencyData,
70
- locs: Array<BabelSourceLocation>,
76
+ locs: Array<ReadonlySourceLocation>,
71
77
  index: number,
72
78
  name: string,
73
79
  };
74
80
 
75
- export type InternalDependency = $ReadOnly<MutableInternalDependency>;
81
+ export type InternalDependency = Readonly<MutableInternalDependency>;
76
82
 
77
83
  export type State = {
78
84
  asyncRequireModulePathStringLiteral: ?StringLiteral,
@@ -85,26 +91,26 @@ export type State = {
85
91
  allowOptionalDependencies: AllowOptionalDependencies,
86
92
  /** Enable `require.context` statements which can be used to import multiple files in a directory. */
87
93
  unstable_allowRequireContext: boolean,
88
- unstable_isESMImportAtSource: ?(BabelSourceLocation) => boolean,
94
+ unstable_isESMImportAtSource: ?(ReadonlySourceLocation) => boolean,
89
95
  };
90
96
 
91
- export type Options = $ReadOnly<{
97
+ export type Options = Readonly<{
92
98
  asyncRequireModulePath: string,
93
99
  dependencyMapName: ?string,
94
100
  dynamicRequires: DynamicRequiresBehavior,
95
- inlineableCalls: $ReadOnlyArray<string>,
101
+ inlineableCalls: ReadonlyArray<string>,
96
102
  keepRequireNames: boolean,
97
103
  allowOptionalDependencies: AllowOptionalDependencies,
98
104
  dependencyTransformer?: DependencyTransformer,
99
105
  /** Enable `require.context` statements which can be used to import multiple files in a directory. */
100
106
  unstable_allowRequireContext: boolean,
101
- unstable_isESMImportAtSource?: ?(BabelSourceLocation) => boolean,
107
+ unstable_isESMImportAtSource?: ?(ReadonlySourceLocation) => boolean,
102
108
  }>;
103
109
 
104
- export type CollectedDependencies = $ReadOnly<{
110
+ export type CollectedDependencies = Readonly<{
105
111
  ast: BabelNodeFile,
106
112
  dependencyMapName: string,
107
- dependencies: $ReadOnlyArray<Dependency>,
113
+ dependencies: ReadonlyArray<Dependency>,
108
114
  }>;
109
115
 
110
116
  export interface DependencyTransformer {
@@ -562,7 +568,7 @@ function processRequireCall(
562
568
  transformer.transformSyncRequire(path, dep, state);
563
569
  }
564
570
 
565
- function getNearestLocFromPath(path: NodePath<>): ?BabelSourceLocation {
571
+ function getNearestLocFromPath(path: NodePath<>): ?ReadonlySourceLocation {
566
572
  let current: ?(NodePath<> | NodePath<BabelNode>) = path;
567
573
  while (
568
574
  current &&
@@ -582,7 +588,7 @@ function getNearestLocFromPath(path: NodePath<>): ?BabelSourceLocation {
582
588
  );
583
589
  }
584
590
 
585
- export type ImportQualifier = $ReadOnly<{
591
+ export type ImportQualifier = Readonly<{
586
592
  name: string,
587
593
  asyncType: AsyncDependencyType | null,
588
594
  isESMImport: boolean,
@@ -732,11 +738,11 @@ const DefaultDependencyTransformer: DependencyTransformer = {
732
738
  state: State,
733
739
  ): void {
734
740
  const moduleIDExpression = createModuleIDExpression(dependency, state);
735
- path.node.arguments = ([moduleIDExpression]: Array<
741
+ path.node.arguments = [moduleIDExpression] as Array<
736
742
  | BabelNodeExpression
737
743
  | BabelNodeSpreadElement
738
744
  | BabelNodeArgumentPlaceholder,
739
- >);
745
+ >;
740
746
  // Always add the debug name argument last
741
747
  if (state.keepRequireNames) {
742
748
  path.node.arguments.push(types.stringLiteral(dependency.name));
@@ -0,0 +1,19 @@
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
+ */
9
+
10
+ import type {Node} from '@babel/types';
11
+ /**
12
+ * Select unused names for "metroImportDefault" and "metroImportAll", by
13
+ * calling "generateUid".
14
+ */
15
+ declare function generateImportNames(ast: Node): {
16
+ importAll: string;
17
+ importDefault: string;
18
+ };
19
+ export default generateImportNames;
@@ -4,10 +4,12 @@
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
- * @format
8
7
  * @flow strict-local
8
+ * @format
9
9
  */
10
10
 
11
+ import type {Node} from '@babel/types';
12
+
11
13
  import traverse from '@babel/traverse';
12
14
  import nullthrows from 'nullthrows';
13
15
 
@@ -15,7 +17,7 @@ import nullthrows from 'nullthrows';
15
17
  * Select unused names for "metroImportDefault" and "metroImportAll", by
16
18
  * calling "generateUid".
17
19
  */
18
- export default function generateImportNames(ast: BabelNode): {
20
+ export default function generateImportNames(ast: Node): {
19
21
  importAll: string,
20
22
  importDefault: string,
21
23
  } {
@@ -0,0 +1,26 @@
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 {ReadonlySourceLocation} from '../../shared/types';
12
+ import type {PluginObj} from '@babel/core';
13
+ import type * as $$IMPORT_TYPEOF_1$$ from '@babel/types';
14
+ import type {MetroBabelFileMetadata} from 'metro-babel-transformer';
15
+
16
+ type Types = typeof $$IMPORT_TYPEOF_1$$;
17
+ type ImportDeclarationLocs = Set<string>;
18
+ type State = {
19
+ importDeclarationLocs: ImportDeclarationLocs;
20
+ file: {metadata?: MetroBabelFileMetadata};
21
+ };
22
+ declare function importLocationsPlugin($$PARAM_0$$: {
23
+ types: Types;
24
+ }): PluginObj<State>;
25
+ declare function locToKey(loc: ReadonlySourceLocation): string;
26
+ export {importLocationsPlugin, locToKey};
@@ -9,7 +9,8 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- import type {File, PluginObj} from '@babel/core';
12
+ import type {ReadonlySourceLocation} from '../../shared/types';
13
+ import type {PluginObj} from '@babel/core';
13
14
  import typeof * as Types from '@babel/types';
14
15
  import type {MetroBabelFileMetadata} from 'metro-babel-transformer';
15
16
 
@@ -17,7 +18,10 @@ type ImportDeclarationLocs = Set<string>;
17
18
 
18
19
  type State = {
19
20
  importDeclarationLocs: ImportDeclarationLocs,
20
- file: File,
21
+ file: {
22
+ metadata?: MetroBabelFileMetadata,
23
+ ...
24
+ },
21
25
  ...
22
26
  };
23
27
 
@@ -78,7 +82,7 @@ function importLocationsPlugin({
78
82
  // Very simple serialisation of a source location. This should remain opaque to
79
83
  // the caller.
80
84
  const MISSING_LOC = {line: -1, column: -1};
81
- function locToKey(loc: BabelSourceLocation): string {
85
+ function locToKey(loc: ReadonlySourceLocation): string {
82
86
  const {start = MISSING_LOC, end = MISSING_LOC} = loc;
83
87
  return `${start.line},${start.column}:${end.line},${end.column}`;
84
88
  }
@@ -10,12 +10,9 @@
10
10
 
11
11
  import type {IncomingMessage, ServerResponse} from 'http';
12
12
 
13
- export type Data = string | Buffer | Uint8Array;
14
- export interface Headers {
15
- [name: string]: string | number;
16
- }
17
-
18
- export default class MultipartResponse {
13
+ type Data = string | Buffer | Uint8Array;
14
+ type Headers = {[$$Key$$: string]: string | number};
15
+ declare class MultipartResponse {
19
16
  static wrapIfSupported(
20
17
  req: IncomingMessage,
21
18
  res: ServerResponse,
@@ -28,4 +25,6 @@ export default class MultipartResponse {
28
25
  writeHead(status: number, headers?: Headers): void;
29
26
  setHeader(name: string, value: string | number): void;
30
27
  end(data?: Data): void;
28
+ once(name: string, fn: () => unknown): this;
31
29
  }
30
+ export default MultipartResponse;
@@ -94,7 +94,7 @@ export default class MultipartResponse {
94
94
  this.res.end();
95
95
  }
96
96
 
97
- once(name: string, fn: () => mixed): this {
97
+ once(name: string, fn: () => unknown): this {
98
98
  this.res.once(name, fn);
99
99
  return this;
100
100
  }
@@ -31,7 +31,7 @@ export type IntermediateStackFrame = {
31
31
  collapse?: boolean,
32
32
  ...
33
33
  };
34
- export type StackFrameOutput = $ReadOnly<IntermediateStackFrame>;
34
+ export type StackFrameOutput = Readonly<IntermediateStackFrame>;
35
35
  type ExplodedSourceMapModule = ExplodedSourceMap[number];
36
36
  type Position = {+line1Based: number, column0Based: number};
37
37
 
@@ -57,11 +57,11 @@ function createFunctionNameGetter(
57
57
  }
58
58
 
59
59
  export default async function symbolicate(
60
- stack: $ReadOnlyArray<StackFrameInput>,
60
+ stack: ReadonlyArray<StackFrameInput>,
61
61
  maps: Iterable<[string, ExplodedSourceMap]>,
62
62
  config: ConfigT,
63
- extraData: mixed,
64
- ): Promise<$ReadOnlyArray<StackFrameOutput>> {
63
+ extraData: unknown,
64
+ ): Promise<ReadonlyArray<StackFrameOutput>> {
65
65
  const mapsByUrl = new Map<?string, ExplodedSourceMap>();
66
66
  for (const [url, map] of maps) {
67
67
  mapsByUrl.set(url, map);
package/src/Server.d.ts CHANGED
@@ -8,111 +8,264 @@
8
8
  * @oncall react_native
9
9
  */
10
10
 
11
- import type {AssetData} from './Asset';
11
+ import type {AssetData} from './Assets';
12
+ import type {ExplodedSourceMap} from './DeltaBundler/Serializers/getExplodedSourceMap';
12
13
  import type {RamBundleInfo} from './DeltaBundler/Serializers/getRamBundleInfo';
14
+ import type {
15
+ Module,
16
+ ReadOnlyDependencies,
17
+ ReadOnlyGraph,
18
+ TransformInputOptions,
19
+ } from './DeltaBundler/types';
20
+ import type {RevisionId} from './IncrementalBundler';
13
21
  import type {GraphId} from './lib/getGraphId';
14
- import type MultipartResponse from './Server/MultipartResponse';
22
+ import type {Reporter} from './lib/reporting';
15
23
  import type {
16
24
  BuildOptions,
17
25
  BundleOptions,
18
26
  GraphOptions,
27
+ ResolverInputOptions,
19
28
  SplitBundleOptions,
20
29
  } from './shared/types';
21
- import type {IncomingMessage, ServerResponse} from 'http';
22
- import type {
23
- CustomTransformOptions,
24
- TransformProfile,
25
- } from 'metro-babel-transformer';
30
+ import type {IncomingMessage} from 'connect';
31
+ import type {ServerResponse} from 'http';
26
32
  import type {ConfigT, RootPerfLogger} from 'metro-config';
27
- import type {CustomResolverOptions} from 'metro-resolver';
33
+ import type {
34
+ ActionLogEntryData,
35
+ ActionStartLogEntry,
36
+ } from 'metro-core/private/Logger';
37
+ import type {CustomResolverOptions} from 'metro-resolver/private/types';
38
+ import type {CustomTransformOptions} from 'metro-transform-worker';
28
39
 
29
- import IncrementalBundler, {RevisionId} from './IncrementalBundler';
40
+ import IncrementalBundler from './IncrementalBundler';
41
+ import MultipartResponse from './Server/MultipartResponse';
42
+ import {SourcePathsMode} from './shared/types';
43
+ import {Logger} from 'metro-core';
30
44
 
31
- export interface SegmentLoadData {
32
- [index: number]: [number[], number | null];
33
- }
34
-
35
- export interface BundleMetadata {
45
+ export type SegmentLoadData = {
46
+ [$$Key$$: number]: [Array<number>, null | undefined | number];
47
+ };
48
+ export type BundleMetadata = {
36
49
  hash: string;
37
- otaBuildNumber: string | null;
38
- mobileConfigs: string[];
39
- segmentHashes: string[];
50
+ otaBuildNumber: null | undefined | string;
51
+ mobileConfigs: Array<string>;
52
+ segmentHashes: Array<string>;
40
53
  segmentLoadData: SegmentLoadData;
41
- }
42
-
43
- export interface ProcessStartContext extends SplitBundleOptions {
54
+ };
55
+ type ProcessStartContext = Omit<
56
+ SplitBundleOptions,
57
+ keyof {
58
+ readonly buildNumber: number;
59
+ readonly bundleOptions: BundleOptions;
60
+ readonly graphId: GraphId;
61
+ readonly graphOptions: GraphOptions;
62
+ readonly mres: MultipartResponse | ServerResponse;
63
+ readonly req: IncomingMessage;
64
+ readonly revisionId?: null | undefined | RevisionId;
65
+ readonly bundlePerfLogger: RootPerfLogger;
66
+ readonly requestStartTimestamp: number;
67
+ }
68
+ > & {
44
69
  readonly buildNumber: number;
45
70
  readonly bundleOptions: BundleOptions;
46
71
  readonly graphId: GraphId;
47
72
  readonly graphOptions: GraphOptions;
48
73
  readonly mres: MultipartResponse | ServerResponse;
49
74
  readonly req: IncomingMessage;
50
- readonly revisionId?: RevisionId | null;
75
+ readonly revisionId?: null | undefined | RevisionId;
51
76
  readonly bundlePerfLogger: RootPerfLogger;
52
- }
53
-
54
- export interface ProcessDeleteContext {
77
+ readonly requestStartTimestamp: number;
78
+ };
79
+ type ProcessDeleteContext = {
55
80
  readonly graphId: GraphId;
56
81
  readonly req: IncomingMessage;
57
82
  readonly res: ServerResponse;
58
- }
59
-
60
- export interface ProcessEndContext<T> extends ProcessStartContext {
61
- readonly result: T;
62
- }
63
-
83
+ };
84
+ type ProcessEndContext<T> = Omit<
85
+ ProcessStartContext,
86
+ keyof {readonly result: T}
87
+ > & {readonly result: T};
64
88
  export type ServerOptions = Readonly<{
65
89
  hasReducedPerformance?: boolean;
66
90
  onBundleBuilt?: (bundlePath: string) => void;
67
91
  watch?: boolean;
68
92
  }>;
69
-
70
- export interface DefaultGraphOptions {
71
- customResolverOptions: CustomResolverOptions;
72
- customTransformOptions: CustomTransformOptions;
73
- dev: boolean;
74
- minify: boolean;
75
- runtimeBytecodeVersion?: number;
76
- unstable_transformProfile: TransformProfile;
77
- }
78
-
79
- export interface DefaultBundleOptions extends DefaultGraphOptions {
80
- excludeSource: false;
81
- inlineSourceMap: false;
82
- modulesOnly: false;
83
- onProgress: null;
84
- runModule: true;
85
- shallow: false;
86
- sourceMapUrl: null;
87
- sourceUrl: null;
88
- }
89
-
90
- export default class Server {
91
- static DEFAULT_GRAPH_OPTIONS: DefaultGraphOptions;
92
- static DEFAULT_BUNDLE_OPTIONS: BundleOptions;
93
+ type FetchTiming = {
94
+ graphId: GraphId;
95
+ startTime: number;
96
+ endTime: number | null;
97
+ isPrefetch: boolean;
98
+ };
99
+ declare class Server {
100
+ _bundler: IncrementalBundler;
101
+ _config: ConfigT;
102
+ _createModuleId: (path: string) => number;
103
+ _isEnded: boolean;
104
+ _logger: typeof Logger;
105
+ _nextBundleBuildNumber: number;
106
+ _platforms: Set<string>;
107
+ _reporter: Reporter;
108
+ _serverOptions: ServerOptions | void;
109
+ _allowedSuffixesForSourceRequests: ReadonlyArray<string>;
110
+ _sourceRequestRoutingMap: ReadonlyArray<
111
+ [pathnamePrefix: string, normalizedRootDir: string]
112
+ >;
113
+ _fetchTimings: Array<FetchTiming>;
114
+ _activeFetchCount: number;
93
115
  constructor(config: ConfigT, options?: ServerOptions);
94
116
  end(): void;
95
117
  getBundler(): IncrementalBundler;
96
118
  getCreateModuleId(): (path: string) => number;
119
+ _serializeGraph(
120
+ $$PARAM_0$$: Readonly<{
121
+ splitOptions: SplitBundleOptions;
122
+ prepend: ReadonlyArray<Module>;
123
+ graph: ReadOnlyGraph;
124
+ }>,
125
+ ): Promise<{code: string; map: string}>;
97
126
  build(
98
127
  bundleOptions: BundleOptions,
99
- buildOptions?: BuildOptions,
100
- ): Promise<{
101
- code: string;
102
- map: string;
103
- assets?: ReadonlyArray<AssetData>;
104
- }>;
128
+ $$PARAM_1$$?: BuildOptions,
129
+ ): Promise<{code: string; map: string; assets?: ReadonlyArray<AssetData>}>;
105
130
  getRamBundleInfo(options: BundleOptions): Promise<RamBundleInfo>;
106
131
  getAssets(options: BundleOptions): Promise<ReadonlyArray<AssetData>>;
132
+ _getAssetsFromDependencies(
133
+ dependencies: ReadOnlyDependencies,
134
+ platform: null | undefined | string,
135
+ ): Promise<ReadonlyArray<AssetData>>;
107
136
  getOrderedDependencyPaths(options: {
108
137
  readonly dev: boolean;
109
138
  readonly entryFile: string;
110
139
  readonly minify: boolean;
111
- readonly platform: string;
112
- }): Promise<string[]>;
113
- processRequest(
114
- IncomingMessage: IncomingMessage,
115
- ServerResponse: ServerResponse,
116
- next: (e: Error | null) => unknown,
117
- ): void;
140
+ readonly platform: null | undefined | string;
141
+ }): Promise<Array<string>>;
142
+ _rangeRequestMiddleware(
143
+ req: IncomingMessage,
144
+ res: ServerResponse,
145
+ data: string | Buffer,
146
+ assetPath: string,
147
+ ): Buffer | string;
148
+ _processSingleAssetRequest(
149
+ req: IncomingMessage,
150
+ res: ServerResponse,
151
+ ): Promise<void>;
152
+ processRequest: (
153
+ $$PARAM_0$$: IncomingMessage,
154
+ $$PARAM_1$$: ServerResponse,
155
+ $$PARAM_2$$: (e: null | undefined | Error) => void,
156
+ ) => void;
157
+ _parseOptions(url: string): BundleOptions;
158
+ _rewriteAndNormalizeUrl(requestUrl: string): string;
159
+ _processRequest(
160
+ req: IncomingMessage,
161
+ res: ServerResponse,
162
+ next: ($$PARAM_0$$: null | undefined | Error) => void,
163
+ ): Promise<void>;
164
+ _processSourceRequest(
165
+ relativeFilePathname: string,
166
+ rootDir: string,
167
+ res: ServerResponse,
168
+ ): Promise<void>;
169
+ _createRequestProcessor<T>($$PARAM_0$$: {
170
+ readonly bundleType: 'assets' | 'bundle' | 'map';
171
+ readonly createStartEntry: (
172
+ context: ProcessStartContext,
173
+ ) => ActionLogEntryData;
174
+ readonly createEndEntry: (
175
+ context: ProcessEndContext<T>,
176
+ ) => Partial<ActionStartLogEntry>;
177
+ readonly build: (context: ProcessStartContext) => Promise<T>;
178
+ readonly delete?: (context: ProcessDeleteContext) => Promise<void>;
179
+ readonly finish: (context: ProcessEndContext<T>) => void;
180
+ }): (
181
+ req: IncomingMessage,
182
+ res: ServerResponse,
183
+ bundleOptions: BundleOptions,
184
+ buildContext: Readonly<{
185
+ buildNumber: number;
186
+ bundlePerfLogger: RootPerfLogger;
187
+ }>,
188
+ ) => Promise<void>;
189
+ _processBundleRequest: (
190
+ req: IncomingMessage,
191
+ res: ServerResponse,
192
+ bundleOptions: BundleOptions,
193
+ buildContext: Readonly<{
194
+ buildNumber: number;
195
+ bundlePerfLogger: RootPerfLogger;
196
+ }>,
197
+ ) => Promise<void>;
198
+ _getSortedModules(graph: ReadOnlyGraph): ReadonlyArray<Module>;
199
+ _processSourceMapRequest: (
200
+ req: IncomingMessage,
201
+ res: ServerResponse,
202
+ bundleOptions: BundleOptions,
203
+ buildContext: Readonly<{
204
+ buildNumber: number;
205
+ bundlePerfLogger: RootPerfLogger;
206
+ }>,
207
+ ) => Promise<void>;
208
+ _processAssetsRequest: (
209
+ req: IncomingMessage,
210
+ res: ServerResponse,
211
+ bundleOptions: BundleOptions,
212
+ buildContext: Readonly<{
213
+ buildNumber: number;
214
+ bundlePerfLogger: RootPerfLogger;
215
+ }>,
216
+ ) => Promise<void>;
217
+ _symbolicate(req: IncomingMessage, res: ServerResponse): Promise<void>;
218
+ _explodedSourceMapForBundleOptions(
219
+ bundleOptions: BundleOptions,
220
+ ): Promise<ExplodedSourceMap>;
221
+ _resolveRelativePath(
222
+ filePath: string,
223
+ $$PARAM_1$$: Readonly<{
224
+ relativeTo: 'project' | 'server';
225
+ resolverOptions: ResolverInputOptions;
226
+ transformOptions: TransformInputOptions;
227
+ }>,
228
+ ): Promise<string>;
229
+ getNewBuildNumber(): number;
230
+ getPlatforms(): ReadonlyArray<string>;
231
+ getWatchFolders(): ReadonlyArray<string>;
232
+ static DEFAULT_GRAPH_OPTIONS: Readonly<{
233
+ customResolverOptions: CustomResolverOptions;
234
+ customTransformOptions: CustomTransformOptions;
235
+ dev: boolean;
236
+ minify: boolean;
237
+ unstable_transformProfile: 'default';
238
+ }>;
239
+ static DEFAULT_BUNDLE_OPTIONS: Omit<
240
+ typeof Server.DEFAULT_GRAPH_OPTIONS,
241
+ keyof {
242
+ excludeSource: false;
243
+ inlineSourceMap: false;
244
+ lazy: false;
245
+ modulesOnly: false;
246
+ onProgress: null;
247
+ runModule: true;
248
+ shallow: false;
249
+ sourceMapUrl: null;
250
+ sourceUrl: null;
251
+ sourcePaths: SourcePathsMode;
252
+ }
253
+ > & {
254
+ excludeSource: false;
255
+ inlineSourceMap: false;
256
+ lazy: false;
257
+ modulesOnly: false;
258
+ onProgress: null;
259
+ runModule: true;
260
+ shallow: false;
261
+ sourceMapUrl: null;
262
+ sourceUrl: null;
263
+ sourcePaths: SourcePathsMode;
264
+ };
265
+ _getServerRootDir(): string;
266
+ _getEntryPointAbsolutePath(entryFile: string): string;
267
+ ready(): Promise<void>;
268
+ _shouldAddModuleToIgnoreList(module: Module): boolean;
269
+ _getModuleSourceUrl(module: Module, mode: SourcePathsMode): string;
118
270
  }
271
+ export default Server;