Skip to content

Commit 34f47d5

Browse files
make multiline importmap definitions work with importmap outdated for instance
i had a package that kept being marked as outdated and thus my ci was failing
1 parent 0a63301 commit 34f47d5

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

lib/importmap/npm.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ def packages_with_versions
4848
# We cannot use the name after "pin" because some dependencies are loaded from inside packages
4949
# Eg. pin "buffer", to: "https://ga.jspm.io/npm:@jspm/[email protected]/nodelibs/browser/buffer.js"
5050

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

5555
private
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ipin "intl-tel-input/build/js/utils.js",
2+
to: "intl-tel-input--build--js--utils.js.js" # @23.5.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ipin "intl-tel-input/build/js/utils.js",
2+
to: "intl-tel-input--build--js--utils.js.js" # @23.3.2

test/npm_test.rb

+24
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,30 @@ class Importmap::NpmTest < ActiveSupport::TestCase
4646
end
4747
end
4848

49+
test "successful outdated packages using multiple lines" do
50+
npm = Importmap::Npm.new(file_fixture("multiline_outdated_import_map.rb"))
51+
response = { "dist-tags" => { "latest" => '23.5.0' } }.to_json
52+
53+
npm.stub(:get_json, response) do
54+
outdated_packages = npm.outdated_packages
55+
56+
assert_equal(1, outdated_packages.size)
57+
assert_equal('intl-tel-input/build/js/utils.js', outdated_packages[0].name)
58+
assert_equal('23.3.2', outdated_packages[0].current_version)
59+
assert_equal('23.5.0', outdated_packages[0].latest_version)
60+
end
61+
end
62+
63+
test "successful updarted packages using multiple lines" do
64+
npm = Importmap::Npm.new(file_fixture("multiline_updated_import_map.rb"))
65+
response = { "dist-tags" => { "latest" => '23.5.0' } }.to_json
66+
67+
npm.stub(:get_json, response) do
68+
outdated_packages = npm.outdated_packages
69+
assert_equal(0, outdated_packages.size)
70+
end
71+
end
72+
4973
test "missing outdated packages with mock" do
5074
response = { "error" => "Not found" }.to_json
5175

0 commit comments

Comments
 (0)