diff --git a/lib/update.js b/lib/update.js index 79f6af8..6ff0918 100644 --- a/lib/update.js +++ b/lib/update.js @@ -404,14 +404,15 @@ function pinInstalledSpec(profileDir, ref) { } if (changed) fs.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`, "utf8"); } - const lockPath = path.join(profileDir, "pnpm-lock.yaml"); - if (!fs.existsSync(lockPath)) return; - const text = fs.readFileSync(lockPath, "utf8"); - const next = text.replace( - /(^|\n)([ \t]*dsh-purge:\r?\n[ \t]+specifier:[ \t]*)\S+([ \t]*\r?\n[ \t]+version:[ \t]*)\S+/g, - `$1$2${url}$3${url}`, - ); - if (next !== text) fs.writeFileSync(lockPath, next, "utf8"); + // 这里曾经用正则把 pnpm-lock.yaml 里 importer 的 specifier/version 两行换成新地址, + // 却没有写 packages:/snapshots: 条目。锁文件于是自相矛盾,pnpm 在任何命令之前校验 + // 锁文件就失败: + // ERR_PNPM_LOCKFILE_MISSING_DEPENDENCY / Broken lockfile: no entry for 'dsh-purge@…' + // dsh 又给子进程带 CI=1(frozen-lockfile 默认开),于是 profile 里连紧随其后、 + // 本来能修好它的 pnpm add --force 都起不来 —— 整个 profile 从此不可安装。 + // 这个手改并不需要:pin 完 package.json 后,pnpm 自己会在 add --force 时按新地址 + // 重新解析,把 importer / packages / snapshots 一次写一致。锁文件只能由解析出这些 + // 字段的解析器来写。 } function planUpdates() {