Add single quote support in importmap.rb
#198
Merged
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.
Related issue: #156
Problem
Wrapping strings with single-quotes in the
importmap.rbfile is not picked up by commandsauditandoutdated.Expectation
The
auditandoutdatedcommands should pick up pins where either double or single quotes are used.Solution
The problematic lines are the following:
importmap-rails/lib/importmap/npm.rb
Line 51 in 9eec49a
importmap-rails/lib/importmap/npm.rb
Line 52 in 9eec49a
The regex are designed to only scan for double-quotes. The proposed change adds in detection for double-quotes and single-quotes.
The implementation proposed is a bit naive in that strings wrapped with one double-quote and one single-quote will return positive. For example,
pin "local_time' #@2.1.0will return positive. Runningoutdatedandauditwill run without issue. On a Rails app using importmap, theSyntaxError: unterminated string meets end of filewill raise.Whether or not it is important to address this quirk is up for discussion.
Below are how example pins (taken from issue #156 and test fixtures) fair against the updated regexes.