diff --git a/README.md b/README.md index 6bdae5c08..81aa988d2 100644 --- a/README.md +++ b/README.md @@ -31,13 +31,10 @@ bun i -g claude-code-best bun pm -g trust claude-code-best ccb # 直接打开 claude code +CLAUDE_BRIDGE_BASE_URL=https://remote-control.claude-code-best.win/ CLAUDE_BRIDGE_OAUTH_TOKEN=test-my-key bun run dev --remote-control # 我们有自部署的远程控制 ``` -⚠️ 国内对 github 网络较差的, 需要先设置这个环境变量 - -```bash -DEFAULT_RELEASE_BASE=https://ghproxy.net/https://github.com/microsoft/ripgrep-prebuilt/releases/download/v15.0.1 -``` +⚠️ 如果 GitHub 下载 ripgrep 失败,postinstall 会自动回退到 ghproxy.net 镜像,无需手动配置。 ## ⚡ 快速开始(源码版) @@ -54,12 +51,6 @@ DEFAULT_RELEASE_BASE=https://ghproxy.net/https://github.com/microsoft/ripgrep-pr bun install ``` -⚠️ 国内对 github 网络较差的,可以使用这个环境变量 - -```bash -DEFAULT_RELEASE_BASE=https://ghproxy.net/https://github.com/microsoft/ripgrep-prebuilt/releases/download/v15.0.1 -``` - ### ▶️ 运行 ```bash diff --git a/scripts/postinstall.cjs b/scripts/postinstall.cjs index 245b4f36d..990d08174 100644 --- a/scripts/postinstall.cjs +++ b/scripts/postinstall.cjs @@ -29,6 +29,7 @@ try { const RG_VERSION = "15.0.1" const DEFAULT_RELEASE_BASE = `https://github.com/microsoft/ripgrep-prebuilt/releases/download/v${RG_VERSION}` +const MIRROR_RELEASE_BASE = `https://ghproxy.net/https://github.com/microsoft/ripgrep-prebuilt/releases/download/v${RG_VERSION}` const RELEASE_BASE = (process.env.RIPGREP_DOWNLOAD_BASE ?? DEFAULT_RELEASE_BASE).replace(/\/$/, "") const scriptDir = path.dirname(__filename) @@ -262,7 +263,6 @@ async function extractTarGz(buffer, binaryPath, extractedBinary, assetName) { async function downloadAndExtract() { const { target, ext } = getPlatformMapping() const assetName = `ripgrep-v${RG_VERSION}-${target}.${ext}` - const downloadUrl = `${RELEASE_BASE}/${assetName}` const binaryPath = getBinaryPath() const binaryDir = path.dirname(binaryPath) @@ -277,12 +277,32 @@ async function downloadAndExtract() { } console.log(`[ripgrep] Downloading v${RG_VERSION} for ${target}...`) - console.log(`[ripgrep] URL: ${downloadUrl}`) const extractedBinary = process.platform === "win32" ? "rg.exe" : "rg" + const mirrors = [RELEASE_BASE] + if (RELEASE_BASE === DEFAULT_RELEASE_BASE.replace(/\/$/, "")) { + mirrors.push(MIRROR_RELEASE_BASE.replace(/\/$/, "")) + } + + let buffer + let lastError + for (const base of mirrors) { + const url = `${base}/${assetName}` + try { + console.log(`[ripgrep] Trying ${url}`) + buffer = await downloadUrlToBufferWithFallback(url) + break + } catch (e) { + console.warn(`[ripgrep] Download from ${base} failed: ${e instanceof Error ? e.message : e}`) + lastError = e + } + } + if (!buffer) { + throw lastError + } + try { - const buffer = await downloadUrlToBufferWithFallback(downloadUrl) console.log(`[ripgrep] Downloaded ${Math.round(buffer.length / 1024)} KB`) mkdirSync(binaryDir, { recursive: true })