importmap-rails 0.4.3 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,32 +0,0 @@
1
- require "httparty"
2
-
3
- class Importmap::Pinner
4
- include HTTParty
5
- base_uri "https://api.jspm.io"
6
-
7
- def pin(*packages, env: "production", from: "jspm")
8
- fetch_imports(*packages, env: env, provider: from)&.tap do |imports|
9
- imports.each do |package, url|
10
- append_to_importmap package, url
11
- end
12
- end
13
- end
14
-
15
- private
16
- def append_to_importmap(package, url)
17
- Rails.root.join("config/importmap.rb").open("a") do |config|
18
- config.puts %(pin "#{package}", to: "#{url}")
19
- end
20
- end
21
-
22
- def fetch_imports(*packages, env:, provider:)
23
- response = self.class.post("/generate", body: {
24
- "install" => Array(packages),
25
- "flattenScope" => true,
26
- "env" => [ "browser", "module", env ],
27
- "provider" => provider.to_s
28
- }.to_json)
29
-
30
- response.dig("map", "imports")
31
- end
32
- end