Skip to content

Commit f80d0a3

Browse files
authored
Merge pull request #192 from jsntv200/fix/module_path_from
Remove prepended forward slash when mapping.path is empty
2 parents fa34a62 + 4b6a838 commit f80d0a3

File tree

6 files changed

+9
-1
lines changed

6 files changed

+9
-1
lines changed

Diff for: lib/importmap/map.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def module_name_from(filename, mapping)
145145
end
146146

147147
def module_path_from(filename, mapping)
148-
[ mapping.path || mapping.under, filename.to_s ].compact.join("/")
148+
[ mapping.path || mapping.under, filename.to_s ].compact.reject(&:empty?).join("/")
149149
end
150150

151151
def find_javascript_files_in_tree(path)

Diff for: test/dummy/app/assets/config/manifest.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//= link_tree ../images
22
//= link_directory ../stylesheets .css
33
//= link_tree ../../javascript .js
4+
//= link_tree ../../components .js
45
//= link_tree ../../../lib/assets/javascripts .js

Diff for: test/dummy/app/components/another_component_controller.js

Whitespace-only changes.

Diff for: test/dummy/app/components/spina/component_controller.js

Whitespace-only changes.

Diff for: test/dummy/config/initializers/assets.rb

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
# Add additional assets to the asset load path.
77
# Rails.application.config.assets.paths << Emoji.images_path
8+
Rails.application.config.assets.paths << Rails.root.join("app/components")
89

910
# Precompile additional assets.
1011
# application.js, application.css, and all non-JS/CSS in the app/assets

Diff for: test/importmap_test.rb

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def setup
1414
pin_all_from "app/javascript/spina/controllers", under: "controllers/spina", to: "spina/controllers", preload: true
1515
pin_all_from "app/javascript/helpers", under: "helpers", preload: true
1616
pin_all_from "lib/assets/javascripts", preload: true
17+
pin_all_from "app/components", under: "controllers", to: "", preload: true
1718
end
1819
end
1920
end
@@ -52,6 +53,11 @@ def setup
5253
assert_match %r|assets/spina/controllers/deeper/again_controller-.*\.js|, generate_importmap_json["imports"]["controllers/spina/deeper/again_controller"]
5354
end
5455

56+
test "directory pin under custom asset path with empty to" do
57+
assert_match %r|assets/spina/component_controller-.*\.js|, generate_importmap_json["imports"]["controllers/spina/component_controller"]
58+
assert_match %r|assets/another_component_controller-.*\.js|, generate_importmap_json["imports"]["controllers/another_component_controller"]
59+
end
60+
5561
test "directory pin without path or under" do
5662
assert_match %r|assets/my_lib-.*\.js|, generate_importmap_json["imports"]["my_lib"]
5763
end

0 commit comments

Comments
 (0)