Skip to content

Commit dad6ae8

Browse files
committed
using RHINO_NPM env var to control used package manager
1 parent 8814582 commit dad6ae8

File tree

5 files changed

+18
-36
lines changed

5 files changed

+18
-36
lines changed

R/config.R

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ rhino_config_definition <- list(
3737
validator = option_validator("app_dir", "source", "box_top_level"),
3838
required = FALSE
3939
),
40-
list(
41-
name = "js_package_manager",
42-
validator = option_validator("npm", "bun"),
43-
required = FALSE
44-
),
4540
list(
4641
name = "legacy_max_lint_r_errors",
4742
validator = positive_integer_validator,
@@ -83,11 +78,5 @@ validate_config <- function(definition, config) {
8378
read_config <- function() {
8479
config <- read_yaml("rhino")
8580
validate_config(rhino_config_definition, config)
86-
# using npm by default
87-
config$js_package_manager <- ifelse(
88-
is.null(config$js_package_manager),
89-
"npm",
90-
config$js_package_manager
91-
)
9281
config
9382
}

R/node.R

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,9 @@ node_path <- function(...) {
22
fs::path(".rhino", ...)
33
}
44

5-
add_node <- function(clean = FALSE) {
6-
if (clean && fs::dir_exists(node_path())) {
7-
fs::dir_delete(node_path())
8-
}
9-
copy_template("node", node_path())
10-
}
11-
125
# Run `npm`/`bun` command (assume node directory already exists in the project).
136
js_package_manager_raw <- function(..., status_ok = 0) {
14-
command <- read_config()$js_package_manager
7+
command <- Sys.getenv("RHINO_NPM", "npm")
158
withr::with_dir(node_path(), {
169
status <- system2(command = command, args = c(...))
1710
})
@@ -22,28 +15,28 @@ js_package_manager_raw <- function(..., status_ok = 0) {
2215

2316
# Run `npm`/`bun` command (create node directory in the project if needed).
2417
js_package_manager <- function(...) {
25-
command <- read_config()$js_package_manager
26-
display_names <- list(
27-
npm = "Node.js",
28-
bun = "Bun"
29-
)
18+
command <- Sys.getenv("RHINO_NPM", "npm")
19+
display_name <- ifelse(command == "npm", "Node.js", command)
3020
check_system_dependency(
3121
cmd = command,
32-
dependency_name = display_names[[command]],
22+
dependency_name = display_name,
3323
documentation_url = "https://go.appsilon.com/rhino-system-dependencies"
3424
)
3525
init_js_package_manager()
3626
js_package_manager_raw(...)
3727
}
3828

3929
init_js_package_manager <- function() {
40-
command <- read_config()$js_package_manager
30+
command <- Sys.getenv("RHINO_NPM", "npm")
4131
if (!fs::dir_exists(node_path())) {
42-
message("Initializing Javascript packages…")
43-
add_node()
32+
message("Initializing Javascript configs\u2026")
33+
copy_template("node", node_path())
4434
}
35+
36+
# existing .rhino and missing node_modules folder
37+
# indicate that packages were not installed but rhino project initialized
4538
if (!fs::dir_exists(node_path("node_modules"))) {
46-
message("Installing dependencies by ", command, "")
39+
message("Installing dependencies by ", command, "\u2026")
4740
js_package_manager_raw("install", "--no-audit", "--no-fund")
4841
}
4942
}
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
sass: node
2-
js_package_manager: npm

vignettes/explanation/node-js-javascript-and-sass-tools.Rmd

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ vignette: >
1313
can execute JavaScript code outside a web browser. It is used widely for
1414
web development. Its package manager,
1515
[npm](https://docs.npmjs.com/about-npm), makes it easy to install
16-
virtually any JavaScript library.
16+
virtually any JavaScript library. You can use other package managers such as
17+
[bun](https://bun.sh) and [pnpm](https://pnpm.io/) that are compatible with
18+
`npm`.
19+
20+
To switch from the default npm usage, set a global environment variable named
21+
`RHINO_NPM`. For instance, if you want to use `bun` instead of `npm`, enter
22+
`RHINO_NPM=bun`.
1723

1824
Rhino uses Node.js to provide state of the art tools for working with
1925
JavaScript and Sass. The following functions require Node.js to work:

vignettes/explanation/rhino-yml.Rmd

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ options are described below.
1919
```yaml
2020
sass: string # required | one of: "node", "r"
2121
legacy_entrypoint: string # optional | one of: "app_dir", "source", "box_top_level"
22-
js_package_manager: string # optional | one of: "npm", "bun"
2322
```
2423
2524
### `sass`
@@ -31,7 +30,3 @@ Read more in [Explanation: Node.js - JavaScript and Sass tools](https://appsilon
3130
### `legacy_entrypoint`
3231
This setting is useful when migrating an existing Shiny application to Rhino. For more details see
3332
[`rhino::app()` details section](https://appsilon.github.io/rhino/reference/app.html#details-1).
34-
35-
### `js_package_manager`
36-
Configures whether [JavaScript packages](https://www.npmjs.com/) should be installed using [npm](https://www.npmjs.com/) or [bun](https://bun.sh/).
37-
It allows to avoid installation of Node.js, and using Bun Javascript runtime.

0 commit comments

Comments
 (0)