@@ -99,14 +99,19 @@ public class TypeScriptParser {
9999 public static final String TYPESCRIPT_RAM_RESERVE_SUFFIX = "TYPESCRIPT_RAM_RESERVE" ;
100100
101101 /**
102- * An environment variable which, if set, allows a debugger to be attached to the Node.js
103- * process. Remote debugging will not be enabled.
102+ * An environment variable with additional VM arguments to pass to the Node process.
104103 * <p>
105- * If set to <code>break</code> the Node.js process will pause on entry waiting for the
106- * debugger to attach (<code>--inspect-brk</code>). If set to any other non-empty value,
107- * it will just enable debugging (<code>--inspect</code>).
104+ * Only <code>--inspect</code> or <code>--inspect-brk</code> may be used at the moment.
108105 */
109- public static final String TYPESCRIPT_ATTACH_DEBUGGER = "SEMMLE_TYPESCRIPT_ATTACH_DEBUGGER" ;
106+ public static final String TYPESCRIPT_NODE_FLAGS = "SEMMLE_TYPESCRIPT_NODE_FLAGS" ;
107+
108+ /**
109+ * Flags that may be passed using {@link #TYPESCRIPT_NODE_FLAGS}
110+ */
111+ private static final Set <String > allowedDebugNodeFlags = new HashSet <String >(Arrays .fromList (
112+ "--inspect" ,
113+ "--inspect-brk"
114+ ));
110115
111116 /** The Node.js parser wrapper process, if it has been started already. */
112117 private Process parserWrapperProcess ;
@@ -213,9 +218,7 @@ private List<String> getNodeJsRuntimeInvocation(String ...args) {
213218 result .add (nodeJsRuntime );
214219 result .addAll (nodeJsRuntimeExtraArgs );
215220 for (String arg : args ) {
216- if (arg .length () > 0 ) {
217- result .add (arg );
218- }
221+ result .add (arg );
219222 }
220223 return result ;
221224 }
@@ -249,21 +252,15 @@ private void setupParserWrapper() {
249252
250253 File parserWrapper = getParserWrapper ();
251254
252- String debuggerFlag = Env .systemEnv ().get (TYPESCRIPT_ATTACH_DEBUGGER );
253- String inspectArg = "" ;
254- if (debuggerFlag != null && debuggerFlag .length () > 0 ) {
255- if (debuggerFlag .equalsIgnoreCase ("break" )) {
256- inspectArg = "--inspect-brk" ;
257- } else {
258- inspectArg = "--inspect" ;
259- }
260- }
255+ String debugFlagString = Env .systemEnv ().getNonEmpty (TYPESCRIPT_NODE_FLAGS );
256+ List <String > debugFlags = debugFlagString == null ? new ArrayList <>() : debugFlagString .split (" " );
257+ debugFlags .retainAll (allowedDebugNodeFlags );
258+
259+ List <String > cmd = getNodeJsRuntimeInvocation ();
260+ cmd .add ("--max_old_space_size=" + (mainMemoryMb + reserveMemoryMb ));
261+ cmd .addAll (debugFlags );
262+ cmd .add (parserWrapper .getAbsolutePath ());
261263
262- List <String > cmd = getNodeJsRuntimeInvocation (
263- "--max_old_space_size=" + (mainMemoryMb + reserveMemoryMb ),
264- inspectArg ,
265- parserWrapper .getAbsolutePath ()
266- );
267264 ProcessBuilder pb = new ProcessBuilder (cmd );
268265 parserWrapperCommand = StringUtil .glue (" " , cmd );
269266 pb .environment ().put ("SEMMLE_TYPESCRIPT_MEMORY_THRESHOLD" , "" + mainMemoryMb );
0 commit comments