diff --git a/lib/importmap/npm.rb b/lib/importmap/npm.rb index 921ac41..b47f39e 100644 --- a/lib/importmap/npm.rb +++ b/lib/importmap/npm.rb @@ -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 diff --git a/test/fixtures/files/single_quote_outdated_import_map.rb b/test/fixtures/files/single_quote_outdated_import_map.rb new file mode 100644 index 0000000..fd9942d --- /dev/null +++ b/test/fixtures/files/single_quote_outdated_import_map.rb @@ -0,0 +1 @@ +pin 'md5', to: 'https://cdn.skypack.dev/md5@2.2.0', preload: true diff --git a/test/fixtures/files/single_quote_outdated_import_map_without_cdn.rb b/test/fixtures/files/single_quote_outdated_import_map_without_cdn.rb new file mode 100644 index 0000000..56b2092 --- /dev/null +++ b/test/fixtures/files/single_quote_outdated_import_map_without_cdn.rb @@ -0,0 +1 @@ +pin 'md5', preload: true #@2.2.0 diff --git a/test/npm_test.rb b/test/npm_test.rb index 4c2a956..fd6f122 100644 --- a/test/npm_test.rb +++ b/test/npm_test.rb @@ -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