rails / importmap-rails

Use ESM with importmap to manage modern JavaScript in Rails without transpiling or bundling.
MIT License
1.07k stars 120 forks source link

Unable to unpin #229

Open jcoyne opened 10 months ago

jcoyne commented 10 months ago

On 2.0.1

I first list the packages I've pinned:

bin/importmap packages
video.js 8.6.1
@babel/runtime 7.23.5
@videojs/vhs-utils 4.1.0
@videojs/vhs-utils 3.0.5
@videojs/xhr 2.6.0
@xmldom/xmldom 0.8.10
dom-walk 0.1.2
global 4.4.0
is-function 1.0.2
keycode 2.2.0
m3u8-parser 6.2.0
min-document 2.19.0
mpd-parser 1.2.2
mux.js 7.0.2
safe-json-parse 4.0.0
url-toolkit 2.2.5
videojs-vtt.js 0.15.5
openseadragon 4.1.0
fscreen 1.2.0
@google/model-viewer 3.3.0
@lit/reactive-element 1.6.3
lit 2.8.0
lit-element 3.3.3
lit-html 2.8.0
three 0.160.0

Then I try to unpin video.js:

bin/importmap unpin video.js 8.6.1
Couldn't find any packages in ["video.js", "8.6.1"] on jspm

If I try it without the version I see:

bin/importmap unpin video.js 
Couldn't find any packages in ["video.js"] on jspm

However I was able to unpin other packages:

bin/importmap unpin lit
Unpinning and removing "lit"
Unpinning and removing "@lit/reactive-element"
Unpinning and removing "lit-element/lit-element.js"
Unpinning and removing "lit-html"
Unpinning and removing "lit-html/is-server.js"
pasl commented 9 months ago

I also had trouble understanding how Importmap works since version 2.

What I've found is that you have to specify the specific version with the '@' sign like this:

bin/importmap pin jsprintmanager@5.0.2

This will result in the following in importmap.rb:

pin "jsprintmanager" # @5.0.2

The version number will be appended in a comment.

It will also download the file to vendor/javascript, which is something we previously needed to explicitly add the --download option for when pinning. Now, it always downloads the file, I believe.

You can see that the parameter to: 'https://....' is no longer used in the importmap.rb file. The 'old' syntax is actually confusing because the version specified in the URL will not match the actual downloaded version.

For unpinning, there's no need to specify the version:

bin/importmap unpin jsprintmanager@5.0.2 bin/importmap unpin jsprintmanager@6.0.0 bin/importmap unpin jsprintmanager

All of these commands will unpin the library even if the version mismatch. The only requirement is that the version actually exists on JSPM is you chose to specify a version.

Also, be careful because bin/importmap update will update all libraries to the latest version. If you need to keep an old version of a specific library, I think you can use:

importmap outdated

and then pin each library that needs to be updated one by one.