metro 0.83.1 → 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.
- package/package.json +15 -15
- package/src/Assets.js +68 -42
- package/src/Assets.js.flow +13 -24
- package/src/Bundler/util.js +40 -17
- package/src/Bundler/util.js.flow +6 -13
- package/src/Bundler.js +17 -6
- package/src/Bundler.js.flow +3 -7
- package/src/DeltaBundler/DeltaCalculator.js +14 -10
- package/src/DeltaBundler/DeltaCalculator.js.flow +4 -7
- package/src/DeltaBundler/Graph.js +44 -35
- package/src/DeltaBundler/Graph.js.flow +3 -4
- package/src/DeltaBundler/Serializers/baseJSBundle.js +24 -10
- package/src/DeltaBundler/Serializers/baseJSBundle.js.flow +6 -9
- package/src/DeltaBundler/Serializers/getAllFiles.js +9 -6
- package/src/DeltaBundler/Serializers/getAllFiles.js.flow +4 -8
- package/src/DeltaBundler/Serializers/getAssets.js +18 -11
- package/src/DeltaBundler/Serializers/getAssets.js.flow +5 -9
- package/src/DeltaBundler/Serializers/getExplodedSourceMap.d.ts +26 -0
- package/src/DeltaBundler/Serializers/getExplodedSourceMap.js +7 -6
- package/src/DeltaBundler/Serializers/getExplodedSourceMap.js.flow +3 -9
- package/src/DeltaBundler/Serializers/getRamBundleInfo.js +40 -23
- package/src/DeltaBundler/Serializers/getRamBundleInfo.js.flow +11 -18
- package/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.js +4 -1
- package/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.js.flow +1 -5
- package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js +7 -4
- package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js.flow +3 -7
- package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.js +4 -1
- package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.js.flow +2 -6
- package/src/DeltaBundler/Serializers/helpers/js.js +65 -31
- package/src/DeltaBundler/Serializers/helpers/js.js.flow +21 -21
- package/src/DeltaBundler/Serializers/helpers/processModules.js +8 -5
- package/src/DeltaBundler/Serializers/helpers/processModules.js.flow +3 -7
- package/src/DeltaBundler/Serializers/hmrJSBundle.js +70 -25
- package/src/DeltaBundler/Serializers/hmrJSBundle.js.flow +43 -33
- package/src/DeltaBundler/Serializers/sourceMapGenerator.js +19 -16
- package/src/DeltaBundler/Serializers/sourceMapGenerator.js.flow +6 -14
- package/src/DeltaBundler/Serializers/sourceMapObject.js +12 -10
- package/src/DeltaBundler/Serializers/sourceMapObject.js.flow +4 -9
- package/src/DeltaBundler/Serializers/sourceMapString.js +14 -12
- package/src/DeltaBundler/Serializers/sourceMapString.js.flow +4 -9
- package/src/DeltaBundler/Transformer.js +31 -22
- package/src/DeltaBundler/Transformer.js.flow +10 -17
- package/src/DeltaBundler/Worker.flow.js +25 -18
- package/src/DeltaBundler/Worker.flow.js.flow +12 -18
- package/src/DeltaBundler/Worker.js.flow +2 -0
- package/src/DeltaBundler/WorkerFarm.js +13 -11
- package/src/DeltaBundler/WorkerFarm.js.flow +7 -9
- package/src/DeltaBundler/buildSubgraph.js +12 -12
- package/src/DeltaBundler/buildSubgraph.js.flow +1 -1
- package/src/DeltaBundler/getTransformCacheKey.js +12 -6
- package/src/DeltaBundler/getTransformCacheKey.js.flow +5 -7
- package/src/DeltaBundler/mergeDeltas.js +4 -1
- package/src/DeltaBundler/mergeDeltas.js.flow +5 -6
- package/src/DeltaBundler/types.d.ts +4 -1
- package/src/DeltaBundler/{types.flow.js.flow → types.js.flow} +5 -3
- package/src/DeltaBundler.js +15 -6
- package/src/DeltaBundler.js.flow +4 -8
- package/src/HmrServer.js +116 -68
- package/src/HmrServer.js.flow +41 -52
- package/src/IncrementalBundler/GraphNotFoundError.js +5 -1
- package/src/IncrementalBundler/GraphNotFoundError.js.flow +1 -5
- package/src/IncrementalBundler/ResourceNotFoundError.js +5 -1
- package/src/IncrementalBundler/ResourceNotFoundError.js.flow +1 -5
- package/src/IncrementalBundler/RevisionNotFoundError.js +5 -1
- package/src/IncrementalBundler/RevisionNotFoundError.js.flow +1 -5
- package/src/IncrementalBundler.js +71 -35
- package/src/IncrementalBundler.js.flow +12 -16
- package/src/ModuleGraph/test-helpers.js +19 -14
- package/src/ModuleGraph/worker/JsFileWrapping.js +19 -18
- package/src/ModuleGraph/worker/JsFileWrapping.js.flow +1 -10
- package/src/ModuleGraph/worker/collectDependencies.js +81 -52
- package/src/ModuleGraph/worker/collectDependencies.js.flow +15 -22
- package/src/ModuleGraph/worker/generateImportNames.js +12 -6
- package/src/ModuleGraph/worker/generateImportNames.js.flow +3 -7
- package/src/ModuleGraph/worker/importLocationsPlugin.js +5 -4
- package/src/ModuleGraph/worker/importLocationsPlugin.js.flow +2 -4
- package/src/Server/MultipartResponse.js +11 -4
- package/src/Server/MultipartResponse.js.flow +2 -5
- package/src/Server/symbolicate.d.ts +31 -0
- package/src/Server/symbolicate.js +15 -16
- package/src/Server/symbolicate.js.flow +6 -16
- package/src/Server.d.ts +0 -1
- package/src/Server.js +298 -191
- package/src/Server.js.flow +136 -99
- package/src/cli-utils.js +13 -4
- package/src/cli-utils.js.flow +3 -5
- package/src/cli.js.flow +2 -0
- package/src/commands/build.js +17 -10
- package/src/commands/build.js.flow +6 -6
- package/src/commands/dependencies.js +26 -16
- package/src/commands/dependencies.js.flow +7 -9
- package/src/commands/serve.js +16 -11
- package/src/commands/serve.js.flow +5 -6
- package/src/index.d.ts +26 -3
- package/src/index.flow.js +162 -72
- package/src/index.flow.js.flow +60 -47
- package/src/index.js.flow +2 -0
- package/src/integration_tests/basic_bundle/TestBundle.js.flow +2 -1
- package/src/integration_tests/basic_bundle/import-export/index.js +2 -2
- package/src/integration_tests/basic_bundle/require-context/mode-eager.js +2 -2
- package/src/integration_tests/basic_bundle/require-context/mode-lazy-once.js +2 -2
- package/src/integration_tests/basic_bundle/require-context/mode-lazy.js +2 -2
- package/src/integration_tests/basic_bundle/require-context/mode-sync.js +1 -1
- package/src/integration_tests/basic_bundle/require-context/utils.js +1 -1
- package/src/integration_tests/execBundle.js +7 -4
- package/src/integration_tests/execBundle.js.flow +1 -3
- package/src/integration_tests/metro.config.js +3 -3
- package/src/lib/BatchProcessor.js +15 -5
- package/src/lib/BatchProcessor.js.flow +2 -6
- package/src/lib/CountingSet.js.flow +2 -2
- package/src/lib/JsonReporter.js +6 -2
- package/src/lib/JsonReporter.js.flow +1 -5
- package/src/lib/RamBundleParser.js +12 -3
- package/src/lib/RamBundleParser.js.flow +2 -6
- package/src/lib/TerminalReporter.js +95 -56
- package/src/lib/TerminalReporter.js.flow +9 -12
- package/src/lib/bundleToString.js +4 -1
- package/src/lib/bundleToString.js.flow +2 -9
- package/src/lib/contextModule.js +2 -2
- package/src/lib/contextModuleTemplates.js +7 -13
- package/src/lib/countLines.js +5 -1
- package/src/lib/countLines.js.flow +1 -3
- package/src/lib/createWebsocketServer.js +6 -2
- package/src/lib/createWebsocketServer.js.flow +4 -4
- package/src/lib/debounceAsyncQueue.js +4 -1
- package/src/lib/debounceAsyncQueue.js.flow +1 -5
- package/src/lib/formatBundlingError.js +32 -22
- package/src/lib/formatBundlingError.js.flow +18 -20
- package/src/lib/getAppendScripts.js +19 -15
- package/src/lib/getAppendScripts.js.flow +9 -13
- package/src/lib/getGraphId.js +12 -6
- package/src/lib/getGraphId.js.flow +4 -10
- package/src/lib/getPreludeCode.js +7 -10
- package/src/lib/getPreludeCode.js.flow +2 -6
- package/src/lib/getPrependedScripts.js +39 -11
- package/src/lib/getPrependedScripts.js.flow +8 -13
- package/src/lib/isResolvedDependency.js.flow +1 -1
- package/src/lib/logToConsole.js +18 -12
- package/src/lib/logToConsole.js.flow +5 -14
- package/src/lib/parseBundleOptionsFromBundleRequestUrl.js +144 -0
- package/src/lib/parseBundleOptionsFromBundleRequestUrl.js.flow +146 -0
- package/src/lib/parseCustomResolverOptions.js +8 -6
- package/src/lib/parseCustomResolverOptions.js.flow +6 -12
- package/src/lib/parseCustomTransformOptions.js +8 -6
- package/src/lib/parseCustomTransformOptions.js.flow +11 -14
- package/src/lib/parseJsonBody.js +4 -1
- package/src/lib/parseJsonBody.js.flow +1 -3
- package/src/lib/pathUtils.js +34 -0
- package/src/lib/pathUtils.js.flow +16 -0
- package/src/lib/relativizeSourceMap.js +12 -3
- package/src/lib/relativizeSourceMap.js.flow +2 -6
- package/src/lib/reporting.js +25 -19
- package/src/lib/reporting.js.flow +6 -16
- package/src/lib/splitBundleOptions.js +4 -2
- package/src/lib/splitBundleOptions.js.flow +4 -7
- package/src/lib/transformHelpers.js +18 -20
- package/src/lib/transformHelpers.js.flow +5 -15
- package/src/node-haste/DependencyGraph/ModuleResolution.js +75 -57
- package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +28 -44
- package/src/node-haste/DependencyGraph/createFileMap.js +13 -7
- package/src/node-haste/DependencyGraph/createFileMap.js.flow +2 -5
- package/src/node-haste/DependencyGraph.js +61 -45
- package/src/node-haste/DependencyGraph.js.flow +34 -31
- package/src/node-haste/Package.js +13 -6
- package/src/node-haste/Package.js.flow +3 -7
- package/src/node-haste/{ModuleCache.js → PackageCache.js} +11 -19
- package/src/node-haste/{ModuleCache.js.flow → PackageCache.js.flow} +2 -30
- package/src/node-haste/lib/AssetPaths.js +14 -8
- package/src/node-haste/lib/AssetPaths.js.flow +7 -8
- package/src/node-haste/lib/parsePlatformFilePath.js +10 -4
- package/src/node-haste/lib/parsePlatformFilePath.js.flow +2 -6
- package/src/shared/output/RamBundle/as-assets.js +42 -22
- package/src/shared/output/RamBundle/as-assets.js.flow +12 -15
- package/src/shared/output/RamBundle/as-indexed-file.js +33 -23
- package/src/shared/output/RamBundle/as-indexed-file.js.flow +10 -16
- package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js +11 -10
- package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js.flow +4 -6
- package/src/shared/output/RamBundle/magic-number.js +5 -1
- package/src/shared/output/RamBundle/magic-number.js.flow +1 -3
- package/src/shared/output/RamBundle/util.js +20 -13
- package/src/shared/output/RamBundle/util.js.flow +4 -6
- package/src/shared/output/RamBundle/write-sourcemap.js +9 -3
- package/src/shared/output/RamBundle/write-sourcemap.js.flow +2 -6
- package/src/shared/output/RamBundle.js +16 -9
- package/src/shared/output/RamBundle.js.flow +8 -12
- package/src/shared/output/bundle.flow.js +37 -13
- package/src/shared/output/bundle.flow.js.flow +24 -12
- package/src/shared/output/bundle.js.flow +2 -0
- package/src/shared/output/meta.js +16 -9
- package/src/shared/output/meta.js.flow +3 -5
- package/src/shared/output/unbundle.js +14 -1
- package/src/shared/output/unbundle.js.flow +1 -3
- package/src/shared/output/writeFile.js +11 -4
- package/src/shared/output/writeFile.js.flow +3 -5
- package/src/shared/types.d.ts +0 -1
- package/src/shared/{types.flow.js.flow → types.js.flow} +16 -17
- package/src/lib/createModuleIdFactory.js +0 -15
- package/src/lib/createModuleIdFactory.js.flow +0 -27
- package/src/lib/getMaxWorkers.js +0 -9
- package/src/lib/getMaxWorkers.js.flow +0 -22
- package/src/lib/parseOptionsFromUrl.js +0 -62
- package/src/lib/parseOptionsFromUrl.js.flow +0 -97
- package/src/node-haste/Module.js +0 -20
- package/src/node-haste/Module.js.flow +0 -41
- /package/src/DeltaBundler/{types.flow.js → types.js} +0 -0
- /package/src/shared/{types.flow.js → types.js} +0 -0
|
@@ -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
|
|
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
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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;
|
package/src/lib/getMaxWorkers.js
DELETED
|
@@ -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
|
-
};
|
package/src/node-haste/Module.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _path = _interopRequireDefault(require("path"));
|
|
4
|
-
function _interopRequireDefault(e) {
|
|
5
|
-
return e && e.__esModule ? e : { default: e };
|
|
6
|
-
}
|
|
7
|
-
class Module {
|
|
8
|
-
constructor(file, moduleCache) {
|
|
9
|
-
if (!_path.default.isAbsolute(file)) {
|
|
10
|
-
throw new Error("Expected file to be absolute path but got " + file);
|
|
11
|
-
}
|
|
12
|
-
this.path = file;
|
|
13
|
-
this._moduleCache = moduleCache;
|
|
14
|
-
}
|
|
15
|
-
getPackage() {
|
|
16
|
-
return this._moduleCache.getPackageForModule(this)?.pkg;
|
|
17
|
-
}
|
|
18
|
-
invalidate() {}
|
|
19
|
-
}
|
|
20
|
-
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
|
|
File without changes
|