Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
genary
uni-app
提交
4ab19605
U
uni-app
项目概览
genary
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4ab19605
编写于
5月 19, 2022
作者:
fxy060608
浏览文件
操作
浏览文件
下载
差异文件
chore: build
上级
f63cd12c
9c2ba65d
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
235 addition
and
2 deletion
+235
-2
packages/uni-stacktracey/build.json
packages/uni-stacktracey/build.json
+16
-0
packages/uni-stacktracey/dist/uni-stacktracey.cjs.js
packages/uni-stacktracey/dist/uni-stacktracey.cjs.js
+0
-1
packages/uni-stacktracey/dist/uni-stacktracey.es.js
packages/uni-stacktracey/dist/uni-stacktracey.es.js
+211
-0
packages/uni-stacktracey/src/index.ts
packages/uni-stacktracey/src/index.ts
+8
-1
未找到文件。
packages/uni-stacktracey/build.json
浏览文件 @
4ab19605
...
...
@@ -4,6 +4,22 @@
"src/index.ts"
:
[
"dist/uni-stacktracey.cjs.js"
]
},
"replacements"
:
{
"__PLATFORM_WEB__"
:
"false"
}
},
{
"input"
:
{
"src/index.ts"
:
[
"dist/uni-stacktracey.es.js"
]
},
"output"
:
{
"format"
:
"es"
},
"replacements"
:
{
"__PLATFORM_WEB__"
:
"true"
}
}
]
\ No newline at end of file
packages/uni-stacktracey/dist/uni-stacktracey.cjs.js
浏览文件 @
4ab19605
...
...
@@ -76,7 +76,6 @@ function getSourceMapContent(sourcemapUrl) {
uni
.
request
({
url
:
sourcemapUrl
,
success
:
(
res
)
=>
{
console
.
log
(
'
sourcemapUrl :>>
'
,
sourcemapUrl
);
sourcemapCatch
[
sourcemapUrl
]
=
res
.
data
;
resolve
(
sourcemapCatch
[
sourcemapUrl
]);
},
...
...
packages/uni-stacktracey/dist/uni-stacktracey.es.js
0 → 100644
浏览文件 @
4ab19605
import
fs
from
'
fs
'
;
import
StackTracey
from
'
stacktracey
'
;
import
{
SourceMapConsumer
}
from
'
source-map
'
;
// @ts-ignore
{
// @ts-ignore
SourceMapConsumer
.
initialize
({
'
lib/mappings.wasm
'
:
'
https://unpkg.com/source-map@0.7.3/lib/mappings.wasm
'
,
});
}
const
nixSlashes
=
(
x
)
=>
x
.
replace
(
/
\\
/g
,
'
/
'
);
const
sourcemapCatch
=
{};
function
stacktracey
(
stacktrace
,
opts
)
{
const
parseStack
=
[];
const
stack
=
opts
.
preset
.
parseStacktrace
(
stacktrace
);
stack
.
items
.
forEach
((
item
,
index
)
=>
{
const
fn
=
()
=>
{
const
{
line
=
0
,
column
=
0
,
file
,
fileName
}
=
item
;
try
{
return
opts
.
preset
.
getSourceMapContent
(
file
,
fileName
)
.
then
((
content
)
=>
{
if
(
content
)
return
SourceMapConsumer
.
with
(
content
,
null
,
(
consumer
)
=>
{
const
sourceMapContent
=
parseSourceMapContent
(
consumer
,
{
line
,
column
,
});
if
(
sourceMapContent
)
{
const
{
source
,
sourcePath
,
sourceLine
,
sourceColumn
,
fileName
=
''
,
}
=
sourceMapContent
;
stack
.
items
[
index
]
=
Object
.
assign
({},
item
,
{
file
:
source
,
line
:
sourceLine
,
column
:
sourceColumn
,
fileShort
:
sourcePath
,
fileRelative
:
sourcePath
,
fileName
,
});
}
});
});
}
catch
(
error
)
{
return
Promise
.
resolve
();
}
};
parseStack
.
push
(
fn
());
});
return
new
Promise
((
resolve
,
reject
)
=>
{
Promise
.
all
(
parseStack
)
.
then
(()
=>
{
const
parseError
=
opts
.
preset
.
asTableStacktrace
({
maxColumnWidths
:
{
callee
:
999
,
file
:
999
,
sourceLine
:
999
,
},
stacktrace
,
});
resolve
(
parseError
);
})
.
catch
(()
=>
{
resolve
(
stacktrace
);
});
});
}
function
getSourceMapContent
(
sourcemapUrl
)
{
try
{
return
(
sourcemapCatch
[
sourcemapUrl
]
||
(
sourcemapCatch
[
sourcemapUrl
]
=
new
Promise
((
resolve
,
reject
)
=>
{
try
{
if
(
/^
[
http|https
]
+:/i
.
test
(
sourcemapUrl
))
{
uni
.
request
({
url
:
sourcemapUrl
,
success
:
(
res
)
=>
{
sourcemapCatch
[
sourcemapUrl
]
=
res
.
data
;
resolve
(
sourcemapCatch
[
sourcemapUrl
]);
},
});
}
else
{
sourcemapCatch
[
sourcemapUrl
]
=
fs
.
readFileSync
(
sourcemapUrl
,
'
utf-8
'
);
resolve
(
sourcemapCatch
[
sourcemapUrl
]);
}
}
catch
(
error
)
{
resolve
(
''
);
}
})));
}
catch
(
error
)
{
return
''
;
}
}
function
parseSourceMapContent
(
consumer
,
obj
)
{
// source -> 'uni-app:///node_modules/@sentry/browser/esm/helpers.js'
const
{
source
,
line
:
sourceLine
,
column
:
sourceColumn
,
}
=
consumer
.
originalPositionFor
(
obj
);
if
(
source
)
{
const
sourcePathSplit
=
source
.
split
(
'
/
'
);
const
sourcePath
=
sourcePathSplit
.
slice
(
3
).
join
(
'
/
'
);
const
fileName
=
sourcePathSplit
.
pop
();
return
{
source
,
sourcePath
,
sourceLine
:
sourceLine
===
null
?
0
:
sourceLine
,
sourceColumn
:
sourceColumn
===
null
?
0
:
sourceColumn
,
fileName
,
};
}
}
function
uniStracktraceyPreset
(
opts
)
{
const
{
base
,
sourceRoot
}
=
opts
;
let
stack
;
return
{
parseSourceMapUrl
(
file
,
fileName
)
{
// 组合 sourceMapUrl
if
(
!
base
)
return
''
;
file
=
(
file
.
match
(
/
(\/
.*
)
/
)
||
[])[
1
];
if
(
!
file
)
return
''
;
if
(
sourceRoot
)
{
return
`
${
file
.
replace
(
sourceRoot
,
base
+
'
/
'
)}
.map`
;
}
return
`
${
base
}
/
${
file
}
.map`
;
},
getSourceMapContent
(
file
,
fileName
)
{
return
Promise
.
resolve
(
getSourceMapContent
(
this
.
parseSourceMapUrl
(
file
,
fileName
)));
},
parseStacktrace
(
stacktrace
)
{
return
(
stack
=
new
StackTracey
(
stacktrace
));
},
asTableStacktrace
({
maxColumnWidths
,
stacktrace
}
=
{
stacktrace
:
''
})
{
const
errorName
=
stacktrace
.
split
(
'
\n
'
)[
0
];
return
((
errorName
.
indexOf
(
'
at
'
)
===
-
1
?
`
${
errorName
}
\n`
:
''
)
+
(
stack
.
asTable
?
stack
.
asTable
({
maxColumnWidths
})
:
''
));
},
};
}
function
utsStracktraceyPreset
(
opts
)
{
const
{
base
,
sourceRoot
}
=
opts
;
let
stack
;
let
errStack
=
[];
return
{
parseSourceMapUrl
(
file
,
fileName
)
{
// 组合 sourceMapUrl
if
(
sourceRoot
)
{
return
`
${
file
.
replace
(
sourceRoot
,
base
+
'
/
'
)}
.map`
;
}
return
`
${
base
}
/
${
file
}
.map`
;
},
getSourceMapContent
(
file
,
fileName
)
{
// 根据 base,filename 组合 sourceMapUrl
return
Promise
.
resolve
(
getSourceMapContent
(
this
.
parseSourceMapUrl
(
file
,
fileName
)));
},
parseStacktrace
(
str
)
{
const
lines
=
(
str
||
''
).
split
(
'
\n
'
);
const
entries
=
lines
.
map
((
line
,
index
)
=>
{
line
=
line
.
trim
();
let
callee
,
fileLineColumn
=
[],
planA
,
planB
;
if
((
planA
=
line
.
match
(
/e:
(
.+
\.
kt
)(
.+
\))
*:
\s
*
(
.+
)
*/
)))
{
errStack
.
push
(
'
%StacktraceyItem%
'
);
callee
=
'
e:
'
;
fileLineColumn
=
(
planA
[
2
].
match
(
/.*:.*
\((\d
+
)
.+
?(\d
+
)\)
/
)
||
[]).
slice
(
1
);
}
else
{
errStack
.
push
(
line
);
return
undefined
;
}
const
fileName
=
planA
[
1
]
?
(
planB
=
planA
[
1
].
match
(
/
(
.*
)
*
\/(
.+
)
/
)
||
[])[
2
]
||
''
:
''
;
return
{
beforeParse
:
line
,
callee
:
callee
||
''
,
index
:
false
,
native
:
false
,
file
:
nixSlashes
(
planA
[
1
]
||
''
),
line
:
parseInt
(
fileLineColumn
[
0
]
||
''
,
10
)
||
undefined
,
column
:
parseInt
(
fileLineColumn
[
1
]
||
''
,
10
)
||
undefined
,
fileName
,
fileShort
:
planB
?
planB
[
1
]
:
''
,
errMsg
:
planA
[
3
]
||
''
,
calleeShort
:
''
,
fileRelative
:
''
,
thirdParty
:
false
,
};
})
.
filter
((
x
)
=>
x
!==
undefined
);
return
(
stack
=
{
items
:
entries
,
});
},
asTableStacktrace
({
stacktrace
}
=
{
stacktrace
:
''
})
{
return
errStack
.
map
((
item
)
=>
{
if
(
item
===
'
%StacktraceyItem%
'
)
{
const
_stack
=
stack
.
items
.
shift
();
if
(
_stack
)
return
`
${
_stack
.
callee
}${
_stack
.
file
}
: (
${
_stack
.
line
}
,
${
_stack
.
column
}
):
${
_stack
.
errMsg
}
`
;
}
return
item
;
})
.
join
(
'
\n
'
);
},
};
}
export
{
stacktracey
,
uniStracktraceyPreset
,
utsStracktraceyPreset
};
packages/uni-stacktracey/src/index.ts
浏览文件 @
4ab19605
...
...
@@ -7,6 +7,14 @@ import {
Position
,
}
from
'
source-map
'
// @ts-ignore
if
(
__PLATFORM_WEB__
)
{
// @ts-ignore
SourceMapConsumer
.
initialize
({
'
lib/mappings.wasm
'
:
'
https://unpkg.com/source-map@0.7.3/lib/mappings.wasm
'
,
})
}
const
nixSlashes
=
(
x
:
string
)
=>
x
.
replace
(
/
\\
/g
,
'
/
'
)
const
sourcemapCatch
:
Record
<
string
,
string
|
Promise
<
string
>>
=
{}
...
...
@@ -123,7 +131,6 @@ function getSourceMapContent(sourcemapUrl: string) {
uni
.
request
({
url
:
sourcemapUrl
,
success
:
(
res
)
=>
{
console
.
log
(
'
sourcemapUrl :>>
'
,
sourcemapUrl
)
sourcemapCatch
[
sourcemapUrl
]
=
res
.
data
as
string
resolve
(
sourcemapCatch
[
sourcemapUrl
])
},
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录