Files
shiny/tools/updatejQuery.R
David Macro 942bdd8c40 Update jQuery to 3.7.1 (#3969)
* Update jquery

* Upgrade to latest types

* Update news

---------

Co-authored-by: Carson Sievert <cpsievert1@gmail.com>
2025-06-16 11:46:17 -05:00

65 lines
1.8 KiB
R

library(magrittr)
version <- "3.7.1"
version_types <- "3.5.29"
jq_cdn_download <- function(version) {
Map(
src = c(".min.js", ".min.map", ".js"),
dst = c(".min.js", ".min.js.map", ".js"),
f = function(src, dst) {
download.file(
file.path("https://code.jquery.com", paste0("jquery-", version, src)),
file.path("inst", "www", "shared", paste0("jquery", dst))
)
}
)
}
jq_cdn_download(version)
# Add in source map location
# Required given comments in https://blog.jquery.com/2014/01/24/jquery-1-11-and-2-1-released/
jquery_min_js <- file.path("inst", "www", "shared", "jquery.min.js")
# Point to the version-less source map file
cat(
file = jquery_min_js,
append = TRUE,
"//# sourceMappingURL=jquery.min.js.map\n"
)
# Replace versioned file source locations with version-less file source
# locations (~2 locations)
jquery_min_js_map <- paste0(jquery_min_js, ".map")
brio::read_lines(jquery_min_js_map) %>%
gsub(
gsub("\\.", "\\\\.", paste0("\"jquery-", version, ".")),
"\"jquery.",
.
) %>%
brio::write_lines(jquery_min_js_map)
download.file(
"https://raw.githubusercontent.com/jquery/jquery/master/AUTHORS.txt",
"inst/www/shared/jquery-AUTHORS.txt"
)
writeLines(
c(
"# Generated by tools/updatejQuery.R; do not edit by hand",
sprintf('version_jquery <- "%s"', version)
),
rprojroot::find_package_root_file("R", "version_jquery.R")
)
# Update TypeScript installation
withr::with_dir(
rprojroot::find_package_root_file(),
{
exit_code <- system(paste0("yarn add --dev jquery@", version))
if (exit_code != 0) stop("yarn could not install jquery")
exit_code <- system(paste0("yarn add @types/jquery@", version_types))
if (exit_code != 0) stop("yarn could not install @types/jquery")
}
)