Skip to content

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

Open
@bensheldon

Description

@bensheldon

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions