rstudio / htmltools

Tools for HTML generation and output
https://rstudio.github.io/htmltools/
215 stars 69 forks source link

fix: copyDependencyToDir tries to copy non-existent files unintentionally #309

Closed atusy closed 2 years ago

atusy commented 2 years ago

when script is a list and all_files is FALSE

This happens because copyDependencyToDir considers unlist(dependency[c('script', 'stylesheet', 'attachment')]) as paths to files, but script can be a list with some html attributes such as defer.

library(htmltools)

# Prepare example data
src <- tempfile()
dir.create(src, showWarnings = FALSE)
script <- c("1.js", "2.js")
invisible(file.create(file.path(src, script)))
deps <- htmlDependency(
  name = "example",
  version = "1.0",
  src = src,
  #script = script,
  script = lapply(script, function(x) list(src = x, defer = NA)),
  all_files = FALSE
)

# Try copyDependencyToDir
outputDir = tempfile()
dir.create(outputDir, showWarnings = FALSE)
copyDependencyToDir(deps,outputDir = outputDir)
#> Error in htmltools::copyDependencyToDir(deps, outputDir = outputDir): Can't copy dependency files that don't exist: '/tmp/RtmpzXKs5M/file121c6ec550eb/1.js', '/tmp/RtmpzXKs5M/file121c6ec550eb/NA', '/tmp/RtmpzXKs5M/file121c6ec550eb/2.js', '/tmp/RtmpzXKs5M/file121c6ec550eb/NA'

Created on 2021-12-29 by the reprex package (v2.0.0)

cpsievert commented 2 years ago

Addressed by https://github.com/rstudio/htmltools/commit/5fe6cd67b25153302351fd026a070d1a7660d7a6