metro 0.76.3 → 0.76.4
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 -22
- package/src/Bundler/util.js +27 -3
- package/src/Bundler/util.js.flow +29 -3
- package/src/DeltaBundler/Graph.js +34 -7
- package/src/DeltaBundler/Graph.js.flow +34 -8
- package/src/DeltaBundler/Serializers/baseJSBundle.js +1 -0
- package/src/DeltaBundler/Serializers/baseJSBundle.js.flow +1 -0
- package/src/DeltaBundler/Serializers/getRamBundleInfo.js +1 -0
- package/src/DeltaBundler/Serializers/getRamBundleInfo.js.flow +3 -1
- package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js +1 -0
- package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js.flow +3 -0
- package/src/DeltaBundler/Serializers/sourceMapGenerator.js +1 -0
- package/src/DeltaBundler/Serializers/sourceMapGenerator.js.flow +10 -12
- package/src/DeltaBundler/Serializers/sourceMapObject.js.flow +3 -8
- package/src/DeltaBundler/Serializers/sourceMapString.js.flow +2 -4
- package/src/DeltaBundler/types.d.ts +1 -0
- package/src/DeltaBundler/types.flow.js.flow +1 -0
- package/src/Server.js +20 -0
- package/src/Server.js.flow +21 -0
- package/src/lib/getAppendScripts.js +1 -0
- package/src/lib/getAppendScripts.js.flow +12 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "metro",
|
|
3
|
-
"version": "0.76.
|
|
3
|
+
"version": "0.76.4",
|
|
4
4
|
"description": "🚇 The JavaScript bundler for React Native.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": "src/cli.js",
|
|
@@ -30,26 +30,26 @@
|
|
|
30
30
|
"error-stack-parser": "^2.0.6",
|
|
31
31
|
"graceful-fs": "^4.2.4",
|
|
32
32
|
"hermes-parser": "0.8.0",
|
|
33
|
-
"image-size": "^0.
|
|
33
|
+
"image-size": "^1.0.2",
|
|
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-inspector-proxy": "0.76.
|
|
44
|
-
"metro-minify-terser": "0.76.
|
|
45
|
-
"metro-minify-uglify": "0.76.
|
|
46
|
-
"metro-react-native-babel-preset": "0.76.
|
|
47
|
-
"metro-resolver": "0.76.
|
|
48
|
-
"metro-runtime": "0.76.
|
|
49
|
-
"metro-source-map": "0.76.
|
|
50
|
-
"metro-symbolicate": "0.76.
|
|
51
|
-
"metro-transform-plugins": "0.76.
|
|
52
|
-
"metro-transform-worker": "0.76.
|
|
37
|
+
"metro-babel-transformer": "0.76.4",
|
|
38
|
+
"metro-cache": "0.76.4",
|
|
39
|
+
"metro-cache-key": "0.76.4",
|
|
40
|
+
"metro-config": "0.76.4",
|
|
41
|
+
"metro-core": "0.76.4",
|
|
42
|
+
"metro-file-map": "0.76.4",
|
|
43
|
+
"metro-inspector-proxy": "0.76.4",
|
|
44
|
+
"metro-minify-terser": "0.76.4",
|
|
45
|
+
"metro-minify-uglify": "0.76.4",
|
|
46
|
+
"metro-react-native-babel-preset": "0.76.4",
|
|
47
|
+
"metro-resolver": "0.76.4",
|
|
48
|
+
"metro-runtime": "0.76.4",
|
|
49
|
+
"metro-source-map": "0.76.4",
|
|
50
|
+
"metro-symbolicate": "0.76.4",
|
|
51
|
+
"metro-transform-plugins": "0.76.4",
|
|
52
|
+
"metro-transform-worker": "0.76.4",
|
|
53
53
|
"mime-types": "^2.1.27",
|
|
54
54
|
"node-fetch": "^2.2.0",
|
|
55
55
|
"nullthrows": "^1.1.1",
|
|
@@ -67,10 +67,10 @@
|
|
|
67
67
|
"dedent": "^0.7.0",
|
|
68
68
|
"jest-snapshot": "^26.5.2",
|
|
69
69
|
"jest-snapshot-serializer-raw": "^1.2.0",
|
|
70
|
-
"metro-babel-register": "0.76.
|
|
71
|
-
"metro-memory-fs": "0.76.
|
|
72
|
-
"metro-react-native-babel-preset": "0.76.
|
|
73
|
-
"metro-react-native-babel-transformer": "0.76.
|
|
70
|
+
"metro-babel-register": "0.76.4",
|
|
71
|
+
"metro-memory-fs": "0.76.4",
|
|
72
|
+
"metro-react-native-babel-preset": "0.76.4",
|
|
73
|
+
"metro-react-native-babel-transformer": "0.76.4",
|
|
74
74
|
"mock-req": "^0.2.0",
|
|
75
75
|
"mock-res": "^0.6.0",
|
|
76
76
|
"stack-trace": "^0.0.10"
|
package/src/Bundler/util.js
CHANGED
|
@@ -15,6 +15,7 @@ const babylon = require("@babel/parser");
|
|
|
15
15
|
const template = require("@babel/template").default;
|
|
16
16
|
const babelTypes = require("@babel/types");
|
|
17
17
|
const nullthrows = require("nullthrows");
|
|
18
|
+
const getImageSize = require("image-size");
|
|
18
19
|
|
|
19
20
|
// Structure of the object: dir.name.scale = asset
|
|
20
21
|
|
|
@@ -105,11 +106,33 @@ function generateRemoteAssetCodeFileAst(
|
|
|
105
106
|
// If it's not one of these, we won't treat it as an image.
|
|
106
107
|
function isAssetTypeAnImage(type) {
|
|
107
108
|
return (
|
|
108
|
-
[
|
|
109
|
-
|
|
110
|
-
|
|
109
|
+
[
|
|
110
|
+
"png",
|
|
111
|
+
"jpg",
|
|
112
|
+
"jpeg",
|
|
113
|
+
"bmp",
|
|
114
|
+
"gif",
|
|
115
|
+
"webp",
|
|
116
|
+
"psd",
|
|
117
|
+
"svg",
|
|
118
|
+
"tiff",
|
|
119
|
+
"ktx",
|
|
120
|
+
].indexOf(type) !== -1
|
|
111
121
|
);
|
|
112
122
|
}
|
|
123
|
+
function getAssetSize(type, content, filePath) {
|
|
124
|
+
if (!isAssetTypeAnImage(type)) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
if (content.length === 0) {
|
|
128
|
+
throw new Error(`Image asset \`${filePath}\` cannot be an empty file.`);
|
|
129
|
+
}
|
|
130
|
+
const { width, height } = getImageSize(content);
|
|
131
|
+
return {
|
|
132
|
+
width,
|
|
133
|
+
height,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
113
136
|
function filterObject(object, blockList) {
|
|
114
137
|
const copied = {
|
|
115
138
|
...object,
|
|
@@ -191,5 +214,6 @@ module.exports = {
|
|
|
191
214
|
createRamBundleGroups,
|
|
192
215
|
generateAssetCodeFileAst,
|
|
193
216
|
generateRemoteAssetCodeFileAst,
|
|
217
|
+
getAssetSize,
|
|
194
218
|
isAssetTypeAnImage,
|
|
195
219
|
};
|
package/src/Bundler/util.js.flow
CHANGED
|
@@ -19,6 +19,7 @@ const babylon = require('@babel/parser');
|
|
|
19
19
|
const template = require('@babel/template').default;
|
|
20
20
|
const babelTypes = require('@babel/types');
|
|
21
21
|
const nullthrows = require('nullthrows');
|
|
22
|
+
const getImageSize = require('image-size');
|
|
22
23
|
|
|
23
24
|
// Structure of the object: dir.name.scale = asset
|
|
24
25
|
export type RemoteFileMap = {
|
|
@@ -146,12 +147,36 @@ function generateRemoteAssetCodeFileAst(
|
|
|
146
147
|
// If it's not one of these, we won't treat it as an image.
|
|
147
148
|
function isAssetTypeAnImage(type: string): boolean {
|
|
148
149
|
return (
|
|
149
|
-
[
|
|
150
|
-
|
|
151
|
-
|
|
150
|
+
[
|
|
151
|
+
'png',
|
|
152
|
+
'jpg',
|
|
153
|
+
'jpeg',
|
|
154
|
+
'bmp',
|
|
155
|
+
'gif',
|
|
156
|
+
'webp',
|
|
157
|
+
'psd',
|
|
158
|
+
'svg',
|
|
159
|
+
'tiff',
|
|
160
|
+
'ktx',
|
|
161
|
+
].indexOf(type) !== -1
|
|
152
162
|
);
|
|
153
163
|
}
|
|
154
164
|
|
|
165
|
+
function getAssetSize(
|
|
166
|
+
type: string,
|
|
167
|
+
content: Buffer,
|
|
168
|
+
filePath: string,
|
|
169
|
+
): ?{+width: number, +height: number} {
|
|
170
|
+
if (!isAssetTypeAnImage(type)) {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
if (content.length === 0) {
|
|
174
|
+
throw new Error(`Image asset \`${filePath}\` cannot be an empty file.`);
|
|
175
|
+
}
|
|
176
|
+
const {width, height} = getImageSize(content);
|
|
177
|
+
return {width, height};
|
|
178
|
+
}
|
|
179
|
+
|
|
155
180
|
function filterObject(
|
|
156
181
|
object: AssetDataWithoutFiles,
|
|
157
182
|
blockList: Set<string>,
|
|
@@ -247,5 +272,6 @@ module.exports = {
|
|
|
247
272
|
createRamBundleGroups,
|
|
248
273
|
generateAssetCodeFileAst,
|
|
249
274
|
generateRemoteAssetCodeFileAst,
|
|
275
|
+
getAssetSize,
|
|
250
276
|
isAssetTypeAnImage,
|
|
251
277
|
};
|
|
@@ -134,10 +134,19 @@ class Graph {
|
|
|
134
134
|
earlyInverseDependencies: new Map(),
|
|
135
135
|
};
|
|
136
136
|
const internalOptions = getInternalOptions(options);
|
|
137
|
-
|
|
138
|
-
|
|
137
|
+
|
|
138
|
+
// Record the paths that are part of the dependency graph before we start
|
|
139
|
+
// traversing - we'll use this to ensure we don't report modules modified
|
|
140
|
+
// that only exist as part of the graph mid-traversal.
|
|
141
|
+
const existingPaths = paths.filter((path) => this.dependencies.has(path));
|
|
142
|
+
for (const path of existingPaths) {
|
|
143
|
+
// Traverse over modules that are part of the dependency graph.
|
|
144
|
+
//
|
|
145
|
+
// Note: A given path may not be part of the graph *at this time*, in
|
|
146
|
+
// particular it may have been removed since we started traversing, but
|
|
147
|
+
// in that case the path will be visited if and when we add it back to
|
|
148
|
+
// the graph in a subsequent iteration.
|
|
139
149
|
if (this.dependencies.get(path)) {
|
|
140
|
-
delta.modified.add(path);
|
|
141
150
|
await this._traverseDependenciesForSingleFile(
|
|
142
151
|
path,
|
|
143
152
|
delta,
|
|
@@ -151,10 +160,23 @@ class Graph {
|
|
|
151
160
|
added.set(path, nullthrows(this.dependencies.get(path)));
|
|
152
161
|
}
|
|
153
162
|
const modified = new Map();
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
163
|
+
|
|
164
|
+
// A path in delta.modified has been processed during this traversal,
|
|
165
|
+
// but may not actually differ, may be new, or may have been deleted after
|
|
166
|
+
// processing. The actually-modified modules are the intersection of
|
|
167
|
+
// delta.modified with the pre-existing paths, minus modules deleted.
|
|
168
|
+
for (const path of existingPaths) {
|
|
169
|
+
invariant(
|
|
170
|
+
!delta.added.has(path),
|
|
171
|
+
"delta.added has %s, but this path was already in the graph.",
|
|
172
|
+
path
|
|
173
|
+
);
|
|
174
|
+
if (delta.modified.has(path)) {
|
|
175
|
+
// Only report a module as modified if we're not already reporting it
|
|
176
|
+
// as added or deleted.
|
|
177
|
+
if (!delta.deleted.has(path)) {
|
|
178
|
+
modified.set(path, nullthrows(this.dependencies.get(path)));
|
|
179
|
+
}
|
|
158
180
|
}
|
|
159
181
|
}
|
|
160
182
|
return {
|
|
@@ -203,6 +225,11 @@ class Graph {
|
|
|
203
225
|
}
|
|
204
226
|
async _processModule(path, delta, options) {
|
|
205
227
|
const resolvedContext = this.#resolvedContexts.get(path);
|
|
228
|
+
|
|
229
|
+
// Mark any module processed as potentially modified. Once we've finished
|
|
230
|
+
// traversing we'll filter this set down.
|
|
231
|
+
delta.modified.add(path);
|
|
232
|
+
|
|
206
233
|
// Transform the file via the given option.
|
|
207
234
|
// TODO: Unbind the transform method from options
|
|
208
235
|
const result = await options.transform(path, resolvedContext);
|
|
@@ -174,11 +174,19 @@ export class Graph<T = MixedOutput> {
|
|
|
174
174
|
|
|
175
175
|
const internalOptions = getInternalOptions(options);
|
|
176
176
|
|
|
177
|
-
|
|
178
|
-
|
|
177
|
+
// Record the paths that are part of the dependency graph before we start
|
|
178
|
+
// traversing - we'll use this to ensure we don't report modules modified
|
|
179
|
+
// that only exist as part of the graph mid-traversal.
|
|
180
|
+
const existingPaths = paths.filter(path => this.dependencies.has(path));
|
|
181
|
+
|
|
182
|
+
for (const path of existingPaths) {
|
|
183
|
+
// Traverse over modules that are part of the dependency graph.
|
|
184
|
+
//
|
|
185
|
+
// Note: A given path may not be part of the graph *at this time*, in
|
|
186
|
+
// particular it may have been removed since we started traversing, but
|
|
187
|
+
// in that case the path will be visited if and when we add it back to
|
|
188
|
+
// the graph in a subsequent iteration.
|
|
179
189
|
if (this.dependencies.get(path)) {
|
|
180
|
-
delta.modified.add(path);
|
|
181
|
-
|
|
182
190
|
await this._traverseDependenciesForSingleFile(
|
|
183
191
|
path,
|
|
184
192
|
delta,
|
|
@@ -195,10 +203,23 @@ export class Graph<T = MixedOutput> {
|
|
|
195
203
|
}
|
|
196
204
|
|
|
197
205
|
const modified = new Map<string, Module<T>>();
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
206
|
+
|
|
207
|
+
// A path in delta.modified has been processed during this traversal,
|
|
208
|
+
// but may not actually differ, may be new, or may have been deleted after
|
|
209
|
+
// processing. The actually-modified modules are the intersection of
|
|
210
|
+
// delta.modified with the pre-existing paths, minus modules deleted.
|
|
211
|
+
for (const path of existingPaths) {
|
|
212
|
+
invariant(
|
|
213
|
+
!delta.added.has(path),
|
|
214
|
+
'delta.added has %s, but this path was already in the graph.',
|
|
215
|
+
path,
|
|
216
|
+
);
|
|
217
|
+
if (delta.modified.has(path)) {
|
|
218
|
+
// Only report a module as modified if we're not already reporting it
|
|
219
|
+
// as added or deleted.
|
|
220
|
+
if (!delta.deleted.has(path)) {
|
|
221
|
+
modified.set(path, nullthrows(this.dependencies.get(path)));
|
|
222
|
+
}
|
|
202
223
|
}
|
|
203
224
|
}
|
|
204
225
|
|
|
@@ -268,6 +289,11 @@ export class Graph<T = MixedOutput> {
|
|
|
268
289
|
options: InternalOptions<T>,
|
|
269
290
|
): Promise<Module<T>> {
|
|
270
291
|
const resolvedContext = this.#resolvedContexts.get(path);
|
|
292
|
+
|
|
293
|
+
// Mark any module processed as potentially modified. Once we've finished
|
|
294
|
+
// traversing we'll filter this set down.
|
|
295
|
+
delta.modified.add(path);
|
|
296
|
+
|
|
271
297
|
// Transform the file via the given option.
|
|
272
298
|
// TODO: Unbind the transform method from options
|
|
273
299
|
const result = await options.transform(path, resolvedContext);
|
|
@@ -45,6 +45,7 @@ function baseJSBundle(entryPoint, preModules, graph, options) {
|
|
|
45
45
|
inlineSourceMap: options.inlineSourceMap,
|
|
46
46
|
runBeforeMainModule: options.runBeforeMainModule,
|
|
47
47
|
runModule: options.runModule,
|
|
48
|
+
shouldAddToIgnoreList: options.shouldAddToIgnoreList,
|
|
48
49
|
sourceMapUrl: options.sourceMapUrl,
|
|
49
50
|
sourceUrl: options.sourceUrl,
|
|
50
51
|
}),
|
|
@@ -64,6 +64,7 @@ function baseJSBundle(
|
|
|
64
64
|
inlineSourceMap: options.inlineSourceMap,
|
|
65
65
|
runBeforeMainModule: options.runBeforeMainModule,
|
|
66
66
|
runModule: options.runModule,
|
|
67
|
+
shouldAddToIgnoreList: options.shouldAddToIgnoreList,
|
|
67
68
|
sourceMapUrl: options.sourceMapUrl,
|
|
68
69
|
sourceUrl: options.sourceUrl,
|
|
69
70
|
}),
|
|
@@ -31,6 +31,7 @@ async function getRamBundleInfo(entryPoint, pre, graph, options) {
|
|
|
31
31
|
map: sourceMapObject([module], {
|
|
32
32
|
excludeSource: options.excludeSource,
|
|
33
33
|
processModuleFilter: options.processModuleFilter,
|
|
34
|
+
shouldAddToIgnoreList: options.shouldAddToIgnoreList,
|
|
34
35
|
}),
|
|
35
36
|
name: path.basename(module.path),
|
|
36
37
|
sourcePath: module.path,
|
|
@@ -16,6 +16,7 @@ import type {
|
|
|
16
16
|
RamModuleTransport,
|
|
17
17
|
} from '../../shared/types.flow';
|
|
18
18
|
import type {Module, ReadOnlyGraph, SerializerOptions} from '../types.flow';
|
|
19
|
+
import type {SourceMapGeneratorOptions} from './sourceMapGenerator';
|
|
19
20
|
import type {GetTransformOptions} from 'metro-config/src/configTypes.flow.js';
|
|
20
21
|
|
|
21
22
|
const {createRamBundleGroups} = require('../../Bundler/util');
|
|
@@ -28,7 +29,7 @@ const path = require('path');
|
|
|
28
29
|
|
|
29
30
|
type Options = $ReadOnly<{
|
|
30
31
|
...SerializerOptions,
|
|
31
|
-
|
|
32
|
+
...SourceMapGeneratorOptions,
|
|
32
33
|
getTransformOptions: ?GetTransformOptions,
|
|
33
34
|
platform: ?string,
|
|
34
35
|
}>;
|
|
@@ -63,6 +64,7 @@ async function getRamBundleInfo(
|
|
|
63
64
|
map: sourceMapObject([module], {
|
|
64
65
|
excludeSource: options.excludeSource,
|
|
65
66
|
processModuleFilter: options.processModuleFilter,
|
|
67
|
+
shouldAddToIgnoreList: options.shouldAddToIgnoreList,
|
|
66
68
|
}),
|
|
67
69
|
name: path.basename(module.path),
|
|
68
70
|
sourcePath: module.path,
|
|
@@ -15,6 +15,7 @@ const { getJsOutput } = require("./js");
|
|
|
15
15
|
function getSourceMapInfo(module, options) {
|
|
16
16
|
return {
|
|
17
17
|
...getJsOutput(module).data,
|
|
18
|
+
isIgnored: options.shouldAddToIgnoreList(module),
|
|
18
19
|
path: module.path,
|
|
19
20
|
source: options.excludeSource ? "" : getModuleSource(module),
|
|
20
21
|
};
|
|
@@ -23,6 +23,7 @@ function getSourceMapInfo(
|
|
|
23
23
|
module: Module<>,
|
|
24
24
|
options: {
|
|
25
25
|
+excludeSource: boolean,
|
|
26
|
+
+shouldAddToIgnoreList: (Module<>) => boolean,
|
|
26
27
|
},
|
|
27
28
|
): {
|
|
28
29
|
+map: Array<MetroSourceMapSegmentTuple>,
|
|
@@ -31,9 +32,11 @@ function getSourceMapInfo(
|
|
|
31
32
|
+path: string,
|
|
32
33
|
+source: string,
|
|
33
34
|
+lineCount: number,
|
|
35
|
+
+isIgnored: boolean,
|
|
34
36
|
} {
|
|
35
37
|
return {
|
|
36
38
|
...getJsOutput(module).data,
|
|
39
|
+
isIgnored: options.shouldAddToIgnoreList(module),
|
|
37
40
|
path: module.path,
|
|
38
41
|
source: options.excludeSource ? '' : getModuleSource(module),
|
|
39
42
|
};
|
|
@@ -29,6 +29,7 @@ function getSourceMapInfosImpl(isBlocking, onDone, modules, options) {
|
|
|
29
29
|
const mod = modulesToProcess.shift();
|
|
30
30
|
const info = getSourceMapInfo(mod, {
|
|
31
31
|
excludeSource: options.excludeSource,
|
|
32
|
+
shouldAddToIgnoreList: options.shouldAddToIgnoreList,
|
|
32
33
|
});
|
|
33
34
|
sourceMapInfos.push(info);
|
|
34
35
|
return false;
|
|
@@ -13,6 +13,12 @@
|
|
|
13
13
|
|
|
14
14
|
import type {Module} from '../types.flow';
|
|
15
15
|
|
|
16
|
+
export type SourceMapGeneratorOptions = $ReadOnly<{
|
|
17
|
+
excludeSource: boolean,
|
|
18
|
+
processModuleFilter: (module: Module<>) => boolean,
|
|
19
|
+
shouldAddToIgnoreList: (module: Module<>) => boolean,
|
|
20
|
+
}>;
|
|
21
|
+
|
|
16
22
|
const getSourceMapInfo = require('./helpers/getSourceMapInfo');
|
|
17
23
|
const {isJsModule} = require('./helpers/js');
|
|
18
24
|
const {
|
|
@@ -26,10 +32,7 @@ function getSourceMapInfosImpl(
|
|
|
26
32
|
isBlocking: boolean,
|
|
27
33
|
onDone: ($ReadOnlyArray<ReturnType<typeof getSourceMapInfo>>) => void,
|
|
28
34
|
modules: $ReadOnlyArray<Module<>>,
|
|
29
|
-
options:
|
|
30
|
-
+excludeSource: boolean,
|
|
31
|
-
+processModuleFilter: (module: Module<>) => boolean,
|
|
32
|
-
},
|
|
35
|
+
options: SourceMapGeneratorOptions,
|
|
33
36
|
): void {
|
|
34
37
|
const sourceMapInfos = [];
|
|
35
38
|
const modulesToProcess = modules
|
|
@@ -44,6 +47,7 @@ function getSourceMapInfosImpl(
|
|
|
44
47
|
const mod = modulesToProcess.shift();
|
|
45
48
|
const info = getSourceMapInfo(mod, {
|
|
46
49
|
excludeSource: options.excludeSource,
|
|
50
|
+
shouldAddToIgnoreList: options.shouldAddToIgnoreList,
|
|
47
51
|
});
|
|
48
52
|
sourceMapInfos.push(info);
|
|
49
53
|
return false;
|
|
@@ -77,10 +81,7 @@ function getSourceMapInfosImpl(
|
|
|
77
81
|
|
|
78
82
|
function sourceMapGenerator(
|
|
79
83
|
modules: $ReadOnlyArray<Module<>>,
|
|
80
|
-
options:
|
|
81
|
-
+excludeSource: boolean,
|
|
82
|
-
+processModuleFilter: (module: Module<>) => boolean,
|
|
83
|
-
},
|
|
84
|
+
options: SourceMapGeneratorOptions,
|
|
84
85
|
): ReturnType<typeof fromRawMappings> {
|
|
85
86
|
let sourceMapInfos;
|
|
86
87
|
getSourceMapInfosImpl(
|
|
@@ -101,10 +102,7 @@ function sourceMapGenerator(
|
|
|
101
102
|
|
|
102
103
|
async function sourceMapGeneratorNonBlocking(
|
|
103
104
|
modules: $ReadOnlyArray<Module<>>,
|
|
104
|
-
options:
|
|
105
|
-
+excludeSource: boolean,
|
|
106
|
-
+processModuleFilter: (module: Module<>) => boolean,
|
|
107
|
-
},
|
|
105
|
+
options: SourceMapGeneratorOptions,
|
|
108
106
|
): ReturnType<typeof fromRawMappingsNonBlocking> {
|
|
109
107
|
const sourceMapInfos = await new Promise<
|
|
110
108
|
$ReadOnlyArray<ReturnType<typeof getSourceMapInfo>>,
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
14
|
import type {Module} from '../types.flow';
|
|
15
|
+
import type {SourceMapGeneratorOptions} from './sourceMapGenerator';
|
|
15
16
|
import type {MixedSourceMap} from 'metro-source-map';
|
|
16
17
|
|
|
17
18
|
const {
|
|
@@ -21,10 +22,7 @@ const {
|
|
|
21
22
|
|
|
22
23
|
function sourceMapObject(
|
|
23
24
|
modules: $ReadOnlyArray<Module<>>,
|
|
24
|
-
options:
|
|
25
|
-
+excludeSource: boolean,
|
|
26
|
-
+processModuleFilter: (module: Module<>) => boolean,
|
|
27
|
-
},
|
|
25
|
+
options: SourceMapGeneratorOptions,
|
|
28
26
|
): MixedSourceMap {
|
|
29
27
|
const generator = sourceMapGenerator(modules, options);
|
|
30
28
|
return generator.toMap(undefined, {
|
|
@@ -34,10 +32,7 @@ function sourceMapObject(
|
|
|
34
32
|
|
|
35
33
|
async function sourceMapObjectNonBlocking(
|
|
36
34
|
modules: $ReadOnlyArray<Module<>>,
|
|
37
|
-
options:
|
|
38
|
-
+excludeSource: boolean,
|
|
39
|
-
+processModuleFilter: (module: Module<>) => boolean,
|
|
40
|
-
},
|
|
35
|
+
options: SourceMapGeneratorOptions,
|
|
41
36
|
): Promise<MixedSourceMap> {
|
|
42
37
|
const generator = await sourceMapGeneratorNonBlocking(modules, options);
|
|
43
38
|
return generator.toMap(undefined, {
|
|
@@ -12,15 +12,13 @@
|
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
14
|
import type {Module} from '../types.flow';
|
|
15
|
+
import type {SourceMapGeneratorOptions} from './sourceMapGenerator';
|
|
15
16
|
|
|
16
17
|
const {sourceMapGenerator} = require('./sourceMapGenerator');
|
|
17
18
|
|
|
18
19
|
function sourceMapString(
|
|
19
20
|
modules: $ReadOnlyArray<Module<>>,
|
|
20
|
-
options:
|
|
21
|
-
+excludeSource: boolean,
|
|
22
|
-
+processModuleFilter: (module: Module<>) => boolean,
|
|
23
|
-
},
|
|
21
|
+
options: SourceMapGeneratorOptions,
|
|
24
22
|
): string {
|
|
25
23
|
return sourceMapGenerator(modules, options).toString(undefined, {
|
|
26
24
|
excludeSource: options.excludeSource,
|
|
@@ -164,6 +164,7 @@ export interface SerializerOptions<T = MixedOutput> {
|
|
|
164
164
|
readonly runBeforeMainModule: ReadonlyArray<string>;
|
|
165
165
|
readonly runModule: boolean;
|
|
166
166
|
readonly serverRoot: string;
|
|
167
|
+
readonly shouldAddToIgnoreList: (module: Module<T>) => boolean;
|
|
167
168
|
readonly sourceMapUrl?: string;
|
|
168
169
|
readonly sourceUrl?: string;
|
|
169
170
|
}
|
package/src/Server.js
CHANGED
|
@@ -136,6 +136,8 @@ class Server {
|
|
|
136
136
|
inlineSourceMap: serializerOptions.inlineSourceMap,
|
|
137
137
|
serverRoot:
|
|
138
138
|
this._config.server.unstable_serverRoot ?? this._config.projectRoot,
|
|
139
|
+
shouldAddToIgnoreList: (module) =>
|
|
140
|
+
this._shouldAddModuleToIgnoreList(module),
|
|
139
141
|
};
|
|
140
142
|
let bundleCode = null;
|
|
141
143
|
let bundleMap = null;
|
|
@@ -163,6 +165,7 @@ class Server {
|
|
|
163
165
|
{
|
|
164
166
|
excludeSource: serializerOptions.excludeSource,
|
|
165
167
|
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
168
|
+
shouldAddToIgnoreList: bundleOptions.shouldAddToIgnoreList,
|
|
166
169
|
}
|
|
167
170
|
);
|
|
168
171
|
}
|
|
@@ -220,6 +223,8 @@ class Server {
|
|
|
220
223
|
inlineSourceMap: serializerOptions.inlineSourceMap,
|
|
221
224
|
serverRoot:
|
|
222
225
|
this._config.server.unstable_serverRoot ?? this._config.projectRoot,
|
|
226
|
+
shouldAddToIgnoreList: (module) =>
|
|
227
|
+
this._shouldAddModuleToIgnoreList(module),
|
|
223
228
|
});
|
|
224
229
|
}
|
|
225
230
|
async getAssets(options) {
|
|
@@ -683,6 +688,8 @@ class Server {
|
|
|
683
688
|
inlineSourceMap: serializerOptions.inlineSourceMap,
|
|
684
689
|
serverRoot:
|
|
685
690
|
this._config.server.unstable_serverRoot ?? this._config.projectRoot,
|
|
691
|
+
shouldAddToIgnoreList: (module) =>
|
|
692
|
+
this._shouldAddModuleToIgnoreList(module),
|
|
686
693
|
}
|
|
687
694
|
);
|
|
688
695
|
bundlePerfLogger.point("serializingBundle_end");
|
|
@@ -792,6 +799,8 @@ class Server {
|
|
|
792
799
|
return sourceMapString([...prepend, ...this._getSortedModules(graph)], {
|
|
793
800
|
excludeSource: serializerOptions.excludeSource,
|
|
794
801
|
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
802
|
+
shouldAddToIgnoreList: (module) =>
|
|
803
|
+
this._shouldAddModuleToIgnoreList(module),
|
|
795
804
|
});
|
|
796
805
|
},
|
|
797
806
|
finish({ mres, result }) {
|
|
@@ -1057,6 +1066,17 @@ class Server {
|
|
|
1057
1066
|
async ready() {
|
|
1058
1067
|
await this._bundler.ready();
|
|
1059
1068
|
}
|
|
1069
|
+
_shouldAddModuleToIgnoreList(module) {
|
|
1070
|
+
// TODO: Add flag to Module signifying whether it represents generated code
|
|
1071
|
+
// and clean up these heuristics.
|
|
1072
|
+
return (
|
|
1073
|
+
// Prelude code, see getPrependedScripts.js
|
|
1074
|
+
module.path === "__prelude__" ||
|
|
1075
|
+
// Generated require.context() module, see contextModule.js
|
|
1076
|
+
module.path.includes("?ctx=") ||
|
|
1077
|
+
this._config.serializer.isThirdPartyModule(module)
|
|
1078
|
+
);
|
|
1079
|
+
}
|
|
1060
1080
|
}
|
|
1061
1081
|
function* zip(xs, ys) {
|
|
1062
1082
|
//$FlowIssue #9324959
|
package/src/Server.js.flow
CHANGED
|
@@ -233,6 +233,8 @@ class Server {
|
|
|
233
233
|
inlineSourceMap: serializerOptions.inlineSourceMap,
|
|
234
234
|
serverRoot:
|
|
235
235
|
this._config.server.unstable_serverRoot ?? this._config.projectRoot,
|
|
236
|
+
shouldAddToIgnoreList: (module: Module<>) =>
|
|
237
|
+
this._shouldAddModuleToIgnoreList(module),
|
|
236
238
|
};
|
|
237
239
|
let bundleCode = null;
|
|
238
240
|
let bundleMap = null;
|
|
@@ -260,6 +262,7 @@ class Server {
|
|
|
260
262
|
{
|
|
261
263
|
excludeSource: serializerOptions.excludeSource,
|
|
262
264
|
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
265
|
+
shouldAddToIgnoreList: bundleOptions.shouldAddToIgnoreList,
|
|
263
266
|
},
|
|
264
267
|
);
|
|
265
268
|
}
|
|
@@ -321,6 +324,8 @@ class Server {
|
|
|
321
324
|
inlineSourceMap: serializerOptions.inlineSourceMap,
|
|
322
325
|
serverRoot:
|
|
323
326
|
this._config.server.unstable_serverRoot ?? this._config.projectRoot,
|
|
327
|
+
shouldAddToIgnoreList: (module: Module<>) =>
|
|
328
|
+
this._shouldAddModuleToIgnoreList(module),
|
|
324
329
|
});
|
|
325
330
|
}
|
|
326
331
|
|
|
@@ -875,6 +880,8 @@ class Server {
|
|
|
875
880
|
inlineSourceMap: serializerOptions.inlineSourceMap,
|
|
876
881
|
serverRoot:
|
|
877
882
|
this._config.server.unstable_serverRoot ?? this._config.projectRoot,
|
|
883
|
+
shouldAddToIgnoreList: (module: Module<>) =>
|
|
884
|
+
this._shouldAddModuleToIgnoreList(module),
|
|
878
885
|
},
|
|
879
886
|
);
|
|
880
887
|
bundlePerfLogger.point('serializingBundle_end');
|
|
@@ -996,6 +1003,8 @@ class Server {
|
|
|
996
1003
|
return sourceMapString([...prepend, ...this._getSortedModules(graph)], {
|
|
997
1004
|
excludeSource: serializerOptions.excludeSource,
|
|
998
1005
|
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
1006
|
+
shouldAddToIgnoreList: (module: Module<>) =>
|
|
1007
|
+
this._shouldAddModuleToIgnoreList(module),
|
|
999
1008
|
});
|
|
1000
1009
|
},
|
|
1001
1010
|
finish({mres, result}) {
|
|
@@ -1309,6 +1318,18 @@ class Server {
|
|
|
1309
1318
|
async ready(): Promise<void> {
|
|
1310
1319
|
await this._bundler.ready();
|
|
1311
1320
|
}
|
|
1321
|
+
|
|
1322
|
+
_shouldAddModuleToIgnoreList(module: Module<>): boolean {
|
|
1323
|
+
// TODO: Add flag to Module signifying whether it represents generated code
|
|
1324
|
+
// and clean up these heuristics.
|
|
1325
|
+
return (
|
|
1326
|
+
// Prelude code, see getPrependedScripts.js
|
|
1327
|
+
module.path === '__prelude__' ||
|
|
1328
|
+
// Generated require.context() module, see contextModule.js
|
|
1329
|
+
module.path.includes('?ctx=') ||
|
|
1330
|
+
this._config.serializer.isThirdPartyModule(module)
|
|
1331
|
+
);
|
|
1332
|
+
}
|
|
1312
1333
|
}
|
|
1313
1334
|
|
|
1314
1335
|
function* zip<X, Y>(xs: Iterable<X>, ys: Iterable<Y>): Iterable<[X, Y]> {
|
|
@@ -20,17 +20,18 @@ const sourceMapString = require('../DeltaBundler/Serializers/sourceMapString');
|
|
|
20
20
|
const countLines = require('./countLines');
|
|
21
21
|
const nullthrows = require('nullthrows');
|
|
22
22
|
|
|
23
|
-
type Options<T: number | string> = {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
type Options<T: number | string> = $ReadOnly<{
|
|
24
|
+
asyncRequireModulePath: string,
|
|
25
|
+
createModuleId: string => T,
|
|
26
|
+
getRunModuleStatement: T => string,
|
|
27
|
+
inlineSourceMap: ?boolean,
|
|
28
|
+
runBeforeMainModule: $ReadOnlyArray<string>,
|
|
29
|
+
runModule: boolean,
|
|
30
|
+
shouldAddToIgnoreList: (Module<>) => boolean,
|
|
31
|
+
sourceMapUrl: ?string,
|
|
32
|
+
sourceUrl: ?string,
|
|
32
33
|
...
|
|
33
|
-
}
|
|
34
|
+
}>;
|
|
34
35
|
|
|
35
36
|
function getAppendScripts<T: number | string>(
|
|
36
37
|
entryPoint: string,
|
|
@@ -73,6 +74,7 @@ function getAppendScripts<T: number | string>(
|
|
|
73
74
|
sourceMapString(modules, {
|
|
74
75
|
processModuleFilter: (): boolean => true,
|
|
75
76
|
excludeSource: false,
|
|
77
|
+
shouldAddToIgnoreList: options.shouldAddToIgnoreList,
|
|
76
78
|
}),
|
|
77
79
|
)
|
|
78
80
|
: nullthrows(options.sourceMapUrl);
|