@linkdesk/plugin-sdk 0.1.60 → 0.1.61

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.
@@ -0,0 +1,107 @@
1
+ /**
2
+ * @linkdesk/plugin-sdk/own-dict-coverage 的类型声明(实现 = 同目录 own-dict-coverage.mjs,免构建直发)。
3
+ * 判据出处(用户 2026-09-30 拍板「谁的仓谁译文」)与两条判据的域内外声明见 .mjs 头注——
4
+ * 那里是单一真源,这里不重述。
5
+ */
6
+
7
+ export interface OwnDictDecl {
8
+ /** 声明出处,如 `contributes.i18n.en` / `contributes.languages[zh]` */
9
+ origin: string;
10
+ /** 语言码(`contributes.languages` 取 id) */
11
+ lang: string;
12
+ /** 相对插件根的路径 */
13
+ rel: string;
14
+ }
15
+
16
+ export interface OwnDictFile extends OwnDictDecl {
17
+ /** 该文件里的 key(key = 原文,与语言无关) */
18
+ keys: string[];
19
+ }
20
+
21
+ export interface OwnDictLoad {
22
+ /** 全部声明字典的 key 并集 */
23
+ keys: Set<string>;
24
+ files: OwnDictFile[];
25
+ /** 读不到 / 解析不动的声明(非空 ⇒ degraded) */
26
+ problems: string[];
27
+ /** 字典不完整 ⇒ 调用方**跳过判红**(否则「全是 gap」是假红) */
28
+ degraded: boolean;
29
+ }
30
+
31
+ /** 一条可渲染 manifest 字段的判据规格 */
32
+ export interface RenderableFieldSpec {
33
+ /** 路径步:普通键名 / `"*"` 开放键 / `"[]"` 数组 / `"**"` 沿 children 递归 */
34
+ steps: string[];
35
+ /** 取值字段;`null` ⇒ 落点自己就是那条字符串 */
36
+ field: string | null;
37
+ /** 消费方(渲染点在哪里)——文档与报错里同款 */
38
+ consumer: string;
39
+ /** 值形态是「映射/枚举显示名」——对象与数组两种写法都收 */
40
+ mapValues?: boolean;
41
+ }
42
+
43
+ export interface ManifestString {
44
+ text: string;
45
+ field: string;
46
+ consumer: string;
47
+ }
48
+
49
+ export interface SourceKey {
50
+ key: string;
51
+ /** 出现的源码文件(相对插件根,POSIX 斜杠) */
52
+ at: string[];
53
+ }
54
+
55
+ export interface OwnDictCheckOptions {
56
+ /** 已解析的 `plugin.json`(JSONC 解析由调用方负责,与壳侧读到的必须是同一份清单) */
57
+ manifest?: unknown;
58
+ /** 跳过的目录名集合;缺省 = DEFAULT_SKIP_DIRS */
59
+ skipDirs?: Set<string>;
60
+ /** 源码根(相对插件根);缺省 `src` */
61
+ srcDir?: string;
62
+ }
63
+
64
+ export interface OwnDictCheckResult {
65
+ dict: OwnDictLoad;
66
+ scanned: { manifestStrings: number; sourceKeys: number };
67
+ /** 红:声明在本仓的 manifest 渲染串没住本仓字典 */
68
+ manifestGap: ManifestString[];
69
+ /** 黄:本仓 `t("中文")` key 没住本仓字典(应用级字典是合法提供方) */
70
+ sourceGap: SourceKey[];
71
+ degraded: boolean;
72
+ problems: string[];
73
+ }
74
+
75
+ /** 本仓**自己声明的**字典文件(`contributes.i18n` + `contributes.languages[].path`)。 */
76
+ export declare function collectOwnDictDecls(manifest: unknown): OwnDictDecl[];
77
+
78
+ /** 读本仓声明的字典 → key 并集 + 每份字典的 key(key = 原文,与语言无关)。 */
79
+ export declare function loadOwnDict(absRoot: string, manifest: unknown): OwnDictLoad;
80
+
81
+ /** manifest 里的**可渲染中文串**(按 text 去重,保留首个落点)。 */
82
+ export declare function collectRenderableManifestStrings(manifest: unknown): ManifestString[];
83
+
84
+ /** 本仓 `src/**` 里 `t("…")` 的**中文**字面量 key(只收含中文的,非中文原文插件不在此列)。 */
85
+ export declare function collectSourceTKeys(absRoot: string, options?: OwnDictCheckOptions): SourceKey[];
86
+
87
+ /** 判据主体——manifest 缺口(红)+ 源码 t() 缺口(黄)。 */
88
+ export declare function checkOwnDictCoverage(absRoot: string, options?: OwnDictCheckOptions): OwnDictCheckResult;
89
+
90
+ /** 违规一律以投影类型表示(`text` 在 = manifest 缺口;`key` 在 = 源码缺口) */
91
+ export type OwnDictIssue = ManifestString | SourceKey;
92
+
93
+ /** 违规 → 人类可读一行(两轴打印同款)。 */
94
+ export declare function formatOwnDictIssue(issue: OwnDictIssue): string;
95
+
96
+ /** 违规 → 修法提示(按 manifest / source 给因)。 */
97
+ export declare function ownDictHint(issue: OwnDictIssue): string;
98
+
99
+ /** 参与 `t()` 扫描的源码文件(测试 / mock 不在其列)。 */
100
+ export declare function isSourceFile(relPath: string): boolean;
101
+
102
+ /** 口径一句话——门禁与文档互钉用。 */
103
+ export declare const OWN_DICT_CALIBER: string;
104
+
105
+ export declare const RENDERABLE_MANIFEST_FIELDS: RenderableFieldSpec[];
106
+
107
+ export declare const DEFAULT_SKIP_DIRS: Set<string>;
@@ -0,0 +1,344 @@
1
+ /**
2
+ * 「**谁的仓谁译文**」判据——插件自己声明的可渲染文案,必须住在**自己的字典**里。
3
+ *
4
+ * ═══ 为什么必须有它(出处:2026-09-30 用户实机立案 E6#161)═══
5
+ * 用户报「**设置插件自己的翻译没做全,比如自己在设置中的声明项**」——英文界面下设置页左栏
6
+ * 那组「设置插件/打开方式」仍是中文。追下去发现两层:
7
+ * ① 设置仓**一个 i18n 键都没有**:它的文案一律「`plugin.json` 留中文原文、渲染时才 `t()`」
8
+ * (E5#109 方案 B),而英文全住**另一个仓**(官方语言包 `lang-defaults`)。
9
+ * ② 于是「声明项要不要补译」变成**跨仓**的事:设置仓加一条声明,lang-defaults 仓**跟不动**
10
+ * (它连这个键都不知道)。这不是谁的笔误,是**归属没定**。
11
+ *
12
+ * 用户 2026-09-30 拍板定归属:**谁的仓谁译文**——插件自己声明的可渲染文案,译名住自己的
13
+ * `i18n/<lang>.json`;壳核心文字仍住语言包(那是「一个应用的整体翻译」这件事的载体)。
14
+ * 本模块就是那条规则的机械尺(三层固化第 3 层)。
15
+ *
16
+ * ═══ 判据(两条,severity 不同——理由见下)═══
17
+ * ① **manifest 声明串**(红):`plugin.json` 里**有渲染消费方**的字段值(清单见
18
+ * `RENDERABLE_MANIFEST_FIELDS`,逐条带消费方),若含中文,必须命中本仓**自己声明的字典**
19
+ * (`contributes.i18n` / `contributes.languages[].path`)的某个 key。
20
+ * **为什么可以硬判**:声明在**本仓**、渲染在**壳或别的插件**——跨仓追不上,只有本仓能负责。
21
+ * ② **源码 `t()` 串**(黄):本仓 `src/**` 里 `t("中文")` 字面量 key 没住在自有字典。
22
+ * **为什么只能黄**:应用级字典(`lang-defaults`)**是合法提供方**,插件仓里判不出「这个键
23
+ * 是不是别处给的」——硬判必出假红,而假红会让真红失效(同 `warnOnKeyOverlap` 的立论)。
24
+ * 存量缺口按「谁的仓」逐仓迁(settings 是试点);迁完这条可以升红。
25
+ * ⛔ **域外(本判据不管,别以为漏了)**:值译得对不对;跨仓撞键(归壳侧 `warnOnKeyOverlap`);
26
+ * 非中文原文的插件(E5.8#37.9 明文:作者可用任意语言原文做 key,缺译文静默回退 = 设计意图,
27
+ * 不是漏翻——故本判据**只审中文串**)。
28
+ *
29
+ * ═══ 消费方(两轴同一份实现,⛔ 不许各写一份)═══
30
+ * · 作者侧:`create-linkdesk-plugin` 模板的 `scripts/ci-verify.mjs` ③ 段——插件仓 CI 判红
31
+ * (经 `@linkdesk/plugin-sdk/own-dict-coverage` subpath 引入:插件仓**零新增 devDependency**,
32
+ * 纯数据插件仓也在覆盖内)。
33
+ * · 壳侧:`scripts/audit-i18n.mjs` 的 manifest 腿——走**全部官方/第三方仓**
34
+ * (仓清单读 `scripts/lib/plugin-repos.mjs`),并额外做「跨仓池对照」(`lang-defaults` 是合法池)。
35
+ *
36
+ * 用法:
37
+ * import { checkOwnDictCoverage } from "@linkdesk/plugin-sdk/own-dict-coverage";
38
+ * const r = checkOwnDictCoverage(process.cwd()); // ⇒ { manifestGap, sourceGap, dict, ... }
39
+ */
40
+
41
+ import { readdirSync, readFileSync } from "node:fs";
42
+ import { join, sep } from "node:path";
43
+
44
+ /** 口径一句话——门禁与文档互钉用(改判据就改这句,两处锚词比对会跟着红) */
45
+ export const OWN_DICT_CALIBER =
46
+ "谁的仓谁译文:插件自己声明的可渲染文案(manifest 渲染字段 + 本仓 t() 中文 key)必须住在本仓声明的字典里——声明在谁手里,译名就归谁,跨仓追不上。";
47
+
48
+ /** 中文(CJK 统一表意)——只有含它的串才进判据(英文/法文原文插件 = 设计允许,见文件头 ⛔ 域外) */
49
+ const CJK_RE = /[\u4e00-\u9fff]/;
50
+
51
+ /**
52
+ * **可渲染 manifest 字段清单**——每条 = 一条路径(`steps`)+ 取值字段(`field`)+ **消费方**。
53
+ *
54
+ * `steps` 的三种步:
55
+ * · 普通键名 —— 下钻该键;
56
+ * · `"*"` —— 对象的值逐个走(贡献点里 `<id>` 段那种开放键名);
57
+ * · `"[]"` —— 数组元素逐个走;
58
+ * · `"**"` —— 沿 `children` 递归(菜单子菜单,任意深度)。
59
+ * `field` 为 `null` ⇒ 落点**自己就是那条字符串**(如 `groupDescriptions` 的值)。
60
+ *
61
+ * 🔴 **改 `schemas/plugin.schema.json` 的渲染字段时,同笔改这里**(两处是同一件事的两面:
62
+ * schema 说「能声明什么」,本表说「声明了要译」)。⛔ 别把「声明数据」(`commands[].description`
63
+ * / `params[].description`——2026-09-28 裁决:消费方 = 契约 → AI,零渲染消费方)塞进来;
64
+ * 撤销条件 = 那些说明一旦进 UI。
65
+ * ⛔ 故意**不在表内**的专名/元数据(各有理由,与壳侧旧名单同一口径):
66
+ * `contributes.themes[].label` / `languages[].label` / `langDefs[].aliases`(品牌名/语言自称)、
67
+ * `icons.*.description`(作者面元数据,消费方是**别的作者**不是用户)、以及一切路径/ID/上下文键
68
+ * (`entry` / `icon` / `render` / `path` / `sidebar` / `when` / `key` / 菜单 `group` 槽位 / `cssVars` /
69
+ * `tabBehavior` / `minAppVersion` / `screenshots` / `resources`…)。
70
+ */
71
+ export const RENDERABLE_MANIFEST_FIELDS = [
72
+ { steps: [], field: "name", consumer: "插件名(市场列表行 / 详情页 / 侧栏标题)" },
73
+ { steps: [], field: "description", consumer: "插件一行说明(详情页 t(description) / 市场列表行)" },
74
+ { steps: ["statusBar", "[]"], field: "label", consumer: "状态栏条目文本" },
75
+ { steps: ["contributes", "commands", "[]"], field: "title", consumer: "命令面板 / 菜单标题" },
76
+ { steps: ["contributes", "commands", "[]"], field: "category", consumer: "命令面板分组名" },
77
+ { steps: ["contributes", "menus", "*", "[]", "**"], field: "label", consumer: "菜单项 / 子菜单标签" },
78
+ { steps: ["contributes", "configuration"], field: "title", consumer: "设置页分组名" },
79
+ { steps: ["contributes", "configuration"], field: "subtitle", consumer: "设置页分组副标题" },
80
+ {
81
+ steps: ["contributes", "configuration", "groupDescriptions", "*"],
82
+ field: null,
83
+ consumer: "设置页分节说明(settings 仓 t(groupDescriptions[组名]))",
84
+ },
85
+ {
86
+ steps: ["contributes", "configuration", "properties", "*"],
87
+ field: "description",
88
+ consumer: "设置项说明(settings 仓 t(prop.description))",
89
+ },
90
+ {
91
+ steps: ["contributes", "configuration", "properties", "*"],
92
+ field: "group",
93
+ consumer: "设置页二级标题(settings 仓 t(bucket.group))",
94
+ },
95
+ {
96
+ steps: ["contributes", "configuration", "properties", "*"],
97
+ field: "enumDescriptions",
98
+ consumer: "设置页枚举显示名(值形态:对象 value→名 或 数组)",
99
+ mapValues: true,
100
+ },
101
+ { steps: ["contributes", "viewsContainers", "*"], field: "title", consumer: "侧栏容器标题" },
102
+ { steps: ["contributes", "views", "*", "[]"], field: "title", consumer: "侧栏 / 面板视图标题" },
103
+ { steps: ["contributes", "views", "*", "[]"], field: "singleViewPaneContainerTitle", consumer: "单视图容器标题" },
104
+ { steps: ["contributes", "views", "*", "[]"], field: "titleDescription", consumer: "视图标题说明" },
105
+ { steps: ["contributes", "views", "*", "[]"], field: "titleTooltip", consumer: "视图标题提示" },
106
+ { steps: ["contributes", "views", "*", "[]", "titleActions", "[]"], field: "title", consumer: "视图动作按钮 tooltip / 文本" },
107
+ {
108
+ steps: ["contributes", "views", "*", "[]", "titleActions", "[]", "items", "[]"],
109
+ field: "label",
110
+ consumer: "视图动作下拉项标签",
111
+ },
112
+ { steps: ["contributes", "titleBar", "left", "[]"], field: "label", consumer: "标题栏按钮文本" },
113
+ { steps: ["contributes", "titleBar", "right", "[]"], field: "label", consumer: "标题栏按钮文本" },
114
+ { steps: ["contributes", "fileAssociations", "[]"], field: "displayName", consumer: "「打开方式…」选择器显示名" },
115
+ ];
116
+
117
+ /** 默认跳过的目录名——构建产物 / 依赖 / 编辑器临时目录 */
118
+ export const DEFAULT_SKIP_DIRS = new Set([
119
+ "node_modules",
120
+ "dist",
121
+ "dist-electron",
122
+ ".git",
123
+ ".vite",
124
+ "coverage",
125
+ "__tests__",
126
+ "build",
127
+ ]);
128
+
129
+ /** 参与 `t()` 扫描的源码文件(测试 / mock 不在其列——它们不受这条纪律约束,同 ci-verify 口径) */
130
+ export function isSourceFile(relPath) {
131
+ return (
132
+ /\.(ts|tsx|js|jsx)$/.test(relPath) &&
133
+ !/\.(test|spec)\./.test(relPath) &&
134
+ !/\.(fixture|mock)\./.test(relPath) &&
135
+ !/mock/i.test(relPath)
136
+ );
137
+ }
138
+
139
+ /** 本仓**自己声明的**字典文件——`contributes.i18n`(langId → 路径)+ `contributes.languages[].path` */
140
+ export function collectOwnDictDecls(manifest) {
141
+ const out = [];
142
+ const c = manifest?.contributes;
143
+ if (!c || typeof c !== "object") return out;
144
+ if (c.i18n && typeof c.i18n === "object" && !Array.isArray(c.i18n)) {
145
+ for (const [lang, rel] of Object.entries(c.i18n)) {
146
+ if (typeof rel === "string") out.push({ origin: `contributes.i18n.${lang}`, lang, rel });
147
+ }
148
+ }
149
+ if (Array.isArray(c.languages)) {
150
+ for (const l of c.languages) {
151
+ if (l && typeof l.path === "string") {
152
+ out.push({ origin: `contributes.languages[${l.id ?? "?"}]`, lang: String(l.id ?? ""), rel: l.path });
153
+ }
154
+ }
155
+ }
156
+ return out;
157
+ }
158
+
159
+ /**
160
+ * 读本仓声明的字典 → key 集合(key = 原文,与语言无关)。
161
+ * 任一文件读不到 / 解析不动 ⇒ `degraded: true` + `problems`——**调用方据此跳过判红**
162
+ * (字典不完整时「全部 gap」是假红,而假红会让真红失效;那条硬伤由字典完整性那条腿报)。
163
+ */
164
+ export function loadOwnDict(absRoot, manifest) {
165
+ const files = [];
166
+ const problems = [];
167
+ const keys = new Set();
168
+ for (const d of collectOwnDictDecls(manifest)) {
169
+ let raw;
170
+ try {
171
+ raw = readFileSync(join(absRoot, d.rel.split("/").join(sep)), "utf8");
172
+ } catch {
173
+ problems.push(`${d.rel}(${d.origin} 声明但读不到)`);
174
+ continue;
175
+ }
176
+ let dict;
177
+ try {
178
+ dict = JSON.parse(raw);
179
+ } catch (e) {
180
+ problems.push(`${d.rel} 不是合法 JSON:${e instanceof Error ? e.message : String(e)}`);
181
+ continue;
182
+ }
183
+ if (!dict || typeof dict !== "object" || Array.isArray(dict)) {
184
+ problems.push(`${d.rel} 不是「key → 文案」对象`);
185
+ continue;
186
+ }
187
+ const own = Object.keys(dict);
188
+ own.forEach((k) => keys.add(k));
189
+ files.push({ origin: d.origin, rel: d.rel, lang: d.lang, keys: own });
190
+ }
191
+ return { keys, files, problems, degraded: problems.length > 0 };
192
+ }
193
+
194
+ /** `steps` 逐段下钻 → 落点数组(`"*"` 开放键 / `"[]"` 数组 / `"**"` 沿 children 递归) */
195
+ function resolveSteps(node, steps) {
196
+ if (steps.length === 0) return [node];
197
+ const [s, ...rest] = steps;
198
+ if (s === "[]") return Array.isArray(node) ? node.flatMap((n) => resolveSteps(n, rest)) : [];
199
+ if (s === "*") {
200
+ if (!node || typeof node !== "object" || Array.isArray(node)) return [];
201
+ return Object.values(node).flatMap((n) => resolveSteps(n, rest));
202
+ }
203
+ if (s === "**") {
204
+ const out = [];
205
+ const walk = (n) => {
206
+ if (Array.isArray(n)) {
207
+ n.forEach(walk);
208
+ return;
209
+ }
210
+ if (!n || typeof n !== "object") return;
211
+ out.push(...resolveSteps(n, rest));
212
+ walk(n.children);
213
+ };
214
+ walk(node);
215
+ return out;
216
+ }
217
+ if (!node || typeof node !== "object") return [];
218
+ return resolveSteps(node[s], rest);
219
+ }
220
+
221
+ /** 落点 → 要判的字符串们(`field: null` ⇒ 落点自己就是;`mapValues` ⇒ 对象/数组两种形态的值) */
222
+ function fieldValues(node, spec) {
223
+ if (spec.field == null) return [node];
224
+ if (!node || typeof node !== "object" || Array.isArray(node)) return [];
225
+ const v = node[spec.field];
226
+ if (v === undefined) return [];
227
+ if (spec.mapValues) {
228
+ if (Array.isArray(v)) return v; // 数组形态(壳侧 `enumDescriptions: string[]` 就是这种)
229
+ if (v && typeof v === "object") return Object.values(v); // 对象形态(value → 显示名)
230
+ return [v];
231
+ }
232
+ return [v];
233
+ }
234
+
235
+ /**
236
+ * 收集 manifest 里的**可渲染中文串** → `[{ text, field, consumer }]`(按 text 去重,保留首个落点)。
237
+ * 只收含中文的串:非中文原文插件(设计允许)不在此列。
238
+ */
239
+ export function collectRenderableManifestStrings(manifest) {
240
+ const out = [];
241
+ const seen = new Set();
242
+ for (const spec of RENDERABLE_MANIFEST_FIELDS) {
243
+ // 路径可读化:`[]` 贴在前一段上(`contributes.commands[]` 比 `contributes.commands.[]` 好读)
244
+ const where = (spec.steps.length ? spec.steps.join(".") : "(顶层)")
245
+ .replace(/\.\[\]/g, "[]")
246
+ .replace(/\.\*\[\]/g, ".*[]");
247
+ for (const node of resolveSteps(manifest, spec.steps)) {
248
+ for (const v of fieldValues(node, spec)) {
249
+ if (typeof v !== "string" || !CJK_RE.test(v)) continue;
250
+ if (seen.has(v)) continue;
251
+ seen.add(v);
252
+ out.push({ text: v, field: `${where}${spec.field ? `.${spec.field}` : ""}`, consumer: spec.consumer });
253
+ }
254
+ }
255
+ }
256
+ return out;
257
+ }
258
+
259
+ /**
260
+ * 扫本仓 `src/**` 的 `t("…")` 字面量 key → `[{ key, at: ["src/x.tsx", …] }]`(只收含中文的 key)。
261
+ * 与壳侧 `audit-i18n` 的 G2 分工:那边管**标识符形态**的 key(数据键名误走翻译),这边管**中文** key
262
+ * (该不该由本仓提供译名)——**同一份正则**,免得同一个调用点两把尺子说法不同。
263
+ */
264
+ export function collectSourceTKeys(absRoot, options = {}) {
265
+ const skipDirs = options.skipDirs ?? DEFAULT_SKIP_DIRS;
266
+ const srcRel = options.srcDir ?? "src";
267
+ const found = new Map();
268
+ const walk = (absDir, relDir) => {
269
+ let entries;
270
+ try {
271
+ entries = readdirSync(absDir, { withFileTypes: true });
272
+ } catch {
273
+ return;
274
+ }
275
+ for (const e of entries) {
276
+ const rel = relDir ? `${relDir}/${e.name}` : e.name;
277
+ if (e.isDirectory()) {
278
+ if (skipDirs.has(e.name) || e.name.startsWith(".")) continue;
279
+ walk(join(absDir, e.name), rel);
280
+ continue;
281
+ }
282
+ if (!e.isFile() || !isSourceFile(rel)) continue;
283
+ let text;
284
+ try {
285
+ text = readFileSync(join(absDir, e.name), "utf8");
286
+ } catch {
287
+ continue;
288
+ }
289
+ for (const m of text.matchAll(/\bt\(\s*(["'])((?:\\.|(?!\1)[^\\\r\n])*)\1/g)) {
290
+ const key = m[2].replace(/\\(["'\\nrt])/g, (_, c) =>
291
+ c === "n" ? "\n" : c === "r" ? "\r" : c === "t" ? "\t" : c,
292
+ );
293
+ if (!CJK_RE.test(key)) continue;
294
+ const at = found.get(key) ?? [];
295
+ if (!at.includes(rel)) at.push(rel); // 同一文件里出现多次只记一次(报错读的是「在哪几处」)
296
+ found.set(key, at);
297
+ }
298
+ }
299
+ };
300
+ walk(join(absRoot, srcRel.split("/").join(sep)), srcRel);
301
+ return [...found].map(([key, at]) => ({ key, at }));
302
+ }
303
+
304
+ /**
305
+ * 判据主体——`{ manifestGap, sourceGap, dict, scanned, degraded, problems }`。
306
+ *
307
+ * `manifestGap[i]` = `{ text, field, consumer }`(**红**:声明在本仓,跨仓追不上);
308
+ * `sourceGap[i]` = `{ key, at }`(**黄**:应用级字典是合法提供方,本仓判不出「是不是别处给的」)。
309
+ */
310
+ export function checkOwnDictCoverage(absRoot, options = {}) {
311
+ const manifest = options.manifest;
312
+ const dict = loadOwnDict(absRoot, manifest);
313
+ const manifestStrings = collectRenderableManifestStrings(manifest);
314
+ const sourceKeys = collectSourceTKeys(absRoot, options);
315
+ return {
316
+ dict,
317
+ scanned: { manifestStrings: manifestStrings.length, sourceKeys: sourceKeys.length },
318
+ manifestGap: manifestStrings.filter((s) => !dict.keys.has(s.text)),
319
+ sourceGap: sourceKeys.filter((k) => !dict.keys.has(k.key)),
320
+ degraded: dict.degraded,
321
+ problems: dict.problems,
322
+ };
323
+ }
324
+
325
+ /** 违规 → 人类可读一行(两轴打印同款,免得同一条错两种说法) */
326
+ export function formatOwnDictIssue(issue) {
327
+ if ("text" in issue) return `${JSON.stringify(issue.text)} @${issue.field}(${issue.consumer})`;
328
+ return `${JSON.stringify(issue.key)} t() @${issue.at.slice(0, 3).join(" / ")}${issue.at.length > 3 ? ` 等 ${issue.at.length} 处` : ""}`;
329
+ }
330
+
331
+ /** 违规 → 修法提示(按 severity 给因——两种缺口的修法不同) */
332
+ export function ownDictHint(issue) {
333
+ if ("text" in issue) {
334
+ return (
335
+ "声明在你仓里 ⇒ 译名也该住你仓:在本仓 `i18n/<lang>.json` 加一条 `\"原文\": \"译文\"`," +
336
+ "并在 `plugin.json` 的 `contributes.i18n` 里声明该文件(照 `create-linkdesk-plugin` 模板)。" +
337
+ "⛔ 别去改官方语言包——那条路跨仓,跟不动(本判据的出处就是这个病)。"
338
+ );
339
+ }
340
+ return (
341
+ "本仓 `src` 里的 t() 中文 key 没住自有字典。**黄灯不拦**:它可能由应用级字典(lang-defaults 插件)提供。" +
342
+ "按「谁的仓谁译文」逐条迁进本仓 `i18n/<lang>.json`(迁完在语言包侧删同键,免得撞键出声)。"
343
+ );
344
+ }
package/package.json CHANGED
@@ -1,85 +1,91 @@
1
- {
2
- "name": "@linkdesk/plugin-sdk",
3
- "version": "0.1.60",
4
- "description": "@linkdesk/plugin-sdk——LinkDesk 插件作者 SDK(对标 @types/vscode):window.linkdesk.* 类型 + 一键 build(.linkdesk-plugin) + dev 宿主 + plugin.json 验证 + eslint 门禁(E6#54d)。作者 npm i 后零壳源码依赖。",
5
- "type": "module",
6
- "main": "./dist/index.js",
7
- "types": "./dist/index.d.ts",
8
- "exports": {
9
- ".": {
10
- "types": "./dist/index.d.ts",
11
- "default": "./dist/index.js"
12
- },
13
- "./eslint": {
14
- "types": "./dist/eslint/index.d.ts",
15
- "default": "./dist/eslint/index.js"
16
- },
17
- "./vitest-setup": {
18
- "types": "./dist/vitest-setup.d.ts",
19
- "default": "./dist/vitest-setup.js"
20
- },
21
- "./test-audit": {
22
- "types": "./test-audit.d.ts",
23
- "default": "./test-audit.mjs"
24
- },
25
- "./svg-wellformed": {
26
- "types": "./svg-wellformed.d.ts",
27
- "default": "./svg-wellformed.mjs"
28
- },
29
- "./package.json": "./package.json"
30
- },
31
- "files": [
32
- "dist",
33
- "schemas",
34
- "dev-host",
35
- "test-audit.mjs",
36
- "test-audit.d.ts",
37
- "svg-wellformed.mjs",
38
- "svg-wellformed.d.ts"
39
- ],
40
- "sideEffects": false,
41
- "bin": {
42
- "linkdesk-plugin-sdk": "./dist/bin.js"
43
- },
44
- "publishConfig": {
45
- "access": "public"
46
- },
47
- "engines": {
48
- "node": ">=20.0.0"
49
- },
50
- "scripts": {
51
- "build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
52
- "typecheck": "tsc -p tsconfig.json --noEmit",
53
- "prepack": "npm run build"
54
- },
55
- "dependencies": {
56
- "@linkdesk/contracts": "^0.1.1",
57
- "@typescript-eslint/eslint-plugin": "^8.0.0",
58
- "@typescript-eslint/parser": "^8.0.0",
59
- "@vitejs/plugin-react": "^4.3.4",
60
- "ajv": "^8.17.1",
61
- "eslint": "^9.0.0",
62
- "eslint-import-resolver-typescript": "^4.4.5",
63
- "eslint-plugin-import-x": "^4.17.1",
64
- "eslint-plugin-react-hooks": "^7.1.1",
65
- "i18next": "^26.3.6",
66
- "jsonc-parser": "^3.3.1",
67
- "jszip": "^3.10.1",
68
- "react": "^18.3.1",
69
- "react-dom": "^18.3.1",
70
- "react-i18next": "^17.0.10",
71
- "saxes": "^6.0.0",
72
- "vite": "^6.0.0"
73
- },
74
- "devDependencies": {
75
- "@types/node": "^24.0.0",
76
- "typescript": "^5.9.0"
77
- },
78
- "keywords": [
79
- "linkdesk",
80
- "plugin",
81
- "sdk",
82
- "vite"
83
- ],
84
- "license": "MIT"
85
- }
1
+ {
2
+ "name": "@linkdesk/plugin-sdk",
3
+ "version": "0.1.61",
4
+ "description": "@linkdesk/plugin-sdk——LinkDesk 插件作者 SDK(对标 @types/vscode):window.linkdesk.* 类型 + 一键 build(.linkdesk-plugin) + dev 宿主 + plugin.json 验证 + eslint 门禁(E6#54d)。作者 npm i 后零壳源码依赖。",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ },
13
+ "./eslint": {
14
+ "types": "./dist/eslint/index.d.ts",
15
+ "default": "./dist/eslint/index.js"
16
+ },
17
+ "./vitest-setup": {
18
+ "types": "./dist/vitest-setup.d.ts",
19
+ "default": "./dist/vitest-setup.js"
20
+ },
21
+ "./test-audit": {
22
+ "types": "./test-audit.d.ts",
23
+ "default": "./test-audit.mjs"
24
+ },
25
+ "./svg-wellformed": {
26
+ "types": "./svg-wellformed.d.ts",
27
+ "default": "./svg-wellformed.mjs"
28
+ },
29
+ "./package.json": "./package.json",
30
+ "./own-dict-coverage": {
31
+ "types": "./own-dict-coverage.d.ts",
32
+ "default": "./own-dict-coverage.mjs"
33
+ }
34
+ },
35
+ "files": [
36
+ "dist",
37
+ "schemas",
38
+ "dev-host",
39
+ "test-audit.mjs",
40
+ "test-audit.d.ts",
41
+ "svg-wellformed.mjs",
42
+ "svg-wellformed.d.ts",
43
+ "own-dict-coverage.mjs",
44
+ "own-dict-coverage.d.ts"
45
+ ],
46
+ "sideEffects": false,
47
+ "bin": {
48
+ "linkdesk-plugin-sdk": "./dist/bin.js"
49
+ },
50
+ "publishConfig": {
51
+ "access": "public"
52
+ },
53
+ "engines": {
54
+ "node": ">=20.0.0"
55
+ },
56
+ "scripts": {
57
+ "build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
58
+ "typecheck": "tsc -p tsconfig.json --noEmit",
59
+ "prepack": "npm run build"
60
+ },
61
+ "dependencies": {
62
+ "@linkdesk/contracts": "^0.1.1",
63
+ "@typescript-eslint/eslint-plugin": "^8.0.0",
64
+ "@typescript-eslint/parser": "^8.0.0",
65
+ "@vitejs/plugin-react": "^4.3.4",
66
+ "ajv": "^8.17.1",
67
+ "eslint": "^9.0.0",
68
+ "eslint-import-resolver-typescript": "^4.4.5",
69
+ "eslint-plugin-import-x": "^4.17.1",
70
+ "eslint-plugin-react-hooks": "^7.1.1",
71
+ "i18next": "^26.3.6",
72
+ "jsonc-parser": "^3.3.1",
73
+ "jszip": "^3.10.1",
74
+ "react": "^18.3.1",
75
+ "react-dom": "^18.3.1",
76
+ "react-i18next": "^17.0.10",
77
+ "saxes": "^6.0.0",
78
+ "vite": "^6.0.0"
79
+ },
80
+ "devDependencies": {
81
+ "@types/node": "^24.0.0",
82
+ "typescript": "^5.9.0"
83
+ },
84
+ "keywords": [
85
+ "linkdesk",
86
+ "plugin",
87
+ "sdk",
88
+ "vite"
89
+ ],
90
+ "license": "MIT"
91
+ }