From 3f6ef2821259d17b32896b0d09a234c2b9dfd2bc Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 23 Jan 2024 16:09:00 +0100 Subject: [PATCH 01/12] introduce 'entry_point' argument for esbuild configuration --- R/jstools.R | 13 +++++++++++-- R/utils.R | 11 +++++++---- inst/utils/esbuild.prod.js | 2 +- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/R/jstools.R b/R/jstools.R index f349053..bf08b4d 100644 --- a/R/jstools.R +++ b/R/jstools.R @@ -8,16 +8,25 @@ #' @param mode Production or development mode. Choose either "prod" or "dev". #' "prod" bundles, aggregates and minifyies files. "dev" only bundles the code. #' Modules follow the ES6 format (import/export). +#' @param entry_point Entry points to use in esbuild configuration. In case of +#' a monolithic bundle, only one entrypoint is needed. This the default. +#' In case of component based bundles, a vector of entrypoints is needed. +#' The output files will match the entrypoints names. #' @export #' @importFrom utils tail packageVersion -build_js <- function(dir = "srcjs", mode = c("prod", "dev")) { +build_js <- function(dir = "srcjs", mode = c("prod", "dev"), entry_point = "main.js") { mode <- match.arg(mode) pkg_desc <- desc::description$new("./DESCRIPTION")$get(c("Package", "Version", "License")) outputDir <- sprintf("inst/%s-%s/dist", pkg_desc[1], pkg_desc[2]) + # make sure entrypoints look like ./dir/file.js + if (!grepl(sprintf("^\\./%s", dir), entry_point)) { + entry_point <- paste0("./", dir, "/", entry_point) + } + # run esbuild - run_esbuild(mode, outputDir) + run_esbuild(mode, outputDir, entry_point) # create custom dependency create_custom_dependency( diff --git a/R/utils.R b/R/utils.R index 946d6b5..0b4d3cd 100644 --- a/R/utils.R +++ b/R/utils.R @@ -101,7 +101,7 @@ process_template <- function(template, ..., where = system.file("utils", package ) }, version = pars$version, - entry_point = "main.js", + entry_point = paste0(shQuote(pars$entry_point), collapse = ", "), license = pars$license, .open = "<<", .close = ">>" @@ -170,7 +170,8 @@ set_esbuild <- function(light = FALSE) { "package.json", name = pkg_desc[1], version = pkg_desc[2], # node does not support 0.1.0.9000 - license = pkg_desc[3] + license = pkg_desc[3], + entry_point = "main.js" ) npm::npm_install( @@ -300,8 +301,9 @@ copy_charpente_utils <- function(pkg_name) { #' #' @inheritParams build_js #' @param outputDir Output directory +#' @param entry_point Entry points to be used #' @keywords internal -run_esbuild <- function(mode, outputDir) { +run_esbuild <- function(mode, outputDir, entry_point) { # styles did not exist in previous {charpent} versions if (!dir.exists("styles")) { # Only add missing pieces ... @@ -317,7 +319,8 @@ run_esbuild <- function(mode, outputDir) { process_template( sprintf("esbuild.%s.js", mode), name = pkg_desc[[1]], - version = pkg_desc[[2]] + version = pkg_desc[[2]], + entry_point = entry_point ) npm::npm_run(sprintf("run build-%s", mode)) diff --git a/inst/utils/esbuild.prod.js b/inst/utils/esbuild.prod.js index 4b59fc8..f96ca8b 100644 --- a/inst/utils/esbuild.prod.js +++ b/inst/utils/esbuild.prod.js @@ -5,7 +5,7 @@ import autoprefixer from 'autoprefixer'; esbuild .build({ - entryPoints: ["./srcjs/main.js"], + entryPoints: [<>], outfile: "inst/<>-<>/dist/<>.min.js", bundle: true, format: "esm", From c3b15ba85116d36246b400c30769a69da2d5587e Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 23 Jan 2024 16:32:52 +0100 Subject: [PATCH 02/12] add 'entry_name' arg to process_template() --- R/jstools.R | 4 ++-- R/utils.R | 2 ++ inst/utils/esbuild.prod.js | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/R/jstools.R b/R/jstools.R index bf08b4d..d2205c8 100644 --- a/R/jstools.R +++ b/R/jstools.R @@ -8,7 +8,7 @@ #' @param mode Production or development mode. Choose either "prod" or "dev". #' "prod" bundles, aggregates and minifyies files. "dev" only bundles the code. #' Modules follow the ES6 format (import/export). -#' @param entry_point Entry points to use in esbuild configuration. In case of +#' @param entry_point Entry point(s) to use in esbuild configuration. In case of #' a monolithic bundle, only one entrypoint is needed. This the default. #' In case of component based bundles, a vector of entrypoints is needed. #' The output files will match the entrypoints names. @@ -21,7 +21,7 @@ build_js <- function(dir = "srcjs", mode = c("prod", "dev"), entry_point = "main outputDir <- sprintf("inst/%s-%s/dist", pkg_desc[1], pkg_desc[2]) # make sure entrypoints look like ./dir/file.js - if (!grepl(sprintf("^\\./%s", dir), entry_point)) { + if (any(!grepl(sprintf("^\\./%s", dir), entry_point))) { entry_point <- paste0("./", dir, "/", entry_point) } diff --git a/R/utils.R b/R/utils.R index 0b4d3cd..c431a9f 100644 --- a/R/utils.R +++ b/R/utils.R @@ -102,6 +102,7 @@ process_template <- function(template, ..., where = system.file("utils", package }, version = pars$version, entry_point = paste0(shQuote(pars$entry_point), collapse = ", "), + entry_name = pars$entry_name, license = pars$license, .open = "<<", .close = ">>" @@ -319,6 +320,7 @@ run_esbuild <- function(mode, outputDir, entry_point) { process_template( sprintf("esbuild.%s.js", mode), name = pkg_desc[[1]], + entry_name = if (length(entry_point) == 1) pkg_desc[[1]] else "[name]", version = pkg_desc[[2]], entry_point = entry_point ) diff --git a/inst/utils/esbuild.prod.js b/inst/utils/esbuild.prod.js index f96ca8b..650d972 100644 --- a/inst/utils/esbuild.prod.js +++ b/inst/utils/esbuild.prod.js @@ -6,7 +6,8 @@ import autoprefixer from 'autoprefixer'; esbuild .build({ entryPoints: [<>], - outfile: "inst/<>-<>/dist/<>.min.js", + outdir: "inst/<>-<>/dist", + entryNames: "<>.min", bundle: true, format: "esm", minify: true, // prod From 83c642f33f9f238b16e63bea1178949b3e260ed3 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 23 Jan 2024 16:40:41 +0100 Subject: [PATCH 03/12] add check for incorrect paths --- R/jstools.R | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/R/jstools.R b/R/jstools.R index d2205c8..4b4d0a9 100644 --- a/R/jstools.R +++ b/R/jstools.R @@ -25,6 +25,12 @@ build_js <- function(dir = "srcjs", mode = c("prod", "dev"), entry_point = "main entry_point <- paste0("./", dir, "/", entry_point) } + # check if entry_point exists + if (any(!file.exists(entry_point))) { + missing_entry_point <- entry_point[!file.exists(entry_point)] + ui_stop("The following entry points don't exist: {paste0(entry_point, collapse = ', ')}") + } + # run esbuild run_esbuild(mode, outputDir, entry_point) From ae7588d70d2de83b29e991c6d320451a846435d6 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 23 Jan 2024 16:44:09 +0100 Subject: [PATCH 04/12] allow 'entry_point' and 'entry_name' to be used in dev config --- inst/utils/esbuild.dev.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/inst/utils/esbuild.dev.js b/inst/utils/esbuild.dev.js index cf38a8f..d96cbd2 100644 --- a/inst/utils/esbuild.dev.js +++ b/inst/utils/esbuild.dev.js @@ -5,8 +5,9 @@ import autoprefixer from 'autoprefixer'; esbuild .build({ - entryPoints: ["./srcjs/main.js"], - outfile: "inst/<>-<>/dist/<>.js", + entryPoints: [<>], + outdir: "inst/<>-<>/dist", + entryNames: "<>.min", bundle: true, format: "esm", minify: false, // dev From 2cb64b97fb0e76ccc4a14886b6e3b95699cf6b0b Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Wed, 24 Jan 2024 08:50:04 +0100 Subject: [PATCH 05/12] write multiple HTML deps for multiple entry points --- R/deps.R | 90 +++++++++++++++++++++++++++-------------------------- R/jstools.R | 5 +-- 2 files changed, 49 insertions(+), 46 deletions(-) diff --git a/R/deps.R b/R/deps.R index 3fea812..fa4aa79 100644 --- a/R/deps.R +++ b/R/deps.R @@ -186,13 +186,11 @@ create_dependency <- function(name, tag = NULL, open = interactive(), options = #' #' @param name Package name. #' @param version Package version. +#' @param entry_point Entry points to create dependency for. #' @param open Whether to allow rstudioapi to open the newly created script. Default to TRUE. #' @param mode Internal. Don't use. #' @keywords Internal -create_custom_dependency <- function(name, version, open = interactive(), mode) { - - stylesheet <- sprintf("%s%s.css", name, mode) - script <- sprintf("%s%s.js", name, mode) +create_custom_dependency <- function(name, version, entry_point, open = interactive(), mode) { # need to overwrite path which was used before path <- sprintf("R/%s-dependencies.R", name) @@ -203,53 +201,57 @@ create_custom_dependency <- function(name, version, open = interactive(), mode) write(..., file = path, append = TRUE) } - # if we have multiple scripts/stylesheets - insert_multiple_lines <- function(what) { - lapply(seq_along(what), function (i) { - if (i == length(what)) { - write_there(sprintf(' "%s"', what[[i]])) - } else { - write_there(sprintf(' "%s",', what[[i]])) - } - }) + if (length(entry_point) > 1) { + # remove everything before last / and remove .js + entry_point_names <- gsub(".*/|.js", "", entry_point) + } else { + entry_point_names <- name } - # roxygen export - write_there(sprintf("#' %s dependencies utils", name)) - write_there("#'") - write_there(sprintf("#' @description This function attaches %s dependencies to the given tag", name)) - write_there("#'") - write_there("#' @param tag Element to attach the dependencies.") - write_there("#'") - write_there("#' @importFrom utils packageVersion") - write_there("#' @importFrom htmltools tagList htmlDependency") - write_there("#' @export") - # attach function - write_there(sprintf("add_%s_deps <- function(tag) {", name)) - - # htmlDependency content - write_there(sprintf(" %s_deps <- htmlDependency(", name)) - write_there(sprintf(' name = "%s",', name)) - write_there(sprintf(' version = "%s",', version)) - write_there(sprintf(' src = c(file = "%s-%s"),', name, version)) - write_there(sprintf(' script = "dist/%s",', script)) - write_there(sprintf(' stylesheet = "dist/%s",', stylesheet)) - write_there(sprintf(' package = "%s",', name)) - # end deps - write_there(" )") - - # attach deps - write_there(sprintf(" tagList(tag, %s_deps)", name)) - # end function - write_there("}") - write_there(" ") + # write in file for each entry point + lapply(entry_point_names, function(dep) { + + stylesheet <- sprintf("%s%s.css", dep, mode) + script <- sprintf("%s%s.js", dep, mode) + + # roxygen export + write_there(sprintf("#' %s dependencies utils", dep)) + write_there("#'") + write_there(sprintf("#' @description This function attaches %s dependencies to the given tag", dep)) + write_there("#'") + write_there("#' @param tag Element to attach the dependencies.") + write_there("#'") + write_there("#' @importFrom utils packageVersion") + write_there("#' @importFrom htmltools tagList htmlDependency") + write_there("#' @export") + # attach function + write_there(sprintf("add_%s_deps <- function(tag) {", dep)) + + # htmlDependency content + write_there(sprintf(" %s_deps <- htmlDependency(", dep)) + write_there(sprintf(' name = "%s",', dep)) + write_there(sprintf(' version = "%s",', version)) + write_there(sprintf(' src = c(file = "%s-%s"),', name, version)) + write_there(sprintf(' script = "dist/%s",', script)) + write_there(sprintf(' stylesheet = "dist/%s",', stylesheet)) + write_there(sprintf(' package = "%s",', name)) + # end deps + write_there(" )") + + # attach deps + write_there(sprintf(" tagList(tag, %s_deps)", dep)) + # end function + write_there("}") + write_there(" ") + }) # path to dependency if (!file.exists(sprintf("R/%s-dependencies.R", name))) { - ui_done("Dependency successfully created!") + ui_oops("Failed to create dependencies file!") } else { - ui_done("Dependency successfully updated!") + ui_done("Dependencies successfully updated!") } + if (open && rstudioapi::isAvailable()) rstudioapi::navigateToFile(path) } diff --git a/R/jstools.R b/R/jstools.R index 4b4d0a9..5e4acc4 100644 --- a/R/jstools.R +++ b/R/jstools.R @@ -36,8 +36,9 @@ build_js <- function(dir = "srcjs", mode = c("prod", "dev"), entry_point = "main # create custom dependency create_custom_dependency( - pkg_desc[1], - pkg_desc[2], + name = pkg_desc[1], + version = pkg_desc[2], + entry_point = entry_point, open = FALSE, mode = if (mode == "dev") "" else if (mode == "prod") ".min" ) From c8ac7701373a0267a98410570d496c4d27d823dc Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Wed, 24 Jan 2024 08:54:37 +0100 Subject: [PATCH 06/12] replace 'entry_point' with 'entry_points' --- R/deps.R | 8 ++++---- R/jstools.R | 20 ++++++++++---------- R/utils.R | 12 ++++++------ inst/utils/esbuild.dev.js | 2 +- inst/utils/esbuild.prod.js | 2 +- inst/utils/package.json | 2 +- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/R/deps.R b/R/deps.R index fa4aa79..09ef4b7 100644 --- a/R/deps.R +++ b/R/deps.R @@ -186,11 +186,11 @@ create_dependency <- function(name, tag = NULL, open = interactive(), options = #' #' @param name Package name. #' @param version Package version. -#' @param entry_point Entry points to create dependency for. +#' @param entry_points Entry points to create dependency for. #' @param open Whether to allow rstudioapi to open the newly created script. Default to TRUE. #' @param mode Internal. Don't use. #' @keywords Internal -create_custom_dependency <- function(name, version, entry_point, open = interactive(), mode) { +create_custom_dependency <- function(name, version, entry_points, open = interactive(), mode) { # need to overwrite path which was used before path <- sprintf("R/%s-dependencies.R", name) @@ -201,9 +201,9 @@ create_custom_dependency <- function(name, version, entry_point, open = interact write(..., file = path, append = TRUE) } - if (length(entry_point) > 1) { + if (length(entry_points) > 1) { # remove everything before last / and remove .js - entry_point_names <- gsub(".*/|.js", "", entry_point) + entry_point_names <- gsub(".*/|.js", "", entry_points) } else { entry_point_names <- name } diff --git a/R/jstools.R b/R/jstools.R index 5e4acc4..f8fb16c 100644 --- a/R/jstools.R +++ b/R/jstools.R @@ -8,37 +8,37 @@ #' @param mode Production or development mode. Choose either "prod" or "dev". #' "prod" bundles, aggregates and minifyies files. "dev" only bundles the code. #' Modules follow the ES6 format (import/export). -#' @param entry_point Entry point(s) to use in esbuild configuration. In case of +#' @param entry_points Entry point(s) to use in esbuild configuration. In case of #' a monolithic bundle, only one entrypoint is needed. This the default. #' In case of component based bundles, a vector of entrypoints is needed. #' The output files will match the entrypoints names. #' @export #' @importFrom utils tail packageVersion -build_js <- function(dir = "srcjs", mode = c("prod", "dev"), entry_point = "main.js") { +build_js <- function(dir = "srcjs", mode = c("prod", "dev"), entry_points = "main.js") { mode <- match.arg(mode) pkg_desc <- desc::description$new("./DESCRIPTION")$get(c("Package", "Version", "License")) outputDir <- sprintf("inst/%s-%s/dist", pkg_desc[1], pkg_desc[2]) # make sure entrypoints look like ./dir/file.js - if (any(!grepl(sprintf("^\\./%s", dir), entry_point))) { - entry_point <- paste0("./", dir, "/", entry_point) + if (any(!grepl(sprintf("^\\./%s", dir), entry_points))) { + entry_points <- paste0("./", dir, "/", entry_points) } - # check if entry_point exists - if (any(!file.exists(entry_point))) { - missing_entry_point <- entry_point[!file.exists(entry_point)] - ui_stop("The following entry points don't exist: {paste0(entry_point, collapse = ', ')}") + # check if entry_points exists + if (any(!file.exists(entry_points))) { + missing_entry_points <- entry_points[!file.exists(entry_points)] + ui_stop("The following entry points don't exist: {paste0(entry_points, collapse = ', ')}") } # run esbuild - run_esbuild(mode, outputDir, entry_point) + run_esbuild(mode, outputDir, entry_points) # create custom dependency create_custom_dependency( name = pkg_desc[1], version = pkg_desc[2], - entry_point = entry_point, + entry_points = entry_points, open = FALSE, mode = if (mode == "dev") "" else if (mode == "prod") ".min" ) diff --git a/R/utils.R b/R/utils.R index c431a9f..9276206 100644 --- a/R/utils.R +++ b/R/utils.R @@ -101,7 +101,7 @@ process_template <- function(template, ..., where = system.file("utils", package ) }, version = pars$version, - entry_point = paste0(shQuote(pars$entry_point), collapse = ", "), + entry_points = paste0(shQuote(pars$entry_points), collapse = ", "), entry_name = pars$entry_name, license = pars$license, .open = "<<", @@ -172,7 +172,7 @@ set_esbuild <- function(light = FALSE) { name = pkg_desc[1], version = pkg_desc[2], # node does not support 0.1.0.9000 license = pkg_desc[3], - entry_point = "main.js" + entry_points = "main.js" ) npm::npm_install( @@ -302,9 +302,9 @@ copy_charpente_utils <- function(pkg_name) { #' #' @inheritParams build_js #' @param outputDir Output directory -#' @param entry_point Entry points to be used +#' @param entry_points Entry points to be used #' @keywords internal -run_esbuild <- function(mode, outputDir, entry_point) { +run_esbuild <- function(mode, outputDir, entry_points) { # styles did not exist in previous {charpent} versions if (!dir.exists("styles")) { # Only add missing pieces ... @@ -320,9 +320,9 @@ run_esbuild <- function(mode, outputDir, entry_point) { process_template( sprintf("esbuild.%s.js", mode), name = pkg_desc[[1]], - entry_name = if (length(entry_point) == 1) pkg_desc[[1]] else "[name]", + entry_name = if (length(entry_points) == 1) pkg_desc[[1]] else "[name]", version = pkg_desc[[2]], - entry_point = entry_point + entry_points = entry_points ) npm::npm_run(sprintf("run build-%s", mode)) diff --git a/inst/utils/esbuild.dev.js b/inst/utils/esbuild.dev.js index d96cbd2..d4b08e9 100644 --- a/inst/utils/esbuild.dev.js +++ b/inst/utils/esbuild.dev.js @@ -5,7 +5,7 @@ import autoprefixer from 'autoprefixer'; esbuild .build({ - entryPoints: [<>], + entryPoints: [<>], outdir: "inst/<>-<>/dist", entryNames: "<>.min", bundle: true, diff --git a/inst/utils/esbuild.prod.js b/inst/utils/esbuild.prod.js index 650d972..d568696 100644 --- a/inst/utils/esbuild.prod.js +++ b/inst/utils/esbuild.prod.js @@ -5,7 +5,7 @@ import autoprefixer from 'autoprefixer'; esbuild .build({ - entryPoints: [<>], + entryPoints: [<>], outdir: "inst/<>-<>/dist", entryNames: "<>.min", bundle: true, diff --git a/inst/utils/package.json b/inst/utils/package.json index fc1765e..550e284 100644 --- a/inst/utils/package.json +++ b/inst/utils/package.json @@ -3,7 +3,7 @@ "version": "<>", "description": "", "private": true, - "main": "<>", + "main": "<>", "directories": { "man": "man" }, From 01e0180d91366b72f5d55329298207e3a5de216e Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Wed, 24 Jan 2024 09:02:25 +0100 Subject: [PATCH 07/12] remove .min in dev config --- inst/utils/esbuild.dev.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/utils/esbuild.dev.js b/inst/utils/esbuild.dev.js index d4b08e9..694f891 100644 --- a/inst/utils/esbuild.dev.js +++ b/inst/utils/esbuild.dev.js @@ -7,7 +7,7 @@ esbuild .build({ entryPoints: [<>], outdir: "inst/<>-<>/dist", - entryNames: "<>.min", + entryNames: "<>", bundle: true, format: "esm", minify: false, // dev From 32745c2bd3cd5fa4bb79d717f20c48b3af894aa1 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Wed, 24 Jan 2024 09:17:17 +0100 Subject: [PATCH 08/12] update docs --- README.md | 28 ++++++++++++++++++++++++++++ man/build_js.Rd | 7 ++++++- man/create_custom_dependency.Rd | 10 +++++++++- man/run_esbuild.Rd | 4 +++- 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 514359c..d1f5b95 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,34 @@ set_esbuild() set_mocha() ``` +## Monolithic and component based bundling + +`{charpente}` offers two ways of bundling your JS code: monolithic and component based. The monolithic bundling is the default one and is the simplest to use. It will bundle all your JS and CSS code into single files. By default, the entry point is `/scrjs/main.js`, which will also be created when setting esbuild for the first time with `set_esbuid()`. In this case bundling is easy and can be achieved with: + +```r +build_js() +``` + +Component based bundling might be convenient in situations where you want to create a bundle for each (standalone) component. Bundling per component will make sure that only the necessary assets are loaded. This is particularly useful when you want to create a package with multiple components, and not a complete template. To use component based bundling, you can specify multiple `entry_points` in `build_js()`. + +For the below structure in the /srcjs folder: + +``` +srcjs +├── component1.js +└── component2.js +``` + +You can build as follows: + +```r +build_js(entry_points = c("component1.js", "component2.js")) +``` + +CSS styles for each component can be loaded in the js files with `import` statements, e.g. `import "../styles/component1.scss";`. + +You JS code will be bundled into `/inst/{package-name}-{version}/`. Dependencies for your HTML are automatically created in `R/{package-name}-dependencies.R`. There will be only one HTML dependency in case of monolithic building, and multiple in case of component based building. + ## Acknowledgment The author would like to warmly thank [Victor Perrier](https://twitter.com/_pvictorr?lang=fr), [John Coene](https://twitter.com/jdatap), [Colin Fay](https://twitter.com/_ColinFay), [Alan Dipert](https://twitter.com/alandipert), [Kenton Russel](https://twitter.com/timelyportfolio) for providing many building block and inspiration to this package. diff --git a/man/build_js.Rd b/man/build_js.Rd index 9ee0f91..4490ea0 100644 --- a/man/build_js.Rd +++ b/man/build_js.Rd @@ -4,7 +4,7 @@ \alias{build_js} \title{Compress and optimize all files in the current folder} \usage{ -build_js(dir = "srcjs", mode = c("prod", "dev")) +build_js(dir = "srcjs", mode = c("prod", "dev"), entry_points = "main.js") } \arguments{ \item{dir}{Default to srcjs.} @@ -12,6 +12,11 @@ build_js(dir = "srcjs", mode = c("prod", "dev")) \item{mode}{Production or development mode. Choose either "prod" or "dev". "prod" bundles, aggregates and minifyies files. "dev" only bundles the code. Modules follow the ES6 format (import/export).} + +\item{entry_points}{Entry point(s) to use in esbuild configuration. In case of +a monolithic bundle, only one entrypoint is needed. This the default. +In case of component based bundles, a vector of entrypoints is needed. +The output files will match the entrypoints names.} } \description{ Generates a minified file under inst/pkg_name-pkg_version, if mode diff --git a/man/create_custom_dependency.Rd b/man/create_custom_dependency.Rd index e2caa76..9396773 100644 --- a/man/create_custom_dependency.Rd +++ b/man/create_custom_dependency.Rd @@ -4,13 +4,21 @@ \alias{create_custom_dependency} \title{Imports Internal Dependencies} \usage{ -create_custom_dependency(name, version, open = interactive(), mode) +create_custom_dependency( + name, + version, + entry_points, + open = interactive(), + mode +) } \arguments{ \item{name}{Package name.} \item{version}{Package version.} +\item{entry_points}{Entry points to create dependency for.} + \item{open}{Whether to allow rstudioapi to open the newly created script. Default to TRUE.} \item{mode}{Internal. Don't use.} diff --git a/man/run_esbuild.Rd b/man/run_esbuild.Rd index 1ffcc6a..2029cec 100644 --- a/man/run_esbuild.Rd +++ b/man/run_esbuild.Rd @@ -4,7 +4,7 @@ \alias{run_esbuild} \title{Run esbuild} \usage{ -run_esbuild(mode, outputDir) +run_esbuild(mode, outputDir, entry_points) } \arguments{ \item{mode}{Production or development mode. Choose either "prod" or "dev". @@ -12,6 +12,8 @@ run_esbuild(mode, outputDir) Modules follow the ES6 format (import/export).} \item{outputDir}{Output directory} + +\item{entry_points}{Entry points to be used} } \description{ Apply esbuild to the srcjs folder. From 6c9588be41c37c71decd15fb09a5ced70a50e7f7 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Wed, 24 Jan 2024 13:15:11 +0100 Subject: [PATCH 09/12] add check for special char or digit in entry point names --- R/deps.R | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/R/deps.R b/R/deps.R index 09ef4b7..bab5267 100644 --- a/R/deps.R +++ b/R/deps.R @@ -204,6 +204,29 @@ create_custom_dependency <- function(name, version, entry_points, open = interac if (length(entry_points) > 1) { # remove everything before last / and remove .js entry_point_names <- gsub(".*/|.js", "", entry_points) + + # Check for special characters, digits, and replace - with _ + has_special_or_digit <- grepl("[^a-zA-Z\\s]|\\d", entry_point_names) + has_hyphen <- grepl("-", entry_point_names) + + if (any(has_special_or_digit)) { + format_names <- entry_point_names[has_special_or_digit] + + ui_warn( + "Consider removing special characters or digits from the following entry point filenames: + {paste(format_names, collapse = ', ')}" + ) + + if (any(has_hyphen)) { + entry_point_names[has_hyphen] <- gsub("-", "_", entry_point_names[has_hyphen]) + + ui_done( + "Replaced - with _ in the following entry points: + {paste(format_names, collapse = ', ')}" + ) + } + } + } else { entry_point_names <- name } From 4c7b436631dbfac92f90e64ad98823463f329a42 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Wed, 24 Jan 2024 13:22:14 +0100 Subject: [PATCH 10/12] bump up package version to 0.7.0 --- DESCRIPTION | 2 +- NEWS.md | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 22a79f5..ec8c54e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: charpente Title: Seamlessly design robust 'shiny' extensions -Version: 0.6.0 +Version: 0.7.0 Authors@R: c( person( given = "David", diff --git a/NEWS.md b/NEWS.md index f190326..6acf1bb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +# charpente 0.7.0 + +## New: +- Enhanced `esbuild` configuration to allow component based bundling. `build_js` now accepts an `entry_points` argument to specify the entry files processed by `esbuild`. The (minified) output files will correspond to the given entry files. The default is monolithic building with the `./srcjs/main.js` file. See `?build_js` for more details. + # charpente 0.6.0 ## New: From 2b23b48eef615a7eab975a5c131cb7b95358f26b Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Wed, 24 Jan 2024 13:26:19 +0100 Subject: [PATCH 11/12] use correct 'format_names' --- R/deps.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/deps.R b/R/deps.R index bab5267..0434b0d 100644 --- a/R/deps.R +++ b/R/deps.R @@ -220,6 +220,8 @@ create_custom_dependency <- function(name, version, entry_points, open = interac if (any(has_hyphen)) { entry_point_names[has_hyphen] <- gsub("-", "_", entry_point_names[has_hyphen]) + format_names <- entry_point_names[has_hyphen] + ui_done( "Replaced - with _ in the following entry points: {paste(format_names, collapse = ', ')}" From fe75615d7a9b2287be3b97fa7206cad92ac4313b Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Wed, 24 Jan 2024 15:23:45 +0100 Subject: [PATCH 12/12] include Veerle van Leemput as contributor --- DESCRIPTION | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/DESCRIPTION b/DESCRIPTION index ec8c54e..00e9227 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -15,6 +15,12 @@ Authors@R: c( role = "ctb", comment = "Functions from html2r" ), + person( + given = "Veerle", + family = "van Leemput", + role = "ctb", + email = "veerle@hypebright.nl" + ), person(family = "RinteRface", role = "cph"), person(family = "ThinkR", role = "cph", comment = "Some utils from golem") )