Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enforce fewer layout restrictions #1003

Merged
merged 1 commit into from
Sep 27, 2023
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
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
* Do not use `getOption("available_packages_filters")` option when calling
`available.packages()`. (#1002)

* Improve reporting of errors returned by shinyapps.io. (#997)
aronatkins marked this conversation as resolved.
Show resolved Hide resolved

* Remove most directory layout validation checks. (#998)


# rsconnect 1.1.0

* Fixed analysis of directories that were smaller than the
Expand Down
27 changes: 2 additions & 25 deletions R/appMetadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ appMetadata <- function(appDir,

checkAppLayout <- function(appDir, appPrimaryDoc = NULL) {
appFilesBase <- tolower(list.files(appDir))
wwwFiles <- tolower(list.files(file.path(appDir, "www/")))

primaryIsRScript <- identical(tolower(tools::file_ext(appPrimaryDoc)), "r")

# check for single-file app collision
Expand All @@ -93,29 +91,8 @@ checkAppLayout <- function(appDir, appPrimaryDoc = NULL) {
)
}

# Do some checks for a valid application structure
satisfiedLayouts <- c(
shinyAndUi = all(c("server.r", "ui.r") %in% appFilesBase),
shinyAndIndex = "server.r" %in% appFilesBase && "index.html" %in% wwwFiles,
app = primaryIsRScript || any("app.r" %in% appFilesBase),
Rmd = any(grepl(glob2rx("*.rmd"), appFilesBase)),
Qmd = any(grepl(glob2rx("*.qmd"), appFilesBase)),
static = any(grepl("(?:html?|pdf)$", appFilesBase)),
plumber = any(c("entrypoint.r", "plumber.r") %in% appFilesBase)
)

if (any(satisfiedLayouts)) {
return()
}

cli::cli_abort(c(
"Cancelling deployment: invalid project layout.",
i = "Expecting one of the following publication types:",
" " = "1. A Shiny app with `app.R` or `server.R` + `ui.R`",
" " = "2. R Markdown (`.Rmd`) or Quarto (`.qmd`) documents.",
" " = "3. A website containing `.html` and/or `.pdf` files.",
" " = "4. A plumber API with `plumber.R` or `entrypoint.R`."
))
# all other layouts are allowed; the server determines (with the required packages) if the content
# can be run/served.
}

# infer the mode of the application from files in the root dir
Expand Down
15 changes: 1 addition & 14 deletions tests/testthat/_snaps/appMetadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,11 @@
# checkLayout() errors if primary doc & app.R

Code
checkAppLayout(dir, "myscript.R")
checkAppLayout(dir, appPrimaryDoc = "myscript.R")
Condition
Error in `checkAppLayout()`:
! Project must not contain both 'app.R' and a single-file Shiny app.

# checkLayout fails if no known structure

Code
checkAppLayout(dir)
Condition
Error in `checkAppLayout()`:
! Cancelling deployment: invalid project layout.
i Expecting one of the following publication types:
1. A Shiny app with `app.R` or `server.R` + `ui.R`
2. R Markdown (`.Rmd`) or Quarto (`.qmd`) documents.
3. A website containing `.html` and/or `.pdf` files.
4. A plumber API with `plumber.R` or `entrypoint.R`.

# errors if no files with needed extension

Code
Expand Down
39 changes: 26 additions & 13 deletions tests/testthat/test-appMetadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,30 +65,43 @@ test_that("checkLayout() errors if primary doc & app.R", {
"myscript.R" = ""
))

expect_snapshot(checkAppLayout(dir, "myscript.R"), error = TRUE)
})

test_that("checkLayout fails if no known structure", {
dir <- local_temp_app(list(
"data.txt" = "",
"cats.csv" = ""
))

expect_snapshot(checkAppLayout(dir), error = TRUE)
expect_snapshot(checkAppLayout(dir, appPrimaryDoc = "myscript.R"), error = TRUE)
})

test_that("checkLayout succeeds with some common app structures", {
rmd <- local_temp_app(list("foo.Rmd" = ""))
expect_no_error(checkAppLayout(rmd))

qmd <- local_temp_app(list("foo.qmd" = ""))
expect_no_error(checkAppLayout(qmd))

# perhaps script.R is a pre-render script that generates *.qmd
project <- local_temp_app(list("_quarto.yml" = "", "script.R" = ""))
expect_no_error(checkAppLayout(project))

md <- local_temp_app(list("_quarto.yml" = "", "index.md" = ""))
expect_no_error(checkAppLayout(md))

shiny1 <- local_temp_app(list("app.R" = ""))
expect_no_error(checkAppLayout(rmd))
expect_no_error(checkAppLayout(shiny1))

shiny2 <- local_temp_app(list("server.R" = "", "ui.R" = ""))
expect_no_error(checkAppLayout(rmd))
expect_no_error(checkAppLayout(shiny2))

api <- local_temp_app(list("plumber.R" = ""))
expect_no_error(checkAppLayout(api))

static <- local_temp_app(list("foo.html" = ""))
expect_no_error(checkAppLayout(rmd))
expect_no_error(checkAppLayout(static))

staticxml <- local_temp_app(list("data.xml" = ""))
expect_no_error(checkAppLayout(staticxml))

staticdata <- local_temp_app(list(
"data.txt" = "",
"cats.csv" = ""
))
expect_no_error(checkAppLayout(staticdata))
})

# inferAppMode ------------------------------------------------------------
Expand Down
Loading