From b3195441b0a9dc30f761369bfddc432bc5251a99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=8E=E4=BC=9F=E6=9D=B0?= <674416404@qq.com> Date: Wed, 5 Aug 2026 12:47:34 +0800 Subject: [PATCH] feat(ui): support multiple package managers --- packages/app/app/components/Commits.vue | 62 ++++++++++++++++++++----- 1 file changed, 50 insertions(+), 12 deletions(-) diff --git a/packages/app/app/components/Commits.vue b/packages/app/app/components/Commits.vue index 4deb4416..8f8728c7 100644 --- a/packages/app/app/components/Commits.vue +++ b/packages/app/app/components/Commits.vue @@ -8,10 +8,14 @@ import { createJavaScriptRegexEngine } from "shiki/engine/javascript"; interface PackageInfo { name: string; installUrl: string; - installCommand: string; isOnNpm: boolean; } +type PackageManager = "npm" | "yarn" | "pnpm" | "bun"; + +const packageManagers: PackageManager[] = ["npm", "yarn", "pnpm", "bun"]; +const selectedPackageManager = ref("npm"); + interface RepoCommitsResponse { id: string; name: string; @@ -120,10 +124,23 @@ const colorMode = useColorMode(); const highlightCache = new Map(); -function highlightInstallCommand(code: string) { - if (props.withDev) { - code += " --dev"; - } +function getInstallCommand(pkg: PackageInfo) { + const descriptor = + selectedPackageManager.value === "yarn" + ? `${pkg.name}@${pkg.installUrl}.tgz` + : pkg.installUrl; + const installCommand: Record = { + npm: "npm i", + yarn: "yarn add", + pnpm: "pnpm add", + bun: "bun add", + }; + + return `${installCommand[selectedPackageManager.value]} ${descriptor}${props.withDev ? " -D" : ""}`; +} + +function highlightInstallCommand(pkg: PackageInfo) { + const code = getInstallCommand(pkg); if (!shiki) return ""; const theme = colorMode.value === "dark" ? "github-dark" : "github-light"; const cacheKey = `${theme}::${code}`; @@ -151,11 +168,8 @@ const copiedPackage = ref(null); let copyTimeoutId: ReturnType | null = null; function copyInstallCommand(pkg: PackageInfo) { - const text = props.withDev - ? `${pkg.installCommand} --dev` - : pkg.installCommand; - navigator.clipboard?.writeText(text); - copiedPackage.value = pkg.name; + navigator.clipboard?.writeText(getInstallCommand(pkg)); + copiedPackage.value = `${selectedPackageManager.value}:${pkg.name}`; if (copyTimeoutId) clearTimeout(copyTimeoutId); copyTimeoutId = setTimeout(() => { copiedPackage.value = null; @@ -412,6 +426,30 @@ async function goPrevPage() {
+
+
+ + {{ packageManager }} + +
+