diff --git a/R/config.R b/R/config.R index ed91ba76..7ac65222 100644 --- a/R/config.R +++ b/R/config.R @@ -37,11 +37,6 @@ rhino_config_definition <- list( validator = option_validator("app_dir", "source", "box_top_level"), required = FALSE ), - list( - name = "js_package_manager", - validator = option_validator("npm", "bun"), - required = FALSE - ), list( name = "legacy_max_lint_r_errors", validator = positive_integer_validator, @@ -83,11 +78,5 @@ validate_config <- function(definition, config) { read_config <- function() { config <- read_yaml("rhino") validate_config(rhino_config_definition, config) - # using npm by default - config$js_package_manager <- ifelse( - is.null(config$js_package_manager), - "npm", - config$js_package_manager - ) config } diff --git a/R/node.R b/R/node.R index a63a245c..866cded1 100644 --- a/R/node.R +++ b/R/node.R @@ -2,16 +2,9 @@ node_path <- function(...) { fs::path(".rhino", ...) } -add_node <- function(clean = FALSE) { - if (clean && fs::dir_exists(node_path())) { - fs::dir_delete(node_path()) - } - copy_template("node", node_path()) -} - # Run `npm`/`bun` command (assume node directory already exists in the project). js_package_manager_raw <- function(..., status_ok = 0) { - command <- read_config()$js_package_manager + command <- Sys.getenv("RHINO_NPM", "npm") withr::with_dir(node_path(), { status <- system2(command = command, args = c(...)) }) @@ -22,14 +15,11 @@ js_package_manager_raw <- function(..., status_ok = 0) { # Run `npm`/`bun` command (create node directory in the project if needed). js_package_manager <- function(...) { - command <- read_config()$js_package_manager - display_names <- list( - npm = "Node.js", - bun = "Bun" - ) + command <- Sys.getenv("RHINO_NPM", "npm") + display_name <- ifelse(command == "npm", "Node.js", command) check_system_dependency( cmd = command, - dependency_name = display_names[[command]], + dependency_name = display_name, documentation_url = "https://go.appsilon.com/rhino-system-dependencies" ) init_js_package_manager() @@ -37,13 +27,16 @@ js_package_manager <- function(...) { } init_js_package_manager <- function() { - command <- read_config()$js_package_manager + command <- Sys.getenv("RHINO_NPM", "npm") if (!fs::dir_exists(node_path())) { - message("Initializing Javascript packages…") - add_node() + message("Initializing Javascript configs\u2026") + copy_template("node", node_path()) } + + # existing .rhino and missing node_modules folder + # indicate that packages were not installed but rhino project initialized if (!fs::dir_exists(node_path("node_modules"))) { - message("Installing dependencies by ", command, "…") + message("Installing dependencies by ", command, "\u2026") js_package_manager_raw("install", "--no-audit", "--no-fund") } } diff --git a/inst/templates/app_structure/rhino.yml b/inst/templates/app_structure/rhino.yml index f3e28992..fea13278 100644 --- a/inst/templates/app_structure/rhino.yml +++ b/inst/templates/app_structure/rhino.yml @@ -1,2 +1 @@ sass: node -js_package_manager: npm diff --git a/vignettes/explanation/node-js-javascript-and-sass-tools.Rmd b/vignettes/explanation/node-js-javascript-and-sass-tools.Rmd index e9044fd9..1adeed9e 100644 --- a/vignettes/explanation/node-js-javascript-and-sass-tools.Rmd +++ b/vignettes/explanation/node-js-javascript-and-sass-tools.Rmd @@ -13,7 +13,13 @@ vignette: > can execute JavaScript code outside a web browser. It is used widely for web development. Its package manager, [npm](https://docs.npmjs.com/about-npm), makes it easy to install -virtually any JavaScript library. +virtually any JavaScript library. You can use other package managers such as +[bun](https://bun.sh) and [pnpm](https://pnpm.io/) that are compatible with +`npm`. + +To switch from the default npm usage, set a global environment variable named +`RHINO_NPM`. For instance, if you want to use `bun` instead of `npm`, enter +`RHINO_NPM=bun`. Rhino uses Node.js to provide state of the art tools for working with JavaScript and Sass. The following functions require Node.js to work: diff --git a/vignettes/explanation/rhino-yml.Rmd b/vignettes/explanation/rhino-yml.Rmd index 0f9ce56b..f43b223a 100644 --- a/vignettes/explanation/rhino-yml.Rmd +++ b/vignettes/explanation/rhino-yml.Rmd @@ -19,7 +19,6 @@ options are described below. ```yaml sass: string # required | one of: "node", "r" legacy_entrypoint: string # optional | one of: "app_dir", "source", "box_top_level" -js_package_manager: string # optional | one of: "npm", "bun" ``` ### `sass` @@ -31,7 +30,3 @@ Read more in [Explanation: Node.js - JavaScript and Sass tools](https://appsilon ### `legacy_entrypoint` This setting is useful when migrating an existing Shiny application to Rhino. For more details see [`rhino::app()` details section](https://appsilon.github.io/rhino/reference/app.html#details-1). - -### `js_package_manager` -Configures whether [JavaScript packages](https://www.npmjs.com/) should be installed using [npm](https://www.npmjs.com/) or [bun](https://bun.sh/). -It allows to avoid installation of Node.js, and using Bun Javascript runtime.