diff --git a/lib/importmap/map.rb b/lib/importmap/map.rb index ac0885e..3ef8107 100644 --- a/lib/importmap/map.rb +++ b/lib/importmap/map.rb @@ -145,7 +145,7 @@ def module_name_from(filename, mapping) end def module_path_from(filename, mapping) - [ mapping.path || mapping.under, filename.to_s ].compact.join("/") + [ mapping.path || mapping.under, filename.to_s ].compact.reject(&:empty?).join("/") end def find_javascript_files_in_tree(path) diff --git a/test/dummy/app/assets/config/manifest.js b/test/dummy/app/assets/config/manifest.js index 0c7d56d..c86e0e2 100644 --- a/test/dummy/app/assets/config/manifest.js +++ b/test/dummy/app/assets/config/manifest.js @@ -1,4 +1,5 @@ //= link_tree ../images //= link_directory ../stylesheets .css //= link_tree ../../javascript .js +//= link_tree ../../components .js //= link_tree ../../../lib/assets/javascripts .js diff --git a/test/dummy/app/components/another_component_controller.js b/test/dummy/app/components/another_component_controller.js new file mode 100644 index 0000000..e69de29 diff --git a/test/dummy/app/components/spina/component_controller.js b/test/dummy/app/components/spina/component_controller.js new file mode 100644 index 0000000..e69de29 diff --git a/test/dummy/config/initializers/assets.rb b/test/dummy/config/initializers/assets.rb index fe48fc3..969a5d8 100644 --- a/test/dummy/config/initializers/assets.rb +++ b/test/dummy/config/initializers/assets.rb @@ -5,6 +5,7 @@ # Add additional assets to the asset load path. # Rails.application.config.assets.paths << Emoji.images_path +Rails.application.config.assets.paths << Rails.root.join("app/components") # Precompile additional assets. # application.js, application.css, and all non-JS/CSS in the app/assets diff --git a/test/importmap_test.rb b/test/importmap_test.rb index 1bb1c94..fb51dab 100644 --- a/test/importmap_test.rb +++ b/test/importmap_test.rb @@ -14,6 +14,7 @@ def setup pin_all_from "app/javascript/spina/controllers", under: "controllers/spina", to: "spina/controllers", preload: true pin_all_from "app/javascript/helpers", under: "helpers", preload: true pin_all_from "lib/assets/javascripts", preload: true + pin_all_from "app/components", under: "controllers", to: "", preload: true end end end @@ -52,6 +53,11 @@ def setup assert_match %r|assets/spina/controllers/deeper/again_controller-.*\.js|, generate_importmap_json["imports"]["controllers/spina/deeper/again_controller"] end + test "directory pin under custom asset path with empty to" do + assert_match %r|assets/spina/component_controller-.*\.js|, generate_importmap_json["imports"]["controllers/spina/component_controller"] + assert_match %r|assets/another_component_controller-.*\.js|, generate_importmap_json["imports"]["controllers/another_component_controller"] + end + test "directory pin without path or under" do assert_match %r|assets/my_lib-.*\.js|, generate_importmap_json["imports"]["my_lib"] end