Skip to content

Commit 51c32d2

Browse files
chore(ci): 恢复 check-sync.js(v0.7.12 重写删除,但 CI/发布闸门仍引用)
v0.7.12(dd0ed78)重写时误删了 scripts/check-sync.js,而 ci.yml 的 「Sync check (src↔lib)」步骤、release.yml 的 test job 都引用它(node scripts/check-sync.js)。 历史教训 PR #60 → issue #65:只改 src 忘同步 lib,发布包跑旧代码。此脚本是发布前 src/↔lib/ 一致性守门,v0.7.9 引入(f5e6cbe),本 PR 恢复并纳入新 CI 流水线。 Co-Authored-By: Anans-Ivresse <[email protected]>
1 parent dbc3f02 commit 51c32d2

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

‎dsh-mneme/scripts/check-sync.js‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// 发布前校验 src/ 与 lib/ 一致性。
2+
//
3+
// npm 包实际加载 lib/(package main → lib/index.js),而 root 层 `npm publish`
4+
// 不触发 dsh-mneme/ 的 prepack → sync 同步。历史教训:PR #60 只改了 src 忘了同步
5+
// lib,v0.7.8 发出去的 npm 包跑的还是旧代码(issue #65)。此脚本让这类漂移在发布时
6+
// 直接 fail,而不是带着旧产物上线。
7+
//
8+
// 用法:node scripts/check-sync.js (root package.json 的 prepack 钩子自动调用)
9+
import { existsSync, readFileSync, readdirSync } from "node:fs";
10+
import { join, relative } from "node:path";
11+
import { fileURLToPath } from "node:url";
12+
13+
const root = join(fileURLToPath(new URL("..", import.meta.url))); // dsh-mneme/
14+
const srcDir = join(root, "src");
15+
const libDir = join(root, "lib");
16+
17+
function walk(dir) {
18+
const out = [];
19+
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
20+
const full = join(dir, entry.name);
21+
if (entry.isDirectory()) out.push(...walk(full));
22+
else if (entry.isFile()) out.push(full);
23+
}
24+
return out;
25+
}
26+
27+
const bad = [];
28+
for (const file of walk(srcDir)) {
29+
const rel = relative(srcDir, file);
30+
const dest = join(libDir, rel);
31+
if (!existsSync(dest)) {
32+
bad.push(`missing lib/${rel}`);
33+
} else if (!readFileSync(file).equals(readFileSync(dest))) {
34+
bad.push(`differ lib/${rel}`);
35+
}
36+
}
37+
if (bad.length) {
38+
console.error(`✗ src/ 与 lib/ 不一致(${bad.length} 处)——npm 包实际加载 lib/,请先 npm run sync 并提交:`);
39+
for (const line of bad) console.error(` ${line}`);
40+
process.exit(1);
41+
}
42+
console.log(`✓ src/ 与 lib/ 一致(${walk(srcDir).length} 个文件)`);

0 commit comments

Comments
 (0)