Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove prepended forward slash when mapping.path is empty #192

Merged
merged 3 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/importmap/map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions test/dummy/app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -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
Empty file.
Empty file.
1 change: 1 addition & 0 deletions test/dummy/config/initializers/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions test/importmap_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down