@lark-apaas/coding-preset-vite-react 0.1.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/LICENSE +13 -0
- package/lib/index.d.ts +52 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +410 -0
- package/lib/index.js.map +1 -0
- package/lib/plugins/capabilities.d.ts +23 -0
- package/lib/plugins/capabilities.d.ts.map +1 -0
- package/lib/plugins/capabilities.js +151 -0
- package/lib/plugins/capabilities.js.map +1 -0
- package/lib/plugins/dev-logs.d.ts +44 -0
- package/lib/plugins/dev-logs.d.ts.map +1 -0
- package/lib/plugins/dev-logs.js +544 -0
- package/lib/plugins/dev-logs.js.map +1 -0
- package/lib/plugins/error-overlay.d.ts +19 -0
- package/lib/plugins/error-overlay.d.ts.map +1 -0
- package/lib/plugins/error-overlay.js +136 -0
- package/lib/plugins/error-overlay.js.map +1 -0
- package/lib/plugins/fonts-mirror.d.ts +14 -0
- package/lib/plugins/fonts-mirror.d.ts.map +1 -0
- package/lib/plugins/fonts-mirror.js +70 -0
- package/lib/plugins/fonts-mirror.js.map +1 -0
- package/lib/plugins/health.d.ts +19 -0
- package/lib/plugins/health.d.ts.map +1 -0
- package/lib/plugins/health.js +36 -0
- package/lib/plugins/health.js.map +1 -0
- package/lib/plugins/hmr-timing.d.ts +13 -0
- package/lib/plugins/hmr-timing.d.ts.map +1 -0
- package/lib/plugins/hmr-timing.js +93 -0
- package/lib/plugins/hmr-timing.js.map +1 -0
- package/lib/plugins/html-minify.d.ts +18 -0
- package/lib/plugins/html-minify.d.ts.map +1 -0
- package/lib/plugins/html-minify.js +100 -0
- package/lib/plugins/html-minify.js.map +1 -0
- package/lib/plugins/module-alias.d.ts +12 -0
- package/lib/plugins/module-alias.d.ts.map +1 -0
- package/lib/plugins/module-alias.js +78 -0
- package/lib/plugins/module-alias.js.map +1 -0
- package/lib/plugins/og-meta.d.ts +21 -0
- package/lib/plugins/og-meta.d.ts.map +1 -0
- package/lib/plugins/og-meta.js +60 -0
- package/lib/plugins/og-meta.js.map +1 -0
- package/lib/plugins/polyfill.d.ts +11 -0
- package/lib/plugins/polyfill.d.ts.map +1 -0
- package/lib/plugins/polyfill.js +140 -0
- package/lib/plugins/polyfill.js.map +1 -0
- package/lib/plugins/routes.d.ts +26 -0
- package/lib/plugins/routes.d.ts.map +1 -0
- package/lib/plugins/routes.js +265 -0
- package/lib/plugins/routes.js.map +1 -0
- package/lib/plugins/slardar.d.ts +24 -0
- package/lib/plugins/slardar.d.ts.map +1 -0
- package/lib/plugins/slardar.js +74 -0
- package/lib/plugins/slardar.js.map +1 -0
- package/lib/plugins/static-assets.d.ts +10 -0
- package/lib/plugins/static-assets.d.ts.map +1 -0
- package/lib/plugins/static-assets.js +297 -0
- package/lib/plugins/static-assets.js.map +1 -0
- package/lib/plugins/view-context.d.ts +22 -0
- package/lib/plugins/view-context.d.ts.map +1 -0
- package/lib/plugins/view-context.js +132 -0
- package/lib/plugins/view-context.js.map +1 -0
- package/lib/plugins/vite-client-patch.d.ts +4 -0
- package/lib/plugins/vite-client-patch.d.ts.map +1 -0
- package/lib/plugins/vite-client-patch.js +37 -0
- package/lib/plugins/vite-client-patch.js.map +1 -0
- package/lib/plugins/ws-watchdog.d.ts +22 -0
- package/lib/plugins/ws-watchdog.d.ts.map +1 -0
- package/lib/plugins/ws-watchdog.js +103 -0
- package/lib/plugins/ws-watchdog.js.map +1 -0
- package/lib/polyfills/index.d.ts +15 -0
- package/lib/polyfills/index.d.ts.map +1 -0
- package/lib/polyfills/index.js +36 -0
- package/lib/polyfills/index.js.map +1 -0
- package/lib/utils/normalize-base-path.d.ts +37 -0
- package/lib/utils/normalize-base-path.d.ts.map +1 -0
- package/lib/utils/normalize-base-path.js +57 -0
- package/lib/utils/normalize-base-path.js.map +1 -0
- package/lib/utils/snapdom-proxy.d.ts +12 -0
- package/lib/utils/snapdom-proxy.d.ts.map +1 -0
- package/lib/utils/snapdom-proxy.js +75 -0
- package/lib/utils/snapdom-proxy.js.map +1 -0
- package/package.json +63 -0
- package/src/empty.css +1 -0
- package/src/inspector-stub.js +6 -0
- package/src/module-alias/clsx.mjs +8 -0
- package/src/module-alias/echarts-for-react.mjs +130 -0
- package/src/module-alias/echarts.mjs +43 -0
- package/src/module-alias/registry_echarts_theme.mjs +390 -0
- package/src/overlay/components.js +94 -0
- package/src/overlay/index.js +443 -0
- package/src/overlay/vite-client.js +555 -0
- package/src/polyfills/index.ts +35 -0
- package/src/runtime/ws-watchdog-client.mjs +148 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/* eslint-env browser */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* WebSocket Watchdog Client。在 Vite 沙箱 iframe 内自启动;
|
|
5
|
+
* 通过 createHotContext 走 HMR 通道发 ping/收 pong;判死后 postMessage 给 parent。
|
|
6
|
+
*
|
|
7
|
+
* 设计 spec: docs/superpowers/specs/2026-04-27-sandbox-ws-watchdog-design.md
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {Object} WatchdogDeps
|
|
12
|
+
* @property {(event: string, data: unknown) => void} sendCustom
|
|
13
|
+
* @property {(event: string, cb: (data: unknown) => void) => void} onCustom
|
|
14
|
+
* @property {(status: 'connected' | 'disconnected') => void} postStatus
|
|
15
|
+
* @property {(handler: () => void, ms: number) => number} setInterval
|
|
16
|
+
* @property {(handle: number) => void} clearInterval
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @typedef {Object} WatchdogOptions
|
|
21
|
+
* @property {number} [intervalMs] 默认 5000
|
|
22
|
+
* @property {number} [missThreshold] 默认 2
|
|
23
|
+
* @property {number} [echoFreshnessMs] 默认 15000
|
|
24
|
+
* @property {string} [pingEvent] 默认 'ws-watchdog:ping'
|
|
25
|
+
* @property {string} [pongEvent] 默认 'ws-watchdog:pong'
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 不返回 dispose——watchdog 跟 iframe 同生命周期,无独立销毁路径。
|
|
30
|
+
* @param {WatchdogDeps} deps
|
|
31
|
+
* @param {WatchdogOptions} [options]
|
|
32
|
+
*/
|
|
33
|
+
export function createWatchdog(deps, options = {}) {
|
|
34
|
+
const intervalMs = options.intervalMs ?? 5000;
|
|
35
|
+
const missThreshold = options.missThreshold ?? 2;
|
|
36
|
+
const echoFreshnessMs = options.echoFreshnessMs ?? 15000;
|
|
37
|
+
const pingEvent = options.pingEvent ?? 'ws-watchdog:ping';
|
|
38
|
+
const pongEvent = options.pongEvent ?? 'ws-watchdog:pong';
|
|
39
|
+
|
|
40
|
+
let missed = 0;
|
|
41
|
+
/** @type {'connected' | 'disconnected'} */
|
|
42
|
+
let reportedStatus = 'connected';
|
|
43
|
+
let pingSeq = 0;
|
|
44
|
+
/** @type {Map<number, number>} seq → wall-clock 时间戳 */
|
|
45
|
+
const recentPings = new Map();
|
|
46
|
+
|
|
47
|
+
function onTick() {
|
|
48
|
+
// missed++ 必须先于 sendCustom:发送侧抛错时 missed 已累加,下一 tick 仍能判死。
|
|
49
|
+
missed += 1;
|
|
50
|
+
const seq = ++pingSeq;
|
|
51
|
+
const now = Date.now();
|
|
52
|
+
recentPings.set(seq, now);
|
|
53
|
+
for (const [s, ts] of recentPings) {
|
|
54
|
+
if (now - ts > echoFreshnessMs) recentPings.delete(s);
|
|
55
|
+
}
|
|
56
|
+
deps.sendCustom(pingEvent, { t: seq });
|
|
57
|
+
if (missed >= missThreshold && reportedStatus !== 'disconnected') {
|
|
58
|
+
deps.postStatus('disconnected');
|
|
59
|
+
reportedStatus = 'disconnected';
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
deps.onCustom(pongEvent, (raw) => {
|
|
64
|
+
const data = /** @type {{ echo?: number } | undefined} */ (raw);
|
|
65
|
+
if (typeof data?.echo !== 'number' || !recentPings.has(data.echo)) return;
|
|
66
|
+
recentPings.delete(data.echo);
|
|
67
|
+
missed = 0;
|
|
68
|
+
if (reportedStatus !== 'connected') {
|
|
69
|
+
deps.postStatus('connected');
|
|
70
|
+
reportedStatus = 'connected';
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
deps.setInterval(onTick, intervalMs);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// postMessage 的 targetOrigin 必须显式指定,禁止用 '*'。
|
|
78
|
+
|
|
79
|
+
const PARENT_ORIGIN_KEY = '__parentOrigin';
|
|
80
|
+
|
|
81
|
+
function getParentOriginFromParams() {
|
|
82
|
+
try {
|
|
83
|
+
const origin = new URLSearchParams(window.location.search).get(PARENT_ORIGIN_KEY);
|
|
84
|
+
if (origin) {
|
|
85
|
+
try { sessionStorage.setItem(PARENT_ORIGIN_KEY, origin); } catch { /* 忽略 */ }
|
|
86
|
+
return origin;
|
|
87
|
+
}
|
|
88
|
+
} catch { /* 忽略 URL 解析失败 */ }
|
|
89
|
+
try { return sessionStorage.getItem(PARENT_ORIGIN_KEY) || undefined; }
|
|
90
|
+
catch { return undefined; }
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function getLegacyParentOrigin() {
|
|
94
|
+
const { origin } = window.location;
|
|
95
|
+
if (origin.includes('force.feishuapp.net')) return 'https://force.feishu.cn';
|
|
96
|
+
if (origin.includes('force-pre.feishuapp.net')) return 'https://force.feishu-pre.cn';
|
|
97
|
+
if (origin.includes('force.byted.org')) return 'https://force.feishu-boe.cn';
|
|
98
|
+
if (origin.includes('feishuapp.cn') || origin.includes('miaoda.feishuapp.net')) return 'https://miaoda.feishu.cn';
|
|
99
|
+
if (origin.includes('fsapp.kundou.cn') || origin.includes('miaoda-pre.feishuapp.net')) return 'https://miaoda.feishu-pre.cn';
|
|
100
|
+
return 'https://miaoda.feishu-boe.cn';
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function resolveParentOrigin() {
|
|
104
|
+
const paramOrigin = getParentOriginFromParams();
|
|
105
|
+
if (paramOrigin) return paramOrigin;
|
|
106
|
+
// plugin middleware 在送出脚本时把这个 token 编译期替换成字符串字面量。
|
|
107
|
+
return process.env.FORCE_FRAMEWORK_DOMAIN_MAIN || getLegacyParentOrigin();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function postStatus(status) {
|
|
111
|
+
try {
|
|
112
|
+
const origin = resolveParentOrigin();
|
|
113
|
+
if (!origin) return;
|
|
114
|
+
window.parent.postMessage(
|
|
115
|
+
{ type: 'DevServerMessage', data: { type: 'devServer-status', status } },
|
|
116
|
+
origin,
|
|
117
|
+
);
|
|
118
|
+
} catch (e) {
|
|
119
|
+
console.error('[fullstack-ws-watchdog] postMessage error:', e);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// 仅在 iframe 内自启动;jsdom(vitest)下 window.parent === window 自然跳过。
|
|
124
|
+
// 直出的 raw module 拿不到 import.meta.hot,所以借 createHotContext 走 HMR 通道。
|
|
125
|
+
// CLIENT_BASE_PATH 由 plugin 编译期替换;缺前缀会被网关 404。
|
|
126
|
+
const CLIENT_BASE_PATH = process.env.CLIENT_BASE_PATH || '';
|
|
127
|
+
|
|
128
|
+
if (typeof window !== 'undefined' && window.parent !== window) {
|
|
129
|
+
(async () => {
|
|
130
|
+
try {
|
|
131
|
+
const { createHotContext } = await import(CLIENT_BASE_PATH + '/@vite/client');
|
|
132
|
+
const hot = createHotContext(CLIENT_BASE_PATH + '/@ws-watchdog.js');
|
|
133
|
+
createWatchdog({
|
|
134
|
+
sendCustom: (event, data) => {
|
|
135
|
+
// 断连时 hot.send 可能抛;吞掉即可——missed 已在 onTick 顶部累加。
|
|
136
|
+
try { hot.send(event, data); }
|
|
137
|
+
catch (e) { console.warn('[fullstack-ws-watchdog] send failed:', e); }
|
|
138
|
+
},
|
|
139
|
+
onCustom: (event, cb) => hot.on(event, cb),
|
|
140
|
+
postStatus,
|
|
141
|
+
setInterval: (handler, ms) => window.setInterval(handler, ms),
|
|
142
|
+
clearInterval: (handle) => window.clearInterval(handle),
|
|
143
|
+
});
|
|
144
|
+
} catch (e) {
|
|
145
|
+
console.warn('[fullstack-ws-watchdog] bootstrap failed:', e);
|
|
146
|
+
}
|
|
147
|
+
})();
|
|
148
|
+
}
|