metro-source-map 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 +3 -3
- package/src/Generator.js +42 -22
- package/src/Generator.js.flow +59 -23
- package/src/composeSourceMaps.js +6 -0
- package/src/composeSourceMaps.js.flow +6 -0
- package/src/source-map.js +3 -1
- package/src/source-map.js.flow +13 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "metro-source-map",
|
|
3
|
-
"version": "0.76.
|
|
3
|
+
"version": "0.76.4",
|
|
4
4
|
"description": "🚇 Source map generator for Metro.",
|
|
5
5
|
"main": "src/source-map.js",
|
|
6
6
|
"repository": {
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
"@babel/traverse": "^7.20.0",
|
|
16
16
|
"@babel/types": "^7.20.0",
|
|
17
17
|
"invariant": "^2.2.4",
|
|
18
|
-
"metro-symbolicate": "0.76.
|
|
18
|
+
"metro-symbolicate": "0.76.4",
|
|
19
19
|
"nullthrows": "^1.1.1",
|
|
20
|
-
"ob1": "0.76.
|
|
20
|
+
"ob1": "0.76.4",
|
|
21
21
|
"source-map": "^0.5.6",
|
|
22
22
|
"vlq": "^1.0.0"
|
|
23
23
|
},
|
package/src/Generator.js
CHANGED
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
"use strict";
|
|
13
13
|
|
|
14
14
|
const B64Builder = require("./B64Builder");
|
|
15
|
-
|
|
16
15
|
/**
|
|
17
16
|
* Generates a source map from raw mappings.
|
|
18
17
|
*
|
|
@@ -25,6 +24,8 @@ const B64Builder = require("./B64Builder");
|
|
|
25
24
|
* Mappings have to be passed in the order appearance in the generated source.
|
|
26
25
|
*/
|
|
27
26
|
class Generator {
|
|
27
|
+
// https://developer.chrome.com/blog/devtools-better-angular-debugging/#the-x_google_ignorelist-source-map-extension
|
|
28
|
+
|
|
28
29
|
constructor() {
|
|
29
30
|
this.builder = new B64Builder();
|
|
30
31
|
this.last = {
|
|
@@ -41,15 +42,21 @@ class Generator {
|
|
|
41
42
|
this.sources = [];
|
|
42
43
|
this.sourcesContent = [];
|
|
43
44
|
this.x_facebook_sources = [];
|
|
45
|
+
this.x_google_ignoreList = [];
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
/**
|
|
47
49
|
* Mark the beginning of a new source file.
|
|
48
50
|
*/
|
|
49
|
-
startFile(file, code, functionMap) {
|
|
50
|
-
|
|
51
|
+
startFile(file, code, functionMap, flags) {
|
|
52
|
+
const { addToIgnoreList = false } = flags ?? {};
|
|
53
|
+
const sourceIndex = this.sources.push(file) - 1;
|
|
54
|
+
this.source = sourceIndex;
|
|
51
55
|
this.sourcesContent.push(code);
|
|
52
56
|
this.x_facebook_sources.push(functionMap ? [functionMap] : null);
|
|
57
|
+
if (addToIgnoreList) {
|
|
58
|
+
this.x_google_ignoreList.push(sourceIndex);
|
|
59
|
+
}
|
|
53
60
|
}
|
|
54
61
|
|
|
55
62
|
/**
|
|
@@ -126,28 +133,31 @@ class Generator {
|
|
|
126
133
|
* Return the source map as object.
|
|
127
134
|
*/
|
|
128
135
|
toMap(file, options) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
136
|
+
const content =
|
|
137
|
+
options && options.excludeSource === true
|
|
138
|
+
? {}
|
|
139
|
+
: {
|
|
140
|
+
sourcesContent: this.sourcesContent.slice(),
|
|
141
|
+
};
|
|
142
|
+
const sourcesMetadata = this.hasSourcesMetadata()
|
|
143
|
+
? {
|
|
144
|
+
x_facebook_sources: JSON.parse(
|
|
145
|
+
JSON.stringify(this.x_facebook_sources)
|
|
146
|
+
),
|
|
147
|
+
}
|
|
148
|
+
: {};
|
|
149
|
+
const ignoreList = this.x_google_ignoreList.length
|
|
150
|
+
? {
|
|
151
|
+
x_google_ignoreList: this.x_google_ignoreList,
|
|
152
|
+
}
|
|
153
|
+
: {};
|
|
144
154
|
return {
|
|
145
155
|
version: 3,
|
|
146
156
|
file,
|
|
147
157
|
sources: this.sources.slice(),
|
|
148
|
-
// $FlowFixMe[exponential-spread]
|
|
149
158
|
...content,
|
|
150
159
|
...sourcesMetadata,
|
|
160
|
+
...ignoreList,
|
|
151
161
|
names: this.names.items(),
|
|
152
162
|
mappings: this.builder.toString(),
|
|
153
163
|
};
|
|
@@ -159,12 +169,13 @@ class Generator {
|
|
|
159
169
|
* This is ~2.5x faster than calling `JSON.stringify(generator.toMap())`
|
|
160
170
|
*/
|
|
161
171
|
toString(file, options) {
|
|
162
|
-
let content
|
|
163
|
-
if (options && options.excludeSource) {
|
|
172
|
+
let content;
|
|
173
|
+
if (options && options.excludeSource === true) {
|
|
164
174
|
content = "";
|
|
165
175
|
} else {
|
|
166
176
|
content = `"sourcesContent":${JSON.stringify(this.sourcesContent)},`;
|
|
167
177
|
}
|
|
178
|
+
let sourcesMetadata;
|
|
168
179
|
if (this.hasSourcesMetadata()) {
|
|
169
180
|
sourcesMetadata = `"x_facebook_sources":${JSON.stringify(
|
|
170
181
|
this.x_facebook_sources
|
|
@@ -172,13 +183,22 @@ class Generator {
|
|
|
172
183
|
} else {
|
|
173
184
|
sourcesMetadata = "";
|
|
174
185
|
}
|
|
186
|
+
let ignoreList;
|
|
187
|
+
if (this.x_google_ignoreList.length) {
|
|
188
|
+
ignoreList = `"x_google_ignoreList":${JSON.stringify(
|
|
189
|
+
this.x_google_ignoreList
|
|
190
|
+
)},`;
|
|
191
|
+
} else {
|
|
192
|
+
ignoreList = "";
|
|
193
|
+
}
|
|
175
194
|
return (
|
|
176
195
|
"{" +
|
|
177
196
|
'"version":3,' +
|
|
178
|
-
(file ? `"file":${JSON.stringify(file)},` : "") +
|
|
197
|
+
(file != null ? `"file":${JSON.stringify(file)},` : "") +
|
|
179
198
|
`"sources":${JSON.stringify(this.sources)},` +
|
|
180
199
|
content +
|
|
181
200
|
sourcesMetadata +
|
|
201
|
+
ignoreList +
|
|
182
202
|
`"names":${JSON.stringify(this.names.items())},` +
|
|
183
203
|
`"mappings":"${this.builder.toString()}"` +
|
|
184
204
|
"}"
|
package/src/Generator.js.flow
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
|
-
* @flow
|
|
7
|
+
* @flow strict-local
|
|
8
8
|
* @format
|
|
9
9
|
* @oncall react_native
|
|
10
10
|
*/
|
|
@@ -19,6 +19,10 @@ import type {
|
|
|
19
19
|
|
|
20
20
|
const B64Builder = require('./B64Builder');
|
|
21
21
|
|
|
22
|
+
type FileFlags = $ReadOnly<{
|
|
23
|
+
addToIgnoreList?: boolean,
|
|
24
|
+
}>;
|
|
25
|
+
|
|
22
26
|
/**
|
|
23
27
|
* Generates a source map from raw mappings.
|
|
24
28
|
*
|
|
@@ -45,6 +49,8 @@ class Generator {
|
|
|
45
49
|
sources: Array<string>;
|
|
46
50
|
sourcesContent: Array<?string>;
|
|
47
51
|
x_facebook_sources: Array<?FBSourceMetadata>;
|
|
52
|
+
// https://developer.chrome.com/blog/devtools-better-angular-debugging/#the-x_google_ignorelist-source-map-extension
|
|
53
|
+
x_google_ignoreList: Array<number>;
|
|
48
54
|
|
|
49
55
|
constructor() {
|
|
50
56
|
this.builder = new B64Builder();
|
|
@@ -61,15 +67,26 @@ class Generator {
|
|
|
61
67
|
this.sources = [];
|
|
62
68
|
this.sourcesContent = [];
|
|
63
69
|
this.x_facebook_sources = [];
|
|
70
|
+
this.x_google_ignoreList = [];
|
|
64
71
|
}
|
|
65
72
|
|
|
66
73
|
/**
|
|
67
74
|
* Mark the beginning of a new source file.
|
|
68
75
|
*/
|
|
69
|
-
startFile(
|
|
70
|
-
|
|
76
|
+
startFile(
|
|
77
|
+
file: string,
|
|
78
|
+
code: string,
|
|
79
|
+
functionMap: ?FBSourceFunctionMap,
|
|
80
|
+
flags?: FileFlags,
|
|
81
|
+
) {
|
|
82
|
+
const {addToIgnoreList = false} = flags ?? {};
|
|
83
|
+
const sourceIndex = this.sources.push(file) - 1;
|
|
84
|
+
this.source = sourceIndex;
|
|
71
85
|
this.sourcesContent.push(code);
|
|
72
86
|
this.x_facebook_sources.push(functionMap ? [functionMap] : null);
|
|
87
|
+
if (addToIgnoreList) {
|
|
88
|
+
this.x_google_ignoreList.push(sourceIndex);
|
|
89
|
+
}
|
|
73
90
|
}
|
|
74
91
|
|
|
75
92
|
/**
|
|
@@ -159,32 +176,41 @@ class Generator {
|
|
|
159
176
|
file?: string,
|
|
160
177
|
options?: {excludeSource?: boolean, ...},
|
|
161
178
|
): BasicSourceMap {
|
|
162
|
-
|
|
179
|
+
const content: {
|
|
180
|
+
sourcesContent?: Array<?string>,
|
|
181
|
+
} =
|
|
182
|
+
options && options.excludeSource === true
|
|
183
|
+
? {}
|
|
184
|
+
: {sourcesContent: this.sourcesContent.slice()};
|
|
163
185
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
186
|
+
const sourcesMetadata: {
|
|
187
|
+
x_facebook_sources?: Array<FBSourceMetadata>,
|
|
188
|
+
} = this.hasSourcesMetadata()
|
|
189
|
+
? {
|
|
190
|
+
x_facebook_sources: JSON.parse(
|
|
191
|
+
JSON.stringify(this.x_facebook_sources),
|
|
192
|
+
),
|
|
193
|
+
}
|
|
194
|
+
: {};
|
|
169
195
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
196
|
+
const ignoreList: {
|
|
197
|
+
x_google_ignoreList?: Array<number>,
|
|
198
|
+
} = this.x_google_ignoreList.length
|
|
199
|
+
? {
|
|
200
|
+
x_google_ignoreList: this.x_google_ignoreList,
|
|
201
|
+
}
|
|
202
|
+
: {};
|
|
177
203
|
|
|
178
|
-
return {
|
|
204
|
+
return ({
|
|
179
205
|
version: 3,
|
|
180
206
|
file,
|
|
181
207
|
sources: this.sources.slice(),
|
|
182
|
-
// $FlowFixMe[exponential-spread]
|
|
183
208
|
...content,
|
|
184
209
|
...sourcesMetadata,
|
|
210
|
+
...ignoreList,
|
|
185
211
|
names: this.names.items(),
|
|
186
212
|
mappings: this.builder.toString(),
|
|
187
|
-
};
|
|
213
|
+
}: BasicSourceMap);
|
|
188
214
|
}
|
|
189
215
|
|
|
190
216
|
/**
|
|
@@ -193,14 +219,14 @@ class Generator {
|
|
|
193
219
|
* This is ~2.5x faster than calling `JSON.stringify(generator.toMap())`
|
|
194
220
|
*/
|
|
195
221
|
toString(file?: string, options?: {excludeSource?: boolean, ...}): string {
|
|
196
|
-
let content
|
|
197
|
-
|
|
198
|
-
if (options && options.excludeSource) {
|
|
222
|
+
let content;
|
|
223
|
+
if (options && options.excludeSource === true) {
|
|
199
224
|
content = '';
|
|
200
225
|
} else {
|
|
201
226
|
content = `"sourcesContent":${JSON.stringify(this.sourcesContent)},`;
|
|
202
227
|
}
|
|
203
228
|
|
|
229
|
+
let sourcesMetadata;
|
|
204
230
|
if (this.hasSourcesMetadata()) {
|
|
205
231
|
sourcesMetadata = `"x_facebook_sources":${JSON.stringify(
|
|
206
232
|
this.x_facebook_sources,
|
|
@@ -209,13 +235,23 @@ class Generator {
|
|
|
209
235
|
sourcesMetadata = '';
|
|
210
236
|
}
|
|
211
237
|
|
|
238
|
+
let ignoreList;
|
|
239
|
+
if (this.x_google_ignoreList.length) {
|
|
240
|
+
ignoreList = `"x_google_ignoreList":${JSON.stringify(
|
|
241
|
+
this.x_google_ignoreList,
|
|
242
|
+
)},`;
|
|
243
|
+
} else {
|
|
244
|
+
ignoreList = '';
|
|
245
|
+
}
|
|
246
|
+
|
|
212
247
|
return (
|
|
213
248
|
'{' +
|
|
214
249
|
'"version":3,' +
|
|
215
|
-
(file ? `"file":${JSON.stringify(file)},` : '') +
|
|
250
|
+
(file != null ? `"file":${JSON.stringify(file)},` : '') +
|
|
216
251
|
`"sources":${JSON.stringify(this.sources)},` +
|
|
217
252
|
content +
|
|
218
253
|
sourcesMetadata +
|
|
254
|
+
ignoreList +
|
|
219
255
|
`"names":${JSON.stringify(this.names.items())},` +
|
|
220
256
|
`"mappings":"${this.builder.toString()}"` +
|
|
221
257
|
'}'
|
package/src/composeSourceMaps.js
CHANGED
|
@@ -21,6 +21,7 @@ Consumer;
|
|
|
21
21
|
function composeSourceMaps(maps) {
|
|
22
22
|
// NOTE: require() here to break dependency cycle
|
|
23
23
|
const SourceMetadataMapConsumer = require("metro-symbolicate/src/SourceMetadataMapConsumer");
|
|
24
|
+
const GoogleIgnoreListConsumer = require("metro-symbolicate/src/GoogleIgnoreListConsumer");
|
|
24
25
|
if (maps.length < 1) {
|
|
25
26
|
throw new Error("composeSourceMaps: Expected at least one map");
|
|
26
27
|
}
|
|
@@ -70,6 +71,11 @@ function composeSourceMaps(maps) {
|
|
|
70
71
|
if (function_offsets) {
|
|
71
72
|
composedMap.x_hermes_function_offsets = function_offsets;
|
|
72
73
|
}
|
|
74
|
+
const ignoreListConsumer = new GoogleIgnoreListConsumer(firstMap);
|
|
75
|
+
const x_google_ignoreList = ignoreListConsumer.toArray(composedMap.sources);
|
|
76
|
+
if (x_google_ignoreList.length) {
|
|
77
|
+
composedMap.x_google_ignoreList = x_google_ignoreList;
|
|
78
|
+
}
|
|
73
79
|
return composedMap;
|
|
74
80
|
}
|
|
75
81
|
function findOriginalPosition(consumers, generatedLine, generatedColumn) {
|
|
@@ -27,6 +27,7 @@ function composeSourceMaps(
|
|
|
27
27
|
): MixedSourceMap {
|
|
28
28
|
// NOTE: require() here to break dependency cycle
|
|
29
29
|
const SourceMetadataMapConsumer = require('metro-symbolicate/src/SourceMetadataMapConsumer');
|
|
30
|
+
const GoogleIgnoreListConsumer = require('metro-symbolicate/src/GoogleIgnoreListConsumer');
|
|
30
31
|
if (maps.length < 1) {
|
|
31
32
|
throw new Error('composeSourceMaps: Expected at least one map');
|
|
32
33
|
}
|
|
@@ -81,6 +82,11 @@ function composeSourceMaps(
|
|
|
81
82
|
if (function_offsets) {
|
|
82
83
|
composedMap.x_hermes_function_offsets = function_offsets;
|
|
83
84
|
}
|
|
85
|
+
const ignoreListConsumer = new GoogleIgnoreListConsumer(firstMap);
|
|
86
|
+
const x_google_ignoreList = ignoreListConsumer.toArray(composedMap.sources);
|
|
87
|
+
if (x_google_ignoreList.length) {
|
|
88
|
+
composedMap.x_google_ignoreList = x_google_ignoreList;
|
|
89
|
+
}
|
|
84
90
|
return composedMap;
|
|
85
91
|
}
|
|
86
92
|
|
package/src/source-map.js
CHANGED
|
@@ -139,7 +139,9 @@ function toSegmentTuple(mapping) {
|
|
|
139
139
|
return [line, column, original.line, original.column, name];
|
|
140
140
|
}
|
|
141
141
|
function addMappingsForFile(generator, mappings, module, carryOver) {
|
|
142
|
-
generator.startFile(module.path, module.source, module.functionMap
|
|
142
|
+
generator.startFile(module.path, module.source, module.functionMap, {
|
|
143
|
+
addToIgnoreList: module.isIgnored,
|
|
144
|
+
});
|
|
143
145
|
for (let i = 0, n = mappings.length; i < n; ++i) {
|
|
144
146
|
addMapping(generator, mappings[i], carryOver);
|
|
145
147
|
}
|
package/src/source-map.js.flow
CHANGED
|
@@ -59,6 +59,7 @@ export type BasicSourceMap = {
|
|
|
59
59
|
+x_facebook_sources?: FBSourcesArray,
|
|
60
60
|
+x_facebook_segments?: FBSegmentMap,
|
|
61
61
|
+x_hermes_function_offsets?: HermesFunctionOffsets,
|
|
62
|
+
+x_google_ignoreList?: Array<number>,
|
|
62
63
|
};
|
|
63
64
|
|
|
64
65
|
export type IndexMapSection = {
|
|
@@ -82,6 +83,7 @@ export type IndexMap = {
|
|
|
82
83
|
+x_facebook_sources?: void,
|
|
83
84
|
+x_facebook_segments?: FBSegmentMap,
|
|
84
85
|
+x_hermes_function_offsets?: HermesFunctionOffsets,
|
|
86
|
+
+x_google_ignoreList?: void,
|
|
85
87
|
};
|
|
86
88
|
|
|
87
89
|
export type MixedSourceMap = IndexMap | BasicSourceMap;
|
|
@@ -104,7 +106,8 @@ function fromRawMappingsImpl(
|
|
|
104
106
|
+path: string,
|
|
105
107
|
+source: string,
|
|
106
108
|
+code: string,
|
|
107
|
-
|
|
109
|
+
+isIgnored: boolean,
|
|
110
|
+
+lineCount?: number,
|
|
108
111
|
}>,
|
|
109
112
|
offsetLines: number,
|
|
110
113
|
): void {
|
|
@@ -171,7 +174,8 @@ function fromRawMappings(
|
|
|
171
174
|
+path: string,
|
|
172
175
|
+source: string,
|
|
173
176
|
+code: string,
|
|
174
|
-
|
|
177
|
+
+isIgnored: boolean,
|
|
178
|
+
+lineCount?: number,
|
|
175
179
|
}>,
|
|
176
180
|
offsetLines: number = 0,
|
|
177
181
|
): Generator {
|
|
@@ -197,7 +201,8 @@ async function fromRawMappingsNonBlocking(
|
|
|
197
201
|
+path: string,
|
|
198
202
|
+source: string,
|
|
199
203
|
+code: string,
|
|
200
|
-
|
|
204
|
+
+isIgnored: boolean,
|
|
205
|
+
+lineCount?: number,
|
|
201
206
|
}>,
|
|
202
207
|
offsetLines: number = 0,
|
|
203
208
|
): Promise<Generator> {
|
|
@@ -272,11 +277,14 @@ function addMappingsForFile(
|
|
|
272
277
|
+map: ?Array<MetroSourceMapSegmentTuple>,
|
|
273
278
|
+path: string,
|
|
274
279
|
+source: string,
|
|
275
|
-
|
|
280
|
+
+isIgnored: boolean,
|
|
281
|
+
+lineCount?: number,
|
|
276
282
|
},
|
|
277
283
|
carryOver: number,
|
|
278
284
|
) {
|
|
279
|
-
generator.startFile(module.path, module.source, module.functionMap
|
|
285
|
+
generator.startFile(module.path, module.source, module.functionMap, {
|
|
286
|
+
addToIgnoreList: module.isIgnored,
|
|
287
|
+
});
|
|
280
288
|
|
|
281
289
|
for (let i = 0, n = mappings.length; i < n; ++i) {
|
|
282
290
|
addMapping(generator, mappings[i], carryOver);
|