Respect remote URL pins and preserve pin options in bin/importmap - #327
Open
mhenrixon wants to merge 1 commit into
Open
Respect remote URL pins and preserve pin options in bin/importmap#327mhenrixon wants to merge 1 commit into
mhenrixon wants to merge 1 commit into
Conversation
Pinning or updating a package rewrote every pin in the jspm response (including transitive dependencies) with default options, wiping preload: false and replacing hand-written remote URL pins with vendored downloads. - pin_package now extracts the existing pin's options first: preload survives any rewrite unless --preload is passed explicitly - pins with to: "https://..." stay remote: the URL is re-resolved from the same CDN provider (ga.jspm.io, unpkg.com, cdn.jsdelivr.net, cdn.skypack.dev, esm.sh); unknown hosts are left untouched with a notice; failed provider resolution keeps the existing pin - new --remote flag on pin creates URL pins without downloading and removes a previously vendored file when converting - pristine skips remote pins (nothing to redownload) - npm version scan recognizes esm.sh URLs (incl. the * prefix) and version extraction keeps prerelease suffixes (@2.0.0-beta.19) - Gemfile.lock synced with the 2.2.3 version bump
|
We’re running into this issue in practice while using thoughtbot/importmap-update for automated dependency updates. Some existing pin attributes (for example preload: false) can disappear when dependencies are updated, which can result in unintended changes to the importmap configuration. Would be great to get this merged, as it would make automated dependency updates much safer and more reliable for us. Thanks @mhenrixon for putting together the fix! 🙏 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Running
bin/importmap pin pkg@x.y.z(orupdate) rewrites every pin in the jspm response — including transitive dependencies — from scratch:preload: falseis wiped on every bump. The new pin line is built solely from the CLI's--preloadflag, so options on existing pins (and on every dependency that happens to be in the response) are lost.updatepreserved preload for directly-requested packages, butpinnever did, and dependencies were always clobbered.pin "pkg", to: "https://ga.jspm.io/npm:pkg@1.0.0/index.js"is silently converted to a vendored download the next time the package is pinned, updated, or pulled in as a dependency.Changes
pin_packagenow looks at the existing pin before writing:preloadvalue survivespin/updateunless--preloadis passed explicitly. This applies to dependencies re-pinned along the way, not just requested packages.to:is anhttps://URL:ga.jspm.io,unpkg.com,cdn.jsdelivr.net,cdn.skypack.dev,esm.sh) are re-resolved from the same provider at the new version — a jsdelivr pin updates to a new jsdelivr URL even though resolution goes through jspm.Skipping "pkg" pinned to custom URL ...notice.--remoteflag onpincreates URL pins without downloading (pin "react", to: "https://ga.jspm.io/npm:react@19.1.0/index.js"), and removes the previously vendored file when converting an existing vendored pin.pristineskips remote pins — there is nothing to redownload.esm.shURLs (including its*external-deps prefix), and version extraction keeps prerelease suffixes (@2.0.0-beta.19no longer truncates to@2.0.0).An explicit
integrity:value is still dropped when a pin's URL changes (unchanged policy — the stale hash would break the page).Notes
updatestripsto:from URL pins encoded exactly the behavior this fixes, so it is inverted; the Skypack test fixtures were moved to jsdelivr since Skypack no longer resolves through the generator.Gemfile.lockis synced with the 2.2.3 version bump fromPrepare for 2.2.3(the lock still said 2.2.2) and picks up thearm64-darwin-24platform.Testing
Full suite passes: 112 runs, 0 failures. The commands tests run
bin/importmapas a subprocess against the live jspm API and assert on the resultingconfig/importmap.rb, covering: remote pins survivingpin/update, dependency options surviving a bump,--remotecreation and vendored→remote conversion, custom-host pins left byte-identical, andpristineskipping remote pins.