diff --git a/R/engine.R b/R/engine.R index a02d02b..f073bdf 100644 --- a/R/engine.R +++ b/R/engine.R @@ -3,12 +3,20 @@ new_engine <- function(path, dirs, port, host, ignore) { ignore <- ignore %||% c("*.sqlite", "*.git*") |> paste0(collapse = "|") |> utils::glob2rx() + runner_port <- port %||% httpuv::randomPort( + host = host, + n = 100L + ) + socket_port <- httpuv::randomPort( + host = host, + n = 100L + ) list2env( list( runner = NULL, config = list( - port = port %||% httpuv::randomPort(host = host), + port = port %||% runner_port, path = dirname(path), plumber_path = path, dirs = dirs, @@ -20,7 +28,7 @@ new_engine <- function(path, dirs, port, host, ignore) { listen = sprintf( "ws://%s:%s", host, - httpuv::randomPort(host = host) + socket_port ), autostart = TRUE ) diff --git a/R/watcher.R b/R/watcher.R index 954565d..75f5406 100644 --- a/R/watcher.R +++ b/R/watcher.R @@ -30,5 +30,6 @@ directory_state <- function(paths, ignore_pattern) { extra_cols = FALSE ) res <- res[grep(pattern = ignore_pattern, x = row.names(res), invert = TRUE), ] + res <- res[res$size > 0L, ] stats::setNames(res$mtime, row.names(res)) } diff --git a/README.md b/README.md index 710ff46..59ea6ce 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ devtools::install_github("ElianHugh/hotwater") ## Example -This is a basic example which shows you how to solve a common problem: +Hotwater can be run via an R session: ``` r hotwater::run( @@ -39,3 +39,14 @@ hotwater::run( ✔ Server running on <127.0.0.1:9999> [17ms] → Watching ./path/to/ for changes... ``` + +or a terminal using the bash script: + +```sh +hotwater -f my/plumber/api.R -p 9999 +``` + +``` r +✔ Server running on <127.0.0.1:9999> [17ms] +→ Watching ./path/to/ for changes... +``` diff --git a/TODO.md b/TODO.md index 2b5fb69..055b1d0 100644 --- a/TODO.md +++ b/TODO.md @@ -8,14 +8,6 @@ - It would be nice to remove callr dependency and just rely on mirai/nanonext -## 4 - -- Empty files ideally shouldn't force a refresh - -## 5 - -- Creating a file without any content shouldn't cause a refresh - ## 6 - Updating CSS shouldn't typically cause a refresh @@ -23,7 +15,3 @@ ## 7 - Nanonext is currently only used because I want an async connection for the local webpage refresh. May not need to use nanonext, considering we fake the protocol on the JS side of things anyway - -## 9 - -- text in the CLI can often be out of order diff --git a/tests/testthat/test-watcher.R b/tests/testthat/test-watcher.R index 27d198d..f0302be 100644 --- a/tests/testthat/test-watcher.R +++ b/tests/testthat/test-watcher.R @@ -51,7 +51,8 @@ test_that("directory_state returns expected file state", { watcher_dir <<- withr::local_tempdir("testdir") writeLines("Hello world", file.path(watcher_dir, "hello.R")) writeLines("Bye world", file.path(watcher_dir, "bye.R")) - state <<- directory_state(watcher_dir, "*.gitignore") + file.create(file.path(watcher_dir, "empty.R")) + state <- directory_state(watcher_dir, "*.gitignore") expect_length(state, 2L) expect_length(names(state), 2L) expect_s3_class(state, c("POSIXct", "POSIXt"))