Skip to content

Commit 27b8d9f

Browse files
committed
Add directory containing npx to PATH when starting RPC
1 parent 75e1f80 commit 27b8d9f

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

rewrite-core/src/main/java/org/openrewrite/rpc/RewriteRpc.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,10 @@ protected <P> P send(String method, @Nullable RpcRequest body, Class<P> response
475475

476476
// If we get here, we've hit the total timeout
477477
throw new RuntimeException("Request timed out after " + timeout.getSeconds() + " seconds");
478+
} catch (RuntimeException e) {
479+
// Check if process crashed during the request
480+
checkLiveness();
481+
throw e;
478482
} catch (ExecutionException | InterruptedException e) {
479483
// Check if process crashed during the request
480484
checkLiveness();

rewrite-javascript/src/main/java/org/openrewrite/javascript/rpc/JavaScriptRewriteRpc.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,11 @@ public JavaScriptRewriteRpc get() {
275275
}
276276
}
277277
process.environment().put("NODE_OPTIONS", nodeOptions.toString());
278+
if (npxPath.getParent() != null) {
279+
// `npx` is typically a shebang script alongside the `node` executable
280+
process.environment().put("PATH", npxPath.getParent() + File.pathSeparator +
281+
System.getenv("PATH"));
282+
}
278283
process.start();
279284

280285
try {

0 commit comments

Comments
 (0)