Skip to content

Commit 00fe72e

Browse files
Simplify extraction
1 parent 0d3f6f0 commit 00fe72e

File tree

4 files changed

+8
-80
lines changed

4 files changed

+8
-80
lines changed

nodejs/examples/basic-example.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
* Copyright (c) Microsoft Corporation. All rights reserved.
33
*--------------------------------------------------------------------------------------------*/
44

5-
import { z } from "zod";
6-
import { join } from "node:path";
75
import { homedir } from "node:os";
6+
import { join } from "node:path";
7+
import { z } from "zod";
88
import { CopilotClient, defineTool } from "../src/index.js";
99

1010
console.log("🚀 Starting Copilot SDK Example\n");
@@ -27,6 +27,7 @@ const client = new CopilotClient({
2727
logLevel: "info",
2828
acquisition: {
2929
downloadDir: join(homedir(), ".copilot-sdk-example", "cli"),
30+
minVersion: "0.0.400",
3031
onProgress: ({ bytesDownloaded, totalBytes }) => {
3132
if (totalBytes > 0) {
3233
const pct = Math.round((bytesDownloaded / totalBytes) * 100);

nodejs/package-lock.json

Lines changed: 0 additions & 64 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nodejs/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
"prettier": "^3.4.0",
6060
"quicktype-core": "^23.2.6",
6161
"rimraf": "^6.1.2",
62-
"tar": "^7.5.7",
6362
"tsx": "^4.20.6",
6463
"typescript": "^5.0.0",
6564
"vitest": "^4.0.18"

nodejs/src/acquisition.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { rename, rm } from "node:fs/promises";
77
import { homedir, platform, arch, tmpdir } from "node:os";
88
import { join, dirname, resolve } from "node:path";
99
import { spawn } from "node:child_process";
10-
import { extract } from "tar";
1110
import * as semver from "semver";
1211
import { CopilotClient } from "./client.js";
1312
import { 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

Comments
 (0)