Skip to content

Commit

Permalink
Merge pull request #198 from vietqhoang/add-single-quote-support
Browse files Browse the repository at this point in the history
Add single quote support in `importmap.rb`
  • Loading branch information
rafaelfranca authored Oct 27, 2023
2 parents 9eec49a + 5ca80cf commit 9fac238
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/importmap/npm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def packages_with_versions
# We cannot use the name after "pin" because some dependencies are loaded from inside packages
# Eg. pin "buffer", to: "https://ga.jspm.io/npm:@jspm/core@2.0.0-beta.19/nodelibs/browser/buffer.js"

importmap.scan(/^pin .*(?<=npm:|npm\/|skypack\.dev\/|unpkg\.com\/)(.*)(?=@\d+\.\d+\.\d+)@(\d+\.\d+\.\d+(?:[^\/\s"]*)).*$/) |
importmap.scan(/^pin "([^"]*)".* #.*@(\d+\.\d+\.\d+(?:[^\s]*)).*$/)
importmap.scan(/^pin .*(?<=npm:|npm\/|skypack\.dev\/|unpkg\.com\/)(.*)(?=@\d+\.\d+\.\d+)@(\d+\.\d+\.\d+(?:[^\/\s["']]*)).*$/) |
importmap.scan(/^pin ["']([^["']]*)["'].* #.*@(\d+\.\d+\.\d+(?:[^\s]*)).*$/)
end

private
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/files/single_quote_outdated_import_map.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pin 'md5', to: 'https://cdn.skypack.dev/md5@2.2.0', preload: true
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pin 'md5', preload: true #@2.2.0
28 changes: 28 additions & 0 deletions test/npm_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,34 @@ class Importmap::NpmTest < ActiveSupport::TestCase
end
end

test "successful outdated packages using single-quotes with mock" do
npm = Importmap::Npm.new(file_fixture("single_quote_outdated_import_map.rb"))
response = { "dist-tags" => { "latest" => '2.3.0' } }.to_json

npm.stub(:get_json, response) do
outdated_packages = npm.outdated_packages

assert_equal(1, outdated_packages.size)
assert_equal('md5', outdated_packages[0].name)
assert_equal('2.2.0', outdated_packages[0].current_version)
assert_equal('2.3.0', outdated_packages[0].latest_version)
end
end

test "successful outdated packages using single-quotes and without CDN with mock" do
npm = Importmap::Npm.new(file_fixture("single_quote_outdated_import_map_without_cdn.rb"))
response = { "dist-tags" => { "latest" => '2.3.0' } }.to_json

npm.stub(:get_json, response) do
outdated_packages = npm.outdated_packages

assert_equal(1, outdated_packages.size)
assert_equal('md5', outdated_packages[0].name)
assert_equal('2.2.0', outdated_packages[0].current_version)
assert_equal('2.3.0', outdated_packages[0].latest_version)
end
end

test "missing outdated packages with mock" do
response = { "error" => "Not found" }.to_json

Expand Down

0 comments on commit 9fac238

Please sign in to comment.