@lark-apaas/fullstack-vite-preset 1.0.20-alpha.2 → 1.0.20-alpha.4
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.
|
@@ -8,12 +8,6 @@ import type { Plugin } from 'vite';
|
|
|
8
8
|
export interface WsWatchdogPluginOptions {
|
|
9
9
|
pingEvent?: string;
|
|
10
10
|
pongEvent?: string;
|
|
11
|
-
/**
|
|
12
|
-
* 仅用于测试:开启后服务端故意吞掉所有 ping,从不回 pong。
|
|
13
|
-
* 客户端因此会在 ~10s 后判死,复现 zombie 故障。
|
|
14
|
-
* 生产环境必须为 false。
|
|
15
|
-
*/
|
|
16
|
-
simulateZombie?: boolean;
|
|
17
11
|
/**
|
|
18
12
|
* 客户端 base 路径(如 `/app/app_xxx`)。aiforce 等网关把完整路径透传给 Vite,
|
|
19
13
|
* middleware 匹配和注入的 <script src> 都必须带 base;空串退化为本地裸路径。
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ws-watchdog-plugin.d.ts","sourceRoot":"","sources":["../../src/vite-plugins/ws-watchdog-plugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAqB,MAAM,MAAM,CAAC;AAqBtD,MAAM,WAAW,uBAAuB;IACtC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB
|
|
1
|
+
{"version":3,"file":"ws-watchdog-plugin.d.ts","sourceRoot":"","sources":["../../src/vite-plugins/ws-watchdog-plugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAqB,MAAM,MAAM,CAAC;AAqBtD,MAAM,WAAW,uBAAuB;IACtC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,wBAAgB,sBAAsB,CACpC,OAAO,GAAE,uBAA4B,GACpC,MAAM,CAwER;AAED,eAAe,sBAAsB,CAAC"}
|
|
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.createWsWatchdogPlugin = createWsWatchdogPlugin;
|
|
13
13
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
14
14
|
const node_path_1 = __importDefault(require("node:path"));
|
|
15
|
-
const CLIENT_RUNTIME_PATH = '/@
|
|
15
|
+
const CLIENT_RUNTIME_PATH = '/@ws-watchdog.js';
|
|
16
16
|
// 本包是 CommonJS,所以走 __dirname;编译后/源码两种布局各一套候选。
|
|
17
17
|
const CLIENT_RUNTIME_CANDIDATES = [
|
|
18
18
|
node_path_1.default.resolve(__dirname, '../../src/runtime/ws-watchdog-client.mjs'),
|
|
@@ -27,20 +27,14 @@ function getClientRuntimePath() {
|
|
|
27
27
|
return null;
|
|
28
28
|
}
|
|
29
29
|
function createWsWatchdogPlugin(options = {}) {
|
|
30
|
-
const { pingEvent = '
|
|
30
|
+
const { pingEvent = 'ws-watchdog:ping', pongEvent = 'ws-watchdog:pong', clientBasePath = '', } = options;
|
|
31
31
|
const watchdogPath = clientBasePath + CLIENT_RUNTIME_PATH;
|
|
32
32
|
return {
|
|
33
33
|
name: 'fullstack-ws-watchdog',
|
|
34
34
|
apply: 'serve',
|
|
35
35
|
configureServer(server) {
|
|
36
36
|
console.info('[fullstack-ws-watchdog] active');
|
|
37
|
-
if (simulateZombie) {
|
|
38
|
-
console.warn('[fullstack-ws-watchdog] simulateZombie 已启用,pong 将不会回应。' +
|
|
39
|
-
'此模式仅用于测试,生产环境必须关闭。');
|
|
40
|
-
}
|
|
41
37
|
server.ws.on(pingEvent, (data, client) => {
|
|
42
|
-
if (simulateZombie)
|
|
43
|
-
return;
|
|
44
38
|
if (typeof data?.t !== 'number')
|
|
45
39
|
return;
|
|
46
40
|
client.send(pongEvent, { echo: data.t });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ws-watchdog-plugin.js","sourceRoot":"","sources":["../../src/vite-plugins/ws-watchdog-plugin.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;
|
|
1
|
+
{"version":3,"file":"ws-watchdog-plugin.js","sourceRoot":"","sources":["../../src/vite-plugins/ws-watchdog-plugin.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;AAmCH,wDA0EC;AA3GD,sDAAyB;AACzB,0DAA6B;AAG7B,MAAM,mBAAmB,GAAG,kBAAkB,CAAC;AAE/C,8CAA8C;AAC9C,MAAM,yBAAyB,GAAG;IAChC,mBAAI,CAAC,OAAO,CAAC,SAAS,EAAE,0CAA0C,CAAC;IACnE,mBAAI,CAAC,OAAO,CAAC,SAAS,EAAE,mCAAmC,CAAC;CAC7D,CAAC;AAEF,SAAS,oBAAoB;IAC3B,KAAK,MAAM,CAAC,IAAI,yBAAyB,EAAE,CAAC;QAC1C,IAAI,iBAAE,CAAC,UAAU,CAAC,CAAC,CAAC;YAAE,OAAO,CAAC,CAAC;IACjC,CAAC;IACD,OAAO,CAAC,KAAK,CACX,mDAAmD,EACnD,yBAAyB,CAC1B,CAAC;IACF,OAAO,IAAI,CAAC;AACd,CAAC;AAYD,SAAgB,sBAAsB,CACpC,UAAmC,EAAE;IAErC,MAAM,EACJ,SAAS,GAAG,kBAAkB,EAC9B,SAAS,GAAG,kBAAkB,EAC9B,cAAc,GAAG,EAAE,GACpB,GAAG,OAAO,CAAC;IACZ,MAAM,YAAY,GAAG,cAAc,GAAG,mBAAmB,CAAC;IAE1D,OAAO;QACL,IAAI,EAAE,uBAAuB;QAC7B,KAAK,EAAE,OAAO;QAEd,eAAe,CAAC,MAAM;YACpB,OAAO,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC;YAE/C,MAAM,CAAC,EAAE,CAAC,EAAE,CACV,SAAS,EACT,CAAC,IAAgC,EAAE,MAAM,EAAE,EAAE;gBAC3C,IAAI,OA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AE,UAAU,CAAC,CAAC;oBAC3C,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gBAChB,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACX,OAAO,CAAC,KAAK,CACX,iDAAiD,EACjD,CAAC,CACF,CAAC;oBACF,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC;oBACrB,GAAG,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;gBAC5B,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;QAED,kBAAkB;YAChB,MAAM,IAAI,GAAwB;gBAChC;oBACE,GAAG,EAAE,QAAQ;oBACb,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,YAAY,EAAE;oBAC5C,QAAQ,EAAE,cAAc;iBACzB;aACF,CAAC;YACF,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC;AAED,kBAAe,sBAAsB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/fullstack-vite-preset",
|
|
3
|
-
"version": "1.0.20-alpha.
|
|
3
|
+
"version": "1.0.20-alpha.4",
|
|
4
4
|
"files": [
|
|
5
5
|
"lib",
|
|
6
6
|
"src/empty.css",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"@babel/parser": "^7.28.0",
|
|
35
35
|
"@babel/traverse": "^7.28.0",
|
|
36
36
|
"@babel/types": "^7.28.2",
|
|
37
|
-
"@lark-apaas/devtool-kits": "
|
|
37
|
+
"@lark-apaas/devtool-kits": "1.2.22-alpha.1",
|
|
38
38
|
"@lark-apaas/styled-jsx": "^1.0.1",
|
|
39
39
|
"@lark-apaas/vite-inspector-plugin": "^1.0.3",
|
|
40
40
|
"@vitejs/plugin-react": "^4.5.0",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
* @property {number} [intervalMs] 默认 5000
|
|
22
22
|
* @property {number} [missThreshold] 默认 2
|
|
23
23
|
* @property {number} [echoFreshnessMs] 默认 15000
|
|
24
|
-
* @property {string} [pingEvent] 默认 '
|
|
25
|
-
* @property {string} [pongEvent] 默认 '
|
|
24
|
+
* @property {string} [pingEvent] 默认 'ws-watchdog:ping'
|
|
25
|
+
* @property {string} [pongEvent] 默认 'ws-watchdog:pong'
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
28
|
/**
|
|
@@ -34,8 +34,8 @@ export function createWatchdog(deps, options = {}) {
|
|
|
34
34
|
const intervalMs = options.intervalMs ?? 5000;
|
|
35
35
|
const missThreshold = options.missThreshold ?? 2;
|
|
36
36
|
const echoFreshnessMs = options.echoFreshnessMs ?? 15000;
|
|
37
|
-
const pingEvent = options.pingEvent ?? '
|
|
38
|
-
const pongEvent = options.pongEvent ?? '
|
|
37
|
+
const pingEvent = options.pingEvent ?? 'ws-watchdog:ping';
|
|
38
|
+
const pongEvent = options.pongEvent ?? 'ws-watchdog:pong';
|
|
39
39
|
|
|
40
40
|
let missed = 0;
|
|
41
41
|
/** @type {'connected' | 'disconnected'} */
|
|
@@ -129,7 +129,7 @@ if (typeof window !== 'undefined' && window.parent !== window) {
|
|
|
129
129
|
(async () => {
|
|
130
130
|
try {
|
|
131
131
|
const { createHotContext } = await import(CLIENT_BASE_PATH + '/@vite/client');
|
|
132
|
-
const hot = createHotContext(CLIENT_BASE_PATH + '/@
|
|
132
|
+
const hot = createHotContext(CLIENT_BASE_PATH + '/@ws-watchdog.js');
|
|
133
133
|
createWatchdog({
|
|
134
134
|
sendCustom: (event, data) => {
|
|
135
135
|
// 断连时 hot.send 可能抛;吞掉即可——missed 已在 onTick 顶部累加。
|