Skip to content

Commit

Permalink
call the jsdelivr resolve API to resolve 'latest' to a version number…
Browse files Browse the repository at this point in the history
…; this will return a smaller payload so should also be faster (previously all version numbers are returned)
  • Loading branch information
yihui committed Oct 9, 2024
1 parent 9616f89 commit 765b3de
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -931,13 +931,13 @@ jsdelivr = function(file, dir = 'npm/@xiee/utils/') {
# get the latest version of jsdelivr assets
jsd_version = local({
vers = list() # cache versions in current session
function(pkg) {
if (is.character(v <- vers[[pkg]])) return(v)
function(pkg, force = FALSE) {
if (!force && is.character(v <- vers[[pkg]])) return(v)
x = tryCatch(
xfun::read_utf8(paste0('https://data.jsdelivr.com/v1/package/', pkg)),
xfun::read_utf8(paste0('https://data.jsdelivr.com/v1/packages/', pkg, '/resolved')),
error = function(e) ''
)
v = grep_sub('.*"latest":\\s*"([0-9.]+)".*', '@\\1', x)
v = grep_sub('.*"version":\\s*"([0-9.]+)".*', '@\\1', x)
vers[[pkg]] <<- if (length(v)) v[1] else ''
}
})
Expand Down

0 comments on commit 765b3de

Please sign in to comment.