Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to bin/importmap pin URL to create direct/remote link without downloading #247

Open
bensheldon opened this issue Feb 25, 2024 · 0 comments

Comments

@bensheldon
Copy link

bensheldon commented Feb 25, 2024

It's currently possible to "manually" add a URL to config/importmap.rb that will not attempt to be locally cached e.g.

# config/importmap.rb
pin "some-package", to: "https://someotherhost.com/some-package.js"

...but there isn't currently a way to add that entry through the $ bin/importmap pin command because it will always attempt to download and vendor the file through jspm:

def pin(*packages)
if imports = packager.import(*packages, env: options[:env], from: options[:from])
imports.each do |package, url|
puts %(Pinning "#{package}" to #{packager.vendor_path}/#{package}.js via download from #{url})
packager.download(package, url)

This Issue proposes an option for adding a new entry using bin/importmap pin that will not be downloaded and maintain the direct URL:

bin/importmap pin https://mycdn.com/some-package.js --from direct

Update: Thinking some more about this, I wonder if when using the CLI pin command, merely passing a value that starts with http[s]:// would result in the direct mode.

Update2: Oops, I overlooked the change where pin is now synonymous with vendoring the library. I think maybe I have two thoughts now on this:

  1. The behavior of providing a static URL does still seem to work when added to the config/importmap.rb file.
  2. The use-case behind this is a desire to use my own js libraries that are served from their own remote host and are available upon multiple websites/projects and I'd like to update/manage them remotely without vendoring/updating/managing them within multiple individual Rails apps. Unfortunately browser imports only allow a single <script type="importmap"> ... tag per HTML page, which means that all importmap definitions would need to go through a single helper.
@bensheldon bensheldon changed the title Add option to bin/importmap pin URL to create CDN direct link without downloading Add option to bin/importmap pin URL to create direct/remote link without downloading Feb 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant