@dcloudio/uni-stacktracey 3.0.0-3071120230427001 → 3.0.0-3080420230531001
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/dist/uni-stacktracey.cjs.js +671 -671
- package/dist/uni-stacktracey.es.js +681 -681
- package/package.json +1 -1
|
@@ -10,201 +10,201 @@ var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
|
10
10
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
11
11
|
var os__default = /*#__PURE__*/_interopDefault(os);
|
|
12
12
|
|
|
13
|
-
/* ------------------------------------------------------------------------ */
|
|
14
|
-
const O = Object, isBrowser =
|
|
15
|
-
/* eslint-disable */
|
|
16
|
-
typeof window !== 'undefined' &&
|
|
17
|
-
/* eslint-disable */
|
|
18
|
-
window.window === window &&
|
|
19
|
-
/* eslint-disable */
|
|
20
|
-
window.navigator, nodeRequire = isBrowser ? null : module.require, // to prevent bundlers from expanding the require call
|
|
21
|
-
lastOf = (x) => x[x.length - 1], nixSlashes$1 = (x) => x.replace(/\\/g, '/'), pathRoot = isBrowser ? window.location.href : nixSlashes$1(process.cwd()) + '/';
|
|
22
|
-
/* ------------------------------------------------------------------------ */
|
|
23
|
-
class StackTracey {
|
|
24
|
-
constructor(input, uniPlatform, offset) {
|
|
25
|
-
this.itemsHeader = [];
|
|
26
|
-
this.isMP = false;
|
|
27
|
-
const originalInput = input, isParseableSyntaxError = input && input instanceof SyntaxError && !isBrowser;
|
|
28
|
-
/* new StackTracey () */
|
|
29
|
-
if (!input) {
|
|
30
|
-
input = new Error();
|
|
31
|
-
offset = offset === undefined ? 1 : offset;
|
|
32
|
-
}
|
|
33
|
-
/* new StackTracey (Error) */
|
|
34
|
-
if (input instanceof Error) {
|
|
35
|
-
input = input.stack || '';
|
|
36
|
-
}
|
|
37
|
-
/* new StackTracey (string) */
|
|
38
|
-
if (typeof input === 'string') {
|
|
39
|
-
this.isMP = uniPlatform === 'mp-weixin';
|
|
40
|
-
input = this.rawParse(input)
|
|
41
|
-
.slice(offset)
|
|
42
|
-
.map((x) => this.extractEntryMetadata(x));
|
|
43
|
-
}
|
|
44
|
-
/* new StackTracey (array) */
|
|
45
|
-
if (Array.isArray(input)) {
|
|
46
|
-
if (isParseableSyntaxError) {
|
|
47
|
-
const rawLines = nodeRequire('util')
|
|
48
|
-
.inspect(originalInput)
|
|
49
|
-
.split('\n'), fileLine = rawLines[0].split(':'), line = fileLine.pop(), file = fileLine.join(':');
|
|
50
|
-
if (file) {
|
|
51
|
-
input.unshift({
|
|
52
|
-
file: nixSlashes$1(file),
|
|
53
|
-
line: line,
|
|
54
|
-
column: (rawLines[2] || '').indexOf('^') + 1,
|
|
55
|
-
sourceLine: rawLines[1],
|
|
56
|
-
callee: '(syntax error)',
|
|
57
|
-
syntaxError: true,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
this.items = input;
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
this.items = [];
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
extractEntryMetadata(e) {
|
|
68
|
-
const decomposedPath = this.decomposePath(e.file || '');
|
|
69
|
-
const fileRelative = decomposedPath[0];
|
|
70
|
-
const externalDomain = decomposedPath[1];
|
|
71
|
-
return O.assign(e, {
|
|
72
|
-
calleeShort: e.calleeShort || lastOf((e.callee || '').split('.')),
|
|
73
|
-
fileRelative: fileRelative,
|
|
74
|
-
fileShort: this.shortenPath(fileRelative),
|
|
75
|
-
fileName: lastOf((e.file || '').split('/')),
|
|
76
|
-
thirdParty: this.isThirdParty(fileRelative, externalDomain) && !e.index,
|
|
77
|
-
externalDomain: externalDomain,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
shortenPath(relativePath) {
|
|
81
|
-
return relativePath
|
|
82
|
-
.replace(/^node_modules\//, '')
|
|
83
|
-
.replace(/^webpack\/bootstrap\//, '')
|
|
84
|
-
.replace(/^__parcel_source_root\//, '');
|
|
85
|
-
}
|
|
86
|
-
decomposePath(fullPath) {
|
|
87
|
-
let result = fullPath;
|
|
88
|
-
if (isBrowser)
|
|
89
|
-
result = result.replace(pathRoot, '');
|
|
90
|
-
const externalDomainMatch = result.match(/^(http|https)\:\/\/?([^\/]+)\/{1,}(.*)/);
|
|
91
|
-
const externalDomain = externalDomainMatch
|
|
92
|
-
? externalDomainMatch[2]
|
|
93
|
-
: undefined;
|
|
94
|
-
result = externalDomainMatch ? externalDomainMatch[3] : result;
|
|
95
|
-
// if (!isBrowser) result = nodeRequire!('path').relative(pathRoot, result)
|
|
96
|
-
return [
|
|
97
|
-
nixSlashes$1(result).replace(/^.*\:\/\/?\/?/, ''),
|
|
98
|
-
externalDomain,
|
|
99
|
-
];
|
|
100
|
-
}
|
|
101
|
-
isThirdParty(relativePath, externalDomain) {
|
|
102
|
-
if (this.isMP) {
|
|
103
|
-
if (typeof externalDomain === 'undefined')
|
|
104
|
-
return false;
|
|
105
|
-
return externalDomain !== 'usr';
|
|
106
|
-
}
|
|
107
|
-
return (
|
|
108
|
-
// 由于 hello-uniapp web 端报错携带 hellouniapp.dcloud.net.cn
|
|
109
|
-
// externalDomain ||
|
|
110
|
-
relativePath[0] === '~' || // webpack-specific heuristic
|
|
111
|
-
relativePath[0] === '/' || // external source
|
|
112
|
-
relativePath.indexOf('@dcloudio') !== -1 ||
|
|
113
|
-
relativePath.indexOf('weex-main-jsfm') !== -1 ||
|
|
114
|
-
relativePath.indexOf('webpack/bootstrap') === 0);
|
|
115
|
-
}
|
|
116
|
-
rawParse(str) {
|
|
117
|
-
const lines = (str || '').split('\n');
|
|
118
|
-
const entries = lines.map((line, index) => {
|
|
119
|
-
line = line.trim();
|
|
120
|
-
let callee, fileLineColumn = [], native, planA, planB;
|
|
121
|
-
if (line.indexOf('file:') !== -1) {
|
|
122
|
-
line = line.replace(/file:\/\/(.*)www/, 'file://');
|
|
123
|
-
}
|
|
124
|
-
if ((planA = line.match(/at (.+) \(eval at .+ \((.+)\), .+\)/)) || // eval calls
|
|
125
|
-
(planA = line.match(/at (.+) \((.+)\)/)) ||
|
|
126
|
-
(line.slice(0, 3) !== 'at ' && (planA = line.match(/(.*)@(.*)/)))) {
|
|
127
|
-
this.itemsHeader.push('%StacktraceyItem%');
|
|
128
|
-
callee = planA[1];
|
|
129
|
-
native = planA[2] === 'native';
|
|
130
|
-
fileLineColumn = (planA[2].match(/(.*):(\d+):(\d+)/) ||
|
|
131
|
-
planA[2].match(/(.*):(\d+)/) ||
|
|
132
|
-
planA[2].match(/\[(.*)\]/) ||
|
|
133
|
-
[]).slice(1);
|
|
134
|
-
}
|
|
135
|
-
else if ((planB = line.match(/^(at\s*)*(.*)\s+(.+):(\d+):(\d+)/))) {
|
|
136
|
-
this.itemsHeader.push('%StacktraceyItem%');
|
|
137
|
-
callee = planB[2].trim();
|
|
138
|
-
fileLineColumn = planB.slice(3);
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
this.itemsHeader.push(line);
|
|
142
|
-
return undefined;
|
|
143
|
-
}
|
|
144
|
-
/* Detect things like Array.reduce
|
|
145
|
-
TODO: detect more built-in types */
|
|
146
|
-
if (callee && !fileLineColumn[0]) {
|
|
147
|
-
const type = callee.split('.')[0];
|
|
148
|
-
if (type === 'Array') {
|
|
149
|
-
native = true;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return {
|
|
153
|
-
beforeParse: line,
|
|
154
|
-
callee: callee || '',
|
|
155
|
-
/* eslint-disable */
|
|
156
|
-
index: isBrowser && fileLineColumn[0] === window.location.href,
|
|
157
|
-
native: native || false,
|
|
158
|
-
file: nixSlashes$1(fileLineColumn[0] || ''),
|
|
159
|
-
line: parseInt(fileLineColumn[1] || '', 10) || undefined,
|
|
160
|
-
column: parseInt(fileLineColumn[2] || '', 10) || undefined,
|
|
161
|
-
};
|
|
162
|
-
});
|
|
163
|
-
return entries.filter((x) => x !== undefined);
|
|
164
|
-
}
|
|
165
|
-
maxColumnWidths() {
|
|
166
|
-
return {
|
|
167
|
-
callee: 30,
|
|
168
|
-
file: 60,
|
|
169
|
-
sourceLine: 80,
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
asTable(opts) {
|
|
173
|
-
const maxColumnWidths = (opts && opts.maxColumnWidths) || this.maxColumnWidths();
|
|
174
|
-
const trimmed = this
|
|
175
|
-
.filter((e) => !e.thirdParty)
|
|
176
|
-
.map((e) => parseItem(e, maxColumnWidths, this.isMP));
|
|
177
|
-
const trimmedThirdParty = this
|
|
178
|
-
.filter((e) => e.thirdParty)
|
|
179
|
-
.map((e) => parseItem(e, maxColumnWidths, this.isMP));
|
|
180
|
-
return {
|
|
181
|
-
items: trimmed.items,
|
|
182
|
-
thirdPartyItems: trimmedThirdParty.items,
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
const trimEnd = (s, n) => s && (s.length > n ? s.slice(0, n - 1) + '…' : s);
|
|
187
|
-
const trimStart = (s, n) => s && (s.length > n ? '…' + s.slice(-(n - 1)) : s);
|
|
188
|
-
function parseItem(e, maxColumnWidths, isMP) {
|
|
189
|
-
if (!e.parsed) {
|
|
190
|
-
return e.beforeParse;
|
|
191
|
-
}
|
|
192
|
-
const filePath = (isMP ? e.file && e.file : e.fileShort && e.fileShort) +
|
|
193
|
-
`${e.line ? ':' + e.line : ''}` +
|
|
194
|
-
`${e.column ? ':' + e.column : ''}`;
|
|
195
|
-
return [
|
|
196
|
-
'at ' + trimEnd(isMP ? e.callee : e.calleeShort, maxColumnWidths.callee),
|
|
197
|
-
trimStart(filePath || '', maxColumnWidths.file),
|
|
198
|
-
trimEnd((e.sourceLine || '').trim() || '', maxColumnWidths.sourceLine),
|
|
199
|
-
];
|
|
200
|
-
}
|
|
201
|
-
['map', 'filter', 'slice', 'concat'].forEach((method) => {
|
|
202
|
-
StackTracey.prototype[method] = function ( /*...args */) {
|
|
203
|
-
// no support for ...args in Node v4 :(
|
|
204
|
-
return new StackTracey(this.items[method].apply(this.items, arguments));
|
|
205
|
-
};
|
|
206
|
-
});
|
|
207
|
-
/* ------------------------------------------------------------------------ */
|
|
13
|
+
/* ------------------------------------------------------------------------ */
|
|
14
|
+
const O = Object, isBrowser =
|
|
15
|
+
/* eslint-disable */
|
|
16
|
+
typeof window !== 'undefined' &&
|
|
17
|
+
/* eslint-disable */
|
|
18
|
+
window.window === window &&
|
|
19
|
+
/* eslint-disable */
|
|
20
|
+
window.navigator, nodeRequire = isBrowser ? null : module.require, // to prevent bundlers from expanding the require call
|
|
21
|
+
lastOf = (x) => x[x.length - 1], nixSlashes$1 = (x) => x.replace(/\\/g, '/'), pathRoot = isBrowser ? window.location.href : nixSlashes$1(process.cwd()) + '/';
|
|
22
|
+
/* ------------------------------------------------------------------------ */
|
|
23
|
+
class StackTracey {
|
|
24
|
+
constructor(input, uniPlatform, offset) {
|
|
25
|
+
this.itemsHeader = [];
|
|
26
|
+
this.isMP = false;
|
|
27
|
+
const originalInput = input, isParseableSyntaxError = input && input instanceof SyntaxError && !isBrowser;
|
|
28
|
+
/* new StackTracey () */
|
|
29
|
+
if (!input) {
|
|
30
|
+
input = new Error();
|
|
31
|
+
offset = offset === undefined ? 1 : offset;
|
|
32
|
+
}
|
|
33
|
+
/* new StackTracey (Error) */
|
|
34
|
+
if (input instanceof Error) {
|
|
35
|
+
input = input.stack || '';
|
|
36
|
+
}
|
|
37
|
+
/* new StackTracey (string) */
|
|
38
|
+
if (typeof input === 'string') {
|
|
39
|
+
this.isMP = uniPlatform === 'mp-weixin';
|
|
40
|
+
input = this.rawParse(input)
|
|
41
|
+
.slice(offset)
|
|
42
|
+
.map((x) => this.extractEntryMetadata(x));
|
|
43
|
+
}
|
|
44
|
+
/* new StackTracey (array) */
|
|
45
|
+
if (Array.isArray(input)) {
|
|
46
|
+
if (isParseableSyntaxError) {
|
|
47
|
+
const rawLines = nodeRequire('util')
|
|
48
|
+
.inspect(originalInput)
|
|
49
|
+
.split('\n'), fileLine = rawLines[0].split(':'), line = fileLine.pop(), file = fileLine.join(':');
|
|
50
|
+
if (file) {
|
|
51
|
+
input.unshift({
|
|
52
|
+
file: nixSlashes$1(file),
|
|
53
|
+
line: line,
|
|
54
|
+
column: (rawLines[2] || '').indexOf('^') + 1,
|
|
55
|
+
sourceLine: rawLines[1],
|
|
56
|
+
callee: '(syntax error)',
|
|
57
|
+
syntaxError: true,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
this.items = input;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
this.items = [];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
extractEntryMetadata(e) {
|
|
68
|
+
const decomposedPath = this.decomposePath(e.file || '');
|
|
69
|
+
const fileRelative = decomposedPath[0];
|
|
70
|
+
const externalDomain = decomposedPath[1];
|
|
71
|
+
return O.assign(e, {
|
|
72
|
+
calleeShort: e.calleeShort || lastOf((e.callee || '').split('.')),
|
|
73
|
+
fileRelative: fileRelative,
|
|
74
|
+
fileShort: this.shortenPath(fileRelative),
|
|
75
|
+
fileName: lastOf((e.file || '').split('/')),
|
|
76
|
+
thirdParty: this.isThirdParty(fileRelative, externalDomain) && !e.index,
|
|
77
|
+
externalDomain: externalDomain,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
shortenPath(relativePath) {
|
|
81
|
+
return relativePath
|
|
82
|
+
.replace(/^node_modules\//, '')
|
|
83
|
+
.replace(/^webpack\/bootstrap\//, '')
|
|
84
|
+
.replace(/^__parcel_source_root\//, '');
|
|
85
|
+
}
|
|
86
|
+
decomposePath(fullPath) {
|
|
87
|
+
let result = fullPath;
|
|
88
|
+
if (isBrowser)
|
|
89
|
+
result = result.replace(pathRoot, '');
|
|
90
|
+
const externalDomainMatch = result.match(/^(http|https)\:\/\/?([^\/]+)\/{1,}(.*)/);
|
|
91
|
+
const externalDomain = externalDomainMatch
|
|
92
|
+
? externalDomainMatch[2]
|
|
93
|
+
: undefined;
|
|
94
|
+
result = externalDomainMatch ? externalDomainMatch[3] : result;
|
|
95
|
+
// if (!isBrowser) result = nodeRequire!('path').relative(pathRoot, result)
|
|
96
|
+
return [
|
|
97
|
+
nixSlashes$1(result).replace(/^.*\:\/\/?\/?/, ''),
|
|
98
|
+
externalDomain,
|
|
99
|
+
];
|
|
100
|
+
}
|
|
101
|
+
isThirdParty(relativePath, externalDomain) {
|
|
102
|
+
if (this.isMP) {
|
|
103
|
+
if (typeof externalDomain === 'undefined')
|
|
104
|
+
return false;
|
|
105
|
+
return externalDomain !== 'usr';
|
|
106
|
+
}
|
|
107
|
+
return (
|
|
108
|
+
// 由于 hello-uniapp web 端报错携带 hellouniapp.dcloud.net.cn
|
|
109
|
+
// externalDomain ||
|
|
110
|
+
relativePath[0] === '~' || // webpack-specific heuristic
|
|
111
|
+
relativePath[0] === '/' || // external source
|
|
112
|
+
relativePath.indexOf('@dcloudio') !== -1 ||
|
|
113
|
+
relativePath.indexOf('weex-main-jsfm') !== -1 ||
|
|
114
|
+
relativePath.indexOf('webpack/bootstrap') === 0);
|
|
115
|
+
}
|
|
116
|
+
rawParse(str) {
|
|
117
|
+
const lines = (str || '').split('\n');
|
|
118
|
+
const entries = lines.map((line, index) => {
|
|
119
|
+
line = line.trim();
|
|
120
|
+
let callee, fileLineColumn = [], native, planA, planB;
|
|
121
|
+
if (line.indexOf('file:') !== -1) {
|
|
122
|
+
line = line.replace(/file:\/\/(.*)www/, 'file://');
|
|
123
|
+
}
|
|
124
|
+
if ((planA = line.match(/at (.+) \(eval at .+ \((.+)\), .+\)/)) || // eval calls
|
|
125
|
+
(planA = line.match(/at (.+) \((.+)\)/)) ||
|
|
126
|
+
(line.slice(0, 3) !== 'at ' && (planA = line.match(/(.*)@(.*)/)))) {
|
|
127
|
+
this.itemsHeader.push('%StacktraceyItem%');
|
|
128
|
+
callee = planA[1];
|
|
129
|
+
native = planA[2] === 'native';
|
|
130
|
+
fileLineColumn = (planA[2].match(/(.*):(\d+):(\d+)/) ||
|
|
131
|
+
planA[2].match(/(.*):(\d+)/) ||
|
|
132
|
+
planA[2].match(/\[(.*)\]/) ||
|
|
133
|
+
[]).slice(1);
|
|
134
|
+
}
|
|
135
|
+
else if ((planB = line.match(/^(at\s*)*(.*)\s+(.+):(\d+):(\d+)/))) {
|
|
136
|
+
this.itemsHeader.push('%StacktraceyItem%');
|
|
137
|
+
callee = planB[2].trim();
|
|
138
|
+
fileLineColumn = planB.slice(3);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
this.itemsHeader.push(line);
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
144
|
+
/* Detect things like Array.reduce
|
|
145
|
+
TODO: detect more built-in types */
|
|
146
|
+
if (callee && !fileLineColumn[0]) {
|
|
147
|
+
const type = callee.split('.')[0];
|
|
148
|
+
if (type === 'Array') {
|
|
149
|
+
native = true;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
beforeParse: line,
|
|
154
|
+
callee: callee || '',
|
|
155
|
+
/* eslint-disable */
|
|
156
|
+
index: isBrowser && fileLineColumn[0] === window.location.href,
|
|
157
|
+
native: native || false,
|
|
158
|
+
file: nixSlashes$1(fileLineColumn[0] || ''),
|
|
159
|
+
line: parseInt(fileLineColumn[1] || '', 10) || undefined,
|
|
160
|
+
column: parseInt(fileLineColumn[2] || '', 10) || undefined,
|
|
161
|
+
};
|
|
162
|
+
});
|
|
163
|
+
return entries.filter((x) => x !== undefined);
|
|
164
|
+
}
|
|
165
|
+
maxColumnWidths() {
|
|
166
|
+
return {
|
|
167
|
+
callee: 30,
|
|
168
|
+
file: 60,
|
|
169
|
+
sourceLine: 80,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
asTable(opts) {
|
|
173
|
+
const maxColumnWidths = (opts && opts.maxColumnWidths) || this.maxColumnWidths();
|
|
174
|
+
const trimmed = this
|
|
175
|
+
.filter((e) => !e.thirdParty)
|
|
176
|
+
.map((e) => parseItem(e, maxColumnWidths, this.isMP));
|
|
177
|
+
const trimmedThirdParty = this
|
|
178
|
+
.filter((e) => e.thirdParty)
|
|
179
|
+
.map((e) => parseItem(e, maxColumnWidths, this.isMP));
|
|
180
|
+
return {
|
|
181
|
+
items: trimmed.items,
|
|
182
|
+
thirdPartyItems: trimmedThirdParty.items,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const trimEnd = (s, n) => s && (s.length > n ? s.slice(0, n - 1) + '…' : s);
|
|
187
|
+
const trimStart = (s, n) => s && (s.length > n ? '…' + s.slice(-(n - 1)) : s);
|
|
188
|
+
function parseItem(e, maxColumnWidths, isMP) {
|
|
189
|
+
if (!e.parsed) {
|
|
190
|
+
return e.beforeParse;
|
|
191
|
+
}
|
|
192
|
+
const filePath = (isMP ? e.file && e.file : e.fileShort && e.fileShort) +
|
|
193
|
+
`${e.line ? ':' + e.line : ''}` +
|
|
194
|
+
`${e.column ? ':' + e.column : ''}`;
|
|
195
|
+
return [
|
|
196
|
+
'at ' + trimEnd(isMP ? e.callee : e.calleeShort, maxColumnWidths.callee),
|
|
197
|
+
trimStart(filePath || '', maxColumnWidths.file),
|
|
198
|
+
trimEnd((e.sourceLine || '').trim() || '', maxColumnWidths.sourceLine),
|
|
199
|
+
];
|
|
200
|
+
}
|
|
201
|
+
['map', 'filter', 'slice', 'concat'].forEach((method) => {
|
|
202
|
+
StackTracey.prototype[method] = function ( /*...args */) {
|
|
203
|
+
// no support for ...args in Node v4 :(
|
|
204
|
+
return new StackTracey(this.items[method].apply(this.items, arguments));
|
|
205
|
+
};
|
|
206
|
+
});
|
|
207
|
+
/* ------------------------------------------------------------------------ */
|
|
208
208
|
var StackTracey$1 = StackTracey;
|
|
209
209
|
|
|
210
210
|
var util$1 = {};
|
|
@@ -2479,488 +2479,488 @@ function _factoryBSM(aSourceMap, aSourceMapURL) {
|
|
|
2479
2479
|
*/
|
|
2480
2480
|
var SourceMapConsumer = sourceMapConsumer.SourceMapConsumer;
|
|
2481
2481
|
|
|
2482
|
-
const splitRE = /\r?\n/;
|
|
2483
|
-
const range = 2;
|
|
2484
|
-
function posToNumber(source, pos) {
|
|
2485
|
-
if (typeof pos === 'number')
|
|
2486
|
-
return pos;
|
|
2487
|
-
const lines = source.split(splitRE);
|
|
2488
|
-
const { line, column } = pos;
|
|
2489
|
-
let start = 0;
|
|
2490
|
-
for (let i = 0; i < line - 1; i++) {
|
|
2491
|
-
start += lines[i].length + 1;
|
|
2492
|
-
}
|
|
2493
|
-
return start + column;
|
|
2494
|
-
}
|
|
2495
|
-
function generateCodeFrame(source, start = 0, end) {
|
|
2496
|
-
start = posToNumber(source, start);
|
|
2497
|
-
end = end || start;
|
|
2498
|
-
const lines = source.split(splitRE);
|
|
2499
|
-
let count = 0;
|
|
2500
|
-
const res = [];
|
|
2501
|
-
for (let i = 0; i < lines.length; i++) {
|
|
2502
|
-
count += lines[i].length + 1;
|
|
2503
|
-
if (count >= start) {
|
|
2504
|
-
for (let j = i - range; j <= i + range || end > count; j++) {
|
|
2505
|
-
if (j < 0 || j >= lines.length)
|
|
2506
|
-
continue;
|
|
2507
|
-
const line = j + 1;
|
|
2508
|
-
res.push(`${line}${' '.repeat(Math.max(3 - String(line).length, 0))}| ${lines[j]}`);
|
|
2509
|
-
const lineLength = lines[j].length;
|
|
2510
|
-
if (j === i) {
|
|
2511
|
-
// push underline
|
|
2512
|
-
const pad = start - (count - lineLength) + 1;
|
|
2513
|
-
const length = Math.max(1, end > count ? lineLength - pad : end - start);
|
|
2514
|
-
res.push(` | ` + ' '.repeat(pad) + '^'.repeat(length));
|
|
2515
|
-
}
|
|
2516
|
-
else if (j > i) {
|
|
2517
|
-
if (end > count) {
|
|
2518
|
-
const length = Math.max(Math.min(end - count, lineLength), 1);
|
|
2519
|
-
res.push(` | ` + '^'.repeat(length));
|
|
2520
|
-
}
|
|
2521
|
-
count += lineLength + 1;
|
|
2522
|
-
}
|
|
2523
|
-
}
|
|
2524
|
-
break;
|
|
2525
|
-
}
|
|
2526
|
-
}
|
|
2527
|
-
return res.join('\n');
|
|
2528
|
-
}
|
|
2529
|
-
let isWindows = false;
|
|
2530
|
-
try {
|
|
2531
|
-
isWindows = os__default.default.platform() === 'win32';
|
|
2532
|
-
}
|
|
2533
|
-
catch (error) { }
|
|
2534
|
-
function normalizePath(id) {
|
|
2535
|
-
return isWindows ? id.replace(/\\/g, '/') : id;
|
|
2536
|
-
}
|
|
2537
|
-
function generateCodeFrameSourceMapConsumer(consumer, m, options = {}) {
|
|
2538
|
-
if (m.file) {
|
|
2539
|
-
const res = consumer.originalPositionFor({
|
|
2540
|
-
line: m.line,
|
|
2541
|
-
column: m.column,
|
|
2542
|
-
});
|
|
2543
|
-
if (res.source != null && res.line != null && res.column != null) {
|
|
2544
|
-
let code = consumer.sourceContentFor(res.source, true);
|
|
2545
|
-
if (code) {
|
|
2546
|
-
code = generateCodeFrame(code, { line: res.line, column: res.column });
|
|
2547
|
-
if (options.replaceTabsWithSpace) {
|
|
2548
|
-
code = code.replace(/\t/g, ' ');
|
|
2549
|
-
}
|
|
2550
|
-
return {
|
|
2551
|
-
type: m.type,
|
|
2552
|
-
file: options.sourceRoot
|
|
2553
|
-
? normalizePath(path__default.default.relative(options.sourceRoot, res.source.replace('\\\\?\\', '')))
|
|
2554
|
-
: res.source,
|
|
2555
|
-
line: res.line,
|
|
2556
|
-
column: res.column,
|
|
2557
|
-
message: m.message,
|
|
2558
|
-
code,
|
|
2559
|
-
};
|
|
2560
|
-
}
|
|
2561
|
-
}
|
|
2562
|
-
}
|
|
2563
|
-
}
|
|
2564
|
-
function initConsumer(filename) {
|
|
2565
|
-
if (fs__default.default.existsSync(filename)) {
|
|
2566
|
-
return new SourceMapConsumer(fs__default.default.readFileSync(filename, 'utf8'));
|
|
2567
|
-
}
|
|
2568
|
-
return Promise.resolve(undefined);
|
|
2569
|
-
}
|
|
2570
|
-
function generateCodeFrameWithSourceMapPath(filename, messages, options = {}) {
|
|
2571
|
-
if (typeof messages === 'string') {
|
|
2572
|
-
try {
|
|
2573
|
-
messages = JSON.parse(messages);
|
|
2574
|
-
}
|
|
2575
|
-
catch (e) { }
|
|
2576
|
-
}
|
|
2577
|
-
if (Array.isArray(messages) && messages.length) {
|
|
2578
|
-
return new Promise((resolve) => {
|
|
2579
|
-
initConsumer(filename).then((consumer) => {
|
|
2580
|
-
resolve(messages
|
|
2581
|
-
.map((m) => {
|
|
2582
|
-
if (m.file && consumer) {
|
|
2583
|
-
const message = generateCodeFrameSourceMapConsumer(consumer, m, options);
|
|
2584
|
-
if (message) {
|
|
2585
|
-
return message;
|
|
2586
|
-
}
|
|
2587
|
-
}
|
|
2588
|
-
if (!m.file) {
|
|
2589
|
-
m.file = '';
|
|
2590
|
-
}
|
|
2591
|
-
return m;
|
|
2592
|
-
})
|
|
2593
|
-
.filter(Boolean));
|
|
2594
|
-
});
|
|
2595
|
-
});
|
|
2596
|
-
}
|
|
2597
|
-
return Promise.resolve([]);
|
|
2598
|
-
}
|
|
2599
|
-
function resolveSourceMapPath(sourceMapFilename, name, outputDir) {
|
|
2600
|
-
const is_uni_modules = path__default.default.basename(path__default.default.dirname(name)) === 'uni_modules';
|
|
2601
|
-
return path__default.default.resolve(outputDir, '../.sourcemap/app', name, is_uni_modules ? 'utssdk' : '', sourceMapFilename);
|
|
2602
|
-
}
|
|
2603
|
-
function generateCodeFrameWithKotlinStacktrace(stacktrace, { name, inputDir, outputDir }) {
|
|
2604
|
-
const sourceMapFilename = resolveSourceMapPath('app-android/index.kt.map', name, outputDir);
|
|
2605
|
-
return generateCodeFrameWithStacktrace(stacktrace, /e:\s+(.*):\s+\(([0-9]+),\s+([0-9]+)\):\s+(.*)/g, {
|
|
2606
|
-
sourceRoot: inputDir,
|
|
2607
|
-
sourceMapFilename,
|
|
2608
|
-
});
|
|
2609
|
-
}
|
|
2610
|
-
function generateCodeFrameWithSwiftStacktrace(stacktrace, { name, inputDir, outputDir }) {
|
|
2611
|
-
const sourceMapFilename = resolveSourceMapPath('app-ios/index.swift.map', name, outputDir);
|
|
2612
|
-
return generateCodeFrameWithStacktrace(stacktrace, /(.*):([0-9]+):([0-9]+):\s+error:\s+(.*)/g, {
|
|
2613
|
-
sourceRoot: inputDir,
|
|
2614
|
-
sourceMapFilename,
|
|
2615
|
-
});
|
|
2616
|
-
}
|
|
2617
|
-
function generateCodeFrameWithStacktrace(stacktrace, regexp, { sourceRoot, sourceMapFilename, replaceTabsWithSpace, }) {
|
|
2618
|
-
return new Promise((resolve) => {
|
|
2619
|
-
initConsumer(sourceMapFilename).then((consumer) => {
|
|
2620
|
-
if (!consumer) {
|
|
2621
|
-
return resolve(stacktrace);
|
|
2622
|
-
}
|
|
2623
|
-
resolve(stacktrace.replace(regexp, (substring, file, line, column, message) => {
|
|
2624
|
-
const m = generateCodeFrameSourceMapConsumer(consumer, {
|
|
2625
|
-
type: 'error',
|
|
2626
|
-
file,
|
|
2627
|
-
message,
|
|
2628
|
-
line: parseInt(line),
|
|
2629
|
-
column: parseInt(column),
|
|
2630
|
-
}, { sourceRoot, replaceTabsWithSpace });
|
|
2631
|
-
if (!m) {
|
|
2632
|
-
return substring;
|
|
2633
|
-
}
|
|
2482
|
+
const splitRE = /\r?\n/;
|
|
2483
|
+
const range = 2;
|
|
2484
|
+
function posToNumber(source, pos) {
|
|
2485
|
+
if (typeof pos === 'number')
|
|
2486
|
+
return pos;
|
|
2487
|
+
const lines = source.split(splitRE);
|
|
2488
|
+
const { line, column } = pos;
|
|
2489
|
+
let start = 0;
|
|
2490
|
+
for (let i = 0; i < line - 1; i++) {
|
|
2491
|
+
start += lines[i].length + 1;
|
|
2492
|
+
}
|
|
2493
|
+
return start + column;
|
|
2494
|
+
}
|
|
2495
|
+
function generateCodeFrame(source, start = 0, end) {
|
|
2496
|
+
start = posToNumber(source, start);
|
|
2497
|
+
end = end || start;
|
|
2498
|
+
const lines = source.split(splitRE);
|
|
2499
|
+
let count = 0;
|
|
2500
|
+
const res = [];
|
|
2501
|
+
for (let i = 0; i < lines.length; i++) {
|
|
2502
|
+
count += lines[i].length + 1;
|
|
2503
|
+
if (count >= start) {
|
|
2504
|
+
for (let j = i - range; j <= i + range || end > count; j++) {
|
|
2505
|
+
if (j < 0 || j >= lines.length)
|
|
2506
|
+
continue;
|
|
2507
|
+
const line = j + 1;
|
|
2508
|
+
res.push(`${line}${' '.repeat(Math.max(3 - String(line).length, 0))}| ${lines[j]}`);
|
|
2509
|
+
const lineLength = lines[j].length;
|
|
2510
|
+
if (j === i) {
|
|
2511
|
+
// push underline
|
|
2512
|
+
const pad = start - (count - lineLength) + 1;
|
|
2513
|
+
const length = Math.max(1, end > count ? lineLength - pad : end - start);
|
|
2514
|
+
res.push(` | ` + ' '.repeat(pad) + '^'.repeat(length));
|
|
2515
|
+
}
|
|
2516
|
+
else if (j > i) {
|
|
2517
|
+
if (end > count) {
|
|
2518
|
+
const length = Math.max(Math.min(end - count, lineLength), 1);
|
|
2519
|
+
res.push(` | ` + '^'.repeat(length));
|
|
2520
|
+
}
|
|
2521
|
+
count += lineLength + 1;
|
|
2522
|
+
}
|
|
2523
|
+
}
|
|
2524
|
+
break;
|
|
2525
|
+
}
|
|
2526
|
+
}
|
|
2527
|
+
return res.join('\n');
|
|
2528
|
+
}
|
|
2529
|
+
let isWindows = false;
|
|
2530
|
+
try {
|
|
2531
|
+
isWindows = os__default.default.platform() === 'win32';
|
|
2532
|
+
}
|
|
2533
|
+
catch (error) { }
|
|
2534
|
+
function normalizePath(id) {
|
|
2535
|
+
return isWindows ? id.replace(/\\/g, '/') : id;
|
|
2536
|
+
}
|
|
2537
|
+
function generateCodeFrameSourceMapConsumer(consumer, m, options = {}) {
|
|
2538
|
+
if (m.file) {
|
|
2539
|
+
const res = consumer.originalPositionFor({
|
|
2540
|
+
line: m.line,
|
|
2541
|
+
column: m.column,
|
|
2542
|
+
});
|
|
2543
|
+
if (res.source != null && res.line != null && res.column != null) {
|
|
2544
|
+
let code = consumer.sourceContentFor(res.source, true);
|
|
2545
|
+
if (code) {
|
|
2546
|
+
code = generateCodeFrame(code, { line: res.line, column: res.column });
|
|
2547
|
+
if (options.replaceTabsWithSpace) {
|
|
2548
|
+
code = code.replace(/\t/g, ' ');
|
|
2549
|
+
}
|
|
2550
|
+
return {
|
|
2551
|
+
type: m.type,
|
|
2552
|
+
file: options.sourceRoot
|
|
2553
|
+
? normalizePath(path__default.default.relative(options.sourceRoot, res.source.replace('\\\\?\\', '')))
|
|
2554
|
+
: res.source,
|
|
2555
|
+
line: res.line,
|
|
2556
|
+
column: res.column,
|
|
2557
|
+
message: m.message,
|
|
2558
|
+
code,
|
|
2559
|
+
};
|
|
2560
|
+
}
|
|
2561
|
+
}
|
|
2562
|
+
}
|
|
2563
|
+
}
|
|
2564
|
+
function initConsumer(filename) {
|
|
2565
|
+
if (fs__default.default.existsSync(filename)) {
|
|
2566
|
+
return new SourceMapConsumer(fs__default.default.readFileSync(filename, 'utf8'));
|
|
2567
|
+
}
|
|
2568
|
+
return Promise.resolve(undefined);
|
|
2569
|
+
}
|
|
2570
|
+
function generateCodeFrameWithSourceMapPath(filename, messages, options = {}) {
|
|
2571
|
+
if (typeof messages === 'string') {
|
|
2572
|
+
try {
|
|
2573
|
+
messages = JSON.parse(messages);
|
|
2574
|
+
}
|
|
2575
|
+
catch (e) { }
|
|
2576
|
+
}
|
|
2577
|
+
if (Array.isArray(messages) && messages.length) {
|
|
2578
|
+
return new Promise((resolve) => {
|
|
2579
|
+
initConsumer(filename).then((consumer) => {
|
|
2580
|
+
resolve(messages
|
|
2581
|
+
.map((m) => {
|
|
2582
|
+
if (m.file && consumer) {
|
|
2583
|
+
const message = generateCodeFrameSourceMapConsumer(consumer, m, options);
|
|
2584
|
+
if (message) {
|
|
2585
|
+
return message;
|
|
2586
|
+
}
|
|
2587
|
+
}
|
|
2588
|
+
if (!m.file) {
|
|
2589
|
+
m.file = '';
|
|
2590
|
+
}
|
|
2591
|
+
return m;
|
|
2592
|
+
})
|
|
2593
|
+
.filter(Boolean));
|
|
2594
|
+
});
|
|
2595
|
+
});
|
|
2596
|
+
}
|
|
2597
|
+
return Promise.resolve([]);
|
|
2598
|
+
}
|
|
2599
|
+
function resolveSourceMapPath(sourceMapFilename, name, outputDir) {
|
|
2600
|
+
const is_uni_modules = path__default.default.basename(path__default.default.dirname(name)) === 'uni_modules';
|
|
2601
|
+
return path__default.default.resolve(outputDir, '../.sourcemap/app', name, is_uni_modules ? 'utssdk' : '', sourceMapFilename);
|
|
2602
|
+
}
|
|
2603
|
+
function generateCodeFrameWithKotlinStacktrace(stacktrace, { name, inputDir, outputDir }) {
|
|
2604
|
+
const sourceMapFilename = resolveSourceMapPath('app-android/index.kt.map', name, outputDir);
|
|
2605
|
+
return generateCodeFrameWithStacktrace(stacktrace, /e:\s+(.*):\s+\(([0-9]+),\s+([0-9]+)\):\s+(.*)/g, {
|
|
2606
|
+
sourceRoot: inputDir,
|
|
2607
|
+
sourceMapFilename,
|
|
2608
|
+
});
|
|
2609
|
+
}
|
|
2610
|
+
function generateCodeFrameWithSwiftStacktrace(stacktrace, { name, inputDir, outputDir }) {
|
|
2611
|
+
const sourceMapFilename = resolveSourceMapPath('app-ios/index.swift.map', name, outputDir);
|
|
2612
|
+
return generateCodeFrameWithStacktrace(stacktrace, /(.*):([0-9]+):([0-9]+):\s+error:\s+(.*)/g, {
|
|
2613
|
+
sourceRoot: inputDir,
|
|
2614
|
+
sourceMapFilename,
|
|
2615
|
+
});
|
|
2616
|
+
}
|
|
2617
|
+
function generateCodeFrameWithStacktrace(stacktrace, regexp, { sourceRoot, sourceMapFilename, replaceTabsWithSpace, }) {
|
|
2618
|
+
return new Promise((resolve) => {
|
|
2619
|
+
initConsumer(sourceMapFilename).then((consumer) => {
|
|
2620
|
+
if (!consumer) {
|
|
2621
|
+
return resolve(stacktrace);
|
|
2622
|
+
}
|
|
2623
|
+
resolve(stacktrace.replace(regexp, (substring, file, line, column, message) => {
|
|
2624
|
+
const m = generateCodeFrameSourceMapConsumer(consumer, {
|
|
2625
|
+
type: 'error',
|
|
2626
|
+
file,
|
|
2627
|
+
message,
|
|
2628
|
+
line: parseInt(line),
|
|
2629
|
+
column: parseInt(column),
|
|
2630
|
+
}, { sourceRoot, replaceTabsWithSpace });
|
|
2631
|
+
if (!m) {
|
|
2632
|
+
return substring;
|
|
2633
|
+
}
|
|
2634
2634
|
return `error: ${message}
|
|
2635
2635
|
at ${m.file}:${m.line}:${m.column}
|
|
2636
2636
|
${m.code}
|
|
2637
|
-
`;
|
|
2638
|
-
}));
|
|
2639
|
-
});
|
|
2640
|
-
});
|
|
2637
|
+
`;
|
|
2638
|
+
}));
|
|
2639
|
+
});
|
|
2640
|
+
});
|
|
2641
2641
|
}
|
|
2642
2642
|
|
|
2643
|
-
const nixSlashes = (x) => x.replace(/\\/g, '/');
|
|
2644
|
-
const sourcemapCatch = {};
|
|
2645
|
-
function stacktracey(stacktrace, opts) {
|
|
2646
|
-
const stack = opts.preset.parseStacktrace(stacktrace);
|
|
2647
|
-
let parseStack = Promise.resolve();
|
|
2648
|
-
stack.items.forEach((item, index) => {
|
|
2649
|
-
const fn = (item, index) => {
|
|
2650
|
-
const { line = 0, column = 0, file, fileName, fileRelative } = item;
|
|
2651
|
-
if (item.thirdParty) {
|
|
2652
|
-
return Promise.resolve();
|
|
2653
|
-
}
|
|
2654
|
-
function _getSourceMapContent(file, fileName, fileRelative) {
|
|
2655
|
-
return opts.preset
|
|
2656
|
-
.getSourceMapContent(file, fileName, fileRelative)
|
|
2657
|
-
.then((content) => {
|
|
2658
|
-
if (content) {
|
|
2659
|
-
return getConsumer(content).then((consumer) => {
|
|
2660
|
-
return parseSourceMapContent(consumer, {
|
|
2661
|
-
line: line + (opts.preset.lineOffset || 0),
|
|
2662
|
-
column,
|
|
2663
|
-
}, !!opts.withSourceContent);
|
|
2664
|
-
});
|
|
2665
|
-
}
|
|
2666
|
-
});
|
|
2667
|
-
}
|
|
2668
|
-
try {
|
|
2669
|
-
return _getSourceMapContent(file, fileName, fileRelative).then((sourceMapContent) => {
|
|
2670
|
-
if (sourceMapContent) {
|
|
2671
|
-
const { source, sourcePath, sourceLine, sourceColumn, sourceContent, fileName = '', } = sourceMapContent;
|
|
2672
|
-
stack.items[index] = Object.assign({}, item, {
|
|
2673
|
-
file: source,
|
|
2674
|
-
line: sourceLine,
|
|
2675
|
-
column: sourceColumn,
|
|
2676
|
-
fileShort: sourcePath,
|
|
2677
|
-
fileRelative: source,
|
|
2678
|
-
fileName,
|
|
2679
|
-
thirdParty: isThirdParty(sourcePath),
|
|
2680
|
-
parsed: true,
|
|
2681
|
-
sourceContent,
|
|
2682
|
-
});
|
|
2683
|
-
/**
|
|
2684
|
-
* 以 .js 结尾
|
|
2685
|
-
* 包含 app-service.js 则需要再解析 两次
|
|
2686
|
-
* 不包含 app-service.js 则无需再解析 一次
|
|
2687
|
-
*/
|
|
2688
|
-
const curItem = stack.items[index];
|
|
2689
|
-
if (stack.isMP &&
|
|
2690
|
-
curItem.beforeParse.indexOf('app-service') !== -1) {
|
|
2691
|
-
return fn(curItem, index);
|
|
2692
|
-
}
|
|
2693
|
-
}
|
|
2694
|
-
});
|
|
2695
|
-
}
|
|
2696
|
-
catch (error) {
|
|
2697
|
-
return Promise.resolve();
|
|
2698
|
-
}
|
|
2699
|
-
};
|
|
2700
|
-
parseStack = parseStack.then(() => {
|
|
2701
|
-
return new Promise((resolve, reject) => {
|
|
2702
|
-
setTimeout(() => {
|
|
2703
|
-
fn(item, index).then(resolve);
|
|
2704
|
-
}, 0);
|
|
2705
|
-
});
|
|
2706
|
-
});
|
|
2707
|
-
});
|
|
2708
|
-
const _promise = new Promise((resolve, reject) => {
|
|
2709
|
-
parseStack
|
|
2710
|
-
.then(() => {
|
|
2711
|
-
const parseError = opts.preset.asTableStacktrace({
|
|
2712
|
-
stack,
|
|
2713
|
-
maxColumnWidths: {
|
|
2714
|
-
callee: 999,
|
|
2715
|
-
file: 999,
|
|
2716
|
-
sourceLine: 999,
|
|
2717
|
-
},
|
|
2718
|
-
stacktrace,
|
|
2719
|
-
});
|
|
2720
|
-
resolve(parseError);
|
|
2721
|
-
})
|
|
2722
|
-
.catch(() => {
|
|
2723
|
-
resolve(stacktrace);
|
|
2724
|
-
});
|
|
2725
|
-
});
|
|
2726
|
-
return _promise;
|
|
2727
|
-
}
|
|
2728
|
-
function isThirdParty(relativePath) {
|
|
2729
|
-
return relativePath.indexOf('@dcloudio') !== -1;
|
|
2730
|
-
}
|
|
2731
|
-
function getConsumer(content) {
|
|
2732
|
-
return new Promise((resolve, reject) => {
|
|
2733
|
-
try {
|
|
2734
|
-
if (SourceMapConsumer.with) {
|
|
2735
|
-
SourceMapConsumer.with(content, null, (consumer) => {
|
|
2736
|
-
resolve(consumer);
|
|
2737
|
-
});
|
|
2738
|
-
}
|
|
2739
|
-
else {
|
|
2740
|
-
// @ts-ignore
|
|
2741
|
-
const consumer = SourceMapConsumer(content);
|
|
2742
|
-
resolve(consumer);
|
|
2743
|
-
}
|
|
2744
|
-
}
|
|
2745
|
-
catch (error) {
|
|
2746
|
-
reject();
|
|
2747
|
-
}
|
|
2748
|
-
});
|
|
2749
|
-
}
|
|
2750
|
-
function getSourceMapContent(sourcemapUrl) {
|
|
2751
|
-
try {
|
|
2752
|
-
return (sourcemapCatch[sourcemapUrl] ||
|
|
2753
|
-
(sourcemapCatch[sourcemapUrl] = new Promise((resolve, reject) => {
|
|
2754
|
-
try {
|
|
2755
|
-
if (/^[http|https]+:/i.test(sourcemapUrl)) {
|
|
2756
|
-
uni.request({
|
|
2757
|
-
url: sourcemapUrl,
|
|
2758
|
-
success: (res) => {
|
|
2759
|
-
if (res.statusCode === 200) {
|
|
2760
|
-
sourcemapCatch[sourcemapUrl] = res.data;
|
|
2761
|
-
resolve(sourcemapCatch[sourcemapUrl]);
|
|
2762
|
-
}
|
|
2763
|
-
else {
|
|
2764
|
-
resolve((sourcemapCatch[sourcemapUrl] = ''));
|
|
2765
|
-
}
|
|
2766
|
-
},
|
|
2767
|
-
fail() {
|
|
2768
|
-
resolve((sourcemapCatch[sourcemapUrl] = ''));
|
|
2769
|
-
},
|
|
2770
|
-
});
|
|
2771
|
-
}
|
|
2772
|
-
else {
|
|
2773
|
-
sourcemapCatch[sourcemapUrl] = fs__default.default.readFileSync(sourcemapUrl, 'utf-8');
|
|
2774
|
-
resolve(sourcemapCatch[sourcemapUrl]);
|
|
2775
|
-
}
|
|
2776
|
-
}
|
|
2777
|
-
catch (error) {
|
|
2778
|
-
resolve('');
|
|
2779
|
-
}
|
|
2780
|
-
})));
|
|
2781
|
-
}
|
|
2782
|
-
catch (error) {
|
|
2783
|
-
return '';
|
|
2784
|
-
}
|
|
2785
|
-
}
|
|
2786
|
-
function parseSourceMapContent(consumer, obj, withSourceContent) {
|
|
2787
|
-
// source -> 'uni-app:///node_modules/@sentry/browser/esm/helpers.js'
|
|
2788
|
-
const { source, line: sourceLine, column: sourceColumn, } = consumer.originalPositionFor(obj);
|
|
2789
|
-
if (source) {
|
|
2790
|
-
const sourcePathSplit = source.split('/');
|
|
2791
|
-
const sourcePath = sourcePathSplit.slice(3).join('/');
|
|
2792
|
-
const fileName = sourcePathSplit.pop();
|
|
2793
|
-
return {
|
|
2794
|
-
source,
|
|
2795
|
-
sourcePath,
|
|
2796
|
-
sourceLine: sourceLine === null ? 0 : sourceLine,
|
|
2797
|
-
sourceColumn: sourceColumn === null ? 0 : sourceColumn,
|
|
2798
|
-
fileName,
|
|
2799
|
-
sourceContent: withSourceContent
|
|
2800
|
-
? consumer.sourceContentFor(source) || ''
|
|
2801
|
-
: '',
|
|
2802
|
-
};
|
|
2803
|
-
}
|
|
2804
|
-
}
|
|
2805
|
-
function joinItem(item) {
|
|
2806
|
-
if (typeof item === 'string') {
|
|
2807
|
-
return item;
|
|
2808
|
-
}
|
|
2809
|
-
const a = item[0];
|
|
2810
|
-
const b = item[1] ? ` ${item[1]}` : '';
|
|
2811
|
-
const c = item[2] ? ` ${item[2]}` : '';
|
|
2812
|
-
return `${a}${b}${c}`;
|
|
2813
|
-
}
|
|
2814
|
-
function uniStracktraceyPreset(opts) {
|
|
2815
|
-
const { base, sourceRoot, splitThirdParty, uniPlatform, lineOffset } = opts;
|
|
2816
|
-
let stack;
|
|
2817
|
-
return {
|
|
2818
|
-
/**
|
|
2819
|
-
*
|
|
2820
|
-
* 微信特殊处理
|
|
2821
|
-
* 微信解析步骤:
|
|
2822
|
-
* 1. //usr/app-service.js -> 'weixin/__APP__/app-service.map.map'
|
|
2823
|
-
* 2. //usr/pages/API/app-service.js -> 'weixin/pages/API/app-service.map.map'
|
|
2824
|
-
* 3. uni-list-item/uni-list-item.js -> ${base}/uni-list-item/uni-list-item.js.map
|
|
2825
|
-
*/
|
|
2826
|
-
parseSourceMapUrl(file, fileName, fileRelative) {
|
|
2827
|
-
// 组合 sourceMapUrl
|
|
2828
|
-
if (fileRelative.indexOf('(') !== -1)
|
|
2829
|
-
fileRelative = fileRelative.match(/\((.*)/)[1];
|
|
2830
|
-
if (!base || !fileRelative)
|
|
2831
|
-
return '';
|
|
2832
|
-
if (sourceRoot) {
|
|
2833
|
-
return `${fileRelative.replace(sourceRoot, base + '/')}.map`;
|
|
2834
|
-
}
|
|
2835
|
-
let baseAfter = '';
|
|
2836
|
-
if (stack.isMP) {
|
|
2837
|
-
if (fileRelative.indexOf('app-service.js') !== -1) {
|
|
2838
|
-
baseAfter = (base.match(/\w$/) ? '/' : '') + '__WEIXIN__';
|
|
2839
|
-
if (fileRelative === fileName) {
|
|
2840
|
-
baseAfter += '/__APP__';
|
|
2841
|
-
}
|
|
2842
|
-
fileRelative = fileRelative.replace('.js', '.map');
|
|
2843
|
-
}
|
|
2844
|
-
if (baseAfter && !!fileRelative.match(/^\w/))
|
|
2845
|
-
baseAfter += '/';
|
|
2846
|
-
}
|
|
2847
|
-
return `${base}${baseAfter}${fileRelative}.map`;
|
|
2848
|
-
},
|
|
2849
|
-
getSourceMapContent(file, fileName, fileRelative) {
|
|
2850
|
-
if (stack.isMP && fileRelative.indexOf('.js') === -1) {
|
|
2851
|
-
return Promise.resolve('');
|
|
2852
|
-
}
|
|
2853
|
-
const sourcemapUrl = this.parseSourceMapUrl(file, fileName, fileRelative);
|
|
2854
|
-
return Promise.resolve(getSourceMapContent(sourcemapUrl));
|
|
2855
|
-
},
|
|
2856
|
-
parseStacktrace(stacktrace) {
|
|
2857
|
-
stack = new StackTracey$1(stacktrace, uniPlatform);
|
|
2858
|
-
return stack;
|
|
2859
|
-
},
|
|
2860
|
-
asTableStacktrace({ maxColumnWidths, stacktrace, stack }) {
|
|
2861
|
-
const errorName = stacktrace.split('\n')[0];
|
|
2862
|
-
const lines = stack.asTable
|
|
2863
|
-
? stack.asTable(maxColumnWidths ? { maxColumnWidths } : undefined)
|
|
2864
|
-
: { items: [], thirdPartyItems: [] };
|
|
2865
|
-
if (lines.items.length || lines.thirdPartyItems.length) {
|
|
2866
|
-
const { items: stackLines, thirdPartyItems: stackThirdPartyLines } = lines;
|
|
2867
|
-
const userError = stack.itemsHeader
|
|
2868
|
-
.map((item) => {
|
|
2869
|
-
if (item === '%StacktraceyItem%') {
|
|
2870
|
-
const _stack = stackLines.shift();
|
|
2871
|
-
return _stack ? joinItem(_stack) : '';
|
|
2872
|
-
}
|
|
2873
|
-
return item;
|
|
2874
|
-
})
|
|
2875
|
-
.filter(Boolean)
|
|
2876
|
-
.join('\n');
|
|
2877
|
-
const thirdParty = stackThirdPartyLines.length
|
|
2878
|
-
? stackThirdPartyLines.map(joinItem).join('\n')
|
|
2879
|
-
: '';
|
|
2880
|
-
if (splitThirdParty) {
|
|
2881
|
-
return {
|
|
2882
|
-
userError,
|
|
2883
|
-
thirdParty,
|
|
2884
|
-
};
|
|
2885
|
-
}
|
|
2886
|
-
return userError + '\n' + thirdParty;
|
|
2887
|
-
}
|
|
2888
|
-
else {
|
|
2889
|
-
if (splitThirdParty) {
|
|
2890
|
-
return {
|
|
2891
|
-
userError: errorName,
|
|
2892
|
-
thirdParty: '',
|
|
2893
|
-
};
|
|
2894
|
-
}
|
|
2895
|
-
return errorName;
|
|
2896
|
-
}
|
|
2897
|
-
},
|
|
2898
|
-
lineOffset,
|
|
2899
|
-
};
|
|
2900
|
-
}
|
|
2901
|
-
function utsStracktraceyPreset(opts) {
|
|
2902
|
-
const { inputRoot, outputRoot, sourceMapRoot } = opts;
|
|
2903
|
-
let errStack = [];
|
|
2904
|
-
return {
|
|
2905
|
-
parseSourceMapUrl(file, fileName, fileRelative) {
|
|
2906
|
-
return path__default.default.resolve(sourceMapRoot, path__default.default.relative(outputRoot, file) + '.map');
|
|
2907
|
-
},
|
|
2908
|
-
getSourceMapContent(file, fileName, fileRelative) {
|
|
2909
|
-
// 根据 base,filename 组合 sourceMapUrl
|
|
2910
|
-
return Promise.resolve(getSourceMapContent(this.parseSourceMapUrl(file, fileName, fileRelative)));
|
|
2911
|
-
},
|
|
2912
|
-
parseStacktrace(str) {
|
|
2913
|
-
const lines = (str || '').split('\n');
|
|
2914
|
-
const entries = lines
|
|
2915
|
-
.map((line, index) => {
|
|
2916
|
-
line = line.trim();
|
|
2917
|
-
const matches = line.match(/\s*(.+\.kt):([0-9]+):([0-9]+):\s+(.*)/);
|
|
2918
|
-
if (matches) {
|
|
2919
|
-
errStack.push('%StacktraceyItem%');
|
|
2920
|
-
}
|
|
2921
|
-
else {
|
|
2922
|
-
errStack.push(line);
|
|
2923
|
-
return;
|
|
2924
|
-
}
|
|
2925
|
-
const fileName = matches[1].replace(/^.*(\\|\/|\:)/, '');
|
|
2926
|
-
return {
|
|
2927
|
-
beforeParse: line,
|
|
2928
|
-
callee: '',
|
|
2929
|
-
index: false,
|
|
2930
|
-
native: false,
|
|
2931
|
-
file: nixSlashes(matches[1]),
|
|
2932
|
-
line: parseInt(matches[2]),
|
|
2933
|
-
column: parseInt(matches[3]),
|
|
2934
|
-
fileName,
|
|
2935
|
-
fileShort: line,
|
|
2936
|
-
errMsg: matches[4] || '',
|
|
2937
|
-
calleeShort: '',
|
|
2938
|
-
fileRelative: '',
|
|
2939
|
-
thirdParty: false,
|
|
2940
|
-
};
|
|
2941
|
-
})
|
|
2942
|
-
.filter((x) => x !== undefined);
|
|
2943
|
-
return {
|
|
2944
|
-
items: entries,
|
|
2945
|
-
itemsHeader: [],
|
|
2946
|
-
};
|
|
2947
|
-
},
|
|
2948
|
-
asTableStacktrace({ maxColumnWidths, stacktrace, stack }) {
|
|
2949
|
-
return errStack
|
|
2950
|
-
.map((item) => {
|
|
2951
|
-
if (item === '%StacktraceyItem%') {
|
|
2952
|
-
const _stack = stack.items.shift();
|
|
2953
|
-
if (_stack) {
|
|
2643
|
+
const nixSlashes = (x) => x.replace(/\\/g, '/');
|
|
2644
|
+
const sourcemapCatch = {};
|
|
2645
|
+
function stacktracey(stacktrace, opts) {
|
|
2646
|
+
const stack = opts.preset.parseStacktrace(stacktrace);
|
|
2647
|
+
let parseStack = Promise.resolve();
|
|
2648
|
+
stack.items.forEach((item, index) => {
|
|
2649
|
+
const fn = (item, index) => {
|
|
2650
|
+
const { line = 0, column = 0, file, fileName, fileRelative } = item;
|
|
2651
|
+
if (item.thirdParty) {
|
|
2652
|
+
return Promise.resolve();
|
|
2653
|
+
}
|
|
2654
|
+
function _getSourceMapContent(file, fileName, fileRelative) {
|
|
2655
|
+
return opts.preset
|
|
2656
|
+
.getSourceMapContent(file, fileName, fileRelative)
|
|
2657
|
+
.then((content) => {
|
|
2658
|
+
if (content) {
|
|
2659
|
+
return getConsumer(content).then((consumer) => {
|
|
2660
|
+
return parseSourceMapContent(consumer, {
|
|
2661
|
+
line: line + (opts.preset.lineOffset || 0),
|
|
2662
|
+
column,
|
|
2663
|
+
}, !!opts.withSourceContent);
|
|
2664
|
+
});
|
|
2665
|
+
}
|
|
2666
|
+
});
|
|
2667
|
+
}
|
|
2668
|
+
try {
|
|
2669
|
+
return _getSourceMapContent(file, fileName, fileRelative).then((sourceMapContent) => {
|
|
2670
|
+
if (sourceMapContent) {
|
|
2671
|
+
const { source, sourcePath, sourceLine, sourceColumn, sourceContent, fileName = '', } = sourceMapContent;
|
|
2672
|
+
stack.items[index] = Object.assign({}, item, {
|
|
2673
|
+
file: source,
|
|
2674
|
+
line: sourceLine,
|
|
2675
|
+
column: sourceColumn,
|
|
2676
|
+
fileShort: sourcePath,
|
|
2677
|
+
fileRelative: source,
|
|
2678
|
+
fileName,
|
|
2679
|
+
thirdParty: isThirdParty(sourcePath),
|
|
2680
|
+
parsed: true,
|
|
2681
|
+
sourceContent,
|
|
2682
|
+
});
|
|
2683
|
+
/**
|
|
2684
|
+
* 以 .js 结尾
|
|
2685
|
+
* 包含 app-service.js 则需要再解析 两次
|
|
2686
|
+
* 不包含 app-service.js 则无需再解析 一次
|
|
2687
|
+
*/
|
|
2688
|
+
const curItem = stack.items[index];
|
|
2689
|
+
if (stack.isMP &&
|
|
2690
|
+
curItem.beforeParse.indexOf('app-service') !== -1) {
|
|
2691
|
+
return fn(curItem, index);
|
|
2692
|
+
}
|
|
2693
|
+
}
|
|
2694
|
+
});
|
|
2695
|
+
}
|
|
2696
|
+
catch (error) {
|
|
2697
|
+
return Promise.resolve();
|
|
2698
|
+
}
|
|
2699
|
+
};
|
|
2700
|
+
parseStack = parseStack.then(() => {
|
|
2701
|
+
return new Promise((resolve, reject) => {
|
|
2702
|
+
setTimeout(() => {
|
|
2703
|
+
fn(item, index).then(resolve);
|
|
2704
|
+
}, 0);
|
|
2705
|
+
});
|
|
2706
|
+
});
|
|
2707
|
+
});
|
|
2708
|
+
const _promise = new Promise((resolve, reject) => {
|
|
2709
|
+
parseStack
|
|
2710
|
+
.then(() => {
|
|
2711
|
+
const parseError = opts.preset.asTableStacktrace({
|
|
2712
|
+
stack,
|
|
2713
|
+
maxColumnWidths: {
|
|
2714
|
+
callee: 999,
|
|
2715
|
+
file: 999,
|
|
2716
|
+
sourceLine: 999,
|
|
2717
|
+
},
|
|
2718
|
+
stacktrace,
|
|
2719
|
+
});
|
|
2720
|
+
resolve(parseError);
|
|
2721
|
+
})
|
|
2722
|
+
.catch(() => {
|
|
2723
|
+
resolve(stacktrace);
|
|
2724
|
+
});
|
|
2725
|
+
});
|
|
2726
|
+
return _promise;
|
|
2727
|
+
}
|
|
2728
|
+
function isThirdParty(relativePath) {
|
|
2729
|
+
return relativePath.indexOf('@dcloudio') !== -1;
|
|
2730
|
+
}
|
|
2731
|
+
function getConsumer(content) {
|
|
2732
|
+
return new Promise((resolve, reject) => {
|
|
2733
|
+
try {
|
|
2734
|
+
if (SourceMapConsumer.with) {
|
|
2735
|
+
SourceMapConsumer.with(content, null, (consumer) => {
|
|
2736
|
+
resolve(consumer);
|
|
2737
|
+
});
|
|
2738
|
+
}
|
|
2739
|
+
else {
|
|
2740
|
+
// @ts-ignore
|
|
2741
|
+
const consumer = SourceMapConsumer(content);
|
|
2742
|
+
resolve(consumer);
|
|
2743
|
+
}
|
|
2744
|
+
}
|
|
2745
|
+
catch (error) {
|
|
2746
|
+
reject();
|
|
2747
|
+
}
|
|
2748
|
+
});
|
|
2749
|
+
}
|
|
2750
|
+
function getSourceMapContent(sourcemapUrl) {
|
|
2751
|
+
try {
|
|
2752
|
+
return (sourcemapCatch[sourcemapUrl] ||
|
|
2753
|
+
(sourcemapCatch[sourcemapUrl] = new Promise((resolve, reject) => {
|
|
2754
|
+
try {
|
|
2755
|
+
if (/^[http|https]+:/i.test(sourcemapUrl)) {
|
|
2756
|
+
uni.request({
|
|
2757
|
+
url: sourcemapUrl,
|
|
2758
|
+
success: (res) => {
|
|
2759
|
+
if (res.statusCode === 200) {
|
|
2760
|
+
sourcemapCatch[sourcemapUrl] = res.data;
|
|
2761
|
+
resolve(sourcemapCatch[sourcemapUrl]);
|
|
2762
|
+
}
|
|
2763
|
+
else {
|
|
2764
|
+
resolve((sourcemapCatch[sourcemapUrl] = ''));
|
|
2765
|
+
}
|
|
2766
|
+
},
|
|
2767
|
+
fail() {
|
|
2768
|
+
resolve((sourcemapCatch[sourcemapUrl] = ''));
|
|
2769
|
+
},
|
|
2770
|
+
});
|
|
2771
|
+
}
|
|
2772
|
+
else {
|
|
2773
|
+
sourcemapCatch[sourcemapUrl] = fs__default.default.readFileSync(sourcemapUrl, 'utf-8');
|
|
2774
|
+
resolve(sourcemapCatch[sourcemapUrl]);
|
|
2775
|
+
}
|
|
2776
|
+
}
|
|
2777
|
+
catch (error) {
|
|
2778
|
+
resolve('');
|
|
2779
|
+
}
|
|
2780
|
+
})));
|
|
2781
|
+
}
|
|
2782
|
+
catch (error) {
|
|
2783
|
+
return '';
|
|
2784
|
+
}
|
|
2785
|
+
}
|
|
2786
|
+
function parseSourceMapContent(consumer, obj, withSourceContent) {
|
|
2787
|
+
// source -> 'uni-app:///node_modules/@sentry/browser/esm/helpers.js'
|
|
2788
|
+
const { source, line: sourceLine, column: sourceColumn, } = consumer.originalPositionFor(obj);
|
|
2789
|
+
if (source) {
|
|
2790
|
+
const sourcePathSplit = source.split('/');
|
|
2791
|
+
const sourcePath = sourcePathSplit.slice(3).join('/');
|
|
2792
|
+
const fileName = sourcePathSplit.pop();
|
|
2793
|
+
return {
|
|
2794
|
+
source,
|
|
2795
|
+
sourcePath,
|
|
2796
|
+
sourceLine: sourceLine === null ? 0 : sourceLine,
|
|
2797
|
+
sourceColumn: sourceColumn === null ? 0 : sourceColumn,
|
|
2798
|
+
fileName,
|
|
2799
|
+
sourceContent: withSourceContent
|
|
2800
|
+
? consumer.sourceContentFor(source) || ''
|
|
2801
|
+
: '',
|
|
2802
|
+
};
|
|
2803
|
+
}
|
|
2804
|
+
}
|
|
2805
|
+
function joinItem(item) {
|
|
2806
|
+
if (typeof item === 'string') {
|
|
2807
|
+
return item;
|
|
2808
|
+
}
|
|
2809
|
+
const a = item[0];
|
|
2810
|
+
const b = item[1] ? ` ${item[1]}` : '';
|
|
2811
|
+
const c = item[2] ? ` ${item[2]}` : '';
|
|
2812
|
+
return `${a}${b}${c}`;
|
|
2813
|
+
}
|
|
2814
|
+
function uniStracktraceyPreset(opts) {
|
|
2815
|
+
const { base, sourceRoot, splitThirdParty, uniPlatform, lineOffset } = opts;
|
|
2816
|
+
let stack;
|
|
2817
|
+
return {
|
|
2818
|
+
/**
|
|
2819
|
+
*
|
|
2820
|
+
* 微信特殊处理
|
|
2821
|
+
* 微信解析步骤:
|
|
2822
|
+
* 1. //usr/app-service.js -> 'weixin/__APP__/app-service.map.map'
|
|
2823
|
+
* 2. //usr/pages/API/app-service.js -> 'weixin/pages/API/app-service.map.map'
|
|
2824
|
+
* 3. uni-list-item/uni-list-item.js -> ${base}/uni-list-item/uni-list-item.js.map
|
|
2825
|
+
*/
|
|
2826
|
+
parseSourceMapUrl(file, fileName, fileRelative) {
|
|
2827
|
+
// 组合 sourceMapUrl
|
|
2828
|
+
if (fileRelative.indexOf('(') !== -1)
|
|
2829
|
+
fileRelative = fileRelative.match(/\((.*)/)[1];
|
|
2830
|
+
if (!base || !fileRelative)
|
|
2831
|
+
return '';
|
|
2832
|
+
if (sourceRoot) {
|
|
2833
|
+
return `${fileRelative.replace(sourceRoot, base + '/')}.map`;
|
|
2834
|
+
}
|
|
2835
|
+
let baseAfter = '';
|
|
2836
|
+
if (stack.isMP) {
|
|
2837
|
+
if (fileRelative.indexOf('app-service.js') !== -1) {
|
|
2838
|
+
baseAfter = (base.match(/\w$/) ? '/' : '') + '__WEIXIN__';
|
|
2839
|
+
if (fileRelative === fileName) {
|
|
2840
|
+
baseAfter += '/__APP__';
|
|
2841
|
+
}
|
|
2842
|
+
fileRelative = fileRelative.replace('.js', '.map');
|
|
2843
|
+
}
|
|
2844
|
+
if (baseAfter && !!fileRelative.match(/^\w/))
|
|
2845
|
+
baseAfter += '/';
|
|
2846
|
+
}
|
|
2847
|
+
return `${base}${baseAfter}${fileRelative}.map`;
|
|
2848
|
+
},
|
|
2849
|
+
getSourceMapContent(file, fileName, fileRelative) {
|
|
2850
|
+
if (stack.isMP && fileRelative.indexOf('.js') === -1) {
|
|
2851
|
+
return Promise.resolve('');
|
|
2852
|
+
}
|
|
2853
|
+
const sourcemapUrl = this.parseSourceMapUrl(file, fileName, fileRelative);
|
|
2854
|
+
return Promise.resolve(getSourceMapContent(sourcemapUrl));
|
|
2855
|
+
},
|
|
2856
|
+
parseStacktrace(stacktrace) {
|
|
2857
|
+
stack = new StackTracey$1(stacktrace, uniPlatform);
|
|
2858
|
+
return stack;
|
|
2859
|
+
},
|
|
2860
|
+
asTableStacktrace({ maxColumnWidths, stacktrace, stack }) {
|
|
2861
|
+
const errorName = stacktrace.split('\n')[0];
|
|
2862
|
+
const lines = stack.asTable
|
|
2863
|
+
? stack.asTable(maxColumnWidths ? { maxColumnWidths } : undefined)
|
|
2864
|
+
: { items: [], thirdPartyItems: [] };
|
|
2865
|
+
if (lines.items.length || lines.thirdPartyItems.length) {
|
|
2866
|
+
const { items: stackLines, thirdPartyItems: stackThirdPartyLines } = lines;
|
|
2867
|
+
const userError = stack.itemsHeader
|
|
2868
|
+
.map((item) => {
|
|
2869
|
+
if (item === '%StacktraceyItem%') {
|
|
2870
|
+
const _stack = stackLines.shift();
|
|
2871
|
+
return _stack ? joinItem(_stack) : '';
|
|
2872
|
+
}
|
|
2873
|
+
return item;
|
|
2874
|
+
})
|
|
2875
|
+
.filter(Boolean)
|
|
2876
|
+
.join('\n');
|
|
2877
|
+
const thirdParty = stackThirdPartyLines.length
|
|
2878
|
+
? stackThirdPartyLines.map(joinItem).join('\n')
|
|
2879
|
+
: '';
|
|
2880
|
+
if (splitThirdParty) {
|
|
2881
|
+
return {
|
|
2882
|
+
userError,
|
|
2883
|
+
thirdParty,
|
|
2884
|
+
};
|
|
2885
|
+
}
|
|
2886
|
+
return userError + '\n' + thirdParty;
|
|
2887
|
+
}
|
|
2888
|
+
else {
|
|
2889
|
+
if (splitThirdParty) {
|
|
2890
|
+
return {
|
|
2891
|
+
userError: errorName,
|
|
2892
|
+
thirdParty: '',
|
|
2893
|
+
};
|
|
2894
|
+
}
|
|
2895
|
+
return errorName;
|
|
2896
|
+
}
|
|
2897
|
+
},
|
|
2898
|
+
lineOffset,
|
|
2899
|
+
};
|
|
2900
|
+
}
|
|
2901
|
+
function utsStracktraceyPreset(opts) {
|
|
2902
|
+
const { inputRoot, outputRoot, sourceMapRoot } = opts;
|
|
2903
|
+
let errStack = [];
|
|
2904
|
+
return {
|
|
2905
|
+
parseSourceMapUrl(file, fileName, fileRelative) {
|
|
2906
|
+
return path__default.default.resolve(sourceMapRoot, path__default.default.relative(outputRoot, file) + '.map');
|
|
2907
|
+
},
|
|
2908
|
+
getSourceMapContent(file, fileName, fileRelative) {
|
|
2909
|
+
// 根据 base,filename 组合 sourceMapUrl
|
|
2910
|
+
return Promise.resolve(getSourceMapContent(this.parseSourceMapUrl(file, fileName, fileRelative)));
|
|
2911
|
+
},
|
|
2912
|
+
parseStacktrace(str) {
|
|
2913
|
+
const lines = (str || '').split('\n');
|
|
2914
|
+
const entries = lines
|
|
2915
|
+
.map((line, index) => {
|
|
2916
|
+
line = line.trim();
|
|
2917
|
+
const matches = line.match(/\s*(.+\.kt):([0-9]+):([0-9]+):\s+(.*)/);
|
|
2918
|
+
if (matches) {
|
|
2919
|
+
errStack.push('%StacktraceyItem%');
|
|
2920
|
+
}
|
|
2921
|
+
else {
|
|
2922
|
+
errStack.push(line);
|
|
2923
|
+
return;
|
|
2924
|
+
}
|
|
2925
|
+
const fileName = matches[1].replace(/^.*(\\|\/|\:)/, '');
|
|
2926
|
+
return {
|
|
2927
|
+
beforeParse: line,
|
|
2928
|
+
callee: '',
|
|
2929
|
+
index: false,
|
|
2930
|
+
native: false,
|
|
2931
|
+
file: nixSlashes(matches[1]),
|
|
2932
|
+
line: parseInt(matches[2]),
|
|
2933
|
+
column: parseInt(matches[3]),
|
|
2934
|
+
fileName,
|
|
2935
|
+
fileShort: line,
|
|
2936
|
+
errMsg: matches[4] || '',
|
|
2937
|
+
calleeShort: '',
|
|
2938
|
+
fileRelative: '',
|
|
2939
|
+
thirdParty: false,
|
|
2940
|
+
};
|
|
2941
|
+
})
|
|
2942
|
+
.filter((x) => x !== undefined);
|
|
2943
|
+
return {
|
|
2944
|
+
items: entries,
|
|
2945
|
+
itemsHeader: [],
|
|
2946
|
+
};
|
|
2947
|
+
},
|
|
2948
|
+
asTableStacktrace({ maxColumnWidths, stacktrace, stack }) {
|
|
2949
|
+
return errStack
|
|
2950
|
+
.map((item) => {
|
|
2951
|
+
if (item === '%StacktraceyItem%') {
|
|
2952
|
+
const _stack = stack.items.shift();
|
|
2953
|
+
if (_stack) {
|
|
2954
2954
|
return `at ${nixSlashes(path__default.default.relative(inputRoot, _stack.file.replace('\\\\?\\', '')))}:${_stack.line}:${_stack.column}
|
|
2955
|
-
${_stack.errMsg}`;
|
|
2956
|
-
}
|
|
2957
|
-
return '';
|
|
2958
|
-
}
|
|
2959
|
-
return item;
|
|
2960
|
-
})
|
|
2961
|
-
.join('\n');
|
|
2962
|
-
},
|
|
2963
|
-
};
|
|
2955
|
+
${_stack.errMsg}`;
|
|
2956
|
+
}
|
|
2957
|
+
return '';
|
|
2958
|
+
}
|
|
2959
|
+
return item;
|
|
2960
|
+
})
|
|
2961
|
+
.join('\n');
|
|
2962
|
+
},
|
|
2963
|
+
};
|
|
2964
2964
|
}
|
|
2965
2965
|
|
|
2966
2966
|
exports.SourceMapConsumer = SourceMapConsumer;
|