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,17 +1,24 @@
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.default = void 0;
7
+ var _chalk = _interopRequireDefault(require("chalk"));
8
+ var _util = _interopRequireDefault(require("util"));
9
+ function _interopRequireDefault(e) {
10
+ return e && e.__esModule ? e : { default: e };
11
+ }
5
12
  const groupStack = [];
6
13
  let collapsedGuardTimer;
7
- module.exports = (terminal, level, mode, ...data) => {
14
+ var _default = (terminal, level, ...data) => {
8
15
  const logFunction = console[level] && level !== "trace" ? level : "log";
9
16
  const color =
10
17
  level === "error"
11
- ? chalk.inverse.red
18
+ ? _chalk.default.inverse.red
12
19
  : level === "warn"
13
- ? chalk.inverse.yellow
14
- : chalk.inverse.white;
20
+ ? _chalk.default.inverse.yellow
21
+ : _chalk.default.inverse.white;
15
22
  if (level === "group") {
16
23
  groupStack.push(level);
17
24
  } else if (level === "groupCollapsed") {
@@ -20,8 +27,8 @@ module.exports = (terminal, level, mode, ...data) => {
20
27
  collapsedGuardTimer = setTimeout(() => {
21
28
  if (groupStack.includes("groupCollapsed")) {
22
29
  terminal.log(
23
- chalk.inverse.yellow.bold(" WARN "),
24
- "Expected `console.groupEnd` to be called after `console.groupCollapsed`."
30
+ _chalk.default.inverse.yellow.bold(" WARN "),
31
+ "Expected `console.groupEnd` to be called after `console.groupCollapsed`.",
25
32
  );
26
33
  groupStack.length = 0;
27
34
  }
@@ -39,12 +46,11 @@ module.exports = (terminal, level, mode, ...data) => {
39
46
  if (typeof lastItem === "string") {
40
47
  data[data.length - 1] = lastItem.trimEnd();
41
48
  }
42
- const modePrefix =
43
- !mode || mode == "BRIDGE" ? "" : `(${mode.toUpperCase()}) `;
44
49
  terminal.log(
45
- color.bold(` ${modePrefix}${logFunction.toUpperCase()} `) +
50
+ color.bold(` ${logFunction.toUpperCase()} `) +
46
51
  "".padEnd(groupStack.length * 2, " "),
47
- util.format(...data)
52
+ _util.default.format(...data),
48
53
  );
49
54
  }
50
55
  };
56
+ exports.default = _default;
@@ -10,22 +10,15 @@
10
10
 
11
11
  /* eslint-disable no-console */
12
12
 
13
- 'use strict';
14
-
15
13
  import type {Terminal} from 'metro-core';
16
14
 
17
- const chalk = require('chalk');
18
- const util = require('util');
15
+ import chalk from 'chalk';
16
+ import util from 'util';
19
17
 
20
18
  const groupStack = [];
21
19
  let collapsedGuardTimer;
22
20
 
23
- module.exports = (
24
- terminal: Terminal,
25
- level: string,
26
- mode: 'BRIDGE' | 'NOBRIDGE',
27
- ...data: Array<mixed>
28
- ) => {
21
+ export default (terminal: Terminal, level: string, ...data: Array<mixed>) => {
29
22
  // $FlowFixMe[invalid-computed-prop]
30
23
  const logFunction = console[level] && level !== 'trace' ? level : 'log';
31
24
  const color =
@@ -66,15 +59,13 @@ module.exports = (
66
59
  data[data.length - 1] = lastItem.trimEnd();
67
60
  }
68
61
 
69
- const modePrefix =
70
- !mode || mode == 'BRIDGE' ? '' : `(${mode.toUpperCase()}) `;
71
62
  terminal.log(
72
- color.bold(` ${modePrefix}${logFunction.toUpperCase()} `) +
63
+ color.bold(` ${logFunction.toUpperCase()} `) +
73
64
  ''.padEnd(groupStack.length * 2, ' '),
74
65
  // `util.format` actually accepts any arguments.
75
66
  // If the first argument is a string, it tries to format it.
76
67
  // Otherwise, it just concatenates all arguments.
77
- // $FlowIssue[incompatible-call] util.format expected the first argument to be a string
68
+ // $FlowFixMe[incompatible-type] util.format expected the first argument to be a string
78
69
  util.format(...data),
79
70
  );
80
71
  }
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.default = parseBundleOptionsFromBundleRequestUrl;
7
+ var _parsePlatformFilePath = _interopRequireDefault(
8
+ require("../node-haste/lib/parsePlatformFilePath"),
9
+ );
10
+ var _types = require("../shared/types");
11
+ var _parseCustomResolverOptions = _interopRequireDefault(
12
+ require("./parseCustomResolverOptions"),
13
+ );
14
+ var _parseCustomTransformOptions = _interopRequireDefault(
15
+ require("./parseCustomTransformOptions"),
16
+ );
17
+ var jscSafeUrl = _interopRequireWildcard(require("jsc-safe-url"));
18
+ var _path = _interopRequireDefault(require("path"));
19
+ function _getRequireWildcardCache(e) {
20
+ if ("function" != typeof WeakMap) return null;
21
+ var r = new WeakMap(),
22
+ t = new WeakMap();
23
+ return (_getRequireWildcardCache = function (e) {
24
+ return e ? t : r;
25
+ })(e);
26
+ }
27
+ function _interopRequireWildcard(e, r) {
28
+ if (!r && e && e.__esModule) return e;
29
+ if (null === e || ("object" != typeof e && "function" != typeof e))
30
+ return { default: e };
31
+ var t = _getRequireWildcardCache(r);
32
+ if (t && t.has(e)) return t.get(e);
33
+ var n = { __proto__: null },
34
+ a = Object.defineProperty && Object.getOwnPropertyDescriptor;
35
+ for (var u in e)
36
+ if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
37
+ var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
38
+ i && (i.get || i.set) ? Object.defineProperty(n, u, i) : (n[u] = e[u]);
39
+ }
40
+ return ((n.default = e), t && t.set(e, n), n);
41
+ }
42
+ function _interopRequireDefault(e) {
43
+ return e && e.__esModule ? e : { default: e };
44
+ }
45
+ const debug = require("debug")(
46
+ "Metro:Server:parseBundleOptionsFromBundleRequestUrl",
47
+ );
48
+ const TRUE_STRINGS = new Set(["true", "1"]);
49
+ const RESOLVE_BASE_URL = "resolve://";
50
+ const getBoolQueryParam = (searchParams, opt, defaultValue) =>
51
+ searchParams.has(opt)
52
+ ? TRUE_STRINGS.has(searchParams.get(opt) || "")
53
+ : defaultValue;
54
+ const getBundleType = (bundleType) =>
55
+ bundleType === "map" ? bundleType : "bundle";
56
+ const getTransformProfile = (transformProfile) =>
57
+ transformProfile === "hermes-stable" || transformProfile === "hermes-canary"
58
+ ? transformProfile
59
+ : "default";
60
+ function parseBundleOptionsFromBundleRequestUrl(
61
+ rawNonJscSafeUrlEncodedUrl,
62
+ platforms,
63
+ ) {
64
+ if (!URL.canParse(rawNonJscSafeUrlEncodedUrl, RESOLVE_BASE_URL)) {
65
+ throw new Error("Invalid URL", {
66
+ cause: rawNonJscSafeUrlEncodedUrl,
67
+ });
68
+ }
69
+ const {
70
+ protocol: _tempProtocol,
71
+ host,
72
+ searchParams,
73
+ pathname: requestPathname,
74
+ search,
75
+ hash,
76
+ } = new URL(rawNonJscSafeUrlEncodedUrl, RESOLVE_BASE_URL);
77
+ const isRelativeProtocol = rawNonJscSafeUrlEncodedUrl.startsWith("//");
78
+ const protocolPart = isRelativeProtocol ? "//" : _tempProtocol + "//";
79
+ const isNoProtocol = !isRelativeProtocol && protocolPart === RESOLVE_BASE_URL;
80
+ if (isNoProtocol) {
81
+ throw new Error(
82
+ 'Expecting the request url to have a valid protocol, e.g. "http://", "https://", or "//"',
83
+ {
84
+ cause: rawNonJscSafeUrlEncodedUrl,
85
+ },
86
+ );
87
+ }
88
+ const sourceUrl = jscSafeUrl.toJscSafeUrl(
89
+ protocolPart + host + requestPathname + search + hash,
90
+ );
91
+ const pathname = searchParams.get("bundleEntry") || requestPathname || "";
92
+ const platform =
93
+ searchParams.get("platform") ||
94
+ (0, _parsePlatformFilePath.default)(pathname, platforms).platform;
95
+ const bundleType = getBundleType(
96
+ _path.default.extname(pathname).substring(1),
97
+ );
98
+ const { pathname: sourceMapPathname } = new URL(
99
+ pathname.replace(/\.(bundle|delta)$/, ".map"),
100
+ RESOLVE_BASE_URL,
101
+ );
102
+ const sourceMapUrl = protocolPart + host + sourceMapPathname + search + hash;
103
+ const filePathPosix = pathname
104
+ .split("/")
105
+ .map((segment) => decodeURIComponent(segment))
106
+ .join("/")
107
+ .replace(/^(?:\.?\/)?/, "./")
108
+ .replace(/\.[^/.]+$/, "");
109
+ debug(
110
+ "Bundle options parsed from rawNonJscSafeUrlEncodedUrl: %s:\nsourceUrl: %s\nsourceMapUrl: %s\nentryFile: %s",
111
+ rawNonJscSafeUrlEncodedUrl,
112
+ sourceUrl,
113
+ sourceMapUrl,
114
+ filePathPosix,
115
+ );
116
+ return {
117
+ bundleType,
118
+ customResolverOptions: (0, _parseCustomResolverOptions.default)(
119
+ searchParams,
120
+ ),
121
+ customTransformOptions: (0, _parseCustomTransformOptions.default)(
122
+ searchParams,
123
+ ),
124
+ dev: getBoolQueryParam(searchParams, "dev", true),
125
+ entryFile: filePathPosix,
126
+ excludeSource: getBoolQueryParam(searchParams, "excludeSource", false),
127
+ inlineSourceMap: getBoolQueryParam(searchParams, "inlineSourceMap", false),
128
+ lazy: getBoolQueryParam(searchParams, "lazy", false),
129
+ minify: getBoolQueryParam(searchParams, "minify", false),
130
+ modulesOnly: getBoolQueryParam(searchParams, "modulesOnly", false),
131
+ onProgress: null,
132
+ platform,
133
+ runModule: getBoolQueryParam(searchParams, "runModule", true),
134
+ shallow: getBoolQueryParam(searchParams, "shallow", false),
135
+ sourceMapUrl,
136
+ sourcePaths:
137
+ _types.SourcePathsMode.cast(searchParams.get("sourcePaths")) ??
138
+ _types.SourcePathsMode.Absolute,
139
+ sourceUrl,
140
+ unstable_transformProfile: getTransformProfile(
141
+ searchParams.get("unstable_transformProfile"),
142
+ ),
143
+ };
144
+ }
@@ -0,0 +1,146 @@
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
+ * @flow strict-local
8
+ * @format
9
+ * @oncall react_native
10
+ */
11
+
12
+ import type {BundleOptions} from '../shared/types';
13
+ import type {TransformProfile} from 'metro-babel-transformer';
14
+
15
+ import parsePlatformFilePath from '../node-haste/lib/parsePlatformFilePath';
16
+ import {SourcePathsMode} from '../shared/types';
17
+ import parseCustomResolverOptions from './parseCustomResolverOptions';
18
+ import parseCustomTransformOptions from './parseCustomTransformOptions';
19
+ import * as jscSafeUrl from 'jsc-safe-url';
20
+ import path from 'path';
21
+
22
+ // eslint-disable-next-line import/no-commonjs
23
+ const debug = require('debug')(
24
+ 'Metro:Server:parseBundleOptionsFromBundleRequestUrl',
25
+ );
26
+
27
+ const TRUE_STRINGS = new Set<string>(['true', '1']);
28
+
29
+ // This is a bit weird but this is the recommended way of getting around "URL" demanding to have a valid protocol
30
+ // for when handling relative URLs: https://nodejs.org/docs/latest-v24.x/api/url.html#urlresolvefrom-to
31
+ const RESOLVE_BASE_URL = 'resolve://';
32
+
33
+ const getBoolQueryParam = (
34
+ searchParams: URLSearchParams,
35
+ opt: string,
36
+ defaultValue: boolean,
37
+ ) =>
38
+ searchParams.has(opt)
39
+ ? TRUE_STRINGS.has(searchParams.get(opt) || '')
40
+ : defaultValue;
41
+
42
+ const getBundleType = (bundleType: string): 'map' | 'bundle' =>
43
+ bundleType === 'map' ? bundleType : 'bundle';
44
+
45
+ const getTransformProfile = (transformProfile: ?string): TransformProfile =>
46
+ transformProfile === 'hermes-stable' || transformProfile === 'hermes-canary'
47
+ ? transformProfile
48
+ : 'default';
49
+
50
+ export default function parseBundleOptionsFromBundleRequestUrl(
51
+ rawNonJscSafeUrlEncodedUrl: string,
52
+ platforms: Set<string>,
53
+ ): {
54
+ ...BundleOptions,
55
+ // Retained for backwards compatibility, unused in Metro, to be removed.
56
+ bundleType: string,
57
+ } {
58
+ if (
59
+ !URL.canParse(rawNonJscSafeUrlEncodedUrl, RESOLVE_BASE_URL /* baseURL */)
60
+ ) {
61
+ throw new Error('Invalid URL', {cause: rawNonJscSafeUrlEncodedUrl});
62
+ }
63
+
64
+ const {
65
+ protocol: _tempProtocol,
66
+ host,
67
+ searchParams,
68
+ pathname: requestPathname,
69
+ search,
70
+ hash,
71
+ } = new URL(rawNonJscSafeUrlEncodedUrl, RESOLVE_BASE_URL /* baseURL */);
72
+
73
+ // e.g. "//localhost:8081/foo/bar.js?platform=ios"
74
+ const isRelativeProtocol = rawNonJscSafeUrlEncodedUrl.startsWith('//');
75
+
76
+ const protocolPart = isRelativeProtocol ? '//' : _tempProtocol + '//';
77
+
78
+ // e.g. "/foo/bar.js?platform=ios"
79
+ const isNoProtocol = !isRelativeProtocol && protocolPart === RESOLVE_BASE_URL;
80
+ if (isNoProtocol) {
81
+ throw new Error(
82
+ 'Expecting the request url to have a valid protocol, e.g. "http://", "https://", or "//"',
83
+ {cause: rawNonJscSafeUrlEncodedUrl},
84
+ );
85
+ }
86
+
87
+ const sourceUrl = jscSafeUrl.toJscSafeUrl(
88
+ protocolPart + host + requestPathname + search + hash,
89
+ );
90
+
91
+ const pathname = searchParams.get('bundleEntry') || requestPathname || '';
92
+
93
+ const platform =
94
+ searchParams.get('platform') ||
95
+ parsePlatformFilePath(pathname, platforms).platform;
96
+
97
+ const bundleType = getBundleType(path.extname(pathname).substring(1));
98
+
99
+ const {pathname: sourceMapPathname} = new URL(
100
+ pathname.replace(/\.(bundle|delta)$/, '.map'),
101
+ RESOLVE_BASE_URL /* baseURL */,
102
+ );
103
+ const sourceMapUrl = protocolPart + host + sourceMapPathname + search + hash;
104
+
105
+ const filePathPosix = pathname
106
+ // Using this Metro particular convention for decoding URL paths into file paths
107
+ .split('/')
108
+ .map(segment => decodeURIComponent(segment))
109
+ .join('/')
110
+ .replace(/^(?:\.?\/)?/, './')
111
+ .replace(/\.[^/.]+$/, '');
112
+
113
+ debug(
114
+ 'Bundle options parsed from rawNonJscSafeUrlEncodedUrl: %s:\nsourceUrl: %s\nsourceMapUrl: %s\nentryFile: %s',
115
+ rawNonJscSafeUrlEncodedUrl,
116
+ sourceUrl,
117
+ sourceMapUrl,
118
+ filePathPosix,
119
+ );
120
+
121
+ return {
122
+ bundleType,
123
+ customResolverOptions: parseCustomResolverOptions(searchParams),
124
+ customTransformOptions: parseCustomTransformOptions(searchParams),
125
+ dev: getBoolQueryParam(searchParams, 'dev', true),
126
+ // Absolute and relative paths are converted to paths relative to root
127
+ entryFile: filePathPosix,
128
+ excludeSource: getBoolQueryParam(searchParams, 'excludeSource', false),
129
+ inlineSourceMap: getBoolQueryParam(searchParams, 'inlineSourceMap', false),
130
+ lazy: getBoolQueryParam(searchParams, 'lazy', false),
131
+ minify: getBoolQueryParam(searchParams, 'minify', false),
132
+ modulesOnly: getBoolQueryParam(searchParams, 'modulesOnly', false),
133
+ onProgress: null,
134
+ platform,
135
+ runModule: getBoolQueryParam(searchParams, 'runModule', true),
136
+ shallow: getBoolQueryParam(searchParams, 'shallow', false),
137
+ sourceMapUrl,
138
+ sourcePaths:
139
+ SourcePathsMode.cast(searchParams.get('sourcePaths')) ??
140
+ SourcePathsMode.Absolute,
141
+ sourceUrl,
142
+ unstable_transformProfile: getTransformProfile(
143
+ searchParams.get('unstable_transformProfile'),
144
+ ),
145
+ };
146
+ }
@@ -1,14 +1,16 @@
1
1
  "use strict";
2
2
 
3
- const nullthrows = require("nullthrows");
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.default = parseCustomResolverOptions;
4
7
  const PREFIX = "resolver.";
5
- module.exports = function parseCustomResolverOptions(urlObj) {
8
+ function parseCustomResolverOptions(searchParams) {
6
9
  const customResolverOptions = Object.create(null);
7
- const query = nullthrows(urlObj.query);
8
- Object.keys(query).forEach((key) => {
10
+ searchParams.forEach((value, key) => {
9
11
  if (key.startsWith(PREFIX)) {
10
- customResolverOptions[key.substr(PREFIX.length)] = query[key];
12
+ customResolverOptions[key.substring(PREFIX.length)] = value;
11
13
  }
12
14
  });
13
15
  return customResolverOptions;
14
- };
16
+ }
@@ -9,30 +9,24 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- 'use strict';
13
-
14
12
  import type {CustomResolverOptions} from '../../../metro-resolver/src/types';
15
13
 
16
- const nullthrows = require('nullthrows');
17
-
18
14
  const PREFIX = 'resolver.';
19
15
 
20
- module.exports = function parseCustomResolverOptions(urlObj: {
21
- +query?: {[string]: string, ...},
22
- ...
23
- }): CustomResolverOptions {
16
+ export default function parseCustomResolverOptions(
17
+ searchParams: URLSearchParams,
18
+ ): CustomResolverOptions {
24
19
  const customResolverOptions: {
25
20
  __proto__: null,
26
21
  [string]: mixed,
27
22
  ...
28
23
  } = Object.create(null);
29
- const query = nullthrows(urlObj.query);
30
24
 
31
- Object.keys(query).forEach((key: string) => {
25
+ searchParams.forEach((value: string, key: string) => {
32
26
  if (key.startsWith(PREFIX)) {
33
- customResolverOptions[key.substr(PREFIX.length)] = query[key];
27
+ customResolverOptions[key.substring(PREFIX.length)] = value;
34
28
  }
35
29
  });
36
30
 
37
31
  return customResolverOptions;
38
- };
32
+ }
@@ -1,14 +1,16 @@
1
1
  "use strict";
2
2
 
3
- const nullthrows = require("nullthrows");
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.default = parseCustomTransformOptions;
4
7
  const PREFIX = "transform.";
5
- module.exports = function parseCustomTransformOptions(urlObj) {
8
+ function parseCustomTransformOptions(searchParams) {
6
9
  const customTransformOptions = Object.create(null);
7
- const query = nullthrows(urlObj.query);
8
- Object.keys(query).forEach((key) => {
10
+ searchParams.forEach((value, key) => {
9
11
  if (key.startsWith(PREFIX)) {
10
- customTransformOptions[key.substr(PREFIX.length)] = query[key];
12
+ customTransformOptions[key.substring(PREFIX.length)] = value;
11
13
  }
12
14
  });
13
15
  return customTransformOptions;
14
- };
16
+ }
@@ -9,27 +9,24 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- 'use strict';
13
-
14
12
  import type {CustomTransformOptions} from 'metro-transform-worker';
15
13
 
16
- const nullthrows = require('nullthrows');
17
-
18
14
  const PREFIX = 'transform.';
19
15
 
20
- module.exports = function parseCustomTransformOptions(urlObj: {
21
- +query?: {[string]: string, ...},
22
- ...
23
- }): CustomTransformOptions {
24
- const customTransformOptions = Object.create(null);
25
- const query = nullthrows(urlObj.query);
16
+ export default function parseCustomTransformOptions(
17
+ searchParams: URLSearchParams,
18
+ ): CustomTransformOptions {
19
+ const customTransformOptions: {
20
+ __proto__: null,
21
+ [string]: mixed,
22
+ ...
23
+ } = Object.create(null);
26
24
 
27
- Object.keys(query).forEach((key: string) => {
25
+ searchParams.forEach((value: string, key: string) => {
28
26
  if (key.startsWith(PREFIX)) {
29
- // $FlowFixMe[prop-missing]
30
- customTransformOptions[key.substr(PREFIX.length)] = query[key];
27
+ customTransformOptions[key.substring(PREFIX.length)] = value;
31
28
  }
32
29
  });
33
30
 
34
31
  return customTransformOptions;
35
- };
32
+ }
@@ -1,5 +1,9 @@
1
1
  "use strict";
2
2
 
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.default = parseJsonBody;
3
7
  const CONTENT_TYPE = "application/json";
4
8
  const SIZE_LIMIT = 100 * 1024 * 1024;
5
9
  function parseJsonBody(req, options = {}) {
@@ -32,4 +36,3 @@ function parseJsonBody(req, options = {}) {
32
36
  });
33
37
  });
34
38
  }
35
- module.exports = parseJsonBody;
@@ -17,7 +17,7 @@ const SIZE_LIMIT = 100 * 1024 * 1024; // 100MB
17
17
  /**
18
18
  * Attempt to parse a request body as JSON.
19
19
  */
20
- function parseJsonBody(
20
+ export default function parseJsonBody(
21
21
  req: IncomingMessage,
22
22
  options: {strict?: boolean} = {},
23
23
  ): Promise<$FlowFixMe> {
@@ -56,5 +56,3 @@ function parseJsonBody(
56
56
  });
57
57
  });
58
58
  }
59
-
60
- module.exports = parseJsonBody;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.normalizePathSeparatorsToPosix = void 0;
7
+ var path = _interopRequireWildcard(require("path"));
8
+ function _getRequireWildcardCache(e) {
9
+ if ("function" != typeof WeakMap) return null;
10
+ var r = new WeakMap(),
11
+ t = new WeakMap();
12
+ return (_getRequireWildcardCache = function (e) {
13
+ return e ? t : r;
14
+ })(e);
15
+ }
16
+ function _interopRequireWildcard(e, r) {
17
+ if (!r && e && e.__esModule) return e;
18
+ if (null === e || ("object" != typeof e && "function" != typeof e))
19
+ return { default: e };
20
+ var t = _getRequireWildcardCache(r);
21
+ if (t && t.has(e)) return t.get(e);
22
+ var n = { __proto__: null },
23
+ a = Object.defineProperty && Object.getOwnPropertyDescriptor;
24
+ for (var u in e)
25
+ if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
26
+ var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
27
+ i && (i.get || i.set) ? Object.defineProperty(n, u, i) : (n[u] = e[u]);
28
+ }
29
+ return ((n.default = e), t && t.set(e, n), n);
30
+ }
31
+ const normalizePathSeparatorsToPosix = (exports.normalizePathSeparatorsToPosix =
32
+ path.sep === "/"
33
+ ? (filePath) => filePath
34
+ : (filePath) => filePath.replaceAll("\\", "/"));
@@ -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
+ * @flow strict
9
+ */
10
+
11
+ import * as path from 'path';
12
+
13
+ export const normalizePathSeparatorsToPosix: string => string =
14
+ path.sep === '/'
15
+ ? filePath => filePath
16
+ : filePath => filePath.replaceAll('\\', '/');
@@ -1,6 +1,13 @@
1
1
  "use strict";
2
2
 
3
- const path = require("path");
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.default = relativizeSourceMapInline;
7
+ var _path = _interopRequireDefault(require("path"));
8
+ function _interopRequireDefault(e) {
9
+ return e && e.__esModule ? e : { default: e };
10
+ }
4
11
  function relativizeSourceMapInline(sourceMap, sourcesRoot) {
5
12
  if (sourceMap.mappings === undefined) {
6
13
  for (let i = 0; i < sourceMap.sections.length; i++) {
@@ -8,8 +15,10 @@ function relativizeSourceMapInline(sourceMap, sourcesRoot) {
8
15
  }
9
16
  } else {
10
17
  for (let i = 0; i < sourceMap.sources.length; i++) {
11
- sourceMap.sources[i] = path.relative(sourcesRoot, sourceMap.sources[i]);
18
+ sourceMap.sources[i] = _path.default.relative(
19
+ sourcesRoot,
20
+ sourceMap.sources[i],
21
+ );
12
22
  }
13
23
  }
14
24
  }
15
- module.exports = relativizeSourceMapInline;
@@ -9,13 +9,11 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- 'use strict';
13
-
14
12
  import type {MixedSourceMap} from 'metro-source-map';
15
13
 
16
- const path = require('path');
14
+ import path from 'path';
17
15
 
18
- function relativizeSourceMapInline(
16
+ export default function relativizeSourceMapInline(
19
17
  sourceMap: MixedSourceMap,
20
18
  sourcesRoot: string,
21
19
  ): void {
@@ -30,5 +28,3 @@ function relativizeSourceMapInline(
30
28
  }
31
29
  }
32
30
  }
33
-
34
- module.exports = relativizeSourceMapInline;