-
Notifications
You must be signed in to change notification settings - Fork 120
Description
Great job on this gem! I was testing the pin and pin_all_from methods and was looking into how they generate the Import Map. The way pin works is we specify the "name under which we want a file inside JS modules to be referred as" as the first parameter, and the :to option accepts the "file inside public/assets which the name will resolve to". That is:
# config/importmap.rb
pin "foobar", to: "foobar.js"generates:
{
"foobar": "/assets/foobar-06d932.js"
}This same convention might not be followed for pin_all_from, since the first parameter accepts the "path to the folder (excluding the app/javascript part) inside public/assets that we want to resolve", and :under option accepts the "name(s) under which we want all those files to be accessed as". That is:
# config/importmap.rb
pin_all_from "app/javascript/controllers", under: "controllers"generates:
{
"controllers/hello_controller": "/assets/controllers/hello_controller-074c78.js",
"controllers": "/assets/controllers/index-9f08c7.js"
}Also, in the pin_all_from's case, we have to specify the file path relative to the project's root, whereas in the case of pin, it auto-resolves.
I feel that there's an ideal difference between pin_all_from and pin. The arguments to pin rely on app/assets/config/manifest.js to make sure that the processed files are put properly inside the public/assets folder. But the arguments to pin_all_from feel like they care about the folder/files themselves and don't rely on the manifest file.
This might not be an issue as such and that I'm assuming/understanding things incorrectly. So please feel free to disagree with an explanation of where I might be wrong. Cause that would be helpful if someone else has the same doubts.