Skip to content

Commit

Permalink
tmp: work around a problem with processx on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilzyla committed Oct 17, 2024
1 parent 09b60f1 commit 47b05db
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions R/node.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ npm <- function(...) {
node_check <- function() {
npm_command <- Sys.getenv("RHINO_NPM", "npm")
version <- tryCatch(
processx::run(npm_command, "--version")$stdout,
processx::run("cmd", rlang::chr("/c", npm_command, "--version"))$stdout,
error = function(e) NULL
)
list(
Expand Down Expand Up @@ -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()
}
}

0 comments on commit 47b05db

Please sign in to comment.