metro 0.76.0 → 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 +24 -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/getRamBundleInfo.d.ts +18 -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 +167 -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.d.ts +113 -0
- package/src/Server.js +11 -133
- 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 +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 +151 -0
- package/src/index.flow.js +8 -2
- package/src/index.flow.js.flow +18 -6
- 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 +1 -0
- package/src/node-haste/DependencyGraph.js.flow +1 -0
- 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.76.
|
|
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",
|
|
@@ -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.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",
|
|
54
53
|
"mime-types": "^2.1.27",
|
|
55
54
|
"node-fetch": "^2.2.0",
|
|
56
55
|
"nullthrows": "^1.1.1",
|
|
@@ -58,21 +57,22 @@
|
|
|
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",
|
|
66
|
+
"@types/babel__code-frame": "^7.0.3",
|
|
67
|
+
"@types/ws": "^8.5.4",
|
|
68
68
|
"babel-jest": "^29.2.1",
|
|
69
69
|
"dedent": "^0.7.0",
|
|
70
70
|
"jest-snapshot": "^26.5.2",
|
|
71
71
|
"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.
|
|
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",
|
|
76
76
|
"mock-req": "^0.2.0",
|
|
77
77
|
"mock-res": "^0.6.0",
|
|
78
78
|
"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
|
+
}
|
|
@@ -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,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
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
DeltaResult,
|
|
13
|
+
Graph,
|
|
14
|
+
MixedOutput,
|
|
15
|
+
Options,
|
|
16
|
+
ReadOnlyGraph,
|
|
17
|
+
} from './DeltaBundler/types';
|
|
18
|
+
import type {EventEmitter} from 'events';
|
|
19
|
+
|
|
20
|
+
export type {
|
|
21
|
+
DeltaResult,
|
|
22
|
+
Graph,
|
|
23
|
+
Dependencies,
|
|
24
|
+
MixedOutput,
|
|
25
|
+
Module,
|
|
26
|
+
ReadOnlyGraph,
|
|
27
|
+
TransformFn,
|
|
28
|
+
TransformResult,
|
|
29
|
+
TransformResultDependency,
|
|
30
|
+
TransformResultWithSource,
|
|
31
|
+
} from './DeltaBundler/types';
|
|
32
|
+
|
|
33
|
+
export default class DeltaBundler<T = MixedOutput> {
|
|
34
|
+
constructor(changeEventSource: EventEmitter);
|
|
35
|
+
end(): void;
|
|
36
|
+
getDependencies(
|
|
37
|
+
entryPoints: ReadonlyArray<string>,
|
|
38
|
+
options: Options<T>,
|
|
39
|
+
): Promise<ReadOnlyGraph<T>['dependencies']>;
|
|
40
|
+
buildGraph(
|
|
41
|
+
entryPoints: ReadonlyArray<string>,
|
|
42
|
+
options: Options<T>,
|
|
43
|
+
): Promise<Graph<T>>;
|
|
44
|
+
|
|
45
|
+
getDelta(
|
|
46
|
+
graph: Graph<T>,
|
|
47
|
+
{
|
|
48
|
+
reset,
|
|
49
|
+
shallow,
|
|
50
|
+
}: {
|
|
51
|
+
reset: boolean;
|
|
52
|
+
shallow: boolean;
|
|
53
|
+
},
|
|
54
|
+
): Promise<DeltaResult<T>>;
|
|
55
|
+
|
|
56
|
+
listen(graph: Graph<T>, callback: () => Promise<void>): () => void;
|
|
57
|
+
endGraph(graph: Graph<T>): void;
|
|
58
|
+
}
|
package/src/HmrServer.js
CHANGED
|
@@ -24,9 +24,6 @@ const {
|
|
|
24
24
|
} = require("metro-core");
|
|
25
25
|
const nullthrows = require("nullthrows");
|
|
26
26
|
const url = require("url");
|
|
27
|
-
function getBytecodeVersion() {
|
|
28
|
-
return require("metro-hermes-compiler").VERSION;
|
|
29
|
-
}
|
|
30
27
|
function send(sendFns, message) {
|
|
31
28
|
const strMessage = JSON.stringify(message);
|
|
32
29
|
sendFns.forEach((sendFn) => sendFn(strMessage));
|
|
@@ -60,8 +57,7 @@ class HmrServer {
|
|
|
60
57
|
const clientUrl = nullthrows(url.parse(requestUrl, true));
|
|
61
58
|
const options = parseOptionsFromUrl(
|
|
62
59
|
requestUrl,
|
|
63
|
-
new Set(this._config.resolver.platforms)
|
|
64
|
-
getBytecodeVersion()
|
|
60
|
+
new Set(this._config.resolver.platforms)
|
|
65
61
|
);
|
|
66
62
|
const { entryFile, resolverOptions, transformOptions, graphOptions } =
|
|
67
63
|
splitBundleOptions(options);
|
package/src/HmrServer.js.flow
CHANGED
|
@@ -50,10 +50,6 @@ type ClientGroup = {
|
|
|
50
50
|
+unlisten: () => void,
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
-
function getBytecodeVersion() {
|
|
54
|
-
return require('metro-hermes-compiler').VERSION;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
53
|
function send(sendFns: Array<(string) => void>, message: HmrMessage): void {
|
|
58
54
|
const strMessage = JSON.stringify(message);
|
|
59
55
|
sendFns.forEach((sendFn: string => void) => sendFn(strMessage));
|
|
@@ -106,7 +102,6 @@ class HmrServer<TClient: Client> {
|
|
|
106
102
|
const options = parseOptionsFromUrl(
|
|
107
103
|
requestUrl,
|
|
108
104
|
new Set(this._config.resolver.platforms),
|
|
109
|
-
getBytecodeVersion(),
|
|
110
105
|
);
|
|
111
106
|
const {entryFile, resolverOptions, transformOptions, graphOptions} =
|
|
112
107
|
splitBundleOptions(options);
|
|
@@ -0,0 +1,97 @@
|
|
|
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
|
+
Options as DeltaBundlerOptions,
|
|
13
|
+
ReadOnlyDependencies,
|
|
14
|
+
TransformInputOptions,
|
|
15
|
+
} from './DeltaBundler/types';
|
|
16
|
+
import {ResolverInputOptions} from './shared/types';
|
|
17
|
+
import type {ConfigT} from 'metro-config';
|
|
18
|
+
import type {GraphId} from './lib/getGraphId';
|
|
19
|
+
import DeltaBundler, {DeltaResult, Graph, Module} from './DeltaBundler';
|
|
20
|
+
import type Bundler from './Bundler';
|
|
21
|
+
|
|
22
|
+
export type RevisionId = string;
|
|
23
|
+
|
|
24
|
+
export type OutputGraph = Graph<void>;
|
|
25
|
+
|
|
26
|
+
export interface OtherOptions {
|
|
27
|
+
readonly onProgress: DeltaBundlerOptions<void>['onProgress'];
|
|
28
|
+
readonly shallow: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface GraphRevision {
|
|
32
|
+
readonly id: RevisionId;
|
|
33
|
+
readonly date: Date;
|
|
34
|
+
readonly graphId: GraphId;
|
|
35
|
+
readonly graph: OutputGraph;
|
|
36
|
+
readonly prepend: ReadonlyArray<Module<void>>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface IncrementalBundlerOptions {
|
|
40
|
+
readonly hasReducedPerformance?: boolean;
|
|
41
|
+
readonly watch?: boolean;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export default class IncrementalBundler {
|
|
45
|
+
static revisionIdFromString: (str: string) => RevisionId;
|
|
46
|
+
constructor(config: ConfigT, options?: IncrementalBundlerOptions);
|
|
47
|
+
|
|
48
|
+
end(): void;
|
|
49
|
+
getBundler(): Bundler;
|
|
50
|
+
getDeltaBundler(): DeltaBundler<void>;
|
|
51
|
+
getRevision(revisionId: RevisionId): Promise<GraphRevision> | null;
|
|
52
|
+
getRevisionByGraphId(graphId: GraphId): Promise<GraphRevision> | null;
|
|
53
|
+
|
|
54
|
+
buildGraphForEntries(
|
|
55
|
+
entryFiles: ReadonlyArray<string>,
|
|
56
|
+
transformOptions: TransformInputOptions,
|
|
57
|
+
resolverOptions: ResolverInputOptions,
|
|
58
|
+
otherOptions?: OtherOptions,
|
|
59
|
+
): Promise<OutputGraph>;
|
|
60
|
+
|
|
61
|
+
getDependencies(
|
|
62
|
+
entryFiles: ReadonlyArray<string>,
|
|
63
|
+
transformOptions: TransformInputOptions,
|
|
64
|
+
resolverOptions: ResolverInputOptions,
|
|
65
|
+
otherOptions?: OtherOptions,
|
|
66
|
+
): Promise<ReadOnlyDependencies<void>>;
|
|
67
|
+
|
|
68
|
+
buildGraph(
|
|
69
|
+
entryFile: string,
|
|
70
|
+
transformOptions: TransformInputOptions,
|
|
71
|
+
resolverOptions: ResolverInputOptions,
|
|
72
|
+
otherOptions?: OtherOptions,
|
|
73
|
+
): Promise<
|
|
74
|
+
Readonly<{graph: OutputGraph; prepend: ReadonlyArray<Module<void>>}>
|
|
75
|
+
>;
|
|
76
|
+
|
|
77
|
+
initializeGraph(
|
|
78
|
+
entryFile: string,
|
|
79
|
+
transformOptions: TransformInputOptions,
|
|
80
|
+
resolverOptions: ResolverInputOptions,
|
|
81
|
+
otherOptions?: OtherOptions,
|
|
82
|
+
): Promise<{
|
|
83
|
+
delta: DeltaResult<void>;
|
|
84
|
+
revision: GraphRevision;
|
|
85
|
+
}>;
|
|
86
|
+
|
|
87
|
+
updateGraph(
|
|
88
|
+
revision: GraphRevision,
|
|
89
|
+
reset: boolean,
|
|
90
|
+
): Promise<{
|
|
91
|
+
delta: DeltaResult<void>;
|
|
92
|
+
revision: GraphRevision;
|
|
93
|
+
}>;
|
|
94
|
+
|
|
95
|
+
endGraph(graphId: GraphId): Promise<void>;
|
|
96
|
+
ready(): Promise<void>;
|
|
97
|
+
}
|