dsh-feishu-lark-notify 0.29.0 → 0.29.1
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/CHANGELOG.md +23 -0
- package/README.md +16 -0
- package/README.zh.md +16 -0
- package/docs/README.md +1 -0
- package/docs/install-from-discover.md +87 -0
- package/lib/index.js +1 -1
- package/market/icons/feishu.svg +9 -0
- package/market/index.json +137 -0
- package/market/sources.json +28 -0
- package/package.json +10 -3
- package/scripts/gen-market.mjs +210 -0
- package/scripts/validate-market.mjs +264 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,29 @@ All notable changes to this project are documented here. The format follows
|
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
|
|
5
5
|
[Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [0.29.1] — 未发布
|
|
8
|
+
|
|
9
|
+
> 只改「怎么装」和元数据,不动插件行为。
|
|
10
|
+
|
|
11
|
+
### 新增
|
|
12
|
+
|
|
13
|
+
- **插件索引(「发现」页可装)**:`market/index.json`(DSH 索引 format 1)+ `market/icons/feishu.svg`。
|
|
14
|
+
DSH 不内置索引源,用户加一条
|
|
15
|
+
`https://cdn.jsdelivr.net/npm/dsh-feishu-lark-notify@latest/market/index.json` 就能在**发现**页点装,
|
|
16
|
+
不用敲 `dsh plugin add`。
|
|
17
|
+
- `scripts/gen-market.mjs`:从 `market/sources.json` + npm registry 生成,只列**未弃用**且声明了
|
|
18
|
+
`dsh.bundle` 的版本(`0.0.0-stage` 没有 bundle、`0.28.1` 已弃用,都不列)。
|
|
19
|
+
- `scripts/validate-market.mjs`:结构检查 + 调用 DSH 自带的 `@deepseek-ai/dsh-plugin-market-index`
|
|
20
|
+
跑 `parseMarketIndex`,与「发现」页同一份规则;CI 里没有 DSH 时自动跳过语义层。
|
|
21
|
+
- npm scripts:`market:gen` / `market:check`。
|
|
22
|
+
- **`engines.dsh`**:声明 `>=0.2.0-rc.2`。以前只有 `engines.node`,且没有 peer 依赖,等于任何 DSH 版本都放行;
|
|
23
|
+
现在装到不兼容的宿主上会在安装阶段被明确拒绝。
|
|
24
|
+
|
|
25
|
+
### 文档
|
|
26
|
+
|
|
27
|
+
- 新增 [从「发现」页安装](docs/install-from-discover.md),README 中英双版各加一节。
|
|
28
|
+
- `homepage` 指向 quickstart(npm 页面的 Homepage 直接落到安装步骤)。
|
|
29
|
+
|
|
7
30
|
## [0.29.0] — 2026-11-25
|
|
8
31
|
|
|
9
32
|
> 从这一版开始,飞书里几乎不用回电脑:卡片上能点按钮、能新建会话(自定标题与分组)、
|
package/README.md
CHANGED
|
@@ -98,6 +98,22 @@ Then mount it in the profile with `name` set to the package name:
|
|
|
98
98
|
The bundled `cordis.patch.yml` only carries Feishu defaults — the other channels are no longer written
|
|
99
99
|
as empty shells.
|
|
100
100
|
|
|
101
|
+
### From the Discover page (plugin index)
|
|
102
|
+
|
|
103
|
+
Same package, no CLI. DSH ships no index source, so add this one once:
|
|
104
|
+
|
|
105
|
+
1. **Plugins → Experimental plugins → Custom plugin indexes** → switch on. A **Discover** tab appears.
|
|
106
|
+
2. **Discover → Add index source** → paste:
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
https://cdn.jsdelivr.net/npm/dsh-feishu-lark-notify@latest/market/index.json
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
3. Press **Install**; the confirmation must read `dsh-feishu-lark-notify@<version>`.
|
|
113
|
+
|
|
114
|
+
That replaces the install step only — configuration is identical to the rest of this page.
|
|
115
|
+
How the index is built and checked: [install from Discover](docs/install-from-discover.md).
|
|
116
|
+
|
|
101
117
|
### From a `.tgz` package (offline / air-gapped)
|
|
102
118
|
|
|
103
119
|
```powershell
|
package/README.zh.md
CHANGED
|
@@ -95,6 +95,22 @@ dsh plugin --profile desktop add dsh-feishu-lark-notify
|
|
|
95
95
|
|
|
96
96
|
包自带的 `cordis.patch.yml` 只包含**飞书这一路**的默认配置(其余渠道不再写成空壳)。
|
|
97
97
|
|
|
98
|
+
### 从「发现」页安装(插件索引)
|
|
99
|
+
|
|
100
|
+
同一个包,不用敲命令。DSH 不内置任何索引源,所以先加这一个:
|
|
101
|
+
|
|
102
|
+
1. **插件 → 实验性插件 → 自定义插件索引** → 打开开关,旁边会出现**发现**标签。
|
|
103
|
+
2. **发现 → 添加索引源** → 粘贴:
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
https://cdn.jsdelivr.net/npm/dsh-feishu-lark-notify@latest/market/index.json
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
3. 点**安装**;确认框里必须显示 `dsh-feishu-lark-notify@<版本>`。
|
|
110
|
+
|
|
111
|
+
这一步只替代「装」,配置和本文其余部分完全一样。
|
|
112
|
+
索引怎么生成、怎么校验:[从发现页安装](docs/install-from-discover.md)。
|
|
113
|
+
|
|
98
114
|
### 拿到 `.tgz` 包(离线 / 内网)
|
|
99
115
|
|
|
100
116
|
```powershell
|
package/docs/README.md
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
| 我想… | 看这篇 |
|
|
6
6
|
|---|---|
|
|
7
7
|
| 第一次装、想尽快收到一条通知 | [从零配置(quickstart)](quickstart.md) |
|
|
8
|
+
| 不想敲命令,想在插件页点两下装 | [从「发现」页安装](install-from-discover.md) |
|
|
8
9
|
| **装完发现没反应,想知道到底缺什么** | 先跑 `npm run doctor`,再查 [排错](troubleshooting.md) |
|
|
9
10
|
| 查某个字段 / 环境变量到底叫什么、默认值多少 | [配置项参考](config-reference.md)(**自动生成**,与代码同步) |
|
|
10
11
|
| 各平台怎么拿 webhook / token | [渠道接入](channels.md) |
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# 从「发现」页安装(插件索引)
|
|
2
|
+
|
|
3
|
+
不想记 `dsh plugin --profile … add …`,也不想手改 profile?DSH 的**插件索引**就是给这条路准备的:
|
|
4
|
+
一个 JSON 文件,DSH 读它,把可装的插件画成卡片,你点「安装」。
|
|
5
|
+
|
|
6
|
+
这一步只是换一种装法。装完之后该配的还是要配——接着看 [从零配置](quickstart.md) 或直接打开
|
|
7
|
+
`/plugins/feishu-notify` 配置页。
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## 三步装完
|
|
12
|
+
|
|
13
|
+
1. 打开 **插件** 页 → **实验性插件** 下找到 **自定义插件索引** → 打开开关。
|
|
14
|
+
开关一开,**已安装** 旁边会出现 **发现** 标签页。
|
|
15
|
+
2. 进 **发现** → **添加索引源** → 粘贴下面的地址。
|
|
16
|
+
3. 卡片上点 **安装**,确认框里应该显示 `dsh-feishu-lark-notify@<版本>`。
|
|
17
|
+
|
|
18
|
+
| 索引地址 | 什么时候用 |
|
|
19
|
+
|---|---|
|
|
20
|
+
| `https://cdn.jsdelivr.net/npm/dsh-feishu-lark-notify@latest/market/index.json` | 现在就能用(随 npm 包发布) |
|
|
21
|
+
| `https://unpkg.com/dsh-feishu-lark-notify@latest/market/index.json` | 同一个文件的备用 CDN,jsDelivr 抽风时换这个 |
|
|
22
|
+
|
|
23
|
+
索引源属于当前 profile,换 profile 要再加一次。DSH **不内置任何索引源**,所以第一次一定是手动加。
|
|
24
|
+
|
|
25
|
+
## 想自己托管索引时,主机只有一个硬要求
|
|
26
|
+
|
|
27
|
+
DSH 对索引地址的要求是:**`http(s)`、返回 2xx、且不经过重定向**(重定向会被直接拒绝,
|
|
28
|
+
不会跟到最终地址)。满足这条的静态主机都行,不限于某一家:
|
|
29
|
+
|
|
30
|
+
| 主机 | 能不能用 | 说明 |
|
|
31
|
+
|---|---|---|
|
|
32
|
+
| jsDelivr / unpkg(从 npm 包取) | ✅ 200 直出 | 零运维;索引更新要跟一次 npm 发版 |
|
|
33
|
+
| GitHub Pages / GitLab Pages | ✅ 200 直出 | 索引可以独立于发版更新;国内访问 github.io 偏慢 |
|
|
34
|
+
| 对象存储(OSS / COS / 七牛)公开读 + 默认域名 | ✅ 200 直出 | 国内快;按量几块钱一个月 |
|
|
35
|
+
| **Gitee 仓库 raw** | ❌ | `gitee.com/<u>/<r>/raw/<branch>/<file>` 返回 **302** 跳到
|
|
36
|
+
`raw.giteeusercontent.com/…?signature=…`,签名每次不同、无法作为固定地址配置 |
|
|
37
|
+
| 任何带重定向的 CDN / 短链 | ❌ | 同理被拒 |
|
|
38
|
+
|
|
39
|
+
所以 Gitee 适合放源码,不适合当索引主机——**不是 GitHub 专属,是"不重定向"专属**。
|
|
40
|
+
|
|
41
|
+
## 这个索引里有什么
|
|
42
|
+
|
|
43
|
+
索引文件本身在仓库的 `market/index.json`,由 `market/sources.json` 加 npm registry 生成:
|
|
44
|
+
|
|
45
|
+
- 只列**未弃用、且声明了 `dsh.bundle`** 的版本(所以 `0.0.0-stage` 和已弃用的 `0.28.1` 不在里面);
|
|
46
|
+
- 每个版本带精确的 `publishTimestamp`(Unix 秒)和 `source.type = npm`;
|
|
47
|
+
- 装了 `engines.dsh` 的版本会带上兼容范围,DSH 安装前会再检查一次;
|
|
48
|
+
- 图标是相对路径 `icons/feishu.svg`,按索引 URL 解析。
|
|
49
|
+
|
|
50
|
+
改完 `market/sources.json` 之后:
|
|
51
|
+
|
|
52
|
+
```powershell
|
|
53
|
+
npm run market:gen # 重新生成 market/index.json
|
|
54
|
+
npm run market:check # 用 DSH 自带的校验器验一遍
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`market:check` 在本机装了 DSH 时会直接调用 DSH 的
|
|
58
|
+
`@deepseek-ai/dsh-plugin-market-index`——和「发现」页用的是同一份规则,通过了就是真能装。
|
|
59
|
+
在 CI 里(没有 DSH)它会自动跳过语义层,只跑结构检查。
|
|
60
|
+
|
|
61
|
+
> 注意:Desktop 的 DSH 装在 `app.asar` 里,普通 `node` 读不了。
|
|
62
|
+
> 本机手动跑语义层时用 Electron 当 node:
|
|
63
|
+
>
|
|
64
|
+
> ```powershell
|
|
65
|
+
> $env:ELECTRON_RUN_AS_NODE = '1'
|
|
66
|
+
> & $env:DSH_NODE_EXECUTABLE scripts/validate-market.mjs
|
|
67
|
+
> ```
|
|
68
|
+
|
|
69
|
+
## 安全边界
|
|
70
|
+
|
|
71
|
+
索引是第三方内容。DSH 只校验**格式**,不校验里面的名字、作者、图标和来源声明,
|
|
72
|
+
也不校验版本号与包是否真的一致。所以:
|
|
73
|
+
|
|
74
|
+
- 只添加你信任的索引源;
|
|
75
|
+
- 安装前看一眼确认框里的来源(这里应该是 npm 上的 `dsh-feishu-lark-notify`);
|
|
76
|
+
- 索引走 `http:` 时,网络路径上的任何人都能改它——用 `https:`。
|
|
77
|
+
|
|
78
|
+
## 装不上时先看这三条
|
|
79
|
+
|
|
80
|
+
| 现象 | 原因 |
|
|
81
|
+
|---|---|
|
|
82
|
+
| 插件页没有「发现」标签 | 「自定义插件索引」这个实验性开关没开 |
|
|
83
|
+
| 「添加索引源」报错 | URL 必须是 `http(s)`,且不能带用户名、密码或 `#` 片段;同一 URL 不能加两次 |
|
|
84
|
+
| 索引源下面显示一串错误 | 索引被拒了,原因后面跟着 JSON 路径(例如 `$.plugins[0].versions[0].publishTimestamp`),多半是时间戳不是整数秒 |
|
|
85
|
+
| 卡片显示「无兼容版本」 | 该版本 `engines.dsh` 与当前 DSH 版本不匹配;退回去用 `dsh plugin add` 装旧版本,或升级 DSH |
|
|
86
|
+
|
|
87
|
+
更完整的排错在 [故障排查](troubleshooting.md)。
|
package/lib/index.js
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64" role="img" aria-label="dsh-feishu-lark-notify">
|
|
2
|
+
<title>dsh-feishu-lark-notify</title>
|
|
3
|
+
<rect width="64" height="64" rx="14" fill="#3370FF"/>
|
|
4
|
+
<path d="M22 42h28a6 6 0 0 0 6-6V20a6 6 0 0 0-6-6H20a6 6 0 0 0-6 6v16a6 6 0 0 0 6 6h2v10l8-10z" fill="#FFFFFF"/>
|
|
5
|
+
<rect x="20" y="21" width="26" height="4" rx="2" fill="#3370FF"/>
|
|
6
|
+
<rect x="20" y="28" width="19" height="4" rx="2" fill="#3370FF"/>
|
|
7
|
+
<rect x="20" y="35" width="12" height="4" rx="2" fill="#3370FF"/>
|
|
8
|
+
<circle cx="49" cy="15" r="8.5" fill="#FF5C5C" stroke="#FFFFFF" stroke-width="3"/>
|
|
9
|
+
</svg>
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
{
|
|
2
|
+
"format": 1,
|
|
3
|
+
"title": {
|
|
4
|
+
"en": "zy230252 DSH plugins",
|
|
5
|
+
"zh": "zy230252 的 DSH 插件"
|
|
6
|
+
},
|
|
7
|
+
"description": {
|
|
8
|
+
"en": "Plugins by zy230252 for DeepSeek Harness. Feishu / Lark notifications first; more to come.",
|
|
9
|
+
"zh": "zy230252 给 DeepSeek Harness 写的插件。目前是飞书通知,以后新的也往这张表里加。"
|
|
10
|
+
},
|
|
11
|
+
"metadata": {
|
|
12
|
+
"categories": {
|
|
13
|
+
"notify": {
|
|
14
|
+
"title": {
|
|
15
|
+
"en": "Notifications",
|
|
16
|
+
"zh": "通知"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"sortKeys": {
|
|
21
|
+
"npm_weekly_downloads": {
|
|
22
|
+
"title": {
|
|
23
|
+
"en": "Weekly downloads",
|
|
24
|
+
"zh": "周下载"
|
|
25
|
+
},
|
|
26
|
+
"order": "desc"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"plugins": [
|
|
31
|
+
{
|
|
32
|
+
"name": "dsh-feishu-lark-notify",
|
|
33
|
+
"title": {
|
|
34
|
+
"en": "Feishu / Lark notify",
|
|
35
|
+
"zh": "飞书通知"
|
|
36
|
+
},
|
|
37
|
+
"description": {
|
|
38
|
+
"en": "Push turn results, approvals and questions to Feishu; approve, answer and command sessions from the chat. Eight channels, built-in settings page.",
|
|
39
|
+
"zh": "把 DSH 的任务完成 / 审批 / 提问推到飞书,能在飞书里点允许、答问题、按标题把指令交给指定会话。八种渠道,自带配置页。"
|
|
40
|
+
},
|
|
41
|
+
"icon": "icons/feishu.svg",
|
|
42
|
+
"author": "zy230252",
|
|
43
|
+
"homepage": "https://gitee.com/zy230252/dsh-feishu-notify/blob/main/docs/quickstart.md",
|
|
44
|
+
"repository": {
|
|
45
|
+
"url": "https://gitee.com/zy230252/dsh-feishu-notify"
|
|
46
|
+
},
|
|
47
|
+
"metadata": {
|
|
48
|
+
"category": "notify",
|
|
49
|
+
"sortKeys": {
|
|
50
|
+
"npm_weekly_downloads": 331
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"versions": [
|
|
54
|
+
{
|
|
55
|
+
"version": "0.29.1",
|
|
56
|
+
"publishTimestamp": 1795870845,
|
|
57
|
+
"source": {
|
|
58
|
+
"type": "npm"
|
|
59
|
+
},
|
|
60
|
+
"engines": {
|
|
61
|
+
"dsh": ">=0.2.0-rc.2"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"version": "0.29.0",
|
|
66
|
+
"publishTimestamp": 1795600259,
|
|
67
|
+
"source": {
|
|
68
|
+
"type": "npm"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"version": "0.28.0",
|
|
73
|
+
"publishTimestamp": 1794715676,
|
|
74
|
+
"source": {
|
|
75
|
+
"type": "npm"
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"version": "0.27.0",
|
|
80
|
+
"publishTimestamp": 1794541305,
|
|
81
|
+
"source": {
|
|
82
|
+
"type": "npm"
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"version": "0.26.2",
|
|
87
|
+
"publishTimestamp": 1794540676,
|
|
88
|
+
"source": {
|
|
89
|
+
"type": "npm"
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"version": "0.26.1",
|
|
94
|
+
"publishTimestamp": 1794531526,
|
|
95
|
+
"source": {
|
|
96
|
+
"type": "npm"
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
"version": "0.26.0",
|
|
101
|
+
"publishTimestamp": 1794531110,
|
|
102
|
+
"source": {
|
|
103
|
+
"type": "npm"
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"version": "0.25.2",
|
|
108
|
+
"publishTimestamp": 1794474213,
|
|
109
|
+
"source": {
|
|
110
|
+
"type": "npm"
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"version": "0.25.1",
|
|
115
|
+
"publishTimestamp": 1794465737,
|
|
116
|
+
"source": {
|
|
117
|
+
"type": "npm"
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"version": "0.25.0",
|
|
122
|
+
"publishTimestamp": 1794464816,
|
|
123
|
+
"source": {
|
|
124
|
+
"type": "npm"
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
"version": "0.21.1",
|
|
129
|
+
"publishTimestamp": 1794209417,
|
|
130
|
+
"source": {
|
|
131
|
+
"type": "npm"
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
]
|
|
135
|
+
}
|
|
136
|
+
]
|
|
137
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"title": { "en": "zy230252 DSH plugins", "zh": "zy230252 的 DSH 插件" },
|
|
3
|
+
"description": {
|
|
4
|
+
"en": "Plugins by zy230252 for DeepSeek Harness. Feishu / Lark notifications first; more to come.",
|
|
5
|
+
"zh": "zy230252 给 DeepSeek Harness 写的插件。目前是飞书通知,以后新的也往这张表里加。"
|
|
6
|
+
},
|
|
7
|
+
"categories": {
|
|
8
|
+
"notify": { "title": { "en": "Notifications", "zh": "通知" } }
|
|
9
|
+
},
|
|
10
|
+
"sortKeys": {
|
|
11
|
+
"npm_weekly_downloads": { "title": { "en": "Weekly downloads", "zh": "周下载" }, "order": "desc" }
|
|
12
|
+
},
|
|
13
|
+
"plugins": [
|
|
14
|
+
{
|
|
15
|
+
"name": "dsh-feishu-lark-notify",
|
|
16
|
+
"title": { "en": "Feishu / Lark notify", "zh": "飞书通知" },
|
|
17
|
+
"description": {
|
|
18
|
+
"en": "Push turn results, approvals and questions to Feishu; approve, answer and command sessions from the chat. Eight channels, built-in settings page.",
|
|
19
|
+
"zh": "把 DSH 的任务完成 / 审批 / 提问推到飞书,能在飞书里点允许、答问题、按标题把指令交给指定会话。八种渠道,自带配置页。"
|
|
20
|
+
},
|
|
21
|
+
"icon": "icons/feishu.svg",
|
|
22
|
+
"author": "zy230252",
|
|
23
|
+
"homepage": "https://gitee.com/zy230252/dsh-feishu-notify/blob/main/docs/quickstart.md",
|
|
24
|
+
"repository": { "url": "https://gitee.com/zy230252/dsh-feishu-notify" },
|
|
25
|
+
"category": "notify"
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-feishu-lark-notify",
|
|
3
|
-
"version": "0.29.
|
|
3
|
+
"version": "0.29.1",
|
|
4
4
|
"description": "把 DSH 的任务完成 / 需要你处理的通知推到飞书(Lark):在飞书里点审批、答选择题、按标题把指令交给指定会话,也能收发图片和文件。自带可视化配置页。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -14,7 +14,10 @@
|
|
|
14
14
|
"cordis.patch.yml",
|
|
15
15
|
"docs",
|
|
16
16
|
"examples",
|
|
17
|
+
"market",
|
|
17
18
|
".env.example",
|
|
19
|
+
"scripts/gen-market.mjs",
|
|
20
|
+
"scripts/validate-market.mjs",
|
|
18
21
|
"scripts/gen-docs.mjs",
|
|
19
22
|
"scripts/doctor.mjs",
|
|
20
23
|
"scripts/send-file.mjs",
|
|
@@ -37,7 +40,8 @@
|
|
|
37
40
|
],
|
|
38
41
|
"license": "MIT",
|
|
39
42
|
"engines": {
|
|
40
|
-
"node": ">=20"
|
|
43
|
+
"node": ">=20",
|
|
44
|
+
"dsh": ">=0.2.0-rc.2"
|
|
41
45
|
},
|
|
42
46
|
"dsh": {
|
|
43
47
|
"bundle": {
|
|
@@ -48,6 +52,9 @@
|
|
|
48
52
|
"test": "node --test \"test/*.test.mjs\"",
|
|
49
53
|
"test:watch": "node --test --watch \"test/*.test.mjs\"",
|
|
50
54
|
"docs": "node scripts/gen-docs.mjs",
|
|
55
|
+
"market:gen": "node scripts/gen-market.mjs",
|
|
56
|
+
"market:check": "node scripts/validate-market.mjs",
|
|
57
|
+
"prepublishOnly": "node scripts/gen-market.mjs --with-local && node scripts/validate-market.mjs",
|
|
51
58
|
"send-file": "node scripts/send-file.mjs",
|
|
52
59
|
"dist": "node scripts/dist.mjs",
|
|
53
60
|
"doctor": "node scripts/doctor.mjs"
|
|
@@ -59,7 +66,7 @@
|
|
|
59
66
|
"type": "git",
|
|
60
67
|
"url": "git+https://gitee.com/zy230252/dsh-feishu-notify.git"
|
|
61
68
|
},
|
|
62
|
-
"homepage": "https://gitee.com/zy230252/dsh-feishu-notify",
|
|
69
|
+
"homepage": "https://gitee.com/zy230252/dsh-feishu-notify/blob/main/docs/quickstart.md",
|
|
63
70
|
"bugs": {
|
|
64
71
|
"url": "https://gitee.com/zy230252/dsh-feishu-notify/issues"
|
|
65
72
|
},
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* 从 market/sources.json + npm registry 生成 market/index.json(DSH 插件索引 format 1)。
|
|
4
|
+
*
|
|
5
|
+
* node scripts/gen-market.mjs # 生成
|
|
6
|
+
* node scripts/gen-market.mjs --check # 只比对,不写文件(CI 用)
|
|
7
|
+
*
|
|
8
|
+
* 为什么要有这脚本:索引里每个版本都要一个精确的 publishTimestamp(Unix 秒),
|
|
9
|
+
* 手抄必然出错,而 DSH 只要有一条不合规就整个索引拒收。
|
|
10
|
+
* 生成后一定跑 scripts/validate-market.mjs —— 那里用的是 DSH 自带的校验器。
|
|
11
|
+
*
|
|
12
|
+
* 只读网络、只写 market/index.json,从不安装或执行任何包的代码。
|
|
13
|
+
*/
|
|
14
|
+
import fs from 'node:fs/promises'
|
|
15
|
+
import path from 'node:path'
|
|
16
|
+
import { fileURLToPath } from 'node:url'
|
|
17
|
+
|
|
18
|
+
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
|
|
19
|
+
const MARKET = path.join(ROOT, 'market')
|
|
20
|
+
const SOURCES = path.join(MARKET, 'sources.json')
|
|
21
|
+
const OUTPUT = path.join(MARKET, 'index.json')
|
|
22
|
+
const REGISTRY = 'https://registry.npmjs.org'
|
|
23
|
+
const DOWNLOADS = 'https://api.npmjs.org/downloads/point/last-week'
|
|
24
|
+
const CHECK_ONLY = process.argv.includes('--check')
|
|
25
|
+
/**
|
|
26
|
+
* --with-local:把仓库当前版本也写进索引。
|
|
27
|
+
*
|
|
28
|
+
* 为什么需要它:索引跟着 npm 包一起发,但发版那一刻 registry 上还没有这个版本,
|
|
29
|
+
* 于是包里的索引永远滞后一版(发 0.29.1 时只能列到 0.29.0)。npm publish 会先跑
|
|
30
|
+
* prepublishOnly,这一步用 --with-local 把即将发布的版本补进索引,包里那份就正确了。
|
|
31
|
+
*
|
|
32
|
+
* 只在 prepublishOnly 里用:平时(含 CI)跑不带这个 flag,绝不凭空列出 registry 上没有的版本。
|
|
33
|
+
*/
|
|
34
|
+
const WITH_LOCAL = process.argv.includes('--with-local')
|
|
35
|
+
const PKG = JSON.parse(await fs.readFile(path.join(ROOT, 'package.json'), 'utf8'))
|
|
36
|
+
|
|
37
|
+
const UA = 'dsh-market-index-generator (+https://gitee.com/zy230252/dsh-feishu-notify)'
|
|
38
|
+
|
|
39
|
+
async function getJson(url, timeoutMs = 25000) {
|
|
40
|
+
const controller = new AbortController()
|
|
41
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs)
|
|
42
|
+
try {
|
|
43
|
+
const res = await fetch(url, { signal: controller.signal, headers: { 'user-agent': UA } })
|
|
44
|
+
if (!res.ok) throw new Error(`${res.status} ${res.statusText} — ${url}`)
|
|
45
|
+
return await res.json()
|
|
46
|
+
} finally {
|
|
47
|
+
clearTimeout(timer)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** SemVer 比较:足够处理本仓库用到的 x.y.z 与带 prerelease 的形式。 */
|
|
52
|
+
function compareVersions(a, b) {
|
|
53
|
+
const split = (v) => {
|
|
54
|
+
const [core, pre = ''] = v.split('+')[0].split('-', 2)
|
|
55
|
+
return [core.split('.').map((n) => Number(n) || 0), pre ? pre.split('.') : []]
|
|
56
|
+
}
|
|
57
|
+
const [ac, ap] = split(a)
|
|
58
|
+
const [bc, bp] = split(b)
|
|
59
|
+
for (let i = 0; i < 3; i += 1) {
|
|
60
|
+
if (ac[i] !== bc[i]) return ac[i] - bc[i]
|
|
61
|
+
}
|
|
62
|
+
if (!ap.length && !bp.length) return 0
|
|
63
|
+
if (!ap.length) return 1
|
|
64
|
+
if (!bp.length) return -1
|
|
65
|
+
for (let i = 0; i < Math.max(ap.length, bp.length); i += 1) {
|
|
66
|
+
const x = ap[i]
|
|
67
|
+
const y = bp[i]
|
|
68
|
+
if (x === undefined) return -1
|
|
69
|
+
if (y === undefined) return 1
|
|
70
|
+
const nx = /^\d+$/.test(x)
|
|
71
|
+
const ny = /^\d+$/.test(y)
|
|
72
|
+
if (nx && ny && Number(x) !== Number(y)) return Number(x) - Number(y)
|
|
73
|
+
if (nx !== ny) return nx ? -1 : 1
|
|
74
|
+
if (x !== y) return x < y ? -1 : 1
|
|
75
|
+
}
|
|
76
|
+
return 0
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** 一个包在索引里的版本:未弃用、未设私有、且声明了 dsh.bundle。 */
|
|
80
|
+
function collectVersions(doc, entry) {
|
|
81
|
+
const times = doc.time ?? {}
|
|
82
|
+
const out = []
|
|
83
|
+
for (const [version, manifest] of Object.entries(doc.versions ?? {})) {
|
|
84
|
+
if (!manifest || typeof manifest !== 'object') continue
|
|
85
|
+
if (manifest.deprecated) continue
|
|
86
|
+
if (manifest.private === true) continue
|
|
87
|
+
if (!manifest.dsh?.bundle) continue
|
|
88
|
+
if (entry.includePrerelease === false && /-/.test(version.replace(/^v/, ''))) continue
|
|
89
|
+
const iso = times[version]
|
|
90
|
+
const published = iso ? Math.floor(Date.parse(iso) / 1000) : 0
|
|
91
|
+
if (!Number.isInteger(published) || published <= 0) continue
|
|
92
|
+
const record = {
|
|
93
|
+
version,
|
|
94
|
+
publishTimestamp: published,
|
|
95
|
+
source: { type: 'npm' },
|
|
96
|
+
}
|
|
97
|
+
// 索引里的 engines.dsh 必须与包自身一致:包没声明就不写,别替它承诺兼容性。
|
|
98
|
+
const range = manifest.engines?.dsh
|
|
99
|
+
if (typeof range === 'string' && range.trim()) record.engines = { dsh: range.trim() }
|
|
100
|
+
out.push(record)
|
|
101
|
+
}
|
|
102
|
+
out.sort((a, b) => compareVersions(b.version, a.version))
|
|
103
|
+
return out
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async function weeklyDownloads(name) {
|
|
107
|
+
try {
|
|
108
|
+
const doc = await getJson(`${DOWNLOADS}/${name.startsWith('@') ? name.replace('/', '%2F') : name}`)
|
|
109
|
+
return Number.isFinite(doc?.downloads) ? doc.downloads : null
|
|
110
|
+
} catch (err) {
|
|
111
|
+
process.stderr.write(` ! 周下载量取不到(${name}):${err.message}\n`)
|
|
112
|
+
return null
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function buildPlugin(entry, doc, downloads) {
|
|
117
|
+
const highest = Object.entries(doc.versions ?? {})
|
|
118
|
+
.map(([v, m]) => [v, m])
|
|
119
|
+
.filter(([, m]) => m && !m.deprecated)
|
|
120
|
+
.sort((a, b) => compareVersions(b[0], a[0]))[0]?.[1]
|
|
121
|
+
const versions = collectVersions(doc, entry)
|
|
122
|
+
if (!versions.length) throw new Error(`${entry.name}: registry 里没有声明 dsh.bundle 的可发布版本`)
|
|
123
|
+
|
|
124
|
+
const plugin = { name: entry.name }
|
|
125
|
+
const title = entry.title ?? highest?.dsh?.bundle?.title
|
|
126
|
+
const description = entry.description ?? highest?.description
|
|
127
|
+
if (title) plugin.title = title
|
|
128
|
+
if (description) plugin.description = description
|
|
129
|
+
if (entry.icon) plugin.icon = entry.icon
|
|
130
|
+
plugin.author = entry.author ?? highest?.author?.name ?? 'zy230252'
|
|
131
|
+
if (entry.homepage ?? highest?.homepage) plugin.homepage = entry.homepage ?? highest.homepage
|
|
132
|
+
if (entry.repository ?? highest?.repository) {
|
|
133
|
+
const repo = entry.repository ?? { url: `https://github.com/${String(highest.repository.url).replace(/^git\+|\.git$|^github:/g, '')}` }
|
|
134
|
+
plugin.repository = repo
|
|
135
|
+
}
|
|
136
|
+
const metadata = {}
|
|
137
|
+
if (entry.category) metadata.category = entry.category
|
|
138
|
+
if (Array.isArray(entry.labels) && entry.labels.length) metadata.labels = entry.labels
|
|
139
|
+
const sortKeys = { ...(entry.sortKeys ?? {}) }
|
|
140
|
+
if (downloads !== null) sortKeys.npm_weekly_downloads = downloads
|
|
141
|
+
if (Object.keys(sortKeys).length) metadata.sortKeys = sortKeys
|
|
142
|
+
if (Object.keys(metadata).length) plugin.metadata = metadata
|
|
143
|
+
plugin.versions = versions
|
|
144
|
+
return plugin
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** --with-local:把仓库当前版本补进索引(仅 prepublishOnly 使用,见上方注释)。 */
|
|
148
|
+
function prependLocalVersion(plugin) {
|
|
149
|
+
if (PKG.name !== plugin.name) return
|
|
150
|
+
if (!PKG.dsh?.bundle) return
|
|
151
|
+
if (!/^\d+\.\d+\.\d+/.test(PKG.version ?? '')) return
|
|
152
|
+
if (plugin.versions.some((v) => v.version === PKG.version)) return
|
|
153
|
+
const record = { version: PKG.version, publishTimestamp: Math.floor(Date.now() / 1000), source: { type: 'npm' } }
|
|
154
|
+
const range = PKG.engines?.dsh
|
|
155
|
+
if (typeof range === 'string' && range.trim()) record.engines = { dsh: range.trim() }
|
|
156
|
+
plugin.versions.unshift(record)
|
|
157
|
+
plugin.versions.sort((a, b) => compareVersions(b.version, a.version))
|
|
158
|
+
process.stdout.write(` 含本地未发布版本 ${PKG.version}(--with-local,随本次发布上线)\n`)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
async function main() {
|
|
162
|
+
const sources = JSON.parse(await fs.readFile(SOURCES, 'utf8'))
|
|
163
|
+
if (!sources.title?.en) throw new Error('sources.json: title 必须带 en(DSH 要求本地化文本对象含 en)')
|
|
164
|
+
if (!Array.isArray(sources.plugins) || !sources.plugins.length) throw new Error('sources.json: plugins 不能为空')
|
|
165
|
+
|
|
166
|
+
const index = { format: 1, title: sources.title }
|
|
167
|
+
if (sources.description) index.description = sources.description
|
|
168
|
+
const metadata = {}
|
|
169
|
+
if (sources.categories && Object.keys(sources.categories).length) metadata.categories = sources.categories
|
|
170
|
+
if (sources.labels && Object.keys(sources.labels).length) metadata.labels = sources.labels
|
|
171
|
+
if (sources.sortKeys && Object.keys(sources.sortKeys).length) metadata.sortKeys = sources.sortKeys
|
|
172
|
+
if (Object.keys(metadata).length) index.metadata = metadata
|
|
173
|
+
|
|
174
|
+
const plugins = []
|
|
175
|
+
for (const entry of sources.plugins) {
|
|
176
|
+
if (!entry?.name) throw new Error('sources.json: 每个插件都要有 name')
|
|
177
|
+
process.stdout.write(`· ${entry.name}\n`)
|
|
178
|
+
const doc = await getJson(`${REGISTRY}/${entry.name.startsWith('@') ? entry.name.replace('/', '%2F') : entry.name}`)
|
|
179
|
+
const downloads = await weeklyDownloads(entry.name)
|
|
180
|
+
const plugin = buildPlugin(entry, doc, downloads)
|
|
181
|
+
if (WITH_LOCAL) prependLocalVersion(plugin)
|
|
182
|
+
process.stdout.write(
|
|
183
|
+
` ${plugin.versions.length} 个版本,最新 ${plugin.versions[0].version}` +
|
|
184
|
+
(downloads === null ? '' : `,周下载 ${downloads}`) +
|
|
185
|
+
'\n',
|
|
186
|
+
)
|
|
187
|
+
plugins.push(plugin)
|
|
188
|
+
}
|
|
189
|
+
index.plugins = plugins
|
|
190
|
+
|
|
191
|
+
const body = `${JSON.stringify(index, null, 2)}\n`
|
|
192
|
+
const previous = await fs.readFile(OUTPUT, 'utf8').catch(() => null)
|
|
193
|
+
if (CHECK_ONLY) {
|
|
194
|
+
if (previous === body) {
|
|
195
|
+
process.stdout.write('index.json 与生成结果一致\n')
|
|
196
|
+
return
|
|
197
|
+
}
|
|
198
|
+
process.stderr.write('index.json 与 registry 现状不一致,请运行 node scripts/gen-market.mjs\n')
|
|
199
|
+
process.exitCode = 1
|
|
200
|
+
return
|
|
201
|
+
}
|
|
202
|
+
if (previous === body) {
|
|
203
|
+
process.stdout.write('index.json 无变化\n')
|
|
204
|
+
return
|
|
205
|
+
}
|
|
206
|
+
await fs.writeFile(OUTPUT, body, 'utf8')
|
|
207
|
+
process.stdout.write(`已写入 ${path.relative(ROOT, OUTPUT)}(${Buffer.byteLength(body)} 字节)\n`)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
await main()
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* 校验 market/index.json 能不能被 DSH 接受。
|
|
4
|
+
*
|
|
5
|
+
* 分两层:
|
|
6
|
+
* 1. 结构层(任何机器都能跑):format / title.en / 版本时间戳 / 降序 / 图标文件存在 / 无 BOM;
|
|
7
|
+
* 2. 语义层(在本机装了 DSH 的地方跑):用 DSH 自带的
|
|
8
|
+
* @deepseek-ai/dsh-plugin-market-index 跑 parseMarketIndex —— 和「发现」页是同一份规则。
|
|
9
|
+
*
|
|
10
|
+
* 因为校验器在 Desktop 的 app.asar 里,普通 node 读不了 asar,必须用 Electron 当 node:
|
|
11
|
+
*
|
|
12
|
+
* $env:ELECTRON_RUN_AS_NODE = '1'
|
|
13
|
+
* & $env:DSH_NODE_EXECUTABLE scripts/validate-market.mjs
|
|
14
|
+
*
|
|
15
|
+
* 没有 DSH 的环境(例如 CI)直接 `node scripts/validate-market.mjs`,语义层会跳过而不是失败。
|
|
16
|
+
*/
|
|
17
|
+
import fs from 'node:fs'
|
|
18
|
+
import path from 'node:path'
|
|
19
|
+
import { createRequire } from 'node:module'
|
|
20
|
+
import { fileURLToPath } from 'node:url'
|
|
21
|
+
|
|
22
|
+
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
|
|
23
|
+
const MARKET = path.join(ROOT, 'market')
|
|
24
|
+
const INDEX_FILE = path.join(MARKET, 'index.json')
|
|
25
|
+
const MAX_INDEX_BYTES = 128 * 1024 * 1024
|
|
26
|
+
const MAX_ICON_BYTES = 32 * 1024
|
|
27
|
+
|
|
28
|
+
const INDEX_URL =
|
|
29
|
+
process.env.DSH_MARKET_INDEX_URL ??
|
|
30
|
+
'https://cdn.jsdelivr.net/npm/dsh-feishu-lark-notify@latest/market/index.json'
|
|
31
|
+
|
|
32
|
+
let failures = 0
|
|
33
|
+
let checks = 0
|
|
34
|
+
|
|
35
|
+
function ok(label, detail = '') {
|
|
36
|
+
checks += 1
|
|
37
|
+
process.stdout.write(` PASS ${label}${detail ? ` — ${detail}` : ''}\n`)
|
|
38
|
+
}
|
|
39
|
+
function bad(label, detail) {
|
|
40
|
+
checks += 1
|
|
41
|
+
failures += 1
|
|
42
|
+
process.stdout.write(` FAIL ${label} — ${detail}\n`)
|
|
43
|
+
}
|
|
44
|
+
function skip(label, detail) {
|
|
45
|
+
process.stdout.write(` SKIP ${label} — ${detail}\n`)
|
|
46
|
+
}
|
|
47
|
+
function expect(cond, label, detail) {
|
|
48
|
+
if (cond) ok(label, detail)
|
|
49
|
+
else bad(label, detail)
|
|
50
|
+
return cond
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function compareVersions(a, b) {
|
|
54
|
+
const strip = (v) => v.split('+')[0].split('-')
|
|
55
|
+
const [ax, ap = ''] = strip(a)
|
|
56
|
+
const [bx, bp = ''] = strip(b)
|
|
57
|
+
const an = ax.split('.').map(Number)
|
|
58
|
+
const bn = bx.split('.').map(Number)
|
|
59
|
+
for (let i = 0; i < 3; i += 1) {
|
|
60
|
+
if ((an[i] ?? 0) !== (bn[i] ?? 0)) return (an[i] ?? 0) - (bn[i] ?? 0)
|
|
61
|
+
}
|
|
62
|
+
if (!ap && !bp) return 0
|
|
63
|
+
if (!ap) return 1
|
|
64
|
+
if (!bp) return -1
|
|
65
|
+
return ap < bp ? -1 : ap > bp ? 1 : 0
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// ---------- 1. 结构层 ----------
|
|
69
|
+
process.stdout.write(`索引文件:${path.relative(ROOT, INDEX_FILE)}\n索引 URL:${INDEX_URL}\n\n[结构]\n`)
|
|
70
|
+
|
|
71
|
+
let raw
|
|
72
|
+
try {
|
|
73
|
+
raw = fs.readFileSync(INDEX_FILE)
|
|
74
|
+
} catch (err) {
|
|
75
|
+
bad('读取 index.json', err.message)
|
|
76
|
+
process.exit(1)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
expect(raw.length > 0, '非空文件', `${raw.length} 字节`)
|
|
80
|
+
expect(raw.length < MAX_INDEX_BYTES, '体积上限', `≤ 128 MiB`)
|
|
81
|
+
expect(!(raw[0] === 0xef && raw[1] === 0xbb && raw[2] === 0xbf), '无 UTF-8 BOM', 'DSH 按严格 UTF-8 解析')
|
|
82
|
+
|
|
83
|
+
let index
|
|
84
|
+
try {
|
|
85
|
+
index = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(raw))
|
|
86
|
+
ok('严格 UTF-8 + JSON 可解析')
|
|
87
|
+
} catch (err) {
|
|
88
|
+
bad('严格 UTF-8 + JSON 可解析', err.message)
|
|
89
|
+
process.exit(1)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf8'))
|
|
93
|
+
expect(index.format === 1, 'format', '= 1')
|
|
94
|
+
expect(typeof index.title?.en === 'string' && index.title.en.length > 0, 'title.en 存在', '本地化对象必须含 en')
|
|
95
|
+
expect(Array.isArray(index.plugins) && index.plugins.length > 0, 'plugins 非空')
|
|
96
|
+
|
|
97
|
+
const categories = Object.keys(index.metadata?.categories ?? {})
|
|
98
|
+
const labels = Object.keys(index.metadata?.labels ?? {})
|
|
99
|
+
const sortKeys = Object.keys(index.metadata?.sortKeys ?? {})
|
|
100
|
+
const seen = new Set()
|
|
101
|
+
|
|
102
|
+
for (const plugin of index.plugins ?? []) {
|
|
103
|
+
const where = `plugins[${plugin.name ?? '?'}]`
|
|
104
|
+
if (!expect(typeof plugin.name === 'string' && plugin.name, `${where}.name`)) continue
|
|
105
|
+
expect(!seen.has(plugin.name), `${where} 名字唯一`)
|
|
106
|
+
seen.add(plugin.name)
|
|
107
|
+
expect(plugin.title === undefined || typeof plugin.title?.en === 'string', `${where}.title.en`)
|
|
108
|
+
|
|
109
|
+
if (plugin.metadata?.category !== undefined) {
|
|
110
|
+
expect(categories.includes(plugin.metadata.category), `${where}.metadata.category 已声明`, plugin.metadata.category)
|
|
111
|
+
}
|
|
112
|
+
for (const label of plugin.metadata?.labels ?? []) {
|
|
113
|
+
expect(labels.includes(label), `${where}.metadata.labels 已声明`, label)
|
|
114
|
+
}
|
|
115
|
+
for (const key of Object.keys(plugin.metadata?.sortKeys ?? {})) {
|
|
116
|
+
expect(sortKeys.includes(key), `${where}.metadata.sortKeys 已声明`, key)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// 图标:内联 data: 或 http(s) 绝对 URL 或相对路径;相对路径必须真的落在 market/ 里
|
|
120
|
+
if (plugin.icon) {
|
|
121
|
+
if (/^data:/.test(plugin.icon)) {
|
|
122
|
+
const payload = plugin.icon.slice(plugin.icon.indexOf(',') + 1)
|
|
123
|
+
expect(Buffer.from(payload, 'base64').length <= MAX_ICON_BYTES, `${where}.icon 内联体积`, '≤ 32 KiB')
|
|
124
|
+
} else if (/^https?:/.test(plugin.icon)) {
|
|
125
|
+
ok(`${where}.icon 绝对 URL`, plugin.icon)
|
|
126
|
+
} else {
|
|
127
|
+
const file = path.join(MARKET, plugin.icon)
|
|
128
|
+
const exists = fs.existsSync(file)
|
|
129
|
+
if (expect(exists, `${where}.icon 文件存在`, plugin.icon)) {
|
|
130
|
+
expect(fs.statSync(file).size <= MAX_ICON_BYTES, `${where}.icon 文件体积`, '≤ 32 KiB')
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const versions = plugin.versions
|
|
136
|
+
if (!expect(Array.isArray(versions) && versions.length > 0, `${where}.versions 非空`)) continue
|
|
137
|
+
for (let i = 0; i < versions.length; i += 1) {
|
|
138
|
+
const v = versions[i]
|
|
139
|
+
const tag = `${where}.versions[${v.version ?? i}]`
|
|
140
|
+
if (!expect(/^\d+\.\d+\.\d+/.test(v.version ?? ''), `${tag}.version 是 SemVer`)) continue
|
|
141
|
+
expect(Number.isInteger(v.publishTimestamp) && v.publishTimestamp > 0, `${tag}.publishTimestamp 整数秒`)
|
|
142
|
+
const source = v.source
|
|
143
|
+
if (expect(source && typeof source.type === 'string', `${tag}.source`)) {
|
|
144
|
+
if (source.type === 'npm') {
|
|
145
|
+
ok(`${tag}.source.type = npm`)
|
|
146
|
+
} else if (source.type === 'git') {
|
|
147
|
+
expect(/^[0-9a-f]{40}$/.test(source.commit ?? ''), `${tag}.source.commit 40 位 sha`)
|
|
148
|
+
expect(/^https:/.test(source.url ?? ''), `${tag}.source.url 是 https`)
|
|
149
|
+
} else {
|
|
150
|
+
bad(`${tag}.source.type`, '只能是 npm 或 git')
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (v.engines !== undefined) {
|
|
154
|
+
expect(typeof v.engines?.dsh === 'string' && v.engines.dsh.trim(), `${tag}.engines.dsh 是范围字符串`)
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
for (let i = 1; i < versions.length; i += 1) {
|
|
158
|
+
if (compareVersions(versions[i - 1].version, versions[i].version) <= 0) {
|
|
159
|
+
bad(`${where}.versions 降序`, `${versions[i - 1].version} 之后是 ${versions[i].version}`)
|
|
160
|
+
break
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
ok(`${where}.versions 降序`)
|
|
164
|
+
|
|
165
|
+
// engines 与包自身一致(只在索引里的版本 == 仓库当前版本时才有意义)
|
|
166
|
+
const same = versions.find((v) => v.version === pkg.version)
|
|
167
|
+
if (same) {
|
|
168
|
+
const inPkg = pkg.engines?.dsh
|
|
169
|
+
if (inPkg && same.engines?.dsh !== inPkg) {
|
|
170
|
+
bad(`${where} engines.dsh 与 package.json 一致`, `索引 ${same.engines?.dsh} / 包 ${inPkg}`)
|
|
171
|
+
} else if (!inPkg && same.engines?.dsh) {
|
|
172
|
+
bad(`${where} engines.dsh 与 package.json 一致`, `package.json 没有 engines.dsh,索引不该声明`)
|
|
173
|
+
} else if (!inPkg) {
|
|
174
|
+
skip(`${where} engines.dsh`, 'package.json 尚未声明 engines.dsh,索引里也不写(下一个版本再带)')
|
|
175
|
+
} else {
|
|
176
|
+
ok(`${where} engines.dsh 与 package.json 一致`, inPkg)
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// ---------- 2. 语义层:DSH 自带校验器 ----------
|
|
182
|
+
function loadValidator() {
|
|
183
|
+
const install = process.env.DSH_INSTALL_DIR
|
|
184
|
+
if (!install) {
|
|
185
|
+
skip('parseMarketIndex', '没有 DSH_INSTALL_DIR;结构层通过即视为合格,语义层请在本机 DSH 环境再跑一次')
|
|
186
|
+
return null
|
|
187
|
+
}
|
|
188
|
+
const validatorDir = path.join(path.dirname(install), 'dsh-plugin-market-index')
|
|
189
|
+
try {
|
|
190
|
+
return createRequire(import.meta.url)(validatorDir)
|
|
191
|
+
} catch (err) {
|
|
192
|
+
skip('parseMarketIndex', `无法加载 ${validatorDir}(普通 node 读不了 app.asar,请用 ELECTRON_RUN_AS_NODE + DSH_NODE_EXECUTABLE):${err.message}`)
|
|
193
|
+
return null
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function validateWithDSH(mod, indexObject, label) {
|
|
198
|
+
let parsed
|
|
199
|
+
try {
|
|
200
|
+
parsed = mod.parseMarketIndex(indexObject, INDEX_URL)
|
|
201
|
+
ok(`parseMarketIndex 接受${label}`)
|
|
202
|
+
} catch (err) {
|
|
203
|
+
bad(`parseMarketIndex 拒绝${label}`, `${err.path ?? ''} ${err.reason ?? err.message}`)
|
|
204
|
+
return
|
|
205
|
+
}
|
|
206
|
+
for (const plugin of parsed.plugins) {
|
|
207
|
+
const stable = plugin.versions.find((v) => !/-/.test(v.version))
|
|
208
|
+
const target = stable ?? plugin.versions[0]
|
|
209
|
+
const got = mod.marketInstallTarget(plugin.name, target)
|
|
210
|
+
const want = `${plugin.name}@${target.version}`
|
|
211
|
+
expect(got?.spec === want, `install spec(默认版本 ${target.version})`, got?.spec)
|
|
212
|
+
}
|
|
213
|
+
// 图标相对路径在真实索引 URL 下会解析成什么
|
|
214
|
+
for (const plugin of parsed.plugins) {
|
|
215
|
+
if (plugin.icon) ok(`${plugin.name}.icon 解析为`, plugin.icon)
|
|
216
|
+
}
|
|
217
|
+
ok('版本集合', parsed.plugins.map((p) => `${p.name}: ${p.versions.length} 个版本,最新 ${p.versions[0].version}`).join(';'))
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
process.stdout.write('\n[DSH 校验器 · 本地文件]\n')
|
|
221
|
+
const validator = loadValidator()
|
|
222
|
+
if (validator) validateWithDSH(validator, index, '索引')
|
|
223
|
+
|
|
224
|
+
// ---------- 3. 传输层:真的按 URL 取一次(--http)----------
|
|
225
|
+
if (process.argv.includes('--http')) {
|
|
226
|
+
process.stdout.write(`\n[传输 · ${INDEX_URL}]\n`)
|
|
227
|
+
let res
|
|
228
|
+
try {
|
|
229
|
+
res = await fetch(INDEX_URL, { redirect: 'manual', headers: { 'user-agent': 'dsh-market-check' } })
|
|
230
|
+
} catch (err) {
|
|
231
|
+
bad('GET 索引 URL', err.message)
|
|
232
|
+
}
|
|
233
|
+
if (res) {
|
|
234
|
+
const okStatus = expect(res.status >= 200 && res.status < 300, '状态码 2xx', String(res.status))
|
|
235
|
+
if (!okStatus && res.status >= 300 && res.status < 400) {
|
|
236
|
+
bad('不能重定向', `DSH 拒绝重定向,改用 ${res.headers.get('location') ?? '最终地址'}`)
|
|
237
|
+
}
|
|
238
|
+
expect(/json/i.test(res.headers.get('content-type') ?? ''), 'Content-Type 是 JSON', res.headers.get('content-type') ?? '(缺失)')
|
|
239
|
+
const bytes = Buffer.from(await res.arrayBuffer())
|
|
240
|
+
expect(bytes.length > 0 && bytes.length < MAX_INDEX_BYTES, '响应体积', `${bytes.length} 字节`)
|
|
241
|
+
let remote
|
|
242
|
+
try {
|
|
243
|
+
remote = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes))
|
|
244
|
+
ok('响应是严格 UTF-8 的 JSON')
|
|
245
|
+
} catch (err) {
|
|
246
|
+
bad('响应是严格 UTF-8 的 JSON', err.message)
|
|
247
|
+
}
|
|
248
|
+
if (remote && validator) validateWithDSH(validator, remote, '远程索引')
|
|
249
|
+
// 图标真的能取到(DSH 相对索引 URL 解析图标)
|
|
250
|
+
const icon = remote?.plugins?.find((p) => p.icon && !/^(data:|https?:)/.test(p.icon))?.icon
|
|
251
|
+
if (icon) {
|
|
252
|
+
const iconUrl = new URL(icon, INDEX_URL).href
|
|
253
|
+
try {
|
|
254
|
+
const iconRes = await fetch(iconUrl, { redirect: 'manual' })
|
|
255
|
+
expect(iconRes.status === 200, '图标可取到', `${iconUrl} → ${iconRes.status}`)
|
|
256
|
+
} catch (err) {
|
|
257
|
+
bad('图标可取到', `${iconUrl} → ${err.message}`)
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
process.stdout.write(`\n${failures ? '✗' : '✓'} ${checks - failures}/${checks} 项通过\n`)
|
|
264
|
+
if (failures) process.exitCode = 1
|