@@ -20,21 +20,34 @@ class Builder {
20
20
private readonly rootPath = path . resolve ( __dirname , ".." ) ;
21
21
private readonly outPath = process . env . OUT || this . rootPath ;
22
22
private _target ?: "darwin" | "alpine" | "linux" ;
23
- private task ?: Task ;
23
+ private currentTask ?: Task ;
24
24
25
25
public run ( task : Task | undefined , args : string [ ] ) : void {
26
- this . task = task ;
26
+ this . currentTask = task ;
27
27
this . doRun ( task , args ) . catch ( ( error ) => {
28
28
console . error ( error . message ) ;
29
29
process . exit ( 1 ) ;
30
30
} ) ;
31
31
}
32
32
33
+ private async task < T > ( message : string , fn : ( ) => Promise < T > ) : Promise < T > {
34
+ const time = Date . now ( ) ;
35
+ this . log ( `${ message } ...` , true ) ;
36
+ try {
37
+ const t = await fn ( ) ;
38
+ process . stdout . write ( `took ${ Date . now ( ) - time } ms\n` ) ;
39
+ return t ;
40
+ } catch ( error ) {
41
+ process . stdout . write ( "failed\n" ) ;
42
+ throw error ;
43
+ }
44
+ }
45
+
33
46
/**
34
47
* Writes to stdout with an optional newline.
35
48
*/
36
49
private log ( message : string , skipNewline : boolean = false ) : void {
37
- process . stdout . write ( `[${ this . task || "default" } ] ${ message } ` ) ;
50
+ process . stdout . write ( `[${ this . currentTask || "default" } ] ${ message } ` ) ;
38
51
if ( ! skipNewline ) {
39
52
process . stdout . write ( "\n" ) ;
40
53
}
@@ -140,43 +153,28 @@ class Builder {
140
153
* Build code-server within VS Code.
141
154
*/
142
155
private async build ( vscodeSourcePath : string , vscodeVersion : string , codeServerVersion : string , finalBuildPath : string ) : Promise < void > {
143
- const task = async < T > ( message : string , fn : ( ) => Promise < T > ) : Promise < T > => {
144
- const time = Date . now ( ) ;
145
- this . log ( `${ message } ...` , true ) ;
146
- try {
147
- const t = await fn ( ) ;
148
- process . stdout . write ( `took ${ Date . now ( ) - time } ms\n` ) ;
149
- return t ;
150
- } catch ( error ) {
151
- process . stdout . write ( "failed\n" ) ;
152
- throw error ;
153
- }
154
- } ;
155
-
156
156
// Install dependencies (should be cached by CI).
157
- // Ignore scripts since we'll install VS Code dependencies separately.
158
- await task ( "Installing code-server dependencies" , async ( ) => {
159
- await util . promisify ( cp . exec ) ( "yarn --ignore-scripts" , { cwd : this . rootPath } ) ;
160
- await util . promisify ( cp . exec ) ( "yarn postinstall" , { cwd : this . rootPath } ) ;
157
+ await this . task ( "Installing code-server dependencies" , async ( ) => {
158
+ await util . promisify ( cp . exec ) ( "yarn" , { cwd : this . rootPath } ) ;
161
159
} ) ;
162
160
163
161
// Download and prepare VS Code if necessary (should be cached by CI).
164
162
const exists = fs . existsSync ( vscodeSourcePath ) ;
165
163
if ( exists ) {
166
164
this . log ( "Using existing VS Code directory" ) ;
167
165
} else {
168
- await task ( "Cloning VS Code" , ( ) => {
166
+ await this . task ( "Cloning VS Code" , ( ) => {
169
167
return util . promisify ( cp . exec ) (
170
168
"git clone https://github.com/microsoft/vscode"
171
169
+ ` --quiet --branch "${ vscodeVersion } "`
172
170
+ ` --single-branch --depth=1 "${ vscodeSourcePath } "` ) ;
173
171
} ) ;
174
172
175
- await task ( "Installing VS Code dependencies" , ( ) => {
173
+ await this . task ( "Installing VS Code dependencies" , ( ) => {
176
174
return util . promisify ( cp . exec ) ( "yarn" , { cwd : vscodeSourcePath } ) ;
177
175
} ) ;
178
176
179
- await task ( "Building default extensions" , ( ) => {
177
+ await this . task ( "Building default extensions" , ( ) => {
180
178
return util . promisify ( cp . exec ) (
181
179
"yarn gulp compile-extensions-build --max-old-space-size=32384" ,
182
180
{ cwd : vscodeSourcePath } ,
@@ -185,31 +183,31 @@ class Builder {
185
183
}
186
184
187
185
// Clean before patching or it could fail if already patched.
188
- await task ( "Patching VS Code" , async ( ) => {
186
+ await this . task ( "Patching VS Code" , async ( ) => {
189
187
await util . promisify ( cp . exec ) ( "git reset --hard" , { cwd : vscodeSourcePath } ) ;
190
188
await util . promisify ( cp . exec ) ( "git clean -fd" , { cwd : vscodeSourcePath } ) ;
191
189
await util . promisify ( cp . exec ) ( `git apply ${ this . rootPath } /scripts/vscode.patch` , { cwd : vscodeSourcePath } ) ;
192
190
} ) ;
193
191
194
192
const serverPath = path . join ( vscodeSourcePath , "src/vs/server" ) ;
195
- await task ( "Copying code-server into VS Code" , async ( ) => {
193
+ await this . task ( "Copying code-server into VS Code" , async ( ) => {
196
194
await fs . remove ( serverPath ) ;
197
195
await fs . mkdirp ( serverPath ) ;
198
196
await Promise . all ( [ "main.js" , "node_modules" , "src" , "typings" ] . map ( ( fileName ) => {
199
197
return fs . copy ( path . join ( this . rootPath , fileName ) , path . join ( serverPath , fileName ) ) ;
200
198
} ) ) ;
201
199
} ) ;
202
200
203
- await task ( "Building VS Code" , ( ) => {
201
+ await this . task ( "Building VS Code" , ( ) => {
204
202
return util . promisify ( cp . exec ) ( "yarn gulp compile-build --max-old-space-size=32384" , { cwd : vscodeSourcePath } ) ;
205
203
} ) ;
206
204
207
- await task ( "Optimizing VS Code" , async ( ) => {
205
+ await this . task ( "Optimizing VS Code" , async ( ) => {
208
206
await fs . copyFile ( path . join ( this . rootPath , "scripts/optimize.js" ) , path . join ( vscodeSourcePath , "coder.js" ) ) ;
209
207
await util . promisify ( cp . exec ) ( `yarn gulp optimize --max-old-space-size=32384 --gulpfile ./coder.js` , { cwd : vscodeSourcePath } ) ;
210
208
} ) ;
211
209
212
- const { productJson, packageJson } = await task ( "Generating final package.json and product.json" , async ( ) => {
210
+ const { productJson, packageJson } = await this . task ( "Generating final package.json and product.json" , async ( ) => {
213
211
const merge = async ( name : string , extraJson : { [ key : string ] : string } = { } ) : Promise < { [ key : string ] : string } > => {
214
212
const [ aJson , bJson ] = ( await Promise . all ( [
215
213
fs . readFile ( path . join ( vscodeSourcePath , `${ name } .json` ) , "utf8" ) ,
@@ -247,13 +245,13 @@ class Builder {
247
245
} ) ;
248
246
249
247
if ( process . env . MINIFY ) {
250
- await task ( "Minifying VS Code" , ( ) => {
248
+ await this . task ( "Minifying VS Code" , ( ) => {
251
249
return util . promisify ( cp . exec ) ( "yarn gulp minify --max-old-space-size=32384 --gulpfile ./coder.js" , { cwd : vscodeSourcePath } ) ;
252
250
} ) ;
253
251
}
254
252
255
253
const finalServerPath = path . join ( finalBuildPath , "out/vs/server" ) ;
256
- await task ( "Copying into final build directory" , async ( ) => {
254
+ await this . task ( "Copying into final build directory" , async ( ) => {
257
255
await fs . remove ( finalBuildPath ) ;
258
256
await fs . mkdirp ( finalBuildPath ) ;
259
257
await Promise . all ( [
@@ -271,18 +269,17 @@ class Builder {
271
269
} ) ;
272
270
273
271
if ( process . env . MINIFY ) {
274
- await task ( "Restricting to production dependencies" , async ( ) => {
272
+ await this . task ( "Restricting to production dependencies" , async ( ) => {
275
273
await Promise . all ( [ "package.json" , "yarn.lock" ] . map ( ( fileName ) => {
276
274
Promise . all ( [
277
275
fs . copy ( path . join ( this . rootPath , fileName ) , path . join ( finalServerPath , fileName ) ) ,
278
276
fs . copy ( path . join ( path . join ( vscodeSourcePath , "remote" ) , fileName ) , path . join ( finalBuildPath , fileName ) ) ,
279
277
] ) ;
280
278
} ) ) ;
281
279
282
- await Promise . all ( [
283
- util . promisify ( cp . exec ) ( "yarn --production --ignore-scripts" , { cwd : finalServerPath } ) ,
284
- util . promisify ( cp . exec ) ( "yarn --production" , { cwd : finalBuildPath } ) ,
285
- ] ) ;
280
+ await Promise . all ( [ finalServerPath , finalBuildPath ] . map ( ( cwd ) => {
281
+ return util . promisify ( cp . exec ) ( "yarn --production" , { cwd } ) ;
282
+ } ) ) ;
286
283
287
284
await Promise . all ( [ "package.json" , "yarn.lock" ] . map ( ( fileName ) => {
288
285
return Promise . all ( [
@@ -293,15 +290,15 @@ class Builder {
293
290
} ) ;
294
291
}
295
292
296
- await task ( "Writing final package.json and product.json" , ( ) => {
293
+ await this . task ( "Writing final package.json and product.json" , ( ) => {
297
294
return Promise . all ( [
298
295
fs . writeFile ( path . join ( finalBuildPath , "package.json" ) , JSON . stringify ( packageJson , null , 2 ) ) ,
299
296
fs . writeFile ( path . join ( finalBuildPath , "product.json" ) , JSON . stringify ( productJson , null , 2 ) ) ,
300
297
] ) ;
301
298
} ) ;
302
299
303
300
// This is so it doesn't get cached along with VS Code (no point).
304
- await task ( "Removing copied server" , ( ) => fs . remove ( serverPath ) ) ;
301
+ await this . task ( "Removing copied server" , ( ) => fs . remove ( serverPath ) ) ;
305
302
306
303
// Prepend code to the target which enables finding files within the binary.
307
304
const prependLoader = async ( relativeFilePath : string ) : Promise < void > => {
@@ -322,7 +319,7 @@ class Builder {
322
319
await fs . writeFile ( filePath , shim + ( await fs . readFile ( filePath , "utf8" ) ) ) ;
323
320
} ;
324
321
325
- await task ( "Prepending nbin loader" , ( ) => {
322
+ await this . task ( "Prepending nbin loader" , ( ) => {
326
323
return Promise . all ( [
327
324
prependLoader ( "out/vs/server/main.js" ) ,
328
325
prependLoader ( "out/bootstrap-fork.js" ) ,
0 commit comments