Skip to content

Commit 3b58360

Browse files
committed
fix: installation error on various platforms
1 parent 6a5daf7 commit 3b58360

File tree

6 files changed

+75
-18
lines changed

6 files changed

+75
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
node_modules
33

44
out
5+
*.tgz

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
### 2.5.2 | 2024-04-09
4+
5+
- Fix install issue on various platforms
6+
37
### 2.5.1 | 2024-04-07
48

59
- Allow downloading server versions

lib/download.test.mts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ import {
1515
fetchTargetInferredVersion,
1616
} from './download.js';
1717
import { SilentReporter } from './progress.js';
18-
import { resolveCliPathFromVSCodeExecutablePath, systemDefaultPlatform } from './util.js';
18+
import {
19+
isPlatformDarwin,
20+
isPlatformLinux,
21+
isPlatformWindows,
22+
resolveCliPathFromVSCodeExecutablePath
23+
} from './util.js';
1924

2025
const platforms = [
2126
'darwin',
@@ -25,6 +30,14 @@ const platforms = [
2530
'linux-x64',
2631
'linux-arm64',
2732
'linux-armhf',
33+
34+
'cli-linux-x64',
35+
'cli-win32-x64',
36+
'cli-darwin-x64',
37+
38+
'server-win32-x64',
39+
'server-darwin',
40+
'server-linux-x64',
2841
];
2942

3043
describe('sane downloads', () => {
@@ -34,6 +47,13 @@ describe('sane downloads', () => {
3447
await fs.mkdir(testTempDir, { recursive: true });
3548
});
3649

50+
const isRunnableOnThisPlatform =
51+
process.platform === 'win32'
52+
? isPlatformWindows
53+
: process.platform === 'darwin'
54+
? isPlatformDarwin
55+
: isPlatformLinux;
56+
3757
for (const quality of ['insiders', 'stable']) {
3858
for (const platform of platforms) {
3959
test.concurrent(`${quality}/${platform}`, async () => {
@@ -53,7 +73,7 @@ describe('sane downloads', () => {
5373
throw new Error(`expected ${exePath} to from ${location}`);
5474
}
5575

56-
if (platform === systemDefaultPlatform) {
76+
if (platform.includes(process.arch) && isRunnableOnThisPlatform(platform)) {
5777
const shell = process.platform === 'win32';
5878
const version = spawnSync(shell ? `"${exePath}"` : exePath, ['--version'], { shell });
5979
expect(version.status).to.equal(0);

lib/download.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
insidersDownloadDirToExecutablePath,
2222
isDefined,
2323
isPlatformCLI,
24+
isPlatformServer,
2425
isSubdirectory,
2526
onceWithoutRejections,
2627
streamToBuffer,
@@ -349,9 +350,9 @@ async function unzipVSCode(
349350
) {
350351
const stagingFile = path.join(tmpdir(), `vscode-test-${Date.now()}.zip`);
351352
const checksum = validateStream(stream, length, sha256);
352-
const stripComponents = isPlatformCLI(platform) ? 0 : 1;
353353

354354
if (format === 'zip') {
355+
const stripComponents = isPlatformServer(platform) ? 1 : 0;
355356
try {
356357
reporter.report({ stage: ProgressReportStage.ExtractingSynchonrously });
357358

@@ -409,6 +410,8 @@ async function unzipVSCode(
409410
fs.unlink(stagingFile, () => undefined);
410411
}
411412
} else {
413+
const stripComponents = isPlatformCLI(platform) ? 0 : 1;
414+
412415
// tar does not create extractDir by default
413416
if (!fs.existsSync(extractDir)) {
414417
fs.mkdirSync(extractDir);

lib/util.ts

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export let systemDefaultPlatform: DownloadPlatform;
2020

2121
export const isPlatformWindows = (platform: string) => platform.includes('win32');
2222
export const isPlatformDarwin = (platform: string) => platform.includes('darwin');
23+
export const isPlatformLinux = (platform: string) => platform.includes('linux');
2324
export const isPlatformServer = (platform: string) => platform.includes('server');
2425
export const isPlatformCLI = (platform: string) => platform.includes('cli-');
2526

@@ -108,28 +109,38 @@ export function urlToOptions(url: string): https.RequestOptions {
108109
}
109110

110111
export function downloadDirToExecutablePath(dir: string, platform: DownloadPlatform) {
111-
if (isPlatformWindows(platform)) {
112-
return isPlatformServer(platform) ? path.resolve(dir, 'bin', 'code-server.cmd') : path.resolve(dir, 'Code.exe');
113-
} else if (isPlatformServer(platform)) {
114-
return path.resolve(dir, 'bin', 'code-server');
115-
} else if (isPlatformDarwin(platform)) {
116-
return path.resolve(dir, 'Visual Studio Code.app/Contents/MacOS/Electron');
112+
if (isPlatformServer(platform)) {
113+
return isPlatformWindows(platform)
114+
? path.resolve(dir, 'bin', 'code-server.cmd')
115+
: path.resolve(dir, 'bin', 'code-server');
116+
} else if (isPlatformCLI(platform)) {
117+
return isPlatformWindows(platform) ? path.resolve(dir, 'code.exe') : path.resolve(dir, 'code');
117118
} else {
118-
return path.resolve(dir, 'code');
119+
if (isPlatformWindows(platform)) {
120+
return path.resolve(dir, 'Code.exe');
121+
} else if (isPlatformDarwin(platform)) {
122+
return path.resolve(dir, 'Visual Studio Code.app/Contents/MacOS/Electron');
123+
} else {
124+
return path.resolve(dir, 'code');
125+
}
119126
}
120127
}
121128

122129
export function insidersDownloadDirToExecutablePath(dir: string, platform: DownloadPlatform) {
123-
if (isPlatformWindows(platform)) {
124-
return isPlatformServer(platform)
130+
if (isPlatformServer(platform)) {
131+
return isPlatformWindows(platform)
125132
? path.resolve(dir, 'bin', 'code-server-insiders.cmd')
126-
: path.resolve(dir, 'Code - Insiders.exe');
127-
} else if (isPlatformServer(platform)) {
128-
return path.resolve(dir, 'bin', 'code-server-insiders');
129-
} else if (isPlatformDarwin(platform)) {
130-
return path.resolve(dir, 'Visual Studio Code - Insiders.app/Contents/MacOS/Electron');
133+
: path.resolve(dir, 'bin', 'code-server-insiders');
134+
} else if (isPlatformCLI(platform)) {
135+
return isPlatformWindows(platform) ? path.resolve(dir, 'code-insiders.exe') : path.resolve(dir, 'code-insiders');
131136
} else {
132-
return path.resolve(dir, 'code-insiders');
137+
if (isPlatformWindows(platform)) {
138+
return path.resolve(dir, 'Code - Insiders.exe');
139+
} else if (isPlatformDarwin(platform)) {
140+
return path.resolve(dir, 'Visual Studio Code - Insiders.app/Contents/MacOS/Electron');
141+
} else {
142+
return path.resolve(dir, 'code-insiders');
143+
}
133144
}
134145
}
135146

@@ -193,6 +204,10 @@ export function resolveCliPathFromVSCodeExecutablePath(
193204
if (platform === 'win32-archive') {
194205
throw new Error('Windows 32-bit is no longer supported');
195206
}
207+
if (isPlatformServer(platform) || isPlatformCLI(platform)) {
208+
// no separate CLI
209+
return vscodeExecutablePath;
210+
}
196211
if (isPlatformWindows(platform)) {
197212
if (vscodeExecutablePath.endsWith('Code - Insiders.exe')) {
198213
return path.resolve(vscodeExecutablePath, '../bin/code-insiders.cmd');

pipeline.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,24 @@ extends:
2929
- script: npm ci
3030
displayName: Install dependencies
3131

32+
testPlatforms:
33+
- name: Linux
34+
nodeVersions:
35+
- 20.x
36+
- name: MacOS
37+
nodeVersions:
38+
- 20.x
39+
- name: Windows
40+
nodeVersions:
41+
- 20.x
42+
3243
testSteps:
3344
- script: npm ci
3445
displayName: Install dependencies
3546

47+
- script: npm test
48+
displayName: Run own tests
49+
3650
- script: cd sample && npm ci
3751
displayName: Install dependencies (fs-provider)
3852

0 commit comments

Comments
 (0)