@dcloudio/uni-stacktracey 2.0.1-alpha-36920221118002 → 3.0.0-3060520221121001

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/README.md ADDED
@@ -0,0 +1,115 @@
1
+ ### uni-stacktracey 使用说明
2
+
3
+ #### 引用方式
4
+
5
+ ```js
6
+ const {
7
+ sourcemap: { stacktracey, uniStracktraceyPreset, utsStracktraceyPreset },
8
+ } = require('${HBuilderX}/plugins/uniapp-cli-vite')
9
+ ```
10
+
11
+ #### stacktracey 方法
12
+
13
+ **stacktracey 方法有两个参数:**
14
+
15
+ 1. stacktrace
16
+ 2. opts
17
+
18
+ ##### stacktrace 参数说明
19
+
20
+ > 一个错误堆栈。String 类型
21
+
22
+ **示例**
23
+
24
+ ```js
25
+ // js 错误堆栈
26
+ const uniErrorMsg = `Error: Sentry Error
27
+ at a.throwError(/static/js/pages-index-index.3ab0d0e5.js:1:567)
28
+ at click(/static/js/pages-index-index.3ab0d0e5.js:1:2745)
29
+ at ee(/static/js/chunk-vendors.75525bd5.js:34:11927)
30
+ at n(/static/js/chunk-vendors.75525bd5.js:34:13747)
31
+ at ee(/static/js/chunk-vendors.75525bd5.js:34:11927)
32
+ at HTMLElement.n(/static/js/chunk-vendors.75525bd5.js:34:13824)
33
+ at HTMLElement.o._wrapper(/static/js/chunk-vendors.75525bd5.js:34:53966)
34
+ at HTMLElement.i(/static/js/chunk-vendors.75525bd5.js:7:609894)`
35
+
36
+ // uts 错误堆栈
37
+ const utsErrorMsg = `e: DCloud-UTSPlugin/android/src/io/dcloud/uniplugin/TestModule.kt: (9, 5): Unresolved reference: logxxxxxxx
38
+
39
+ FAILURE: Build failed with an exception.
40
+
41
+ * What went wrong:
42
+ Execution failed for task ':nativeplugins:DCloud-UTSPlugin:compileReleaseKotlin'.
43
+ > Compilation error. See log for more details
44
+
45
+ * Try:
46
+ Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
47
+
48
+ * Get more help at https://help.gradle.org
49
+
50
+ BUILD FAILED in 2s
51
+ `
52
+ ```
53
+
54
+ #### opts 参数说明
55
+
56
+ > 解析生成错误栈时需要用到的一些方法。
57
+
58
+ > 此处提供了生成该参数的两种预设方案:uniStracktraceyPreset、utsStracktraceyPreset
59
+
60
+ **预设一:`uniStracktraceyPreset`**
61
+
62
+ > 解析 js 错误栈的预设方案
63
+
64
+ ```js
65
+ // 调用方式
66
+ stacktracey(uniErrorMsg, {
67
+ preset: uniStracktraceyPreset({
68
+ base: path.resolve(__dirname, './__UNI__APPID__/1.0.0/.sourcemap/h5/'),
69
+ sourceRoot: '',
70
+ }),
71
+ }).then((stacktrace) => {
72
+ // stacktrace 即为解析 sourcemap 后的错误信息
73
+ console.log('stacktrace :>> ', stacktrace)
74
+ })
75
+ ```
76
+
77
+ **预设二:`utsStracktraceyPreset`**
78
+
79
+ > 解析 uts 错误栈的预设方案
80
+
81
+ ```js
82
+ // 调用方式
83
+ stacktracey(utsErrorMsg, {
84
+ preset: utsStracktraceyPreset({
85
+ base: path.resolve(
86
+ __dirname,
87
+ './nativeplugins-sourceMap/DCloud-UTSPlugin/'
88
+ ),
89
+ sourceRoot: 'DCloud-UTSPlugin/android/src/',
90
+ }),
91
+ }).then((stacktrace) => {
92
+ // stacktrace 即为解析 sourcemap 后的错误信息
93
+ console.log('stacktrace :>> ', stacktrace)
94
+ })
95
+ ```
96
+
97
+ **预设方案的参数说明**
98
+
99
+ > 需要使用 base 和 sourceRoot 从错误信息中生成 sourcemap 路径。sourceRoot 即为需要将 错误信息路径替换为 base 的部分。
100
+
101
+ 1. `base`:当前项目 `sourcemap` 文件绝对路径。如果由 `http:、https:` 开头,则会发送网络请求获取
102
+ 2. `sourceRoot`:当前项目资源路径
103
+
104
+ 3. 详细说明
105
+
106
+ > 由上述 stacktrace 参数说明中 `utsErrorMsg` 为例
107
+ >
108
+ > 错误信息为 e: DCloud-UTSPlugin/android/src/io/dcloud/uniplugin/TestModule.kt: (9, 5): Unresolved reference: logxxxxxxx
109
+
110
+ - 第一步:根据 `sourceRoot` 解析出包含 path 的 fileName
111
+ - 比如,`sourceRoot` 参数为:`DCloud-UTSPlugin/android/src/`
112
+ - 解析出的 `fileName` 为:`io/dcloud/uniplugin/TestModule.kt`
113
+ - 第二步:根据 `base + fileName` 参数拼接出 `sourcemap` 路径
114
+ - 比如,`base` 参数为:`C:/project/test-uni/.sourcemap/`
115
+ - 解析出的 `sourcemap` 路径为 `C:/project/test-uni/.sourcemap/io/dcloud/uniplugin/TestModule.kt.map`