dsh-token-gauge 0.1.2 → 0.1.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.
- package/build.mjs +26 -5
- package/lib/client.mjs +39 -1917
- package/package.json +1 -1
- package/src/client.ts +32 -10
package/build.mjs
CHANGED
|
@@ -1,17 +1,29 @@
|
|
|
1
1
|
// DSH 插件构建脚本:用 esbuild 产出 Host(Node) 与 Client(浏览器) 两个半边。
|
|
2
2
|
// Host: 监听会话用量事件、累计与计费(Node 环境)
|
|
3
|
-
// Client: 侧边栏仪表盘 UI
|
|
4
|
-
//
|
|
5
|
-
//
|
|
3
|
+
// Client: 侧边栏仪表盘 UI(浏览器环境)。
|
|
4
|
+
//
|
|
5
|
+
// 关键契约(稳定版 DSH 0.1.1-rc.x 的 client 加载器 @deepseek-ai/dsh-client-modules):
|
|
6
|
+
// 加载器把 client bundle 作为脚本注入,要求 bundle 在加载时主动调用
|
|
7
|
+
// window.__ModuleLoader__.load({ id: '<包名>', factory: (require) => <module.exports> })
|
|
8
|
+
// 自注册(参考 dsh-better-sidebar 等所有正常插件都是此格式)。factory 内用
|
|
9
|
+
// 运行时提供的 require 取依赖(如 react),从而与运行时 React 共享同一实例。
|
|
10
|
+
// 早期误用 ESM + export 导致「loaded without registering」错误,现已修正为
|
|
11
|
+
// __ModuleLoader__.load 包裹的 CJS。
|
|
12
|
+
//
|
|
13
|
+
// 输出到 lib/index.mjs / lib/client.mjs(未跟踪的新文件名,避免覆盖受版本库
|
|
14
|
+
// 只读覆盖层保护的旧 lib/index.js / lib/client.js)。
|
|
6
15
|
import { build } from 'esbuild'
|
|
7
16
|
import { copyFileSync } from 'node:fs'
|
|
8
17
|
|
|
18
|
+
const PLUGIN_ID = 'dsh-token-gauge'
|
|
19
|
+
|
|
9
20
|
const common = {
|
|
10
21
|
bundle: true,
|
|
11
22
|
sourcemap: false,
|
|
12
23
|
logLevel: 'info',
|
|
13
24
|
}
|
|
14
25
|
|
|
26
|
+
// Host 半边:Node 环境,ESM 即可(webServer 路由)
|
|
15
27
|
await build({
|
|
16
28
|
...common,
|
|
17
29
|
entryPoints: ['src/host.ts'],
|
|
@@ -21,13 +33,22 @@ await build({
|
|
|
21
33
|
target: 'node20',
|
|
22
34
|
})
|
|
23
35
|
|
|
36
|
+
// Client 半边:DSH client-modules 加载器契约 = window.__ModuleLoader__.load 包裹的 CJS
|
|
37
|
+
// react 标为 external,由运行时 require("react") 提供(共享单实例,规避双 React 冲突)。
|
|
24
38
|
await build({
|
|
25
39
|
...common,
|
|
26
40
|
entryPoints: ['src/client.ts'],
|
|
27
41
|
outfile: 'lib/client.mjs',
|
|
28
42
|
platform: 'browser',
|
|
29
|
-
format: '
|
|
43
|
+
format: 'cjs',
|
|
30
44
|
target: 'es2020',
|
|
45
|
+
external: ['react', 'react-dom', 'react/jsx-runtime'],
|
|
46
|
+
banner: {
|
|
47
|
+
js: `window.__ModuleLoader__.load({ id: "${PLUGIN_ID}", factory: function(require){ var module = { exports: {} }; var exports = module.exports;`,
|
|
48
|
+
},
|
|
49
|
+
footer: {
|
|
50
|
+
js: `; return module.exports; } });`,
|
|
51
|
+
},
|
|
31
52
|
})
|
|
32
53
|
|
|
33
54
|
// 同步市场元数据文件
|
|
@@ -37,4 +58,4 @@ try {
|
|
|
37
58
|
/* 非必需 */
|
|
38
59
|
}
|
|
39
60
|
|
|
40
|
-
console.log('[dsh-token-gauge] build done -> lib/index.mjs (host), lib/client.mjs (client)')
|
|
61
|
+
console.log('[dsh-token-gauge] build done -> lib/index.mjs (host), lib/client.mjs (client, __ModuleLoader__.load format)')
|