diff --git a/NEWS.md b/NEWS.md index 755262326..a71218b68 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # pkgdown (development version) +* `as.pkgdown()` will no longer prompt you to install a missing template package from CRAN, since these are almost always found in GitHub (#2076). * `init_site()` once again describes one copy per line, and now uses a better prefix when copying assets from pkgdown itself (#2445). * Very wide words are now automatically broken across lines and hyphenated (when possible) when they'd otherwise create a horizontal scrollbar on mobile (#1888). * The `repo.source.url` field no longer requires a trailing slash (#2017). diff --git a/R/package.R b/R/package.R index cbef499c5..8878cf984 100644 --- a/R/package.R +++ b/R/package.R @@ -331,12 +331,19 @@ package_vignettes <- function(path = ".") { out[order(basename(out$file_out)), ] } -find_template_config <- function(package, bs_version = NULL) { +find_template_config <- function(package, + bs_version = NULL, + error_call = caller_env()) { if (is.null(package)) { return(list()) } - config <- path_package_pkgdown("_pkgdown.yml", package, bs_version) + config <- path_package_pkgdown( + "_pkgdown.yml", + package, + bs_version, + error_call = error_call + ) if (!file_exists(config)) { return(list()) } diff --git a/R/utils-fs.R b/R/utils-fs.R index a48bfedd8..cb6f29f9b 100644 --- a/R/utils-fs.R +++ b/R/utils-fs.R @@ -96,8 +96,21 @@ path_first_existing <- function(...) { NULL } -path_package_pkgdown <- function(path, package, bs_version) { - check_installed(package) +path_package_pkgdown <- function(path, + package, + bs_version, + error_call = caller_env()) { + # package will usually be a github package, and check_installed() + # tries to install from CRAN, which is highly likely to fail. + if (!is_installed(package)) { + cli::cli_abort( + c( + "Template package {.val {package}} is not installed.", + i = "Please install before continuing." + ), + call = error_call + ) + } base <- system_file("pkgdown", package = package) # If bs_version supplied, first try for versioned template diff --git a/tests/testthat/_snaps/utils-fs.md b/tests/testthat/_snaps/utils-fs.md new file mode 100644 index 000000000..b83869d86 --- /dev/null +++ b/tests/testthat/_snaps/utils-fs.md @@ -0,0 +1,9 @@ +# missing template package yields custom error + + Code + path_package_pkgdown("x", "missing", 3) + Condition + Error: + ! Template package "missing" is not installed. + i Please install before continuing. + diff --git a/tests/testthat/test-utils-fs.R b/tests/testthat/test-utils-fs.R new file mode 100644 index 000000000..59924d4cc --- /dev/null +++ b/tests/testthat/test-utils-fs.R @@ -0,0 +1,3 @@ +test_that("missing template package yields custom error", { + expect_snapshot(path_package_pkgdown("x", "missing", 3), error = TRUE) +})