From 08df826668662b66a017321aa3ec4736ad7450b8 Mon Sep 17 00:00:00 2001 From: Kamil Zyla Date: Mon, 7 Oct 2024 14:36:27 +0200 Subject: [PATCH] fix: worka around issue with processx on Windows --- R/node.R | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/R/node.R b/R/node.R index 4ab20c5a..f0e20894 100644 --- a/R/node.R +++ b/R/node.R @@ -60,18 +60,29 @@ node_init <- function(npm_command) { # Run the specified command in Node.js directory (assume it already exists). node_run <- function(command, ..., background = FALSE) { - args <- list( - command = command, - args = rlang::chr(...), + if (.Platform$OS.type == "windows") { + # Workaround: {processx} cannot find `npm` on Windows, but it works with a shell. + call_args <- list( + command = "cmd", + args = rlang::chr("/c", command, ...) + ) + } else { + call_args <- list( + command = command, + args = rlang::chr(...) + ) + } + call_args <- c( + call_args, wd = node_path(), stdin = NULL, stdout = "", stderr = "" ) if (background) { - do.call(processx::process$new, args) + do.call(processx::process$new, call_args) } else { - do.call(processx::run, args) + do.call(processx::run, call_args) invisible() } }