metro 0.76.0 → 0.76.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 +22 -24
- package/src/Asset.d.ts +25 -0
- package/src/Bundler.d.ts +39 -0
- package/src/DeltaBundler/Graph.d.ts +40 -0
- package/src/DeltaBundler/Serializers/baseJSBundle.js +1 -0
- package/src/DeltaBundler/Serializers/baseJSBundle.js.flow +1 -0
- package/src/DeltaBundler/Serializers/getRamBundleInfo.d.ts +18 -0
- package/src/DeltaBundler/Serializers/helpers/js.js +22 -6
- package/src/DeltaBundler/Serializers/helpers/js.js.flow +24 -6
- package/src/DeltaBundler/Serializers/helpers/processModules.js +2 -0
- package/src/DeltaBundler/Serializers/helpers/processModules.js.flow +3 -0
- package/src/DeltaBundler/Serializers/hmrJSBundle.js +1 -0
- package/src/DeltaBundler/Serializers/hmrJSBundle.js.flow +1 -0
- 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 +169 -0
- package/src/DeltaBundler.d.ts +58 -0
- package/src/HmrServer.js +1 -5
- package/src/HmrServer.js.flow +0 -5
- package/src/IncrementalBundler.d.ts +97 -0
- package/src/IncrementalBundler.js +1 -0
- package/src/IncrementalBundler.js.flow +1 -0
- package/src/ModuleGraph/worker/collectDependencies.d.ts +27 -0
- package/src/ModuleGraph/worker/collectDependencies.js +42 -25
- package/src/ModuleGraph/worker/collectDependencies.js.flow +41 -36
- package/src/Server/MultipartResponse.d.ts +31 -0
- package/src/Server/symbolicate.js +33 -5
- package/src/Server/symbolicate.js.flow +40 -9
- package/src/Server.d.ts +113 -0
- package/src/Server.js +16 -136
- package/src/Server.js.flow +16 -156
- 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 +11 -9
- 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 +161 -0
- package/src/index.flow.js +17 -4
- package/src/index.flow.js.flow +41 -10
- package/src/lib/CountingSet.d.ts +48 -0
- package/src/lib/TerminalReporter.d.ts +27 -0
- package/src/lib/TerminalReporter.js +1 -4
- package/src/lib/TerminalReporter.js.flow +1 -5
- package/src/lib/contextModule.d.ts +22 -0
- package/src/lib/getGraphId.d.ts +11 -0
- package/src/lib/getGraphId.js +0 -1
- package/src/lib/getGraphId.js.flow +0 -1
- package/src/lib/getPrependedScripts.js +0 -9
- package/src/lib/getPrependedScripts.js.flow +0 -9
- 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 +0 -1
- package/src/lib/transformHelpers.js.flow +0 -1
- package/src/node-haste/DependencyGraph/createHasteMap.js +0 -1
- package/src/node-haste/DependencyGraph/createHasteMap.js.flow +0 -1
- package/src/node-haste/DependencyGraph.d.ts +59 -0
- package/src/node-haste/DependencyGraph.js +7 -1
- package/src/node-haste/DependencyGraph.js.flow +8 -1
- 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 -2
- 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.76.
|
|
3
|
+
"version": "0.76.2",
|
|
4
4
|
"description": "🚇 The JavaScript bundler for React Native.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": "src/cli.js",
|
|
@@ -34,23 +34,22 @@
|
|
|
34
34
|
"invariant": "^2.2.4",
|
|
35
35
|
"jest-worker": "^27.2.0",
|
|
36
36
|
"lodash.throttle": "^4.1.1",
|
|
37
|
-
"metro-babel-transformer": "0.76.
|
|
38
|
-
"metro-cache": "0.76.
|
|
39
|
-
"metro-cache-key": "0.76.
|
|
40
|
-
"metro-config": "0.76.
|
|
41
|
-
"metro-core": "0.76.
|
|
42
|
-
"metro-file-map": "0.76.
|
|
43
|
-
"metro-
|
|
44
|
-
"metro-
|
|
45
|
-
"metro-minify-
|
|
46
|
-
"metro-
|
|
47
|
-
"metro-
|
|
48
|
-
"metro-
|
|
49
|
-
"metro-
|
|
50
|
-
"metro-
|
|
51
|
-
"metro-
|
|
52
|
-
"metro-transform-
|
|
53
|
-
"metro-transform-worker": "0.76.0",
|
|
37
|
+
"metro-babel-transformer": "0.76.2",
|
|
38
|
+
"metro-cache": "0.76.2",
|
|
39
|
+
"metro-cache-key": "0.76.2",
|
|
40
|
+
"metro-config": "0.76.2",
|
|
41
|
+
"metro-core": "0.76.2",
|
|
42
|
+
"metro-file-map": "0.76.2",
|
|
43
|
+
"metro-inspector-proxy": "0.76.2",
|
|
44
|
+
"metro-minify-terser": "0.76.2",
|
|
45
|
+
"metro-minify-uglify": "0.76.2",
|
|
46
|
+
"metro-react-native-babel-preset": "0.76.2",
|
|
47
|
+
"metro-resolver": "0.76.2",
|
|
48
|
+
"metro-runtime": "0.76.2",
|
|
49
|
+
"metro-source-map": "0.76.2",
|
|
50
|
+
"metro-symbolicate": "0.76.2",
|
|
51
|
+
"metro-transform-plugins": "0.76.2",
|
|
52
|
+
"metro-transform-worker": "0.76.2",
|
|
54
53
|
"mime-types": "^2.1.27",
|
|
55
54
|
"node-fetch": "^2.2.0",
|
|
56
55
|
"nullthrows": "^1.1.1",
|
|
@@ -58,10 +57,9 @@
|
|
|
58
57
|
"serialize-error": "^2.1.0",
|
|
59
58
|
"source-map": "^0.5.6",
|
|
60
59
|
"strip-ansi": "^6.0.0",
|
|
61
|
-
"temp": "0.8.3",
|
|
62
60
|
"throat": "^5.0.0",
|
|
63
61
|
"ws": "^7.5.1",
|
|
64
|
-
"yargs": "^17.
|
|
62
|
+
"yargs": "^17.6.2"
|
|
65
63
|
},
|
|
66
64
|
"devDependencies": {
|
|
67
65
|
"@babel/plugin-transform-flow-strip-types": "^7.0.0",
|
|
@@ -69,10 +67,10 @@
|
|
|
69
67
|
"dedent": "^0.7.0",
|
|
70
68
|
"jest-snapshot": "^26.5.2",
|
|
71
69
|
"jest-snapshot-serializer-raw": "^1.2.0",
|
|
72
|
-
"metro-babel-register": "0.76.
|
|
73
|
-
"metro-memory-fs": "0.76.
|
|
74
|
-
"metro-react-native-babel-preset": "0.76.
|
|
75
|
-
"metro-react-native-babel-transformer": "0.76.
|
|
70
|
+
"metro-babel-register": "0.76.2",
|
|
71
|
+
"metro-memory-fs": "0.76.2",
|
|
72
|
+
"metro-react-native-babel-preset": "0.76.2",
|
|
73
|
+
"metro-react-native-babel-transformer": "0.76.2",
|
|
76
74
|
"mock-req": "^0.2.0",
|
|
77
75
|
"mock-res": "^0.6.0",
|
|
78
76
|
"stack-trace": "^0.0.10"
|
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/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
|
+
}
|
|
@@ -24,6 +24,7 @@ function baseJSBundle(entryPoint, preModules, graph, options) {
|
|
|
24
24
|
includeAsyncPaths: options.includeAsyncPaths,
|
|
25
25
|
projectRoot: options.projectRoot,
|
|
26
26
|
serverRoot: options.serverRoot,
|
|
27
|
+
sourceUrl: options.sourceUrl,
|
|
27
28
|
};
|
|
28
29
|
|
|
29
30
|
// Do not prepend polyfills or the require runtime when only modules are requested
|
|
@@ -39,6 +39,7 @@ function baseJSBundle(
|
|
|
39
39
|
includeAsyncPaths: options.includeAsyncPaths,
|
|
40
40
|
projectRoot: options.projectRoot,
|
|
41
41
|
serverRoot: options.serverRoot,
|
|
42
|
+
sourceUrl: options.sourceUrl,
|
|
42
43
|
};
|
|
43
44
|
|
|
44
45
|
// Do not prepend polyfills or the require runtime when only modules are requested
|
|
@@ -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
|
+
}
|
|
@@ -31,16 +31,32 @@ function getModuleParams(module, options) {
|
|
|
31
31
|
const id = options.createModuleId(dependency.absolutePath);
|
|
32
32
|
if (options.includeAsyncPaths && dependency.data.data.asyncType != null) {
|
|
33
33
|
hasPaths = true;
|
|
34
|
+
invariant(
|
|
35
|
+
options.sourceUrl != null,
|
|
36
|
+
"sourceUrl is required when includeAsyncPaths is true"
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
// TODO: Only include path if the target is not in the bundle
|
|
40
|
+
|
|
41
|
+
// Construct a server-relative URL for the split bundle, propagating
|
|
42
|
+
// most parameters from the main bundle's URL.
|
|
43
|
+
|
|
44
|
+
const { searchParams } = new URL(options.sourceUrl);
|
|
45
|
+
searchParams.set("modulesOnly", "true");
|
|
46
|
+
searchParams.set("runModule", "false");
|
|
34
47
|
const bundlePath = path.relative(
|
|
35
48
|
options.serverRoot,
|
|
36
49
|
dependency.absolutePath
|
|
37
50
|
);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
51
|
+
paths[id] =
|
|
52
|
+
"/" +
|
|
53
|
+
path.join(
|
|
54
|
+
path.dirname(bundlePath),
|
|
55
|
+
// Strip the file extension
|
|
56
|
+
path.basename(bundlePath, path.extname(bundlePath))
|
|
57
|
+
) +
|
|
58
|
+
".bundle?" +
|
|
59
|
+
searchParams.toString();
|
|
44
60
|
}
|
|
45
61
|
return id;
|
|
46
62
|
}
|
|
@@ -24,6 +24,7 @@ export type Options = $ReadOnly<{
|
|
|
24
24
|
includeAsyncPaths: boolean,
|
|
25
25
|
projectRoot: string,
|
|
26
26
|
serverRoot: string,
|
|
27
|
+
sourceUrl: ?string,
|
|
27
28
|
...
|
|
28
29
|
}>;
|
|
29
30
|
|
|
@@ -48,16 +49,33 @@ function getModuleParams(module: Module<>, options: Options): Array<mixed> {
|
|
|
48
49
|
const id = options.createModuleId(dependency.absolutePath);
|
|
49
50
|
if (options.includeAsyncPaths && dependency.data.data.asyncType != null) {
|
|
50
51
|
hasPaths = true;
|
|
52
|
+
invariant(
|
|
53
|
+
options.sourceUrl != null,
|
|
54
|
+
'sourceUrl is required when includeAsyncPaths is true',
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
// TODO: Only include path if the target is not in the bundle
|
|
58
|
+
|
|
59
|
+
// Construct a server-relative URL for the split bundle, propagating
|
|
60
|
+
// most parameters from the main bundle's URL.
|
|
61
|
+
|
|
62
|
+
const {searchParams} = new URL(options.sourceUrl);
|
|
63
|
+
searchParams.set('modulesOnly', 'true');
|
|
64
|
+
searchParams.set('runModule', 'false');
|
|
65
|
+
|
|
51
66
|
const bundlePath = path.relative(
|
|
52
67
|
options.serverRoot,
|
|
53
68
|
dependency.absolutePath,
|
|
54
69
|
);
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
70
|
+
paths[id] =
|
|
71
|
+
'/' +
|
|
72
|
+
path.join(
|
|
73
|
+
path.dirname(bundlePath),
|
|
74
|
+
// Strip the file extension
|
|
75
|
+
path.basename(bundlePath, path.extname(bundlePath)),
|
|
76
|
+
) +
|
|
77
|
+
'.bundle?' +
|
|
78
|
+
searchParams.toString();
|
|
61
79
|
}
|
|
62
80
|
return id;
|
|
63
81
|
},
|
|
@@ -21,6 +21,7 @@ function processModules(
|
|
|
21
21
|
includeAsyncPaths,
|
|
22
22
|
projectRoot,
|
|
23
23
|
serverRoot,
|
|
24
|
+
sourceUrl,
|
|
24
25
|
}
|
|
25
26
|
) {
|
|
26
27
|
return [...modules]
|
|
@@ -34,6 +35,7 @@ function processModules(
|
|
|
34
35
|
includeAsyncPaths,
|
|
35
36
|
projectRoot,
|
|
36
37
|
serverRoot,
|
|
38
|
+
sourceUrl,
|
|
37
39
|
}),
|
|
38
40
|
]);
|
|
39
41
|
}
|
|
@@ -24,6 +24,7 @@ function processModules(
|
|
|
24
24
|
includeAsyncPaths,
|
|
25
25
|
projectRoot,
|
|
26
26
|
serverRoot,
|
|
27
|
+
sourceUrl,
|
|
27
28
|
}: $ReadOnly<{
|
|
28
29
|
filter?: (module: Module<>) => boolean,
|
|
29
30
|
createModuleId: string => number,
|
|
@@ -31,6 +32,7 @@ function processModules(
|
|
|
31
32
|
includeAsyncPaths: boolean,
|
|
32
33
|
projectRoot: string,
|
|
33
34
|
serverRoot: string,
|
|
35
|
+
sourceUrl: ?string,
|
|
34
36
|
}>,
|
|
35
37
|
): $ReadOnlyArray<[Module<>, string]> {
|
|
36
38
|
return [...modules]
|
|
@@ -44,6 +46,7 @@ function processModules(
|
|
|
44
46
|
includeAsyncPaths,
|
|
45
47
|
projectRoot,
|
|
46
48
|
serverRoot,
|
|
49
|
+
sourceUrl,
|
|
47
50
|
}),
|
|
48
51
|
]);
|
|
49
52
|
}
|
|
@@ -50,6 +50,7 @@ function generateModules(sourceModules, graph, options) {
|
|
|
50
50
|
function prepareModule(module, graph, options) {
|
|
51
51
|
const code = wrapModule(module, {
|
|
52
52
|
...options,
|
|
53
|
+
sourceUrl: url.format(options.clientUrl),
|
|
53
54
|
dev: true,
|
|
54
55
|
});
|
|
55
56
|
const inverseDependencies = getInverseDependencies(module.path, graph);
|
|
@@ -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,169 @@
|
|
|
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 {JsTransformOptions} from 'metro-transform-worker';
|
|
12
|
+
import type {RequireContextParams} from '../ModuleGraph/worker/collectDependencies';
|
|
13
|
+
import type {RequireContext} from '../lib/contextModule';
|
|
14
|
+
import type CountingSet from '../lib/CountingSet';
|
|
15
|
+
import type {Graph} from './Graph';
|
|
16
|
+
|
|
17
|
+
export interface MixedOutput {
|
|
18
|
+
readonly data: {code: string};
|
|
19
|
+
readonly type: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type AsyncDependencyType = 'async' | 'prefetch';
|
|
23
|
+
|
|
24
|
+
export interface TransformResultDependency {
|
|
25
|
+
/**
|
|
26
|
+
* The literal name provided to a require or import call. For example 'foo' in
|
|
27
|
+
* case of `require('foo')`.
|
|
28
|
+
*/
|
|
29
|
+
readonly name: string;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Extra data returned by the dependency extractor.
|
|
33
|
+
*/
|
|
34
|
+
readonly data: {
|
|
35
|
+
/**
|
|
36
|
+
* A locally unique key for this dependency within the current module.
|
|
37
|
+
*/
|
|
38
|
+
readonly key: string;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* If not null, this dependency is due to a dynamic `import()` or `__prefetchImport()` call.
|
|
42
|
+
*/
|
|
43
|
+
readonly asyncType: AsyncDependencyType | null;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The condition for splitting on this dependency edge.
|
|
47
|
+
*/
|
|
48
|
+
readonly splitCondition?: {
|
|
49
|
+
readonly mobileConfigName: string;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The dependency is enclosed in a try/catch block.
|
|
54
|
+
*/
|
|
55
|
+
readonly isOptional?: boolean;
|
|
56
|
+
|
|
57
|
+
readonly locs: ReadonlyArray<{
|
|
58
|
+
readonly start: {readonly line: number; readonly column: number};
|
|
59
|
+
readonly end: {readonly line: number; readonly column: number};
|
|
60
|
+
}>;
|
|
61
|
+
|
|
62
|
+
/** Context for requiring a collection of modules. */
|
|
63
|
+
readonly contextParams?: RequireContextParams;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface Dependency {
|
|
68
|
+
readonly absolutePath: string;
|
|
69
|
+
readonly data: TransformResultDependency;
|
|
70
|
+
[key: string]: unknown;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface Module<T = MixedOutput> {
|
|
74
|
+
readonly dependencies: Map<string, Dependency>;
|
|
75
|
+
readonly inverseDependencies: CountingSet<string>;
|
|
76
|
+
readonly output: ReadonlyArray<T>;
|
|
77
|
+
readonly path: string;
|
|
78
|
+
readonly getSource: () => Buffer;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export type Dependencies<T = MixedOutput> = Map<string, Module<T>>;
|
|
82
|
+
export type ReadOnlyDependencies<T = MixedOutput> = ReadonlyMap<
|
|
83
|
+
string,
|
|
84
|
+
Module<T>
|
|
85
|
+
>;
|
|
86
|
+
|
|
87
|
+
export type TransformInputOptions = Omit<
|
|
88
|
+
JsTransformOptions,
|
|
89
|
+
'inlinePlatform' | 'inlineRequires'
|
|
90
|
+
>;
|
|
91
|
+
|
|
92
|
+
export type GraphInputOptions = Readonly<{
|
|
93
|
+
entryPoints: ReadonlySet<string>;
|
|
94
|
+
// Unused in core but useful for custom serializers / experimentalSerializerHook
|
|
95
|
+
transformOptions: TransformInputOptions;
|
|
96
|
+
}>;
|
|
97
|
+
|
|
98
|
+
export interface ReadOnlyGraph<T = MixedOutput> {
|
|
99
|
+
readonly entryPoints: ReadonlySet<string>;
|
|
100
|
+
// Unused in core but useful for custom serializers / experimentalSerializerHook
|
|
101
|
+
readonly transformOptions: Readonly<TransformInputOptions>;
|
|
102
|
+
readonly dependencies: ReadOnlyDependencies<T>;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export type {Graph};
|
|
106
|
+
|
|
107
|
+
export interface TransformResult<T = MixedOutput> {
|
|
108
|
+
dependencies: ReadonlyArray<TransformResultDependency>;
|
|
109
|
+
output: ReadonlyArray<T>;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface TransformResultWithSource<T = MixedOutput>
|
|
113
|
+
extends TransformResult<T> {
|
|
114
|
+
getSource: () => Buffer;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export type TransformFn<T = MixedOutput> = (
|
|
118
|
+
modulePath: string,
|
|
119
|
+
requireContext: RequireContext | null,
|
|
120
|
+
) => Promise<TransformResultWithSource<T>>;
|
|
121
|
+
|
|
122
|
+
export interface AllowOptionalDependenciesWithOptions {
|
|
123
|
+
readonly exclude: string[];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export type AllowOptionalDependencies =
|
|
127
|
+
| boolean
|
|
128
|
+
| AllowOptionalDependenciesWithOptions;
|
|
129
|
+
|
|
130
|
+
export interface BundlerResolution {
|
|
131
|
+
readonly type: 'sourceFile';
|
|
132
|
+
readonly filePath: string;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface Options<T = MixedOutput> {
|
|
136
|
+
readonly resolve: (from: string, to: string) => string;
|
|
137
|
+
readonly transform: TransformFn<T>;
|
|
138
|
+
readonly transformOptions: TransformInputOptions;
|
|
139
|
+
readonly onProgress:
|
|
140
|
+
| ((numProcessed: number, total: number) => unknown)
|
|
141
|
+
| null;
|
|
142
|
+
readonly experimentalImportBundleSupport: boolean;
|
|
143
|
+
readonly unstable_allowRequireContext: boolean;
|
|
144
|
+
readonly shallow: boolean;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export interface DeltaResult<T = MixedOutput> {
|
|
148
|
+
readonly added: Map<string, Module<T>>;
|
|
149
|
+
readonly modified: Map<string, Module<T>>;
|
|
150
|
+
readonly deleted: Set<string>;
|
|
151
|
+
readonly reset: boolean;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export interface SerializerOptions<T = MixedOutput> {
|
|
155
|
+
readonly asyncRequireModulePath: string;
|
|
156
|
+
readonly createModuleId: (filePath: string) => number;
|
|
157
|
+
readonly dev: boolean;
|
|
158
|
+
readonly getRunModuleStatement: (moduleId: string | number) => string;
|
|
159
|
+
readonly includeAsyncPaths: boolean;
|
|
160
|
+
readonly inlineSourceMap?: boolean;
|
|
161
|
+
readonly modulesOnly: boolean;
|
|
162
|
+
readonly processModuleFilter: (module: Module<T>) => boolean;
|
|
163
|
+
readonly projectRoot: string;
|
|
164
|
+
readonly runBeforeMainModule: ReadonlyArray<string>;
|
|
165
|
+
readonly runModule: boolean;
|
|
166
|
+
readonly serverRoot: string;
|
|
167
|
+
readonly sourceMapUrl?: string;
|
|
168
|
+
readonly sourceUrl?: string;
|
|
169
|
+
}
|