Skip to content

Commit

Permalink
fix: executable path being returned incorrectly on cross-platform dow…
Browse files Browse the repository at this point in the history
…nloads

Fixes #124
  • Loading branch information
connor4312 committed Feb 3, 2022
1 parent 25eafb9 commit 50a3fde
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### 2.1.2 | TBD

- Fix executable path being returned incorrectly on cross-platform downloads

### 2.1.1 | 2021-01-20

- Fix excessive logging when running in CI
Expand Down
10 changes: 5 additions & 5 deletions lib/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,14 @@ export async function download(options: Partial<DownloadOptions> = {}): Promise<
if (fs.existsSync(downloadedPath)) {
if (version === 'insiders') {
reporter.report({ stage: ProgressReportStage.FetchingInsidersMetadata });
const { version: currentHash, date: currentDate } = insidersDownloadDirMetadata(downloadedPath);
const { version: currentHash, date: currentDate } = insidersDownloadDirMetadata(downloadedPath, platform);

const { version: latestHash, timestamp: latestTimestamp } = await getLatestInsidersMetadata(
systemDefaultPlatform
);
if (currentHash === latestHash) {
reporter.report({ stage: ProgressReportStage.FoundMatchingInstall, downloadedPath });
return Promise.resolve(insidersDownloadDirToExecutablePath(downloadedPath));
return Promise.resolve(insidersDownloadDirToExecutablePath(downloadedPath, platform));
} else {
try {
reporter.report({
Expand All @@ -229,7 +229,7 @@ export async function download(options: Partial<DownloadOptions> = {}): Promise<
}
} else {
reporter.report({ stage: ProgressReportStage.FoundMatchingInstall, downloadedPath });
return Promise.resolve(downloadDirToExecutablePath(downloadedPath));
return Promise.resolve(downloadDirToExecutablePath(downloadedPath, platform));
}
}

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

if (version === 'insiders') {
return Promise.resolve(insidersDownloadDirToExecutablePath(downloadedPath));
return Promise.resolve(insidersDownloadDirToExecutablePath(downloadedPath, platform));
} else {
return downloadDirToExecutablePath(downloadedPath);
return downloadDirToExecutablePath(downloadedPath, platform);
}
}

Expand Down
28 changes: 14 additions & 14 deletions lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,31 +78,31 @@ export function urlToOptions(url: string): https.RequestOptions {
return options;
}

export function downloadDirToExecutablePath(dir: string) {
if (process.platform === 'win32') {
export function downloadDirToExecutablePath(dir: string, platform: DownloadPlatform) {
if (platform === 'win32-archive' || platform === 'win32-x64-archive') {
return path.resolve(dir, 'Code.exe');
} else if (process.platform === 'darwin') {
} else if (platform === 'darwin') {
return path.resolve(dir, 'Visual Studio Code.app/Contents/MacOS/Electron');
} else {
return path.resolve(dir, 'VSCode-linux-x64/code');
}
}

export function insidersDownloadDirToExecutablePath(dir: string) {
if (process.platform === 'win32') {
export function insidersDownloadDirToExecutablePath(dir: string, platform: DownloadPlatform) {
if (platform === 'win32-archive' || platform === 'win32-x64-archive') {
return path.resolve(dir, 'Code - Insiders.exe');
} else if (process.platform === 'darwin') {
} else if (platform === 'darwin') {
return path.resolve(dir, 'Visual Studio Code - Insiders.app/Contents/MacOS/Electron');
} else {
return path.resolve(dir, 'VSCode-linux-x64/code-insiders');
}
}

export function insidersDownloadDirMetadata(dir: string) {
export function insidersDownloadDirMetadata(dir: string, platform: DownloadPlatform) {
let productJsonPath;
if (process.platform === 'win32') {
if (platform === 'win32-archive' || platform === 'win32-x64-archive') {
productJsonPath = path.resolve(dir, 'resources/app/product.json');
} else if (process.platform === 'darwin') {
} else if (platform === 'darwin') {
productJsonPath = path.resolve(dir, 'Visual Studio Code - Insiders.app/Contents/Resources/app/product.json');
} else {
productJsonPath = path.resolve(dir, 'VSCode-linux-x64/resources/app/product.json');
Expand Down Expand Up @@ -136,14 +136,14 @@ export async function getLatestInsidersMetadata(platform: string) {
* Resolve the VS Code cli path from executable path returned from `downloadAndUnzipVSCode`.
* Usually you will want {@link resolveCliArgsFromVSCodeExecutablePath} instead.
*/
export function resolveCliPathFromVSCodeExecutablePath(vscodeExecutablePath: string) {
if (process.platform === 'win32') {
export function resolveCliPathFromVSCodeExecutablePath(vscodeExecutablePath: string, platform: DownloadPlatform) {
if (platform === 'win32') {
if (vscodeExecutablePath.endsWith('Code - Insiders.exe')) {
return path.resolve(vscodeExecutablePath, '../bin/code-insiders.cmd');
} else {
return path.resolve(vscodeExecutablePath, '../bin/code.cmd');
}
} else if (process.platform === 'darwin') {
} else if (platform === 'darwin') {
return path.resolve(vscodeExecutablePath, '../../../Contents/Resources/app/bin/code');
} else {
if (vscodeExecutablePath.endsWith('code-insiders')) {
Expand Down Expand Up @@ -171,8 +171,8 @@ export function resolveCliPathFromVSCodeExecutablePath(vscodeExecutablePath: str
*
* @param vscodeExecutablePath The `vscodeExecutablePath` from `downloadAndUnzipVSCode`.
*/
export function resolveCliArgsFromVSCodeExecutablePath(vscodeExecutablePath: string, options?: Pick<TestOptions, 'reuseMachineInstall'>) {
const args = [resolveCliPathFromVSCodeExecutablePath(vscodeExecutablePath)];
export function resolveCliArgsFromVSCodeExecutablePath(vscodeExecutablePath: string, options?: Pick<TestOptions, 'reuseMachineInstall' | 'platform'>) {
const args = [resolveCliPathFromVSCodeExecutablePath(vscodeExecutablePath, options?.platform ?? process.platform)];
if (!options?.reuseMachineInstall) {
args.push(...getProfileArguments(args));
}
Expand Down

0 comments on commit 50a3fde

Please sign in to comment.