From ee8fa10fdc1a26d219662ff84d4105ed322d1ca8 Mon Sep 17 00:00:00 2001 From: bookworm Date: Tue, 7 Apr 2026 00:20:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20build.ps1=20pkg=20PATH=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=20+=20gen-authcode=20pkg=E8=B7=AF=E5=BE=84=E5=85=BC?= =?UTF-8?q?=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.ps1 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/build.ps1 b/build.ps1 index 96464b6..1308986 100644 --- a/build.ps1 +++ b/build.ps1 @@ -96,13 +96,16 @@ if ($buildAdmin) { } # 安装/检查 pkg - $pkgCmd = Get-Command pkg -ErrorAction SilentlyContinue + # 优先找 npm global bin 目录下的 pkg(不依赖 PATH 是否刷新) + $npmGlobalBin = Join-Path (npm root -g 2>$null) "..\pkg.cmd" | Resolve-Path -ErrorAction SilentlyContinue + $pkgCmd = if ($npmGlobalBin) { $npmGlobalBin.Path } else { (Get-Command pkg -ErrorAction SilentlyContinue)?.Source } if (-not $pkgCmd) { Write-Warn "pkg 未安装,正在安装..." npm install -g pkg - # 刷新 PATH $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") + $npmGlobalBin = Join-Path (npm root -g 2>$null) "..\pkg.cmd" | Resolve-Path -ErrorAction SilentlyContinue + $pkgCmd = $npmGlobalBin.Path } $inputJs = Join-Path $ScriptDir "gen-authcode.js" @@ -117,7 +120,7 @@ if ($buildAdmin) { Write-Host " 输出: $outputExe" -ForegroundColor Gray Write-Host " (内嵌 Node.js 运行时,首次打包约 1 分钟)" -ForegroundColor Gray - pkg $inputJs --targets node18-win-x64 --output $outputExe 2>&1 | + & $pkgCmd $inputJs --targets node18-win-x64 --output $outputExe 2>&1 | ForEach-Object { Write-Host " $_" -ForegroundColor Gray } if (Test-Path $outputExe) {