metro 0.75.1 → 0.76.1
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 +25 -26
- package/src/Asset.d.ts +25 -0
- package/src/Assets.js +2 -2
- package/src/Assets.js.flow +1 -1
- package/src/Bundler.d.ts +39 -0
- package/src/DeltaBundler/Graph.d.ts +40 -0
- package/src/DeltaBundler/Graph.js +11 -28
- package/src/DeltaBundler/Graph.js.flow +7 -0
- package/src/DeltaBundler/Serializers/getRamBundleInfo.d.ts +18 -0
- package/src/DeltaBundler/Serializers/helpers/js.js +2 -7
- package/src/DeltaBundler/Transformer.js +1 -2
- package/src/DeltaBundler/Transformer.js.flow +1 -2
- package/src/DeltaBundler/Worker.d.ts +47 -0
- package/src/DeltaBundler/types.d.ts +167 -0
- package/src/DeltaBundler/types.flow.js.flow +1 -7
- package/src/DeltaBundler.d.ts +58 -0
- package/src/HmrServer.js +10 -37
- package/src/HmrServer.js.flow +0 -5
- package/src/IncrementalBundler.d.ts +97 -0
- package/src/IncrementalBundler.js +6 -9
- package/src/IncrementalBundler.js.flow +1 -0
- package/src/ModuleGraph/worker/collectDependencies.d.ts +27 -0
- package/src/ModuleGraph/worker/collectDependencies.js +94 -113
- package/src/ModuleGraph/worker/collectDependencies.js.flow +148 -171
- package/src/Server/MultipartResponse.d.ts +31 -0
- package/src/Server/symbolicate.js +1 -5
- package/src/Server.d.ts +113 -0
- package/src/Server.js +17 -182
- package/src/Server.js.flow +12 -154
- package/src/cli/parseKeyValueParamArray.js +34 -0
- package/src/cli/parseKeyValueParamArray.js.flow +31 -0
- package/src/cli-utils.js.flow +2 -6
- package/src/cli.js +2 -0
- package/src/cli.js.flow +1 -0
- package/src/commands/build.js +34 -7
- package/src/commands/build.js.flow +50 -8
- package/src/commands/dependencies.js +12 -14
- package/src/commands/dependencies.js.flow +128 -0
- package/src/commands/serve.js +11 -4
- package/src/commands/serve.js.flow +26 -6
- package/src/index.d.ts +151 -0
- package/src/index.flow.js +9 -4
- package/src/index.flow.js.flow +18 -6
- package/src/integration_tests/basic_bundle/TestBigInt.js +0 -3
- package/src/integration_tests/basic_bundle/TestBigInt.js.flow +0 -3
- package/src/integration_tests/basic_bundle/require-resolveWeak/import-and-resolveWeak.js +28 -0
- package/src/integration_tests/basic_bundle/require-resolveWeak/import-and-resolveWeak.js.flow +33 -0
- package/src/integration_tests/basic_bundle/require-resolveWeak/multiple.js +20 -0
- package/src/integration_tests/basic_bundle/require-resolveWeak/multiple.js.flow +23 -0
- package/src/integration_tests/basic_bundle/require-resolveWeak/never-required.js +18 -0
- package/src/integration_tests/basic_bundle/require-resolveWeak/never-required.js.flow +21 -0
- package/src/integration_tests/basic_bundle/require-resolveWeak/require-and-resolveWeak.js +28 -0
- package/src/integration_tests/basic_bundle/require-resolveWeak/require-and-resolveWeak.js.flow +33 -0
- package/src/integration_tests/basic_bundle/require-resolveWeak/subdir/counter-module.js +19 -0
- package/src/integration_tests/basic_bundle/require-resolveWeak/subdir/counter-module.js.flow +18 -0
- package/src/integration_tests/basic_bundle/require-resolveWeak/subdir/throwing-module.js +13 -0
- package/src/integration_tests/basic_bundle/require-resolveWeak/subdir/throwing-module.js.flow +11 -0
- package/src/integration_tests/basic_bundle/require-resolveWeak/utils.js +1 -0
- package/src/integration_tests/basic_bundle/require-resolveWeak/utils.js.flow +14 -0
- package/src/lib/CountingSet.d.ts +48 -0
- package/src/lib/CountingSet.js +1 -5
- package/src/lib/RamBundleParser.js +0 -1
- package/src/lib/RamBundleParser.js.flow +0 -1
- package/src/lib/TerminalReporter.d.ts +27 -0
- package/src/lib/TerminalReporter.js +4 -21
- package/src/lib/TerminalReporter.js.flow +1 -5
- package/src/lib/contextModule.d.ts +22 -0
- package/src/lib/contextModuleTemplates.js +1 -1
- package/src/lib/contextModuleTemplates.js.flow +1 -1
- package/src/lib/formatBundlingError.js +0 -3
- package/src/lib/formatBundlingError.js.flow +0 -3
- package/src/lib/getAppendScripts.js +0 -3
- package/src/lib/getAppendScripts.js.flow +0 -3
- package/src/lib/getGraphId.d.ts +11 -0
- package/src/lib/getGraphId.js +2 -12
- package/src/lib/getGraphId.js.flow +0 -1
- package/src/lib/getPrependedScripts.js +0 -10
- package/src/lib/getPrependedScripts.js.flow +0 -10
- package/src/lib/parseOptionsFromUrl.js +1 -16
- package/src/lib/parseOptionsFromUrl.js.flow +0 -17
- package/src/lib/reporting.d.ts +140 -0
- package/src/lib/reporting.js.flow +0 -1
- package/src/lib/splitBundleOptions.js +0 -1
- package/src/lib/splitBundleOptions.js.flow +0 -1
- package/src/lib/transformHelpers.js +14 -23
- package/src/lib/transformHelpers.js.flow +5 -9
- package/src/node-haste/DependencyGraph/ModuleResolution.js +4 -11
- package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +3 -5
- package/src/node-haste/DependencyGraph/createHasteMap.js +12 -38
- package/src/node-haste/DependencyGraph/createHasteMap.js.flow +1 -1
- package/src/node-haste/DependencyGraph.d.ts +59 -0
- package/src/node-haste/DependencyGraph.js +7 -17
- package/src/node-haste/DependencyGraph.js.flow +2 -5
- package/src/node-haste/Module.js +5 -3
- package/src/node-haste/Module.js.flow +2 -3
- package/src/node-haste/ModuleCache.js +1 -5
- package/src/shared/output/RamBundle/as-assets.js +1 -0
- package/src/shared/output/RamBundle/as-assets.js.flow +1 -0
- package/src/shared/output/RamBundle/write-sourcemap.js +1 -0
- package/src/shared/output/RamBundle/write-sourcemap.js.flow +1 -0
- package/src/shared/output/bundle.d.ts +31 -0
- package/src/shared/types.d.ts +138 -0
- package/src/shared/types.flow.js.flow +2 -1
- package/types/Asset.d.ts +25 -0
- package/types/Bundler.d.ts +39 -0
- package/types/DeltaBundler/Graph.d.ts +40 -0
- package/types/DeltaBundler/Serializers/getRamBundleInfo.d.ts +18 -0
- package/types/DeltaBundler/Worker.d.ts +47 -0
- package/types/DeltaBundler/types.d.ts +167 -0
- package/types/DeltaBundler.d.ts +58 -0
- package/types/IncrementalBundler.d.ts +97 -0
- package/types/ModuleGraph/worker/collectDependencies.d.ts +27 -0
- package/types/Server/MultipartResponse.d.ts +31 -0
- package/types/Server.d.ts +113 -0
- package/types/index.d.ts +151 -0
- package/types/lib/CountingSet.d.ts +48 -0
- package/types/lib/TerminalReporter.d.ts +27 -0
- package/types/lib/contextModule.d.ts +22 -0
- package/types/lib/getGraphId.d.ts +11 -0
- package/types/lib/reporting.d.ts +140 -0
- package/types/node-haste/DependencyGraph.d.ts +59 -0
- package/types/shared/output/bundle.d.ts +31 -0
- package/types/shared/types.d.ts +138 -0
- package/src/DeltaBundler/Serializers/baseBytecodeBundle.js +0 -81
- package/src/DeltaBundler/Serializers/baseBytecodeBundle.js.flow +0 -103
- package/src/DeltaBundler/Serializers/helpers/bytecode.js +0 -61
- package/src/DeltaBundler/Serializers/helpers/bytecode.js.flow +0 -75
- package/src/DeltaBundler/Serializers/helpers/processBytecodeModules.js +0 -40
- package/src/DeltaBundler/Serializers/helpers/processBytecodeModules.js.flow +0 -51
- package/src/lib/bundleToBytecode.js +0 -79
- package/src/lib/bundleToBytecode.js.flow +0 -97
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "metro",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.76.1",
|
|
4
4
|
"description": "🚇 The JavaScript bundler for React Native.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": "src/cli.js",
|
|
@@ -20,7 +20,6 @@
|
|
|
20
20
|
"@babel/template": "^7.0.0",
|
|
21
21
|
"@babel/traverse": "^7.20.0",
|
|
22
22
|
"@babel/types": "^7.20.0",
|
|
23
|
-
"absolute-path": "^0.0.0",
|
|
24
23
|
"accepts": "^1.3.7",
|
|
25
24
|
"async": "^3.2.2",
|
|
26
25
|
"chalk": "^4.0.0",
|
|
@@ -35,23 +34,22 @@
|
|
|
35
34
|
"invariant": "^2.2.4",
|
|
36
35
|
"jest-worker": "^27.2.0",
|
|
37
36
|
"lodash.throttle": "^4.1.1",
|
|
38
|
-
"metro-babel-transformer": "0.
|
|
39
|
-
"metro-cache": "0.
|
|
40
|
-
"metro-cache-key": "0.
|
|
41
|
-
"metro-config": "0.
|
|
42
|
-
"metro-core": "0.
|
|
43
|
-
"metro-file-map": "0.
|
|
44
|
-
"metro-
|
|
45
|
-
"metro-
|
|
46
|
-
"metro-minify-
|
|
47
|
-
"metro-
|
|
48
|
-
"metro-
|
|
49
|
-
"metro-
|
|
50
|
-
"metro-
|
|
51
|
-
"metro-
|
|
52
|
-
"metro-
|
|
53
|
-
"metro-transform-
|
|
54
|
-
"metro-transform-worker": "0.75.1",
|
|
37
|
+
"metro-babel-transformer": "0.76.1",
|
|
38
|
+
"metro-cache": "0.76.1",
|
|
39
|
+
"metro-cache-key": "0.76.1",
|
|
40
|
+
"metro-config": "0.76.1",
|
|
41
|
+
"metro-core": "0.76.1",
|
|
42
|
+
"metro-file-map": "0.76.1",
|
|
43
|
+
"metro-inspector-proxy": "0.76.1",
|
|
44
|
+
"metro-minify-terser": "0.76.1",
|
|
45
|
+
"metro-minify-uglify": "0.76.1",
|
|
46
|
+
"metro-react-native-babel-preset": "0.76.1",
|
|
47
|
+
"metro-resolver": "0.76.1",
|
|
48
|
+
"metro-runtime": "0.76.1",
|
|
49
|
+
"metro-source-map": "0.76.1",
|
|
50
|
+
"metro-symbolicate": "0.76.1",
|
|
51
|
+
"metro-transform-plugins": "0.76.1",
|
|
52
|
+
"metro-transform-worker": "0.76.1",
|
|
55
53
|
"mime-types": "^2.1.27",
|
|
56
54
|
"node-fetch": "^2.2.0",
|
|
57
55
|
"nullthrows": "^1.1.1",
|
|
@@ -59,27 +57,28 @@
|
|
|
59
57
|
"serialize-error": "^2.1.0",
|
|
60
58
|
"source-map": "^0.5.6",
|
|
61
59
|
"strip-ansi": "^6.0.0",
|
|
62
|
-
"temp": "0.8.3",
|
|
63
60
|
"throat": "^5.0.0",
|
|
64
61
|
"ws": "^7.5.1",
|
|
65
|
-
"yargs": "^17.
|
|
62
|
+
"yargs": "^17.6.2"
|
|
66
63
|
},
|
|
67
64
|
"devDependencies": {
|
|
68
65
|
"@babel/plugin-transform-flow-strip-types": "^7.0.0",
|
|
66
|
+
"@types/babel__code-frame": "^7.0.3",
|
|
67
|
+
"@types/ws": "^8.5.4",
|
|
69
68
|
"babel-jest": "^29.2.1",
|
|
70
69
|
"dedent": "^0.7.0",
|
|
71
70
|
"jest-snapshot": "^26.5.2",
|
|
72
71
|
"jest-snapshot-serializer-raw": "^1.2.0",
|
|
73
|
-
"metro-babel-register": "0.
|
|
74
|
-
"metro-memory-fs": "0.
|
|
75
|
-
"metro-react-native-babel-preset": "0.
|
|
76
|
-
"metro-react-native-babel-transformer": "0.
|
|
72
|
+
"metro-babel-register": "0.76.1",
|
|
73
|
+
"metro-memory-fs": "0.76.1",
|
|
74
|
+
"metro-react-native-babel-preset": "0.76.1",
|
|
75
|
+
"metro-react-native-babel-transformer": "0.76.1",
|
|
77
76
|
"mock-req": "^0.2.0",
|
|
78
77
|
"mock-res": "^0.6.0",
|
|
79
78
|
"stack-trace": "^0.0.10"
|
|
80
79
|
},
|
|
81
80
|
"license": "MIT",
|
|
82
81
|
"engines": {
|
|
83
|
-
"node": ">=
|
|
82
|
+
"node": ">=16"
|
|
84
83
|
}
|
|
85
84
|
}
|
package/src/Asset.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
* @oncall react_native
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export interface AssetDataWithoutFiles {
|
|
12
|
+
readonly __packager_asset: boolean;
|
|
13
|
+
readonly fileSystemLocation: string;
|
|
14
|
+
readonly hash: string;
|
|
15
|
+
readonly height?: number;
|
|
16
|
+
readonly httpServerLocation: string;
|
|
17
|
+
readonly name: string;
|
|
18
|
+
readonly scales: number[];
|
|
19
|
+
readonly type: string;
|
|
20
|
+
readonly width?: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface AssetData extends AssetDataWithoutFiles {
|
|
24
|
+
readonly files: string[];
|
|
25
|
+
}
|
package/src/Assets.js
CHANGED
|
@@ -93,7 +93,7 @@ async function getAbsoluteAssetRecord(assetPath, platform = null) {
|
|
|
93
93
|
if (!record) {
|
|
94
94
|
throw new Error(
|
|
95
95
|
`Asset not found: ${assetPath} for platform: ${
|
|
96
|
-
platform
|
|
96
|
+
platform ?? "(unspecified)"
|
|
97
97
|
}`
|
|
98
98
|
);
|
|
99
99
|
}
|
|
@@ -134,7 +134,7 @@ async function getAssetData(
|
|
|
134
134
|
|
|
135
135
|
// On Windows, change backslashes to slashes to get proper URL path from file path.
|
|
136
136
|
if (path.sep === "\\") {
|
|
137
|
-
assetUrlPath = assetUrlPath.
|
|
137
|
+
assetUrlPath = assetUrlPath.replaceAll("\\", "/");
|
|
138
138
|
}
|
|
139
139
|
const isImage = isAssetTypeAnImage(path.extname(assetPath).slice(1));
|
|
140
140
|
const assetInfo = await getAbsoluteAssetInfo(assetPath, platform);
|
package/src/Assets.js.flow
CHANGED
|
@@ -200,7 +200,7 @@ async function getAssetData(
|
|
|
200
200
|
|
|
201
201
|
// On Windows, change backslashes to slashes to get proper URL path from file path.
|
|
202
202
|
if (path.sep === '\\') {
|
|
203
|
-
assetUrlPath = assetUrlPath.
|
|
203
|
+
assetUrlPath = assetUrlPath.replaceAll('\\', '/');
|
|
204
204
|
}
|
|
205
205
|
|
|
206
206
|
const isImage = isAssetTypeAnImage(path.extname(assetPath).slice(1));
|
package/src/Bundler.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
* @oncall react_native
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type {TransformResultWithSource} from './DeltaBundler';
|
|
12
|
+
import type {TransformOptions} from './DeltaBundler/Worker';
|
|
13
|
+
import type DependencyGraph from './node-haste/DependencyGraph';
|
|
14
|
+
import type {ConfigT} from 'metro-config';
|
|
15
|
+
import type {EventEmitter} from 'events';
|
|
16
|
+
|
|
17
|
+
export interface BundlerOptions {
|
|
18
|
+
readonly hasReducedPerformance?: boolean;
|
|
19
|
+
readonly watch?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default class Bundler {
|
|
23
|
+
constructor(config: ConfigT, options?: BundlerOptions);
|
|
24
|
+
|
|
25
|
+
getWatcher(): EventEmitter;
|
|
26
|
+
|
|
27
|
+
end(): Promise<void>;
|
|
28
|
+
|
|
29
|
+
getDependencyGraph(): Promise<DependencyGraph>;
|
|
30
|
+
|
|
31
|
+
transformFile(
|
|
32
|
+
filePath: string,
|
|
33
|
+
transformOptions: TransformOptions,
|
|
34
|
+
/** Optionally provide the file contents, this can be used to provide virtual contents for a file. */
|
|
35
|
+
fileBuffer?: Buffer,
|
|
36
|
+
): Promise<TransformResultWithSource<void>>;
|
|
37
|
+
|
|
38
|
+
ready(): Promise<void>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
* @oncall react_native
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type {
|
|
12
|
+
Dependencies,
|
|
13
|
+
GraphInputOptions,
|
|
14
|
+
MixedOutput,
|
|
15
|
+
Module,
|
|
16
|
+
Options,
|
|
17
|
+
TransformInputOptions,
|
|
18
|
+
} from './types';
|
|
19
|
+
|
|
20
|
+
export interface Result<T> {
|
|
21
|
+
added: Map<string, Module<T>>;
|
|
22
|
+
modified: Map<string, Module<T>>;
|
|
23
|
+
deleted: Set<string>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class Graph<T = MixedOutput> {
|
|
27
|
+
entryPoints: ReadonlySet<string>;
|
|
28
|
+
transformOptions: TransformInputOptions;
|
|
29
|
+
dependencies: Dependencies<T>;
|
|
30
|
+
constructor(options: GraphInputOptions);
|
|
31
|
+
traverseDependencies(
|
|
32
|
+
paths: ReadonlyArray<string>,
|
|
33
|
+
options: Options<T>,
|
|
34
|
+
): Promise<Result<T>>;
|
|
35
|
+
initialTraverseDependencies(options: Options<T>): Promise<Result<T>>;
|
|
36
|
+
markModifiedContextModules(
|
|
37
|
+
filePath: string,
|
|
38
|
+
modifiedPaths: Set<string>,
|
|
39
|
+
): void;
|
|
40
|
+
}
|
|
@@ -284,6 +284,8 @@ class Graph {
|
|
|
284
284
|
let module = this.dependencies.get(path);
|
|
285
285
|
if (options.shallow) {
|
|
286
286
|
// Don't add a node for the module if the graph is shallow (single-module).
|
|
287
|
+
} else if (dependency.data.data.asyncType === "weak") {
|
|
288
|
+
// Exclude weak dependencies from the bundle.
|
|
287
289
|
} else if (
|
|
288
290
|
options.experimentalImportBundleSupport &&
|
|
289
291
|
dependency.data.data.asyncType != null
|
|
@@ -332,6 +334,10 @@ class Graph {
|
|
|
332
334
|
_removeDependency(parentModule, key, dependency, delta, options) {
|
|
333
335
|
parentModule.dependencies.delete(key);
|
|
334
336
|
const { absolutePath } = dependency;
|
|
337
|
+
if (dependency.data.data.asyncType === "weak") {
|
|
338
|
+
// Weak dependencies are excluded from the bundle.
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
335
341
|
if (
|
|
336
342
|
options.experimentalImportBundleSupport &&
|
|
337
343
|
dependency.data.data.asyncType != null
|
|
@@ -376,26 +382,8 @@ class Graph {
|
|
|
376
382
|
* traverseDependencies. Note that the list may contain duplicates.
|
|
377
383
|
*/
|
|
378
384
|
*getModifiedModulesForDeletedPath(filePath) {
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
_this$importBundleNod,
|
|
382
|
-
_this$importBundleNod2;
|
|
383
|
-
yield* (_this$dependencies$ge =
|
|
384
|
-
(_this$dependencies$ge2 = this.dependencies.get(filePath)) === null ||
|
|
385
|
-
_this$dependencies$ge2 === void 0
|
|
386
|
-
? void 0
|
|
387
|
-
: _this$dependencies$ge2.inverseDependencies) !== null &&
|
|
388
|
-
_this$dependencies$ge !== void 0
|
|
389
|
-
? _this$dependencies$ge
|
|
390
|
-
: [];
|
|
391
|
-
yield* (_this$importBundleNod =
|
|
392
|
-
(_this$importBundleNod2 = this.#importBundleNodes.get(filePath)) ===
|
|
393
|
-
null || _this$importBundleNod2 === void 0
|
|
394
|
-
? void 0
|
|
395
|
-
: _this$importBundleNod2.inverseDependencies) !== null &&
|
|
396
|
-
_this$importBundleNod !== void 0
|
|
397
|
-
? _this$importBundleNod
|
|
398
|
-
: [];
|
|
385
|
+
yield* this.dependencies.get(filePath)?.inverseDependencies ?? [];
|
|
386
|
+
yield* this.#importBundleNodes.get(filePath)?.inverseDependencies ?? [];
|
|
399
387
|
}
|
|
400
388
|
_resolveDependencies(parentPath, dependencies, options) {
|
|
401
389
|
const maybeResolvedDeps = new Map();
|
|
@@ -511,15 +499,10 @@ class Graph {
|
|
|
511
499
|
|
|
512
500
|
// Add an entry to importBundleNodes (or record an inverse dependency of an existing one)
|
|
513
501
|
_incrementImportBundleReference(dependency, parentModule) {
|
|
514
|
-
var _this$importBundleNod3;
|
|
515
502
|
const { absolutePath } = dependency;
|
|
516
|
-
const importBundleNode =
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
? _this$importBundleNod3
|
|
520
|
-
: {
|
|
521
|
-
inverseDependencies: new _CountingSet.default(),
|
|
522
|
-
};
|
|
503
|
+
const importBundleNode = this.#importBundleNodes.get(absolutePath) ?? {
|
|
504
|
+
inverseDependencies: new _CountingSet.default(),
|
|
505
|
+
};
|
|
523
506
|
importBundleNode.inverseDependencies.add(parentModule.path);
|
|
524
507
|
this.#importBundleNodes.set(absolutePath, importBundleNode);
|
|
525
508
|
}
|
|
@@ -355,6 +355,8 @@ export class Graph<T = MixedOutput> {
|
|
|
355
355
|
|
|
356
356
|
if (options.shallow) {
|
|
357
357
|
// Don't add a node for the module if the graph is shallow (single-module).
|
|
358
|
+
} else if (dependency.data.data.asyncType === 'weak') {
|
|
359
|
+
// Exclude weak dependencies from the bundle.
|
|
358
360
|
} else if (
|
|
359
361
|
options.experimentalImportBundleSupport &&
|
|
360
362
|
dependency.data.data.asyncType != null
|
|
@@ -414,6 +416,11 @@ export class Graph<T = MixedOutput> {
|
|
|
414
416
|
|
|
415
417
|
const {absolutePath} = dependency;
|
|
416
418
|
|
|
419
|
+
if (dependency.data.data.asyncType === 'weak') {
|
|
420
|
+
// Weak dependencies are excluded from the bundle.
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
|
|
417
424
|
if (
|
|
418
425
|
options.experimentalImportBundleSupport &&
|
|
419
426
|
dependency.data.data.asyncType != null
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
* @oncall react_native
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import {ModuleTransportLike} from '../../shared/types';
|
|
12
|
+
|
|
13
|
+
export interface RamBundleInfo {
|
|
14
|
+
getDependencies: (filePath: string) => Set<string>;
|
|
15
|
+
startupModules: Readonly<ModuleTransportLike>;
|
|
16
|
+
lazyModules: Readonly<ModuleTransportLike>;
|
|
17
|
+
groups: Map<number, Set<number>>;
|
|
18
|
+
}
|
|
@@ -63,23 +63,18 @@ function getModuleParams(module, options) {
|
|
|
63
63
|
return params;
|
|
64
64
|
}
|
|
65
65
|
function getJsOutput(module) {
|
|
66
|
-
var _module$path, _module$path2;
|
|
67
66
|
const jsModules = module.output.filter(({ type }) => type.startsWith("js/"));
|
|
68
67
|
invariant(
|
|
69
68
|
jsModules.length === 1,
|
|
70
69
|
`Modules must have exactly one JS output, but ${
|
|
71
|
-
|
|
72
|
-
? _module$path
|
|
73
|
-
: "unknown module"
|
|
70
|
+
module.path ?? "unknown module"
|
|
74
71
|
} has ${jsModules.length} JS outputs.`
|
|
75
72
|
);
|
|
76
73
|
const jsOutput = jsModules[0];
|
|
77
74
|
invariant(
|
|
78
75
|
Number.isFinite(jsOutput.data.lineCount),
|
|
79
76
|
`JS output must populate lineCount, but ${
|
|
80
|
-
|
|
81
|
-
? _module$path2
|
|
82
|
-
: "unknown module"
|
|
77
|
+
module.path ?? "unknown module"
|
|
83
78
|
} has ${jsOutput.type} output with lineCount '${jsOutput.data.lineCount}'`
|
|
84
79
|
);
|
|
85
80
|
return jsOutput;
|
|
@@ -63,7 +63,6 @@ class Transformer {
|
|
|
63
63
|
minify,
|
|
64
64
|
nonInlinedRequires,
|
|
65
65
|
platform,
|
|
66
|
-
runtimeBytecodeVersion,
|
|
67
66
|
type,
|
|
68
67
|
unstable_disableES6Transforms,
|
|
69
68
|
unstable_transformProfile,
|
|
@@ -92,7 +91,6 @@ class Transformer {
|
|
|
92
91
|
minify,
|
|
93
92
|
nonInlinedRequires,
|
|
94
93
|
platform,
|
|
95
|
-
runtimeBytecodeVersion,
|
|
96
94
|
type,
|
|
97
95
|
unstable_disableES6Transforms,
|
|
98
96
|
unstable_transformProfile,
|
|
@@ -141,6 +139,7 @@ class Transformer {
|
|
|
141
139
|
};
|
|
142
140
|
}
|
|
143
141
|
end() {
|
|
142
|
+
// $FlowFixMe[unused-promise]
|
|
144
143
|
this._workerFarm.kill();
|
|
145
144
|
}
|
|
146
145
|
}
|
|
@@ -82,7 +82,6 @@ class Transformer {
|
|
|
82
82
|
minify,
|
|
83
83
|
nonInlinedRequires,
|
|
84
84
|
platform,
|
|
85
|
-
runtimeBytecodeVersion,
|
|
86
85
|
type,
|
|
87
86
|
unstable_disableES6Transforms,
|
|
88
87
|
unstable_transformProfile,
|
|
@@ -116,7 +115,6 @@ class Transformer {
|
|
|
116
115
|
minify,
|
|
117
116
|
nonInlinedRequires,
|
|
118
117
|
platform,
|
|
119
|
-
runtimeBytecodeVersion,
|
|
120
118
|
type,
|
|
121
119
|
unstable_disableES6Transforms,
|
|
122
120
|
unstable_transformProfile,
|
|
@@ -167,6 +165,7 @@ class Transformer {
|
|
|
167
165
|
}
|
|
168
166
|
|
|
169
167
|
end(): void {
|
|
168
|
+
// $FlowFixMe[unused-promise]
|
|
170
169
|
this._workerFarm.kill();
|
|
171
170
|
}
|
|
172
171
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
* @oncall react_native
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type {
|
|
12
|
+
JsTransformerConfig,
|
|
13
|
+
JsTransformOptions,
|
|
14
|
+
} from 'metro-transform-worker';
|
|
15
|
+
import type {TransformResult} from './types';
|
|
16
|
+
|
|
17
|
+
type LogEntry = unknown;
|
|
18
|
+
|
|
19
|
+
export type TransformOptions = JsTransformOptions;
|
|
20
|
+
|
|
21
|
+
declare function transform(
|
|
22
|
+
filename: string,
|
|
23
|
+
transformOptions: JsTransformOptions,
|
|
24
|
+
projectRoot: string,
|
|
25
|
+
transformerConfig: TransformerConfig,
|
|
26
|
+
fileBuffer?: Buffer,
|
|
27
|
+
): Promise<Data>;
|
|
28
|
+
|
|
29
|
+
export interface Worker {
|
|
30
|
+
readonly transform: typeof transform;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface TransformerConfig {
|
|
34
|
+
transformerPath: string;
|
|
35
|
+
transformerConfig: JsTransformerConfig;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface Data {
|
|
39
|
+
readonly result: TransformResult<void>;
|
|
40
|
+
readonly sha1: string;
|
|
41
|
+
readonly transformFileStartLogEntry: LogEntry;
|
|
42
|
+
readonly transformFileEndLogEntry: LogEntry;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
declare const worker: Worker;
|
|
46
|
+
|
|
47
|
+
export default worker;
|
|
@@ -0,0 +1,167 @@
|
|
|
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
|
+
* @oncall react_native
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type {SourceLocation} from '@babel/code-frame';
|
|
12
|
+
import type {JsTransformOptions} from 'metro-transform-worker';
|
|
13
|
+
import type {RequireContextParams} from '../ModuleGraph/worker/collectDependencies';
|
|
14
|
+
import type {RequireContext} from '../lib/contextModule';
|
|
15
|
+
import type CountingSet from '../lib/CountingSet';
|
|
16
|
+
import type {Graph} from './Graph';
|
|
17
|
+
|
|
18
|
+
export interface MixedOutput {
|
|
19
|
+
readonly data: {code: string};
|
|
20
|
+
readonly type: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type AsyncDependencyType = 'async' | 'prefetch';
|
|
24
|
+
|
|
25
|
+
export interface TransformResultDependency {
|
|
26
|
+
/**
|
|
27
|
+
* The literal name provided to a require or import call. For example 'foo' in
|
|
28
|
+
* case of `require('foo')`.
|
|
29
|
+
*/
|
|
30
|
+
readonly name: string;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Extra data returned by the dependency extractor.
|
|
34
|
+
*/
|
|
35
|
+
readonly data: {
|
|
36
|
+
/**
|
|
37
|
+
* A locally unique key for this dependency within the current module.
|
|
38
|
+
*/
|
|
39
|
+
readonly key: string;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* If not null, this dependency is due to a dynamic `import()` or `__prefetchImport()` call.
|
|
43
|
+
*/
|
|
44
|
+
readonly asyncType: AsyncDependencyType | null;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The condition for splitting on this dependency edge.
|
|
48
|
+
*/
|
|
49
|
+
readonly splitCondition?: {
|
|
50
|
+
readonly mobileConfigName: string;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The dependency is enclosed in a try/catch block.
|
|
55
|
+
*/
|
|
56
|
+
readonly isOptional?: boolean;
|
|
57
|
+
|
|
58
|
+
readonly locs: ReadonlyArray<SourceLocation>;
|
|
59
|
+
|
|
60
|
+
/** Context for requiring a collection of modules. */
|
|
61
|
+
readonly contextParams?: RequireContextParams;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface Dependency {
|
|
66
|
+
readonly absolutePath: string;
|
|
67
|
+
readonly data: TransformResultDependency;
|
|
68
|
+
[key: string]: unknown;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface Module<T = MixedOutput> {
|
|
72
|
+
readonly dependencies: Map<string, Dependency>;
|
|
73
|
+
readonly inverseDependencies: CountingSet<string>;
|
|
74
|
+
readonly output: ReadonlyArray<T>;
|
|
75
|
+
readonly path: string;
|
|
76
|
+
readonly getSource: () => Buffer;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export type Dependencies<T = MixedOutput> = Map<string, Module<T>>;
|
|
80
|
+
export type ReadOnlyDependencies<T = MixedOutput> = ReadonlyMap<
|
|
81
|
+
string,
|
|
82
|
+
Module<T>
|
|
83
|
+
>;
|
|
84
|
+
|
|
85
|
+
export type TransformInputOptions = Omit<
|
|
86
|
+
JsTransformOptions,
|
|
87
|
+
'inlinePlatform' | 'inlineRequires'
|
|
88
|
+
>;
|
|
89
|
+
|
|
90
|
+
export type GraphInputOptions = Readonly<{
|
|
91
|
+
entryPoints: ReadonlySet<string>;
|
|
92
|
+
// Unused in core but useful for custom serializers / experimentalSerializerHook
|
|
93
|
+
transformOptions: TransformInputOptions;
|
|
94
|
+
}>;
|
|
95
|
+
|
|
96
|
+
export interface ReadOnlyGraph<T = MixedOutput> {
|
|
97
|
+
readonly entryPoints: ReadonlySet<string>;
|
|
98
|
+
// Unused in core but useful for custom serializers / experimentalSerializerHook
|
|
99
|
+
readonly transformOptions: Readonly<TransformInputOptions>;
|
|
100
|
+
readonly dependencies: ReadOnlyDependencies<T>;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export type {Graph};
|
|
104
|
+
|
|
105
|
+
export interface TransformResult<T = MixedOutput> {
|
|
106
|
+
dependencies: ReadonlyArray<TransformResultDependency>;
|
|
107
|
+
output: ReadonlyArray<T>;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface TransformResultWithSource<T = MixedOutput>
|
|
111
|
+
extends TransformResult<T> {
|
|
112
|
+
getSource: () => Buffer;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export type TransformFn<T = MixedOutput> = (
|
|
116
|
+
modulePath: string,
|
|
117
|
+
requireContext: RequireContext | null,
|
|
118
|
+
) => Promise<TransformResultWithSource<T>>;
|
|
119
|
+
|
|
120
|
+
export interface AllowOptionalDependenciesWithOptions {
|
|
121
|
+
readonly exclude: string[];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export type AllowOptionalDependencies =
|
|
125
|
+
| boolean
|
|
126
|
+
| AllowOptionalDependenciesWithOptions;
|
|
127
|
+
|
|
128
|
+
export interface BundlerResolution {
|
|
129
|
+
readonly type: 'sourceFile';
|
|
130
|
+
readonly filePath: string;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export interface Options<T = MixedOutput> {
|
|
134
|
+
readonly resolve: (from: string, to: string) => string;
|
|
135
|
+
readonly transform: TransformFn<T>;
|
|
136
|
+
readonly transformOptions: TransformInputOptions;
|
|
137
|
+
readonly onProgress:
|
|
138
|
+
| ((numProcessed: number, total: number) => unknown)
|
|
139
|
+
| null;
|
|
140
|
+
readonly experimentalImportBundleSupport: boolean;
|
|
141
|
+
readonly unstable_allowRequireContext: boolean;
|
|
142
|
+
readonly shallow: boolean;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export interface DeltaResult<T = MixedOutput> {
|
|
146
|
+
readonly added: Map<string, Module<T>>;
|
|
147
|
+
readonly modified: Map<string, Module<T>>;
|
|
148
|
+
readonly deleted: Set<string>;
|
|
149
|
+
readonly reset: boolean;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export interface SerializerOptions<T = MixedOutput> {
|
|
153
|
+
readonly asyncRequireModulePath: string;
|
|
154
|
+
readonly createModuleId: (filePath: string) => number;
|
|
155
|
+
readonly dev: boolean;
|
|
156
|
+
readonly getRunModuleStatement: (moduleId: string | number) => string;
|
|
157
|
+
readonly includeAsyncPaths: boolean;
|
|
158
|
+
readonly inlineSourceMap?: boolean;
|
|
159
|
+
readonly modulesOnly: boolean;
|
|
160
|
+
readonly processModuleFilter: (module: Module<T>) => boolean;
|
|
161
|
+
readonly projectRoot: string;
|
|
162
|
+
readonly runBeforeMainModule: ReadonlyArray<string>;
|
|
163
|
+
readonly runModule: boolean;
|
|
164
|
+
readonly serverRoot: string;
|
|
165
|
+
readonly sourceMapUrl?: string;
|
|
166
|
+
readonly sourceUrl?: string;
|
|
167
|
+
}
|
|
@@ -23,7 +23,7 @@ export type MixedOutput = {
|
|
|
23
23
|
+type: string,
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
export type AsyncDependencyType = 'async' | 'prefetch';
|
|
26
|
+
export type AsyncDependencyType = 'async' | 'prefetch' | 'weak';
|
|
27
27
|
|
|
28
28
|
export type TransformResultDependency = {
|
|
29
29
|
/**
|
|
@@ -44,12 +44,6 @@ export type TransformResultDependency = {
|
|
|
44
44
|
* If not null, this dependency is due to a dynamic `import()` or `__prefetchImport()` call.
|
|
45
45
|
*/
|
|
46
46
|
+asyncType: AsyncDependencyType | null,
|
|
47
|
-
/**
|
|
48
|
-
* The condition for splitting on this dependency edge.
|
|
49
|
-
*/
|
|
50
|
-
+splitCondition?: {
|
|
51
|
-
+mobileConfigName: string,
|
|
52
|
-
},
|
|
53
47
|
/**
|
|
54
48
|
* The dependency is enclosed in a try/catch block.
|
|
55
49
|
*/
|