Skip to content

Commit 50a3fde

Browse files
committed
fix: executable path being returned incorrectly on cross-platform downloads
Fixes #124
1 parent 25eafb9 commit 50a3fde

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

Diff for: CHANGELOG.md

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

3+
### 2.1.2 | TBD
4+
5+
- Fix executable path being returned incorrectly on cross-platform downloads
6+
37
### 2.1.1 | 2021-01-20
48

59
- Fix excessive logging when running in CI

Diff for: lib/download.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,14 @@ export async function download(options: Partial<DownloadOptions> = {}): Promise<
203203
if (fs.existsSync(downloadedPath)) {
204204
if (version === 'insiders') {
205205
reporter.report({ stage: ProgressReportStage.FetchingInsidersMetadata });
206-
const { version: currentHash, date: currentDate } = insidersDownloadDirMetadata(downloadedPath);
206+
const { version: currentHash, date: currentDate } = insidersDownloadDirMetadata(downloadedPath, platform);
207207

208208
const { version: latestHash, timestamp: latestTimestamp } = await getLatestInsidersMetadata(
209209
systemDefaultPlatform
210210
);
211211
if (currentHash === latestHash) {
212212
reporter.report({ stage: ProgressReportStage.FoundMatchingInstall, downloadedPath });
213-
return Promise.resolve(insidersDownloadDirToExecutablePath(downloadedPath));
213+
return Promise.resolve(insidersDownloadDirToExecutablePath(downloadedPath, platform));
214214
} else {
215215
try {
216216
reporter.report({
@@ -229,7 +229,7 @@ export async function download(options: Partial<DownloadOptions> = {}): Promise<
229229
}
230230
} else {
231231
reporter.report({ stage: ProgressReportStage.FoundMatchingInstall, downloadedPath });
232-
return Promise.resolve(downloadDirToExecutablePath(downloadedPath));
232+
return Promise.resolve(downloadDirToExecutablePath(downloadedPath, platform));
233233
}
234234
}
235235

@@ -243,9 +243,9 @@ export async function download(options: Partial<DownloadOptions> = {}): Promise<
243243
}
244244

245245
if (version === 'insiders') {
246-
return Promise.resolve(insidersDownloadDirToExecutablePath(downloadedPath));
246+
return Promise.resolve(insidersDownloadDirToExecutablePath(downloadedPath, platform));
247247
} else {
248-
return downloadDirToExecutablePath(downloadedPath);
248+
return downloadDirToExecutablePath(downloadedPath, platform);
249249
}
250250
}
251251

Diff for: lib/util.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -78,31 +78,31 @@ export function urlToOptions(url: string): https.RequestOptions {
7878
return options;
7979
}
8080

81-
export function downloadDirToExecutablePath(dir: string) {
82-
if (process.platform === 'win32') {
81+
export function downloadDirToExecutablePath(dir: string, platform: DownloadPlatform) {
82+
if (platform === 'win32-archive' || platform === 'win32-x64-archive') {
8383
return path.resolve(dir, 'Code.exe');
84-
} else if (process.platform === 'darwin') {
84+
} else if (platform === 'darwin') {
8585
return path.resolve(dir, 'Visual Studio Code.app/Contents/MacOS/Electron');
8686
} else {
8787
return path.resolve(dir, 'VSCode-linux-x64/code');
8888
}
8989
}
9090

91-
export function insidersDownloadDirToExecutablePath(dir: string) {
92-
if (process.platform === 'win32') {
91+
export function insidersDownloadDirToExecutablePath(dir: string, platform: DownloadPlatform) {
92+
if (platform === 'win32-archive' || platform === 'win32-x64-archive') {
9393
return path.resolve(dir, 'Code - Insiders.exe');
94-
} else if (process.platform === 'darwin') {
94+
} else if (platform === 'darwin') {
9595
return path.resolve(dir, 'Visual Studio Code - Insiders.app/Contents/MacOS/Electron');
9696
} else {
9797
return path.resolve(dir, 'VSCode-linux-x64/code-insiders');
9898
}
9999
}
100100

101-
export function insidersDownloadDirMetadata(dir: string) {
101+
export function insidersDownloadDirMetadata(dir: string, platform: DownloadPlatform) {
102102
let productJsonPath;
103-
if (process.platform === 'win32') {
103+
if (platform === 'win32-archive' || platform === 'win32-x64-archive') {
104104
productJsonPath = path.resolve(dir, 'resources/app/product.json');
105-
} else if (process.platform === 'darwin') {
105+
} else if (platform === 'darwin') {
106106
productJsonPath = path.resolve(dir, 'Visual Studio Code - Insiders.app/Contents/Resources/app/product.json');
107107
} else {
108108
productJsonPath = path.resolve(dir, 'VSCode-linux-x64/resources/app/product.json');
@@ -136,14 +136,14 @@ export async function getLatestInsidersMetadata(platform: string) {
136136
* Resolve the VS Code cli path from executable path returned from `downloadAndUnzipVSCode`.
137137
* Usually you will want {@link resolveCliArgsFromVSCodeExecutablePath} instead.
138138
*/
139-
export function resolveCliPathFromVSCodeExecutablePath(vscodeExecutablePath: string) {
140-
if (process.platform === 'win32') {
139+
export function resolveCliPathFromVSCodeExecutablePath(vscodeExecutablePath: string, platform: DownloadPlatform) {
140+
if (platform === 'win32') {
141141
if (vscodeExecutablePath.endsWith('Code - Insiders.exe')) {
142142
return path.resolve(vscodeExecutablePath, '../bin/code-insiders.cmd');
143143
} else {
144144
return path.resolve(vscodeExecutablePath, '../bin/code.cmd');
145145
}
146-
} else if (process.platform === 'darwin') {
146+
} else if (platform === 'darwin') {
147147
return path.resolve(vscodeExecutablePath, '../../../Contents/Resources/app/bin/code');
148148
} else {
149149
if (vscodeExecutablePath.endsWith('code-insiders')) {
@@ -171,8 +171,8 @@ export function resolveCliPathFromVSCodeExecutablePath(vscodeExecutablePath: str
171171
*
172172
* @param vscodeExecutablePath The `vscodeExecutablePath` from `downloadAndUnzipVSCode`.
173173
*/
174-
export function resolveCliArgsFromVSCodeExecutablePath(vscodeExecutablePath: string, options?: Pick<TestOptions, 'reuseMachineInstall'>) {
175-
const args = [resolveCliPathFromVSCodeExecutablePath(vscodeExecutablePath)];
174+
export function resolveCliArgsFromVSCodeExecutablePath(vscodeExecutablePath: string, options?: Pick<TestOptions, 'reuseMachineInstall' | 'platform'>) {
175+
const args = [resolveCliPathFromVSCodeExecutablePath(vscodeExecutablePath, options?.platform ?? process.platform)];
176176
if (!options?.reuseMachineInstall) {
177177
args.push(...getProfileArguments(args));
178178
}

0 commit comments

Comments
 (0)