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,28 +1,35 @@
1
1
  "use strict";
2
2
 
3
- const crypto = require("crypto");
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.default = _default;
7
+ var _crypto = _interopRequireDefault(require("crypto"));
8
+ function _interopRequireDefault(e) {
9
+ return e && e.__esModule ? e : { default: e };
10
+ }
4
11
  const isUTF8 = (encoding) => /^utf-?8$/i.test(encoding);
5
12
  const constantFor = (encoding) =>
6
13
  /^ascii$/i.test(encoding)
7
14
  ? 1
8
15
  : isUTF8(encoding)
9
- ? 2
10
- : /^(?:utf-?16(?:le)?|ucs-?2)$/.test(encoding)
11
- ? 3
12
- : 0;
13
- module.exports = function (code, encoding = "utf8") {
16
+ ? 2
17
+ : /^(?:utf-?16(?:le)?|ucs-?2)$/.test(encoding)
18
+ ? 3
19
+ : 0;
20
+ function _default(code, encoding = "utf8") {
14
21
  const buffer = asBuffer(code, encoding);
15
- const hash = crypto.createHash("sha1");
22
+ const hash = _crypto.default.createHash("sha1");
16
23
  hash.update(buffer);
17
24
  const digest = hash.digest("buffer");
18
25
  const signature = Buffer.alloc(digest.length + 1);
19
26
  digest.copy(signature);
20
27
  signature.writeUInt8(
21
28
  constantFor(tryAsciiPromotion(buffer, encoding)),
22
- signature.length - 1
29
+ signature.length - 1,
23
30
  );
24
31
  return signature;
25
- };
32
+ }
26
33
  function tryAsciiPromotion(buffer, encoding) {
27
34
  if (!isUTF8(encoding)) {
28
35
  return encoding;
@@ -9,9 +9,7 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- 'use strict';
13
-
14
- const crypto = require('crypto');
12
+ import crypto from 'crypto';
15
13
 
16
14
  const isUTF8 = (encoding: 'ascii' | 'utf16le' | 'utf8') =>
17
15
  /^utf-?8$/i.test(encoding);
@@ -25,7 +23,7 @@ const constantFor = (encoding: 'ascii' | 'utf16le' | 'utf8') =>
25
23
  ? 3
26
24
  : 0;
27
25
 
28
- module.exports = function (
26
+ export default function (
29
27
  code: Buffer | string,
30
28
  encoding: 'ascii' | 'utf16le' | 'utf8' = 'utf8',
31
29
  ): Buffer {
@@ -40,7 +38,7 @@ module.exports = function (
40
38
  signature.length - 1,
41
39
  );
42
40
  return signature;
43
- };
41
+ }
44
42
 
45
43
  function tryAsciiPromotion(
46
44
  buffer: Buffer,
@@ -1,3 +1,16 @@
1
1
  "use strict";
2
2
 
3
- module.exports = require("./RamBundle");
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ var _RamBundle = require("./RamBundle");
7
+ Object.keys(_RamBundle).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _RamBundle[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _RamBundle[key];
14
+ },
15
+ });
16
+ });
@@ -9,8 +9,6 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- 'use strict';
13
-
14
12
  /* This is for retro-compatibility of React Native with older versions of
15
13
  * Metro. Use the `RamBundle` module directly. */
16
- module.exports = require('./RamBundle');
14
+ export * from './RamBundle';
@@ -1,6 +1,13 @@
1
1
  "use strict";
2
2
 
3
- const fs = require("fs");
4
- const throat = require("throat");
5
- const writeFile = throat(128, fs.promises.writeFile);
6
- module.exports = writeFile;
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.default = void 0;
7
+ var _fs = _interopRequireDefault(require("fs"));
8
+ var _throat = _interopRequireDefault(require("throat"));
9
+ function _interopRequireDefault(e) {
10
+ return e && e.__esModule ? e : { default: e };
11
+ }
12
+ const writeFile = (0, _throat.default)(128, _fs.default.promises.writeFile);
13
+ var _default = (exports.default = writeFile);
@@ -9,14 +9,12 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- 'use strict';
13
-
14
- const fs = require('fs');
15
- const throat = require('throat');
12
+ import fs from 'fs';
13
+ import throat from 'throat';
16
14
 
17
15
  const writeFile: typeof fs.promises.writeFile = throat(
18
16
  128,
19
17
  fs.promises.writeFile,
20
18
  );
21
19
 
22
- module.exports = writeFile;
20
+ export default writeFile;
@@ -31,7 +31,6 @@ export interface BundleOptions {
31
31
  dev: boolean;
32
32
  entryFile: string;
33
33
  readonly excludeSource: boolean;
34
- readonly hot: boolean;
35
34
  readonly inlineSourceMap: boolean;
36
35
  readonly lazy: boolean;
37
36
  minify: boolean;
@@ -9,12 +9,10 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- 'use strict';
13
-
14
12
  import type {
15
13
  Options as DeltaBundlerOptions,
16
14
  TransformInputOptions,
17
- } from '../DeltaBundler/types.flow';
15
+ } from '../DeltaBundler/types';
18
16
  import type {TransformProfile} from 'metro-babel-transformer';
19
17
  import type {CustomResolverOptions} from 'metro-resolver';
20
18
  import type {
@@ -43,7 +41,6 @@ export type BundleOptions = {
43
41
  dev: boolean,
44
42
  entryFile: string,
45
43
  +excludeSource: boolean,
46
- +hot: boolean,
47
44
  +inlineSourceMap: boolean,
48
45
  +lazy: boolean,
49
46
  minify: boolean,
@@ -132,18 +129,20 @@ export type OutputOptions = {
132
129
  ...
133
130
  };
134
131
 
135
- export type RequestOptions = {
136
- entryFile: string,
137
- inlineSourceMap?: boolean,
138
- sourceMapUrl?: string,
139
- dev?: boolean,
140
- minify: boolean,
141
- platform: string,
142
- createModuleIdFactory?: () => (path: string) => number,
143
- onProgress?: (transformedFileCount: number, totalFileCount: number) => void,
144
- +customResolverOptions?: CustomResolverOptions,
145
- +customTransformOptions?: CustomTransformOptions,
146
- +unstable_transformProfile?: TransformProfile,
147
- };
132
+ export type RequestOptions = $ReadOnly<
133
+ SafeOptionalProps<{
134
+ entryFile: string,
135
+ inlineSourceMap?: boolean,
136
+ sourceMapUrl?: string,
137
+ dev?: boolean,
138
+ minify: boolean,
139
+ platform: string,
140
+ createModuleIdFactory?: () => (path: string) => number,
141
+ onProgress?: (transformedFileCount: number, totalFileCount: number) => void,
142
+ customResolverOptions?: CustomResolverOptions,
143
+ customTransformOptions?: CustomTransformOptions,
144
+ unstable_transformProfile?: TransformProfile,
145
+ }>,
146
+ >;
148
147
 
149
148
  export type {MinifierOptions};
@@ -1,15 +0,0 @@
1
- "use strict";
2
-
3
- function createModuleIdFactory() {
4
- const fileToIdMap = new Map();
5
- let nextId = 0;
6
- return (path) => {
7
- let id = fileToIdMap.get(path);
8
- if (typeof id !== "number") {
9
- id = nextId++;
10
- fileToIdMap.set(path, id);
11
- }
12
- return id;
13
- };
14
- }
15
- module.exports = createModuleIdFactory;
@@ -1,27 +0,0 @@
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
8
- * @format
9
- * @oncall react_native
10
- */
11
-
12
- 'use strict';
13
-
14
- function createModuleIdFactory(): (path: string) => number {
15
- const fileToIdMap: Map<string, number> = new Map();
16
- let nextId = 0;
17
- return (path: string) => {
18
- let id = fileToIdMap.get(path);
19
- if (typeof id !== 'number') {
20
- id = nextId++;
21
- fileToIdMap.set(path, id);
22
- }
23
- return id;
24
- };
25
- }
26
-
27
- module.exports = createModuleIdFactory;
@@ -1,9 +0,0 @@
1
- "use strict";
2
-
3
- const os = require("os");
4
- module.exports = (workers) => {
5
- const cores = os.availableParallelism();
6
- return typeof workers === "number" && Number.isInteger(workers)
7
- ? Math.min(cores, workers > 0 ? workers : 1)
8
- : Math.max(1, Math.ceil(cores * (0.5 + 0.5 * Math.exp(-cores * 0.07)) - 1));
9
- };
@@ -1,22 +0,0 @@
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
8
- * @format
9
- * @oncall react_native
10
- */
11
-
12
- 'use strict';
13
-
14
- const os = require('os');
15
-
16
- module.exports = (workers: ?number): number => {
17
- // $FlowFixMe[prop-missing] Missing Flow lib def for availableParallelism
18
- const cores = os.availableParallelism();
19
- return typeof workers === 'number' && Number.isInteger(workers)
20
- ? Math.min(cores, workers > 0 ? workers : 1)
21
- : Math.max(1, Math.ceil(cores * (0.5 + 0.5 * Math.exp(-cores * 0.07)) - 1));
22
- };
@@ -1,62 +0,0 @@
1
- "use strict";
2
-
3
- var _types = require("../shared/types.flow");
4
- const parsePlatformFilePath = require("../node-haste/lib/parsePlatformFilePath");
5
- const parseCustomResolverOptions = require("./parseCustomResolverOptions");
6
- const parseCustomTransformOptions = require("./parseCustomTransformOptions");
7
- const jscSafeUrl = require("jsc-safe-url");
8
- const nullthrows = require("nullthrows");
9
- const path = require("path");
10
- const url = require("url");
11
- const getBoolean = (query, opt, defaultValue) =>
12
- query[opt] == null
13
- ? defaultValue
14
- : query[opt] === "true" || query[opt] === "1";
15
- const getBundleType = (bundleType) =>
16
- bundleType === "map" ? bundleType : "bundle";
17
- const getTransformProfile = (transformProfile) =>
18
- transformProfile === "hermes-stable" || transformProfile === "hermes-canary"
19
- ? transformProfile
20
- : "default";
21
- module.exports = function parseOptionsFromUrl(normalizedRequestUrl, platforms) {
22
- const parsedURL = nullthrows(url.parse(normalizedRequestUrl, true));
23
- const query = nullthrows(parsedURL.query);
24
- const pathname =
25
- query.bundleEntry ||
26
- (parsedURL.pathname != null ? decodeURIComponent(parsedURL.pathname) : "");
27
- const platform =
28
- query.platform || parsePlatformFilePath(pathname, platforms).platform;
29
- const bundleType = getBundleType(path.extname(pathname).substr(1));
30
- return {
31
- bundleType,
32
- customResolverOptions: parseCustomResolverOptions(parsedURL),
33
- customTransformOptions: parseCustomTransformOptions(parsedURL),
34
- dev: getBoolean(query, "dev", true),
35
- entryFile: pathname.replace(/^(?:\.?\/)?/, "./").replace(/\.[^/.]+$/, ""),
36
- excludeSource: getBoolean(query, "excludeSource", false),
37
- hot: true,
38
- inlineSourceMap: getBoolean(query, "inlineSourceMap", false),
39
- lazy: getBoolean(query, "lazy", false),
40
- minify: getBoolean(query, "minify", false),
41
- modulesOnly: getBoolean(query, "modulesOnly", false),
42
- onProgress: null,
43
- platform,
44
- runModule: getBoolean(query, "runModule", true),
45
- shallow: getBoolean(query, "shallow", false),
46
- sourceMapUrl: url.format({
47
- ...parsedURL,
48
- protocol:
49
- platform != null && platform.match(/^(android|ios|vr|windows|macos)$/)
50
- ? "http"
51
- : "",
52
- pathname: pathname.replace(/\.(bundle|delta)$/, ".map"),
53
- }),
54
- sourcePaths:
55
- _types.SourcePathsMode.cast(query.sourcePaths) ??
56
- _types.SourcePathsMode.Absolute,
57
- sourceUrl: jscSafeUrl.toJscSafeUrl(normalizedRequestUrl),
58
- unstable_transformProfile: getTransformProfile(
59
- query.unstable_transformProfile
60
- ),
61
- };
62
- };
@@ -1,97 +0,0 @@
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
- 'use strict';
13
-
14
- import type {BundleOptions} from '../shared/types.flow';
15
- import type {TransformProfile} from 'metro-babel-transformer';
16
-
17
- import {SourcePathsMode} from '../shared/types.flow';
18
-
19
- const parsePlatformFilePath = require('../node-haste/lib/parsePlatformFilePath');
20
- const parseCustomResolverOptions = require('./parseCustomResolverOptions');
21
- const parseCustomTransformOptions = require('./parseCustomTransformOptions');
22
- const jscSafeUrl = require('jsc-safe-url');
23
- const nullthrows = require('nullthrows');
24
- const path = require('path');
25
- const url = require('url');
26
-
27
- const getBoolean = (
28
- query: $ReadOnly<{[opt: string]: string}>,
29
- opt: string,
30
- defaultValue: boolean,
31
- ) =>
32
- query[opt] == null
33
- ? defaultValue
34
- : query[opt] === 'true' || query[opt] === '1';
35
-
36
- const getBundleType = (bundleType: string): 'map' | 'bundle' =>
37
- bundleType === 'map' ? bundleType : 'bundle';
38
-
39
- const getTransformProfile = (transformProfile: string): TransformProfile =>
40
- transformProfile === 'hermes-stable' || transformProfile === 'hermes-canary'
41
- ? transformProfile
42
- : 'default';
43
-
44
- module.exports = function parseOptionsFromUrl(
45
- normalizedRequestUrl: string,
46
- platforms: Set<string>,
47
- ): {
48
- ...BundleOptions,
49
- // Retained for backwards compatibility, unused in Metro, to be removed.
50
- bundleType: string,
51
- } {
52
- const parsedURL = nullthrows(url.parse(normalizedRequestUrl, true)); // `true` to parse the query param as an object.
53
- const query = nullthrows(parsedURL.query);
54
- const pathname =
55
- query.bundleEntry ||
56
- (parsedURL.pathname != null ? decodeURIComponent(parsedURL.pathname) : '');
57
- const platform =
58
- query.platform || parsePlatformFilePath(pathname, platforms).platform;
59
- const bundleType = getBundleType(path.extname(pathname).substr(1));
60
-
61
- return {
62
- bundleType,
63
- customResolverOptions: parseCustomResolverOptions(parsedURL),
64
- customTransformOptions: parseCustomTransformOptions(parsedURL),
65
- dev: getBoolean(query, 'dev', true),
66
- entryFile: pathname.replace(/^(?:\.?\/)?/, './').replace(/\.[^/.]+$/, ''),
67
- excludeSource: getBoolean(query, 'excludeSource', false),
68
- hot: true,
69
- inlineSourceMap: getBoolean(query, 'inlineSourceMap', false),
70
- lazy: getBoolean(query, 'lazy', false),
71
- minify: getBoolean(query, 'minify', false),
72
- modulesOnly: getBoolean(query, 'modulesOnly', false),
73
- onProgress: null,
74
- platform,
75
- runModule: getBoolean(query, 'runModule', true),
76
- shallow: getBoolean(query, 'shallow', false),
77
- sourceMapUrl: url.format({
78
- ...parsedURL,
79
- // The Chrome Debugger loads bundles via Blob urls, whose
80
- // protocol is blob:http. This breaks loading source maps through
81
- // protocol-relative URLs, which is why we must force the HTTP protocol
82
- // when loading the bundle for either Android or iOS.
83
- // TODO(T167298674): Remove when remote debugging is not needed in React Native
84
- protocol:
85
- platform != null && platform.match(/^(android|ios|vr|windows|macos)$/)
86
- ? 'http'
87
- : '',
88
- pathname: pathname.replace(/\.(bundle|delta)$/, '.map'),
89
- }),
90
- sourcePaths:
91
- SourcePathsMode.cast(query.sourcePaths) ?? SourcePathsMode.Absolute,
92
- sourceUrl: jscSafeUrl.toJscSafeUrl(normalizedRequestUrl),
93
- unstable_transformProfile: getTransformProfile(
94
- query.unstable_transformProfile,
95
- ),
96
- };
97
- };
@@ -1,24 +0,0 @@
1
- "use strict";
2
-
3
- var _path = _interopRequireDefault(require("path"));
4
- function _interopRequireDefault(e) {
5
- return e && e.__esModule
6
- ? e
7
- : {
8
- default: e,
9
- };
10
- }
11
- class Module {
12
- constructor(file, moduleCache) {
13
- if (!_path.default.isAbsolute(file)) {
14
- throw new Error("Expected file to be absolute path but got " + file);
15
- }
16
- this.path = file;
17
- this._moduleCache = moduleCache;
18
- }
19
- getPackage() {
20
- return this._moduleCache.getPackageForModule(this)?.pkg;
21
- }
22
- invalidate() {}
23
- }
24
- module.exports = Module;
@@ -1,41 +0,0 @@
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
- 'use strict';
13
-
14
- import type ModuleCache from './ModuleCache';
15
- import type Package from './Package';
16
-
17
- import path from 'path';
18
-
19
- class Module {
20
- path: string;
21
-
22
- _moduleCache: ModuleCache;
23
- _sourceCode: ?string;
24
-
25
- constructor(file: string, moduleCache: ModuleCache) {
26
- if (!path.isAbsolute(file)) {
27
- throw new Error('Expected file to be absolute path but got ' + file);
28
- }
29
-
30
- this.path = file;
31
- this._moduleCache = moduleCache;
32
- }
33
-
34
- getPackage(): ?Package {
35
- return this._moduleCache.getPackageForModule(this)?.pkg;
36
- }
37
-
38
- invalidate() {}
39
- }
40
-
41
- module.exports = Module;
File without changes