@@ -47,7 +47,6 @@ const getArgs = (): Args => {
47
47
case "wait" :
48
48
case "disable-gpu" :
49
49
// TODO: pretty sure these don't work but not 100%.
50
- case "max-memory" :
51
50
case "prof-startup" :
52
51
case "inspect-extensions" :
53
52
case "inspect-brk-extensions" :
@@ -82,8 +81,7 @@ const getArgs = (): Args => {
82
81
return validatePaths ( args ) ;
83
82
} ;
84
83
85
- const startVscode = async ( ) : Promise < void | void [ ] > => {
86
- const args = getArgs ( ) ;
84
+ const startVscode = async ( args : Args ) : Promise < void | void [ ] > => {
87
85
const extra = args [ "_" ] || [ ] ;
88
86
const options = {
89
87
auth : args . auth || AuthType . Password ,
@@ -155,8 +153,7 @@ const startVscode = async (): Promise<void | void[]> => {
155
153
}
156
154
} ;
157
155
158
- const startCli = ( ) : boolean | Promise < void > => {
159
- const args = getArgs ( ) ;
156
+ const startCli = ( args : Args ) : boolean | Promise < void > => {
160
157
if ( args . help ) {
161
158
const executable = `${ product . applicationName } ${ os . platform ( ) === "win32" ? ".exe" : "" } ` ;
162
159
console . log ( buildHelpMessage ( product . nameLong , executable , product . codeServerVersion , OPTIONS , false ) ) ;
@@ -198,7 +195,7 @@ export class WrapperProcess {
198
195
private started ?: Promise < void > ;
199
196
private currentVersion = product . codeServerVersion ;
200
197
201
- public constructor ( ) {
198
+ public constructor ( private readonly args : Args ) {
202
199
ipcMain . onMessage ( async ( message ) => {
203
200
switch ( message . type ) {
204
201
case "relaunch" :
@@ -235,6 +232,14 @@ export class WrapperProcess {
235
232
}
236
233
237
234
private spawn ( ) : cp . ChildProcess {
235
+ // Flags to pass along to the Node binary. We use the environment variable
236
+ // since otherwise the code-server binary will swallow them.
237
+ const maxMemory = this . args [ "max-memory" ] || 2048 ;
238
+ let nodeOptions = `${ process . env . NODE_OPTIONS || "" } ${ this . args [ "js-flags" ] || "" } ` ;
239
+ if ( ! / m a x _ o l d _ s p a c e _ s i z e = ( \d + ) / g. exec ( nodeOptions ) ) {
240
+ nodeOptions += ` --max_old_space_size=${ maxMemory } ` ;
241
+ }
242
+
238
243
// If we're using loose files then we need to specify the path. If we're in
239
244
// the binary we need to let the binary determine the path (via nbin) since
240
245
// it could be different between binaries which presents a problem when
@@ -246,18 +251,20 @@ export class WrapperProcess {
246
251
LAUNCH_VSCODE : "true" ,
247
252
NBIN_BYPASS : undefined ,
248
253
VSCODE_PARENT_PID : process . pid . toString ( ) ,
254
+ NODE_OPTIONS : nodeOptions ,
249
255
} ,
250
256
stdio : [ "inherit" , "inherit" , "inherit" , "ipc" ] ,
251
257
} ) ;
252
258
}
253
259
}
254
260
255
261
const main = async ( ) : Promise < boolean | void | void [ ] > => {
262
+ const args = getArgs ( ) ;
256
263
if ( process . env . LAUNCH_VSCODE ) {
257
264
await ipcMain . handshake ( ) ;
258
- return startVscode ( ) ;
265
+ return startVscode ( args ) ;
259
266
}
260
- return startCli ( ) || new WrapperProcess ( ) . start ( ) ;
267
+ return startCli ( args ) || new WrapperProcess ( args ) . start ( ) ;
261
268
} ;
262
269
263
270
const exit = process . exit ;
0 commit comments