@dcloudio/uni-stacktracey 3.0.0-alpha-4070720250804001 → 3.0.0-alpha-4070620250731002

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.
@@ -2,11 +2,210 @@
2
2
 
3
3
  var fs = require('fs');
4
4
  var path = require('path');
5
+ var os = require('os');
5
6
 
6
7
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
8
 
8
9
  var fs__default = /*#__PURE__*/_interopDefault(fs);
9
10
  var path__default = /*#__PURE__*/_interopDefault(path);
11
+ var os__default = /*#__PURE__*/_interopDefault(os);
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,
21
+ // @ts-ignore
22
+ nodeRequire = isBrowser ? null : module.require, // to prevent bundlers from expanding the require call
23
+ lastOf = (x) => x[x.length - 1], nixSlashes$1 = (x) => x.replace(/\\/g, '/'), pathRoot = isBrowser ? window.location.href : nixSlashes$1(process.cwd()) + '/';
24
+ /* ------------------------------------------------------------------------ */
25
+ class StackTracey {
26
+ constructor(input, uniPlatform, offset) {
27
+ this.itemsHeader = [];
28
+ this.isMP = false;
29
+ const originalInput = input, isParseableSyntaxError = input && input instanceof SyntaxError && !isBrowser;
30
+ /* new StackTracey () */
31
+ if (!input) {
32
+ input = new Error();
33
+ offset = offset === undefined ? 1 : offset;
34
+ }
35
+ /* new StackTracey (Error) */
36
+ if (input instanceof Error) {
37
+ input = input.stack || '';
38
+ }
39
+ /* new StackTracey (string) */
40
+ if (typeof input === 'string') {
41
+ this.isMP = uniPlatform === 'mp-weixin';
42
+ input = this.rawParse(input)
43
+ .slice(offset)
44
+ .map((x) => this.extractEntryMetadata(x));
45
+ }
46
+ /* new StackTracey (array) */
47
+ if (Array.isArray(input)) {
48
+ if (isParseableSyntaxError) {
49
+ const rawLines = nodeRequire('util')
50
+ .inspect(originalInput)
51
+ .split('\n'), fileLine = rawLines[0].split(':'), line = fileLine.pop(), file = fileLine.join(':');
52
+ if (file) {
53
+ input.unshift({
54
+ file: nixSlashes$1(file),
55
+ line: line,
56
+ column: (rawLines[2] || '').indexOf('^') + 1,
57
+ sourceLine: rawLines[1],
58
+ callee: '(syntax error)',
59
+ syntaxError: true,
60
+ });
61
+ }
62
+ }
63
+ this.items = input;
64
+ }
65
+ else {
66
+ this.items = [];
67
+ }
68
+ }
69
+ extractEntryMetadata(e) {
70
+ const decomposedPath = this.decomposePath(e.file || '');
71
+ const fileRelative = decomposedPath[0];
72
+ const externalDomain = decomposedPath[1];
73
+ return O.assign(e, {
74
+ calleeShort: e.calleeShort || lastOf((e.callee || '').split('.')),
75
+ fileRelative: fileRelative,
76
+ fileShort: this.shortenPath(fileRelative),
77
+ fileName: lastOf((e.file || '').split('/')),
78
+ thirdParty: this.isThirdParty(fileRelative, externalDomain) && !e.index,
79
+ externalDomain: externalDomain,
80
+ });
81
+ }
82
+ shortenPath(relativePath) {
83
+ return relativePath
84
+ .replace(/^node_modules\//, '')
85
+ .replace(/^webpack\/bootstrap\//, '')
86
+ .replace(/^__parcel_source_root\//, '');
87
+ }
88
+ decomposePath(fullPath) {
89
+ let result = fullPath;
90
+ if (isBrowser)
91
+ result = result.replace(pathRoot, '');
92
+ const externalDomainMatch = result.match(/^(http|https)\:\/\/?([^\/]+)\/{1,}(.*)/);
93
+ const externalDomain = externalDomainMatch
94
+ ? externalDomainMatch[2]
95
+ : undefined;
96
+ result = externalDomainMatch ? externalDomainMatch[3] : result;
97
+ // if (!isBrowser) result = nodeRequire!('path').relative(pathRoot, result)
98
+ return [
99
+ nixSlashes$1(result).replace(/^.*\:\/\/?\/?/, ''), // cut webpack:/// and webpack:/ things
100
+ externalDomain,
101
+ ];
102
+ }
103
+ isThirdParty(relativePath, externalDomain) {
104
+ if (this.isMP) {
105
+ if (typeof externalDomain === 'undefined')
106
+ return false;
107
+ return externalDomain !== 'usr';
108
+ }
109
+ return (
110
+ // 由于 hello-uniapp web 端报错携带 hellouniapp.dcloud.net.cn
111
+ // externalDomain ||
112
+ relativePath[0] === '~' || // webpack-specific heuristic
113
+ relativePath[0] === '/' || // external source
114
+ relativePath.indexOf('@dcloudio') !== -1 ||
115
+ relativePath.indexOf('weex-main-jsfm') !== -1 ||
116
+ relativePath.indexOf('webpack/bootstrap') === 0);
117
+ }
118
+ rawParse(str) {
119
+ const lines = (str || '').split('\n');
120
+ const entries = lines.map((line, index) => {
121
+ line = line.trim();
122
+ let callee, fileLineColumn = [], native, planA, planB;
123
+ if (line.indexOf('file:') !== -1) {
124
+ line = line.replace(/file:\/\/(.*)www/, 'file://');
125
+ }
126
+ if ((planA = line.match(/at (.+) \(eval at .+ \((.+)\), .+\)/)) || // eval calls
127
+ (planA = line.match(/at (.+) \((.+)\)/)) ||
128
+ (line.slice(0, 3) !== 'at ' && (planA = line.match(/(.*)@(.*)/)))) {
129
+ this.itemsHeader.push('%StacktraceyItem%');
130
+ callee = planA[1];
131
+ native = planA[2] === 'native';
132
+ fileLineColumn = (planA[2].match(/(.*):(\d+):(\d+)/) ||
133
+ planA[2].match(/(.*):(\d+)/) ||
134
+ planA[2].match(/\[(.*)\]/) ||
135
+ []).slice(1);
136
+ }
137
+ else if ((planB = line.match(/^(at\s*)*(.*)\s+(.+):(\d+):(\d+)/))) {
138
+ this.itemsHeader.push('%StacktraceyItem%');
139
+ callee = planB[2].trim();
140
+ fileLineColumn = planB.slice(3);
141
+ }
142
+ else {
143
+ this.itemsHeader.push(line);
144
+ return undefined;
145
+ }
146
+ /* Detect things like Array.reduce
147
+ TODO: detect more built-in types */
148
+ if (callee && !fileLineColumn[0]) {
149
+ const type = callee.split('.')[0];
150
+ if (type === 'Array') {
151
+ native = true;
152
+ }
153
+ }
154
+ return {
155
+ beforeParse: line,
156
+ callee: callee || '',
157
+ /* eslint-disable */
158
+ index: isBrowser && fileLineColumn[0] === window.location.href,
159
+ native: native || false,
160
+ file: nixSlashes$1(fileLineColumn[0] || ''),
161
+ line: parseInt(fileLineColumn[1] || '', 10) || undefined,
162
+ column: parseInt(fileLineColumn[2] || '', 10) || undefined,
163
+ };
164
+ });
165
+ return entries.filter((x) => x !== undefined);
166
+ }
167
+ maxColumnWidths() {
168
+ return {
169
+ callee: 30,
170
+ file: 60,
171
+ sourceLine: 80,
172
+ };
173
+ }
174
+ asTable(opts) {
175
+ const maxColumnWidths = (opts && opts.maxColumnWidths) || this.maxColumnWidths();
176
+ const trimmed = this
177
+ .filter((e) => !e.thirdParty)
178
+ .map((e) => parseItem(e, maxColumnWidths, this.isMP));
179
+ const trimmedThirdParty = this
180
+ .filter((e) => e.thirdParty)
181
+ .map((e) => parseItem(e, maxColumnWidths, this.isMP));
182
+ return {
183
+ items: trimmed.items,
184
+ thirdPartyItems: trimmedThirdParty.items,
185
+ };
186
+ }
187
+ }
188
+ const trimEnd = (s, n) => s && (s.length > n ? s.slice(0, n - 1) + '…' : s);
189
+ const trimStart = (s, n) => s && (s.length > n ? '…' + s.slice(-(n - 1)) : s);
190
+ function parseItem(e, maxColumnWidths, isMP) {
191
+ if (!e.parsed) {
192
+ return e.beforeParse;
193
+ }
194
+ const filePath = (isMP ? e.file && e.file : e.fileShort && e.fileShort) +
195
+ `${typeof e.line !== 'undefined' ? ':' + e.line : ''}` +
196
+ `${typeof e.column !== 'undefined' ? ':' + e.column : ''}`;
197
+ return [
198
+ 'at ' + trimEnd(isMP ? e.callee : e.calleeShort, maxColumnWidths.callee),
199
+ trimStart(filePath || '', maxColumnWidths.file),
200
+ trimEnd((e.sourceLine || '').trim() || '', maxColumnWidths.sourceLine),
201
+ ];
202
+ }
203
+ ['map', 'filter', 'slice', 'concat'].forEach((method) => {
204
+ StackTracey.prototype[method] = function ( /*...args */) {
205
+ // no support for ...args in Node v4 :(
206
+ return new StackTracey(this.items[method].apply(this.items, arguments));
207
+ };
208
+ });
10
209
 
11
210
  var util$1 = {};
12
211
 
@@ -2278,13 +2477,12 @@ function _factoryBSM(aSourceMap, aSourceMapURL) {
2278
2477
  */
2279
2478
  var SourceMapConsumer = sourceMapConsumer.SourceMapConsumer;
2280
2479
 
2281
- const splitRE = /\r?\n/;
2282
- const STACK_ERROR_PLACEHOLDER = '%StacktraceItem%';
2480
+ const splitRE$1 = /\r?\n/;
2283
2481
  const range = 2;
2284
2482
  function posToNumber(source, pos) {
2285
2483
  if (typeof pos === 'number')
2286
2484
  return pos;
2287
- const lines = source.split(splitRE);
2485
+ const lines = source.split(splitRE$1);
2288
2486
  const { line, column } = pos;
2289
2487
  let start = 0;
2290
2488
  for (let i = 0; i < line - 1; i++) {
@@ -2295,7 +2493,7 @@ function posToNumber(source, pos) {
2295
2493
  function generateCodeFrame(source, start = 0, end) {
2296
2494
  start = posToNumber(source, start);
2297
2495
  end = end || start;
2298
- const lines = source.split(splitRE);
2496
+ const lines = source.split(splitRE$1);
2299
2497
  let count = 0;
2300
2498
  const res = [];
2301
2499
  for (let i = 0; i < lines.length; i++) {
@@ -2326,6 +2524,14 @@ function generateCodeFrame(source, start = 0, end) {
2326
2524
  }
2327
2525
  return res.join('\n');
2328
2526
  }
2527
+ let isWindows = false;
2528
+ try {
2529
+ isWindows = os__default.default.platform() === 'win32';
2530
+ }
2531
+ catch (error) { }
2532
+ function normalizePath(id) {
2533
+ return isWindows ? id.replace(/\\/g, '/') : id;
2534
+ }
2329
2535
  function generateCodeFrameSourceMapConsumer(consumer, m, options = {}) {
2330
2536
  if (m.file) {
2331
2537
  const res = consumer.originalPositionFor({
@@ -2431,239 +2637,96 @@ ${m.code}
2431
2637
  });
2432
2638
  });
2433
2639
  }
2434
- function normalizePath(id) {
2435
- return id.replace(/\\/g, '/');
2436
- }
2437
- function getFileContent(sourcemapUrl) {
2438
- return new Promise((resolve, reject) => {
2439
- if (/^[http|https]+:/i.test(sourcemapUrl)) {
2440
- uni.request({
2441
- url: sourcemapUrl,
2442
- dataType: 'string',
2443
- success: (res) => {
2444
- if (res.statusCode === 200) {
2445
- resolve(res.data);
2446
- }
2447
- else {
2448
- resolve('');
2449
- }
2450
- },
2451
- fail() {
2452
- resolve('');
2453
- },
2454
- });
2455
- }
2456
- else {
2457
- fs__default.default.readFile(sourcemapUrl, 'utf-8', (err, data) => {
2458
- if (err) {
2459
- resolve('');
2460
- }
2461
- else {
2462
- resolve(data);
2463
- }
2464
- });
2465
- }
2466
- });
2467
- }
2468
2640
 
2469
- /* ------------------------------------------------------------------------ */
2470
- const O = Object, isBrowser =
2471
- /* eslint-disable */
2472
- typeof window !== 'undefined' &&
2473
- /* eslint-disable */
2474
- window.window === window &&
2475
- /* eslint-disable */
2476
- window.navigator,
2477
- // @ts-ignore
2478
- nodeRequire = isBrowser ? null : module.require, // to prevent bundlers from expanding the require call
2479
- lastOf = (x) => x[x.length - 1], nixSlashes = (x) => x.replace(/\\/g, '/'), pathRoot = isBrowser ? window.location.href : nixSlashes(process.cwd()) + '/';
2480
- /* ------------------------------------------------------------------------ */
2481
- class StackTracey {
2482
- constructor(input, uniPlatform, offset) {
2483
- this.itemsHeader = [];
2484
- this.isMP = false;
2485
- const originalInput = input, isParseableSyntaxError = input && input instanceof SyntaxError && !isBrowser;
2486
- /* new StackTracey () */
2487
- if (!input) {
2488
- input = new Error();
2489
- offset = offset === undefined ? 1 : offset;
2490
- }
2491
- /* new StackTracey (Error) */
2492
- if (input instanceof Error) {
2493
- input = input.stack || '';
2494
- }
2495
- /* new StackTracey (string) */
2496
- if (typeof input === 'string') {
2497
- this.isMP = uniPlatform === 'mp-weixin';
2498
- input = this.rawParse(input)
2499
- .slice(offset)
2500
- .map((x) => this.extractEntryMetadata(x));
2501
- }
2502
- /* new StackTracey (array) */
2503
- if (Array.isArray(input)) {
2504
- if (isParseableSyntaxError) {
2505
- const rawLines = nodeRequire('util')
2506
- .inspect(originalInput)
2507
- .split('\n'), fileLine = rawLines[0].split(':'), line = fileLine.pop(), file = fileLine.join(':');
2508
- if (file) {
2509
- input.unshift({
2510
- file: nixSlashes(file),
2511
- line: line,
2512
- column: (rawLines[2] || '').indexOf('^') + 1,
2513
- sourceLine: rawLines[1],
2514
- callee: '(syntax error)',
2515
- syntaxError: true,
2516
- });
2517
- }
2518
- }
2519
- this.items = input;
2520
- }
2521
- else {
2522
- this.items = [];
2523
- }
2524
- }
2525
- extractEntryMetadata(e) {
2526
- const decomposedPath = this.decomposePath(e.file || '');
2527
- const fileRelative = decomposedPath[0];
2528
- const externalDomain = decomposedPath[1];
2529
- return O.assign(e, {
2530
- calleeShort: e.calleeShort || lastOf((e.callee || '').split('.')),
2531
- fileRelative: fileRelative,
2532
- fileShort: this.shortenPath(fileRelative),
2533
- fileName: lastOf((e.file || '').split('/')),
2534
- thirdParty: this.isThirdParty(fileRelative, externalDomain) && !e.index,
2535
- externalDomain: externalDomain,
2536
- });
2537
- }
2538
- shortenPath(relativePath) {
2539
- return relativePath
2540
- .replace(/^node_modules\//, '')
2541
- .replace(/^webpack\/bootstrap\//, '')
2542
- .replace(/^__parcel_source_root\//, '');
2543
- }
2544
- decomposePath(fullPath) {
2545
- let result = fullPath;
2546
- if (isBrowser)
2547
- result = result.replace(pathRoot, '');
2548
- const externalDomainMatch = result.match(/^(http|https)\:\/\/?([^\/]+)\/{1,}(.*)/);
2549
- const externalDomain = externalDomainMatch
2550
- ? externalDomainMatch[2]
2551
- : undefined;
2552
- result = externalDomainMatch ? externalDomainMatch[3] : result;
2553
- // if (!isBrowser) result = nodeRequire!('path').relative(pathRoot, result)
2554
- return [
2555
- nixSlashes(result).replace(/^.*\:\/\/?\/?/, ''), // cut webpack:/// and webpack:/ things
2556
- externalDomain,
2557
- ];
2558
- }
2559
- isThirdParty(relativePath, externalDomain) {
2560
- if (this.isMP) {
2561
- if (typeof externalDomain === 'undefined')
2562
- return false;
2563
- return externalDomain !== 'usr';
2564
- }
2565
- return (
2566
- // 由于 hello-uniapp web 端报错携带 hellouniapp.dcloud.net.cn
2567
- // externalDomain ||
2568
- relativePath[0] === '~' || // webpack-specific heuristic
2569
- relativePath[0] === '/' || // external source
2570
- relativePath.indexOf('@dcloudio') !== -1 ||
2571
- relativePath.indexOf('weex-main-jsfm') !== -1 ||
2572
- relativePath.indexOf('webpack/bootstrap') === 0);
2573
- }
2574
- rawParse(str) {
2575
- const lines = (str || '').split('\n');
2576
- const entries = lines.map((line, index) => {
2577
- line = line.trim();
2578
- let callee, fileLineColumn = [], native, planA, planB;
2579
- if (line.indexOf('file:') !== -1) {
2580
- line = line.replace(/file:\/\/(.*)www/, 'file://');
2581
- }
2582
- if ((planA = line.match(/at (.+) \(eval at .+ \((.+)\), .+\)/)) || // eval calls
2583
- (planA = line.match(/at (.+) \((.+)\)/)) ||
2584
- (line.slice(0, 3) !== 'at ' && (planA = line.match(/(.*)@(.*)/)))) {
2585
- this.itemsHeader.push(STACK_ERROR_PLACEHOLDER);
2586
- callee = planA[1];
2587
- native = planA[2] === 'native';
2588
- fileLineColumn = (planA[2].match(/(.*):(\d+):(\d+)/) ||
2589
- planA[2].match(/(.*):(\d+)/) ||
2590
- planA[2].match(/\[(.*)\]/) ||
2591
- []).slice(1);
2641
+ const nixSlashes = (x) => x.replace(/\\/g, '/');
2642
+ const sourcemapCatch = {};
2643
+ function stacktracey(stacktrace, opts) {
2644
+ const stack = opts.preset.parseStacktrace(stacktrace);
2645
+ let parseStack = Promise.resolve();
2646
+ stack.items.forEach((item, index) => {
2647
+ const fn = (item, index) => {
2648
+ const { line = 0, column = 0, file, fileName, fileRelative } = item;
2649
+ if (item.thirdParty) {
2650
+ return Promise.resolve();
2592
2651
  }
2593
- else if ((planB = line.match(/^(at\s*)*(.*)\s+(.+):(\d+):(\d+)/))) {
2594
- this.itemsHeader.push(STACK_ERROR_PLACEHOLDER);
2595
- callee = planB[2].trim();
2596
- fileLineColumn = planB.slice(3);
2652
+ function _getSourceMapContent(file, fileName, fileRelative) {
2653
+ return opts.preset
2654
+ .getSourceMapContent(file, fileName, fileRelative)
2655
+ .then((content) => {
2656
+ if (content) {
2657
+ return getConsumer(content).then((consumer) => {
2658
+ return parseSourceMapContent(consumer, {
2659
+ line: line + (opts.preset.lineOffset || 0),
2660
+ column,
2661
+ }, !!opts.withSourceContent);
2662
+ });
2663
+ }
2664
+ });
2597
2665
  }
2598
- else {
2599
- this.itemsHeader.push(line);
2600
- return undefined;
2666
+ try {
2667
+ return _getSourceMapContent(file, fileName, fileRelative).then((sourceMapContent) => {
2668
+ if (sourceMapContent) {
2669
+ const { source, sourcePath, sourceLine, sourceColumn, sourceContent, fileName = '', } = sourceMapContent;
2670
+ stack.items[index] = Object.assign({}, item, {
2671
+ file: source,
2672
+ line: sourceLine,
2673
+ column: sourceColumn,
2674
+ fileShort: sourcePath || source,
2675
+ fileRelative: source,
2676
+ fileName,
2677
+ thirdParty: isThirdParty(sourcePath),
2678
+ parsed: true,
2679
+ sourceContent,
2680
+ });
2681
+ /**
2682
+ * 以 .js 结尾
2683
+ * 包含 app-service.js 则需要再解析 两次
2684
+ * 不包含 app-service.js 则无需再解析 一次
2685
+ */
2686
+ const curItem = stack.items[index];
2687
+ if (stack.isMP &&
2688
+ curItem.beforeParse.indexOf('app-service') !== -1) {
2689
+ return fn(curItem, index);
2690
+ }
2691
+ }
2692
+ });
2601
2693
  }
2602
- /* Detect things like Array.reduce
2603
- TODO: detect more built-in types */
2604
- if (callee && !fileLineColumn[0]) {
2605
- const type = callee.split('.')[0];
2606
- if (type === 'Array') {
2607
- native = true;
2608
- }
2694
+ catch (error) {
2695
+ return Promise.resolve();
2609
2696
  }
2610
- return {
2611
- beforeParse: line,
2612
- callee: callee || '',
2613
- /* eslint-disable */
2614
- index: isBrowser && fileLineColumn[0] === window.location.href,
2615
- native: native || false,
2616
- file: nixSlashes(fileLineColumn[0] || ''),
2617
- line: parseInt(fileLineColumn[1] || '', 10) || undefined,
2618
- column: parseInt(fileLineColumn[2] || '', 10) || undefined,
2619
- };
2620
- });
2621
- return entries.filter((x) => x !== undefined);
2622
- }
2623
- maxColumnWidths() {
2624
- return {
2625
- callee: 30,
2626
- file: 60,
2627
- sourceLine: 80,
2628
- };
2629
- }
2630
- asTable(opts) {
2631
- const maxColumnWidths = (opts && opts.maxColumnWidths) || this.maxColumnWidths();
2632
- const trimmed = this
2633
- .filter((e) => !e.thirdParty)
2634
- .map((e) => parseItem(e, maxColumnWidths, this.isMP));
2635
- const trimmedThirdParty = this
2636
- .filter((e) => e.thirdParty)
2637
- .map((e) => parseItem(e, maxColumnWidths, this.isMP));
2638
- return {
2639
- items: trimmed.items,
2640
- thirdPartyItems: trimmedThirdParty.items,
2641
2697
  };
2642
- }
2698
+ parseStack = parseStack.then(() => {
2699
+ return new Promise((resolve, reject) => {
2700
+ setTimeout(() => {
2701
+ fn(item, index).then(resolve);
2702
+ }, 0);
2703
+ });
2704
+ });
2705
+ });
2706
+ const _promise = new Promise((resolve, reject) => {
2707
+ parseStack
2708
+ .then(() => {
2709
+ const parseError = opts.preset.asTableStacktrace({
2710
+ stack,
2711
+ maxColumnWidths: {
2712
+ callee: 999,
2713
+ file: 999,
2714
+ sourceLine: 999,
2715
+ },
2716
+ stacktrace,
2717
+ });
2718
+ resolve(parseError);
2719
+ })
2720
+ .catch(() => {
2721
+ resolve(stacktrace);
2722
+ });
2723
+ });
2724
+ return _promise;
2643
2725
  }
2644
- const trimEnd = (s, n) => s && (s.length > n ? s.slice(0, n - 1) + '…' : s);
2645
- const trimStart = (s, n) => s && (s.length > n ? '…' + s.slice(-(n - 1)) : s);
2646
- function parseItem(e, maxColumnWidths, isMP) {
2647
- if (!e.parsed) {
2648
- return e.beforeParse;
2649
- }
2650
- const filePath = (isMP ? e.file && e.file : e.fileShort && e.fileShort) +
2651
- `${typeof e.line !== 'undefined' ? ':' + e.line : ''}` +
2652
- `${typeof e.column !== 'undefined' ? ':' + e.column : ''}`;
2653
- return [
2654
- 'at ' + trimEnd(isMP ? e.callee : e.calleeShort, maxColumnWidths.callee),
2655
- trimStart(filePath || '', maxColumnWidths.file),
2656
- trimEnd((e.sourceLine || '').trim() || '', maxColumnWidths.sourceLine),
2657
- ];
2726
+ function isThirdParty(relativePath) {
2727
+ return relativePath.indexOf('@dcloudio') !== -1;
2658
2728
  }
2659
- ['map', 'filter', 'slice', 'concat'].forEach((method) => {
2660
- StackTracey.prototype[method] = function ( /*...args */) {
2661
- // no support for ...args in Node v4 :(
2662
- return new StackTracey(this.items[method].apply(this.items, arguments));
2663
- };
2664
- });
2665
-
2666
- function getSourceMapConsumer(content) {
2729
+ function getConsumer(content) {
2667
2730
  return new Promise((resolve, reject) => {
2668
2731
  try {
2669
2732
  if (SourceMapConsumer.with) {
@@ -2682,177 +2745,60 @@ function getSourceMapConsumer(content) {
2682
2745
  }
2683
2746
  });
2684
2747
  }
2685
- function originalPositionFor(sourceMapContent, position, withSourceContent = false) {
2686
- return getSourceMapConsumer(sourceMapContent).then((consumer) => {
2687
- if (position.column === 0) {
2688
- position.bias = 2 /* BIAS.LEAST_UPPER_BOUND */;
2689
- }
2690
- // source -> 'uni-app:///node_modules/@sentry/browser/esm/helpers.js'
2691
- const { source, line: sourceLine, column: sourceColumn, } = consumer.originalPositionFor(position);
2692
- if (source) {
2693
- const sourcePathSplit = source.split('/');
2694
- const sourcePath = sourcePathSplit.slice(3).join('/');
2695
- const fileName = sourcePathSplit.pop();
2696
- return {
2697
- source,
2698
- sourcePath,
2699
- sourceLine: sourceLine === null ? 0 : sourceLine,
2700
- sourceColumn: sourceColumn === null ? 0 : sourceColumn,
2701
- fileName,
2702
- sourceContent: withSourceContent
2703
- ? consumer.sourceContentFor(source, true) || ''
2704
- : '',
2705
- };
2706
- }
2707
- });
2708
- }
2709
- const sourcemapCatch = {};
2710
2748
  function getSourceMapContent(sourcemapUrl) {
2711
2749
  try {
2712
- return sourcemapCatch[sourcemapUrl]
2713
- ? Promise.resolve(sourcemapCatch[sourcemapUrl])
2714
- : (sourcemapCatch[sourcemapUrl] = new Promise((resolve, reject) => {
2750
+ return (sourcemapCatch[sourcemapUrl] ||
2751
+ (sourcemapCatch[sourcemapUrl] = new Promise((resolve, reject) => {
2715
2752
  try {
2716
- getFileContent(sourcemapUrl).then((content) => {
2717
- resolve((sourcemapCatch[sourcemapUrl] = content));
2718
- });
2753
+ if (/^[http|https]+:/i.test(sourcemapUrl)) {
2754
+ uni.request({
2755
+ url: sourcemapUrl,
2756
+ success: (res) => {
2757
+ if (res.statusCode === 200) {
2758
+ sourcemapCatch[sourcemapUrl] = res.data;
2759
+ resolve(sourcemapCatch[sourcemapUrl]);
2760
+ }
2761
+ else {
2762
+ resolve((sourcemapCatch[sourcemapUrl] = ''));
2763
+ }
2764
+ },
2765
+ fail() {
2766
+ resolve((sourcemapCatch[sourcemapUrl] = ''));
2767
+ },
2768
+ });
2769
+ }
2770
+ else {
2771
+ sourcemapCatch[sourcemapUrl] = fs__default.default.readFileSync(sourcemapUrl, 'utf-8');
2772
+ resolve(sourcemapCatch[sourcemapUrl]);
2773
+ }
2719
2774
  }
2720
2775
  catch (error) {
2721
- resolve((sourcemapCatch[sourcemapUrl] = ''));
2776
+ resolve('');
2722
2777
  }
2723
- }));
2778
+ })));
2724
2779
  }
2725
2780
  catch (error) {
2726
- return Promise.resolve((sourcemapCatch[sourcemapUrl] = ''));
2781
+ return '';
2727
2782
  }
2728
2783
  }
2729
-
2730
- let kotlinManifest = {
2731
- manifest: {},
2732
- };
2733
- function updateUTSKotlinSourceMapManifestCache(url) {
2734
- return new Promise((resolve, reject) => {
2735
- let manifestFile = '';
2736
- if (/^[http|https]+:/i.test(url)) {
2737
- manifestFile = url;
2738
- }
2739
- else {
2740
- manifestFile = path__default.default.resolve(url, '.manifest.json');
2741
- }
2742
- try {
2743
- getFileContent(manifestFile).then((content) => {
2744
- try {
2745
- const { files } = JSON.parse(content);
2746
- if (files) {
2747
- const classManifest = {};
2748
- Object.keys(files).forEach((name) => {
2749
- const kotlinClass = files[name].class;
2750
- if (kotlinClass) {
2751
- classManifest[kotlinClass] = name;
2752
- }
2753
- });
2754
- kotlinManifest.manifest = classManifest;
2755
- }
2756
- }
2757
- catch (error) {
2758
- // console.log(`Failed to parse Kotlin manifest file: ${url}`)
2759
- }
2760
- resolve();
2761
- });
2762
- }
2763
- catch (e) { }
2764
- });
2765
- }
2766
- function parseFilenameByClassName(className) {
2767
- return kotlinManifest.manifest[className.split('$')[0]] || 'index.kt';
2768
- }
2769
-
2770
- function stacktrace(stacktrace, opts) {
2771
- const _promise = new Promise((resolve, reject) => {
2772
- opts.preset.precondition().then(() => {
2773
- let parseStack = Promise.resolve();
2774
- const stack = opts.preset.parseStacktrace(stacktrace);
2775
- stack.items.forEach((item, index) => {
2776
- const fn = (item, index) => {
2777
- const { line = 0, column = 0, file, fileName, fileRelative } = item;
2778
- if (item.thirdParty) {
2779
- return Promise.resolve();
2780
- }
2781
- function _getSourceMapContent(file, fileName, fileRelative) {
2782
- return opts.preset
2783
- .getSourceMapContent(file, fileName, fileRelative)
2784
- .then((content) => {
2785
- if (content) {
2786
- return originalPositionFor(content, {
2787
- line: line + (opts.preset.lineOffset || 0),
2788
- column,
2789
- }, !!opts.withSourceContent);
2790
- }
2791
- });
2792
- }
2793
- try {
2794
- return _getSourceMapContent(file, fileName, fileRelative).then((sourceMapContent) => {
2795
- if (sourceMapContent) {
2796
- const { source, sourcePath, sourceLine, sourceColumn, sourceContent, fileName = '', } = sourceMapContent;
2797
- stack.items[index] = Object.assign({}, item, {
2798
- file: source,
2799
- line: sourceLine,
2800
- column: sourceColumn,
2801
- fileShort: sourcePath || source,
2802
- fileRelative: source,
2803
- fileName,
2804
- thirdParty: isThirdParty(sourcePath),
2805
- parsed: true,
2806
- sourceContent,
2807
- });
2808
- /**
2809
- * 以 .js 结尾
2810
- * 包含 app-service.js 则需要再解析 两次
2811
- * 不包含 app-service.js 则无需再解析 一次
2812
- */
2813
- const curItem = stack.items[index];
2814
- if (stack.isMP &&
2815
- curItem.beforeParse.indexOf('app-service') !== -1) {
2816
- return fn(curItem, index);
2817
- }
2818
- }
2819
- });
2820
- }
2821
- catch (error) {
2822
- return Promise.resolve();
2823
- }
2824
- };
2825
- parseStack = parseStack.then(() => {
2826
- return new Promise((resolve, reject) => {
2827
- setTimeout(() => {
2828
- fn(item, index).then(resolve);
2829
- }, 0);
2830
- });
2831
- });
2832
- });
2833
- parseStack
2834
- .then(() => {
2835
- const parseError = opts.preset.asTableStacktrace({
2836
- stack,
2837
- maxColumnWidths: {
2838
- callee: 999,
2839
- file: 999,
2840
- sourceLine: 999,
2841
- },
2842
- stacktrace,
2843
- });
2844
- resolve(parseError);
2845
- })
2846
- .catch(() => {
2847
- resolve(stacktrace);
2848
- });
2849
- });
2850
- });
2851
- return _promise;
2852
- }
2853
- const stacktracey = stacktrace;
2854
- function isThirdParty(relativePath) {
2855
- return relativePath.indexOf('@dcloudio') !== -1;
2784
+ function parseSourceMapContent(consumer, obj, withSourceContent) {
2785
+ // source -> 'uni-app:///node_modules/@sentry/browser/esm/helpers.js'
2786
+ const { source, line: sourceLine, column: sourceColumn, } = consumer.originalPositionFor(obj);
2787
+ if (source) {
2788
+ const sourcePathSplit = source.split('/');
2789
+ const sourcePath = sourcePathSplit.slice(3).join('/');
2790
+ const fileName = sourcePathSplit.pop();
2791
+ return {
2792
+ source,
2793
+ sourcePath,
2794
+ sourceLine: sourceLine === null ? 0 : sourceLine,
2795
+ sourceColumn: sourceColumn === null ? 0 : sourceColumn,
2796
+ fileName,
2797
+ sourceContent: withSourceContent
2798
+ ? consumer.sourceContentFor(source) || ''
2799
+ : '',
2800
+ };
2801
+ }
2856
2802
  }
2857
2803
  function joinItem(item) {
2858
2804
  if (typeof item === 'string') {
@@ -2863,7 +2809,7 @@ function joinItem(item) {
2863
2809
  const c = item[2] ? ` ${item[2]}` : '';
2864
2810
  return `${a}${b}${c}`;
2865
2811
  }
2866
- function uniStacktracePreset(opts) {
2812
+ function uniStracktraceyPreset(opts) {
2867
2813
  const { base, sourceRoot, splitThirdParty, uniPlatform, lineOffset } = opts;
2868
2814
  let stack;
2869
2815
  return {
@@ -2921,7 +2867,7 @@ function uniStacktracePreset(opts) {
2921
2867
  const { items: stackLines, thirdPartyItems: stackThirdPartyLines } = lines;
2922
2868
  const userError = stack.itemsHeader
2923
2869
  .map((item) => {
2924
- if (item === STACK_ERROR_PLACEHOLDER) {
2870
+ if (item === '%StacktraceyItem%') {
2925
2871
  const _stack = stackLines.shift();
2926
2872
  return _stack ? joinItem(_stack) : '';
2927
2873
  }
@@ -2950,22 +2896,15 @@ function uniStacktracePreset(opts) {
2950
2896
  return errorName;
2951
2897
  }
2952
2898
  },
2953
- precondition() {
2954
- return Promise.resolve();
2955
- },
2956
2899
  lineOffset,
2957
2900
  };
2958
2901
  }
2959
- const uniStracktraceyPreset = uniStacktracePreset;
2960
- function utsStacktracePreset(opts) {
2902
+ const splitRE = /\r?\n/;
2903
+ function utsStracktraceyPreset(opts) {
2961
2904
  const { inputRoot = '', outputRoot = '', sourceMapRoot = '' } = opts;
2962
2905
  let errStack = [];
2963
- let parseKotlin = false;
2964
2906
  return {
2965
2907
  parseSourceMapUrl(file, fileName, fileRelative) {
2966
- if (parseKotlin) {
2967
- return path__default.default.resolve(sourceMapRoot, file + '.map');
2968
- }
2969
2908
  return path__default.default.resolve(sourceMapRoot, path__default.default.relative(outputRoot, file) + '.map');
2970
2909
  },
2971
2910
  getSourceMapContent(file, fileName, fileRelative) {
@@ -2977,46 +2916,31 @@ function utsStacktracePreset(opts) {
2977
2916
  const entries = lines
2978
2917
  .map((line, index) => {
2979
2918
  line = line.trim();
2980
- let matches = line.match(/\s*(.+\.(kt|swift|ets)):([0-9]+):([0-9]+):?\s*(.*)/);
2981
- if (!matches) {
2982
- matches = line.match(new RegExp('uni\\.\\w+\\.(.*)\\..*\\(*\\.kt:([0-9]+)\\)'));
2983
- if (matches) {
2984
- parseKotlin = true;
2985
- }
2919
+ const matches = line.match(/\s*(.+\.(kt|swift|ets)):([0-9]+):([0-9]+):?\s*(.*)/);
2920
+ if (matches) {
2921
+ errStack.push('%StacktraceyItem%');
2986
2922
  }
2987
- errStack.push(matches ? STACK_ERROR_PLACEHOLDER : line);
2988
- if (!matches) {
2923
+ else {
2924
+ errStack.push(line);
2989
2925
  return;
2990
2926
  }
2991
- let file = matches[1];
2992
- let errorLine = matches[3];
2993
- let column = matches[4];
2994
- let errMsg = matches[5] || '';
2995
- let fileShort = line;
2996
- let fileName = '';
2997
2927
  if (matches[2] === 'ets') {
2998
- file =
2999
- (line.match(/File:\s+(.*):(\d+):(\d+)/) || [])[1] || matches[1];
3000
- }
3001
- if (parseKotlin) {
3002
- fileName = fileShort = file = parseFilenameByClassName(file);
3003
- errorLine = matches[2];
3004
- column = '0';
3005
- }
3006
- else {
3007
- fileName = file.replace(/^.*(\\|\/|\:)/, '');
2928
+ matches[1] =
2929
+ (matches[0].match(/File:\s+(.*):(\d+):(\d+)/) || [])[1] ||
2930
+ matches[1];
3008
2931
  }
2932
+ const fileName = matches[1].replace(/^.*(\\|\/|\:)/, '');
3009
2933
  return {
3010
2934
  beforeParse: line,
3011
2935
  callee: '',
3012
2936
  index: false,
3013
2937
  native: false,
3014
- file: normalizePath(file),
3015
- line: parseInt(errorLine),
3016
- column: parseInt(column),
2938
+ file: nixSlashes(matches[1]),
2939
+ line: parseInt(matches[3]),
2940
+ column: parseInt(matches[4]),
3017
2941
  fileName,
3018
- fileShort,
3019
- errMsg,
2942
+ fileShort: line,
2943
+ errMsg: matches[5] || '',
3020
2944
  calleeShort: '',
3021
2945
  fileRelative: '',
3022
2946
  thirdParty: false,
@@ -3031,12 +2955,11 @@ function utsStacktracePreset(opts) {
3031
2955
  asTableStacktrace({ maxColumnWidths, stacktrace, stack }) {
3032
2956
  return errStack
3033
2957
  .map((item) => {
3034
- if (item === STACK_ERROR_PLACEHOLDER) {
2958
+ if (item === '%StacktraceyItem%') {
3035
2959
  const _stack = stack.items.shift();
3036
2960
  if (_stack) {
3037
- return `at ${normalizePath(parseKotlin
3038
- ? _stack.file
3039
- : path__default.default.relative(inputRoot, _stack.file.replace('\\\\?\\', '')))}:${_stack.line}:${_stack.column}${_stack.errMsg ? `\n${_stack.errMsg}` : ''}`;
2961
+ return `at ${nixSlashes(path__default.default.relative(inputRoot, _stack.file.replace('\\\\?\\', '')))}:${_stack.line}:${_stack.column}
2962
+ ${_stack.errMsg}`;
3040
2963
  }
3041
2964
  return '';
3042
2965
  }
@@ -3044,14 +2967,8 @@ function utsStacktracePreset(opts) {
3044
2967
  })
3045
2968
  .join('\n');
3046
2969
  },
3047
- precondition() {
3048
- return new Promise((resolve, reject) => {
3049
- updateUTSKotlinSourceMapManifestCache(sourceMapRoot).finally(resolve);
3050
- });
3051
- },
3052
2970
  };
3053
2971
  }
3054
- const utsStracktraceyPreset = utsStacktracePreset;
3055
2972
 
3056
2973
  exports.SourceMapConsumer = SourceMapConsumer;
3057
2974
  exports.generateCodeFrame = generateCodeFrame;
@@ -3059,11 +2976,7 @@ exports.generateCodeFrameSourceMapConsumer = generateCodeFrameSourceMapConsumer;
3059
2976
  exports.generateCodeFrameWithKotlinStacktrace = generateCodeFrameWithKotlinStacktrace;
3060
2977
  exports.generateCodeFrameWithSourceMapPath = generateCodeFrameWithSourceMapPath;
3061
2978
  exports.generateCodeFrameWithSwiftStacktrace = generateCodeFrameWithSwiftStacktrace;
3062
- exports.getSourceMapContent = getSourceMapContent;
3063
- exports.originalPositionFor = originalPositionFor;
3064
- exports.stacktrace = stacktrace;
2979
+ exports.splitRE = splitRE;
3065
2980
  exports.stacktracey = stacktracey;
3066
- exports.uniStacktracePreset = uniStacktracePreset;
3067
2981
  exports.uniStracktraceyPreset = uniStracktraceyPreset;
3068
- exports.utsStacktracePreset = utsStacktracePreset;
3069
2982
  exports.utsStracktraceyPreset = utsStracktraceyPreset;