From b3a23dba75adc847d541bb162ef3fb4f34b3c388 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=AB=E6=88=91=E5=B0=8F=E6=9D=A8=E5=90=8C=E5=AD=A6?= <188421097+HunYiSage@users.noreply.github.com> Date: Wed, 23 Sep 2026 00:08:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8F=92=E4=BB=B6=E9=87=8D=E8=A3=85?= =?UTF-8?q?=E6=94=B9=E7=94=A8=20tar.gz=EF=BC=8C=E9=81=BF=E5=85=8D=E6=B2=A1?= =?UTF-8?q?=E8=A3=85=20git=20=E6=97=B6=E8=A7=A3=E6=9E=90=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=20(#30)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pnpm 解析 github: 和 git+https 会执行 git ls-remote。插件自己的更新改为 GitHub archive 包,不依赖本机 git。 Co-authored-by: Cursor --- lib/update.js | 17 +++++++++++------ scripts/test-update-guards.mjs | 8 +++++++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/update.js b/lib/update.js index 0508a83..d541c55 100644 --- a/lib/update.js +++ b/lib/update.js @@ -153,10 +153,6 @@ function archiveTarballUrl(ref) { return `https://github.com/${REPO}/archive/refs/heads/${encodeURIComponent(value)}.tar.gz`; } -function githubSpec(ref) { - return `github:${REPO}#${ref || STABLE_REF}`; -} - function readStamp() { try { return fs.readFileSync(stampPath(), "utf8").trim(); @@ -313,8 +309,17 @@ export function runDshPlugin(profile, args) { export function pluginAddSpec(spec, ref = currentChannelRef()) { const s = String(spec || ""); - if (/\.(zip|tgz|tar\.gz)(\b|$)/i.test(s) || /^https?:\/\//i.test(s)) return archiveTarballUrl(ref); - if (/^github:/i.test(s) || /github\.com\/.+\.git/i.test(s)) return githubSpec(ref); + // github: / git+https 会让 pnpm 跑 git ls-remote。没装 git 时就是 #30。 + // 公开仓库用 archive tar.gz,不依赖本机 git。 + if ( + /\.(zip|tgz|tar\.gz)(\b|$)/i.test(s) || + /^https?:\/\//i.test(s) || + /^git\+https?:\/\//i.test(s) || + /^github:/i.test(s) || + /github\.com\/.+\.git/i.test(s) + ) { + return archiveTarballUrl(ref); + } return ""; } diff --git a/scripts/test-update-guards.mjs b/scripts/test-update-guards.mjs index db3a30e..f58a1fb 100644 --- a/scripts/test-update-guards.mjs +++ b/scripts/test-update-guards.mjs @@ -1,5 +1,5 @@ import assert from "node:assert/strict"; -import { markCurrent, safeUpdateRef } from "../lib/update.js"; +import { markCurrent, pluginAddSpec, safeUpdateRef } from "../lib/update.js"; assert.equal(safeUpdateRef("master"), "master"); assert.equal(safeUpdateRef("beta"), "beta"); @@ -11,6 +11,12 @@ assert.equal(safeUpdateRef("origin/master"), ""); assert.equal(safeUpdateRef("../evil"), ""); assert.equal(safeUpdateRef("master;rm"), ""); +const masterTar = "https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz"; +assert.equal(pluginAddSpec("git+https://github.com/yujunzhixue/dsh-purge.git", "master"), masterTar); +assert.equal(pluginAddSpec("github:yujunzhixue/dsh-purge", "master"), masterTar); +assert.equal(pluginAddSpec("https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.zip", "master"), masterTar); +assert.equal(pluginAddSpec("dsh-purge", "master"), ""); + const head = "9397203733562d6baeec9e38ac519698c619edcb"; const tag = "5e6be24acc3e5aac981c701cc34ef710ce48c4c7"; const versions = [