@dcloudio/uni-stacktracey 3.0.0-alpha-3041020220516004
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 +216 -0
- package/package.json +29 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var fs = require('fs');
|
|
6
|
+
var StackTracey = require('stacktracey');
|
|
7
|
+
var sourceMap = require('source-map');
|
|
8
|
+
|
|
9
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
|
+
|
|
11
|
+
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
12
|
+
var StackTracey__default = /*#__PURE__*/_interopDefaultLegacy(StackTracey);
|
|
13
|
+
|
|
14
|
+
const nixSlashes = (x) => x.replace(/\\/g, '/');
|
|
15
|
+
const sourcemapCatch = {};
|
|
16
|
+
function stacktracey(stacktrace, opts) {
|
|
17
|
+
const parseStack = [];
|
|
18
|
+
const stack = opts.preset.parseStacktrace(stacktrace);
|
|
19
|
+
stack.items.forEach((item, index) => {
|
|
20
|
+
const fn = () => {
|
|
21
|
+
const { line = 0, column = 0, file, fileName } = item;
|
|
22
|
+
try {
|
|
23
|
+
return opts.preset
|
|
24
|
+
.getSourceMapContent(file, fileName)
|
|
25
|
+
.then((content) => {
|
|
26
|
+
if (content)
|
|
27
|
+
return sourceMap.SourceMapConsumer.with(content, null, (consumer) => {
|
|
28
|
+
const sourceMapContent = parseSourceMapContent(consumer, {
|
|
29
|
+
line,
|
|
30
|
+
column,
|
|
31
|
+
});
|
|
32
|
+
if (sourceMapContent) {
|
|
33
|
+
const { source, sourcePath, sourceLine, sourceColumn, fileName = '', } = sourceMapContent;
|
|
34
|
+
stack.items[index] = Object.assign({}, item, {
|
|
35
|
+
file: source,
|
|
36
|
+
line: sourceLine,
|
|
37
|
+
column: sourceColumn,
|
|
38
|
+
fileShort: sourcePath,
|
|
39
|
+
fileRelative: sourcePath,
|
|
40
|
+
fileName,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
return Promise.resolve();
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
parseStack.push(fn());
|
|
51
|
+
});
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
Promise.all(parseStack)
|
|
54
|
+
.then(() => {
|
|
55
|
+
const parseError = opts.preset.asTableStacktrace({
|
|
56
|
+
maxColumnWidths: {
|
|
57
|
+
callee: 999,
|
|
58
|
+
file: 999,
|
|
59
|
+
sourceLine: 999,
|
|
60
|
+
},
|
|
61
|
+
stacktrace,
|
|
62
|
+
});
|
|
63
|
+
resolve(parseError);
|
|
64
|
+
})
|
|
65
|
+
.catch(() => {
|
|
66
|
+
resolve(stacktrace);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
function getSourceMapContent(sourcemapUrl) {
|
|
71
|
+
try {
|
|
72
|
+
return (sourcemapCatch[sourcemapUrl] ||
|
|
73
|
+
(sourcemapCatch[sourcemapUrl] = new Promise((resolve, reject) => {
|
|
74
|
+
try {
|
|
75
|
+
if (/^[http|https]+:/i.test(sourcemapUrl)) {
|
|
76
|
+
uni.request({
|
|
77
|
+
url: sourcemapUrl,
|
|
78
|
+
success: (res) => {
|
|
79
|
+
console.log('sourcemapUrl :>> ', sourcemapUrl);
|
|
80
|
+
sourcemapCatch[sourcemapUrl] = res.data;
|
|
81
|
+
resolve(sourcemapCatch[sourcemapUrl]);
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
sourcemapCatch[sourcemapUrl] = fs__default["default"].readFileSync(sourcemapUrl, 'utf-8');
|
|
87
|
+
resolve(sourcemapCatch[sourcemapUrl]);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
resolve('');
|
|
92
|
+
}
|
|
93
|
+
})));
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
return '';
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function parseSourceMapContent(consumer, obj) {
|
|
100
|
+
// source -> 'uni-app:///node_modules/@sentry/browser/esm/helpers.js'
|
|
101
|
+
const { source, line: sourceLine, column: sourceColumn, } = consumer.originalPositionFor(obj);
|
|
102
|
+
if (source) {
|
|
103
|
+
const sourcePathSplit = source.split('/');
|
|
104
|
+
const sourcePath = sourcePathSplit.slice(3).join('/');
|
|
105
|
+
const fileName = sourcePathSplit.pop();
|
|
106
|
+
return {
|
|
107
|
+
source,
|
|
108
|
+
sourcePath,
|
|
109
|
+
sourceLine: sourceLine === null ? 0 : sourceLine,
|
|
110
|
+
sourceColumn: sourceColumn === null ? 0 : sourceColumn,
|
|
111
|
+
fileName,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function uniStracktraceyPreset(opts) {
|
|
116
|
+
const { base, sourceRoot } = opts;
|
|
117
|
+
let stack;
|
|
118
|
+
return {
|
|
119
|
+
parseSourceMapUrl(file, fileName) {
|
|
120
|
+
// 组合 sourceMapUrl
|
|
121
|
+
if (!base)
|
|
122
|
+
return '';
|
|
123
|
+
file = (file.match(/(\/.*)/) || [])[1];
|
|
124
|
+
if (!file)
|
|
125
|
+
return '';
|
|
126
|
+
if (sourceRoot) {
|
|
127
|
+
return `${file.replace(sourceRoot, base + '/')}.map`;
|
|
128
|
+
}
|
|
129
|
+
return `${base}/${file}.map`;
|
|
130
|
+
},
|
|
131
|
+
getSourceMapContent(file, fileName) {
|
|
132
|
+
return Promise.resolve(getSourceMapContent(this.parseSourceMapUrl(file, fileName)));
|
|
133
|
+
},
|
|
134
|
+
parseStacktrace(stacktrace) {
|
|
135
|
+
return (stack = new StackTracey__default["default"](stacktrace));
|
|
136
|
+
},
|
|
137
|
+
asTableStacktrace({ maxColumnWidths, stacktrace } = { stacktrace: '' }) {
|
|
138
|
+
const errorName = stacktrace.split('\n')[0];
|
|
139
|
+
return ((errorName.indexOf('at') === -1 ? `${errorName}\n` : '') +
|
|
140
|
+
(stack.asTable ? stack.asTable({ maxColumnWidths }) : ''));
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
function utsStracktraceyPreset(opts) {
|
|
145
|
+
const { base, sourceRoot } = opts;
|
|
146
|
+
let stack;
|
|
147
|
+
let errStack = [];
|
|
148
|
+
return {
|
|
149
|
+
parseSourceMapUrl(file, fileName) {
|
|
150
|
+
// 组合 sourceMapUrl
|
|
151
|
+
if (sourceRoot) {
|
|
152
|
+
return `${file.replace(sourceRoot, base + '/')}.map`;
|
|
153
|
+
}
|
|
154
|
+
return `${base}/${file}.map`;
|
|
155
|
+
},
|
|
156
|
+
getSourceMapContent(file, fileName) {
|
|
157
|
+
// 根据 base,filename 组合 sourceMapUrl
|
|
158
|
+
return Promise.resolve(getSourceMapContent(this.parseSourceMapUrl(file, fileName)));
|
|
159
|
+
},
|
|
160
|
+
parseStacktrace(str) {
|
|
161
|
+
const lines = (str || '').split('\n');
|
|
162
|
+
const entries = lines
|
|
163
|
+
.map((line, index) => {
|
|
164
|
+
line = line.trim();
|
|
165
|
+
let callee, fileLineColumn = [], planA, planB;
|
|
166
|
+
if ((planA = line.match(/e: (.+\.kt)(.+\))*:\s*(.+)*/))) {
|
|
167
|
+
errStack.push('%StacktraceyItem%');
|
|
168
|
+
callee = 'e: ';
|
|
169
|
+
fileLineColumn = (planA[2].match(/.*:.*\((\d+).+?(\d+)\)/) || []).slice(1);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
errStack.push(line);
|
|
173
|
+
return undefined;
|
|
174
|
+
}
|
|
175
|
+
const fileName = planA[1]
|
|
176
|
+
? (planB = planA[1].match(/(.*)*\/(.+)/) || [])[2] || ''
|
|
177
|
+
: '';
|
|
178
|
+
return {
|
|
179
|
+
beforeParse: line,
|
|
180
|
+
callee: callee || '',
|
|
181
|
+
index: false,
|
|
182
|
+
native: false,
|
|
183
|
+
file: nixSlashes(planA[1] || ''),
|
|
184
|
+
line: parseInt(fileLineColumn[0] || '', 10) || undefined,
|
|
185
|
+
column: parseInt(fileLineColumn[1] || '', 10) || undefined,
|
|
186
|
+
fileName,
|
|
187
|
+
fileShort: planB ? planB[1] : '',
|
|
188
|
+
errMsg: planA[3] || '',
|
|
189
|
+
calleeShort: '',
|
|
190
|
+
fileRelative: '',
|
|
191
|
+
thirdParty: false,
|
|
192
|
+
};
|
|
193
|
+
})
|
|
194
|
+
.filter((x) => x !== undefined);
|
|
195
|
+
return (stack = {
|
|
196
|
+
items: entries,
|
|
197
|
+
});
|
|
198
|
+
},
|
|
199
|
+
asTableStacktrace({ stacktrace } = { stacktrace: '' }) {
|
|
200
|
+
return errStack
|
|
201
|
+
.map((item) => {
|
|
202
|
+
if (item === '%StacktraceyItem%') {
|
|
203
|
+
const _stack = stack.items.shift();
|
|
204
|
+
if (_stack)
|
|
205
|
+
return `${_stack.callee}${_stack.file}: (${_stack.line}, ${_stack.column}): ${_stack.errMsg}`;
|
|
206
|
+
}
|
|
207
|
+
return item;
|
|
208
|
+
})
|
|
209
|
+
.join('\n');
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
exports.stacktracey = stacktracey;
|
|
215
|
+
exports.uniStracktraceyPreset = uniStracktraceyPreset;
|
|
216
|
+
exports.utsStracktraceyPreset = utsStracktraceyPreset;
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dcloudio/uni-stacktracey",
|
|
3
|
+
"version": "3.0.0-alpha-3041020220516004",
|
|
4
|
+
"description": "@dcloudio/uni-stacktracey",
|
|
5
|
+
"main": "dist/uni-stacktracey.cjs.js",
|
|
6
|
+
"module": "dist/uni-stacktracey.cjs.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"lib"
|
|
10
|
+
],
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/dcloudio/uni-app.git",
|
|
15
|
+
"directory": "packages/uni-stacktracey"
|
|
16
|
+
},
|
|
17
|
+
"license": "Apache-2.0",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/dcloudio/uni-app/issues"
|
|
20
|
+
},
|
|
21
|
+
"gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"stacktracey": "^2.1.8",
|
|
24
|
+
"source-map": "^0.7.3"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@dcloudio/types": "^2.6.6"
|
|
28
|
+
}
|
|
29
|
+
}
|