Skip to content

Commit

Permalink
Update packager#vendored_pin_for
Browse files Browse the repository at this point in the history
The method now preserves the pin option if it is present.
  • Loading branch information
vietqhoang committed Oct 24, 2024
1 parent 41de67a commit 3eaf7a1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/importmap/packager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ def pin_for(package, url)
def vendored_pin_for(package, url)
filename = package_filename(package)
version = extract_package_version_from(url)

if "#{package}.js" == filename
%(pin "#{package}" # #{version})
else
%(pin "#{package}", to: "#{filename}" # #{version})
end
line_formatted_pin_options = pin_options_for_package(package).except("to").map { |option, value| %(#{option}: #{value.is_a?(String) ? %("#{value}") : value}) }
pin_components = [
%(pin "#{package}"),
(%(to: "#{filename}") unless "#{package}.js" == filename),
*line_formatted_pin_options
].compact

%(#{pin_components.join(", ")} # #{version})
end

def packaged?(package)
Expand Down
1 change: 1 addition & 0 deletions test/packager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def code() "200" end
test "vendored_pin_for" do
assert_equal %(pin "react" # @17.0.2), @packager.vendored_pin_for("react", "https://cdn/react@17.0.2")
assert_equal %(pin "javascript/react", to: "javascript--react.js" # @17.0.2), @packager.vendored_pin_for("javascript/react", "https://cdn/react@17.0.2")
assert_equal %(pin "md5", preload: true # @2.1.3), @packager.vendored_pin_for("md5", "https://cdn/md5@2.1.3")
end

test "pin_options_for_package" do
Expand Down

0 comments on commit 3eaf7a1

Please # to comment.