@@ -98,6 +98,16 @@ public class TypeScriptParser {
9898 */
9999 public static final String TYPESCRIPT_RAM_RESERVE_SUFFIX = "TYPESCRIPT_RAM_RESERVE" ;
100100
101+ /**
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.
104+ * <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>).
108+ */
109+ public static final String TYPESCRIPT_ATTACH_DEBUGGER = "SEMMLE_TYPESCRIPT_ATTACH_DEBUGGER" ;
110+
101111 /** The Node.js parser wrapper process, if it has been started already. */
102112 private Process parserWrapperProcess ;
103113
@@ -203,7 +213,9 @@ private List<String> getNodeJsRuntimeInvocation(String ...args) {
203213 result .add (nodeJsRuntime );
204214 result .addAll (nodeJsRuntimeExtraArgs );
205215 for (String arg : args ) {
206- result .add (arg );
216+ if (arg .length () > 0 ) {
217+ result .add (arg );
218+ }
207219 }
208220 return result ;
209221 }
@@ -236,9 +248,20 @@ private void setupParserWrapper() {
236248 int reserveMemoryMb = getMegabyteCountFromPrefixedEnv (TYPESCRIPT_RAM_RESERVE_SUFFIX , 400 );
237249
238250 File parserWrapper = getParserWrapper ();
239-
251+
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+ }
261+
240262 List <String > cmd = getNodeJsRuntimeInvocation (
241263 "--max_old_space_size=" + (mainMemoryMb + reserveMemoryMb ),
264+ inspectArg ,
242265 parserWrapper .getAbsolutePath ()
243266 );
244267 ProcessBuilder pb = new ProcessBuilder (cmd );
0 commit comments