Skip to content

Commit

Permalink
using RHINO_NPM env var to control used package manager
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbn committed Jan 14, 2024
1 parent 8814582 commit dad6ae8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 36 deletions.
11 changes: 0 additions & 11 deletions R/config.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
29 changes: 11 additions & 18 deletions R/node.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(...))
})
Expand All @@ -22,28 +15,28 @@ 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()
js_package_manager_raw(...)
}

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")
}
}
1 change: 0 additions & 1 deletion inst/templates/app_structure/rhino.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
sass: node
js_package_manager: npm
8 changes: 7 additions & 1 deletion vignettes/explanation/node-js-javascript-and-sass-tools.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 0 additions & 5 deletions vignettes/explanation/rhino-yml.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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.

0 comments on commit dad6ae8

Please sign in to comment.