From 6878879dc8249b6bca467547008ce97f4c43fb77 Mon Sep 17 00:00:00 2001 From: colin Date: Wed, 12 Jun 2024 15:09:10 +0200 Subject: [PATCH] feat: install fails gracefully if package is not found on the webr repo --- rpkg/R/get_list_of_tar_gz_dependencies_for_package.R | 10 ++++++++-- src/install.js | 5 +++++ tests/install.test.js | 4 ++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/rpkg/R/get_list_of_tar_gz_dependencies_for_package.R b/rpkg/R/get_list_of_tar_gz_dependencies_for_package.R index 6993e79..35f0b5c 100644 --- a/rpkg/R/get_list_of_tar_gz_dependencies_for_package.R +++ b/rpkg/R/get_list_of_tar_gz_dependencies_for_package.R @@ -21,6 +21,13 @@ get_list_of_tar_gz_dependencies_for_package <- function( options(repos = c(webr = repos)) + # Getting the list of available package + info <- utils::available.packages(contriburl = repos) + + if (!pk_to_install %in% info[, "Package"]) { + return(FALSE) + } + deps <- unique( unlist( use.names = FALSE, @@ -40,8 +47,7 @@ get_list_of_tar_gz_dependencies_for_package <- function( deps ) - # Getting the list of available package - info <- utils::available.packages(contriburl = repos) + res <- data.frame( package = character(0), diff --git a/src/install.js b/src/install.js index 9a7a1e1..38252df 100644 --- a/src/install.js +++ b/src/install.js @@ -29,6 +29,11 @@ const installIt = async function ( package_to_install ) + if (urlsr.values[0] === false){ + console.error(`❌ {${package_to_install}} not found on the webr package repository.`) + return false + } + const paks = urlsr.values[0].values const urls = urlsr.values[1].values let compiled_urls = {} diff --git a/tests/install.test.js b/tests/install.test.js index e6bb59e..104dfda 100644 --- a/tests/install.test.js +++ b/tests/install.test.js @@ -18,6 +18,10 @@ test('installIt works', async () => { ) }; + const pkg_not_installed = await installIt("pouetpouet", temp_dir); + + expect(pkg_not_installed).toBe(false); + await installIt("attempt",temp_dir); expect(