@lark-apaas/coding-preset-vite-react 1.0.1-alpha.1 → 1.0.1-beta.0
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/lib/plugins/slardar.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import type { Plugin } from 'vite';
|
|
|
2
2
|
/**
|
|
3
3
|
* 注入 Slardar SDK + Performance + Tea 监控埋点。
|
|
4
4
|
*
|
|
5
|
-
*
|
|
5
|
+
* 四段都通过 `<script>` 注入到 head-prepend:
|
|
6
|
+
* 0. 早期错误捕获 stub(必须最先执行,覆盖 SDK 就绪前的时序空窗)
|
|
6
7
|
* 1. Slardar SDK loader(onload 后读 `window.tenantId/appId/userId/ENVIRONMENT` 初始化)
|
|
7
8
|
* 2. Performance SDK
|
|
8
9
|
* 3. Tea SDK loader
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slardar.d.ts","sourceRoot":"","sources":["../../src/plugins/slardar.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAqB,MAAM,MAAM,CAAC;AAEtD
|
|
1
|
+
{"version":3,"file":"slardar.d.ts","sourceRoot":"","sources":["../../src/plugins/slardar.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAqB,MAAM,MAAM,CAAC;AAEtD;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,oBAAoB;IACnC,oCAAoC;IACpC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,4CAA4C;IAC5C,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAuGD,wBAAgB,aAAa,CAAC,OAAO,GAAE,oBAAyB,GAAG,MAAM,CAyBxE;AAED,eAAe,aAAa,CAAC"}
|
package/lib/plugins/slardar.js
CHANGED
|
@@ -1,6 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.slardarPlugin = slardarPlugin;
|
|
4
|
+
/**
|
|
5
|
+
* 在 HTML 解析时同步执行的内联脚本(早于任何外部资源加载):
|
|
6
|
+
* 1. 建立 KSlardarWeb 命令队列 stub,保证 SDK 加载前的调用不丢失
|
|
7
|
+
* 2. 立即注册 capture 阶段的资源加载错误监听(直接入队)
|
|
8
|
+
* 3. 运行时错误 / unhandledrejection:
|
|
9
|
+
* - SDK 未就绪时写入 __slardarErrBuf,SDK onload 后统一 flush
|
|
10
|
+
* - SDK 已就绪(window[g].q 消失)时直接调 captureException,
|
|
11
|
+
* 填补 SDK start() 到 common-monitors 插件加载完成之间的时序空窗
|
|
12
|
+
*/
|
|
13
|
+
function buildEarlyResourceErrorScript(globalName) {
|
|
14
|
+
return `(function(g){
|
|
15
|
+
if(!window[g]){var q=[];window[g]=function(){q.push([].slice.call(arguments));};window[g].q=q;}
|
|
16
|
+
window.__slardarErrBuf=window.__slardarErrBuf||[];
|
|
17
|
+
var ref=document.referrer||'';
|
|
18
|
+
function _cap(err){
|
|
19
|
+
if(window[g]&&!window[g].q){
|
|
20
|
+
window[g]('captureException',err instanceof Error?err:new Error(String(err)),{source:'runtime-error',referrer:ref});
|
|
21
|
+
}else{
|
|
22
|
+
(window.__slardarErrBuf=window.__slardarErrBuf||[]).push(err);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
window.addEventListener('error',function(e){
|
|
26
|
+
if(e.error==null&&e.target instanceof Element){
|
|
27
|
+
var t=e.target,url=t.src||t.href||'';
|
|
28
|
+
if(url)window[g]('captureException',new Error('Resource load failed: '+url),{team:'miaoda-sdk',source:'resource-error',resourceType:t.tagName.toLowerCase(),resourceUrl:url,referrer:ref});
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if(e.error!=null){
|
|
32
|
+
var err=e.error;
|
|
33
|
+
if(e.filename&&typeof err.stack==='string'&&err.stack.indexOf(e.filename)<0){
|
|
34
|
+
try{err.stack+='\\n at '+e.filename+':'+(e.lineno||0)+':'+(e.colno||0);}catch(ex){}
|
|
35
|
+
}
|
|
36
|
+
_cap(err);
|
|
37
|
+
}else{
|
|
38
|
+
var msg=e.message||'Script error';
|
|
39
|
+
var err=new Error(msg);
|
|
40
|
+
if(e.filename)err.stack=msg+'\\n at '+e.filename+':'+(e.lineno||0)+':'+(e.colno||0);
|
|
41
|
+
_cap(err);
|
|
42
|
+
}
|
|
43
|
+
},true);
|
|
44
|
+
window.addEventListener('unhandledrejection',function(e){
|
|
45
|
+
if(e.reason!=null)_cap(e.reason instanceof Error?e.reason:new Error(String(e.reason)));
|
|
46
|
+
});
|
|
47
|
+
})('${globalName}');`;
|
|
48
|
+
}
|
|
4
49
|
function buildSlardarScript(bid, globalName) {
|
|
5
50
|
return `
|
|
6
51
|
const slardarScript = document.createElement('script');
|
|
@@ -18,6 +63,12 @@ function buildSlardarScript(bid, globalName) {
|
|
|
18
63
|
userId: window.userId ?? '',
|
|
19
64
|
});
|
|
20
65
|
window.${globalName}('start');
|
|
66
|
+
// Flush errors captured before the SDK finished loading
|
|
67
|
+
var buf = window.__slardarErrBuf || [];
|
|
68
|
+
window.__slardarErrBuf = [];
|
|
69
|
+
buf.forEach(function(err) {
|
|
70
|
+
window.${globalName}('captureException', err instanceof Error ? err : new Error(String(err)), { source: 'pre-sdk-error', referrer: document.referrer || '' });
|
|
71
|
+
});
|
|
21
72
|
}
|
|
22
73
|
};
|
|
23
74
|
slardarScript.onerror = function() {
|
|
@@ -54,6 +105,8 @@ function slardarPlugin(options = {}) {
|
|
|
54
105
|
name: 'miaoda-slardar',
|
|
55
106
|
transformIndexHtml(html) {
|
|
56
107
|
const tags = [
|
|
108
|
+
// Must be first: inline resource-error capture + KSlardarWeb command queue stub.
|
|
109
|
+
{ tag: 'script', children: buildEarlyResourceErrorScript(globalName), injectTo: 'head-prepend' },
|
|
57
110
|
{ tag: 'script', children: buildSlardarScript(bid, globalName), injectTo: 'head-prepend' },
|
|
58
111
|
{
|
|
59
112
|
tag: 'script',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slardar.js","sourceRoot":"","sources":["../../src/plugins/slardar.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"slardar.js","sourceRoot":"","sources":["../../src/plugins/slardar.ts"],"names":[],"mappings":";;AA6HA,sCAyBC;AA9HD;;;;;;;;GAQG;AACH,SAAS,6BAA6B,CAAC,UAAkB;IACvD,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAiCH,UAAU,KAAK,CAAC;AACtB,CAAC;AAED,SAAS,kBAAkB,CAAC,GAAW,EAAE,UAAkB;IACzD,OAAO;;gGAEuF,GAAG,eAAe,UAAU;;;mBAGzG,UAAU;iBACZ,UAAU;;;;iBAIV,UAAU;kBACT,GAAG;;;;iBAIJ,UAAU;;;;;mBAKR,UAAU;;;;;;;;GAQ1B,CAAC;AACJ,CAAC;AAED,SAAS,cAAc;IACrB,OAAO;;;;;;;;;;;;;;;;;;;GAmBN,CAAC;AACJ,CAAC;AAED,SAAgB,aAAa,CAAC,UAAgC,EAAE;IAC9D,MAAM,EAAE,GAAG,GAAG,cAAc,EAAE,UAAU,GAAG,aAAa,EAAE,GAAG,OAAO,CAAC;IAErE,OAAO;QACL,IAAI,EAAE,gBAAgB;QAEtB,kBAAkB,CAAC,IAAI;YACrB,MAAM,IAAI,GAAwB;gBAChC,iFAAiF;gBACjF,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,6BAA6B,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,cAAc,EAAE;gBAChG,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,kBAAkB,CAAC,GAAG,EAAE,UAAU,CAAC,EAAE,QAAQ,EAAE,cAAc,EAAE;gBAC1F;oBACE,GAAG,EAAE,QAAQ;oBACb,KAAK,EAAE;wBACL,GAAG,EAAE,gGAAgG;wBACrG,WAAW,EAAE,WAAW;wBACxB,KAAK,EAAE,IAAI;qBACZ;oBACD,QAAQ,EAAE,cAAc;iBACzB;gBACD,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,cAAc,EAAE,EAAE,QAAQ,EAAE,cAAc,EAAE;aACxE,CAAC;YACF,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;QACxB,CAAC;KACF,CAAC;AACJ,CAAC;AAED,kBAAe,aAAa,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/coding-preset-vite-react",
|
|
3
|
-
"version": "1.0.1-
|
|
3
|
+
"version": "1.0.1-beta.0",
|
|
4
4
|
"description": "Vite 8 preset for miaoda-coding vite-react (jsPage) templates — pure frontend, no fullstack baggage",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|