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 = [