@@ -14,11 +14,14 @@ import { URL } from 'url';
14
14
import { DownloadOptions , DownloadPlatform , defaultCachePath , downloadAndUnzipVSCode } from './download' ;
15
15
import * as request from './request' ;
16
16
import { TestOptions } from './runTest' ;
17
+ import { ProgressReporter } from './progress' ;
17
18
18
19
export let systemDefaultPlatform : DownloadPlatform ;
19
20
20
- const windowsPlatforms = new Set < DownloadPlatform > ( [ 'win32-x64-archive' , 'win32-arm64-archive' ] ) ;
21
- const darwinPlatforms = new Set < DownloadPlatform > ( [ 'darwin-arm64' , 'darwin' ] ) ;
21
+ export const isPlatformWindows = ( platform : string ) => platform . includes ( 'win32' ) ;
22
+ export const isPlatformDarwin = ( platform : string ) => platform . includes ( 'darwin' ) ;
23
+ export const isPlatformServer = ( platform : string ) => platform . includes ( 'server' ) ;
24
+ export const isPlatformCLI = ( platform : string ) => platform . includes ( 'cli-' ) ;
22
25
23
26
switch ( process . platform ) {
24
27
case 'darwin' :
@@ -44,7 +47,10 @@ export class Version {
44
47
return new Version ( version , ! unreleased ) ;
45
48
}
46
49
47
- constructor ( public readonly id : string , public readonly isReleased = true ) { }
50
+ constructor (
51
+ public readonly id : string ,
52
+ public readonly isReleased = true ,
53
+ ) { }
48
54
49
55
public get isCommit ( ) {
50
56
return / ^ [ 0 - 9 a - f ] { 40 } $ / . test ( this . id ) ;
@@ -102,40 +108,57 @@ export function urlToOptions(url: string): https.RequestOptions {
102
108
}
103
109
104
110
export function downloadDirToExecutablePath ( dir : string , platform : DownloadPlatform ) {
105
- if ( windowsPlatforms . has ( platform ) ) {
106
- return path . resolve ( dir , 'Code.exe' ) ;
107
- } else if ( darwinPlatforms . has ( platform ) ) {
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 ) ) {
108
116
return path . resolve ( dir , 'Visual Studio Code.app/Contents/MacOS/Electron' ) ;
109
117
} else {
110
118
return path . resolve ( dir , 'code' ) ;
111
119
}
112
120
}
113
121
114
122
export function insidersDownloadDirToExecutablePath ( dir : string , platform : DownloadPlatform ) {
115
- if ( windowsPlatforms . has ( platform ) ) {
116
- return path . resolve ( dir , 'Code - Insiders.exe' ) ;
117
- } else if ( darwinPlatforms . has ( platform ) ) {
123
+ if ( isPlatformWindows ( platform ) ) {
124
+ return isPlatformServer ( platform )
125
+ ? 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 ) ) {
118
130
return path . resolve ( dir , 'Visual Studio Code - Insiders.app/Contents/MacOS/Electron' ) ;
119
131
} else {
120
132
return path . resolve ( dir , 'code-insiders' ) ;
121
133
}
122
134
}
123
135
124
- export function insidersDownloadDirMetadata ( dir : string , platform : DownloadPlatform ) {
136
+ export function insidersDownloadDirMetadata ( dir : string , platform : DownloadPlatform , reporter : ProgressReporter ) {
125
137
let productJsonPath ;
126
- if ( windowsPlatforms . has ( platform ) ) {
138
+ if ( isPlatformServer ( platform ) ) {
139
+ productJsonPath = path . resolve ( dir , 'product.json' ) ;
140
+ } else if ( isPlatformWindows ( platform ) ) {
127
141
productJsonPath = path . resolve ( dir , 'resources/app/product.json' ) ;
128
- } else if ( darwinPlatforms . has ( platform ) ) {
142
+ } else if ( isPlatformDarwin ( platform ) ) {
129
143
productJsonPath = path . resolve ( dir , 'Visual Studio Code - Insiders.app/Contents/Resources/app/product.json' ) ;
130
144
} else {
131
145
productJsonPath = path . resolve ( dir , 'resources/app/product.json' ) ;
132
146
}
133
- const productJson = JSON . parse ( readFileSync ( productJsonPath , 'utf-8' ) ) ;
134
147
135
- return {
136
- version : productJson . commit ,
137
- date : new Date ( productJson . date ) ,
138
- } ;
148
+ try {
149
+ const productJson = JSON . parse ( readFileSync ( productJsonPath , 'utf-8' ) ) ;
150
+
151
+ return {
152
+ version : productJson . commit ,
153
+ date : new Date ( productJson . date ) ,
154
+ } ;
155
+ } catch ( e ) {
156
+ reporter . error ( `Error reading product.json (${ e } ) will download again` ) ;
157
+ return {
158
+ version : 'unknown' ,
159
+ date : new Date ( 0 ) ,
160
+ } ;
161
+ }
139
162
}
140
163
141
164
export interface IUpdateMetadata {
@@ -165,18 +188,18 @@ export async function getLatestInsidersMetadata(platform: string, released: bool
165
188
*/
166
189
export function resolveCliPathFromVSCodeExecutablePath (
167
190
vscodeExecutablePath : string ,
168
- platform : DownloadPlatform = systemDefaultPlatform
191
+ platform : DownloadPlatform = systemDefaultPlatform ,
169
192
) {
170
193
if ( platform === 'win32-archive' ) {
171
194
throw new Error ( 'Windows 32-bit is no longer supported' ) ;
172
195
}
173
- if ( windowsPlatforms . has ( platform ) ) {
196
+ if ( isPlatformWindows ( platform ) ) {
174
197
if ( vscodeExecutablePath . endsWith ( 'Code - Insiders.exe' ) ) {
175
198
return path . resolve ( vscodeExecutablePath , '../bin/code-insiders.cmd' ) ;
176
199
} else {
177
200
return path . resolve ( vscodeExecutablePath , '../bin/code.cmd' ) ;
178
201
}
179
- } else if ( darwinPlatforms . has ( platform ) ) {
202
+ } else if ( isPlatformDarwin ( platform ) ) {
180
203
return path . resolve ( vscodeExecutablePath , '../../../Contents/Resources/app/bin/code' ) ;
181
204
} else {
182
205
if ( vscodeExecutablePath . endsWith ( 'code-insiders' ) ) {
@@ -207,7 +230,7 @@ export function resolveCliPathFromVSCodeExecutablePath(
207
230
*/
208
231
export function resolveCliArgsFromVSCodeExecutablePath (
209
232
vscodeExecutablePath : string ,
210
- options ?: Pick < TestOptions , 'reuseMachineInstall' | 'platform' >
233
+ options ?: Pick < TestOptions , 'reuseMachineInstall' | 'platform' > ,
211
234
) {
212
235
const args = [
213
236
resolveCliPathFromVSCodeExecutablePath ( vscodeExecutablePath , options ?. platform ?? systemDefaultPlatform ) ,
@@ -258,7 +281,7 @@ export class VSCodeCommandError extends Error {
258
281
args : string [ ] ,
259
282
public readonly exitCode : number | null ,
260
283
public readonly stderr : string ,
261
- public stdout : string
284
+ public stdout : string ,
262
285
) {
263
286
super ( `'code ${ args . join ( ' ' ) } ' failed with exit code ${ exitCode } :\n\n${ stderr } \n\n${ stdout } ` ) ;
264
287
}
@@ -388,7 +411,7 @@ export function killTree(processId: number, force: boolean) {
388
411
cp = spawn (
389
412
path . join ( windir , 'System32' , 'taskkill.exe' ) ,
390
413
[ ...( force ? [ '/F' ] : [ ] ) , '/T' , '/PID' , processId . toString ( ) ] ,
391
- { stdio : 'inherit' }
414
+ { stdio : 'inherit' } ,
392
415
) ;
393
416
} else {
394
417
// on linux and OS X we kill all direct and indirect child processes as well
0 commit comments