From ddf9be434e0aca1103eabafe6d34b0e8a5064057 Mon Sep 17 00:00:00 2001 From: Jose Farias <31393016+josefarias@users.noreply.github.com> Date: Tue, 23 Jan 2024 11:37:47 -0600 Subject: [PATCH] Add `.io` when passing `jspm` as provider (#234) --- lib/importmap/packager.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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