Skip to content
Open
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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# usethis (development version)

* `use_standalone()` now again works outside packages (#2087).

* `pr_resume()` (without a specific `branch`) and `pr_fetch()` (without a specific `number`) no longer error when a branch name contains curly braces (#2107, @jonthegeek).

# usethis 3.2.1
Expand Down
9 changes: 9 additions & 0 deletions R/use_standalone.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ use_standalone <- function(repo_spec, file = NULL, ref = NULL, host = NULL) {

dependencies <- standalone_dependencies(lines, path)

if (!is_package()) {
imports <- dependencies$imports
n <- cli::qty(length(imports$pkg))
ui_bullets(c(
"!" = "You'll need the following {n} package{?s}: {.pkg {imports$pkg}}."
))
return(invisible())
}

for (dependency in dependencies$deps) {
use_standalone(repo_spec, dependency, ref = ref, host = host)
}
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/_snaps/use_standalone.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@
[4] "# ----------------------------------------------------------------------"
[5] "#"

# from a non-package project throws an informative message

Code
use_standalone("r-lib/rlang", "types-check", ref = "73182fe94")
Message
v Writing 'R/import-standalone-types-check.R'.
! You'll need the following package: rlang.

# can offer choices

Code
Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/test-use_standalone.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ test_that("can import standalone file with dependencies", {
expect_match(imports, "rlang")
})

test_that("from a non-package project throws an informative message", {
skip_if_offline("github.com")
create_local_project()
withr::local_options(list(usethis.quiet = FALSE))

# NOTE: Check ref after r-lib/rlang@standalone-dep has been merged
expect_snapshot(
use_standalone("r-lib/rlang", "types-check", ref = "73182fe94")
)
})

test_that("can use full github url", {
skip_if_offline("github.com")
create_local_package()
Expand Down
Loading