dsh-git-push 3.0.0 → 3.1.0
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/README.md +76 -48
- package/cli.mjs +4 -3
- package/lib/app/apply.js +11 -9
- package/lib/app/command-registry.js +4 -2
- package/lib/app/handlers/http-constants.js +8 -0
- package/lib/app/handlers/preprocess.js +3 -6
- package/lib/app/handlers/repo-actions.js +0 -1
- package/lib/app/handlers/repos.js +137 -10
- package/lib/app/handlers/settings.js +34 -15
- package/lib/app/index.js +1 -1
- package/lib/app/inject-text.js +3 -18
- package/lib/app/schema.js +20 -10
- package/lib/app/settings-bridge.js +60 -8
- package/lib/app/tool-call.js +26 -22
- package/lib/cli/commands-vcs.mjs +35 -1
- package/lib/cli/shared.mjs +1 -1
- package/lib/client/index.js +11 -16
- package/lib/client-parts/git/account.js +21 -12
- package/lib/client-parts/git/actions.js +23 -77
- package/lib/client-parts/git/apply.js +8 -2
- package/lib/client-parts/git/browser.js +1 -1
- package/lib/client-parts/git/const.js +33 -1
- package/lib/client-parts/git/controller.js +175 -176
- package/lib/client-parts/git/icons.js +1 -1
- package/lib/client-parts/git/loader.js +1 -1
- package/lib/client-parts/git/npm.js +56 -37
- package/lib/client-parts/git/page.js +53 -1
- package/lib/client-parts/git/repo.js +8 -1
- package/lib/client-parts/git/settings.js +13 -1
- package/lib/client-parts/git/state.js +237 -0
- package/lib/client-parts/git/utils.js +1 -1
- package/lib/client.js +631 -312
- package/lib/commit-push/pre-commit-engine.js +584 -32
- package/lib/commit-push.js +63 -47
- package/lib/context/index.js +7 -5
- package/lib/core/config.js +1 -27
- package/lib/core/exec.js +2 -11
- package/lib/git/identity-rewrite.js +1 -1
- package/lib/git/index.js +1 -1
- package/lib/git/push.js +2 -17
- package/lib/git/repo-index.js +8 -3
- package/lib/npm/install.js +1 -1
- package/lib/npm/registry.js +2 -2
- package/lib/plugin/auto-push.js +3 -6
- package/lib/preprocess/providers.js +5 -1
- package/lib/self/index.js +1 -1
- package/package.json +4 -7
- package/skills/dev/dsh-git-push.md +9 -9
- package/skills/guide/guide-commit-push.md +11 -13
- package/skills/workflow/README.md +0 -1
- package/skills/workflow/task-completion-report.md +2 -2
- package/.auditignore +0 -30
- package/.gitignore +0 -43
- package/lib/BUGFIX-NOTES-2026-09-14.md +0 -278
- package/lib/app/schema-preprocess.js +0 -42
- package/lib/user-requirements.json +0 -15
- package/scripts/build-client.mjs +0 -133
- package/scripts/bump-version.mjs +0 -178
- package/scripts/check.mjs +0 -205
- package/scripts/doc-func.mjs +0 -212
- package/scripts/doc-tree.mjs +0 -458
- package/scripts/doc-version.mjs +0 -149
- package/scripts/local-registry.mjs +0 -38
- package/scripts/scan-version.mjs +0 -125
- package/scripts/version-source.mjs +0 -173
package/scripts/build-client.mjs
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 客户端分片构建(C8 前提①:构建链落地)
|
|
3
|
-
*
|
|
4
|
-
* 背景与目标(任务.md C8):`lib/client.js` 2585 行整文件入库、没有构建脚本,
|
|
5
|
-
* 维护它是「改一处要看整份 2500 行」。改为**分片源码 + 拼接构建**:
|
|
6
|
-
* 源码在 `lib/client-parts/**.js`(git 维护),`lib/client.js` 是**产物**。
|
|
7
|
-
*
|
|
8
|
-
* ⛔ 形态铁律(client-modules 聚合 bundle 兼容,见 client.js 头部注释):
|
|
9
|
-
* 1. `window.__ModuleLoader__.load` 必须是产物里的**第一条语句**;
|
|
10
|
-
* 2. 全部代码在 `factory` 函数体内,文件顶层【零声明】(防 combo 拼接撞名);
|
|
11
|
-
* 3. 内部命名统一 `dshgp_` 前缀。
|
|
12
|
-
* ⇒ 分片是**片段**(fragment):单个分片不是合法 JS(首片开工厂、尾片收工厂),
|
|
13
|
-
* 只有按 PART_ORDER 拼起来才是完整文件。因此 `scripts/check.mjs` 必须排除
|
|
14
|
-
* `lib/client-parts/`,语法检查只对**产物**做。
|
|
15
|
-
*
|
|
16
|
-
* 产物**逐字节可复现**:分片是原文件的精确切片,拼接即原样还原(`--check` 可校验)。
|
|
17
|
-
*
|
|
18
|
-
* 用法:
|
|
19
|
-
* node scripts/build-client.mjs # 校验产物与分片是否一致,不一致则写回
|
|
20
|
-
* node scripts/build-client.mjs --check # 只校验(CI/提交门禁用;不一致 exit 1)
|
|
21
|
-
* node scripts/build-client.mjs --print # 只打印产物到 stdout(不落盘)
|
|
22
|
-
*/
|
|
23
|
-
import { readFileSync, writeFileSync, existsSync, readdirSync } from 'node:fs';
|
|
24
|
-
import { join, dirname } from 'node:path';
|
|
25
|
-
import { fileURLToPath } from 'node:url';
|
|
26
|
-
|
|
27
|
-
export const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
|
|
28
|
-
// 分片按侧分目录(2026-11-08 UI 与审计解耦):
|
|
29
|
-
// · lib/client-parts/git/** —— git / 发布 / 工具链侧,**参与构建**(本文件的 PARTS_DIR)
|
|
30
|
-
// · lib/client-parts/audit/** —— 审计侧,**不参与构建**(UI 上不再有审计 Tab)
|
|
31
|
-
// 审计侧分片留在源码里可查可改(将来拆成独立项目时整体搬走),但不进产物 ⇒ 不进 UI。
|
|
32
|
-
// 不参与构建的方式:不在 PARTS_DIR 下 ⇒ readParts 的「未登记分片」检查天然扫不到它,
|
|
33
|
-
// 也不会因「缺片」报错(缺片检查只针对 PART_ORDER 里列出的片)。
|
|
34
|
-
export const PARTS_DIR = join(ROOT, 'lib', 'client-parts', 'git');
|
|
35
|
-
/** 不参与构建的分片目录(只做归档,构建脚本不读、不校验)。 */
|
|
36
|
-
// 审计前端分片已随审计能力迁出宿主(现在在 audit-sluice 包的 lib/ui/audit-tab.js)。
|
|
37
|
-
// 这里保留一个只读路径常量供历史脚本引用;目录不存在时调用方应按「无归档分片」处理。
|
|
38
|
-
export const ARCHIVE_PARTS_DIR = join(ROOT, 'lib', 'client-parts', 'audit');
|
|
39
|
-
export const OUT_FILE = join(ROOT, 'lib', 'client.js');
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* 拼接顺序 = 依赖顺序(先定义后使用)。
|
|
43
|
-
* 函数声明会提升、但 `const`/`let` 不会——顺序错会在**运行时**才炸(静态查不出),
|
|
44
|
-
* 所以这里与 client.js 的分节标记 `[N]` 一一对应,改分片必须同步改本表。
|
|
45
|
-
*
|
|
46
|
-
* 命名约定:分片文件名**不带数字序号**(顺序只由本表这一处权威声明)。
|
|
47
|
-
* 序号前缀看似方便,实则会漂移——重排/插片时新旧序号并存,扫目录看到的顺序
|
|
48
|
-
* 与真实拼接顺序不一致,比没有序号更坏。顺序信息集中在 PART_ORDER +
|
|
49
|
-
* 每个分片头注释的「第 N/M 片」锚点,改序只改这两处。
|
|
50
|
-
*/
|
|
51
|
-
export const PART_ORDER = [
|
|
52
|
-
'loader.js', // [1] loader + factory 头 + require + NS(必须首片)
|
|
53
|
-
'const.js', // [2] 常量区(BUSY/维度表/超时/样式串)
|
|
54
|
-
'utils.js', // [3] 工具区(ensureCss/getJson/postJson/tokenConfigured/localGet…)
|
|
55
|
-
'icons.js', // [4] 图标区
|
|
56
|
-
'account.js', // [5] 账号信息 Tab
|
|
57
|
-
'browser.js', // [6] 目录选择器
|
|
58
|
-
'repo.js', // [7] 仓库管理卡
|
|
59
|
-
'npm.js', // [7续] NPM 面板(账号卡 + 装包表单 + npm 凭据字段)
|
|
60
|
-
'settings.js', // [8] 设置 Tab(原第 9 片;审计 Tab 已移出构建)
|
|
61
|
-
'page.js', // [9] 页面装配(GitPushPage,两选项卡)
|
|
62
|
-
'controller.js', // [10] Controller:状态机 + 数据加载
|
|
63
|
-
'actions.js', // [10续] Controller:动作注入
|
|
64
|
-
'apply.js', // [11] 收尾:注册 settings.section + factory 返回(必须末片)
|
|
65
|
-
];
|
|
66
|
-
|
|
67
|
-
/** 读出全部分片内容(缺片直接报错,避免拼出半份产物当成功)。 */
|
|
68
|
-
export function readParts(order = PART_ORDER, dir = PARTS_DIR) {
|
|
69
|
-
const missing = order.filter((f) => !existsSync(join(dir, f)));
|
|
70
|
-
if (missing.length) throw new Error(`缺分片:${missing.join(' / ')}(先按 PART_ORDER 建齐,再构建)`);
|
|
71
|
-
const extra = readdirSync(dir).filter((f) => f.endsWith('.js') && !order.includes(f));
|
|
72
|
-
if (extra.length) throw new Error(`分片未登记进 PART_ORDER:${extra.join(' / ')}(未登记 = 不会进入产物,属静默丢失)`);
|
|
73
|
-
return order.map((f) => readFileSync(join(dir, f), 'utf8'));
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** 拼接产物。分片自带行尾,直接相接即为完整文件(**零加工**:不加头尾换行/不加分隔符)。
|
|
77
|
-
* ⚠️ 原文件不以换行结尾(163020 字节,末行无 \n)——构建若补换行会导致产物比原文多一字节,
|
|
78
|
-
* cmp 直接抓到。等价性要求「拼接 = 原文」,任何后处理都会破坏它。 */
|
|
79
|
-
export function buildClient(order = PART_ORDER, dir = PARTS_DIR) {
|
|
80
|
-
const parts = readParts(order, dir);
|
|
81
|
-
return parts.join('');
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/** 形态铁律自检:产物第一条语句必须是 __ModuleLoader__.load,且含 factory 收尾。 */
|
|
85
|
-
export function checkShape(code) {
|
|
86
|
-
const errs = [];
|
|
87
|
-
const firstStmt = code.replace(/^\/\*\*[\s\S]*?\*\/\s*/, '').trimStart();
|
|
88
|
-
if (!/^window\.__ModuleLoader__\.load\(/.test(firstStmt)) {
|
|
89
|
-
errs.push('产物第一条语句不是 window.__ModuleLoader__.load(...)(第 1 条形态铁律)');
|
|
90
|
-
}
|
|
91
|
-
if (!/^\}\)\(\);\s*$/m.test(code.trimEnd().split('\n').slice(-3).join('\n') + '\n')) {
|
|
92
|
-
// 宽松校验:末尾应能闭合 factory 调用
|
|
93
|
-
if (!/\)\s*;?\s*$/.test(code.trimEnd())) errs.push('产物末尾不像闭合的 load({...}) 调用');
|
|
94
|
-
}
|
|
95
|
-
return errs;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function main(argv = process.argv.slice(2)) {
|
|
99
|
-
const checkOnly = argv.includes('--check');
|
|
100
|
-
const printOnly = argv.includes('--print');
|
|
101
|
-
let built;
|
|
102
|
-
try {
|
|
103
|
-
built = buildClient();
|
|
104
|
-
} catch (e) {
|
|
105
|
-
console.error(`❌ ${e.message}`);
|
|
106
|
-
return 1;
|
|
107
|
-
}
|
|
108
|
-
const errs = checkShape(built);
|
|
109
|
-
if (errs.length) {
|
|
110
|
-
console.error('❌ 形态铁律自检失败:');
|
|
111
|
-
for (const e of errs) console.error(` · ${e}`);
|
|
112
|
-
return 1;
|
|
113
|
-
}
|
|
114
|
-
if (printOnly) { process.stdout.write(built); return 0; }
|
|
115
|
-
const current = existsSync(OUT_FILE) ? readFileSync(OUT_FILE, 'utf8') : '';
|
|
116
|
-
if (current === built) {
|
|
117
|
-
console.log(`✅ 产物与分片一致(${built.split('\n').length - 1} 行,${PART_ORDER.length} 个分片)`);
|
|
118
|
-
return 0;
|
|
119
|
-
}
|
|
120
|
-
if (checkOnly) {
|
|
121
|
-
const a = current.split('\n').length - 1;
|
|
122
|
-
const b = built.split('\n').length - 1;
|
|
123
|
-
console.error(`❌ 产物与分片不一致(现存 ${a} 行 / 应为 ${b} 行)——请跑 node scripts/build-client.mjs 重新生成`);
|
|
124
|
-
return 1;
|
|
125
|
-
}
|
|
126
|
-
writeFileSync(OUT_FILE, built, 'utf8');
|
|
127
|
-
console.log(`✅ 已生成 lib/client.js(${built.split('\n').length - 1} 行,${PART_ORDER.length} 个分片)`);
|
|
128
|
-
return 0;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1]) {
|
|
132
|
-
process.exitCode = main();
|
|
133
|
-
}
|
package/scripts/bump-version.mjs
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* dsh-git-push — 一键版本升版(bump-version)
|
|
4
|
-
*
|
|
5
|
-
* 为什么要有这个脚本:版本号散在三处手工同步,每次发版都要手改
|
|
6
|
-
* ① `package.json` 的 version
|
|
7
|
-
* ② `lib/self/index.js` 的 `export const VERSION = '<v>'; // <v>:说明。历史:…`
|
|
8
|
-
* ③ `docs/releases.json` 新增一条 `<v>: "说明"`
|
|
9
|
-
* 少改一处就会被 doc-version / version-drift 门禁判为漂移,而这两处还各带长文本
|
|
10
|
-
* (VERSION 行还挂着历史链),手改既慢又容易写坏引号、破坏 JSON。
|
|
11
|
-
* 第 4 处(README 版本表 / CHANGELOG)已由 doc-version.mjs 从上面两处生成,无需手改。
|
|
12
|
-
*
|
|
13
|
-
* 用法:
|
|
14
|
-
* node scripts/bump-version.mjs --message "本次做了什么" # 预览(默认 dry-run)
|
|
15
|
-
* node scripts/bump-version.mjs --message "…" --apply # 真写盘
|
|
16
|
-
* node scripts/bump-version.mjs --to 2.11.0 --message "…" --apply # 指定版本(默认 patch +1)
|
|
17
|
-
* node scripts/bump-version.mjs --message-file /tmp/msg.txt --apply
|
|
18
|
-
* node scripts/bump-version.mjs --message "…" --comment "VERSION 行用的短摘要(可选)" --apply
|
|
19
|
-
*
|
|
20
|
-
* 约定:
|
|
21
|
-
* · **默认 dry-run**——只打印将要改动的三处(旧值 → 新值),不落盘;确认无误再加 --apply。
|
|
22
|
-
* (与 npm_publish / install-plugin 同口径:有副作用的动作先看预览再执行)
|
|
23
|
-
* · `--message` 必填:发版说明不能凭空生成,属于「人写内容」,脚本只负责把它同步到三处。
|
|
24
|
-
* · VERSION 行的历史链保留最近 2 个版本摘要,避免注释无限变长(沿用既有风格)。
|
|
25
|
-
* · 写完自动重生成版本文档(doc-version apply / doc-func apply / doc-tree sync+apply),
|
|
26
|
-
* 因为版本号一变,CHANGELOG 与函数索引必须跟着走,否则门禁立刻报漂移。
|
|
27
|
-
*/
|
|
28
|
-
import { readFileSync, writeFileSync } from 'node:fs';
|
|
29
|
-
import { join, dirname } from 'node:path';
|
|
30
|
-
import { fileURLToPath } from 'node:url';
|
|
31
|
-
import { execFileSync } from 'node:child_process';
|
|
32
|
-
|
|
33
|
-
const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
|
|
34
|
-
const PKG = join(ROOT, 'package.json');
|
|
35
|
-
const SELF = join(ROOT, 'lib', 'self', 'index.js');
|
|
36
|
-
const RELEASES = join(ROOT, 'docs', 'releases.json');
|
|
37
|
-
|
|
38
|
-
/** 解析命令行参数(只认 --flag value 与布尔 --apply)。 */
|
|
39
|
-
function parseArgs(argv) {
|
|
40
|
-
const out = { apply: false, to: '', message: '', messageFile: '', comment: '' };
|
|
41
|
-
for (let i = 0; i < argv.length; i++) {
|
|
42
|
-
const a = argv[i];
|
|
43
|
-
if (a === '--apply') { out.apply = true; continue; }
|
|
44
|
-
if (a === '--message' || a === '-m') { out.message = argv[++i] || ''; continue; }
|
|
45
|
-
if (a === '--message-file') { out.messageFile = argv[++i] || ''; continue; }
|
|
46
|
-
if (a === '--to') { out.to = argv[++i] || ''; continue; }
|
|
47
|
-
if (a === '--comment') { out.comment = argv[++i] || ''; continue; }
|
|
48
|
-
}
|
|
49
|
-
return out;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const fail = (msg) => { console.error('✗ ' + msg); process.exit(1); };
|
|
53
|
-
|
|
54
|
-
/** 语义化版本比较:a < b 返回负。只支持 x.y.z。 */
|
|
55
|
-
function cmpVer(a, b) {
|
|
56
|
-
const pa = String(a).split('.').map(Number);
|
|
57
|
-
const pb = String(b).split('.').map(Number);
|
|
58
|
-
for (let i = 0; i < 3; i++) if ((pa[i] || 0) !== (pb[i] || 0)) return (pa[i] || 0) - (pb[i] || 0);
|
|
59
|
-
return 0;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/** patch +1:默认每次提交升第三位(version-discipline 的既有口径)。 */
|
|
63
|
-
function bumpPatch(v) {
|
|
64
|
-
const [x, y, z] = String(v).split('.').map(Number);
|
|
65
|
-
return `${x}.${y}.${(z || 0) + 1}`;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function readJson(p) {
|
|
69
|
-
try { return JSON.parse(readFileSync(p, 'utf8')); } catch (e) { fail(`${p} 解析失败:${e.message}`); }
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* 拼新的 VERSION 行。
|
|
74
|
-
* 旧注释形如:`2.10.4:本次说明。历史:2.10.3:更早说明。` → 把「本次说明」降级进历史链,
|
|
75
|
-
* 只保留最近 2 条,避免每版都把整串历史再抄一遍(实测 2.9.x 之后该行已接近不可读)。
|
|
76
|
-
*
|
|
77
|
-
* ⚠️ **行注释必须单行**:`--message-file` 常带多段落,若原样写进 `//` 后面的注释,
|
|
78
|
-
* 换行会把文件撕成多行 → 整个 lib/self/index.js 语法错误(ESM 加载期就炸,
|
|
79
|
-
* `node cli.mjs` 直接 TypeError)。故此处按「首段首句」压成一行摘要,
|
|
80
|
-
* 正文完整内容仍原样进 docs/releases.json(那边是 JSON 字符串,换行合法)。
|
|
81
|
-
* 需要更长摘要时用 `--comment` 显式给。
|
|
82
|
-
*/
|
|
83
|
-
function buildVersionLine(oldLine, newVer, oldVer, message, commentOverride = '') {
|
|
84
|
-
const m = /export const VERSION = '([^']+)';\s*\/\/(.*)$/.exec(oldLine);
|
|
85
|
-
const oldComment = m ? m[2].trim() : '';
|
|
86
|
-
// 旧版本的「本次说明」= 历史链之前的那一段
|
|
87
|
-
const histIdx = oldComment.indexOf('历史:');
|
|
88
|
-
const oldMain = (histIdx >= 0 ? oldComment.slice(0, histIdx) : oldComment).replace(/^[\d.]+\s*[::]\s*/, '').trim();
|
|
89
|
-
const oldHist = histIdx >= 0 ? oldComment.slice(histIdx + '历史:'.length).trim() : '';
|
|
90
|
-
// 历史链:新压入的旧版摘要 + 原有最近 1 条
|
|
91
|
-
const prev = oldMain ? [`${oldVer}:${oldMain}`] : [];
|
|
92
|
-
const kept = oldHist ? oldHist.split(/。\s*(?=[\d.]+:)/).slice(0, 1).map((s) => s.replace(/。$/, '')) : [];
|
|
93
|
-
const chain = prev.length || kept.length ? [...prev, ...kept].join('。').replace(/。+/g, '。') : '';
|
|
94
|
-
// 本轮摘要:显式覆盖优先;否则取首段首句,超长截断
|
|
95
|
-
const oneLine = String(commentOverride || message).replace(/\s+/g, ' ').trim();
|
|
96
|
-
const firstSentence = oneLine.split(/。/)[0].trim();
|
|
97
|
-
const summary = firstSentence.length > 160 ? `${firstSentence.slice(0, 160)}…` : firstSentence;
|
|
98
|
-
const comment = `${newVer}:${summary}。` + (chain ? `历史:${chain}。` : '');
|
|
99
|
-
return `export const VERSION = '${newVer}'; // ${comment}`;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const args = parseArgs(process.argv.slice(2));
|
|
103
|
-
const pkg = readJson(PKG);
|
|
104
|
-
const cur = String(pkg.version || '');
|
|
105
|
-
const target = args.to || bumpPatch(cur);
|
|
106
|
-
let message = args.message;
|
|
107
|
-
if (args.messageFile) {
|
|
108
|
-
try { message = readFileSync(args.messageFile, 'utf8').trim(); } catch (e) { fail(`--message-file 读取失败:${e.message}`); }
|
|
109
|
-
}
|
|
110
|
-
if (!/^\d+\.\d+\.\d+$/.test(target)) fail(`版本号必须为 x.y.z:${target}`);
|
|
111
|
-
if (cmpVer(target, cur) <= 0) fail(`目标版本 ${target} 必须大于当前 ${cur}`);
|
|
112
|
-
if (!message) fail('缺少 --message(发版说明需人写;或从 --message-file 读取)');
|
|
113
|
-
|
|
114
|
-
const releases = readJson(RELEASES);
|
|
115
|
-
if (releases[target]) fail(`docs/releases.json 已存在 ${target} 条目(不要重复升版)`);
|
|
116
|
-
|
|
117
|
-
const selfSrc = readFileSync(SELF, 'utf8');
|
|
118
|
-
const selfLines = selfSrc.split('\n');
|
|
119
|
-
const vi = selfLines.findIndex((l) => /^export const VERSION = '/.test(l));
|
|
120
|
-
if (vi < 0) fail('lib/self/index.js 未找到 VERSION 行');
|
|
121
|
-
const oldLine = selfLines[vi];
|
|
122
|
-
const newLine = buildVersionLine(oldLine, target, cur, message, args.comment);
|
|
123
|
-
// 硬门禁:行注释一旦带换行就把整个 lib/self/index.js 撕成多行(ESM 加载期直接抛
|
|
124
|
-
// "Invalid or unexpected token",cli.mjs / 插件入口全部起不来)。宁可在写盘前失败。
|
|
125
|
-
if (/[\r\n]/.test(newLine)) fail('VERSION 行必须是单行(注释里的换行会破坏整个模块语法)');
|
|
126
|
-
|
|
127
|
-
// ── 预览(默认 dry-run)
|
|
128
|
-
console.log(`升版:${cur} → ${target}${args.apply ? '(--apply 真写盘)' : '(dry-run,未写盘)'}`);
|
|
129
|
-
console.log('\n① package.json');
|
|
130
|
-
console.log(` - "version": "${cur}"`);
|
|
131
|
-
console.log(` + "version": "${target}"`);
|
|
132
|
-
console.log('\n② lib/self/index.js(VERSION 行)');
|
|
133
|
-
console.log(` - ${oldLine.slice(0, 90)}…`);
|
|
134
|
-
console.log(` + ${newLine.slice(0, 90)}…`);
|
|
135
|
-
console.log('\n③ docs/releases.json');
|
|
136
|
-
console.log(` + "${target}": "${message.slice(0, 70)}${message.length > 70 ? '…' : ''}"`);
|
|
137
|
-
console.log('\n④ 随后自动重生成:docs/CHANGELOG.md(doc-version)、docs/FUNCTIONS.md(doc-func)、tree-doc.json(doc-tree)');
|
|
138
|
-
|
|
139
|
-
if (!args.apply) {
|
|
140
|
-
console.log('\n确认无误后追加 --apply 才会写盘。');
|
|
141
|
-
process.exit(0);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// ── 写盘
|
|
145
|
-
// 注意:本仓库在 CIFS 挂载上,write/edit 工具会因 chmod 报 EPERM;脚本用 fs 直接写
|
|
146
|
-
// 普通文件(不触发 chmod),这正是把它脚本化的额外收益。
|
|
147
|
-
const newPkgText = readFileSync(PKG, 'utf8').replace(
|
|
148
|
-
/("version"\s*:\s*")[^"]+(")/,
|
|
149
|
-
`$1${target}$2`,
|
|
150
|
-
);
|
|
151
|
-
if (newPkgText === readFileSync(PKG, 'utf8')) fail('package.json 的 version 未替换成功(正则未命中)');
|
|
152
|
-
writeFileSync(PKG, newPkgText);
|
|
153
|
-
|
|
154
|
-
selfLines[vi] = newLine;
|
|
155
|
-
writeFileSync(SELF, selfLines.join('\n'));
|
|
156
|
-
|
|
157
|
-
const merged = { ...releases };
|
|
158
|
-
merged[target] = message;
|
|
159
|
-
// 按语义化版本排序,保持文件可读(原文件即按版本升序)
|
|
160
|
-
const sorted = {};
|
|
161
|
-
for (const k of Object.keys(merged).sort(cmpVer)) sorted[k] = merged[k];
|
|
162
|
-
writeFileSync(RELEASES, JSON.stringify(sorted, null, 2) + '\n');
|
|
163
|
-
|
|
164
|
-
console.log('\n✔ 三处已写入,重生成派生文档…');
|
|
165
|
-
for (const cmd of [
|
|
166
|
-
['scripts/doc-version.mjs', ['apply']],
|
|
167
|
-
['scripts/doc-func.mjs', ['apply']],
|
|
168
|
-
['scripts/doc-tree.mjs', ['sync']],
|
|
169
|
-
['scripts/doc-tree.mjs', ['apply']],
|
|
170
|
-
]) {
|
|
171
|
-
try {
|
|
172
|
-
execFileSync(process.execPath, [join(ROOT, cmd[0]), ...cmd[1]], { cwd: ROOT, stdio: 'pipe', encoding: 'utf8' });
|
|
173
|
-
console.log(` ✔ ${cmd[0]} ${cmd[1].join(' ')}`);
|
|
174
|
-
} catch (e) {
|
|
175
|
-
console.error(` ✗ ${cmd[0]} 失败:${String(e?.stdout || e?.stderr || e).split('\n')[0]}`);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
console.log(`\n完成:${cur} → ${target}。请跑 node scripts/doc-version.mjs check 与全量回归确认门禁绿。`);
|
package/scripts/check.mjs
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* 语法检查脚本(npm run check)
|
|
4
|
-
* 递归检查 lib/****.js + cli.mjs 语法;任一失败退出 1(checkSyncInAsync 的脚本侧实现)。
|
|
5
|
-
*
|
|
6
|
-
* 2026-10-09(任务.md C8 分片改造)新增两条:
|
|
7
|
-
* ① **跳过 `lib/client-parts/`**:那是客户端**分片源码**——单个分片是片段(首片开 `factory`、
|
|
8
|
-
* 尾片收尾),单独 `node --check` 必然失败;语法检查只对**产物** `lib/client.js` 做。
|
|
9
|
-
* ② **产物新鲜度门禁**:`lib/client.js` 必须与分片按 PART_ORDER 拼出来的一致,
|
|
10
|
-
* 防止有人直接手改产物(下次构建就被覆盖,改动静默丢失)。
|
|
11
|
-
*/
|
|
12
|
-
import { execFileSync } from 'node:child_process';
|
|
13
|
-
import { readdirSync, statSync, readFileSync } from 'node:fs';
|
|
14
|
-
import { join, dirname } from 'node:path';
|
|
15
|
-
import { fileURLToPath } from 'node:url';
|
|
16
|
-
import { buildClient } from './build-client.mjs';
|
|
17
|
-
|
|
18
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
19
|
-
const ROOT = join(__dirname, '..');
|
|
20
|
-
|
|
21
|
-
/** 递归收集 .js 文件(跳过 node_modules、点开头目录,以及分片目录 client-parts)。 */
|
|
22
|
-
function collectJs(dir, acc = []) {
|
|
23
|
-
for (const name of readdirSync(dir)) {
|
|
24
|
-
if (name === 'node_modules' || name.startsWith('.')) continue;
|
|
25
|
-
if (name === 'client-parts') continue; // 分片是片段,见文件头 ①
|
|
26
|
-
const p = join(dir, name);
|
|
27
|
-
if (statSync(p).isDirectory()) collectJs(p, acc);
|
|
28
|
-
else if (name.endsWith('.js')) acc.push(p);
|
|
29
|
-
}
|
|
30
|
-
return acc;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** 递归收集 .json(同样的跳过规则,但不跳过 client-parts——那里没有 .json)。 */
|
|
34
|
-
function collectJson(dir, acc = []) {
|
|
35
|
-
for (const name of readdirSync(dir)) {
|
|
36
|
-
if (name === 'node_modules' || name.startsWith('.')) continue;
|
|
37
|
-
const p = join(dir, name);
|
|
38
|
-
if (statSync(p).isDirectory()) collectJson(p, acc);
|
|
39
|
-
else if (name.endsWith('.json')) acc.push(p);
|
|
40
|
-
}
|
|
41
|
-
return acc;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// 三个 CLI 入口都要做语法检查:它们不是 lib/ 下的文件,靠 collectJs 收不到——
|
|
45
|
-
// 漏检的后果是「新入口语法错,但门禁全绿」(与被拆出来的入口一起构成盲区)。
|
|
46
|
-
// 只检查现存入口:审计 CLI 已随审计能力独立成包(audit-sluice),宿主不再提供 cli-audit.mjs。
|
|
47
|
-
const CLI_ENTRY_FILES = ['cli.mjs', 'cli-tool.mjs'];
|
|
48
|
-
const CLI_ENTRIES = CLI_ENTRY_FILES.map((name) => join(ROOT, name));
|
|
49
|
-
const files = [...collectJs(join(ROOT, 'lib')), ...CLI_ENTRIES];
|
|
50
|
-
// docs/*.json 也必须能解析:版本表与发版说明直接依赖 docs/releases.json,
|
|
51
|
-
// 而它曾在 2.8.4 因一个尾随逗号变成非法 JSON 却**四项门禁全绿**(缺口)——这类错误必须在门禁里变红 ✗
|
|
52
|
-
const jsonFiles = [...collectJson(join(ROOT, 'lib')), ...collectJson(join(ROOT, 'docs'))];
|
|
53
|
-
let fail = 0;
|
|
54
|
-
let jsonFail = 0;
|
|
55
|
-
for (const f of files) {
|
|
56
|
-
try {
|
|
57
|
-
execFileSync(process.execPath, ['--check', f], { stdio: 'pipe', encoding: 'utf8' });
|
|
58
|
-
console.log(`✔ ${f.replace(ROOT + '/', '')}`);
|
|
59
|
-
} catch (e) {
|
|
60
|
-
fail++;
|
|
61
|
-
console.error(`✗ ${f.replace(ROOT + '/', '')}: ${String(e?.stderr || e).trim().split('\n')[0]}`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// JSON 可解析性门禁(独立计数,不并入上面的语法通过率)
|
|
66
|
-
for (const f of jsonFiles) {
|
|
67
|
-
try {
|
|
68
|
-
JSON.parse(readFileSync(f, 'utf8'));
|
|
69
|
-
console.log(`✔ ${f.replace(ROOT + '/', '')}`);
|
|
70
|
-
} catch (e) {
|
|
71
|
-
jsonFail++;
|
|
72
|
-
console.error(`✗ ${f.replace(ROOT + '/', '')}: JSON 解析失败——${String(e?.message || e).split('\n')[0]}`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// 产物新鲜度:client.js 必须是分片构建出来的那一份
|
|
77
|
-
try {
|
|
78
|
-
const built = buildClient();
|
|
79
|
-
const current = readFileSync(join(ROOT, 'lib', 'client.js'), 'utf8');
|
|
80
|
-
if (built === current) {
|
|
81
|
-
console.log('✔ lib/client.js 与分片一致(构建产物新鲜)');
|
|
82
|
-
} else {
|
|
83
|
-
fail++;
|
|
84
|
-
console.error('✗ lib/client.js 与分片不一致——请运行 node scripts/build-client.mjs 重新生成(不要手改产物)');
|
|
85
|
-
}
|
|
86
|
-
} catch (e) {
|
|
87
|
-
fail++;
|
|
88
|
-
console.error(`✗ 分片构建校验失败:${e.message}`);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// ── 拼接产物作用域门禁(2026-11-05)───────────────────────────────────
|
|
92
|
-
// 背景:lib/client-parts/*.js 是**平铺拼接**的片段,14 个分片最终落在**同一个 factory
|
|
93
|
-
// 函数作用域**里。JS 的 var/function 提升规则是「同名后者覆盖前者且不报错」——
|
|
94
|
-
// 一处重名就让某分片功能在运行时静默失效,且没有任何报错可查。
|
|
95
|
-
// 构建脚本头部早写了「顶层零声明 + dshgp_ 前缀」两条铁律,但此前**只是注释**:
|
|
96
|
-
// 新鲜度门禁只保证「产物 == 分片拼接」,保证不了「拼出来的不撞名」。
|
|
97
|
-
// 检查项(通用实现在 lib/ast/scope-collisions.js,项目差异走 package.json 的 dshScopeCheck):
|
|
98
|
-
// ① 同作用域重名(var/function 静默覆盖的触发条件,始终检查);
|
|
99
|
-
// ② 文件顶层零声明;③ 共享作用域命名前缀。
|
|
100
|
-
try {
|
|
101
|
-
const { analyzeScopeCollisions } = await import('../../audit-sluice/lib/ast/scope-collisions.js');
|
|
102
|
-
const pkg = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8'));
|
|
103
|
-
const cfg = pkg?.dshScopeCheck;
|
|
104
|
-
const files = Array.isArray(cfg?.files) && cfg.files.length ? cfg.files : [];
|
|
105
|
-
if (!files.length) {
|
|
106
|
-
console.log('✔ 拼接产物作用域:未配置 dshScopeCheck.files,跳过');
|
|
107
|
-
}
|
|
108
|
-
for (const rel of files) {
|
|
109
|
-
const abs = join(ROOT, rel);
|
|
110
|
-
const scope = analyzeScopeCollisions(readFileSync(abs, 'utf8'), {
|
|
111
|
-
prefix: String(cfg.prefix || ''),
|
|
112
|
-
allowlist: Array.isArray(cfg.allowlist) ? cfg.allowlist.map(String) : [],
|
|
113
|
-
topLevelMustBeEmpty: cfg.topLevelMustBeEmpty !== false,
|
|
114
|
-
});
|
|
115
|
-
if (scope.ok) {
|
|
116
|
-
console.log(`✔ ${rel} 作用域契约(顶层零声明 · 共享作用域 ${scope.declarations.filter((d) => d.frameId === scope.sharedFrameId).length} 个声明均合规 · 无同帧重名)`);
|
|
117
|
-
} else {
|
|
118
|
-
fail += 1;
|
|
119
|
-
for (const v of scope.violations) console.error(`✗ ${rel} 作用域:${v}`);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
} catch (e) {
|
|
123
|
-
fail += 1;
|
|
124
|
-
console.error(`✗ 拼接产物作用域检查失败:${e.message}`);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// ── 层边界门禁(2026-10-24)────────────────────────────────────────────
|
|
128
|
-
// 背景:审计引擎与提交推送**决定不拆成两个 npm 包**(拆包的持续成本——双包版本同步、
|
|
129
|
-
// 固定发布顺序、依赖范围——换不到真实收益:外部使用者要的是「提交前拦截」这个整体,
|
|
130
|
-
// 而「脱离 DSH 跑审计」已由 cli.mjs 的独立 CLI 覆盖)。
|
|
131
|
-
// 但不拆包不等于放弃边界:审计层对 git 层是**实测零依赖**,这个事实一旦被顺手 import
|
|
132
|
-
// 侵蚀就再也回不来(历史包袱太重 = 不可逆)。所以把它钉成门禁。
|
|
133
|
-
// 不变量:
|
|
134
|
-
// ① 审计层任何文件都不得 import git/npm/commit-push 层(方向唯一:git → audit);
|
|
135
|
-
// ② 反向接缝数量有预算上限——允许存在(提交门禁必须调审计),但要能看见它在膨胀。
|
|
136
|
-
// lint-adapter(外部 linter 委托层)纳入审计层口径:编排层(audit)直接依赖它 ⇒ 它属于审计子图,
|
|
137
|
-
// 同样不得伸手 git 层(委托层只读项目文件 + 跑外部二进制,不需要凭据/git)。
|
|
138
|
-
const AUDIT_DIRS = new Set(['ast', 'audit', 'audit-rules', 'checks', 'exempt', 'rule', 'score', 'lint-adapter']);
|
|
139
|
-
const GIT_DIRS = new Set(['git', 'npm']);
|
|
140
|
-
const GIT_TOP = new Set(['commit-push.js']);
|
|
141
|
-
const AUDIT_TOP = new Set(['audit-defaults.js', 'skip-dirs.js']);
|
|
142
|
-
/**
|
|
143
|
-
* 反向接缝预算:实测 **5 处**;上调需写明理由。
|
|
144
|
-
*
|
|
145
|
-
* 2026-11-13 从 7 降到 5:提交前预处理解耦后,`lib/commit-push.js` 不再 import `audit/index.js` 与
|
|
146
|
-
* `score/index.js`(改调外部引擎子进程),只剩 `exempt/index.js` 这一条(示例目录豁免要用)。
|
|
147
|
-
* 预算跟着实收紧,是为了让这个成果**被门禁钉住**——以后谁再往 git 侧加审计 import,5→6 就会红。
|
|
148
|
-
*/
|
|
149
|
-
const SEAM_BUDGET = 5;
|
|
150
|
-
|
|
151
|
-
const layerOf = (rel) => {
|
|
152
|
-
const top = rel.split('/')[0];
|
|
153
|
-
if (rel.includes('/') && AUDIT_DIRS.has(top)) return 'AUDIT';
|
|
154
|
-
if (rel.includes('/') && GIT_DIRS.has(top)) return 'GIT';
|
|
155
|
-
if (!rel.includes('/') && GIT_TOP.has(rel)) return 'GIT';
|
|
156
|
-
if (!rel.includes('/') && AUDIT_TOP.has(rel)) return 'AUDIT';
|
|
157
|
-
return 'OTHER';
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
let boundaryViolations = 0;
|
|
161
|
-
const seams = [];
|
|
162
|
-
for (const f of files) {
|
|
163
|
-
const rel = f.replace(ROOT + '/', '');
|
|
164
|
-
if (!rel.startsWith('lib/')) continue;
|
|
165
|
-
const inner = rel.slice('lib/'.length);
|
|
166
|
-
if (layerOf(inner) !== 'AUDIT') continue;
|
|
167
|
-
let src = '';
|
|
168
|
-
try { src = readFileSync(f, 'utf8'); } catch { continue; }
|
|
169
|
-
for (const m of src.matchAll(/from\s+['"](\.[^'"]+)['"]/g)) {
|
|
170
|
-
const target = join(dirname(f), m[1]).replace(ROOT + '/lib/', '');
|
|
171
|
-
if (layerOf(target) === 'GIT') {
|
|
172
|
-
boundaryViolations++;
|
|
173
|
-
console.error(`✗ 层边界违规:审计层 lib/${inner} import 了 git 层 ${m[1]}(审计引擎解耦)`);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
// 反向接缝统计(允许,但要可见)
|
|
178
|
-
for (const f of files) {
|
|
179
|
-
const rel = f.replace(ROOT + '/', '');
|
|
180
|
-
if (!rel.startsWith('lib/')) continue;
|
|
181
|
-
const inner = rel.slice('lib/'.length);
|
|
182
|
-
if (layerOf(inner) !== 'GIT') continue;
|
|
183
|
-
let src = '';
|
|
184
|
-
try { src = readFileSync(f, 'utf8'); } catch { continue; }
|
|
185
|
-
for (const m of src.matchAll(/from\s+['"](\.[^'"]+)['"]/g)) {
|
|
186
|
-
const target = join(dirname(f), m[1]).replace(ROOT + '/lib/', '');
|
|
187
|
-
if (layerOf(target) === 'AUDIT') seams.push(`${inner} → ${target}`);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
if (boundaryViolations) {
|
|
191
|
-
fail += boundaryViolations;
|
|
192
|
-
console.error(`✗ 层边界:${boundaryViolations} 处违规——审计层不得依赖 git/npm/commit-push`);
|
|
193
|
-
} else {
|
|
194
|
-
console.log(`✔ 层边界:审计层对 git 层 0 依赖(解耦成立)`);
|
|
195
|
-
}
|
|
196
|
-
if (seams.length > SEAM_BUDGET) {
|
|
197
|
-
fail++;
|
|
198
|
-
console.error(`✗ 反向接缝 ${seams.length} 处 > 预算 ${SEAM_BUDGET}:提交门禁调审计是必需的,但膨胀说明边界在糊掉——要么收敛,要么改预算并写明理由`);
|
|
199
|
-
} else {
|
|
200
|
-
console.log(`✔ 反向接缝(git → audit,唯一耦合面):${seams.length}/${SEAM_BUDGET} 处`);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
console.log(`\n${files.length - fail}/${files.length} 文件语法通过`);
|
|
204
|
-
console.log(`${jsonFiles.length - jsonFail}/${jsonFiles.length} 个 JSON 可解析`);
|
|
205
|
-
process.exitCode = (fail > 0 || jsonFail > 0) ? 1 : 0;
|