railsadminteam / rails_admin

RailsAdmin is a Rails engine that provides an easy-to-use interface for managing your data
MIT License
7.87k stars 2.25k forks source link

importmap-rails download error #3626

Open nulty opened 1 year ago

nulty commented 1 year ago

Describe the bug When using bin/importmap pin rails_admin --download, an error is thrown. See below for full stack trace.

Reproduction steps Steps to reproduce the issue seen.

Expected behavior I expect the jquery-ui files to each be downloaded and saved to the vendor directory.

Additional context

Pinning "rails_admin" to vendor/javascript/rails_admin.js via download from https://ga.jspm.io/npm:rails_admin@3.1.2/src/rails_admin/base.js
Pinning "@hotwired/turbo" to vendor/javascript/@hotwired/turbo.js via download from https://ga.jspm.io/npm:@hotwired/turbo@7.3.0/dist/turbo.es2017-esm.js
Pinning "@hotwired/turbo-rails" to vendor/javascript/@hotwired/turbo-rails.js via download from https://ga.jspm.io/npm:@hotwired/turbo-rails@7.3.0/app/javascript/turbo/index.js
Pinning "@popperjs/core" to vendor/javascript/@popperjs/core.js via download from https://ga.jspm.io/npm:@popperjs/core@2.11.7/lib/index.js
Pinning "@rails/actioncable/src" to vendor/javascript/@rails/actioncable/src.js via download from https://ga.jspm.io/npm:@rails/actioncable@7.0.4/src/index.js
Pinning "@rails/ujs" to vendor/javascript/@rails/ujs.js via download from https://ga.jspm.io/npm:@rails/ujs@6.1.7/lib/assets/compiled/rails-ujs.js
Pinning "bootstrap" to vendor/javascript/bootstrap.js via download from https://ga.jspm.io/npm:bootstrap@5.2.3/dist/js/bootstrap.esm.js
Pinning "flatpickr" to vendor/javascript/flatpickr.js via download from https://ga.jspm.io/npm:flatpickr@4.6.13/dist/esm/index.js
Pinning "jquery" to vendor/javascript/jquery.js via download from https://ga.jspm.io/npm:jquery@3.7.0/dist/jquery.js
Pinning "jquery-ui/ui/" to vendor/javascript/jquery-ui/ui/.js via download from https://ga.jspm.io/npm:jquery-ui@1.13.2/ui/
/$HOME/.asdf/installs/ruby/3.2.1/lib/ruby/gems/3.2.0/gems/importmap-rails-1.1.5/lib/importmap/packager.rb:81:in `handle_failure_response': Unexpected response code (404) (Importmap::Packager::HTTPError)
        from /$HOME/.asdf/installs/ruby/3.2.1/lib/ruby/gems/3.2.0/gems/importmap-rails-1.1.5/lib/importmap/packager.rb:119:in `download_package_file'
        from /$HOME/.asdf/installs/ruby/3.2.1/lib/ruby/gems/3.2.0/gems/importmap-rails-1.1.5/lib/importmap/packager.rb:58:in `download'
        from /$HOME/.asdf/installs/ruby/3.2.1/lib/ruby/gems/3.2.0/gems/importmap-rails-1.1.5/lib/importmap/commands.rb:21:in `block in pin'
        from /$HOME/.asdf/installs/ruby/3.2.1/lib/ruby/gems/3.2.0/gems/importmap-rails-1.1.5/lib/importmap/commands.rb:18:in `each'
        from /$HOME/.asdf/installs/ruby/3.2.1/lib/ruby/gems/3.2.0/gems/importmap-rails-1.1.5/lib/importmap/commands.rb:18:in `pin'
        from /$HOME/.asdf/installs/ruby/3.2.1/lib/ruby/gems/3.2.0/gems/thor-1.2.2/lib/thor/command.rb:27:in `run'
        from /$HOME/.asdf/installs/ruby/3.2.1/lib/ruby/gems/3.2.0/gems/thor-1.2.2/lib/thor/invocation.rb:127:in `invoke_command'
        from /$HOME/.asdf/installs/ruby/3.2.1/lib/ruby/gems/3.2.0/gems/thor-1.2.2/lib/thor.rb:392:in `dispatch'
        from /$HOME/.asdf/installs/ruby/3.2.1/lib/ruby/gems/3.2.0/gems/thor-1.2.2/lib/thor/base.rb:485:in `start'
        from /$HOME/.asdf/installs/ruby/3.2.1/lib/ruby/gems/3.2.0/gems/importmap-rails-1.1.5/lib/importmap/commands.rb:142:in `<main>'
        from <internal:/$HOME/.asdf/installs/ruby/3.2.1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from <internal:/$HOME/.asdf/installs/ruby/3.2.1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from /$HOME/.asdf/installs/ruby/3.2.1/lib/ruby/gems/3.2.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
        from /$HOME/.asdf/installs/ruby/3.2.1/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.8/lib/zeitwerk/kernel.rb:38:in `require' from bin/importmap:4:in `<main>'

Add any other context about the problem here.

My understanding is that importmap-rails makes a request to jspm.io for the import maps for the library. The service returns an invalid(?) importmap for jquery-ui

[1] pry(#<Importmap::Packager>)> JSON.parse(response.body).dig("map", "imports")
=> {"rails_admin"=>"https://ga.jspm.io/npm:rails_admin@3.1.2/src/rails_admin/base.js",
 "@hotwired/turbo"=>"https://ga.jspm.io/npm:@hotwired/turbo@7.3.0/dist/turbo.es2017-esm.js",
 "@hotwired/turbo-rails"=>"https://ga.jspm.io/npm:@hotwired/turbo-rails@7.3.0/app/javascript/turbo/index.js",
 "@popperjs/core"=>"https://ga.jspm.io/npm:@popperjs/core@2.11.7/lib/index.js",
 "@rails/actioncable/src"=>"https://ga.jspm.io/npm:@rails/actioncable@7.0.4/src/index.js",
 "@rails/ujs"=>"https://ga.jspm.io/npm:@rails/ujs@6.1.7/lib/assets/compiled/rails-ujs.js",
 "bootstrap"=>"https://ga.jspm.io/npm:bootstrap@5.2.3/dist/js/bootstrap.esm.js",
 "flatpickr"=>"https://ga.jspm.io/npm:flatpickr@4.6.13/dist/esm/index.js",
 "jquery"=>"https://ga.jspm.io/npm:jquery@3.7.0/dist/jquery.js",
 "jquery-ui/ui/"=>"https://ga.jspm.io/npm:jquery-ui@1.13.2/ui/"}

"jquery-ui/ui/"=>"https://ga.jspm.io/npm:jquery-ui@1.13.2/ui/" this line cannot be resolved. I'm guessing each of the jquery-ui library components should be returned in this json?

This is where importmaps is attempting to download the "file" https://github.com/rails/importmap-rails/blob/main/lib/importmap/packager.rb#LL57C23-L57C23

Is it that rails_admin could be packaged in such a way that the import maps returned are downloadable?