Skip to content

Commit

Permalink
Add .io when passing jspm as provider (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
josefarias authored Jan 23, 2024
1 parent 699a9bb commit ddf9be4
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/importmap/packager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ def initialize(importmap_path = "config/importmap.rb", vendor_path: "vendor/java

def import(*packages, env: "production", from: "jspm")
response = post_json({
"install" => Array(packages),
"install" => Array(packages),
"flattenScope" => true,
"env" => [ "browser", "module", env ],
"provider" => from.to_s,
"provider" => normalize_provider(from)
})

case response.code
Expand Down Expand Up @@ -69,6 +69,10 @@ def post_json(body)
raise HTTPError, "Unexpected transport error (#{error.class}: #{error.message})"
end

def normalize_provider(name)
name.to_s == "jspm" ? "jspm.io" : name.to_s
end

def extract_parsed_imports(response)
JSON.parse(response.body).dig("map", "imports")
end
Expand All @@ -80,7 +84,7 @@ def handle_failure_response(response)
raise HTTPError, "Unexpected response code (#{response.code})"
end
end

def parse_service_error(response)
JSON.parse(response.body.to_s)["error"]
rescue JSON::ParserError
Expand Down

0 comments on commit ddf9be4

Please sign in to comment.