Skip to content

Update default provider to use jspm.io instead of jspm #234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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