designpaca/packages/cli/scripts/verify-package.mjs
Yun Chan eecd3f03ff fix(core,cli): harden install engine and argument parsing
- Reject unknown flags with exit 2 and never write on --dry-run, even in a TTY
- Treat files already matching the new content as up to date after an interrupted update
- Remove unmodified orphan files from older versions, keep and report modified ones and shared paths
- Degrade malformed manifests instead of blocking installs; readIfExists only maps ENOENT/ENOTDIR to null
- Block downgrades from older CLIs (semver), honor uninstall --scope, dedupe targets, fix next-step output and table width
- Deeper package verification, LF normalization for .mjs, MIT LICENSE
2026-10-09 18:18:49 +09:00

84 lines
3.6 KiB
JavaScript

// publish 직전 최종 점검 — 스킬이 빠진 채로 배포되는 사고를 막는다.
import fs from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { isAllowedSkillFile } from "./skill-allowlist.mjs";
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
const must = ["dist/index.js", "dist/skill/SKILL.md", "dist/skill/.designpaca_version", "LICENSE"];
const missing = [];
for (const rel of must) {
try {
await fs.access(path.join(root, rel));
} catch {
missing.push(rel);
}
}
if (missing.length) {
console.error(`배포물에 빠진 파일:\n${missing.map((m) => ` - ${m}`).join("\n")}`);
console.error("pnpm build 를 먼저 실행해라.");
process.exit(1);
}
const pkg = JSON.parse(await fs.readFile(path.join(root, "package.json"), "utf8"));
const stamp = (await fs.readFile(path.join(root, "dist/skill/.designpaca_version"), "utf8")).trim();
if (stamp !== pkg.version) {
console.error(`버전 불일치: package.json=${pkg.version} / 스킬 스탬프=${stamp}`);
process.exit(1);
}
// 허용 목록 밖 파일(테스트·스크래치·.env 등)이 설치물에 섞였으면 배포하지 않는다
const skillDir = path.join(root, "dist/skill");
const unexpected = [];
for (const e of await fs.readdir(skillDir, { recursive: true, withFileTypes: true })) {
if (!e.isFile() && !e.isSymbolicLink()) continue;
const rel = path.relative(skillDir, path.join(e.parentPath ?? e.path, e.name)).split(path.sep).join("/");
if (e.isSymbolicLink() || !isAllowedSkillFile(rel)) unexpected.push(rel);
}
if (unexpected.length) {
console.error(`스킬 설치물에 허용 목록 밖 파일:\n${unexpected.map((m) => ` - ${m}`).join("\n")}`);
console.error("scripts/skill-allowlist.mjs 를 확인하고 pnpm build 를 다시 실행해라.");
process.exit(1);
}
// SKILL.md 가 비었거나 프론트매터가 깨졌거나 본문이 링크한 문서가 빠졌으면 배포하지 않는다
const skillMd = await fs.readFile(path.join(skillDir, "SKILL.md"), "utf8");
if (!skillMd.startsWith("---\nname: designpaca\n")) {
console.error('dist/skill/SKILL.md 의 프론트매터가 "name: designpaca" 로 시작하지 않는다 (비었거나 CRLF·손상)');
process.exit(1);
}
const brokenLinks = [];
for (const m of skillMd.matchAll(/\]\((references\/[^)#\s]+)/g)) {
try {
await fs.access(path.join(skillDir, m[1]));
} catch {
brokenLinks.push(m[1]);
}
}
if (brokenLinks.length) {
const list = [...new Set(brokenLinks)].map((m) => ` - ${m}`).join("\n");
console.error(`SKILL.md 가 링크한 문서가 배포물에 없다:\n${list}`);
process.exit(1);
}
// 텍스트는 LF 여야 한다 — 정규화 대상 확장자가 빠졌을 때 여기서 잡는다
const crlf = [];
for (const e of await fs.readdir(skillDir, { recursive: true, withFileTypes: true })) {
if (!e.isFile() || !/\.(md|txt|json|ya?ml|mjs|c?js)$/.test(e.name)) continue;
const full = path.join(e.parentPath ?? e.path, e.name);
if ((await fs.readFile(full, "utf8")).includes("\r\n")) {
crlf.push(path.relative(skillDir, full).split(path.sep).join("/"));
}
}
if (crlf.length) {
console.error(`CRLF 가 남은 파일:\n${crlf.map((m) => ` - ${m}`).join("\n")}`);
process.exit(1);
}
// 실행 진입점은 첫 줄이 shebang 이어야 한다(tsup banner)
const indexHead = (await fs.readFile(path.join(root, "dist/index.js"), "utf8")).split("\n", 1)[0];
if (indexHead !== "#!/usr/bin/env node") {
console.error("dist/index.js 첫 줄이 shebang 이 아니다 (tsup banner 확인)");
process.exit(1);
}
console.log(`배포 점검 통과 (v${pkg.version})`);