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
@@ -11,19 +11,20 @@
11
11
 
12
12
  import type {RequireContext} from '../lib/contextModule';
13
13
  import type {RequireContextParams} from '../ModuleGraph/worker/collectDependencies';
14
+ import type {ReadonlySourceLocation} from '../shared/types';
14
15
  import type {Graph} from './Graph';
15
16
  import type {JsTransformOptions} from 'metro-transform-worker';
16
17
 
17
18
  import CountingSet from '../lib/CountingSet';
18
19
 
19
20
  export type MixedOutput = {
20
- +data: mixed,
21
+ +data: unknown,
21
22
  +type: string,
22
23
  };
23
24
 
24
25
  export type AsyncDependencyType = 'async' | 'maybeSync' | 'prefetch' | 'weak';
25
26
 
26
- export type TransformResultDependency = $ReadOnly<{
27
+ export type TransformResultDependency = Readonly<{
27
28
  /**
28
29
  * The literal name provided to a require or import call. For example 'foo' in
29
30
  * case of `require('foo')`.
@@ -33,7 +34,7 @@ export type TransformResultDependency = $ReadOnly<{
33
34
  /**
34
35
  * Extra data returned by the dependency extractor.
35
36
  */
36
- data: $ReadOnly<{
37
+ data: Readonly<{
37
38
  /**
38
39
  * A locally unique key for this dependency within the current module.
39
40
  */
@@ -52,43 +53,43 @@ export type TransformResultDependency = $ReadOnly<{
52
53
  */
53
54
  isOptional?: boolean,
54
55
 
55
- locs: $ReadOnlyArray<BabelSourceLocation>,
56
+ locs: ReadonlyArray<ReadonlySourceLocation>,
56
57
 
57
58
  /** Context for requiring a collection of modules. */
58
59
  contextParams?: RequireContextParams,
59
60
  }>,
60
61
  }>;
61
62
 
62
- export type ResolvedDependency = $ReadOnly<{
63
+ export type ResolvedDependency = Readonly<{
63
64
  absolutePath: string,
64
65
  data: TransformResultDependency,
65
66
  }>;
66
67
 
67
68
  export type Dependency =
68
69
  | ResolvedDependency
69
- | $ReadOnly<{
70
+ | Readonly<{
70
71
  data: TransformResultDependency,
71
72
  }>;
72
73
 
73
- export type Module<T = MixedOutput> = $ReadOnly<{
74
+ export type Module<T = MixedOutput> = Readonly<{
74
75
  dependencies: Map<string, Dependency>,
75
76
  inverseDependencies: CountingSet<string>,
76
- output: $ReadOnlyArray<T>,
77
+ output: ReadonlyArray<T>,
77
78
  path: string,
78
79
  getSource: () => Buffer,
79
80
  unstable_transformResultKey?: ?string,
80
81
  }>;
81
82
 
82
- export type ModuleData<T = MixedOutput> = $ReadOnly<{
83
- dependencies: $ReadOnlyMap<string, Dependency>,
84
- resolvedContexts: $ReadOnlyMap<string, RequireContext>,
85
- output: $ReadOnlyArray<T>,
83
+ export type ModuleData<T = MixedOutput> = Readonly<{
84
+ dependencies: ReadonlyMap<string, Dependency>,
85
+ resolvedContexts: ReadonlyMap<string, RequireContext>,
86
+ output: ReadonlyArray<T>,
86
87
  getSource: () => Buffer,
87
88
  unstable_transformResultKey?: ?string,
88
89
  }>;
89
90
 
90
91
  export type Dependencies<T = MixedOutput> = Map<string, Module<T>>;
91
- export type ReadOnlyDependencies<T = MixedOutput> = $ReadOnlyMap<
92
+ export type ReadOnlyDependencies<T = MixedOutput> = ReadonlyMap<
92
93
  string,
93
94
  Module<T>,
94
95
  >;
@@ -98,28 +99,28 @@ export type TransformInputOptions = Omit<
98
99
  'inlinePlatform' | 'inlineRequires',
99
100
  >;
100
101
 
101
- export type GraphInputOptions = $ReadOnly<{
102
- entryPoints: $ReadOnlySet<string>,
102
+ export type GraphInputOptions = Readonly<{
103
+ entryPoints: ReadonlySet<string>,
103
104
  // Unused in core but useful for custom serializers / experimentalSerializerHook
104
105
  transformOptions: TransformInputOptions,
105
106
  }>;
106
107
 
107
108
  export interface ReadOnlyGraph<T = MixedOutput> {
108
- +entryPoints: $ReadOnlySet<string>;
109
+ +entryPoints: ReadonlySet<string>;
109
110
  // Unused in core but useful for custom serializers / experimentalSerializerHook
110
- +transformOptions: $ReadOnly<TransformInputOptions>;
111
+ +transformOptions: Readonly<TransformInputOptions>;
111
112
  +dependencies: ReadOnlyDependencies<T>;
112
113
  }
113
114
 
114
115
  export type {Graph};
115
116
 
116
- export type TransformResult<T = MixedOutput> = $ReadOnly<{
117
- dependencies: $ReadOnlyArray<TransformResultDependency>,
118
- output: $ReadOnlyArray<T>,
117
+ export type TransformResult<T = MixedOutput> = Readonly<{
118
+ dependencies: ReadonlyArray<TransformResultDependency>,
119
+ output: ReadonlyArray<T>,
119
120
  unstable_transformResultKey?: ?string,
120
121
  }>;
121
122
 
122
- export type TransformResultWithSource<T = MixedOutput> = $ReadOnly<{
123
+ export type TransformResultWithSource<T = MixedOutput> = Readonly<{
123
124
  ...TransformResult<T>,
124
125
  getSource: () => Buffer,
125
126
  }>;
@@ -141,21 +142,22 @@ export type AllowOptionalDependencies =
141
142
  | boolean
142
143
  | AllowOptionalDependenciesWithOptions;
143
144
 
144
- export type BundlerResolution = $ReadOnly<{
145
+ export type BundlerResolution = Readonly<{
145
146
  type: 'sourceFile',
146
147
  filePath: string,
147
148
  }>;
148
149
 
149
- export type Options<T = MixedOutput> = {
150
- +resolve: ResolveFn,
151
- +transform: TransformFn<T>,
152
- +transformOptions: TransformInputOptions,
153
- +onProgress: ?(numProcessed: number, total: number) => mixed,
154
- +lazy: boolean,
155
- +unstable_allowRequireContext: boolean,
156
- +unstable_enablePackageExports: boolean,
157
- +shallow: boolean,
158
- };
150
+ export type Options<T = MixedOutput> = Readonly<{
151
+ resolve: ResolveFn,
152
+ transform: TransformFn<T>,
153
+ transformOptions: TransformInputOptions,
154
+ onProgress: ?(numProcessed: number, total: number) => unknown,
155
+ lazy: boolean,
156
+ unstable_allowRequireContext: boolean,
157
+ unstable_enablePackageExports: boolean,
158
+ unstable_incrementalResolution: boolean,
159
+ shallow: boolean,
160
+ }>;
159
161
 
160
162
  export type DeltaResult<T = MixedOutput> = {
161
163
  +added: Map<string, Module<T>>,
@@ -164,7 +166,7 @@ export type DeltaResult<T = MixedOutput> = {
164
166
  +reset: boolean,
165
167
  };
166
168
 
167
- export type SerializerOptions = $ReadOnly<{
169
+ export type SerializerOptions = Readonly<{
168
170
  asyncRequireModulePath: string,
169
171
  createModuleId: string => number,
170
172
  dev: boolean,
@@ -178,7 +180,7 @@ export type SerializerOptions = $ReadOnly<{
178
180
  modulesOnly: boolean,
179
181
  processModuleFilter: (module: Module<>) => boolean,
180
182
  projectRoot: string,
181
- runBeforeMainModule: $ReadOnlyArray<string>,
183
+ runBeforeMainModule: ReadonlyArray<string>,
182
184
  runModule: boolean,
183
185
  serverRoot: string,
184
186
  shouldAddToIgnoreList: (Module<>) => boolean,
@@ -15,7 +15,9 @@ import type {
15
15
  Options,
16
16
  ReadOnlyGraph,
17
17
  } from './DeltaBundler/types';
18
- import type {EventEmitter} from 'events';
18
+ import type EventEmitter from 'events';
19
+
20
+ import DeltaCalculator from './DeltaBundler/DeltaCalculator';
19
21
 
20
22
  export type {
21
23
  DeltaResult,
@@ -29,8 +31,15 @@ export type {
29
31
  TransformResultDependency,
30
32
  TransformResultWithSource,
31
33
  } from './DeltaBundler/types';
32
-
33
- export default class DeltaBundler<T = MixedOutput> {
34
+ /**
35
+ * `DeltaBundler` uses the `DeltaTransformer` to build bundle deltas. This
36
+ * module handles all the transformer instances so it can support multiple
37
+ * concurrent clients requesting their own deltas. This is done through the
38
+ * `clientId` param (which maps a client to a specific delta transformer).
39
+ */
40
+ declare class DeltaBundler<T = MixedOutput> {
41
+ _changeEventSource: EventEmitter;
42
+ _deltaCalculators: Map<Graph<T>, DeltaCalculator<T>>;
34
43
  constructor(changeEventSource: EventEmitter);
35
44
  end(): void;
36
45
  getDependencies(
@@ -41,18 +50,11 @@ export default class DeltaBundler<T = MixedOutput> {
41
50
  entryPoints: ReadonlyArray<string>,
42
51
  options: Options<T>,
43
52
  ): Promise<Graph<T>>;
44
-
45
53
  getDelta(
46
54
  graph: Graph<T>,
47
- {
48
- reset,
49
- shallow,
50
- }: {
51
- reset: boolean;
52
- shallow: boolean;
53
- },
55
+ $$PARAM_1$$: {reset: boolean; shallow: boolean},
54
56
  ): Promise<DeltaResult<T>>;
55
-
56
57
  listen(graph: Graph<T>, callback: () => Promise<void>): () => void;
57
58
  endGraph(graph: Graph<T>): void;
58
59
  }
60
+ export default DeltaBundler;
@@ -56,7 +56,7 @@ export default class DeltaBundler<T = MixedOutput> {
56
56
  }
57
57
 
58
58
  async getDependencies(
59
- entryPoints: $ReadOnlyArray<string>,
59
+ entryPoints: ReadonlyArray<string>,
60
60
  options: Options<T>,
61
61
  ): Promise<ReadOnlyGraph<T>['dependencies']> {
62
62
  const deltaCalculator = new DeltaCalculator(
@@ -76,7 +76,7 @@ export default class DeltaBundler<T = MixedOutput> {
76
76
  // so that we don't leak graphs that are not reachable.
77
77
  // To get just the dependencies, use getDependencies which will not leak graphs.
78
78
  async buildGraph(
79
- entryPoints: $ReadOnlyArray<string>,
79
+ entryPoints: ReadonlyArray<string>,
80
80
  options: Options<T>,
81
81
  ): Promise<Graph<T>> {
82
82
  const deltaCalculator = new DeltaCalculator(
@@ -0,0 +1,79 @@
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 {
11
+ RevisionId,
12
+ default as IncrementalBundler,
13
+ } from './IncrementalBundler';
14
+ import type {GraphOptions} from './shared/types';
15
+ import type {ConfigT, RootPerfLogger} from 'metro-config';
16
+ import type {
17
+ HmrErrorMessage,
18
+ HmrUpdateMessage,
19
+ } from 'metro-runtime/src/modules/types';
20
+
21
+ export type Client = {
22
+ optedIntoHMR: boolean;
23
+ revisionIds: Array<RevisionId>;
24
+ readonly sendFn: ($$PARAM_0$$: string) => void;
25
+ };
26
+ type ClientGroup = {
27
+ readonly clients: Set<Client>;
28
+ clientUrl: URL;
29
+ revisionId: RevisionId;
30
+ readonly unlisten: () => void;
31
+ readonly graphOptions: GraphOptions;
32
+ };
33
+ /**
34
+ * The HmrServer (Hot Module Reloading) implements a lightweight interface
35
+ * to communicate easily to the logic in the React Native repository (which
36
+ * is the one that handles the Web Socket connections).
37
+ *
38
+ * This interface allows the HmrServer to hook its own logic to WS clients
39
+ * getting connected, disconnected or having errors (through the
40
+ * `onClientConnect`, `onClientDisconnect` and `onClientError` methods).
41
+ */
42
+ declare class HmrServer<TClient extends Client> {
43
+ _config: ConfigT;
44
+ _bundler: IncrementalBundler;
45
+ _createModuleId: (path: string) => number;
46
+ _clientGroups: Map<RevisionId, ClientGroup>;
47
+ constructor(
48
+ bundler: IncrementalBundler,
49
+ createModuleId: (path: string) => number,
50
+ config: ConfigT,
51
+ );
52
+ onClientConnect: (
53
+ requestUrl: string,
54
+ sendFn: (data: string) => void,
55
+ ) => Promise<Client>;
56
+ _registerEntryPoint(
57
+ client: Client,
58
+ originalRequestUrl: string,
59
+ sendFn: (data: string) => void,
60
+ ): Promise<void>;
61
+ onClientMessage: (
62
+ client: TClient,
63
+ message: string | Buffer | ArrayBuffer | Array<Buffer>,
64
+ sendFn: (data: string) => void,
65
+ ) => Promise<void>;
66
+ onClientError: (client: TClient, e: Error) => void;
67
+ onClientDisconnect: (client: TClient) => void;
68
+ _handleFileChange(
69
+ group: ClientGroup,
70
+ options: {isInitialUpdate: boolean},
71
+ changeEvent: null | undefined | {logger: null | undefined | RootPerfLogger},
72
+ ): Promise<void>;
73
+ _prepareMessage(
74
+ group: ClientGroup,
75
+ options: {isInitialUpdate: boolean},
76
+ changeEvent: null | undefined | {logger: null | undefined | RootPerfLogger},
77
+ ): Promise<HmrUpdateMessage | HmrErrorMessage>;
78
+ }
79
+ export default HmrServer;
package/src/HmrServer.js CHANGED
@@ -31,28 +31,32 @@ var transformHelpers = _interopRequireWildcard(
31
31
  );
32
32
  var _metroCore = require("metro-core");
33
33
  var _nullthrows = _interopRequireDefault(require("nullthrows"));
34
- function _getRequireWildcardCache(e) {
35
- if ("function" != typeof WeakMap) return null;
36
- var r = new WeakMap(),
37
- t = new WeakMap();
38
- return (_getRequireWildcardCache = function (e) {
39
- return e ? t : r;
40
- })(e);
41
- }
42
- function _interopRequireWildcard(e, r) {
43
- if (!r && e && e.__esModule) return e;
44
- if (null === e || ("object" != typeof e && "function" != typeof e))
45
- return { default: e };
46
- var t = _getRequireWildcardCache(r);
47
- if (t && t.has(e)) return t.get(e);
48
- var n = { __proto__: null },
49
- a = Object.defineProperty && Object.getOwnPropertyDescriptor;
50
- for (var u in e)
51
- if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
52
- var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
53
- i && (i.get || i.set) ? Object.defineProperty(n, u, i) : (n[u] = e[u]);
34
+ function _interopRequireWildcard(e, t) {
35
+ if ("function" == typeof WeakMap)
36
+ var r = new WeakMap(),
37
+ n = new WeakMap();
38
+ return (_interopRequireWildcard = function (e, t) {
39
+ if (!t && e && e.__esModule) return e;
40
+ var o,
41
+ i,
42
+ f = { __proto__: null, default: e };
43
+ if (null === e || ("object" != typeof e && "function" != typeof e))
44
+ return f;
45
+ if ((o = t ? n : r)) {
46
+ if (o.has(e)) return o.get(e);
47
+ o.set(e, f);
54
48
  }
55
- return ((n.default = e), t && t.set(e, n), n);
49
+ for (const t in e)
50
+ "default" !== t &&
51
+ {}.hasOwnProperty.call(e, t) &&
52
+ ((i =
53
+ (o = Object.defineProperty) &&
54
+ Object.getOwnPropertyDescriptor(e, t)) &&
55
+ (i.get || i.set)
56
+ ? o(f, t, i)
57
+ : (f[t] = e[t]));
58
+ return f;
59
+ })(e, t);
56
60
  }
57
61
  function _interopRequireDefault(e) {
58
62
  return e && e.__esModule ? e : { default: e };
@@ -77,9 +81,10 @@ class HmrServer {
77
81
  optedIntoHMR: false,
78
82
  };
79
83
  };
80
- async _registerEntryPoint(client, requestUrl, sendFn) {
81
- debug("Registering entry point: %s", requestUrl);
82
- requestUrl = this._config.server.rewriteRequestUrl(requestUrl);
84
+ async _registerEntryPoint(client, originalRequestUrl, sendFn) {
85
+ debug("Registering entry point: %s", originalRequestUrl);
86
+ const requestUrl =
87
+ this._config.server.rewriteRequestUrl(originalRequestUrl);
83
88
  debug("Rewritten as: %s", requestUrl);
84
89
  const { bundleType: _bundleType, ...options } = (0,
85
90
  _parseBundleOptionsFromBundleRequestUrl.default)(
@@ -150,7 +155,7 @@ class HmrServer {
150
155
  unlisten: () => unlisten(),
151
156
  };
152
157
  this._clientGroups.set(id, clientGroup);
153
- let latestEventArgs = [];
158
+ let latestChangeEvent = null;
154
159
  const debounceCallHandleFileChange = (0, _debounceAsyncQueue.default)(
155
160
  async () => {
156
161
  await this._handleFileChange(
@@ -158,15 +163,15 @@ class HmrServer {
158
163
  {
159
164
  isInitialUpdate: false,
160
165
  },
161
- ...latestEventArgs,
166
+ latestChangeEvent,
162
167
  );
163
168
  },
164
169
  50,
165
170
  );
166
171
  const unlisten = this._bundler
167
172
  .getDeltaBundler()
168
- .listen(graph, async (...args) => {
169
- latestEventArgs = args;
173
+ .listen(graph, async (changeEvent) => {
174
+ latestChangeEvent = changeEvent;
170
175
  await debounceCallHandleFileChange();
171
176
  });
172
177
  }
@@ -218,7 +223,7 @@ class HmrServer {
218
223
  onClientError = (client, e) => {
219
224
  this._config.reporter.update({
220
225
  type: "hmr_client_error",
221
- error: e.error,
226
+ error: e,
222
227
  });
223
228
  this.onClientDisconnect(client);
224
229
  };
@@ -4,11 +4,14 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
+ * @flow strict-local
7
8
  * @format
8
- * @flow
9
9
  */
10
10
 
11
- import type IncrementalBundler, {RevisionId} from './IncrementalBundler';
11
+ import type {
12
+ RevisionId,
13
+ default as IncrementalBundler,
14
+ } from './IncrementalBundler';
12
15
  import type {GraphOptions} from './shared/types';
13
16
  import type {ConfigT, RootPerfLogger} from 'metro-config';
14
17
  import type {
@@ -93,11 +96,12 @@ export default class HmrServer<TClient: Client> {
93
96
 
94
97
  async _registerEntryPoint(
95
98
  client: Client,
96
- requestUrl: string,
99
+ originalRequestUrl: string,
97
100
  sendFn: (data: string) => void,
98
101
  ): Promise<void> {
99
- debug('Registering entry point: %s', requestUrl);
100
- requestUrl = this._config.server.rewriteRequestUrl(requestUrl);
102
+ debug('Registering entry point: %s', originalRequestUrl);
103
+ const requestUrl =
104
+ this._config.server.rewriteRequestUrl(originalRequestUrl);
101
105
  debug('Rewritten as: %s', requestUrl);
102
106
 
103
107
  const {bundleType: _bundleType, ...options} =
@@ -176,21 +180,22 @@ export default class HmrServer<TClient: Client> {
176
180
 
177
181
  this._clientGroups.set(id, clientGroup);
178
182
 
179
- let latestEventArgs: Array<any> = [];
183
+ let latestChangeEvent: ?{
184
+ logger: ?RootPerfLogger,
185
+ } = null;
180
186
 
181
187
  const debounceCallHandleFileChange = debounceAsyncQueue(async () => {
182
188
  await this._handleFileChange(
183
189
  nullthrows(clientGroup),
184
190
  {isInitialUpdate: false},
185
- ...latestEventArgs,
191
+ latestChangeEvent,
186
192
  );
187
193
  }, 50);
188
194
 
189
195
  const unlisten = this._bundler
190
196
  .getDeltaBundler()
191
- // $FlowFixMe[missing-local-annot]
192
- .listen(graph, async (...args) => {
193
- latestEventArgs = args;
197
+ .listen(graph, async changeEvent => {
198
+ latestChangeEvent = changeEvent;
194
199
  await debounceCallHandleFileChange();
195
200
  });
196
201
  }
@@ -242,10 +247,10 @@ export default class HmrServer<TClient: Client> {
242
247
  return Promise.resolve();
243
248
  };
244
249
 
245
- onClientError: (client: TClient, e: ErrorEvent) => void = (client, e) => {
250
+ onClientError: (client: TClient, e: Error) => void = (client, e) => {
246
251
  this._config.reporter.update({
247
252
  type: 'hmr_client_error',
248
- error: e.error,
253
+ error: e,
249
254
  });
250
255
  this.onClientDisconnect(client);
251
256
  };
@@ -0,0 +1,17 @@
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 {GraphId} from '../lib/getGraphId';
12
+
13
+ declare class GraphNotFoundError extends Error {
14
+ graphId: GraphId;
15
+ constructor(graphId: GraphId);
16
+ }
17
+ export default GraphNotFoundError;
@@ -0,0 +1,15 @@
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
+ declare class ResourceNotFoundError extends Error {
12
+ resourcePath: string;
13
+ constructor(resourcePath: string);
14
+ }
15
+ export default ResourceNotFoundError;
@@ -0,0 +1,17 @@
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 {RevisionId} from '../IncrementalBundler';
12
+
13
+ declare class RevisionNotFoundError extends Error {
14
+ revisionId: RevisionId;
15
+ constructor(revisionId: RevisionId);
16
+ }
17
+ export default RevisionNotFoundError;