diff --git a/NEWS.md b/NEWS.md index 4c987698..09df2b87 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # rsconnect 0.8.30 (development version) +* `deployApp()` now advertises which startup scripts are run at the normal + `logLevel`, and it evaluates each script in its own environment (#542). + * `deployments()` now formats `when` and `lastSyncTime` as date-times (#714). * `deployApp()` now derives `appName` from `appDir` and `appPrimaryDoc`, diff --git a/R/deployApp.R b/R/deployApp.R index 5c242311..5123b364 100644 --- a/R/deployApp.R +++ b/R/deployApp.R @@ -205,7 +205,7 @@ deployApp <- function(appDir = getwd(), displayStatus <- displayStatus(quiet) # run startup scripts to pick up any user options and establish pre/post deploy hooks - runStartupScripts(appDir, logLevel) + runStartupScripts(appDir, quiet = quiet, verbose = verbose) # at verbose log level, turn on all tracing options implicitly for the # duration of the call @@ -611,22 +611,22 @@ openURL <- function(client, application, launch.browser, on.failure, deploymentS # or open no url if things failed } -runStartupScripts <- function(appDir, logLevel) { +runStartupScripts <- function(appDir, quiet = FALSE, verbose = FALSE) { scripts <- c( # the site-wide startup script file.path(R.home("etc"), "rsconnect.site"), # the user startup script path.expand("~/.rsconnect_profile"), # a startup script specific to this application - file.path(appDir, ".rsconnect_profile")) + file.path(appDir, ".rsconnect_profile") + ) + scripts <- scripts[file.exists(scripts)] # iterate over the startup scripts for (script in scripts) { - if (file.exists(script)) { - if (logLevel == "verbose") { - cat("----- Sourcing startup script", script, "-----\n") - } - source(file = script, verbose = (logLevel == "verbose")) - } + taskStart(quiet, "Running {script}") + + env <- new_environment(parent = globalenv()) + source(script, verbose = verbose, local = env) } } diff --git a/tests/testthat/_snaps/deployApp.md b/tests/testthat/_snaps/deployApp.md index d0b1a263..306db033 100644 --- a/tests/testthat/_snaps/deployApp.md +++ b/tests/testthat/_snaps/deployApp.md @@ -54,6 +54,13 @@ Error in `deployApp()`: ! `appSourceDoc`, "records", does not exist. +# startup scripts are logged by default + + Code + runStartupScripts(".") + Message + i Running ./.rsconnect_profile + # deployHook executes function if set Code diff --git a/tests/testthat/test-deployApp.R b/tests/testthat/test-deployApp.R index b3d234bf..5477fd15 100644 --- a/tests/testthat/test-deployApp.R +++ b/tests/testthat/test-deployApp.R @@ -35,6 +35,14 @@ test_that("appSourceDoc is deprecated & checks path", { }) }) +test_that("startup scripts are logged by default", { + dir <- local_temp_app() + withr::local_dir(dir) + writeLines("1 + 1", file.path(dir, ".rsconnect_profile")) + + expect_snapshot(runStartupScripts(".")) +}) + # record directory -------------------------------------------------------- test_that("findRecordPath() uses recordDir, then appPrimaryDoc, then appDir", {