metro 0.72.1 → 0.72.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 +23 -21
- package/src/DeltaBundler/Serializers/baseBytecodeBundle.js +3 -2
- package/src/DeltaBundler/Serializers/baseBytecodeBundle.js.flow +2 -1
- package/src/DeltaBundler/Serializers/helpers/bytecode.js +2 -2
- package/src/DeltaBundler/Serializers/helpers/bytecode.js.flow +2 -1
- package/src/DeltaBundler.js.flow +1 -1
- package/src/HmrServer.js +9 -5
- package/src/HmrServer.js.flow +9 -4
- package/src/IncrementalBundler.js +16 -4
- package/src/IncrementalBundler.js.flow +17 -4
- package/src/ModuleGraph/node-haste/Package.js.flow +5 -5
- package/src/ModuleGraph/node-haste/node-haste.js +8 -4
- package/src/ModuleGraph/node-haste/node-haste.js.flow +21 -14
- package/src/ModuleGraph/output/util.js +2 -4
- package/src/ModuleGraph/output/util.js.flow +1 -2
- package/src/ModuleGraph/types.flow.js.flow +28 -5
- package/src/Server.js +86 -34
- package/src/Server.js.flow +106 -36
- package/src/index.flow.js +16 -8
- package/src/index.flow.js.flow +14 -8
- package/src/lib/RamBundleParser.js +1 -0
- package/src/lib/RamBundleParser.js.flow +1 -0
- package/src/lib/bundleToBytecode.js +3 -2
- package/src/lib/bundleToBytecode.js.flow +2 -2
- package/src/lib/getGraphId.js +16 -3
- package/src/lib/getGraphId.js.flow +10 -10
- package/src/lib/getPrependedScripts.js +13 -5
- package/src/lib/getPrependedScripts.js.flow +6 -1
- package/src/lib/parseCustomResolverOptions.js +26 -0
- package/src/lib/parseCustomResolverOptions.js.flow +38 -0
- package/src/lib/parseOptionsFromUrl.js +3 -0
- package/src/lib/parseOptionsFromUrl.js.flow +2 -0
- package/src/lib/splitBundleOptions.js +3 -0
- package/src/lib/splitBundleOptions.js.flow +3 -0
- package/src/lib/transformHelpers.js +27 -13
- package/src/lib/transformHelpers.js.flow +27 -7
- package/src/node-haste/DependencyGraph/ModuleResolution.js +18 -2
- package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +5 -0
- package/src/node-haste/DependencyGraph.js +34 -9
- package/src/node-haste/DependencyGraph.js.flow +49 -11
- package/src/node-haste/Module.js +1 -0
- package/src/node-haste/Module.js.flow +1 -0
- package/src/shared/types.flow.js.flow +7 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "metro",
|
|
3
|
-
"version": "0.72.
|
|
3
|
+
"version": "0.72.2",
|
|
4
4
|
"description": "🚇 The JavaScript bundler for React Native.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": "src/cli.js",
|
|
@@ -36,22 +36,22 @@
|
|
|
36
36
|
"invariant": "^2.2.4",
|
|
37
37
|
"jest-worker": "^27.2.0",
|
|
38
38
|
"lodash.throttle": "^4.1.1",
|
|
39
|
-
"metro-babel-transformer": "0.72.
|
|
40
|
-
"metro-cache": "0.72.
|
|
41
|
-
"metro-cache-key": "0.72.
|
|
42
|
-
"metro-config": "0.72.
|
|
43
|
-
"metro-core": "0.72.
|
|
44
|
-
"metro-file-map": "0.72.
|
|
45
|
-
"metro-hermes-compiler": "0.72.
|
|
46
|
-
"metro-inspector-proxy": "0.72.
|
|
47
|
-
"metro-minify-uglify": "0.72.
|
|
48
|
-
"metro-react-native-babel-preset": "0.72.
|
|
49
|
-
"metro-resolver": "0.72.
|
|
50
|
-
"metro-runtime": "0.72.
|
|
51
|
-
"metro-source-map": "0.72.
|
|
52
|
-
"metro-symbolicate": "0.72.
|
|
53
|
-
"metro-transform-plugins": "0.72.
|
|
54
|
-
"metro-transform-worker": "0.72.
|
|
39
|
+
"metro-babel-transformer": "0.72.2",
|
|
40
|
+
"metro-cache": "0.72.2",
|
|
41
|
+
"metro-cache-key": "0.72.2",
|
|
42
|
+
"metro-config": "0.72.2",
|
|
43
|
+
"metro-core": "0.72.2",
|
|
44
|
+
"metro-file-map": "0.72.2",
|
|
45
|
+
"metro-hermes-compiler": "0.72.2",
|
|
46
|
+
"metro-inspector-proxy": "0.72.2",
|
|
47
|
+
"metro-minify-uglify": "0.72.2",
|
|
48
|
+
"metro-react-native-babel-preset": "0.72.2",
|
|
49
|
+
"metro-resolver": "0.72.2",
|
|
50
|
+
"metro-runtime": "0.72.2",
|
|
51
|
+
"metro-source-map": "0.72.2",
|
|
52
|
+
"metro-symbolicate": "0.72.2",
|
|
53
|
+
"metro-transform-plugins": "0.72.2",
|
|
54
|
+
"metro-transform-worker": "0.72.2",
|
|
55
55
|
"mime-types": "^2.1.27",
|
|
56
56
|
"node-fetch": "^2.2.0",
|
|
57
57
|
"nullthrows": "^1.1.1",
|
|
@@ -70,10 +70,12 @@
|
|
|
70
70
|
"babel-jest": "^26.6.3",
|
|
71
71
|
"dedent": "^0.7.0",
|
|
72
72
|
"jest-snapshot": "^26.5.2",
|
|
73
|
-
"metro-babel-register": "0.72.
|
|
74
|
-
"metro-memory-fs": "0.72.
|
|
75
|
-
"metro-react-native-babel-preset": "0.72.
|
|
76
|
-
"metro-react-native-babel-transformer": "0.72.
|
|
73
|
+
"metro-babel-register": "0.72.2",
|
|
74
|
+
"metro-memory-fs": "0.72.2",
|
|
75
|
+
"metro-react-native-babel-preset": "0.72.2",
|
|
76
|
+
"metro-react-native-babel-transformer": "0.72.2",
|
|
77
|
+
"mock-req": "^0.2.0",
|
|
78
|
+
"mock-res": "^0.6.0",
|
|
77
79
|
"stack-trace": "^0.0.10"
|
|
78
80
|
},
|
|
79
81
|
"license": "MIT"
|
|
@@ -15,8 +15,6 @@ const { getJsOutput } = require("./helpers/js");
|
|
|
15
15
|
|
|
16
16
|
const processBytecodeModules = require("./helpers/processBytecodeModules");
|
|
17
17
|
|
|
18
|
-
const { compile } = require("metro-hermes-compiler");
|
|
19
|
-
|
|
20
18
|
function baseBytecodeBundle(entryPoint, preModules, graph, options) {
|
|
21
19
|
for (const module of graph.dependencies.values()) {
|
|
22
20
|
options.createModuleId(module.path);
|
|
@@ -36,6 +34,9 @@ function baseBytecodeBundle(entryPoint, preModules, graph, options) {
|
|
|
36
34
|
const modules = [...graph.dependencies.values()].sort(
|
|
37
35
|
(a, b) => options.createModuleId(a.path) - options.createModuleId(b.path)
|
|
38
36
|
);
|
|
37
|
+
|
|
38
|
+
const { compile } = require("metro-hermes-compiler");
|
|
39
|
+
|
|
39
40
|
const post = processBytecodeModules(
|
|
40
41
|
getAppendScripts(
|
|
41
42
|
entryPoint,
|
|
@@ -21,7 +21,6 @@ import type {BytecodeBundle} from 'metro-runtime/src/modules/types.flow';
|
|
|
21
21
|
const getAppendScripts = require('../../lib/getAppendScripts');
|
|
22
22
|
const {getJsOutput} = require('./helpers/js');
|
|
23
23
|
const processBytecodeModules = require('./helpers/processBytecodeModules');
|
|
24
|
-
const {compile} = require('metro-hermes-compiler');
|
|
25
24
|
|
|
26
25
|
function baseBytecodeBundle(
|
|
27
26
|
entryPoint: string,
|
|
@@ -50,6 +49,8 @@ function baseBytecodeBundle(
|
|
|
50
49
|
options.createModuleId(a.path) - options.createModuleId(b.path),
|
|
51
50
|
);
|
|
52
51
|
|
|
52
|
+
const {compile} = require('metro-hermes-compiler');
|
|
53
|
+
|
|
53
54
|
const post = processBytecodeModules(
|
|
54
55
|
getAppendScripts(
|
|
55
56
|
entryPoint,
|
|
@@ -11,8 +11,6 @@
|
|
|
11
11
|
|
|
12
12
|
const invariant = require("invariant");
|
|
13
13
|
|
|
14
|
-
const { compile } = require("metro-hermes-compiler");
|
|
15
|
-
|
|
16
14
|
const path = require("path");
|
|
17
15
|
|
|
18
16
|
function wrapModule(module, options) {
|
|
@@ -39,6 +37,8 @@ function wrapModule(module, options) {
|
|
|
39
37
|
);
|
|
40
38
|
}
|
|
41
39
|
|
|
40
|
+
const { compile } = require("metro-hermes-compiler");
|
|
41
|
+
|
|
42
42
|
const headerCode = `globalThis.$$METRO_D=[${params.join(",")}];`;
|
|
43
43
|
return [
|
|
44
44
|
compile(headerCode, {
|
|
@@ -14,7 +14,6 @@ import type {Module} from '../../types.flow';
|
|
|
14
14
|
import type {BytecodeOutput} from 'metro-transform-worker';
|
|
15
15
|
|
|
16
16
|
const invariant = require('invariant');
|
|
17
|
-
const {compile} = require('metro-hermes-compiler');
|
|
18
17
|
const path = require('path');
|
|
19
18
|
|
|
20
19
|
export type Options = {
|
|
@@ -48,6 +47,8 @@ function wrapModule(module: Module<>, options: Options): Array<Buffer> {
|
|
|
48
47
|
);
|
|
49
48
|
}
|
|
50
49
|
|
|
50
|
+
const {compile} = require('metro-hermes-compiler');
|
|
51
|
+
|
|
51
52
|
const headerCode = `globalThis.$$METRO_D=[${params.join(',')}];`;
|
|
52
53
|
return [
|
|
53
54
|
compile(headerCode, {
|
package/src/DeltaBundler.js.flow
CHANGED
|
@@ -112,7 +112,7 @@ class DeltaBundler<T = MixedOutput> {
|
|
|
112
112
|
return await deltaCalculator.getDelta({reset, shallow});
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
listen(graph: Graph<T>, callback: () =>
|
|
115
|
+
listen(graph: Graph<T>, callback: () => Promise<void>): () => void {
|
|
116
116
|
const deltaCalculator = this._deltaCalculators.get(graph);
|
|
117
117
|
|
|
118
118
|
if (!deltaCalculator) {
|
package/src/HmrServer.js
CHANGED
|
@@ -31,12 +31,14 @@ const {
|
|
|
31
31
|
Logger: { createActionStartEntry, createActionEndEntry, log },
|
|
32
32
|
} = require("metro-core");
|
|
33
33
|
|
|
34
|
-
const { VERSION: BYTECODE_VERSION } = require("metro-hermes-compiler");
|
|
35
|
-
|
|
36
34
|
const nullthrows = require("nullthrows");
|
|
37
35
|
|
|
38
36
|
const url = require("url");
|
|
39
37
|
|
|
38
|
+
function getBytecodeVersion() {
|
|
39
|
+
return require("metro-hermes-compiler").VERSION;
|
|
40
|
+
}
|
|
41
|
+
|
|
40
42
|
function send(sendFns, message) {
|
|
41
43
|
const strMessage = JSON.stringify(message);
|
|
42
44
|
sendFns.forEach((sendFn) => sendFn(strMessage));
|
|
@@ -75,9 +77,9 @@ class HmrServer {
|
|
|
75
77
|
const options = parseOptionsFromUrl(
|
|
76
78
|
requestUrl,
|
|
77
79
|
new Set(this._config.resolver.platforms),
|
|
78
|
-
|
|
80
|
+
getBytecodeVersion()
|
|
79
81
|
);
|
|
80
|
-
const { entryFile, transformOptions, graphOptions } =
|
|
82
|
+
const { entryFile, resolverOptions, transformOptions, graphOptions } =
|
|
81
83
|
splitBundleOptions(options);
|
|
82
84
|
/**
|
|
83
85
|
* `entryFile` is relative to projectRoot, we need to use resolution function
|
|
@@ -86,7 +88,8 @@ class HmrServer {
|
|
|
86
88
|
|
|
87
89
|
const resolutionFn = await transformHelpers.getResolveDependencyFn(
|
|
88
90
|
this._bundler.getBundler(),
|
|
89
|
-
transformOptions.platform
|
|
91
|
+
transformOptions.platform,
|
|
92
|
+
resolverOptions
|
|
90
93
|
);
|
|
91
94
|
const resolvedEntryFilePath = resolutionFn(
|
|
92
95
|
((_this$_config$server$ = this._config.server.unstable_serverRoot) !==
|
|
@@ -96,6 +99,7 @@ class HmrServer {
|
|
|
96
99
|
entryFile
|
|
97
100
|
);
|
|
98
101
|
const graphId = getGraphId(resolvedEntryFilePath, transformOptions, {
|
|
102
|
+
resolverOptions,
|
|
99
103
|
shallow: graphOptions.shallow,
|
|
100
104
|
experimentalImportBundleSupport:
|
|
101
105
|
this._config.transformer.experimentalImportBundleSupport,
|
package/src/HmrServer.js.flow
CHANGED
|
@@ -31,14 +31,13 @@ const transformHelpers = require('./lib/transformHelpers');
|
|
|
31
31
|
const {
|
|
32
32
|
Logger: {createActionStartEntry, createActionEndEntry, log},
|
|
33
33
|
} = require('metro-core');
|
|
34
|
-
const {VERSION: BYTECODE_VERSION} = require('metro-hermes-compiler');
|
|
35
34
|
const nullthrows = require('nullthrows');
|
|
36
35
|
const url = require('url');
|
|
37
36
|
|
|
38
37
|
type $ReturnType<F> = $Call<<A, R>((...A) => R) => R, F>;
|
|
39
38
|
export type EntryPointURL = $ReturnType<typeof url.parse>;
|
|
40
39
|
|
|
41
|
-
type Client = {
|
|
40
|
+
export type Client = {
|
|
42
41
|
optedIntoHMR: boolean,
|
|
43
42
|
revisionIds: Array<RevisionId>,
|
|
44
43
|
+sendFn: string => void,
|
|
@@ -51,6 +50,10 @@ type ClientGroup = {
|
|
|
51
50
|
+unlisten: () => void,
|
|
52
51
|
};
|
|
53
52
|
|
|
53
|
+
function getBytecodeVersion() {
|
|
54
|
+
return require('metro-hermes-compiler').VERSION;
|
|
55
|
+
}
|
|
56
|
+
|
|
54
57
|
function send(sendFns: Array<(string) => void>, message: HmrMessage): void {
|
|
55
58
|
const strMessage = JSON.stringify(message);
|
|
56
59
|
sendFns.forEach((sendFn: string => void) => sendFn(strMessage));
|
|
@@ -103,9 +106,9 @@ class HmrServer<TClient: Client> {
|
|
|
103
106
|
const options = parseOptionsFromUrl(
|
|
104
107
|
requestUrl,
|
|
105
108
|
new Set(this._config.resolver.platforms),
|
|
106
|
-
|
|
109
|
+
getBytecodeVersion(),
|
|
107
110
|
);
|
|
108
|
-
const {entryFile, transformOptions, graphOptions} =
|
|
111
|
+
const {entryFile, resolverOptions, transformOptions, graphOptions} =
|
|
109
112
|
splitBundleOptions(options);
|
|
110
113
|
|
|
111
114
|
/**
|
|
@@ -115,6 +118,7 @@ class HmrServer<TClient: Client> {
|
|
|
115
118
|
const resolutionFn = await transformHelpers.getResolveDependencyFn(
|
|
116
119
|
this._bundler.getBundler(),
|
|
117
120
|
transformOptions.platform,
|
|
121
|
+
resolverOptions,
|
|
118
122
|
);
|
|
119
123
|
const resolvedEntryFilePath = resolutionFn(
|
|
120
124
|
(this._config.server.unstable_serverRoot ?? this._config.projectRoot) +
|
|
@@ -122,6 +126,7 @@ class HmrServer<TClient: Client> {
|
|
|
122
126
|
entryFile,
|
|
123
127
|
);
|
|
124
128
|
const graphId = getGraphId(resolvedEntryFilePath, transformOptions, {
|
|
129
|
+
resolverOptions,
|
|
125
130
|
shallow: graphOptions.shallow,
|
|
126
131
|
experimentalImportBundleSupport:
|
|
127
132
|
this._config.transformer.experimentalImportBundleSupport,
|
|
@@ -71,6 +71,7 @@ class IncrementalBundler {
|
|
|
71
71
|
async buildGraphForEntries(
|
|
72
72
|
entryFiles,
|
|
73
73
|
transformOptions,
|
|
74
|
+
resolverOptions,
|
|
74
75
|
otherOptions = {
|
|
75
76
|
onProgress: null,
|
|
76
77
|
shallow: false,
|
|
@@ -80,14 +81,16 @@ class IncrementalBundler {
|
|
|
80
81
|
const graph = await this._deltaBundler.buildGraph(absoluteEntryFiles, {
|
|
81
82
|
resolve: await transformHelpers.getResolveDependencyFn(
|
|
82
83
|
this._bundler,
|
|
83
|
-
transformOptions.platform
|
|
84
|
+
transformOptions.platform,
|
|
85
|
+
resolverOptions
|
|
84
86
|
),
|
|
85
87
|
transform: await transformHelpers.getTransformFn(
|
|
86
88
|
absoluteEntryFiles,
|
|
87
89
|
this._bundler,
|
|
88
90
|
this._deltaBundler,
|
|
89
91
|
this._config,
|
|
90
|
-
transformOptions
|
|
92
|
+
transformOptions,
|
|
93
|
+
resolverOptions
|
|
91
94
|
),
|
|
92
95
|
transformOptions,
|
|
93
96
|
onProgress: otherOptions.onProgress,
|
|
@@ -111,6 +114,7 @@ class IncrementalBundler {
|
|
|
111
114
|
async getDependencies(
|
|
112
115
|
entryFiles,
|
|
113
116
|
transformOptions,
|
|
117
|
+
resolverOptions,
|
|
114
118
|
otherOptions = {
|
|
115
119
|
onProgress: null,
|
|
116
120
|
shallow: false,
|
|
@@ -122,14 +126,16 @@ class IncrementalBundler {
|
|
|
122
126
|
{
|
|
123
127
|
resolve: await transformHelpers.getResolveDependencyFn(
|
|
124
128
|
this._bundler,
|
|
125
|
-
transformOptions.platform
|
|
129
|
+
transformOptions.platform,
|
|
130
|
+
resolverOptions
|
|
126
131
|
),
|
|
127
132
|
transform: await transformHelpers.getTransformFn(
|
|
128
133
|
absoluteEntryFiles,
|
|
129
134
|
this._bundler,
|
|
130
135
|
this._deltaBundler,
|
|
131
136
|
this._config,
|
|
132
|
-
transformOptions
|
|
137
|
+
transformOptions,
|
|
138
|
+
resolverOptions
|
|
133
139
|
),
|
|
134
140
|
transformOptions,
|
|
135
141
|
onProgress: otherOptions.onProgress,
|
|
@@ -146,6 +152,7 @@ class IncrementalBundler {
|
|
|
146
152
|
async buildGraph(
|
|
147
153
|
entryFile,
|
|
148
154
|
transformOptions,
|
|
155
|
+
resolverOptions,
|
|
149
156
|
otherOptions = {
|
|
150
157
|
onProgress: null,
|
|
151
158
|
shallow: false,
|
|
@@ -154,12 +161,14 @@ class IncrementalBundler {
|
|
|
154
161
|
const graph = await this.buildGraphForEntries(
|
|
155
162
|
[entryFile],
|
|
156
163
|
transformOptions,
|
|
164
|
+
resolverOptions,
|
|
157
165
|
otherOptions
|
|
158
166
|
);
|
|
159
167
|
const { type: _, ...transformOptionsWithoutType } = transformOptions;
|
|
160
168
|
const prepend = await getPrependedScripts(
|
|
161
169
|
this._config,
|
|
162
170
|
transformOptionsWithoutType,
|
|
171
|
+
resolverOptions,
|
|
163
172
|
this._bundler,
|
|
164
173
|
this._deltaBundler
|
|
165
174
|
);
|
|
@@ -173,12 +182,14 @@ class IncrementalBundler {
|
|
|
173
182
|
async initializeGraph(
|
|
174
183
|
entryFile,
|
|
175
184
|
transformOptions,
|
|
185
|
+
resolverOptions,
|
|
176
186
|
otherOptions = {
|
|
177
187
|
onProgress: null,
|
|
178
188
|
shallow: false,
|
|
179
189
|
}
|
|
180
190
|
) {
|
|
181
191
|
const graphId = getGraphId(entryFile, transformOptions, {
|
|
192
|
+
resolverOptions,
|
|
182
193
|
shallow: otherOptions.shallow,
|
|
183
194
|
experimentalImportBundleSupport:
|
|
184
195
|
this._config.transformer.experimentalImportBundleSupport,
|
|
@@ -191,6 +202,7 @@ class IncrementalBundler {
|
|
|
191
202
|
const { graph, prepend } = await this.buildGraph(
|
|
192
203
|
entryFile,
|
|
193
204
|
transformOptions,
|
|
205
|
+
resolverOptions,
|
|
194
206
|
otherOptions
|
|
195
207
|
);
|
|
196
208
|
return {
|
|
@@ -17,6 +17,7 @@ import type {
|
|
|
17
17
|
TransformInputOptions,
|
|
18
18
|
} from './DeltaBundler/types.flow';
|
|
19
19
|
import type {GraphId} from './lib/getGraphId';
|
|
20
|
+
import type {ResolverInputOptions} from './shared/types.flow';
|
|
20
21
|
import type {ConfigT} from 'metro-config/src/configTypes.flow';
|
|
21
22
|
|
|
22
23
|
const Bundler = require('./Bundler');
|
|
@@ -33,10 +34,10 @@ export opaque type RevisionId: string = string;
|
|
|
33
34
|
|
|
34
35
|
export type OutputGraph = Graph<>;
|
|
35
36
|
|
|
36
|
-
type OtherOptions = {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
37
|
+
type OtherOptions = $ReadOnly<{
|
|
38
|
+
onProgress: $PropertyType<DeltaBundlerOptions<>, 'onProgress'>,
|
|
39
|
+
shallow: boolean,
|
|
40
|
+
}>;
|
|
40
41
|
|
|
41
42
|
export type GraphRevision = {
|
|
42
43
|
// Identifies the last computed revision.
|
|
@@ -100,6 +101,7 @@ class IncrementalBundler {
|
|
|
100
101
|
async buildGraphForEntries(
|
|
101
102
|
entryFiles: $ReadOnlyArray<string>,
|
|
102
103
|
transformOptions: TransformInputOptions,
|
|
104
|
+
resolverOptions: ResolverInputOptions,
|
|
103
105
|
otherOptions?: OtherOptions = {
|
|
104
106
|
onProgress: null,
|
|
105
107
|
shallow: false,
|
|
@@ -111,6 +113,7 @@ class IncrementalBundler {
|
|
|
111
113
|
resolve: await transformHelpers.getResolveDependencyFn(
|
|
112
114
|
this._bundler,
|
|
113
115
|
transformOptions.platform,
|
|
116
|
+
resolverOptions,
|
|
114
117
|
),
|
|
115
118
|
transform: await transformHelpers.getTransformFn(
|
|
116
119
|
absoluteEntryFiles,
|
|
@@ -118,6 +121,7 @@ class IncrementalBundler {
|
|
|
118
121
|
this._deltaBundler,
|
|
119
122
|
this._config,
|
|
120
123
|
transformOptions,
|
|
124
|
+
resolverOptions,
|
|
121
125
|
),
|
|
122
126
|
transformOptions,
|
|
123
127
|
onProgress: otherOptions.onProgress,
|
|
@@ -141,6 +145,7 @@ class IncrementalBundler {
|
|
|
141
145
|
async getDependencies(
|
|
142
146
|
entryFiles: $ReadOnlyArray<string>,
|
|
143
147
|
transformOptions: TransformInputOptions,
|
|
148
|
+
resolverOptions: ResolverInputOptions,
|
|
144
149
|
otherOptions?: OtherOptions = {
|
|
145
150
|
onProgress: null,
|
|
146
151
|
shallow: false,
|
|
@@ -154,6 +159,7 @@ class IncrementalBundler {
|
|
|
154
159
|
resolve: await transformHelpers.getResolveDependencyFn(
|
|
155
160
|
this._bundler,
|
|
156
161
|
transformOptions.platform,
|
|
162
|
+
resolverOptions,
|
|
157
163
|
),
|
|
158
164
|
transform: await transformHelpers.getTransformFn(
|
|
159
165
|
absoluteEntryFiles,
|
|
@@ -161,6 +167,7 @@ class IncrementalBundler {
|
|
|
161
167
|
this._deltaBundler,
|
|
162
168
|
this._config,
|
|
163
169
|
transformOptions,
|
|
170
|
+
resolverOptions,
|
|
164
171
|
),
|
|
165
172
|
transformOptions,
|
|
166
173
|
onProgress: otherOptions.onProgress,
|
|
@@ -178,6 +185,7 @@ class IncrementalBundler {
|
|
|
178
185
|
async buildGraph(
|
|
179
186
|
entryFile: string,
|
|
180
187
|
transformOptions: TransformInputOptions,
|
|
188
|
+
resolverOptions: ResolverInputOptions,
|
|
181
189
|
otherOptions?: OtherOptions = {
|
|
182
190
|
onProgress: null,
|
|
183
191
|
shallow: false,
|
|
@@ -186,6 +194,7 @@ class IncrementalBundler {
|
|
|
186
194
|
const graph = await this.buildGraphForEntries(
|
|
187
195
|
[entryFile],
|
|
188
196
|
transformOptions,
|
|
197
|
+
resolverOptions,
|
|
189
198
|
otherOptions,
|
|
190
199
|
);
|
|
191
200
|
|
|
@@ -194,6 +203,7 @@ class IncrementalBundler {
|
|
|
194
203
|
const prepend = await getPrependedScripts(
|
|
195
204
|
this._config,
|
|
196
205
|
transformOptionsWithoutType,
|
|
206
|
+
resolverOptions,
|
|
197
207
|
this._bundler,
|
|
198
208
|
this._deltaBundler,
|
|
199
209
|
);
|
|
@@ -209,6 +219,7 @@ class IncrementalBundler {
|
|
|
209
219
|
async initializeGraph(
|
|
210
220
|
entryFile: string,
|
|
211
221
|
transformOptions: TransformInputOptions,
|
|
222
|
+
resolverOptions: ResolverInputOptions,
|
|
212
223
|
otherOptions?: OtherOptions = {
|
|
213
224
|
onProgress: null,
|
|
214
225
|
shallow: false,
|
|
@@ -219,6 +230,7 @@ class IncrementalBundler {
|
|
|
219
230
|
...
|
|
220
231
|
}> {
|
|
221
232
|
const graphId = getGraphId(entryFile, transformOptions, {
|
|
233
|
+
resolverOptions,
|
|
222
234
|
shallow: otherOptions.shallow,
|
|
223
235
|
experimentalImportBundleSupport:
|
|
224
236
|
this._config.transformer.experimentalImportBundleSupport,
|
|
@@ -230,6 +242,7 @@ class IncrementalBundler {
|
|
|
230
242
|
const {graph, prepend} = await this.buildGraph(
|
|
231
243
|
entryFile,
|
|
232
244
|
transformOptions,
|
|
245
|
+
resolverOptions,
|
|
233
246
|
otherOptions,
|
|
234
247
|
);
|
|
235
248
|
return {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
import type {PackageData} from '../types.flow';
|
|
13
|
+
import type {PackageData, Replacements} from '../types.flow';
|
|
14
14
|
|
|
15
15
|
const nullthrows = require('nullthrows');
|
|
16
16
|
const path = require('path');
|
|
@@ -57,7 +57,7 @@ module.exports = class Package {
|
|
|
57
57
|
return !!this.data.name;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
redirectRequire(name: string):
|
|
60
|
+
redirectRequire(name: string): string | false {
|
|
61
61
|
// Copied from node-haste/Package.js
|
|
62
62
|
const replacements = getReplacements(this.data);
|
|
63
63
|
|
|
@@ -104,7 +104,7 @@ function getMain(pkg: PackageData): string {
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
// Copied from node-haste/Package.js
|
|
107
|
-
function getReplacements(pkg: PackageData) {
|
|
107
|
+
function getReplacements(pkg: PackageData): ?(string | Replacements) {
|
|
108
108
|
let rn = pkg['react-native'];
|
|
109
109
|
let browser = pkg.browser;
|
|
110
110
|
if (rn == null) {
|
|
@@ -117,11 +117,11 @@ function getReplacements(pkg: PackageData) {
|
|
|
117
117
|
|
|
118
118
|
const main = getMain(pkg);
|
|
119
119
|
if (typeof rn !== 'object') {
|
|
120
|
-
rn = {[main]: rn};
|
|
120
|
+
rn = ({[main]: rn}: Replacements);
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
if (typeof browser !== 'object') {
|
|
124
|
-
browser = {[main]: browser};
|
|
124
|
+
browser = ({[main]: browser}: Replacements);
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
// merge with "browser" as default,
|
|
@@ -147,7 +147,6 @@ exports.createResolveFn = function (options) {
|
|
|
147
147
|
extraNodeModules,
|
|
148
148
|
isAssetFile,
|
|
149
149
|
mainFields: options.mainFields,
|
|
150
|
-
// $FlowFixMe -- error revealed by types-first codemod
|
|
151
150
|
moduleCache,
|
|
152
151
|
moduleMap: new _metroFileMap.ModuleMap({
|
|
153
152
|
duplicates: new Map(),
|
|
@@ -181,8 +180,13 @@ exports.createResolveFn = function (options) {
|
|
|
181
180
|
const from =
|
|
182
181
|
sourcePath != null
|
|
183
182
|
? new Module(sourcePath, moduleCache, getTransformedFile(sourcePath))
|
|
184
|
-
: NULL_MODULE;
|
|
185
|
-
|
|
186
|
-
|
|
183
|
+
: NULL_MODULE;
|
|
184
|
+
return moduleResolver.resolveDependency(
|
|
185
|
+
from,
|
|
186
|
+
id,
|
|
187
|
+
true,
|
|
188
|
+
platform,
|
|
189
|
+
options.resolverOptions
|
|
190
|
+
).path;
|
|
187
191
|
};
|
|
188
192
|
};
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import type {Moduleish} from '../../node-haste/DependencyGraph/ModuleResolution';
|
|
12
|
+
import type {ResolverInputOptions} from '../../shared/types.flow';
|
|
12
13
|
import type {ResolveFn, TransformedCodeFile} from '../types.flow';
|
|
13
14
|
import type {Path} from './node-haste.flow';
|
|
14
15
|
import type {ModuleMapData, ModuleMapItem} from 'metro-file-map';
|
|
@@ -26,13 +27,7 @@ const ModuleCache = require('./ModuleCache');
|
|
|
26
27
|
const defaults = require('metro-config/src/defaults/defaults');
|
|
27
28
|
const path = require('path');
|
|
28
29
|
|
|
29
|
-
type ResolveOptions = {
|
|
30
|
-
/**
|
|
31
|
-
* (Used by the resolver) The extensions tried (in order) to implicitly
|
|
32
|
-
* locate a source file.
|
|
33
|
-
*/
|
|
34
|
-
sourceExts: $ReadOnlyArray<string>,
|
|
35
|
-
|
|
30
|
+
type ResolveOptions = $ReadOnly<{
|
|
36
31
|
/**
|
|
37
32
|
* The additional extensions to include in the file map as source files that
|
|
38
33
|
* can be explicitly imported.
|
|
@@ -41,16 +36,24 @@ type ResolveOptions = {
|
|
|
41
36
|
|
|
42
37
|
assetExts: $ReadOnlyArray<string>,
|
|
43
38
|
assetResolutions: $ReadOnlyArray<string>,
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
disableHierarchicalLookup: boolean,
|
|
40
|
+
emptyModulePath: string,
|
|
46
41
|
extraNodeModules: {[id: string]: string, ...},
|
|
47
42
|
mainFields: $ReadOnlyArray<string>,
|
|
48
43
|
nodeModulesPaths: $ReadOnlyArray<string>,
|
|
49
|
-
|
|
44
|
+
platform: string,
|
|
50
45
|
platforms?: $ReadOnlyArray<string>,
|
|
51
46
|
resolveRequest?: ?CustomResolver,
|
|
47
|
+
resolverOptions: ResolverInputOptions,
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* (Used by the resolver) The extensions tried (in order) to implicitly
|
|
51
|
+
* locate a source file.
|
|
52
|
+
*/
|
|
53
|
+
sourceExts: $ReadOnlyArray<string>,
|
|
54
|
+
|
|
52
55
|
transformedFiles: {[path: Path]: TransformedCodeFile, ...},
|
|
53
|
-
}
|
|
56
|
+
}>;
|
|
54
57
|
|
|
55
58
|
const NATIVE_PLATFORM = 'native';
|
|
56
59
|
const GENERIC_PLATFORM = 'g';
|
|
@@ -173,7 +176,6 @@ exports.createResolveFn = function (options: ResolveOptions): ResolveFn {
|
|
|
173
176
|
extraNodeModules,
|
|
174
177
|
isAssetFile,
|
|
175
178
|
mainFields: options.mainFields,
|
|
176
|
-
// $FlowFixMe -- error revealed by types-first codemod
|
|
177
179
|
moduleCache,
|
|
178
180
|
moduleMap: new ModuleMap({
|
|
179
181
|
duplicates: new Map(),
|
|
@@ -213,7 +215,12 @@ exports.createResolveFn = function (options: ResolveOptions): ResolveFn {
|
|
|
213
215
|
sourcePath != null
|
|
214
216
|
? new Module(sourcePath, moduleCache, getTransformedFile(sourcePath))
|
|
215
217
|
: NULL_MODULE;
|
|
216
|
-
|
|
217
|
-
|
|
218
|
+
return moduleResolver.resolveDependency(
|
|
219
|
+
from,
|
|
220
|
+
id,
|
|
221
|
+
true,
|
|
222
|
+
platform,
|
|
223
|
+
options.resolverOptions,
|
|
224
|
+
).path;
|
|
218
225
|
};
|
|
219
226
|
};
|
|
@@ -17,9 +17,7 @@ const mergeSourceMaps = require("../worker/mergeSourceMaps");
|
|
|
17
17
|
|
|
18
18
|
const reverseDependencyMapReferences = require("./reverse-dependency-map-references");
|
|
19
19
|
|
|
20
|
-
const { parseSync, transformFromAstSync } = require("@babel/core");
|
|
21
|
-
|
|
22
|
-
const HermesParser = require("hermes-parser"); // flowlint-next-line untyped-import:off
|
|
20
|
+
const { parseSync, transformFromAstSync } = require("@babel/core"); // flowlint-next-line untyped-import:off
|
|
23
21
|
|
|
24
22
|
const { passthroughSyntaxPlugins } = require("metro-react-native-babel-preset");
|
|
25
23
|
|
|
@@ -179,7 +177,7 @@ function inlineModuleIds(
|
|
|
179
177
|
const sourceAst =
|
|
180
178
|
isTypeScriptSource(path) || isTSXSource(path) || !hermesParser
|
|
181
179
|
? parseSync(code, babelConfig)
|
|
182
|
-
:
|
|
180
|
+
: require("hermes-parser").parse(code, {
|
|
183
181
|
babel: true,
|
|
184
182
|
// $FlowFixMe[prop-missing]
|
|
185
183
|
sourceType: babelConfig.sourceType,
|
|
@@ -18,7 +18,6 @@ const generate = require('../worker/generate');
|
|
|
18
18
|
const mergeSourceMaps = require('../worker/mergeSourceMaps');
|
|
19
19
|
const reverseDependencyMapReferences = require('./reverse-dependency-map-references');
|
|
20
20
|
const {parseSync, transformFromAstSync} = require('@babel/core');
|
|
21
|
-
const HermesParser = require('hermes-parser');
|
|
22
21
|
// flowlint-next-line untyped-import:off
|
|
23
22
|
const {passthroughSyntaxPlugins} = require('metro-react-native-babel-preset');
|
|
24
23
|
const {addParamsToDefineCall} = require('metro-transform-plugins');
|
|
@@ -179,7 +178,7 @@ function inlineModuleIds(
|
|
|
179
178
|
const sourceAst =
|
|
180
179
|
isTypeScriptSource(path) || isTSXSource(path) || !hermesParser
|
|
181
180
|
? parseSync(code, babelConfig)
|
|
182
|
-
:
|
|
181
|
+
: require('hermes-parser').parse(code, {
|
|
183
182
|
babel: true,
|
|
184
183
|
// $FlowFixMe[prop-missing]
|
|
185
184
|
sourceType: babelConfig.sourceType,
|