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 +4 -4
- data/app/helpers/importmap/importmap_tags_helper.rb +1 -1
- data/lib/importmap/map.rb +18 -13
- data/lib/importmap/version.rb +1 -1
- data/lib/install/install.rb +4 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d76219ce916f51a755ec35408f60b5258cf63b8d8d5b5252ab04b351348cfebb
|
4
|
+
data.tar.gz: 9467508f9d692ce701ccf1943adf146b776be046e1eac06f60541209fe26ace7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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(
|
18
|
-
@directories[
|
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.
|
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
|
70
|
-
module_path =
|
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
|
-
|
79
|
-
|
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
|
-
|
83
|
-
|
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
|
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
|
data/lib/importmap/version.rb
CHANGED
data/lib/install/install.rb
CHANGED
@@ -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
|
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://
|
33
|
-
# pin "vue", to: "https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.esm.browser.js"
|
34
|
-
# pin "d3", to: "https://
|
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.
|
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-
|
11
|
+
date: 2021-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|