@@ -47,7 +47,6 @@ const getArgs = (): Args => {
4747 case "wait" :
4848 case "disable-gpu" :
4949 // TODO: pretty sure these don't work but not 100%.
50- case "max-memory" :
5150 case "prof-startup" :
5251 case "inspect-extensions" :
5352 case "inspect-brk-extensions" :
@@ -82,8 +81,7 @@ const getArgs = (): Args => {
8281 return validatePaths ( args ) ;
8382} ;
8483
85- const startVscode = async ( ) : Promise < void | void [ ] > => {
86- const args = getArgs ( ) ;
84+ const startVscode = async ( args : Args ) : Promise < void | void [ ] > => {
8785 const extra = args [ "_" ] || [ ] ;
8886 const options = {
8987 auth : args . auth || AuthType . Password ,
@@ -155,8 +153,7 @@ const startVscode = async (): Promise<void | void[]> => {
155153 }
156154} ;
157155
158- const startCli = ( ) : boolean | Promise < void > => {
159- const args = getArgs ( ) ;
156+ const startCli = ( args : Args ) : boolean | Promise < void > => {
160157 if ( args . help ) {
161158 const executable = `${ product . applicationName } ${ os . platform ( ) === "win32" ? ".exe" : "" } ` ;
162159 console . log ( buildHelpMessage ( product . nameLong , executable , product . codeServerVersion , OPTIONS , false ) ) ;
@@ -198,7 +195,7 @@ export class WrapperProcess {
198195 private started ?: Promise < void > ;
199196 private currentVersion = product . codeServerVersion ;
200197
201- public constructor ( ) {
198+ public constructor ( private readonly args : Args ) {
202199 ipcMain . onMessage ( async ( message ) => {
203200 switch ( message . type ) {
204201 case "relaunch" :
@@ -235,6 +232,14 @@ export class WrapperProcess {
235232 }
236233
237234 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+
238243 // If we're using loose files then we need to specify the path. If we're in
239244 // the binary we need to let the binary determine the path (via nbin) since
240245 // it could be different between binaries which presents a problem when
@@ -246,18 +251,20 @@ export class WrapperProcess {
246251 LAUNCH_VSCODE : "true" ,
247252 NBIN_BYPASS : undefined ,
248253 VSCODE_PARENT_PID : process . pid . toString ( ) ,
254+ NODE_OPTIONS : nodeOptions ,
249255 } ,
250256 stdio : [ "inherit" , "inherit" , "inherit" , "ipc" ] ,
251257 } ) ;
252258 }
253259}
254260
255261const main = async ( ) : Promise < boolean | void | void [ ] > => {
262+ const args = getArgs ( ) ;
256263 if ( process . env . LAUNCH_VSCODE ) {
257264 await ipcMain . handshake ( ) ;
258- return startVscode ( ) ;
265+ return startVscode ( args ) ;
259266 }
260- return startCli ( ) || new WrapperProcess ( ) . start ( ) ;
267+ return startCli ( args ) || new WrapperProcess ( args ) . start ( ) ;
261268} ;
262269
263270const exit = process . exit ;
0 commit comments