From 9efd290061b0e5c058a2ec8abdb566e27fd05ee4 Mon Sep 17 00:00:00 2001 From: jkooe <62494645+jkooe@users.noreply.github.com> Date: Wed, 7 Oct 2026 02:41:18 +0800 Subject: [PATCH] =?UTF-8?q?fix(pack):=20=E6=89=93=20zip=20=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E5=B9=B3=E5=8F=B0=E5=88=86=E6=B5=81=EF=BC=88Windows?= =?UTF-8?q?=20=E6=97=A0=20Info-ZIP=EF=BC=89=EF=BC=8C=E9=A1=BA=E5=B8=A6?= =?UTF-8?q?=E4=BF=AE=20ls/du?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Windows CI 连续暴露的第三类问题: - zip -q -r ... -x PSK.txt → Windows runner 没有 Info-ZIP,命令不存在 - 同文件里还有 ls -la 与 du -sh,在 Windows 上同样不可用 修法: - zip:Windows 用 PowerShell 的 Compress-Archive(先删 PSK.txt 再压,因为它没有 -x 排除项); macOS 继续用 zip - 列目录改用 Node readdirSync+statSync;体积用 statSync 计算(不再依赖 du) macOS 路径复跑通过(zip 31M),195 单测 / 29 e2e 绿。 --- scripts/pack.mjs | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/scripts/pack.mjs b/scripts/pack.mjs index 4508de8..9704baf 100644 --- a/scripts/pack.mjs +++ b/scripts/pack.mjs @@ -18,8 +18,8 @@ */ import { execFileSync, execSync } from 'node:child_process'; import { - copyFileSync, createWriteStream, existsSync, mkdirSync, - readFileSync, rmSync, writeFileSync, + copyFileSync, createWriteStream, existsSync, mkdirSync, readdirSync, + readFileSync, rmSync, statSync, writeFileSync, } from 'node:fs'; import { get } from 'node:https'; import { randomBytes } from 'node:crypto'; @@ -194,8 +194,13 @@ async function main() { '', ].join('\n'), 'utf8'); - const files = execSync(`ls -la "${PKG_DIR}"`, { encoding: 'utf8' }); - log(files.split('\n').slice(0, 12).join('\n')); + const entries = readdirSync(PKG_DIR, { withFileTypes: true }) + .filter((e) => e.isFile()) + .map((e) => { + const st = statSync(join(PKG_DIR, e.name)); + return `${e.name.padEnd(22)} ${(st.size / 1024).toFixed(0).padStart(8)} KB`; + }); + log(entries.join('\n')); log('\n=== ⑤ 打 zip ==='); const zipOut = join(OUT_DIR, 'nodeagent-win-x64.zip'); @@ -203,10 +208,26 @@ async function main() { // ⚠️ 必须排除 PSK.txt:本 zip 会作为**公开的 GitHub Release 资产**发布, // 把预共享密钥打进包里等于公开密钥。install.cmd 在文件缺失时会自动生成新密钥 // (生成在安装目录,只留在被控端本机),所以排除它不影响安装。 - execSync(`cd "${PKG_DIR}" && zip -q -r "${zipOut}" . -x "PSK.txt"`, { stdio: 'inherit' }); + if (process.platform === 'win32') { + // Windows:GitHub runner / 多数 Windows 没有 Info-ZIP,改用 PowerShell 的 Compress-Archive。 + // 先删掉 PSK.txt(若存在)再压 —— Compress-Archive 无 -x 排除参数。 + const psk = join(PKG_DIR, 'PSK.txt'); + if (existsSync(psk)) rmSync(psk, { force: true }); + execFileSync( + 'powershell', + [ + '-NoProfile', '-Command', + `Compress-Archive -Path '${PKG_DIR}\*' -DestinationPath '${zipOut}' -Force`, + ], + { stdio: 'inherit' }, + ); + } else { + execSync(`cd "${PKG_DIR}" && zip -q -r "${zipOut}" . -x "PSK.txt"`, { stdio: 'inherit' }); + } - const size = execSync(`du -sh "${zipOut}"`, { encoding: 'utf8' }).split('\t')[0]; - log(`\n✓ 完成: ${zipOut}(${size.trim()})`); + const kb = statSync(zipOut).size / 1024; + const size = kb > 1024 ? `${(kb / 1024).toFixed(0)}M` : `${kb.toFixed(0)}K`; + log(`\n✓ 完成: ${zipOut}(${size})`); log(' 分发方式:解压到固定目录 → 双击 install.cmd(自提权,零命令行知识)'); log(' 日后管理:双击 control.cmd'); }