Giter VIP home page Giter VIP logo

leprechaun's People

Contributors

jamierowen avatar johncoene avatar mikejohnpage avatar russhyde avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

leprechaun's Issues

serveAssets ignores all assets

Hi John,

Thanks for your reply and solution in issues JohnCoene/packer#23 and #7. I finally had some time again to take a look at it again.
The ignoring of the index.js works!
However, I noticed that when not adding it to the ignore, it would still be ignored.
It turns out that not ignoring any assets results in all assets being ignored.
I looked into the problem and found the cause, it has to do with the regular expression that is created find ignored assets.
When the vector is empty, the regex becomes "$", this will make it so that all assets are matched and thus ignored.
I fixed it like this:
ignore_pat <- paste0(c("^", ignore), collapse = "|", sep ="$")

This will always add "^$" to the regular expression which should match nothing and thus ignore nothing.

Inconsistent UI between test from run after devtools and run after loading library

Hi, and thanks for this nice package

There seems to be an inconsistency when running an app with devtools::document() ; devtools::load_all() ; run() as described in your quick start guide and running from empty env after library(myapp).

Code to reproduce behavior and screenshot :

behavior 1

# make app as package
usethis::create_package("myapp")
leprechaun::scaffold()
# run it like in quick start from leprechaun doc
devtools::document()
devtools::load_all()
run()

test_with_devtools_run

behavior 2

#then install it
devtools::install()

from a new R session :

library(myapp)
run()

test_with_library_run


My sessionInfo :

> sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.3 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale:
 [1] LC_CTYPE=fr_FR.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=fr_FR.UTF-8        LC_COLLATE=fr_FR.UTF-8    
 [5] LC_MONETARY=fr_FR.UTF-8    LC_MESSAGES=fr_FR.UTF-8   
 [7] LC_PAPER=fr_FR.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=fr_FR.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_4.1.2

`scaffold()` clobbers existing zzz.R

If your package has an existing R/zzz.R with an onload hook the content from scaffold overwrites this completely. Ideally it would add the new content to the onload hook if it already exists.

`serveAssets()` does not add `type = module` to script tags with JavaScript module files

Description of Issue

Desired Behavior

I'm trying to load a JS file containing an ESM module as a dependency using serveAssets(modules = "my_module.js"). The function should create a script tag in the HTML head that looks like this <script src="[...]/my_module.js" type="module">.

Observed Behavior

What actually gets added to the HTML-head is this:

<head>
 ... 
<meta name="type" content="module">
<script src="[...]/my_module.js"></script>
 ... 
</head>

As a result, the browser doesn't know it is is dealing with an ESM module, throws an error Uncaught SyntaxError: Unexpected token 'export' when it encounters the mosule exports, and fails to load the module.

Source of the Issue

I've had a look at the template for assets.R.
I think the error is happening here:

if(!is.null(modules)){
		modules <- htmlDependency(
			"#PKGNAME#-modules",
			version = utils::packageVersion("#PKGNAME#"),
			package = "#PKGNAME#",
			src = ".",
			script = modules,
			meta = list(type = "module")   # <------ !
		)
		dependencies <- append(dependencies, list(modules))
	}

Specifically, the following line doesn't do what you maybe thought it does:

meta = list(type = "module")

That is, it does not add an additional attribute to the created script tag. Instead, it adds an additional tag <meta name="type" content="module"> to the head, as can be seen above. This is also the documented behavior of htmltools::htmlDependency().

Possible Solution

htmltools::htmlDependency() allows the use of a named list with src and any other valid <script> attributes as input to the script argument. Another useful feature is, that it allows to use

An unnamed list, containing a combination of named list with the fields mentioned previously, and strings

Quick fix

A simple way to fix the issue at hand would be to replace the code above with

	if(!is.null(modules)){

	  modules <- lapply(modules, \(src) list(src = src, type = "module"))

		modules <- htmlDependency(
			"pitui.poc-modules",
			version = utils::packageVersion("pitui.poc"),
			package = "pitui.poc",
			src = ".",
			script = modules
		)
		dependencies <- append(dependencies, list(modules))
	}

This will add the correct script tags to the header for the modules:
<script src="[..]/my_module.js" type="module"></script>

Further improvements

It should be possible to further simplify create_assets() by processing all javascript dependencies at the same time, and simply wrapping those that are modules in lists with an additional type = "module" element. Something along the lines of:

# in serveAssets()
#...
# JavaScript files
javascript <- list.files(
  system.file(package = "#PKGNAME#"),
  recursive = TRUE,
  pattern = ".js$"
)

is_module <- basename(javascript) %in% modules

if (sum(is_module)) {
 javascript <- lapply(seq_along(javascript), \(i) {
    if(is_module[i]) list(src = javascript[i], type = "module") else javascript[i]
 })
}
#...

or, using purrr:

purrr::map2(javascript, is_module, \(f, is_module) if(is_module) list(src = f, type = "module") else f )

(not tested)

Build Step

We need to get rid of the build step.

It should be executed on document with roclet or some other way.

leprechaun::use_config() produces incorrect cli output

Hi there—leprechaun is an excellent package! It’s a wonderful addition to the shiny ecosystem :)

I noticed in the leprechaun::use_config() function, the cli output lists the following:

leprechaun::use_config()
✔ Creating inst/config.RCreating inst/config.ymlAdding 'yaml' to Imports in DESCRIPTION

And it actually creates inst/config.yml and R/config.R

├── DESCRIPTION
├── NAMESPACE
├── R/
│   ├── _disable_autoload.R
│   ├── assets.R
│   ├── config.R
│   ├── input-handlers.R
│   ├── leprechaun-utils.R
│   ├── run.R
│   ├── server.R
│   ├── ui.R
│   └── zzz.R
└── inst/
    ├── assets
    ├── config.yml
    ├── dev
    ├── img
    └── run

The link to the cli function is here

I didn't see any contributing guidelines, so I didn't open a PR :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.