fix: 修复 PowerShell 脚本中的 ARM64 判断逻辑并添加调试打印
This commit is contained in:
@@ -6,17 +6,48 @@ export default {
|
|||||||
return new Response(`curl -fsSL ${url.origin}/install.sh | sh -
|
return new Response(`curl -fsSL ${url.origin}/install.sh | sh -
|
||||||
iwr ${url.origin}/install.ps1 -useb | iex
|
iwr ${url.origin}/install.ps1 -useb | iex
|
||||||
|
|
||||||
|
# 常用命令
|
||||||
pnpm env use --global lts
|
pnpm env use --global lts
|
||||||
pnpm config get registry
|
pnpm config get registry
|
||||||
pnpm config set registry https://registry.npmmirror.com
|
pnpm config set registry https://registry.npmmirror.com
|
||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 2. 代理请求
|
||||||
let response = await fetch(`http://get.pnpm.io${url.pathname}`);
|
let response = await fetch(`http://get.pnpm.io${url.pathname}`);
|
||||||
let text = await response.text();
|
let text = await response.text();
|
||||||
|
|
||||||
|
// 3. GitHub 加速替换
|
||||||
text = text.replace(/https:\/\/github.com/g, 'https://ghfast.top/https://github.com');
|
text = text.replace(/https:\/\/github.com/g, 'https://ghfast.top/https://github.com');
|
||||||
text = text.replace('Downloading pnpm from GitHub', 'Downloading pnpm from GitHub (via Cloudflare)');
|
text = text.replace('Downloading pnpm from GitHub', 'Downloading pnpm from GitHub (via Cloudflare)');
|
||||||
text = text.replace('Downloading pnpm', 'Downloading pnpm (via Cloudflare)');
|
text = text.replace('Downloading pnpm', 'Downloading pnpm (via Cloudflare)');
|
||||||
|
|
||||||
|
// 4. 【核心修改】针对 PowerShell 脚本 (install.ps1)
|
||||||
|
if (url.pathname.endsWith('.ps1')) {
|
||||||
|
// --- 修改 A: 修复 ARM64 判断逻辑 ---
|
||||||
|
const originalLogicRegex =
|
||||||
|
/if \(\$platform -eq 'win'\)\s*\{\s*if \(\[System\.Environment\]::Is64BitOperatingSystem -eq \$true\)\s*\{\s*\$architecture = 'x64'/;
|
||||||
|
|
||||||
|
// 使用 elseif 结构,优先判断环境变量是否为 ARM64
|
||||||
|
const patchedLogic = `if ($platform -eq 'win') {
|
||||||
|
if ($env:PROCESSOR_ARCHITECTURE -eq 'ARM64') {
|
||||||
|
$architecture = 'arm64'
|
||||||
|
} elseif ([System.Environment]::Is64BitOperatingSystem -eq $true) {
|
||||||
|
$architecture = 'x64'`;
|
||||||
|
|
||||||
|
text = text.replace(originalLogicRegex, patchedLogic);
|
||||||
|
|
||||||
|
// --- 修改 B: 插入 Debug 打印 ---
|
||||||
|
// 这里的注入点选择在脚本判断完所有架构之后,检查 platform 是否为空之前
|
||||||
|
// 这样能确保打印出最终判定结果
|
||||||
|
const debugPrint = `
|
||||||
|
Write-Host "DEBUG: Platform = $platform" -ForegroundColor Cyan
|
||||||
|
Write-Host "DEBUG: Architecture = $architecture" -ForegroundColor Cyan
|
||||||
|
if ($null -eq $platform) {`;
|
||||||
|
|
||||||
|
text = text.replace('if ($null -eq $platform) {', debugPrint);
|
||||||
|
}
|
||||||
|
|
||||||
return new Response(text);
|
return new Response(text);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user