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
@@ -8,53 +8,39 @@
8
8
  * @oncall react_native
9
9
  */
10
10
 
11
+ import type {Terminal} from 'metro-core';
11
12
  import type {HealthCheckResult, WatcherStatus} from 'metro-file-map';
13
+ import type {CustomResolverOptions} from 'metro-resolver';
14
+ import type {CustomTransformOptions} from 'metro-transform-worker';
12
15
 
13
- export interface BundleDetails {
16
+ export type BundleDetails = {
14
17
  bundleType: string;
18
+ customResolverOptions: CustomResolverOptions;
19
+ customTransformOptions: CustomTransformOptions;
15
20
  dev: boolean;
16
21
  entryFile: string;
17
22
  minify: boolean;
18
- platform?: string;
19
- runtimeBytecodeVersion?: number;
20
- }
21
-
23
+ platform: null | undefined | string;
24
+ };
22
25
  /**
23
26
  * A tagged union of all the actions that may happen and we may want to
24
27
  * report to the tool user.
25
28
  */
26
29
  export type ReportableEvent =
27
- | {
28
- port: number;
29
- hasReducedPerformance: boolean;
30
- type: 'initialize_started';
31
- }
32
- | {
33
- type: 'initialize_failed';
34
- port: number;
35
- error: Error;
36
- }
37
- | {
38
- buildID: string;
39
- type: 'bundle_build_done';
40
- }
41
- | {
42
- buildID: string;
43
- type: 'bundle_build_failed';
44
- }
30
+ | {port: number; hasReducedPerformance: boolean; type: 'initialize_started'}
31
+ | {type: 'initialize_failed'; port: number; error: Error}
32
+ | {type: 'initialize_done'; port: number}
33
+ | {buildID: string; type: 'bundle_build_done'}
34
+ | {buildID: string; type: 'bundle_build_failed'}
35
+ | {type: 'bundle_save_log'; message: string}
45
36
  | {
46
37
  buildID: string;
47
38
  bundleDetails: BundleDetails;
39
+ isPrefetch?: boolean;
48
40
  type: 'bundle_build_started';
49
41
  }
50
- | {
51
- error: Error;
52
- type: 'bundling_error';
53
- }
54
- | {
55
- type: 'dep_graph_loading';
56
- hasReducedPerformance: boolean;
57
- }
42
+ | {error: Error; type: 'bundling_error'}
43
+ | {type: 'dep_graph_loading'; hasReducedPerformance: boolean}
58
44
  | {type: 'dep_graph_loaded'}
59
45
  | {
60
46
  buildID: string;
@@ -62,27 +48,12 @@ export type ReportableEvent =
62
48
  transformedFileCount: number;
63
49
  totalFileCount: number;
64
50
  }
65
- | {
66
- type: 'cache_read_error';
67
- error: Error;
68
- }
69
- | {
70
- type: 'cache_write_error';
71
- error: Error;
72
- }
51
+ | {type: 'cache_read_error'; error: Error}
52
+ | {type: 'cache_write_error'; error: Error}
73
53
  | {type: 'transform_cache_reset'}
74
- | {
75
- type: 'worker_stdout_chunk';
76
- chunk: string;
77
- }
78
- | {
79
- type: 'worker_stderr_chunk';
80
- chunk: string;
81
- }
82
- | {
83
- type: 'hmr_client_error';
84
- error: Error;
85
- }
54
+ | {type: 'worker_stdout_chunk'; chunk: string}
55
+ | {type: 'worker_stderr_chunk'; chunk: string}
56
+ | {type: 'hmr_client_error'; error: Error}
86
57
  | {
87
58
  type: 'client_log';
88
59
  level:
@@ -94,33 +65,15 @@ export type ReportableEvent =
94
65
  | 'groupCollapsed'
95
66
  | 'groupEnd'
96
67
  | 'debug';
97
- data: unknown[];
98
- }
99
- | {
100
- type: 'server_listening';
101
- port: number;
102
- address: string;
103
- family: string;
104
- }
105
- | {
106
- type: 'transformer_load_started';
107
- }
108
- | {
109
- type: 'transformer_load_done';
110
- }
111
- | {
112
- type: 'transformer_load_failed';
113
- error: Error;
114
- }
115
- | {
116
- type: 'watcher_health_check_result';
117
- result: HealthCheckResult;
118
- }
119
- | {
120
- type: 'watcher_status';
121
- status: WatcherStatus;
122
- };
123
-
68
+ data: Array<unknown>;
69
+ }
70
+ | {type: 'resolver_warning'; message: string}
71
+ | {type: 'server_listening'; port: number; address: string; family: string}
72
+ | {type: 'transformer_load_started'}
73
+ | {type: 'transformer_load_done'}
74
+ | {type: 'transformer_load_failed'; error: Error}
75
+ | {type: 'watcher_health_check_result'; result: HealthCheckResult}
76
+ | {type: 'watcher_status'; status: WatcherStatus};
124
77
  /**
125
78
  * Code across the application takes a reporter as an option and calls the
126
79
  * update whenever one of the ReportableEvent happens. Code does not directly
@@ -139,6 +92,37 @@ export type ReportableEvent =
139
92
  * TerminalReporter, that should be the only place in the application should
140
93
  * access the `terminal` module (nor the `console`).
141
94
  */
142
- export interface Reporter {
143
- update: (event: ReportableEvent) => void;
144
- }
95
+ export type Reporter = {update(event: ReportableEvent): void};
96
+ /**
97
+ * A standard way to log a warning to the terminal. This should not be called
98
+ * from some arbitrary Metro logic, only from the reporters. Instead of
99
+ * calling this, add a new type of ReportableEvent instead, and implement a
100
+ * proper handler in the reporter(s).
101
+ */
102
+ export declare function logWarning(
103
+ terminal: Terminal,
104
+ format: string,
105
+ ...args: Array<unknown>
106
+ ): void;
107
+ /**
108
+ * Similar to `logWarning`, but for messages that require the user to act.
109
+ */
110
+ export declare function logError(
111
+ terminal: Terminal,
112
+ format: string,
113
+ ...args: Array<unknown>
114
+ ): void;
115
+ /**
116
+ * Similar to `logWarning`, but for informational messages.
117
+ */
118
+ export declare function logInfo(
119
+ terminal: Terminal,
120
+ format: string,
121
+ ...args: Array<unknown>
122
+ ): void;
123
+ /**
124
+ * A reporter that does nothing. Errors and warnings will be swallowed, that
125
+ * is generally not what you want.
126
+ */
127
+ export declare const nullReporter: {update(): void};
128
+ export declare type nullReporter = typeof nullReporter;
@@ -126,7 +126,7 @@ export type ReportableEvent =
126
126
  | 'groupCollapsed'
127
127
  | 'groupEnd'
128
128
  | 'debug',
129
- data: Array<mixed>,
129
+ data: Array<unknown>,
130
130
  ...
131
131
  }
132
132
  | {
@@ -187,7 +187,7 @@ export type Reporter = interface {update(event: ReportableEvent): void};
187
187
  export function logWarning(
188
188
  terminal: Terminal,
189
189
  format: string,
190
- ...args: Array<mixed>
190
+ ...args: Array<unknown>
191
191
  ): void {
192
192
  const str = util.format(format, ...args);
193
193
  terminal.log('%s %s', chalk.yellow.inverse.bold(' WARN '), str);
@@ -199,7 +199,7 @@ export function logWarning(
199
199
  export function logError(
200
200
  terminal: Terminal,
201
201
  format: string,
202
- ...args: Array<mixed>
202
+ ...args: Array<unknown>
203
203
  ): void {
204
204
  terminal.log(
205
205
  '%s %s',
@@ -221,7 +221,7 @@ export function logError(
221
221
  export function logInfo(
222
222
  terminal: Terminal,
223
223
  format: string,
224
- ...args: Array<mixed>
224
+ ...args: Array<unknown>
225
225
  ): void {
226
226
  const str = util.format(format, ...args);
227
227
  terminal.log('%s %s', chalk.cyan.inverse.bold(' INFO '), str);
@@ -0,0 +1,16 @@
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 {BundleOptions, SplitBundleOptions} from '../shared/types';
12
+ /**
13
+ * Splits a BundleOptions object into smaller, more manageable parts.
14
+ */
15
+ declare function splitBundleOptions(options: BundleOptions): SplitBundleOptions;
16
+ export default splitBundleOptions;
@@ -0,0 +1,35 @@
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 Bundler from '../Bundler';
12
+ import type {TransformFn, default as DeltaBundler} from '../DeltaBundler';
13
+ import type {
14
+ BundlerResolution,
15
+ TransformInputOptions,
16
+ TransformResultDependency,
17
+ } from '../DeltaBundler/types';
18
+ import type {ResolverInputOptions} from '../shared/types';
19
+ import type {ConfigT} from 'metro-config';
20
+
21
+ export declare function getTransformFn(
22
+ entryFiles: ReadonlyArray<string>,
23
+ bundler: Bundler,
24
+ deltaBundler: DeltaBundler,
25
+ config: ConfigT,
26
+ options: TransformInputOptions,
27
+ resolverOptions: ResolverInputOptions,
28
+ ): Promise<TransformFn>;
29
+ export declare function getResolveDependencyFn(
30
+ bundler: Bundler,
31
+ platform: null | undefined | string,
32
+ resolverOptions: ResolverInputOptions,
33
+ ): Promise<
34
+ (from: string, dependency: TransformResultDependency) => BundlerResolution
35
+ >;
@@ -31,8 +31,8 @@ async function calcTransformerOptions(
31
31
  const baseOptions = {
32
32
  customTransformOptions: options.customTransformOptions,
33
33
  dev: options.dev,
34
- inlineRequires: false,
35
34
  inlinePlatform: true,
35
+ inlineRequires: false,
36
36
  minify: options.minify,
37
37
  platform: options.platform,
38
38
  unstable_transformProfile: options.unstable_transformProfile,
@@ -45,11 +45,14 @@ async function calcTransformerOptions(
45
45
  }
46
46
  const getDependencies = async (path) => {
47
47
  const dependencies = await deltaBundler.getDependencies([path], {
48
+ lazy: false,
49
+ onProgress: null,
48
50
  resolve: await getResolveDependencyFn(
49
51
  bundler,
50
52
  options.platform,
51
53
  resolverOptions,
52
54
  ),
55
+ shallow: false,
53
56
  transform: await getTransformFn(
54
57
  [path],
55
58
  bundler,
@@ -62,13 +65,12 @@ async function calcTransformerOptions(
62
65
  resolverOptions,
63
66
  ),
64
67
  transformOptions: options,
65
- onProgress: null,
66
- lazy: false,
67
68
  unstable_allowRequireContext:
68
69
  config.transformer.unstable_allowRequireContext,
69
70
  unstable_enablePackageExports:
70
71
  config.resolver.unstable_enablePackageExports,
71
- shallow: false,
72
+ unstable_incrementalResolution:
73
+ config.resolver.unstable_incrementalResolution,
72
74
  });
73
75
  return Array.from(dependencies.keys());
74
76
  };
@@ -83,15 +85,15 @@ async function calcTransformerOptions(
83
85
  );
84
86
  return {
85
87
  ...baseOptions,
86
- inlineRequires: transform?.inlineRequires || false,
87
88
  experimentalImportSupport: transform?.experimentalImportSupport || false,
89
+ inlineRequires: transform?.inlineRequires || false,
90
+ nonInlinedRequires:
91
+ transform?.nonInlinedRequires || baseIgnoredInlineRequires,
92
+ type: "module",
88
93
  unstable_memoizeInlineRequires:
89
94
  transform?.unstable_memoizeInlineRequires || false,
90
95
  unstable_nonMemoizedInlineRequires:
91
96
  transform?.unstable_nonMemoizedInlineRequires || [],
92
- nonInlinedRequires:
93
- transform?.nonInlinedRequires || baseIgnoredInlineRequires,
94
- type: "module",
95
97
  };
96
98
  }
97
99
  function removeInlineRequiresBlockListFromOptions(path, inlineRequires) {
@@ -138,11 +140,11 @@ async function getTransformFn(
138
140
  modulePath,
139
141
  {
140
142
  ...transformOptions,
141
- type: getType(transformOptions.type, modulePath, assetExts),
142
143
  inlineRequires: removeInlineRequiresBlockListFromOptions(
143
144
  modulePath,
144
145
  inlineRequires,
145
146
  ),
147
+ type: getType(transformOptions.type, modulePath, assetExts),
146
148
  },
147
149
  templateBuffer,
148
150
  );
@@ -10,7 +10,7 @@
10
10
  */
11
11
 
12
12
  import type Bundler from '../Bundler';
13
- import type DeltaBundler, {TransformFn} from '../DeltaBundler';
13
+ import type {TransformFn, default as DeltaBundler} from '../DeltaBundler';
14
14
  import type {
15
15
  BundlerResolution,
16
16
  TransformInputOptions,
@@ -26,10 +26,10 @@ import {getContextModuleTemplate} from './contextModuleTemplates';
26
26
  import isAssetFile from 'metro-resolver/private/utils/isAssetFile';
27
27
 
28
28
  type InlineRequiresRaw =
29
- | $ReadOnly<{blockList: $ReadOnly<{[string]: true, ...}>, ...}>
29
+ | Readonly<{blockList: Readonly<{[string]: true, ...}>, ...}>
30
30
  | boolean;
31
31
 
32
- type TransformOptionsWithRawInlines = $ReadOnly<{
32
+ type TransformOptionsWithRawInlines = Readonly<{
33
33
  ...TransformOptions,
34
34
  inlineRequires: InlineRequiresRaw,
35
35
  }>;
@@ -44,7 +44,7 @@ const baseIgnoredInlineRequires = [
44
44
  ];
45
45
 
46
46
  async function calcTransformerOptions(
47
- entryFiles: $ReadOnlyArray<string>,
47
+ entryFiles: ReadonlyArray<string>,
48
48
  bundler: Bundler,
49
49
  deltaBundler: DeltaBundler<>,
50
50
  config: ConfigT,
@@ -54,8 +54,8 @@ async function calcTransformerOptions(
54
54
  const baseOptions = {
55
55
  customTransformOptions: options.customTransformOptions,
56
56
  dev: options.dev,
57
- inlineRequires: false,
58
57
  inlinePlatform: true,
58
+ inlineRequires: false,
59
59
  minify: options.minify,
60
60
  platform: options.platform,
61
61
  unstable_transformProfile: options.unstable_transformProfile,
@@ -73,11 +73,14 @@ async function calcTransformerOptions(
73
73
 
74
74
  const getDependencies = async (path: string) => {
75
75
  const dependencies = await deltaBundler.getDependencies([path], {
76
+ lazy: false,
77
+ onProgress: null,
76
78
  resolve: await getResolveDependencyFn(
77
79
  bundler,
78
80
  options.platform,
79
81
  resolverOptions,
80
82
  ),
83
+ shallow: false,
81
84
  transform: await getTransformFn(
82
85
  [path],
83
86
  bundler,
@@ -90,13 +93,12 @@ async function calcTransformerOptions(
90
93
  resolverOptions,
91
94
  ),
92
95
  transformOptions: options,
93
- onProgress: null,
94
- lazy: false,
95
96
  unstable_allowRequireContext:
96
97
  config.transformer.unstable_allowRequireContext,
97
98
  unstable_enablePackageExports:
98
99
  config.resolver.unstable_enablePackageExports,
99
- shallow: false,
100
+ unstable_incrementalResolution:
101
+ config.resolver.unstable_incrementalResolution,
100
102
  });
101
103
 
102
104
  return Array.from(dependencies.keys());
@@ -110,15 +112,15 @@ async function calcTransformerOptions(
110
112
 
111
113
  return {
112
114
  ...baseOptions,
113
- inlineRequires: transform?.inlineRequires || false,
114
115
  experimentalImportSupport: transform?.experimentalImportSupport || false,
116
+ inlineRequires: transform?.inlineRequires || false,
117
+ nonInlinedRequires:
118
+ transform?.nonInlinedRequires || baseIgnoredInlineRequires,
119
+ type: 'module',
115
120
  unstable_memoizeInlineRequires:
116
121
  transform?.unstable_memoizeInlineRequires || false,
117
122
  unstable_nonMemoizedInlineRequires:
118
123
  transform?.unstable_nonMemoizedInlineRequires || [],
119
- nonInlinedRequires:
120
- transform?.nonInlinedRequires || baseIgnoredInlineRequires,
121
- type: 'module',
122
124
  };
123
125
  }
124
126
 
@@ -134,7 +136,7 @@ function removeInlineRequiresBlockListFromOptions(
134
136
  }
135
137
 
136
138
  export async function getTransformFn(
137
- entryFiles: $ReadOnlyArray<string>,
139
+ entryFiles: ReadonlyArray<string>,
138
140
  bundler: Bundler,
139
141
  deltaBundler: DeltaBundler<>,
140
142
  config: ConfigT,
@@ -181,11 +183,11 @@ export async function getTransformFn(
181
183
  modulePath,
182
184
  {
183
185
  ...transformOptions,
184
- type: getType(transformOptions.type, modulePath, assetExts),
185
186
  inlineRequires: removeInlineRequiresBlockListFromOptions(
186
187
  modulePath,
187
188
  inlineRequires,
188
189
  ),
190
+ type: getType(transformOptions.type, modulePath, assetExts),
189
191
  },
190
192
  templateBuffer,
191
193
  );
@@ -195,7 +197,7 @@ export async function getTransformFn(
195
197
  function getType(
196
198
  type: string,
197
199
  filePath: string,
198
- assetExts: $ReadOnlySet<string>,
200
+ assetExts: ReadonlySet<string>,
199
201
  ): Type {
200
202
  if (type === 'script') {
201
203
  return type;
@@ -0,0 +1,126 @@
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 {
12
+ BundlerResolution,
13
+ TransformResultDependency,
14
+ } from '../../DeltaBundler/types';
15
+ import type {Reporter} from '../../lib/reporting';
16
+ import type {ResolverInputOptions} from '../../shared/types';
17
+ import type {
18
+ CustomResolver,
19
+ DoesFileExist,
20
+ FileCandidates,
21
+ FileSystemLookup,
22
+ Resolution,
23
+ ResolveAsset,
24
+ } from 'metro-resolver';
25
+ import type {PackageForModule, PackageJson} from 'metro-resolver/private/types';
26
+
27
+ export type DirExistsFn = (filePath: string) => boolean;
28
+ export type Packageish = {path: string; read(): PackageJson};
29
+ export type Moduleish = {readonly path: string};
30
+ export type PackageishCache<TPackage> = {
31
+ getPackage(
32
+ name: string,
33
+ platform?: string,
34
+ supportsNativePlatform?: boolean,
35
+ ): TPackage;
36
+ getPackageOf(
37
+ absolutePath: string,
38
+ ): null | undefined | {pkg: TPackage; packageRelativePath: string};
39
+ };
40
+ type Options<TPackage> = Readonly<{
41
+ assetExts: ReadonlySet<string>;
42
+ dirExists: DirExistsFn;
43
+ disableHierarchicalLookup: boolean;
44
+ doesFileExist: DoesFileExist;
45
+ emptyModulePath: string;
46
+ extraNodeModules: null | undefined | object;
47
+ fileSystemLookup: FileSystemLookup;
48
+ getHasteModulePath: (
49
+ name: string,
50
+ platform: null | undefined | string,
51
+ ) => null | undefined | string;
52
+ getHastePackagePath: (
53
+ name: string,
54
+ platform: null | undefined | string,
55
+ ) => null | undefined | string;
56
+ mainFields: ReadonlyArray<string>;
57
+ packageCache: PackageishCache<TPackage>;
58
+ nodeModulesPaths: ReadonlyArray<string>;
59
+ preferNativePlatform: boolean;
60
+ projectRoot: string;
61
+ reporter: Reporter;
62
+ resolveAsset: ResolveAsset;
63
+ resolveRequest: null | undefined | CustomResolver;
64
+ sourceExts: ReadonlyArray<string>;
65
+ unstable_conditionNames: ReadonlyArray<string>;
66
+ unstable_conditionsByPlatform: Readonly<{
67
+ [platform: string]: ReadonlyArray<string>;
68
+ }>;
69
+ unstable_enablePackageExports: boolean;
70
+ unstable_incrementalResolution: boolean;
71
+ }>;
72
+ export declare class ModuleResolver<TPackage extends Packageish> {
73
+ _options: Options<TPackage>;
74
+ _projectRootFakeModulePath: string;
75
+ _cachedEmptyModule: null | undefined | BundlerResolution;
76
+ constructor(options: Options<TPackage>);
77
+ _getEmptyModule(): BundlerResolution;
78
+ resolveDependency(
79
+ originModulePath: string,
80
+ dependency: TransformResultDependency,
81
+ allowHaste: boolean,
82
+ platform: string | null,
83
+ resolverOptions: ResolverInputOptions,
84
+ ): BundlerResolution;
85
+ _getPackage: (packageJsonPath: string) => null | undefined | PackageJson;
86
+ _getPackageForModule: (
87
+ absolutePath: string,
88
+ ) => null | undefined | PackageForModule;
89
+ /**
90
+ * TODO: Return Resolution instead of coercing to BundlerResolution here
91
+ */
92
+ _getFileResolvedModule(resolution: Resolution): BundlerResolution;
93
+ _logWarning: (message: string) => void;
94
+ _removeRoot(candidates: FileCandidates): FileCandidates;
95
+ }
96
+ export declare class UnableToResolveError extends Error {
97
+ /**
98
+ * File path of the module that tried to require a module, ex. `/js/foo.js`.
99
+ */
100
+ originModulePath: string;
101
+ /**
102
+ * The name of the module that was required, no necessarily a path,
103
+ * ex. `./bar`, or `invariant`.
104
+ */
105
+ targetModuleName: string;
106
+ /**
107
+ * Original error that causes this error
108
+ */
109
+ cause: null | undefined | Error;
110
+ /**
111
+ * Fixed type field in common with other Metro build errors.
112
+ */
113
+ readonly type: 'UnableToResolveError';
114
+ constructor(
115
+ originModulePath: string,
116
+ targetModuleName: string,
117
+ message: string,
118
+ options?: Readonly<{
119
+ dependency?: null | undefined | TransformResultDependency;
120
+ cause?: Error;
121
+ }>,
122
+ );
123
+ buildCodeFrameMessage(
124
+ dependency: null | undefined | TransformResultDependency,
125
+ ): null | undefined | string;
126
+ }