Skip to content

Commit 4f019a6

Browse files
committed
fix: download cli correctly for linux
I'm using this package for some smoke tests involving the CLI. Slight tweak is necessary.
1 parent 7f7e8fd commit 4f019a6

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
### 2.3.2 | 2022-05-11
4+
5+
- Fix download method not working for the vscode cli.
6+
37
### 2.3.1 | 2022-04-04
48

59
- Gracefully kill VS Code if SIGINT is received

lib/download.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ async function downloadVSCodeArchive(options: DownloadOptions) {
258258
async function unzipVSCode(
259259
reporter: ProgressReporter,
260260
extractDir: string,
261-
extractSync: boolean,
262261
stream: Readable,
262+
platform: DownloadPlatform,
263263
format: 'zip' | 'tgz'
264264
) {
265265
const stagingFile = path.join(tmpdir(), `vscode-test-${Date.now()}.zip`);
@@ -306,7 +306,9 @@ async function unzipVSCode(
306306
fs.mkdirSync(extractDir);
307307
}
308308

309-
await spawnDecompressorChild('tar', ['-xzf', '-', '--strip-components=1', '-C', extractDir], stream);
309+
// The CLI is a singular binary that doesn't have a wrapper component to remove
310+
const s = platform.includes('cli-') ? 0 : 1;
311+
await spawnDecompressorChild('tar', ['-xzf', '-', `--strip-components=${s}`, '-C', extractDir], stream);
310312
}
311313
}
312314

@@ -340,7 +342,6 @@ export async function download(options: Partial<DownloadOptions> = {}): Promise<
340342
platform = systemDefaultPlatform,
341343
cachePath = defaultCachePath,
342344
reporter = new ConsoleReporter(process.stdout.isTTY),
343-
extractSync = false,
344345
timeout = 15_000,
345346
} = options;
346347

@@ -421,7 +422,7 @@ export async function download(options: Partial<DownloadOptions> = {}): Promise<
421422
});
422423
// important! do not put anything async here, since unzipVSCode will need
423424
// to start consuming the stream immediately.
424-
await unzipVSCode(reporter, downloadStaging, extractSync, stream, format);
425+
await unzipVSCode(reporter, downloadStaging, stream, platform, format);
425426
await fs.promises.rename(downloadStaging, downloadedPath);
426427

427428
reporter.report({ stage: ProgressReportStage.NewInstallComplete, downloadedPath });

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"scripts": {
55
"compile": "tsc -p ./",
66
"watch": "tsc -w -p ./",
7-
"prepublish": "tsc -p ./",
7+
"prepack": "tsc -p ./",
88
"fmt": "prettier --write \"lib/**/*.ts\" \"*.md\"",
99
"test": "eslint lib --ext ts && vitest && tsc --noEmit",
1010
"prepare": "husky install"

0 commit comments

Comments
 (0)