Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
`use_bundled_html()` gain a `replace` argument. When `TRUE`, an existing
file (or bundle directory) at the target location is overwritten instead
of aborting (#819).
- Development-time scaffolding helpers (`use_*`, `add_*`, `set_golem_*`)
now emit a warning when they are called while `{golem}` is in
production mode (`options('golem.app.prod' = TRUE)`), helping catch
accidental invocations from a deployed app (#808).

# golem 0.5.1 to 0.6.0

Expand Down
2 changes: 2 additions & 0 deletions R/add_ci_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ add_github_action <- function(
golem_wd = get_golem_wd(),
open = TRUE
) {
warn_if_in_prod_mode()
add_deploy_ci_(
template = "github-action-template.yml",
output = fs_path(
Expand Down Expand Up @@ -42,6 +43,7 @@ add_github_action <- function(
#'
#' @return The path to the created GitLab CI file, invisibly.
add_gitlab_ci <- function(golem_wd = get_golem_wd(), open = TRUE) {
warn_if_in_prod_mode()
add_deploy_ci_(
template = "gitlab-ci-template.yml",
output = fs_path(golem_wd, ".gitlab-ci.yml"),
Expand Down
3 changes: 3 additions & 0 deletions R/add_dockerfiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ add_dockerfile <- function(
extra_sysreqs = NULL,
pkg
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
pkg,
fun = as.character(
Expand Down Expand Up @@ -258,6 +259,7 @@ add_dockerfile_shinyproxy <- function(
extra_sysreqs = NULL,
pkg
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
pkg,
fun = as.character(
Expand Down Expand Up @@ -387,6 +389,7 @@ add_dockerfile_heroku <- function(
extra_sysreqs = NULL,
pkg
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
pkg,
fun = as.character(
Expand Down
3 changes: 3 additions & 0 deletions R/add_dockerfiles_renv.R
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ add_dockerfile_with_renv <- function(
...,
source_folder
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
source_folder,
fun = as.character(sys.call()[[1]]),
Expand Down Expand Up @@ -414,6 +415,7 @@ add_dockerfile_with_renv_shinyproxy <- function(
...,
source_folder
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
source_folder,
fun = as.character(sys.call()[[1]]),
Expand Down Expand Up @@ -474,6 +476,7 @@ add_dockerfile_with_renv_heroku <- function(
...,
source_folder
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
source_folder,
fun = as.character(sys.call()[[1]]),
Expand Down
10 changes: 10 additions & 0 deletions R/add_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ add_js_file <- function(
...,
pkg
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
pkg,
fun = as.character(
Expand Down Expand Up @@ -109,6 +110,7 @@ add_js_handler <- function(
...,
pkg
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
pkg,
fun = as.character(
Expand Down Expand Up @@ -357,6 +359,7 @@ add_js_input_binding <- function(
),
pkg
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
pkg,
fun = as.character(
Expand Down Expand Up @@ -663,6 +666,7 @@ add_js_output_binding <- function(
dir_create,
pkg
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
pkg,
fun = as.character(
Expand Down Expand Up @@ -828,6 +832,7 @@ add_css_file <- function(
...,
pkg
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
pkg,
fun = as.character(
Expand Down Expand Up @@ -879,6 +884,7 @@ add_sass_file <- function(
...,
pkg
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
pkg,
fun = as.character(
Expand Down Expand Up @@ -983,6 +989,7 @@ add_empty_file <- function(
...,
pkg
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
pkg,
fun = as.character(
Expand Down Expand Up @@ -1092,6 +1099,7 @@ add_html_template <- function(
dir_create,
pkg
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
pkg,
fun = as.character(
Expand Down Expand Up @@ -1167,6 +1175,7 @@ add_partial_html_template <- function(
dir_create,
pkg
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
pkg,
fun = as.character(
Expand Down Expand Up @@ -1218,6 +1227,7 @@ add_ui_server_files <- function(
dir_create,
pkg
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
pkg,
fun = as.character(
Expand Down
3 changes: 3 additions & 0 deletions R/add_r_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ add_fct <- function(
...,
pkg
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
pkg,
fun = as.character(
Expand Down Expand Up @@ -253,6 +254,7 @@ add_utils <- function(
with_test = FALSE,
pkg
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
pkg,
fun = as.character(
Expand Down Expand Up @@ -282,6 +284,7 @@ add_r6 <- function(
with_test = FALSE,
pkg
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
pkg,
fun = as.character(
Expand Down
4 changes: 4 additions & 0 deletions R/add_rstudio_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ add_positconnect_file <- function(
open = TRUE,
pkg
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
pkg,
fun = as.character(
Expand All @@ -197,6 +198,7 @@ add_shinyappsio_file <- function(
open = TRUE,
pkg
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
pkg,
fun = as.character(
Expand All @@ -218,6 +220,7 @@ add_shinyserver_file <- function(
open = TRUE,
pkg
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
pkg,
fun = as.character(
Expand All @@ -239,6 +242,7 @@ add_rscignore_file <- function(
open = TRUE,
pkg
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
pkg,
fun = as.character(
Expand Down
3 changes: 3 additions & 0 deletions R/golem-yaml-set.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set_golem_wd <- function(
golem_wd,
pkg
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
golem_wd,
fun = as.character(
Expand Down Expand Up @@ -65,6 +66,7 @@ set_golem_name <- function(
old_name = golem::pkg_name(),
pkg
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
pkg,
fun = as.character(
Expand Down Expand Up @@ -237,6 +239,7 @@ set_golem_version <- function(
talkative = TRUE,
pkg
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
pkg,
fun = as.character(
Expand Down
32 changes: 32 additions & 0 deletions R/make_dev.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
#' Warn if called while {golem} is in production mode
#'
#' Helper used by development-time scaffolding functions (`use_*`,
#' `add_*`, `set_golem_*`) to alert the user when they are accidentally
#' invoked from a running app (i.e. when `options('golem.app.prod')` is
#' `TRUE`).
#'
#' @return Used for its side-effect (prints a `cli` warning).
#' @noRd
warn_if_in_prod_mode <- function() {
if (!isTRUE(getOption("golem.app.prod"))) {
return(invisible(NULL))
}
fun_call <- sys.call(-1)
fun_name <- if (length(fun_call)) {
# deparse() (rather than as.character()) keeps the call's textual
# form intact for namespaced invocations like `golem::use_*()`,
# which would otherwise be returned as c("::", "golem", "use_*").
deparse(fun_call[[1L]])
} else {
"This function"
}
warning(
sprintf(
"`%s()` is a development function and should not be called when {golem} is in production mode (`options('golem.app.prod' = TRUE)`).",
fun_name
),
Comment thread
ColinFay marked this conversation as resolved.
call. = FALSE
)
invisible(NULL)
}

#' Make a function dependent to dev mode
#'
#' The function returned will be run only if `golem::app_dev()`
Expand Down
1 change: 1 addition & 0 deletions R/modules_fn.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ add_module <- function(
...,
pkg
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
pkg,
fun = as.character(
Expand Down
1 change: 1 addition & 0 deletions R/set_golem_options.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ set_golem_options <- function(
talkative = TRUE,
config_file = golem::get_current_config(golem_wd)
) {
warn_if_in_prod_mode()
# TODO here we'll run the
# golem_install_dev_pkg() function

Expand Down
4 changes: 4 additions & 0 deletions R/use_agent_skills.R
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ use_skills <- function(
golem_wd = get_golem_wd(),
interactive = rlang_is_interactive()
) {
warn_if_in_prod_mode()
use_agent_implement(
source = source,
agent_specs = agent_specs,
Expand Down Expand Up @@ -203,6 +204,7 @@ use_agent_skills <- function(
golem_wd = get_golem_wd(),
interactive = rlang_is_interactive()
) {
warn_if_in_prod_mode()
use_agent_implement(
source = source,
agent_specs = "agents",
Expand Down Expand Up @@ -231,6 +233,7 @@ use_claude_skills <- function(
golem_wd = get_golem_wd(),
interactive = rlang_is_interactive()
) {
warn_if_in_prod_mode()
use_agent_implement(
source = source,
agent_specs = "claude",
Expand Down Expand Up @@ -265,6 +268,7 @@ use_skill <- function(
golem_wd = get_golem_wd(),
interactive = rlang_is_interactive()
) {
warn_if_in_prod_mode()
if (missing(name) || length(name) != 1 || !nzchar(name)) {
cli_abort("`name` must be a single non-empty skill name.")
}
Expand Down
1 change: 1 addition & 0 deletions R/use_favicon.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use_favicon <- function(
method = "curl",
pkg
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
pkg,
fun = as.character(
Expand Down
5 changes: 5 additions & 0 deletions R/use_files_external.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use_external_js_file <- function(
pkg,
replace = FALSE
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
pkg,
fun = as.character(
Expand Down Expand Up @@ -75,6 +76,7 @@ use_external_css_file <- function(
pkg,
replace = FALSE
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
pkg,
fun = as.character(
Expand Down Expand Up @@ -115,6 +117,7 @@ use_external_html_template <- function(
delete_zip = c("ask", "yes", "no"),
replace = FALSE
) {
warn_if_in_prod_mode()
if (!missing(dir_create)) {
cli_abort_dir_create()
}
Expand Down Expand Up @@ -165,6 +168,7 @@ use_external_file <- function(
pkg,
replace = FALSE
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
pkg,
fun = as.character(
Expand Down Expand Up @@ -204,6 +208,7 @@ use_bundled_html <- function(
delete_zip = c("ask", "yes", "no"),
replace = FALSE
) {
warn_if_in_prod_mode()
extract <- match.arg(extract)
delete_zip <- match.arg(delete_zip)
old <- setwd(fs_path_abs(golem_wd))
Expand Down
4 changes: 4 additions & 0 deletions R/use_files_internal.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use_internal_js_file <- function(
dir_create,
pkg
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
pkg,
fun = as.character(
Expand Down Expand Up @@ -48,6 +49,7 @@ use_internal_css_file <- function(
dir_create,
pkg
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
pkg,
fun = as.character(
Expand Down Expand Up @@ -87,6 +89,7 @@ use_internal_html_template <- function(
dir_create,
pkg
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
pkg,
fun = as.character(
Expand Down Expand Up @@ -124,6 +127,7 @@ use_internal_file <- function(
dir_create,
pkg
) {
warn_if_in_prod_mode()
signal_arg_is_deprecated(
pkg,
fun = as.character(
Expand Down
Loading
Loading