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

Dependencies vs subdependencies #174

Closed
dkniffin opened this issue Feb 9, 2023 · 4 comments
Closed

Dependencies vs subdependencies #174

dkniffin opened this issue Feb 9, 2023 · 4 comments

Comments

@dkniffin
Copy link
Contributor

dkniffin commented Feb 9, 2023

I'm just starting to use importmap-rails now. I noticed when I run importmap pin xyz, if xyz has sub-dependencies, they get pinned too.

When I'm looking at my config/importmap.rb file, how do I distinguish what is one of my direct dependencies, vs what is a subdependency?

Also, what happens if two of my dependencies require different version of the same sub-dependency? Is that up to me to manage?

@dkniffin
Copy link
Contributor Author

dkniffin commented Feb 20, 2023

As I've been exploring importmap-rails usage more, I've been testing this simple solution:

pin "flickity", to: "https://ga.jspm.io/npm:flickity@2.3.0/js/index.js"
  pin "ev-emitter", to: "https://ga.jspm.io/npm:ev-emitter@1.1.1/ev-emitter.js"
  pin "fizzy-ui-utils", to: "https://ga.jspm.io/npm:fizzy-ui-utils@2.0.7/utils.js"
    pin "desandro-matches-selector", to: "https://ga.jspm.io/npm:desandro-matches-selector@2.0.2/matches-selector.js"
  pin "get-size", to: "https://ga.jspm.io/npm:get-size@2.0.3/get-size.js"
  pin "imagesloaded", to: "https://ga.jspm.io/npm:imagesloaded@5.0.0/imagesloaded.js"
  pin "unidragger", to: "https://ga.jspm.io/npm:unidragger@2.4.0/unidragger.js"
  pin "unipointer", to: "https://ga.jspm.io/npm:unipointer@2.4.0/unipointer.js"

Basically, just indent sub-dependencies inside the dependency. Simple.

However, this goes against Rubocop conventions, so I had to add # rubocop:disable Layout/IndentationConsistency.

It also breaks lines like this and this which depend on pin being at the very start of the line. It might break other things I haven't discovered yet.

But the most important downside to this is that it means I have to manually manage the indentation, which works if I have a small number of packages, but for a lot it would get messy.

I would love to see sub-dependencies either abstracted somehow so they're not shown at all inside config/importmap.rb, or have this indentation style officially supported via blocks, or have another option for managing these.

@dkniffin
Copy link
Contributor Author

@dhh can you explain why you marked this as complete? I don't see any recent commits adding this functionality, but maybe I missed something.

@dhh
Copy link
Member

dhh commented Jun 18, 2023

Should have included a comment. This is beyond the scope of what importmap can/should offer in my opinion. We are not a full-featured package manager. Multiple packages can share the same root dependencies, and we don't have any way of representing that with this setup.

@dkniffin
Copy link
Contributor Author

dkniffin commented Jan 15, 2024

Looping back here to mention that I created a gem to add this functionality: https://github.com/quimbee/importmap-package-manager It lets you separate your library imports into a separate config/importmap_packages.yml (which has allows defining version specs), then run rake importmap_package_manager:update to generate/update a config/importmap-packages-lock.rb file (which includes the sub-dependencies), which gets included in the importmap.

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

2 participants