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.
This adds two new commands to Importmap:
./bin/importmap audit
and./bin/importmap outdated
.Both commands use npm's endpoints to fetch the related data.
While
audit
has an endpoint where they accept multiple packages, I couldn't find any to retrieve the versions of multiple packages in order to decrease the requests for theoutdated
check; and thus it's doing one request for each package.I initially used a much simpler regex to extract the name and version (
/^pin "([^"]*)".*@(\d+\.\d+\.\d+(?:[^\/\s]+)?).*$/
), but then I discovered that some packages are loaded from inside other packages, and thus I couldn't rely on the name provided to thepin
method. For a better maintainability I've kept the two regex separate: 1 for remote dependencies, and 1 for local dependencies. The|
would also have the nice addition of "uniq" them.Such dependencies that are downloaded locally might still be affected by this, and there is no reference to the original package name. One option here could be to change the current comment from just
# @version
to something like# from url
, that way it'd include the version, but also the source/package name, and that point we could also have one single regex. What do you think? (I haven't done that change yet)The current regex would also take care of versions like
2.0.0-beta.19
or similar (I've run a check on all versions from ~350k npm packages, and they were all covered by this).It relies on the current structure of those urls, which might be risky on the long term (if they ever change it); an alternative solution could be to add a custom comment for this purpose (always, or just when package name is different), but then we'd have to take care of existing importmap files without that comment.
You can check here some sample data, it should cover all cases 🤞
There could be some edge cases, for example if someone adds a comment similar to the local one to a remote dependency, or uses a different provider. I don't know if we want to support for those as well.
Audit
Outdated
Related to #19