fix(self-hosted): acr update 10/23 部署失敗根因——pnpm 目錄補 commit pnpm-workspace.yaml(ERR_PNPM_IGNORED_BUILDS)+ CLI 失敗帶 stderr 尾段

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
uncle6me-web
2026-06-12 23:25:46 +08:00
parent 38a3cccbee
commit 6e92ca0372
11 changed files with 98 additions and 9 deletions
+18 -9
View File
@@ -336,15 +336,24 @@ function runWranglerDeploy(dir: string, ctx: DeployContext): void {
const installer = existsSync(join(dir, 'pnpm-lock.yaml'))
? ['pnpm', 'install', '--frozen-lockfile']
: ['npm', 'install', '--no-audit', '--no-fund'];
execFileSync(installer[0], installer.slice(1), { cwd: dir, stdio: 'ignore' });
runStep(installer[0], installer.slice(1), dir, process.env);
}
execFileSync('wrangler', ['deploy'], {
cwd: dir,
stdio: 'ignore',
env: {
...process.env,
CLOUDFLARE_API_TOKEN: ctx.apiToken,
CLOUDFLARE_ACCOUNT_ID: ctx.accountId,
},
runStep('wrangler', ['deploy'], dir, {
...process.env,
CLOUDFLARE_API_TOKEN: ctx.apiToken,
CLOUDFLARE_ACCOUNT_ID: ctx.accountId,
});
}
/** 跑一個部署步驟,失敗時把 stderr 尾段帶進錯誤訊息——stdio ignore 會吞掉真因,
* 用戶只看到「Command failed: pnpm install」無從診斷(壓測 2026-06-12
* ERR_PNPM_IGNORED_BUILDS 被吞,10/23 失敗查不到原因)。*/
function runStep(cmd: string, args: string[], dir: string, env: NodeJS.ProcessEnv): void {
try {
execFileSync(cmd, args, { cwd: dir, stdio: ['ignore', 'ignore', 'pipe'], env });
} catch (e) {
const stderr = (e as { stderr?: Buffer }).stderr?.toString().trim() ?? '';
const tail = stderr.split('\n').slice(-3).join(' | ').slice(0, 300);
throw new Error(`${cmd} ${args.join(' ')} 失敗${tail ? `${tail}` : ''}`);
}
}