-
Notifications
You must be signed in to change notification settings - Fork 120
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
Handle String response for "find latest version" #246
Handle String response for "find latest version" #246
Conversation
See rails#245 for context. The TL;DR is the response sometimes returns a String instead of Hash object. This should be handled properly. The way to handle this is up for discussion. To start addressing the issue the String response will just be surfaced as `latest_version`.
Not exactly sure why the CI checks are failing, but it seems to have nothing to do with the proposed changes. |
We only care to assert on the `latest_version` since this is what we care about. Can revert the change if it is desired to assert the rest.
@@ -86,7 +86,7 @@ def get_json(uri) | |||
end | |||
|
|||
def find_latest_version(response) | |||
latest_version = response.dig('dist-tags', 'latest') | |||
latest_version = response.is_a?(String) ? response : response.dig('dist-tags', 'latest') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The response may be a blank String. One reported issue (#245 (comment)) made me question this possibility.
If this is the case then a fallback may be worthwhile. I am writing it with available Rails methods, but can change it to use Ruby-only accessible ones.
latest_version = response.is_a?(String) ? response : response.dig('dist-tags', 'latest') | |
latest_version = response.is_a?(String) ? (response.presence || 'unknown') : response.dig('dist-tags', 'latest') |
Any chance this fix could be merged or at least considered? Without this it's making it very hard for us to figure out which JS dependencies are out of date since we were relying heavily on the |
Closes #245
Problem
It is expected NPM to return a Hash for the response.
importmap-rails/lib/importmap/npm.rb
Line 89 in ddf9be4
But for whatever reason the response can now also return a String, which is not accounted for in
npm.rb
.See the referenced issue for further context.
Expectation
The
importmap outdated
command should handle the problem more gracefully. In this case, a reasonable expectation is to surface the String response.Solution
How to handle is up for discussion.
Just to get the fix process started the propose change is to surface the String in the response as
latest_version
since it isn't clear what the contents of the String could be.Using the fork with change on our production app which has the problematic pinned dependency, the following
outdated
is now returned.