Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(scripts): 在 Windows 上用系统 tar 解压 Electron

davidd0944adc41e7
diff --git a/apps/desktop/src/main/__tests__/ensureDepsElectronBinary.test.ts b/apps/desktop/src/main/__tests__/ensureDepsElectronBinary.test.ts
index 6bee8f69e0..e5251e1f58 100644
--- a/apps/desktop/src/main/__tests__/ensureDepsElectronBinary.test.ts
+++ b/apps/desktop/src/main/__tests__/ensureDepsElectronBinary.test.ts
@@ -6,7 +6,7 @@ import { describe, expect, it } from 'vitest';
// 仓库根的 ESM 工具脚本没有 TS declaration;Vitest 运行时可直接加载。
// @ts-expect-error 见上方说明。
-import { findElectronBinaryIssue, getElectronPlatformBinaryRelPath, getElectronRepairMode } from '../../../../../scripts/ensure-deps.mjs';
+import { findElectronBinaryIssue, getElectronPlatformBinaryRelPath, getElectronRepairMode, resolveSystemTarCommand } from '../../../../../scripts/ensure-deps.mjs';
// @ts-expect-error 见上方说明。
import { commandContainsPath } from '../../../../../scripts/restart-desktop-remote.mjs';
@@ -36,6 +36,19 @@ describe('getElectronRepairMode', () => {
});
});
+// Bug:Git Bash 里 pnpm install,PATH 先命中 Git 的 GNU tar,把 `C:\...` 当远程主机,Electron 解压失败。
+describe('resolveSystemTarCommand', () => {
+ it('Windows 用系统目录的 tar.exe,不按 PATH 找', () => {
+ const systemTar = 'D:\\Win\\System32\\tar.exe';
+ expect(resolveSystemTarCommand('win32', { SystemRoot: 'D:\\Win' }, (file: string) => file === systemTar)).toBe(systemTar);
+ });
+
+ it('系统目录里没有 tar.exe 时退回 PATH;其它平台照旧用 PATH', () => {
+ expect(resolveSystemTarCommand('win32', { SystemRoot: 'D:\\Win' }, () => false)).toBe('tar');
+ expect(resolveSystemTarCommand('darwin', {}, () => true)).toBe('tar');
+ });
+});
+
describe('findElectronBinaryIssue', () => {
it.each(['win32', 'darwin', 'mas', 'linux'])('完整 %s Electron install 返回 null', (platform) => {
const root = createElectronInstall({ platform });
diff --git a/scripts/ensure-deps.mjs b/scripts/ensure-deps.mjs
index 41bfca1499..afc8b33d40 100644
--- a/scripts/ensure-deps.mjs
+++ b/scripts/ensure-deps.mjs
@@ -357,13 +357,26 @@ downloadArtifact({
return zipPath;
}
+/**
+ * Windows 自带的 tar.exe(bsdtar,能解 zip、认盘符路径)。不能按 PATH 找:在 Git Bash 里装依赖时,
+ * PATH 上先命中的是 Git 自带的 GNU tar,它把 `C:\...` 里的冒号当成「远程主机:路径」,
+ * 报 `Cannot connect to C: resolve failed`,也解不了 zip。系统目录里没有时才退回 PATH。
+ */
+export function resolveSystemTarCommand(platform = process.platform, env = process.env, exists = fs.existsSync) {
+ if (platform !== 'win32') return 'tar';
+ const systemRoot = env.SystemRoot || env.SYSTEMROOT || env.windir || env.WINDIR || 'C:\\Windows';
+ const systemTar = path.win32.join(systemRoot, 'System32', 'tar.exe');
+ return exists(systemTar) ? systemTar : 'tar';
+}
+
function extractElectronZipWithSystemTar(zipPath, root = ROOT) {
const electronDir = getElectronDir(root);
const distDir = path.join(electronDir, 'dist');
fs.mkdirSync(distDir, { recursive: true });
- log(`使用系统 tar 解压 Electron zip:${zipPath}`);
- const result = spawnSync('tar', ['-xf', zipPath, '-C', distDir], {
+ const tar = resolveSystemTarCommand();
+ log(`使用系统 tar 解压 Electron zip:${zipPath}(${tar})`);
+ const result = spawnSync(tar, ['-xf', zipPath, '-C', distDir], {
cwd: root,
stdio: 'inherit',
});