@@ -7,53 +7,41 @@ import * as path from 'path';
7
7
import { URL } from 'url' ;
8
8
import * as https from 'https' ;
9
9
import * as request from './request' ;
10
- import { DownloadArchitecture , DownloadPlatform } from './download' ;
10
+ import { DownloadPlatform } from './download' ;
11
11
import * as createHttpsProxyAgent from 'https-proxy-agent' ;
12
12
import * as createHttpProxyAgent from 'http-proxy-agent' ;
13
13
import { readFileSync } from 'fs' ;
14
14
import { getProfileArguments , TestOptions } from './runTest' ;
15
15
16
16
export let systemDefaultPlatform : DownloadPlatform ;
17
17
18
+ const windowsPlatforms = new Set < DownloadPlatform > ( [ 'win32-archive' , 'win32-x64-archive' , 'win32-arm64-archive' ] ) ;
19
+ const darwinPlatforms = new Set < DownloadPlatform > ( [ 'darwin-arm64' , 'darwin' ] ) ;
20
+
18
21
switch ( process . platform ) {
19
22
case 'darwin' :
20
- systemDefaultPlatform = 'darwin' ;
23
+ systemDefaultPlatform = process . arch === 'arm64' ? 'darwin-arm64' : 'darwin' ;
21
24
break ;
22
25
case 'win32' :
23
- systemDefaultPlatform = 'win32-archive' ;
26
+ systemDefaultPlatform = process . arch === 'arm64'
27
+ ? 'win32-arm64-archive'
28
+ : process . arch === 'ia32'
29
+ ? 'win32-archive'
30
+ : 'win32-x64-archive' ;
24
31
break ;
25
32
default :
26
- systemDefaultPlatform = 'linux-x64' ;
33
+ systemDefaultPlatform = process . arch === 'arm64'
34
+ ? 'linux-arm64'
35
+ : process . arch === 'arm'
36
+ ? 'linux-armhf'
37
+ : 'linux-x64' ;
27
38
}
28
39
29
- export const systemDefaultArchitecture = process . arch === 'arm64'
30
- ? DownloadArchitecture . ARM64
31
- : process . arch === 'ia32'
32
- ? DownloadArchitecture . X86
33
- : DownloadArchitecture . X64 ;
34
-
35
- export function getVSCodeDownloadUrl ( version : string , platform = systemDefaultPlatform , architecture = systemDefaultArchitecture ) {
36
-
37
- let downloadSegment : string ;
38
- switch ( platform ) {
39
- case 'darwin' :
40
- downloadSegment = architecture === DownloadArchitecture . ARM64 ? 'darwin-arm64' : 'darwin' ;
41
- break ;
42
- case 'win32-archive' :
43
- downloadSegment = architecture === DownloadArchitecture . ARM64 ? 'win32-arm64-archive' : 'win32-archive' ;
44
- break ;
45
- case 'linux-x64' :
46
- downloadSegment = architecture === DownloadArchitecture . ARM64 ? 'linux-arm64' : 'linux-x64' ;
47
- break ;
48
- default :
49
- downloadSegment = platform ;
50
- break ;
51
- }
52
-
40
+ export function getVSCodeDownloadUrl ( version : string , platform = systemDefaultPlatform ) {
53
41
if ( version === 'insiders' ) {
54
- return `https://update.code.visualstudio.com/latest/${ downloadSegment } /insider` ;
42
+ return `https://update.code.visualstudio.com/latest/${ platform } /insider` ;
55
43
}
56
- return `https://update.code.visualstudio.com/${ version } /${ downloadSegment } /stable` ;
44
+ return `https://update.code.visualstudio.com/${ version } /${ platform } /stable` ;
57
45
}
58
46
59
47
let PROXY_AGENT : createHttpProxyAgent . HttpProxyAgent | undefined = undefined ;
@@ -82,33 +70,33 @@ export function urlToOptions(url: string): https.RequestOptions {
82
70
}
83
71
84
72
export function downloadDirToExecutablePath ( dir : string , platform : DownloadPlatform ) {
85
- if ( platform === 'win32-archive' || platform === 'win32-x64-archive' ) {
73
+ if ( windowsPlatforms . has ( platform ) ) {
86
74
return path . resolve ( dir , 'Code.exe' ) ;
87
- } else if ( platform === 'darwin' ) {
75
+ } else if ( darwinPlatforms . has ( platform ) ) {
88
76
return path . resolve ( dir , 'Visual Studio Code.app/Contents/MacOS/Electron' ) ;
89
77
} else {
90
- return path . resolve ( dir , 'VSCode-linux-x64/ code' ) ;
78
+ return path . resolve ( dir , 'code' ) ;
91
79
}
92
80
}
93
81
94
82
export function insidersDownloadDirToExecutablePath ( dir : string , platform : DownloadPlatform ) {
95
- if ( platform === 'win32-archive' || platform === 'win32-x64-archive' ) {
83
+ if ( windowsPlatforms . has ( platform ) ) {
96
84
return path . resolve ( dir , 'Code - Insiders.exe' ) ;
97
- } else if ( platform === 'darwin' ) {
85
+ } else if ( darwinPlatforms . has ( platform ) ) {
98
86
return path . resolve ( dir , 'Visual Studio Code - Insiders.app/Contents/MacOS/Electron' ) ;
99
87
} else {
100
- return path . resolve ( dir , 'VSCode-linux-x64/ code-insiders' ) ;
88
+ return path . resolve ( dir , 'code-insiders' ) ;
101
89
}
102
90
}
103
91
104
92
export function insidersDownloadDirMetadata ( dir : string , platform : DownloadPlatform ) {
105
93
let productJsonPath ;
106
- if ( platform === 'win32-archive' || platform === 'win32-x64-archive' ) {
94
+ if ( windowsPlatforms . has ( platform ) ) {
107
95
productJsonPath = path . resolve ( dir , 'resources/app/product.json' ) ;
108
- } else if ( platform === 'darwin' ) {
96
+ } else if ( darwinPlatforms . has ( platform ) ) {
109
97
productJsonPath = path . resolve ( dir , 'Visual Studio Code - Insiders.app/Contents/Resources/app/product.json' ) ;
110
98
} else {
111
- productJsonPath = path . resolve ( dir , 'VSCode-linux-x64/ resources/app/product.json' ) ;
99
+ productJsonPath = path . resolve ( dir , 'resources/app/product.json' ) ;
112
100
}
113
101
const productJson = JSON . parse ( readFileSync ( productJsonPath , 'utf-8' ) ) ;
114
102
@@ -140,13 +128,13 @@ export async function getLatestInsidersMetadata(platform: string) {
140
128
* Usually you will want {@link resolveCliArgsFromVSCodeExecutablePath} instead.
141
129
*/
142
130
export function resolveCliPathFromVSCodeExecutablePath ( vscodeExecutablePath : string , platform : DownloadPlatform ) {
143
- if ( platform === 'win32-archive' || platform === 'win32-x64-archive' ) {
131
+ if ( windowsPlatforms . has ( platform ) ) {
144
132
if ( vscodeExecutablePath . endsWith ( 'Code - Insiders.exe' ) ) {
145
133
return path . resolve ( vscodeExecutablePath , '../bin/code-insiders.cmd' ) ;
146
134
} else {
147
135
return path . resolve ( vscodeExecutablePath , '../bin/code.cmd' ) ;
148
136
}
149
- } else if ( platform === 'darwin' ) {
137
+ } else if ( darwinPlatforms . has ( platform ) ) {
150
138
return path . resolve ( vscodeExecutablePath , '../../../Contents/Resources/app/bin/code' ) ;
151
139
} else {
152
140
if ( vscodeExecutablePath . endsWith ( 'code-insiders' ) ) {
0 commit comments