Skip to content

Commit

Permalink
make multiline importmap definitions work with importmap outdated f…
Browse files Browse the repository at this point in the history
…or instance

i had a package that kept being marked as outdated and thus my ci was failing
  • Loading branch information
dorianmariecom committed Jul 19, 2024
1 parent 0a63301 commit 34f47d5
Show file tree
Hide file tree
Showing 4 changed files with 30 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["']]*)).*/m) |
importmap.scan(/pin ["']([^["']]*)["'].* #.*@(\d+\.\d+\.\d+(?:[^\s]*)).*/m)
end

private
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/files/multiline_outdated_import_map.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ipin "intl-tel-input/build/js/utils.js",
to: "intl-tel-input--build--js--utils.js.js" # @23.5.0
2 changes: 2 additions & 0 deletions test/fixtures/files/multiline_updated_import_map.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ipin "intl-tel-input/build/js/utils.js",
to: "intl-tel-input--build--js--utils.js.js" # @23.3.2
24 changes: 24 additions & 0 deletions test/npm_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,30 @@ class Importmap::NpmTest < ActiveSupport::TestCase
end
end

test "successful outdated packages using multiple lines" do
npm = Importmap::Npm.new(file_fixture("multiline_outdated_import_map.rb"))
response = { "dist-tags" => { "latest" => '23.5.0' } }.to_json

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

assert_equal(1, outdated_packages.size)
assert_equal('intl-tel-input/build/js/utils.js', outdated_packages[0].name)
assert_equal('23.3.2', outdated_packages[0].current_version)
assert_equal('23.5.0', outdated_packages[0].latest_version)
end
end

test "successful updarted packages using multiple lines" do
npm = Importmap::Npm.new(file_fixture("multiline_updated_import_map.rb"))
response = { "dist-tags" => { "latest" => '23.5.0' } }.to_json

npm.stub(:get_json, response) do
outdated_packages = npm.outdated_packages
assert_equal(0, outdated_packages.size)
end
end

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

Expand Down

0 comments on commit 34f47d5

Please sign in to comment.