改包名为 @sidaocai/dsh-markmag 时漏了 dist/client.js 的 factory id, 导致 DSH 判定重复注册、插件加载失败,进而把 profile 的 bundles 从 13 个重置成 2 个。 修复: - client bundle 的 id 与包名对齐 - 新增 scripts/repair-profile.mjs 从备份恢复 bundles - package.json 补 publishConfig(锁定私有 registry)/ prepack / prepublishOnly - 新增 scripts/preflight.mjs 发布前七项检查 - 文档记录改包名必须同步的四处(踩坑记录)
60 lines
2.4 KiB
JavaScript
60 lines
2.4 KiB
JavaScript
#!/usr/bin/env node
|
||
/**
|
||
* 修复桌面版 profile 的 bundles 列表。
|
||
*
|
||
* 背景:2026-11-07 改包名后 DSH 启动失败,它自己把 bundles 从 12 个重置成 2 个
|
||
* (只剩官方 base + web-app),第三方插件全被移除。这个脚本从备份恢复。
|
||
*
|
||
* 幂等:跑几次结果一样。
|
||
*/
|
||
import fs from "node:fs"
|
||
import { homedir } from "node:os"
|
||
import { join } from "node:path"
|
||
|
||
const P = join(homedir(), ".dsh/profiles/desktop")
|
||
const PKG = join(P, "package.json")
|
||
const BAK = join(P, "package.json.bak-20261107-plugin")
|
||
const PLUGIN = "@sidaocai/dsh-markmag"
|
||
const LEGACY = "dsh-markmag"
|
||
|
||
const log = (k, v) => console.log(k.padEnd(14), v)
|
||
const die = (m) => { console.error("✗ " + m); process.exit(1) }
|
||
|
||
if (!fs.existsSync(PKG)) die("没找到 " + PKG)
|
||
if (!fs.existsSync(BAK)) die("没找到备份 " + BAK + "(没有它无法恢复 bundles)")
|
||
|
||
const cur = JSON.parse(fs.readFileSync(PKG, "utf8"))
|
||
const bak = JSON.parse(fs.readFileSync(BAK, "utf8"))
|
||
|
||
// 备份里有完整 12 项;保留当前 dependencies(含新包名)
|
||
const restored = (bak.dsh?.profile?.bundles || []).filter((b) => b !== LEGACY)
|
||
if (!restored.includes(PLUGIN)) restored.push(PLUGIN)
|
||
|
||
log("bundles 恢复:", (cur.dsh?.profile?.bundles || []).length + " → " + restored.length)
|
||
|
||
cur.dsh ??= {}
|
||
cur.dsh.profile ??= {}
|
||
cur.dsh.profile.bundles = restored
|
||
cur.dependencies ??= {}
|
||
delete cur.dependencies[LEGACY]
|
||
if (!cur.dependencies[PLUGIN]) cur.dependencies[PLUGIN] = "file:" + join(homedir(), "Documents/Essay_AI/Essay_system/dsh-markmag")
|
||
|
||
// 先备份当前(可能已被 DSH 重置)的版本
|
||
fs.copyFileSync(PKG, PKG + ".bak-repair-" + Date.now())
|
||
fs.writeFileSync(PKG, JSON.stringify(cur, null, 2) + "\n")
|
||
|
||
const out = JSON.parse(fs.readFileSync(PKG, "utf8"))
|
||
const checks = {
|
||
bundleCount: out.dsh.profile.bundles.length,
|
||
hasMediaDesk: out.dsh.profile.bundles.includes("dsh-media-desk"),
|
||
hasContext: out.dsh.profile.bundles.includes("dsh-context"),
|
||
hasOpenviking: out.dsh.profile.bundles.includes("@openviking/dsh-memory-plugin"),
|
||
hasMarkmag: out.dsh.profile.bundles.includes(PLUGIN),
|
||
noLegacy: !out.dsh.profile.bundles.includes(LEGACY),
|
||
}
|
||
log("SELF_CHECK", JSON.stringify(checks))
|
||
if (checks.bundleCount !== restored.length || !checks.hasMarkmag || !checks.hasMediaDesk) {
|
||
console.log("\n✗ 自检没过")
|
||
process.exit(1)
|
||
}
|
||
console.log("\nbundles 已恢复。重启 DSH 生效。") |