@@ -7,7 +7,6 @@ import { rename, rm } from "node:fs/promises";
77import { homedir , platform , arch , tmpdir } from "node:os" ;
88import { join , dirname , resolve } from "node:path" ;
99import { spawn } from "node:child_process" ;
10- import { extract } from "tar" ;
1110import * as semver from "semver" ;
1211import { CopilotClient } from "./client.js" ;
1312import { PREFERRED_CLI_VERSION } from "./generated/versions.js" ;
@@ -212,11 +211,7 @@ async function downloadCli(
212211 const extractDir = join ( tempDir , "extracted" ) ;
213212 mkdirSync ( extractDir , { recursive : true } ) ;
214213
215- if ( ext === "zip" ) {
216- await extractZip ( archivePath , extractDir ) ;
217- } else {
218- await extract ( { file : archivePath , cwd : extractDir } ) ;
219- }
214+ await extractArchive ( archivePath , extractDir ) ;
220215
221216 const execName = platform ( ) === "win32" ? "copilot.exe" : "copilot" ;
222217 const extractedExec = findExecutable ( extractDir , execName ) ;
@@ -251,18 +246,15 @@ async function downloadCli(
251246 }
252247}
253248
254- async function extractZip ( zipPath : string , destDir : string ) : Promise < void > {
249+ // tar is built-in on Windows 10+, macOS, and Linux
250+ async function extractArchive ( archivePath : string , destDir : string ) : Promise < void > {
255251 return new Promise ( ( resolve , reject ) => {
256- const proc = spawn ( "powershell" , [
257- "-NoProfile" ,
258- "-Command" ,
259- `Expand-Archive -Path '${ zipPath } ' -DestinationPath '${ destDir } ' -Force` ,
260- ] ) ;
252+ const proc = spawn ( "tar" , [ "-xf" , archivePath , "-C" , destDir ] , { stdio : "ignore" } ) ;
261253
262254 proc . on ( "error" , reject ) ;
263255 proc . on ( "exit" , ( code ) => {
264256 if ( code === 0 ) resolve ( ) ;
265- else reject ( new Error ( `Expand- Archive failed with code ${ code } ` ) ) ;
257+ else reject ( new Error ( `Archive extraction failed for ${ archivePath } (exit code ${ code } ) ` ) ) ;
266258 } ) ;
267259 } ) ;
268260}
0 commit comments