Skip to content

Commit

Permalink
Move parse checking into shared helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
georgestagg committed Aug 2, 2024
1 parent 123e9a6 commit d94e2d2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
9 changes: 1 addition & 8 deletions R/export.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,7 @@ export <- function(
assets_version <- assets_version()
}

wasm_packages_val <- wasm_packages %||% sys_env_wasm_packages()
wasm_packages <- as.logical(wasm_packages_val)
if (is.na(wasm_packages)) {
cli::cli_abort(c(
"x" = "Could not parse `wasm_packages` value: {.code {wasm_packages_val}}"
))
wasm_packages <- SHINYLIVE_WASM_PACKAGES
}
wasm_packages <- wasm_packages %||% sys_env_wasm_packages()

if (!fs::is_dir(appdir)) {
cli::cli_abort("{.var appdir} must be a directory, but was provided {.path {appdir}}.")
Expand Down
7 changes: 6 additions & 1 deletion R/packages.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ sys_env_max_filesize <- function() {

sys_env_wasm_packages <- function() {
pkgs_env <- Sys.getenv("SHINYLIVE_WASM_PACKAGES", SHINYLIVE_WASM_PACKAGES)
switch(pkgs_env, "1" = TRUE, "0" = FALSE, pkgs_env)
pkgs_env <- switch(pkgs_env, "1" = TRUE, "0" = FALSE, pkgs_env)
wasm_packages <- as.logical(pkgs_env)
if (is.na(wasm_packages)) {
cli::cli_abort("Could not parse `wasm_packages` value: {.code {pkgs_env}}")
}
wasm_packages
}

# Resolve package list, dependencies listed in Depends and Imports
Expand Down
10 changes: 1 addition & 9 deletions R/quarto_ext.R
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,7 @@ build_app_resources <- function(app_json) {
}
})

wasm_packages_val <- sys_env_wasm_packages()
wasm_packages <- as.logical(wasm_packages_val)
if (is.na(wasm_packages)) {
cli::cli_abort(c(
"x" = "Could not parse `wasm_packages` value: {.code {wasm_packages_val}}"
))
wasm_packages <- SHINYLIVE_WASM_PACKAGES
}

wasm_packages <- sys_env_wasm_packages()
if (wasm_packages) {
# Download wasm binaries ready to embed into Quarto deps
withr::with_options(
Expand Down

0 comments on commit d94e2d2

Please sign in to comment.