import { execFile } from 'node:child_process' import { promises as fsp } from 'node:fs' import * as path from 'node:path' function tar(args: string[]): Promise { return new Promise((resolve, reject) => { execFile('tar', args, { timeout: 120_000 }, (err, _stdout, stderr) => { if (err) { reject(new Error(`tar ${args[0]} 失败: ${(stderr ?? '').toString().trim() || err.message}`)) return } resolve() }) }) } export async function packHandoff(stagingDir: string, outFile: string): Promise { await fsp.mkdir(path.dirname(outFile), { recursive: true }) await tar(['-czf', outFile, '-C', stagingDir, '.']) } export async function unpackHandoff(archive: string, dstDir: string): Promise { await fsp.mkdir(dstDir, { recursive: true }) await tar(['-xzf', archive, '-C', dstDir]) }