importmap-rails 0.2.3 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ec141d17e7859eac9dae9d91c47f04957f650f2cef7eeae7cc0449b9c92cd89
4
- data.tar.gz: a2ce05f0a9c340668d407f5c7e2cf64b2fe68f262e567ab94fb1ccc029b10487
3
+ metadata.gz: d76219ce916f51a755ec35408f60b5258cf63b8d8d5b5252ab04b351348cfebb
4
+ data.tar.gz: 9467508f9d692ce701ccf1943adf146b776be046e1eac06f60541209fe26ace7
5
5
  SHA512:
6
- metadata.gz: e692f3214ec9f899ebffd3f239a8f87202811b8098de1f2b2906bcb2558d446801a34fe359b3a94b8b8768220d54918f089ed8149ede3e04708d29f435314872
7
- data.tar.gz: 89eafbbd709cd3e9eb2e97310c96297465bb935b713e841c8b8f7c9dd4a7d4f59c05b0d5720f0d9087dfbcb3a7e86d17c6d89a6c061622c9b8e6387719707795
6
+ metadata.gz: c013fde57b613a62f6f228e6ceb5f106dbbe77af14d3737e2206bcdd38e78d1a8bbdf2c21d5e292b155b03ea6069918c4083c9f913595c925dc626d91286f1ca
7
+ data.tar.gz: dce28047300891ecdea4b5165dd99163066676fbf3145789ac094f74a2ef2aeb5f4f5a99d6b576da66ea70cb502ba3be61d8517e6ab9e0e8d62e40269d85f06d
@@ -2,8 +2,8 @@ module Importmap::ImportmapTagsHelper
2
2
  # Setup all script tags needed to use an importmap-powered entrypoint (which defaults to application.js)
3
3
  def javascript_importmap_tags(entry_point = "application")
4
4
  safe_join [
5
- javascript_importmap_module_preload_tags,
6
5
  javascript_inline_importmap_tag,
6
+ javascript_importmap_module_preload_tags,
7
7
  javascript_importmap_shim_tag,
8
8
  javascript_import_module_tag(entry_point)
9
9
  ], "\n"
data/lib/importmap/map.rb CHANGED
@@ -14,8 +14,8 @@ class Importmap::Map
14
14
  @files[name] = MappedFile.new(name: name, path: to || "#{name}.js", preload: preload)
15
15
  end
16
16
 
17
- def pin_all_from(path, under: nil, preload: true)
18
- @directories[path] = MappedDir.new(path: path, under: under, preload: preload)
17
+ def pin_all_from(dir, under: nil, to: nil, preload: true)
18
+ @directories[dir] = MappedDir.new(dir: dir, under: under, path: to, preload: preload)
19
19
  end
20
20
 
21
21
  def preloaded_module_paths(resolver:)
@@ -32,7 +32,7 @@ class Importmap::Map
32
32
 
33
33
  private
34
34
  MappedFile = Struct.new(:name, :path, :preload, keyword_init: true)
35
- MappedDir = Struct.new(:path, :under, :preload, keyword_init: true)
35
+ MappedDir = Struct.new(:dir, :path, :under, :preload, keyword_init: true)
36
36
 
37
37
  def cache_as(name)
38
38
  if (cached && result = instance_variable_get("@cached_#{name}"))
@@ -63,11 +63,11 @@ class Importmap::Map
63
63
 
64
64
  def expand_directories_into(paths)
65
65
  @directories.values.each do |mapping|
66
- if (absolute_path = absolute_root_of(mapping.path)).exist?
66
+ if (absolute_path = absolute_root_of(mapping.dir)).exist?
67
67
  find_javascript_files_in_tree(absolute_path).each do |filename|
68
68
  module_filename = filename.relative_path_from(absolute_path)
69
- module_name = module_name_from(module_filename, mapping.under)
70
- module_path = mapping.under ? absolute_path.basename.join(module_filename).to_s : module_filename.to_s
69
+ module_name = module_name_from(module_filename, mapping)
70
+ module_path = module_path_from(module_filename, mapping)
71
71
 
72
72
  paths[module_name] = MappedFile.new(name: module_name, path: module_path, preload: mapping.preload)
73
73
  end
@@ -75,18 +75,23 @@ class Importmap::Map
75
75
  end
76
76
  end
77
77
 
78
- # Strip off the extension, /index, or any versioning data for an absolute module name.
79
- def module_name_from(filename, under)
80
- filename_without_ext = filename.to_s.remove(filename.extname)
78
+ def module_name_from(filename, mapping)
79
+ filename_without_ext_and_version = filename.to_s.remove(filename.extname).split("@").first
81
80
 
82
- if filename_without_ext == "index" && under
83
- under
81
+ case
82
+ when filename_without_ext_and_version == "index" && mapping.under
83
+ mapping.under
84
+ when mapping.under
85
+ "#{mapping.under}/#{filename_without_ext_and_version}"
84
86
  else
85
- module_name = filename_without_ext.split("@").first
86
- under ? "#{under}/#{module_name}" : module_name
87
+ module_name
87
88
  end
88
89
  end
89
90
 
91
+ def module_path_from(filename, mapping)
92
+ [ mapping.path || mapping.under, filename.to_s ].join("/")
93
+ end
94
+
90
95
  def find_javascript_files_in_tree(path)
91
96
  Dir[path.join("**/*.js{,m}")].collect { |file| Pathname.new(file) }.select(&:file?)
92
97
  end
@@ -1,3 +1,3 @@
1
1
  module Importmap
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.7"
3
3
  end
@@ -18,7 +18,7 @@ JS
18
18
  end
19
19
 
20
20
  say "Ensure JavaScript files are in the asset pipeline manifest"
21
- append_to_file Rails.root.join("app/assets/config/manifest.js"), %(//= link_tree ../../../javascript .js\n)
21
+ append_to_file Rails.root.join("app/assets/config/manifest.js"), %(//= link_tree ../../javascript .js\n)
22
22
 
23
23
  say "Configure importmap paths in config/initializers/importmap.rb"
24
24
  create_file Rails.root.join("config/initializers/importmap.rb") do <<-RUBY
@@ -29,9 +29,9 @@ Rails.application.config.importmap.draw do
29
29
  # pin "@rails/actioncable", to: "actioncable.esm.js"
30
30
  # pin "@rails/activestorage", to: "activestorage.esm.js"
31
31
 
32
- # Use libraries directly from JavaScript CDNs (see https://www.skypack.dev, https://cdnjs.com, https://www.jsdelivr.com/esm)
33
- # pin "vue", to: "https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.esm.browser.js", preload: true
34
- # pin "d3", to: "https://cdn.skypack.dev/pin/d3@v7.0.0-03vFl9bie0TSesDkWTJV/mode=imports/optimized/d3.js", preload: true
32
+ # Use libraries directly from JavaScript CDNs (see https://www.skypack.dev, https://esm.sh, https://www.jsdelivr.com/esm)
33
+ # pin "vue", to: "https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.esm.browser.js"
34
+ # pin "d3", to: "https://esm.sh/d3?bundle"
35
35
 
36
36
  # Pin vendored modules by first adding the following to app/assets/config/manifest.js:
37
37
  # //= link_tree ../../../vendor/assets/javascripts .js
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: importmap-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-16 00:00:00.000000000 Z
11
+ date: 2021-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails