diff --git a/lib/importmap/packager.rb b/lib/importmap/packager.rb index ba572ea..76f0661 100644 --- a/lib/importmap/packager.rb +++ b/lib/importmap/packager.rb @@ -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 @@ -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 @@ -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