metro 0.83.0 → 0.83.2

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 (208) hide show
  1. package/package.json +16 -16
  2. package/src/Assets.js +68 -42
  3. package/src/Assets.js.flow +13 -24
  4. package/src/Bundler/util.js +40 -17
  5. package/src/Bundler/util.js.flow +6 -13
  6. package/src/Bundler.js +17 -6
  7. package/src/Bundler.js.flow +3 -7
  8. package/src/DeltaBundler/DeltaCalculator.js +15 -15
  9. package/src/DeltaBundler/DeltaCalculator.js.flow +4 -7
  10. package/src/DeltaBundler/Graph.js +45 -40
  11. package/src/DeltaBundler/Graph.js.flow +3 -4
  12. package/src/DeltaBundler/Serializers/baseJSBundle.js +24 -10
  13. package/src/DeltaBundler/Serializers/baseJSBundle.js.flow +6 -9
  14. package/src/DeltaBundler/Serializers/getAllFiles.js +9 -6
  15. package/src/DeltaBundler/Serializers/getAllFiles.js.flow +4 -8
  16. package/src/DeltaBundler/Serializers/getAssets.js +18 -11
  17. package/src/DeltaBundler/Serializers/getAssets.js.flow +5 -9
  18. package/src/DeltaBundler/Serializers/getExplodedSourceMap.d.ts +26 -0
  19. package/src/DeltaBundler/Serializers/getExplodedSourceMap.js +7 -6
  20. package/src/DeltaBundler/Serializers/getExplodedSourceMap.js.flow +3 -9
  21. package/src/DeltaBundler/Serializers/getRamBundleInfo.js +40 -23
  22. package/src/DeltaBundler/Serializers/getRamBundleInfo.js.flow +11 -18
  23. package/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.js +4 -1
  24. package/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.js.flow +1 -5
  25. package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js +7 -4
  26. package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js.flow +3 -7
  27. package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.js +4 -1
  28. package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.js.flow +2 -6
  29. package/src/DeltaBundler/Serializers/helpers/js.js +65 -31
  30. package/src/DeltaBundler/Serializers/helpers/js.js.flow +21 -21
  31. package/src/DeltaBundler/Serializers/helpers/processModules.js +8 -5
  32. package/src/DeltaBundler/Serializers/helpers/processModules.js.flow +3 -7
  33. package/src/DeltaBundler/Serializers/hmrJSBundle.js +70 -25
  34. package/src/DeltaBundler/Serializers/hmrJSBundle.js.flow +43 -33
  35. package/src/DeltaBundler/Serializers/sourceMapGenerator.js +19 -16
  36. package/src/DeltaBundler/Serializers/sourceMapGenerator.js.flow +6 -14
  37. package/src/DeltaBundler/Serializers/sourceMapObject.js +12 -10
  38. package/src/DeltaBundler/Serializers/sourceMapObject.js.flow +4 -9
  39. package/src/DeltaBundler/Serializers/sourceMapString.js +14 -12
  40. package/src/DeltaBundler/Serializers/sourceMapString.js.flow +4 -9
  41. package/src/DeltaBundler/Transformer.js +32 -27
  42. package/src/DeltaBundler/Transformer.js.flow +10 -17
  43. package/src/DeltaBundler/Worker.flow.js +25 -18
  44. package/src/DeltaBundler/Worker.flow.js.flow +12 -18
  45. package/src/DeltaBundler/Worker.js.flow +2 -0
  46. package/src/DeltaBundler/WorkerFarm.js +13 -11
  47. package/src/DeltaBundler/WorkerFarm.js.flow +7 -9
  48. package/src/DeltaBundler/buildSubgraph.js +13 -17
  49. package/src/DeltaBundler/buildSubgraph.js.flow +1 -1
  50. package/src/DeltaBundler/getTransformCacheKey.js +12 -6
  51. package/src/DeltaBundler/getTransformCacheKey.js.flow +5 -7
  52. package/src/DeltaBundler/mergeDeltas.js +4 -1
  53. package/src/DeltaBundler/mergeDeltas.js.flow +5 -6
  54. package/src/DeltaBundler/types.d.ts +4 -1
  55. package/src/DeltaBundler/{types.flow.js → types.js} +1 -5
  56. package/src/DeltaBundler/{types.flow.js.flow → types.js.flow} +5 -3
  57. package/src/DeltaBundler.js +15 -6
  58. package/src/DeltaBundler.js.flow +4 -8
  59. package/src/HmrServer.js +116 -68
  60. package/src/HmrServer.js.flow +41 -52
  61. package/src/IncrementalBundler/GraphNotFoundError.js +5 -1
  62. package/src/IncrementalBundler/GraphNotFoundError.js.flow +1 -5
  63. package/src/IncrementalBundler/ResourceNotFoundError.js +5 -1
  64. package/src/IncrementalBundler/ResourceNotFoundError.js.flow +1 -5
  65. package/src/IncrementalBundler/RevisionNotFoundError.js +5 -1
  66. package/src/IncrementalBundler/RevisionNotFoundError.js.flow +1 -5
  67. package/src/IncrementalBundler.js +71 -35
  68. package/src/IncrementalBundler.js.flow +12 -16
  69. package/src/ModuleGraph/test-helpers.js +19 -14
  70. package/src/ModuleGraph/worker/JsFileWrapping.js +22 -29
  71. package/src/ModuleGraph/worker/JsFileWrapping.js.flow +1 -10
  72. package/src/ModuleGraph/worker/collectDependencies.js +81 -52
  73. package/src/ModuleGraph/worker/collectDependencies.js.flow +15 -22
  74. package/src/ModuleGraph/worker/generateImportNames.js +12 -6
  75. package/src/ModuleGraph/worker/generateImportNames.js.flow +3 -7
  76. package/src/ModuleGraph/worker/importLocationsPlugin.js +5 -4
  77. package/src/ModuleGraph/worker/importLocationsPlugin.js.flow +2 -4
  78. package/src/Server/MultipartResponse.js +11 -4
  79. package/src/Server/MultipartResponse.js.flow +2 -5
  80. package/src/Server/symbolicate.d.ts +31 -0
  81. package/src/Server/symbolicate.js +15 -16
  82. package/src/Server/symbolicate.js.flow +6 -16
  83. package/src/Server.d.ts +0 -1
  84. package/src/Server.js +298 -191
  85. package/src/Server.js.flow +136 -99
  86. package/src/cli-utils.js +13 -4
  87. package/src/cli-utils.js.flow +3 -5
  88. package/src/cli.js.flow +2 -0
  89. package/src/commands/build.js +18 -15
  90. package/src/commands/build.js.flow +6 -6
  91. package/src/commands/dependencies.js +26 -16
  92. package/src/commands/dependencies.js.flow +7 -9
  93. package/src/commands/serve.js +16 -11
  94. package/src/commands/serve.js.flow +5 -6
  95. package/src/index.d.ts +26 -3
  96. package/src/index.flow.js +162 -72
  97. package/src/index.flow.js.flow +60 -47
  98. package/src/index.js.flow +2 -0
  99. package/src/integration_tests/basic_bundle/TestBundle.js.flow +2 -1
  100. package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-import.js +1 -5
  101. package/src/integration_tests/basic_bundle/build-errors/inline-requires-cannot-resolve-import.js +1 -5
  102. package/src/integration_tests/basic_bundle/import-export/index.js +5 -13
  103. package/src/integration_tests/basic_bundle/require-context/mode-eager.js +2 -2
  104. package/src/integration_tests/basic_bundle/require-context/mode-lazy-once.js +2 -2
  105. package/src/integration_tests/basic_bundle/require-context/mode-lazy.js +2 -2
  106. package/src/integration_tests/basic_bundle/require-context/mode-sync.js +1 -1
  107. package/src/integration_tests/basic_bundle/require-context/utils.js +1 -1
  108. package/src/integration_tests/execBundle.js +7 -4
  109. package/src/integration_tests/execBundle.js.flow +1 -3
  110. package/src/integration_tests/metro.config.js +3 -3
  111. package/src/lib/BatchProcessor.js +15 -5
  112. package/src/lib/BatchProcessor.js.flow +2 -6
  113. package/src/lib/CountingSet.js.flow +2 -2
  114. package/src/lib/JsonReporter.js +6 -2
  115. package/src/lib/JsonReporter.js.flow +1 -5
  116. package/src/lib/RamBundleParser.js +12 -3
  117. package/src/lib/RamBundleParser.js.flow +2 -6
  118. package/src/lib/TerminalReporter.js +95 -56
  119. package/src/lib/TerminalReporter.js.flow +9 -12
  120. package/src/lib/bundleToString.js +4 -1
  121. package/src/lib/bundleToString.js.flow +2 -9
  122. package/src/lib/contextModule.js +3 -7
  123. package/src/lib/contextModuleTemplates.js +9 -19
  124. package/src/lib/countLines.js +5 -1
  125. package/src/lib/countLines.js.flow +1 -3
  126. package/src/lib/createWebsocketServer.js +7 -7
  127. package/src/lib/createWebsocketServer.js.flow +4 -4
  128. package/src/lib/debounceAsyncQueue.js +4 -1
  129. package/src/lib/debounceAsyncQueue.js.flow +1 -5
  130. package/src/lib/formatBundlingError.js +32 -22
  131. package/src/lib/formatBundlingError.js.flow +18 -20
  132. package/src/lib/getAppendScripts.js +20 -20
  133. package/src/lib/getAppendScripts.js.flow +9 -13
  134. package/src/lib/getGraphId.js +12 -6
  135. package/src/lib/getGraphId.js.flow +4 -10
  136. package/src/lib/getPreludeCode.js +7 -10
  137. package/src/lib/getPreludeCode.js.flow +2 -6
  138. package/src/lib/getPrependedScripts.js +40 -16
  139. package/src/lib/getPrependedScripts.js.flow +8 -13
  140. package/src/lib/isResolvedDependency.js.flow +1 -1
  141. package/src/lib/logToConsole.js +18 -12
  142. package/src/lib/logToConsole.js.flow +5 -14
  143. package/src/lib/parseBundleOptionsFromBundleRequestUrl.js +144 -0
  144. package/src/lib/parseBundleOptionsFromBundleRequestUrl.js.flow +146 -0
  145. package/src/lib/parseCustomResolverOptions.js +8 -6
  146. package/src/lib/parseCustomResolverOptions.js.flow +6 -12
  147. package/src/lib/parseCustomTransformOptions.js +8 -6
  148. package/src/lib/parseCustomTransformOptions.js.flow +11 -14
  149. package/src/lib/parseJsonBody.js +4 -1
  150. package/src/lib/parseJsonBody.js.flow +1 -3
  151. package/src/lib/pathUtils.js +34 -0
  152. package/src/lib/pathUtils.js.flow +16 -0
  153. package/src/lib/relativizeSourceMap.js +12 -3
  154. package/src/lib/relativizeSourceMap.js.flow +2 -6
  155. package/src/lib/reporting.js +25 -19
  156. package/src/lib/reporting.js.flow +6 -16
  157. package/src/lib/splitBundleOptions.js +4 -2
  158. package/src/lib/splitBundleOptions.js.flow +4 -7
  159. package/src/lib/transformHelpers.js +19 -25
  160. package/src/lib/transformHelpers.js.flow +5 -15
  161. package/src/node-haste/DependencyGraph/ModuleResolution.js +75 -57
  162. package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +28 -44
  163. package/src/node-haste/DependencyGraph/createFileMap.js +15 -13
  164. package/src/node-haste/DependencyGraph/createFileMap.js.flow +2 -5
  165. package/src/node-haste/DependencyGraph.js +61 -45
  166. package/src/node-haste/DependencyGraph.js.flow +34 -31
  167. package/src/node-haste/Package.js +13 -6
  168. package/src/node-haste/Package.js.flow +3 -7
  169. package/src/node-haste/{ModuleCache.js → PackageCache.js} +11 -19
  170. package/src/node-haste/{ModuleCache.js.flow → PackageCache.js.flow} +2 -30
  171. package/src/node-haste/lib/AssetPaths.js +14 -8
  172. package/src/node-haste/lib/AssetPaths.js.flow +7 -8
  173. package/src/node-haste/lib/parsePlatformFilePath.js +10 -4
  174. package/src/node-haste/lib/parsePlatformFilePath.js.flow +2 -6
  175. package/src/shared/output/RamBundle/as-assets.js +42 -22
  176. package/src/shared/output/RamBundle/as-assets.js.flow +12 -15
  177. package/src/shared/output/RamBundle/as-indexed-file.js +33 -23
  178. package/src/shared/output/RamBundle/as-indexed-file.js.flow +10 -16
  179. package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js +11 -10
  180. package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js.flow +4 -6
  181. package/src/shared/output/RamBundle/magic-number.js +5 -1
  182. package/src/shared/output/RamBundle/magic-number.js.flow +1 -3
  183. package/src/shared/output/RamBundle/util.js +21 -18
  184. package/src/shared/output/RamBundle/util.js.flow +4 -6
  185. package/src/shared/output/RamBundle/write-sourcemap.js +9 -3
  186. package/src/shared/output/RamBundle/write-sourcemap.js.flow +2 -6
  187. package/src/shared/output/RamBundle.js +16 -9
  188. package/src/shared/output/RamBundle.js.flow +8 -12
  189. package/src/shared/output/bundle.flow.js +37 -13
  190. package/src/shared/output/bundle.flow.js.flow +24 -12
  191. package/src/shared/output/bundle.js.flow +2 -0
  192. package/src/shared/output/meta.js +16 -9
  193. package/src/shared/output/meta.js.flow +3 -5
  194. package/src/shared/output/unbundle.js +14 -1
  195. package/src/shared/output/unbundle.js.flow +1 -3
  196. package/src/shared/output/writeFile.js +11 -4
  197. package/src/shared/output/writeFile.js.flow +3 -5
  198. package/src/shared/types.d.ts +0 -1
  199. package/src/shared/{types.flow.js.flow → types.js.flow} +16 -17
  200. package/src/lib/createModuleIdFactory.js +0 -15
  201. package/src/lib/createModuleIdFactory.js.flow +0 -27
  202. package/src/lib/getMaxWorkers.js +0 -9
  203. package/src/lib/getMaxWorkers.js.flow +0 -22
  204. package/src/lib/parseOptionsFromUrl.js +0 -62
  205. package/src/lib/parseOptionsFromUrl.js.flow +0 -97
  206. package/src/node-haste/Module.js +0 -24
  207. package/src/node-haste/Module.js.flow +0 -41
  208. /package/src/shared/{types.flow.js → types.js} +0 -0
@@ -1,31 +1,37 @@
1
1
  "use strict";
2
2
 
3
- const chalk = require("chalk");
4
- const util = require("util");
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.logError = logError;
7
+ exports.logInfo = logInfo;
8
+ exports.logWarning = logWarning;
9
+ exports.nullReporter = void 0;
10
+ var _chalk = _interopRequireDefault(require("chalk"));
11
+ var _util = _interopRequireDefault(require("util"));
12
+ function _interopRequireDefault(e) {
13
+ return e && e.__esModule ? e : { default: e };
14
+ }
5
15
  function logWarning(terminal, format, ...args) {
6
- const str = util.format(format, ...args);
7
- terminal.log("%s %s", chalk.yellow.inverse.bold(" WARN "), str);
16
+ const str = _util.default.format(format, ...args);
17
+ terminal.log("%s %s", _chalk.default.yellow.inverse.bold(" WARN "), str);
8
18
  }
9
19
  function logError(terminal, format, ...args) {
10
20
  terminal.log(
11
21
  "%s %s",
12
- chalk.red.inverse.bold(" ERROR "),
13
- util.format(
14
- chalk.supportsColor ? format : util.stripVTControlCharacters(format),
15
- ...args
16
- )
22
+ _chalk.default.red.inverse.bold(" ERROR "),
23
+ _util.default.format(
24
+ _chalk.default.supportsColor
25
+ ? format
26
+ : _util.default.stripVTControlCharacters(format),
27
+ ...args,
28
+ ),
17
29
  );
18
30
  }
19
31
  function logInfo(terminal, format, ...args) {
20
- const str = util.format(format, ...args);
21
- terminal.log("%s %s", chalk.cyan.inverse.bold(" INFO "), str);
32
+ const str = _util.default.format(format, ...args);
33
+ terminal.log("%s %s", _chalk.default.cyan.inverse.bold(" INFO "), str);
22
34
  }
23
- const nullReporter = {
35
+ const nullReporter = (exports.nullReporter = {
24
36
  update() {},
25
- };
26
- module.exports = {
27
- logWarning,
28
- logError,
29
- logInfo,
30
- nullReporter,
31
- };
37
+ });
@@ -9,15 +9,13 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- 'use strict';
13
-
14
12
  import type {Terminal} from 'metro-core';
15
13
  import type {HealthCheckResult, WatcherStatus} from 'metro-file-map';
16
14
  import type {CustomResolverOptions} from 'metro-resolver';
17
15
  import type {CustomTransformOptions} from 'metro-transform-worker';
18
16
 
19
- const chalk = require('chalk');
20
- const util = require('util');
17
+ import chalk from 'chalk';
18
+ import util from 'util';
21
19
 
22
20
  export type BundleDetails = {
23
21
  bundleType: string,
@@ -129,7 +127,6 @@ export type ReportableEvent =
129
127
  | 'groupEnd'
130
128
  | 'debug',
131
129
  data: Array<mixed>,
132
- mode: 'BRIDGE' | 'NOBRIDGE',
133
130
  ...
134
131
  }
135
132
  | {
@@ -187,7 +184,7 @@ export type Reporter = interface {update(event: ReportableEvent): void};
187
184
  * calling this, add a new type of ReportableEvent instead, and implement a
188
185
  * proper handler in the reporter(s).
189
186
  */
190
- function logWarning(
187
+ export function logWarning(
191
188
  terminal: Terminal,
192
189
  format: string,
193
190
  ...args: Array<mixed>
@@ -199,7 +196,7 @@ function logWarning(
199
196
  /**
200
197
  * Similar to `logWarning`, but for messages that require the user to act.
201
198
  */
202
- function logError(
199
+ export function logError(
203
200
  terminal: Terminal,
204
201
  format: string,
205
202
  ...args: Array<mixed>
@@ -221,7 +218,7 @@ function logError(
221
218
  /**
222
219
  * Similar to `logWarning`, but for informational messages.
223
220
  */
224
- function logInfo(
221
+ export function logInfo(
225
222
  terminal: Terminal,
226
223
  format: string,
227
224
  ...args: Array<mixed>
@@ -234,11 +231,4 @@ function logInfo(
234
231
  * A reporter that does nothing. Errors and warnings will be swallowed, that
235
232
  * is generally not what you want.
236
233
  */
237
- const nullReporter = {update(): void {}};
238
-
239
- module.exports = {
240
- logWarning,
241
- logError,
242
- logInfo,
243
- nullReporter,
244
- };
234
+ export const nullReporter = {update(): void {}};
@@ -1,5 +1,9 @@
1
1
  "use strict";
2
2
 
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.default = splitBundleOptions;
3
7
  function splitBundleOptions(options) {
4
8
  return {
5
9
  entryFile: options.entryFile,
@@ -10,7 +14,6 @@ function splitBundleOptions(options) {
10
14
  transformOptions: {
11
15
  customTransformOptions: options.customTransformOptions,
12
16
  dev: options.dev,
13
- hot: options.hot,
14
17
  minify: options.minify,
15
18
  platform: options.platform,
16
19
  type: "module",
@@ -32,4 +35,3 @@ function splitBundleOptions(options) {
32
35
  onProgress: options.onProgress,
33
36
  };
34
37
  }
35
- module.exports = splitBundleOptions;
@@ -9,14 +9,14 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- 'use strict';
13
-
14
- import type {BundleOptions, SplitBundleOptions} from '../shared/types.flow';
12
+ import type {BundleOptions, SplitBundleOptions} from '../shared/types';
15
13
 
16
14
  /**
17
15
  * Splits a BundleOptions object into smaller, more manageable parts.
18
16
  */
19
- function splitBundleOptions(options: BundleOptions): SplitBundleOptions {
17
+ export default function splitBundleOptions(
18
+ options: BundleOptions,
19
+ ): SplitBundleOptions {
20
20
  return {
21
21
  entryFile: options.entryFile,
22
22
  resolverOptions: {
@@ -26,7 +26,6 @@ function splitBundleOptions(options: BundleOptions): SplitBundleOptions {
26
26
  transformOptions: {
27
27
  customTransformOptions: options.customTransformOptions,
28
28
  dev: options.dev,
29
- hot: options.hot,
30
29
  minify: options.minify,
31
30
  platform: options.platform,
32
31
  type: 'module',
@@ -48,5 +47,3 @@ function splitBundleOptions(options: BundleOptions): SplitBundleOptions {
48
47
  onProgress: options.onProgress,
49
48
  };
50
49
  }
51
-
52
- module.exports = splitBundleOptions;
@@ -1,15 +1,16 @@
1
1
  "use strict";
2
2
 
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.getResolveDependencyFn = getResolveDependencyFn;
7
+ exports.getTransformFn = getTransformFn;
3
8
  var _contextModuleTemplates = require("./contextModuleTemplates");
4
9
  var _isAssetFile = _interopRequireDefault(
5
- require("metro-resolver/private/utils/isAssetFile")
10
+ require("metro-resolver/private/utils/isAssetFile"),
6
11
  );
7
12
  function _interopRequireDefault(e) {
8
- return e && e.__esModule
9
- ? e
10
- : {
11
- default: e,
12
- };
13
+ return e && e.__esModule ? e : { default: e };
13
14
  }
14
15
  const baseIgnoredInlineRequires = [
15
16
  "React",
@@ -25,12 +26,11 @@ async function calcTransformerOptions(
25
26
  deltaBundler,
26
27
  config,
27
28
  options,
28
- resolverOptions
29
+ resolverOptions,
29
30
  ) {
30
31
  const baseOptions = {
31
32
  customTransformOptions: options.customTransformOptions,
32
33
  dev: options.dev,
33
- hot: options.hot,
34
34
  inlineRequires: false,
35
35
  inlinePlatform: true,
36
36
  minify: options.minify,
@@ -48,7 +48,7 @@ async function calcTransformerOptions(
48
48
  resolve: await getResolveDependencyFn(
49
49
  bundler,
50
50
  options.platform,
51
- resolverOptions
51
+ resolverOptions,
52
52
  ),
53
53
  transform: await getTransformFn(
54
54
  [path],
@@ -59,7 +59,7 @@ async function calcTransformerOptions(
59
59
  ...options,
60
60
  minify: false,
61
61
  },
62
- resolverOptions
62
+ resolverOptions,
63
63
  ),
64
64
  transformOptions: options,
65
65
  onProgress: null,
@@ -76,17 +76,15 @@ async function calcTransformerOptions(
76
76
  entryFiles,
77
77
  {
78
78
  dev: options.dev,
79
- hot: options.hot,
79
+ hot: true,
80
80
  platform: options.platform,
81
81
  },
82
- getDependencies
82
+ getDependencies,
83
83
  );
84
84
  return {
85
85
  ...baseOptions,
86
86
  inlineRequires: transform?.inlineRequires || false,
87
87
  experimentalImportSupport: transform?.experimentalImportSupport || false,
88
- unstable_disableES6Transforms:
89
- transform?.unstable_disableES6Transforms || false,
90
88
  unstable_memoizeInlineRequires:
91
89
  transform?.unstable_memoizeInlineRequires || false,
92
90
  unstable_nonMemoizedInlineRequires:
@@ -108,7 +106,7 @@ async function getTransformFn(
108
106
  deltaBundler,
109
107
  config,
110
108
  options,
111
- resolverOptions
109
+ resolverOptions,
112
110
  ) {
113
111
  const { inlineRequires, ...transformOptions } = await calcTransformerOptions(
114
112
  entryFiles,
@@ -116,7 +114,7 @@ async function getTransformFn(
116
114
  deltaBundler,
117
115
  config,
118
116
  options,
119
- resolverOptions
117
+ resolverOptions,
120
118
  );
121
119
  const assetExts = new Set(config.resolver.assetExts);
122
120
  return async (modulePath, requireContext) => {
@@ -127,12 +125,12 @@ async function getTransformFn(
127
125
  graph.matchFilesWithContext(requireContext.from, {
128
126
  filter: requireContext.filter,
129
127
  recursive: requireContext.recursive,
130
- })
128
+ }),
131
129
  );
132
130
  const template = (0, _contextModuleTemplates.getContextModuleTemplate)(
133
131
  requireContext.mode,
134
132
  requireContext.from,
135
- files
133
+ files,
136
134
  );
137
135
  templateBuffer = Buffer.from(template);
138
136
  }
@@ -143,10 +141,10 @@ async function getTransformFn(
143
141
  type: getType(transformOptions.type, modulePath, assetExts),
144
142
  inlineRequires: removeInlineRequiresBlockListFromOptions(
145
143
  modulePath,
146
- inlineRequires
144
+ inlineRequires,
147
145
  ),
148
146
  },
149
- templateBuffer
147
+ templateBuffer,
150
148
  );
151
149
  };
152
150
  }
@@ -166,10 +164,6 @@ async function getResolveDependencyFn(bundler, platform, resolverOptions) {
166
164
  from,
167
165
  dependency,
168
166
  platform ?? null,
169
- resolverOptions
167
+ resolverOptions,
170
168
  );
171
169
  }
172
- module.exports = {
173
- getTransformFn,
174
- getResolveDependencyFn,
175
- };
@@ -9,17 +9,15 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- 'use strict';
13
-
14
12
  import type Bundler from '../Bundler';
15
13
  import type DeltaBundler, {TransformFn} from '../DeltaBundler';
16
14
  import type {
17
15
  BundlerResolution,
18
16
  TransformInputOptions,
19
17
  TransformResultDependency,
20
- } from '../DeltaBundler/types.flow';
18
+ } from '../DeltaBundler/types';
21
19
  import type {TransformOptions} from '../DeltaBundler/Worker';
22
- import type {ResolverInputOptions} from '../shared/types.flow';
20
+ import type {ResolverInputOptions} from '../shared/types';
23
21
  import type {RequireContext} from './contextModule';
24
22
  import type {ConfigT} from 'metro-config';
25
23
  import type {Type} from 'metro-transform-worker';
@@ -56,7 +54,6 @@ async function calcTransformerOptions(
56
54
  const baseOptions = {
57
55
  customTransformOptions: options.customTransformOptions,
58
56
  dev: options.dev,
59
- hot: options.hot,
60
57
  inlineRequires: false,
61
58
  inlinePlatform: true,
62
59
  minify: options.minify,
@@ -107,7 +104,7 @@ async function calcTransformerOptions(
107
104
 
108
105
  const {transform} = await config.transformer.getTransformOptions(
109
106
  entryFiles,
110
- {dev: options.dev, hot: options.hot, platform: options.platform},
107
+ {dev: options.dev, hot: true, platform: options.platform},
111
108
  getDependencies,
112
109
  );
113
110
 
@@ -115,8 +112,6 @@ async function calcTransformerOptions(
115
112
  ...baseOptions,
116
113
  inlineRequires: transform?.inlineRequires || false,
117
114
  experimentalImportSupport: transform?.experimentalImportSupport || false,
118
- unstable_disableES6Transforms:
119
- transform?.unstable_disableES6Transforms || false,
120
115
  unstable_memoizeInlineRequires:
121
116
  transform?.unstable_memoizeInlineRequires || false,
122
117
  unstable_nonMemoizedInlineRequires:
@@ -138,7 +133,7 @@ function removeInlineRequiresBlockListFromOptions(
138
133
  return inlineRequires;
139
134
  }
140
135
 
141
- async function getTransformFn(
136
+ export async function getTransformFn(
142
137
  entryFiles: $ReadOnlyArray<string>,
143
138
  bundler: Bundler,
144
139
  deltaBundler: DeltaBundler<>,
@@ -213,7 +208,7 @@ function getType(
213
208
  return 'module';
214
209
  }
215
210
 
216
- async function getResolveDependencyFn(
211
+ export async function getResolveDependencyFn(
217
212
  bundler: Bundler,
218
213
  platform: ?string,
219
214
  resolverOptions: ResolverInputOptions,
@@ -230,8 +225,3 @@ async function getResolveDependencyFn(
230
225
  resolverOptions,
231
226
  );
232
227
  }
233
-
234
- module.exports = {
235
- getTransformFn,
236
- getResolveDependencyFn,
237
- };
@@ -1,33 +1,55 @@
1
1
  "use strict";
2
2
 
3
- const { codeFrameColumns } = require("@babel/code-frame");
4
- const fs = require("fs");
5
- const invariant = require("invariant");
6
- const Resolver = require("metro-resolver");
7
- const createDefaultContext = require("metro-resolver/private/createDefaultContext");
8
- const path = require("path");
9
- const util = require("util");
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.UnableToResolveError = exports.ModuleResolver = void 0;
7
+ var _codeFrame = require("@babel/code-frame");
8
+ var _fs = _interopRequireDefault(require("fs"));
9
+ var _invariant = _interopRequireDefault(require("invariant"));
10
+ var Resolver = _interopRequireWildcard(require("metro-resolver"));
11
+ var _createDefaultContext = _interopRequireDefault(
12
+ require("metro-resolver/private/createDefaultContext"),
13
+ );
14
+ var _path = _interopRequireDefault(require("path"));
15
+ var _util = _interopRequireDefault(require("util"));
16
+ function _getRequireWildcardCache(e) {
17
+ if ("function" != typeof WeakMap) return null;
18
+ var r = new WeakMap(),
19
+ t = new WeakMap();
20
+ return (_getRequireWildcardCache = function (e) {
21
+ return e ? t : r;
22
+ })(e);
23
+ }
24
+ function _interopRequireWildcard(e, r) {
25
+ if (!r && e && e.__esModule) return e;
26
+ if (null === e || ("object" != typeof e && "function" != typeof e))
27
+ return { default: e };
28
+ var t = _getRequireWildcardCache(r);
29
+ if (t && t.has(e)) return t.get(e);
30
+ var n = { __proto__: null },
31
+ a = Object.defineProperty && Object.getOwnPropertyDescriptor;
32
+ for (var u in e)
33
+ if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
34
+ var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
35
+ i && (i.get || i.set) ? Object.defineProperty(n, u, i) : (n[u] = e[u]);
36
+ }
37
+ return ((n.default = e), t && t.set(e, n), n);
38
+ }
39
+ function _interopRequireDefault(e) {
40
+ return e && e.__esModule ? e : { default: e };
41
+ }
10
42
  class ModuleResolver {
11
43
  constructor(options) {
12
44
  this._options = options;
13
- const { projectRoot, moduleCache } = this._options;
14
- this._projectRootFakeModule = {
15
- path: path.join(projectRoot, "_"),
16
- getPackage: () =>
17
- moduleCache.getPackageOf(this._projectRootFakeModule.path)?.pkg,
18
- isHaste() {
19
- throw new Error("not implemented");
20
- },
21
- getName() {
22
- throw new Error("not implemented");
23
- },
24
- };
45
+ const { projectRoot } = this._options;
46
+ this._projectRootFakeModulePath = _path.default.join(projectRoot, "_");
25
47
  }
26
48
  _getEmptyModule() {
27
49
  let emptyModule = this._cachedEmptyModule;
28
50
  if (!emptyModule) {
29
51
  emptyModule = this.resolveDependency(
30
- this._projectRootFakeModule,
52
+ this._projectRootFakeModulePath,
31
53
  {
32
54
  name: this._options.emptyModulePath,
33
55
  data: {
@@ -41,18 +63,18 @@ class ModuleResolver {
41
63
  null,
42
64
  {
43
65
  dev: false,
44
- }
66
+ },
45
67
  );
46
68
  this._cachedEmptyModule = emptyModule;
47
69
  }
48
70
  return emptyModule;
49
71
  }
50
72
  resolveDependency(
51
- fromModule,
73
+ originModulePath,
52
74
  dependency,
53
75
  allowHaste,
54
76
  platform,
55
- resolverOptions
77
+ resolverOptions,
56
78
  ) {
57
79
  const {
58
80
  assetExts,
@@ -72,7 +94,7 @@ class ModuleResolver {
72
94
  } = this._options;
73
95
  try {
74
96
  const result = Resolver.resolve(
75
- createDefaultContext(
97
+ (0, _createDefaultContext.default)(
76
98
  {
77
99
  allowHaste,
78
100
  assetExts,
@@ -93,7 +115,7 @@ class ModuleResolver {
93
115
  unstable_enablePackageExports,
94
116
  unstable_logWarning: this._logWarning,
95
117
  customResolverOptions: resolverOptions.customResolverOptions ?? {},
96
- originModulePath: fromModule.path,
118
+ originModulePath,
97
119
  resolveHasteModule: (name) =>
98
120
  this._options.getHasteModulePath(name, platform),
99
121
  resolveHastePackage: (name) =>
@@ -102,64 +124,62 @@ class ModuleResolver {
102
124
  getPackageForModule: (absoluteModulePath) =>
103
125
  this._getPackageForModule(absoluteModulePath),
104
126
  },
105
- dependency
127
+ dependency,
106
128
  ),
107
129
  dependency.name,
108
- platform
130
+ platform,
109
131
  );
110
132
  return this._getFileResolvedModule(result);
111
133
  } catch (error) {
112
134
  if (error instanceof Resolver.FailedToResolvePathError) {
113
135
  const { candidates } = error;
114
136
  throw new UnableToResolveError(
115
- fromModule.path,
137
+ originModulePath,
116
138
  dependency.name,
117
139
  "\n\nNone of these files exist:\n" +
118
140
  [candidates.file, candidates.dir]
119
141
  .filter(Boolean)
120
142
  .map(
121
143
  (candidates) =>
122
- ` * ${Resolver.formatFileCandidates(
123
- this._removeRoot(candidates)
124
- )}`
144
+ ` * ${Resolver.formatFileCandidates(this._removeRoot(candidates))}`,
125
145
  )
126
146
  .join("\n"),
127
147
  {
128
148
  cause: error,
129
149
  dependency,
130
- }
150
+ },
131
151
  );
132
152
  } else if (error instanceof Resolver.FailedToResolveUnsupportedError) {
133
153
  throw new UnableToResolveError(
134
- fromModule.path,
154
+ originModulePath,
135
155
  dependency.name,
136
156
  error.message,
137
157
  {
138
158
  cause: error,
139
159
  dependency,
140
- }
160
+ },
141
161
  );
142
162
  } else if (error instanceof Resolver.FailedToResolveNameError) {
143
163
  const dirPaths = error.dirPaths;
144
164
  const extraPaths = error.extraPaths;
145
165
  const displayDirPaths = dirPaths
146
166
  .filter((dirPath) => this._options.dirExists(dirPath))
147
- .map((dirPath) => path.relative(this._options.projectRoot, dirPath))
167
+ .map((dirPath) =>
168
+ _path.default.relative(this._options.projectRoot, dirPath),
169
+ )
148
170
  .concat(extraPaths);
149
171
  const hint = displayDirPaths.length ? " or in these directories:" : "";
150
172
  throw new UnableToResolveError(
151
- fromModule.path,
173
+ originModulePath,
152
174
  dependency.name,
153
175
  [
154
- `${dependency.name} could not be found within the project${
155
- hint || "."
156
- }`,
176
+ `${dependency.name} could not be found within the project${hint || "."}`,
157
177
  ...displayDirPaths.map((dirPath) => ` ${dirPath}`),
158
178
  ].join("\n"),
159
179
  {
160
180
  cause: error,
161
181
  dependency,
162
- }
182
+ },
163
183
  );
164
184
  }
165
185
  throw error;
@@ -167,18 +187,18 @@ class ModuleResolver {
167
187
  }
168
188
  _getPackage = (packageJsonPath) => {
169
189
  try {
170
- return this._options.moduleCache.getPackage(packageJsonPath).read();
190
+ return this._options.packageCache.getPackage(packageJsonPath).read();
171
191
  } catch (e) {}
172
192
  return null;
173
193
  };
174
194
  _getPackageForModule = (absolutePath) => {
175
195
  let result;
176
196
  try {
177
- result = this._options.moduleCache.getPackageOf(absolutePath);
197
+ result = this._options.packageCache.getPackageOf(absolutePath);
178
198
  } catch (e) {}
179
199
  return result != null
180
200
  ? {
181
- rootPath: path.dirname(result.pkg.path),
201
+ rootPath: _path.default.dirname(result.pkg.path),
182
202
  packageJson: result.pkg.read(),
183
203
  packageRelativePath: result.packageRelativePath,
184
204
  }
@@ -190,7 +210,7 @@ class ModuleResolver {
190
210
  return resolution;
191
211
  case "assetFiles":
192
212
  const arbitrary = getArrayLowestItem(resolution.filePaths);
193
- invariant(arbitrary != null, "invalid asset resolution");
213
+ (0, _invariant.default)(arbitrary != null, "invalid asset resolution");
194
214
  return {
195
215
  type: "sourceFile",
196
216
  filePath: arbitrary,
@@ -210,14 +230,15 @@ class ModuleResolver {
210
230
  };
211
231
  _removeRoot(candidates) {
212
232
  if (candidates.filePathPrefix) {
213
- candidates.filePathPrefix = path.relative(
233
+ candidates.filePathPrefix = _path.default.relative(
214
234
  this._options.projectRoot,
215
- candidates.filePathPrefix
235
+ candidates.filePathPrefix,
216
236
  );
217
237
  }
218
238
  return candidates;
219
239
  }
220
240
  }
241
+ exports.ModuleResolver = ModuleResolver;
221
242
  function getArrayLowestItem(a) {
222
243
  if (a.length === 0) {
223
244
  return undefined;
@@ -238,18 +259,18 @@ class UnableToResolveError extends Error {
238
259
  this.targetModuleName = targetModuleName;
239
260
  const codeFrameMessage = this.buildCodeFrameMessage(options?.dependency);
240
261
  this.message =
241
- util.format(
262
+ _util.default.format(
242
263
  "Unable to resolve module %s from %s: %s",
243
264
  targetModuleName,
244
265
  originModulePath,
245
- message
266
+ message,
246
267
  ) + (codeFrameMessage ? "\n" + codeFrameMessage : "");
247
268
  this.cause = options?.cause;
248
269
  }
249
270
  buildCodeFrameMessage(dependency) {
250
271
  let file;
251
272
  try {
252
- file = fs.readFileSync(this.originModulePath, "utf8");
273
+ file = _fs.default.readFileSync(this.originModulePath, "utf8");
253
274
  } catch (error) {
254
275
  if (error.code === "ENOENT" || error.code === "EISDIR") {
255
276
  return null;
@@ -260,18 +281,19 @@ class UnableToResolveError extends Error {
260
281
  ? refineDependencyLocation(
261
282
  dependency.data.locs[0],
262
283
  file,
263
- this.targetModuleName
284
+ this.targetModuleName,
264
285
  )
265
286
  : guessDependencyLocation(file, this.targetModuleName);
266
- return codeFrameColumns(
267
- fs.readFileSync(this.originModulePath, "utf8"),
287
+ return (0, _codeFrame.codeFrameColumns)(
288
+ _fs.default.readFileSync(this.originModulePath, "utf8"),
268
289
  location,
269
290
  {
270
291
  forceColor: process.env.NODE_ENV !== "test",
271
- }
292
+ },
272
293
  );
273
294
  }
274
295
  }
296
+ exports.UnableToResolveError = UnableToResolveError;
275
297
  function refineDependencyLocation(loc, fileContents, targetSpecifier) {
276
298
  const lines = fileContents.split("\n");
277
299
  for (let line = loc.end.line - 1; line >= loc.start.line - 1; line--) {
@@ -339,7 +361,3 @@ function guessDependencyLocation(fileContents, targetSpecifier) {
339
361
  function isQuote(str) {
340
362
  return str === '"' || str === "'" || str === "`";
341
363
  }
342
- module.exports = {
343
- ModuleResolver,
344
- UnableToResolveError,
345
- };