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,74 @@
1
1
  "use strict";
2
2
 
3
- const { isJsModule, wrapModule } = require("./helpers/js");
4
- const jscSafeUrl = require("jsc-safe-url");
5
- const { addParamsToDefineCall } = require("metro-transform-plugins");
6
- const path = require("path");
7
- const url = require("url");
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.default = hmrJSBundle;
7
+ var _js = require("./helpers/js");
8
+ var jscSafeUrl = _interopRequireWildcard(require("jsc-safe-url"));
9
+ var _metroTransformPlugins = require("metro-transform-plugins");
10
+ var _path = _interopRequireDefault(require("path"));
11
+ function _interopRequireDefault(e) {
12
+ return e && e.__esModule ? e : { default: e };
13
+ }
14
+ function _getRequireWildcardCache(e) {
15
+ if ("function" != typeof WeakMap) return null;
16
+ var r = new WeakMap(),
17
+ t = new WeakMap();
18
+ return (_getRequireWildcardCache = function (e) {
19
+ return e ? t : r;
20
+ })(e);
21
+ }
22
+ function _interopRequireWildcard(e, r) {
23
+ if (!r && e && e.__esModule) return e;
24
+ if (null === e || ("object" != typeof e && "function" != typeof e))
25
+ return { default: e };
26
+ var t = _getRequireWildcardCache(r);
27
+ if (t && t.has(e)) return t.get(e);
28
+ var n = { __proto__: null },
29
+ a = Object.defineProperty && Object.getOwnPropertyDescriptor;
30
+ for (var u in e)
31
+ if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
32
+ var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
33
+ i && (i.get || i.set) ? Object.defineProperty(n, u, i) : (n[u] = e[u]);
34
+ }
35
+ return ((n.default = e), t && t.set(e, n), n);
36
+ }
37
+ const debug = require("debug")("Metro:HMR");
8
38
  function generateModules(sourceModules, graph, options) {
9
39
  const modules = [];
10
40
  for (const module of sourceModules) {
11
- if (isJsModule(module)) {
12
- const getURL = (extension) => {
13
- const moduleUrl = url.parse(url.format(options.clientUrl), true);
14
- moduleUrl.search = "";
15
- moduleUrl.pathname = path.relative(
16
- options.serverRoot ?? options.projectRoot,
17
- path.join(
18
- path.dirname(module.path),
19
- path.basename(module.path, path.extname(module.path)) +
20
- "." +
21
- extension
41
+ if ((0, _js.isJsModule)(module)) {
42
+ const getPathname = (extension) => {
43
+ return _path.default
44
+ .relative(
45
+ options.serverRoot ?? options.projectRoot,
46
+ _path.default.join(
47
+ _path.default.dirname(module.path),
48
+ _path.default.basename(
49
+ module.path,
50
+ _path.default.extname(module.path),
51
+ ) +
52
+ "." +
53
+ extension,
54
+ ),
22
55
  )
23
- );
24
- delete moduleUrl.query.excludeSource;
25
- return url.format(moduleUrl);
56
+ .split(_path.default.sep)
57
+ .map((segment) => encodeURIComponent(segment))
58
+ .join("/");
26
59
  };
27
- const sourceMappingURL = getURL("map");
28
- const sourceURL = jscSafeUrl.toJscSafeUrl(getURL("bundle"));
60
+ const clientUrl = new URL(options.clientUrl);
61
+ clientUrl.searchParams.delete("excludeSource");
62
+ clientUrl.pathname = getPathname("map");
63
+ const sourceMappingURL = clientUrl.toString();
64
+ clientUrl.pathname = getPathname("bundle");
65
+ const sourceURL = jscSafeUrl.toJscSafeUrl(clientUrl.toString());
66
+ debug(
67
+ "got sourceMappingURL: %s\nand sourceURL: %s\nfor module: %s",
68
+ sourceMappingURL,
69
+ sourceURL,
70
+ module.path,
71
+ );
29
72
  const code =
30
73
  prepareModule(module, graph, options) +
31
74
  `\n//# sourceMappingURL=${sourceMappingURL}\n` +
@@ -40,9 +83,9 @@ function generateModules(sourceModules, graph, options) {
40
83
  return modules;
41
84
  }
42
85
  function prepareModule(module, graph, options) {
43
- const code = wrapModule(module, {
86
+ const code = (0, _js.wrapModule)(module, {
44
87
  ...options,
45
- sourceUrl: url.format(options.clientUrl),
88
+ sourceUrl: options.clientUrl.toString(),
46
89
  dev: true,
47
90
  });
48
91
  const inverseDependencies = getInverseDependencies(module.path, graph);
@@ -52,7 +95,10 @@ function prepareModule(module, graph, options) {
52
95
  path
53
96
  ].map(options.createModuleId);
54
97
  });
55
- return addParamsToDefineCall(code, inverseDependenciesById);
98
+ return (0, _metroTransformPlugins.addParamsToDefineCall)(
99
+ code,
100
+ inverseDependenciesById,
101
+ );
56
102
  }
57
103
  function getInverseDependencies(path, graph, inverseDependencies = {}) {
58
104
  if (path in inverseDependencies) {
@@ -76,4 +122,3 @@ function hmrJSBundle(delta, graph, options) {
76
122
  deleted: [...delta.deleted].map((path) => options.createModuleId(path)),
77
123
  };
78
124
  }
79
- module.exports = hmrJSBundle;
@@ -9,20 +9,19 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- 'use strict';
12
+ import type {DeltaResult, Module, ReadOnlyGraph} from '../types';
13
+ import type {HmrModule} from 'metro-runtime/src/modules/types';
13
14
 
14
- import type {EntryPointURL} from '../../HmrServer';
15
- import type {DeltaResult, Module, ReadOnlyGraph} from '../types.flow';
16
- import type {HmrModule} from 'metro-runtime/src/modules/types.flow';
15
+ import {isJsModule, wrapModule} from './helpers/js';
16
+ import * as jscSafeUrl from 'jsc-safe-url';
17
+ import {addParamsToDefineCall} from 'metro-transform-plugins';
18
+ import path from 'path';
17
19
 
18
- const {isJsModule, wrapModule} = require('./helpers/js');
19
- const jscSafeUrl = require('jsc-safe-url');
20
- const {addParamsToDefineCall} = require('metro-transform-plugins');
21
- const path = require('path');
22
- const url = require('url');
20
+ // eslint-disable-next-line import/no-commonjs
21
+ const debug = require('debug')('Metro:HMR');
23
22
 
24
23
  type Options = $ReadOnly<{
25
- clientUrl: EntryPointURL,
24
+ clientUrl: URL,
26
25
  createModuleId: string => number,
27
26
  includeAsyncPaths: boolean,
28
27
  projectRoot: string,
@@ -39,28 +38,41 @@ function generateModules(
39
38
 
40
39
  for (const module of sourceModules) {
41
40
  if (isJsModule(module)) {
42
- // Construct a bundle URL for this specific module only
43
- const getURL = (extension: 'bundle' | 'map') => {
44
- const moduleUrl = url.parse(url.format(options.clientUrl), true);
45
- // the legacy url object is parsed with both "search" and "query" fields.
46
- // for the "query" field to be used when formatting the object bach to string, the "search" field must be empty.
47
- // https://nodejs.org/api/url.html#urlformaturlobject:~:text=If%20the%20urlObject.search%20property%20is%20undefined
48
- moduleUrl.search = '';
49
- moduleUrl.pathname = path.relative(
50
- options.serverRoot ?? options.projectRoot,
51
- path.join(
52
- path.dirname(module.path),
53
- path.basename(module.path, path.extname(module.path)) +
54
- '.' +
55
- extension,
56
- ),
41
+ const getPathname = (extension: 'bundle' | 'map') => {
42
+ return (
43
+ path
44
+ .relative(
45
+ options.serverRoot ?? options.projectRoot,
46
+ path.join(
47
+ path.dirname(module.path),
48
+ path.basename(module.path, path.extname(module.path)) +
49
+ '.' +
50
+ extension,
51
+ ),
52
+ )
53
+ .split(path.sep)
54
+ // using this Metro particular convention for encoding file paths as URL paths.
55
+ .map(segment => encodeURIComponent(segment))
56
+ .join('/')
57
57
  );
58
- delete moduleUrl.query.excludeSource;
59
- return url.format(moduleUrl);
60
58
  };
61
59
 
62
- const sourceMappingURL = getURL('map');
63
- const sourceURL = jscSafeUrl.toJscSafeUrl(getURL('bundle'));
60
+ const clientUrl = new URL(options.clientUrl);
61
+ clientUrl.searchParams.delete('excludeSource');
62
+
63
+ clientUrl.pathname = getPathname('map');
64
+ const sourceMappingURL = clientUrl.toString();
65
+
66
+ clientUrl.pathname = getPathname('bundle');
67
+ const sourceURL = jscSafeUrl.toJscSafeUrl(clientUrl.toString());
68
+
69
+ debug(
70
+ 'got sourceMappingURL: %s\nand sourceURL: %s\nfor module: %s',
71
+ sourceMappingURL,
72
+ sourceURL,
73
+ module.path,
74
+ );
75
+
64
76
  const code =
65
77
  prepareModule(module, graph, options) +
66
78
  `\n//# sourceMappingURL=${sourceMappingURL}\n` +
@@ -84,7 +96,7 @@ function prepareModule(
84
96
  ): string {
85
97
  const code = wrapModule(module, {
86
98
  ...options,
87
- sourceUrl: url.format(options.clientUrl),
99
+ sourceUrl: options.clientUrl.toString(),
88
100
  dev: true,
89
101
  });
90
102
 
@@ -131,7 +143,7 @@ function getInverseDependencies(
131
143
  return inverseDependencies;
132
144
  }
133
145
 
134
- function hmrJSBundle(
146
+ export default function hmrJSBundle(
135
147
  delta: DeltaResult<>,
136
148
  graph: ReadOnlyGraph<>,
137
149
  options: Options,
@@ -148,5 +160,3 @@ function hmrJSBundle(
148
160
  ),
149
161
  };
150
162
  }
151
-
152
- module.exports = hmrJSBundle;
@@ -1,22 +1,29 @@
1
1
  "use strict";
2
2
 
3
- const getSourceMapInfo = require("./helpers/getSourceMapInfo");
4
- const { isJsModule } = require("./helpers/js");
5
- const {
6
- fromRawMappings,
7
- fromRawMappingsNonBlocking,
8
- } = require("metro-source-map");
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.sourceMapGenerator = sourceMapGenerator;
7
+ exports.sourceMapGeneratorNonBlocking = sourceMapGeneratorNonBlocking;
8
+ var _getSourceMapInfo = _interopRequireDefault(
9
+ require("./helpers/getSourceMapInfo"),
10
+ );
11
+ var _js = require("./helpers/js");
12
+ var _metroSourceMap = require("metro-source-map");
13
+ function _interopRequireDefault(e) {
14
+ return e && e.__esModule ? e : { default: e };
15
+ }
9
16
  function getSourceMapInfosImpl(isBlocking, onDone, modules, options) {
10
17
  const sourceMapInfos = [];
11
18
  const modulesToProcess = modules
12
- .filter(isJsModule)
19
+ .filter(_js.isJsModule)
13
20
  .filter(options.processModuleFilter);
14
21
  function processNextModule() {
15
22
  if (modulesToProcess.length === 0) {
16
23
  return true;
17
24
  }
18
25
  const mod = modulesToProcess.shift();
19
- const info = getSourceMapInfo(mod, {
26
+ const info = (0, _getSourceMapInfo.default)(mod, {
20
27
  excludeSource: options.excludeSource,
21
28
  shouldAddToIgnoreList: options.shouldAddToIgnoreList,
22
29
  getSourceUrl: options.getSourceUrl,
@@ -52,22 +59,18 @@ function sourceMapGenerator(modules, options) {
52
59
  sourceMapInfos = infos;
53
60
  },
54
61
  modules,
55
- options
62
+ options,
56
63
  );
57
64
  if (sourceMapInfos == null) {
58
65
  throw new Error(
59
- "Expected getSourceMapInfosImpl() to finish synchronously."
66
+ "Expected getSourceMapInfosImpl() to finish synchronously.",
60
67
  );
61
68
  }
62
- return fromRawMappings(sourceMapInfos);
69
+ return (0, _metroSourceMap.fromRawMappings)(sourceMapInfos);
63
70
  }
64
71
  async function sourceMapGeneratorNonBlocking(modules, options) {
65
72
  const sourceMapInfos = await new Promise((resolve) => {
66
73
  getSourceMapInfosImpl(false, resolve, modules, options);
67
74
  });
68
- return fromRawMappingsNonBlocking(sourceMapInfos);
75
+ return (0, _metroSourceMap.fromRawMappingsNonBlocking)(sourceMapInfos);
69
76
  }
70
- module.exports = {
71
- sourceMapGenerator,
72
- sourceMapGeneratorNonBlocking,
73
- };
@@ -9,16 +9,11 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- 'use strict';
12
+ import type {Module} from '../types';
13
13
 
14
- import type {Module} from '../types.flow';
15
-
16
- const getSourceMapInfo = require('./helpers/getSourceMapInfo');
17
- const {isJsModule} = require('./helpers/js');
18
- const {
19
- fromRawMappings,
20
- fromRawMappingsNonBlocking,
21
- } = require('metro-source-map');
14
+ import getSourceMapInfo from './helpers/getSourceMapInfo';
15
+ import {isJsModule} from './helpers/js';
16
+ import {fromRawMappings, fromRawMappingsNonBlocking} from 'metro-source-map';
22
17
 
23
18
  export type SourceMapGeneratorOptions = $ReadOnly<{
24
19
  excludeSource: boolean,
@@ -44,7 +39,7 @@ function getSourceMapInfosImpl(
44
39
  }
45
40
 
46
41
  const mod = modulesToProcess.shift();
47
- // $FlowFixMe[incompatible-call]
42
+ // $FlowFixMe[incompatible-type]
48
43
  const info = getSourceMapInfo(mod, {
49
44
  excludeSource: options.excludeSource,
50
45
  shouldAddToIgnoreList: options.shouldAddToIgnoreList,
@@ -113,7 +108,4 @@ async function sourceMapGeneratorNonBlocking(
113
108
  return fromRawMappingsNonBlocking(sourceMapInfos);
114
109
  }
115
110
 
116
- module.exports = {
117
- sourceMapGenerator,
118
- sourceMapGeneratorNonBlocking,
119
- };
111
+ export {sourceMapGenerator, sourceMapGeneratorNonBlocking};
@@ -1,22 +1,24 @@
1
1
  "use strict";
2
2
 
3
- const {
4
- sourceMapGenerator,
5
- sourceMapGeneratorNonBlocking,
6
- } = require("./sourceMapGenerator");
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.sourceMapObject = sourceMapObject;
7
+ exports.sourceMapObjectNonBlocking = sourceMapObjectNonBlocking;
8
+ var _sourceMapGenerator = require("./sourceMapGenerator");
7
9
  function sourceMapObject(modules, options) {
8
- const generator = sourceMapGenerator(modules, options);
10
+ const generator = (0, _sourceMapGenerator.sourceMapGenerator)(
11
+ modules,
12
+ options,
13
+ );
9
14
  return generator.toMap(undefined, {
10
15
  excludeSource: options.excludeSource,
11
16
  });
12
17
  }
13
18
  async function sourceMapObjectNonBlocking(modules, options) {
14
- const generator = await sourceMapGeneratorNonBlocking(modules, options);
19
+ const generator = await (0,
20
+ _sourceMapGenerator.sourceMapGeneratorNonBlocking)(modules, options);
15
21
  return generator.toMap(undefined, {
16
22
  excludeSource: options.excludeSource,
17
23
  });
18
24
  }
19
- module.exports = {
20
- sourceMapObject,
21
- sourceMapObjectNonBlocking,
22
- };
@@ -9,16 +9,14 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- 'use strict';
13
-
14
- import type {Module} from '../types.flow';
12
+ import type {Module} from '../types';
15
13
  import type {SourceMapGeneratorOptions} from './sourceMapGenerator';
16
14
  import type {MixedSourceMap} from 'metro-source-map';
17
15
 
18
- const {
16
+ import {
19
17
  sourceMapGenerator,
20
18
  sourceMapGeneratorNonBlocking,
21
- } = require('./sourceMapGenerator');
19
+ } from './sourceMapGenerator';
22
20
 
23
21
  function sourceMapObject(
24
22
  modules: $ReadOnlyArray<Module<>>,
@@ -40,7 +38,4 @@ async function sourceMapObjectNonBlocking(
40
38
  });
41
39
  }
42
40
 
43
- module.exports = {
44
- sourceMapObject,
45
- sourceMapObjectNonBlocking,
46
- };
41
+ export {sourceMapObject, sourceMapObjectNonBlocking};
@@ -1,21 +1,23 @@
1
1
  "use strict";
2
2
 
3
- const {
4
- sourceMapGenerator,
5
- sourceMapGeneratorNonBlocking,
6
- } = require("./sourceMapGenerator");
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.sourceMapString = sourceMapString;
7
+ exports.sourceMapStringNonBlocking = sourceMapStringNonBlocking;
8
+ var _sourceMapGenerator = require("./sourceMapGenerator");
7
9
  function sourceMapString(modules, options) {
8
- return sourceMapGenerator(modules, options).toString(undefined, {
9
- excludeSource: options.excludeSource,
10
- });
10
+ return (0, _sourceMapGenerator.sourceMapGenerator)(modules, options).toString(
11
+ undefined,
12
+ {
13
+ excludeSource: options.excludeSource,
14
+ },
15
+ );
11
16
  }
12
17
  async function sourceMapStringNonBlocking(modules, options) {
13
- const generator = await sourceMapGeneratorNonBlocking(modules, options);
18
+ const generator = await (0,
19
+ _sourceMapGenerator.sourceMapGeneratorNonBlocking)(modules, options);
14
20
  return generator.toString(undefined, {
15
21
  excludeSource: options.excludeSource,
16
22
  });
17
23
  }
18
- module.exports = {
19
- sourceMapString,
20
- sourceMapStringNonBlocking,
21
- };
@@ -9,15 +9,13 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- 'use strict';
13
-
14
- import type {Module} from '../types.flow';
12
+ import type {Module} from '../types';
15
13
  import type {SourceMapGeneratorOptions} from './sourceMapGenerator';
16
14
 
17
- const {
15
+ import {
18
16
  sourceMapGenerator,
19
17
  sourceMapGeneratorNonBlocking,
20
- } = require('./sourceMapGenerator');
18
+ } from './sourceMapGenerator';
21
19
 
22
20
  function sourceMapString(
23
21
  modules: $ReadOnlyArray<Module<>>,
@@ -38,7 +36,4 @@ async function sourceMapStringNonBlocking(
38
36
  });
39
37
  }
40
38
 
41
- module.exports = {
42
- sourceMapString,
43
- sourceMapStringNonBlocking,
44
- };
39
+ export {sourceMapString, sourceMapStringNonBlocking};
@@ -1,25 +1,28 @@
1
1
  "use strict";
2
2
 
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.default = void 0;
7
+ var _pathUtils = require("../lib/pathUtils");
8
+ var _getTransformCacheKey = _interopRequireDefault(
9
+ require("./getTransformCacheKey"),
10
+ );
11
+ var _WorkerFarm = _interopRequireDefault(require("./WorkerFarm"));
12
+ var _assert = _interopRequireDefault(require("assert"));
3
13
  var _crypto = _interopRequireDefault(require("crypto"));
14
+ var _fs = _interopRequireDefault(require("fs"));
15
+ var _metroCache = require("metro-cache");
16
+ var _path = _interopRequireDefault(require("path"));
4
17
  function _interopRequireDefault(e) {
5
- return e && e.__esModule
6
- ? e
7
- : {
8
- default: e,
9
- };
18
+ return e && e.__esModule ? e : { default: e };
10
19
  }
11
- const getTransformCacheKey = require("./getTransformCacheKey");
12
- const WorkerFarm = require("./WorkerFarm");
13
- const assert = require("assert");
14
20
  const debug = require("debug")("Metro:Transformer");
15
- const fs = require("fs");
16
- const { Cache, stableHash } = require("metro-cache");
17
- const path = require("path");
18
21
  class Transformer {
19
22
  constructor(config, opts) {
20
23
  this._config = config;
21
24
  this._config.watchFolders.forEach(verifyRootExists);
22
- this._cache = new Cache(config.cacheStores);
25
+ this._cache = new _metroCache.Cache(config.cacheStores);
23
26
  this._getSha1 = opts.getOrComputeSha1;
24
27
  const {
25
28
  getTransformOptions: _getTransformOptions,
@@ -31,15 +34,15 @@ class Transformer {
31
34
  transformerPath: this._config.transformerPath,
32
35
  transformerConfig,
33
36
  };
34
- this._workerFarm = new WorkerFarm(config, transformerOptions);
37
+ this._workerFarm = new _WorkerFarm.default(config, transformerOptions);
35
38
  const globalCacheKey = this._cache.isDisabled
36
39
  ? ""
37
- : getTransformCacheKey({
40
+ : (0, _getTransformCacheKey.default)({
38
41
  cacheVersion: this._config.cacheVersion,
39
42
  projectRoot: this._config.projectRoot,
40
43
  transformerConfig: transformerOptions,
41
44
  });
42
- const baseHashBuffer = stableHash([globalCacheKey]);
45
+ const baseHashBuffer = (0, _metroCache.stableHash)([globalCacheKey]);
43
46
  this._baseHash = baseHashBuffer.toString("binary");
44
47
  debug("Base hash: %s", baseHashBuffer.toString("hex"));
45
48
  }
@@ -49,14 +52,12 @@ class Transformer {
49
52
  customTransformOptions,
50
53
  dev,
51
54
  experimentalImportSupport,
52
- hot,
53
55
  inlinePlatform,
54
56
  inlineRequires,
55
57
  minify,
56
58
  nonInlinedRequires,
57
59
  platform,
58
60
  type,
59
- unstable_disableES6Transforms,
60
61
  unstable_transformProfile,
61
62
  unstable_memoizeInlineRequires,
62
63
  unstable_nonMemoizedInlineRequires,
@@ -65,25 +66,26 @@ class Transformer {
65
66
  for (const key in extra) {
66
67
  if (hasOwnProperty.call(extra, key)) {
67
68
  throw new Error(
68
- "Extra keys detected: " + Object.keys(extra).join(", ")
69
+ "Extra keys detected: " + Object.keys(extra).join(", "),
69
70
  );
70
71
  }
71
72
  }
72
- const localPath = path.relative(this._config.projectRoot, filePath);
73
- const partialKey = stableHash([
73
+ const localPath = _path.default.relative(
74
+ this._config.projectRoot,
75
+ filePath,
76
+ );
77
+ const partialKey = (0, _metroCache.stableHash)([
74
78
  this._baseHash,
75
- path.sep === "/" ? localPath : localPath.replaceAll(path.sep, "/"),
79
+ (0, _pathUtils.normalizePathSeparatorsToPosix)(localPath),
76
80
  customTransformOptions,
77
81
  dev,
78
82
  experimentalImportSupport,
79
- hot,
80
83
  inlinePlatform,
81
84
  inlineRequires,
82
85
  minify,
83
86
  nonInlinedRequires,
84
87
  platform,
85
88
  type,
86
- unstable_disableES6Transforms,
87
89
  unstable_memoizeInlineRequires,
88
90
  unstable_nonMemoizedInlineRequires,
89
91
  unstable_transformProfile,
@@ -122,7 +124,7 @@ class Transformer {
122
124
  : await this._workerFarm.transform(
123
125
  localPath,
124
126
  transformerOptions,
125
- content
127
+ content,
126
128
  );
127
129
  if (sha1 !== data.sha1) {
128
130
  fullKey = Buffer.concat([partialKey, Buffer.from(data.sha1, "hex")]);
@@ -140,7 +142,7 @@ class Transformer {
140
142
  if (fileBuffer) {
141
143
  return fileBuffer;
142
144
  }
143
- return fs.readFileSync(filePath);
145
+ return _fs.default.readFileSync(filePath);
144
146
  },
145
147
  };
146
148
  }
@@ -148,7 +150,10 @@ class Transformer {
148
150
  await this._workerFarm.kill();
149
151
  }
150
152
  }
153
+ exports.default = Transformer;
151
154
  function verifyRootExists(root) {
152
- assert(fs.statSync(root).isDirectory(), "Root has to be a valid directory");
155
+ (0, _assert.default)(
156
+ _fs.default.statSync(root).isDirectory(),
157
+ "Root has to be a valid directory",
158
+ );
153
159
  }
154
- module.exports = Transformer;