diff --git a/rewrite-javascript/src/main/java/org/openrewrite/javascript/rpc/JavaScriptRewriteRpc.java b/rewrite-javascript/src/main/java/org/openrewrite/javascript/rpc/JavaScriptRewriteRpc.java index 4fa4aad2edf..749338a5e32 100644 --- a/rewrite-javascript/src/main/java/org/openrewrite/javascript/rpc/JavaScriptRewriteRpc.java +++ b/rewrite-javascript/src/main/java/org/openrewrite/javascript/rpc/JavaScriptRewriteRpc.java @@ -212,7 +212,6 @@ public static class Builder implements Supplier { private @Nullable Integer inspectBrk; private @Nullable Path inspectBrkRewriteSourcePath; - private @Nullable Integer maxHeapSize; private @Nullable Path workingDirectory; public Builder marketplace(RecipeMarketplace marketplace) { @@ -301,19 +300,6 @@ public Builder inspectBrk(Path rewriteDistPath) { return inspectBrk(rewriteDistPath, 9229); } - /** - * Set the maximum heap size for the Node.js process in megabytes. - * Default V8 heap size is approximately 1.5-2 GB on 64-bit systems. - * For large repositories with many source files, you may need to increase this. - * - * @param maxHeapSize Maximum heap size in megabytes (e.g., 4096 for 4GB) - * @return This builder - */ - public Builder maxHeapSize(@Nullable Integer maxHeapSize) { - this.maxHeapSize = maxHeapSize; - return this; - } - /** * Set the working directory for the Node.js process. * This affects where profile logs and other output files are generated. @@ -341,7 +327,6 @@ public JavaScriptRewriteRpc get() { "node", "--enable-source-maps", "--inspect-brk=" + inspectBrk, - maxHeapSize != null ? "--max-old-space-size=" + maxHeapSize : null, serverJs.toAbsolutePath().normalize().toString(), log == null ? null : "--log-file=" + log.toAbsolutePath().normalize(), traceRpcMessages ? "--trace-rpc-messages" : null, @@ -369,18 +354,9 @@ public JavaScriptRewriteRpc get() { process.setWorkingDirectory(workingDirectory); } - // Build NODE_OPTIONS with all necessary flags - StringBuilder nodeOptions = new StringBuilder("--enable-source-maps"); - if (inspectBrk == null) { - // When not using inspect-brk, we need to pass Node.js flags via NODE_OPTIONS - // since npx spawns a child process - // Note: --prof is not allowed in NODE_OPTIONS for security reasons - if (maxHeapSize != null) { - nodeOptions.append(" --max-old-space-size=").append(maxHeapSize); - } - } process.environment().putAll(environment); - process.environment().put("NODE_OPTIONS", nodeOptions.toString()); + // caller-provided options, if any, are taking precedence over the options baked above + process.environment().merge("NODE_OPTIONS", " --enable-source-maps", (callerProvided, local) -> local + " " + callerProvided); if (npxPath.getParent() != null) { // `npx` is typically a shebang script alongside the `node` executable process.environment().put("PATH", npxPath.getParent() + File.pathSeparator +