@linkdesk/plugin-sdk 0.1.63 → 0.1.64
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/own-dict-coverage.d.ts +15 -3
- package/own-dict-coverage.mjs +102 -9
- package/package.json +1 -1
package/own-dict-coverage.d.ts
CHANGED
|
@@ -63,8 +63,8 @@ export interface OwnDictCheckOptions {
|
|
|
63
63
|
|
|
64
64
|
export interface OwnDictCheckResult {
|
|
65
65
|
dict: OwnDictLoad;
|
|
66
|
-
scanned: { manifestStrings: number; sourceKeys: number };
|
|
67
|
-
/** 红:声明在本仓的 manifest
|
|
66
|
+
scanned: { manifestStrings: number; themeStrings: number; sourceKeys: number };
|
|
67
|
+
/** 红:声明在本仓的 manifest 渲染串(含主题数据文件里的名字)没住本仓字典 */
|
|
68
68
|
manifestGap: ManifestString[];
|
|
69
69
|
/** 黄:本仓 `t("中文")` key 没住本仓字典(应用级字典是合法提供方) */
|
|
70
70
|
sourceGap: SourceKey[];
|
|
@@ -81,10 +81,19 @@ export declare function loadOwnDict(absRoot: string, manifest: unknown): OwnDict
|
|
|
81
81
|
/** manifest 里的**可渲染中文串**(按 text 去重,保留首个落点)。 */
|
|
82
82
|
export declare function collectRenderableManifestStrings(manifest: unknown): ManifestString[];
|
|
83
83
|
|
|
84
|
+
/**
|
|
85
|
+
* **主题数据文件**(`contributes.themes[].path` 指到的 JSON)里的可渲染中文串
|
|
86
|
+
* (`name` / `colorways[].name`)+ 读不动的问题串。`field` 形如 `themes/x.json.colorways[].name`。
|
|
87
|
+
*/
|
|
88
|
+
export declare function collectRenderableThemeStrings(
|
|
89
|
+
absRoot: string,
|
|
90
|
+
manifest: unknown,
|
|
91
|
+
): { strings: ManifestString[]; problems: string[] };
|
|
92
|
+
|
|
84
93
|
/** 本仓 `src/**` 里 `t("…")` 的**中文**字面量 key(只收含中文的,非中文原文插件不在此列)。 */
|
|
85
94
|
export declare function collectSourceTKeys(absRoot: string, options?: OwnDictCheckOptions): SourceKey[];
|
|
86
95
|
|
|
87
|
-
/** 判据主体——manifest
|
|
96
|
+
/** 判据主体——manifest 缺口(红,含主题数据文件名)+ 源码 t() 缺口(黄)。 */
|
|
88
97
|
export declare function checkOwnDictCoverage(absRoot: string, options?: OwnDictCheckOptions): OwnDictCheckResult;
|
|
89
98
|
|
|
90
99
|
/** 违规一律以投影类型表示(`text` 在 = manifest 缺口;`key` 在 = 源码缺口) */
|
|
@@ -104,4 +113,7 @@ export declare const OWN_DICT_CALIBER: string;
|
|
|
104
113
|
|
|
105
114
|
export declare const RENDERABLE_MANIFEST_FIELDS: RenderableFieldSpec[];
|
|
106
115
|
|
|
116
|
+
/** **主题数据文件**里的名字规格(`name` / `colorways[].name`)——与上面那张表同一份判域。 */
|
|
117
|
+
export declare const THEME_FILE_NAME_FIELDS: RenderableFieldSpec[];
|
|
118
|
+
|
|
107
119
|
export declare const DEFAULT_SKIP_DIRS: Set<string>;
|
package/own-dict-coverage.mjs
CHANGED
|
@@ -14,8 +14,10 @@
|
|
|
14
14
|
* 本模块就是那条规则的机械尺(三层固化第 3 层)。
|
|
15
15
|
*
|
|
16
16
|
* ═══ 判据(两条,severity 不同——理由见下)═══
|
|
17
|
-
* ①
|
|
18
|
-
* `RENDERABLE_MANIFEST_FIELDS
|
|
17
|
+
* ① **声明串**(红):两处——(a) `plugin.json` 里**有渲染消费方**的字段值(清单见
|
|
18
|
+
* `RENDERABLE_MANIFEST_FIELDS`,逐条带消费方);(b) **主题数据文件里的名字**
|
|
19
|
+
* (`contributes.themes[].path` 指到的 JSON 的 `name` / `colorways[].name`,见下「为什么判到
|
|
20
|
+
* 主题数据文件里」)。若含中文,必须命中本仓**自己声明的字典**
|
|
19
21
|
* (`contributes.i18n` / `contributes.languages[].path`)的某个 key。
|
|
20
22
|
* **为什么可以硬判**:声明在**本仓**、渲染在**壳或别的插件**——跨仓追不上,只有本仓能负责。
|
|
21
23
|
* ② **源码 `t()` 串**(黄):本仓 `src/**` 里 `t("中文")` 字面量 key 没住在自有字典。
|
|
@@ -24,7 +26,22 @@
|
|
|
24
26
|
* 存量缺口按「谁的仓」逐仓迁(settings 是试点);迁完这条可以升红。
|
|
25
27
|
* ⛔ **域外(本判据不管,别以为漏了)**:值译得对不对;跨仓撞键(归壳侧 `warnOnKeyOverlap`);
|
|
26
28
|
* 非中文原文的插件(E5.8#37.9 明文:作者可用任意语言原文做 key,缺译文静默回退 = 设计意图,
|
|
27
|
-
*
|
|
29
|
+
* 不是漏翻——故本判据**只审中文串**);**「双语字面量」本身**不做机械判定(中文名里合法含拉丁专名,
|
|
30
|
+
* 像「Cascadia Mono 终端」——判「中英混排」必出假红,而假红会让真红失效)。把关的是「名字必须住字典」
|
|
31
|
+
* 这条:双语字面量要么去掉英文、要么在字典里自我翻译,两条路都得本仓动手。
|
|
32
|
+
*
|
|
33
|
+
* ═══ 为什么判到**主题数据文件里**(2026-10-01 扩域)═══
|
|
34
|
+
* 用户实机立案「**我不要双语了**」:主题族作者把译名写进位字面量(`"薄荷苏打 Mint Soda"`)⇒ 中文界面
|
|
35
|
+
* 也中英混排。定论 = 字面量只留**中文原文**、译名住本仓字典,显示期由壳过 `t()`(壳侧唯一权威 =
|
|
36
|
+
* `ThemeEngine/naming.ts`)。于是主题的名字有**两个落点、都在本仓**:
|
|
37
|
+
* · `plugin.json` 的 `contributes.themes[].label`(主题数据文件缺 `name` 时的兜底显示名);
|
|
38
|
+
* · 主题数据文件自己的 `name` / `colorways[].name`(配方名 / 配色下拉名)。
|
|
39
|
+
* 两处都得进判域——否则双语字面量在数据文件里照样溜过去(旧判据正是漏在这:本表原先把
|
|
40
|
+
* `themes[].label` 列为豁免,主题数据文件**从不读**)。
|
|
41
|
+
* ⛔ **图标主题不进本判域**(`contributes.iconThemes[].label` + 图标数据文件):图标主题的显示面还没
|
|
42
|
+
* 打通——`app.iconTheme` 下拉当前列的是**原始 id**(`updateConfigurationEnum` 只写 enum、没有
|
|
43
|
+
* `enumDescriptions`),`RegisteredIconTheme.label` **零消费方**,即那条标签今天用户看不到、看到的是 id。
|
|
44
|
+
* 判一条**没人渲染**的串 = 给作者派假活。显示面打通时**同笔**把 `iconThemes[].label` 纳入本表。
|
|
28
45
|
*
|
|
29
46
|
* ═══ 消费方(两轴同一份实现,⛔ 不许各写一份)═══
|
|
30
47
|
* · 作者侧:`create-linkdesk-plugin` 模板的 `scripts/ci-verify.mjs` ③ 段——插件仓 CI 判红
|
|
@@ -43,7 +60,7 @@ import { join, sep } from "node:path";
|
|
|
43
60
|
|
|
44
61
|
/** 口径一句话——门禁与文档互钉用(改判据就改这句,两处锚词比对会跟着红) */
|
|
45
62
|
export const OWN_DICT_CALIBER =
|
|
46
|
-
"谁的仓谁译文:插件自己声明的可渲染文案(manifest 渲染字段 + 本仓 t() 中文 key)必须住在本仓声明的字典里——声明在谁手里,译名就归谁,跨仓追不上。";
|
|
63
|
+
"谁的仓谁译文:插件自己声明的可渲染文案(manifest 渲染字段 + 主题数据文件里的名字 + 本仓 t() 中文 key)必须住在本仓声明的字典里——声明在谁手里,译名就归谁,跨仓追不上。";
|
|
47
64
|
|
|
48
65
|
/** 中文(CJK 统一表意)——只有含它的串才进判据(英文/法文原文插件 = 设计允许,见文件头 ⛔ 域外) */
|
|
49
66
|
const CJK_RE = /[\u4e00-\u9fff]/;
|
|
@@ -63,7 +80,8 @@ const CJK_RE = /[\u4e00-\u9fff]/;
|
|
|
63
80
|
* / `params[].description`——2026-09-28 裁决:消费方 = 契约 → AI,零渲染消费方)塞进来;
|
|
64
81
|
* 撤销条件 = 那些说明一旦进 UI。
|
|
65
82
|
* ⛔ 故意**不在表内**的专名/元数据(各有理由,与壳侧旧名单同一口径):
|
|
66
|
-
* `contributes.
|
|
83
|
+
* `contributes.iconThemes[].label`(显示面未打通,见上「为什么判到主题数据文件里」末段)、
|
|
84
|
+
* `languages[].label` / `langDefs[].aliases`(语言自称/`English`/`English (US)` 这种自称形式)、
|
|
67
85
|
* `icons.*.description`(作者面元数据,消费方是**别的作者**不是用户)、以及一切路径/ID/上下文键
|
|
68
86
|
* (`entry` / `icon` / `render` / `path` / `sidebar` / `when` / `key` / 菜单 `group` 槽位 / `cssVars` /
|
|
69
87
|
* `tabBehavior` / `minAppVersion` / `screenshots` / `resources`…)。
|
|
@@ -112,6 +130,20 @@ export const RENDERABLE_MANIFEST_FIELDS = [
|
|
|
112
130
|
{ steps: ["contributes", "titleBar", "left", "[]"], field: "label", consumer: "标题栏按钮文本" },
|
|
113
131
|
{ steps: ["contributes", "titleBar", "right", "[]"], field: "label", consumer: "标题栏按钮文本" },
|
|
114
132
|
{ steps: ["contributes", "fileAssociations", "[]"], field: "displayName", consumer: "「打开方式…」选择器显示名" },
|
|
133
|
+
{
|
|
134
|
+
steps: ["contributes", "themes", "[]"],
|
|
135
|
+
field: "label",
|
|
136
|
+
consumer: "主题配方名(主题数据文件缺 name 时的兜底显示名——主题卡片 / 设置页「主题」项)",
|
|
137
|
+
},
|
|
138
|
+
];
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* **主题数据文件里的名字规格**——判的是一份**外部 JSON 文件**(`contributes.themes[].path` 指到的那个),
|
|
142
|
+
* 不是 manifest 内的路径:配方名与配色名都住在那份文件里,manifest 的 `label` 只是兜底。
|
|
143
|
+
*/
|
|
144
|
+
export const THEME_FILE_NAME_FIELDS = [
|
|
145
|
+
{ steps: [], field: "name", consumer: "主题配方名(主题卡片 / 配方名兜底)" },
|
|
146
|
+
{ steps: ["colorways", "[]"], field: "name", consumer: "配色变体名(设置页配色下拉 / 主题选择器第二阶段)" },
|
|
115
147
|
];
|
|
116
148
|
|
|
117
149
|
/** 默认跳过的目录名——构建产物 / 依赖 / 编辑器临时目录 */
|
|
@@ -256,6 +288,53 @@ export function collectRenderableManifestStrings(manifest) {
|
|
|
256
288
|
return out;
|
|
257
289
|
}
|
|
258
290
|
|
|
291
|
+
/**
|
|
292
|
+
* 扫**主题数据文件**里的可渲染中文串 → `[{ text, field, consumer }]` + `problems`。
|
|
293
|
+
*
|
|
294
|
+
* 与 `collectRenderableManifestStrings` 的分工:那条腿只读 `plugin.json` 内部路径,这条腿读
|
|
295
|
+
* `contributes.themes[].path` 指到的**外部 JSON**(所以要 `absRoot`)。读不到 / 解析不动 ⇒ `problems`
|
|
296
|
+
* (调用方据此 `degraded`、跳过判红——一条也读不着时「全是缺口」是假红,同字典那条腿的立论)。
|
|
297
|
+
* `field` 写成 `themes/x.json.colorways[].name` 这种「文件 + 落点」,作者照报错能直接定位。
|
|
298
|
+
*/
|
|
299
|
+
export function collectRenderableThemeStrings(absRoot, manifest) {
|
|
300
|
+
const out = [];
|
|
301
|
+
const problems = [];
|
|
302
|
+
const seen = new Set();
|
|
303
|
+
const themes = manifest?.contributes?.themes;
|
|
304
|
+
if (!Array.isArray(themes)) return { strings: out, problems };
|
|
305
|
+
for (const theme of themes) {
|
|
306
|
+
const rel = theme?.path;
|
|
307
|
+
if (typeof rel !== "string" || !rel) continue; // 没声明 path ⇒ 没有数据文件可判(自洽性归 ci-verify ④ 段)
|
|
308
|
+
let raw;
|
|
309
|
+
try {
|
|
310
|
+
raw = readFileSync(join(absRoot, rel.split("/").join(sep)), "utf8");
|
|
311
|
+
} catch {
|
|
312
|
+
problems.push(`${rel}(contributes.themes[].path 声明但读不到)`);
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
let data;
|
|
316
|
+
try {
|
|
317
|
+
data = JSON.parse(raw);
|
|
318
|
+
} catch (e) {
|
|
319
|
+
problems.push(`${rel} 不是合法 JSON:${e instanceof Error ? e.message : String(e)}`);
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
for (const spec of THEME_FILE_NAME_FIELDS) {
|
|
323
|
+
const tail = `${spec.steps.join(".")}${spec.steps.length ? "." : ""}${spec.field}`.replace(/\.\[\]/g, "[]");
|
|
324
|
+
const field = `${rel}.${tail}`;
|
|
325
|
+
for (const node of resolveSteps(data, spec.steps)) {
|
|
326
|
+
for (const v of fieldValues(node, spec)) {
|
|
327
|
+
if (typeof v !== "string" || !CJK_RE.test(v)) continue;
|
|
328
|
+
if (seen.has(v)) continue;
|
|
329
|
+
seen.add(v);
|
|
330
|
+
out.push({ text: v, field, consumer: spec.consumer });
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
return { strings: out, problems };
|
|
336
|
+
}
|
|
337
|
+
|
|
259
338
|
/**
|
|
260
339
|
* 扫本仓 `src/**` 的 `t("…")` 字面量 key → `[{ key, at: ["src/x.tsx", …] }]`(只收含中文的 key)。
|
|
261
340
|
* 与壳侧 `audit-i18n` 的 G2 分工:那边管**标识符形态**的 key(数据键名误走翻译),这边管**中文** key
|
|
@@ -310,15 +389,29 @@ export function collectSourceTKeys(absRoot, options = {}) {
|
|
|
310
389
|
export function checkOwnDictCoverage(absRoot, options = {}) {
|
|
311
390
|
const manifest = options.manifest;
|
|
312
391
|
const dict = loadOwnDict(absRoot, manifest);
|
|
392
|
+
const themeLeg = collectRenderableThemeStrings(absRoot, manifest);
|
|
393
|
+
// 两条腿合流:同一字面量在两处出现(`themes[].label` 与数据文件 `name` 常同串)只报**首个落点**
|
|
313
394
|
const manifestStrings = collectRenderableManifestStrings(manifest);
|
|
395
|
+
const merged = [...manifestStrings];
|
|
396
|
+
const have = new Set(merged.map((s) => s.text));
|
|
397
|
+
for (const s of themeLeg.strings) {
|
|
398
|
+
if (have.has(s.text)) continue;
|
|
399
|
+
have.add(s.text);
|
|
400
|
+
merged.push(s);
|
|
401
|
+
}
|
|
314
402
|
const sourceKeys = collectSourceTKeys(absRoot, options);
|
|
403
|
+
const problems = [...dict.problems, ...themeLeg.problems];
|
|
315
404
|
return {
|
|
316
405
|
dict,
|
|
317
|
-
scanned: {
|
|
318
|
-
|
|
406
|
+
scanned: {
|
|
407
|
+
manifestStrings: merged.length,
|
|
408
|
+
themeStrings: themeLeg.strings.length,
|
|
409
|
+
sourceKeys: sourceKeys.length,
|
|
410
|
+
},
|
|
411
|
+
manifestGap: merged.filter((s) => !dict.keys.has(s.text)),
|
|
319
412
|
sourceGap: sourceKeys.filter((k) => !dict.keys.has(k.key)),
|
|
320
|
-
degraded: dict.degraded,
|
|
321
|
-
problems
|
|
413
|
+
degraded: dict.degraded || themeLeg.problems.length > 0,
|
|
414
|
+
problems,
|
|
322
415
|
};
|
|
323
416
|
}
|
|
324
417
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@linkdesk/plugin-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.64",
|
|
4
4
|
"description": "@linkdesk/plugin-sdk——LinkDesk 插件作者 SDK(对标 @types/vscode):window.linkdesk.* 类型 + 一键 build(.linkdesk-plugin) + dev 宿主 + plugin.json 验证 + eslint 门禁(E6#54d)。作者 npm i 后零壳源码依赖。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|