-
Notifications
You must be signed in to change notification settings - Fork 149
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
Upgrade rake assets:precompile
to update js-routes
files in Rakefile did not work for me
#305
Comments
We can change it like that, but I would want to know exactly why it doesn't work for you and does work for everyone else. Can you debug it? |
Sorry, I still ran into the same problem with The problem is when I don't have
After I run |
I believe that for some reason the files that use Can you try a new rails application if it has the same problem for you and let me know what kind of custom configuration you are using? That might be linters, typescript tools or something else. |
Hi @tae8838 From where does this message come from? (webpacker?, rails assets:precompile?, when deploying?) I'm using esbuild, and in my case I have to guarantee that I'm hooking into your issue because I'm trying to configure everything to work well in development, test and production. I guess that I'll be probably relying on configuring everything externally without the middleware. |
I've just read that |
It seems jsbundling also doesn't try to guarantee any kind of running sequence. It just hooks normally. |
HI @tae8838, I think I was able to reproduce your scenario.
So, if I:
It gives me:
But if I:
It works ok. That's because esbuild throws an error when one of my js files tries to import routes.js and it is not there yet (because Dear @bogdan, I think I can try to open a PR for it so we can discuss the code. |
Could you test this? It worked for me. # lib/tasks/js_routes.rake
# If javascript:build defined, hook into it and everything is fine.
# It will run before it in assets:precompile and in test:prepare
if Rake::Task.task_defined?("javascript:build")
Rake::Task["javascript:build"].enhance(["js:routes:typescript"])
else
Rake::Task["assets:precompile"].enhance(["js:routes:typescript"]) if Rake::Task.task_defined?("assets:precompile")
Rake::Task["test:prepare"].enhance(["js:routes:typescript"]) if Rake::Task.task_defined?("test:prepare")
Rake::Task["spec:prepare"].enhance(["js:routes:typescript"]) if Rake::Task.task_defined?("spec:prepare")
Rake::Task["db:test:prepare"].enhance(["js:routes:typescript"]) if Rake::Task.task_defined?("db:test:prepare")
end |
@abinoam great job on investigating this. Can you clarify where I am also not sure why would we need to generate js-routes on Last but not least: I would also check if |
I'm at the cell phone now. Later I can crafter a more long answer. But, the short answer is And, at its source code I can see how it hooks. https://github.com/rails/jsbundling-rails/blob/main/lib/tasks/jsbundling/build.rake Although it may exist, Im not aware of another javascript:build task injected by a different gem. I need more time to be sure if this would be the "optimal" and more compatible way of doing that. Let's keep discussing more about it until we figure the vest way of doing that so we can update the Readme (as I think we won't need to change js-routes source code) |
In my setup
You're right about it. But I just included it because
This will make the code more resilient. I found the way to do it ( Looking at For The And... perhaps we should fix only the documentation of js-routes (the Readme part where it suggests the js_routes.rake). # lib/tasks/js_routes.rake
# frozen_string_literal: true
# See discussion at https://github.com/railsware/js-routes/issues/305
# If javascript:build is defined, hook into it and everything is fine.
# If not, hook into assets:precompile.
if Rake::Task["assets:precompile"].prerequisites.include?("javascript:build")
Rake::Task["javascript:build"].enhance(["js:routes:typescript"])
else
Rake::Task["assets:precompile"].enhance(["js:routes:typescript"])
end
if Rake::Task.task_defined?("test:prepare") && Rake::Task["test:prepare"].prerequisites.exclude?("javascript:build")
Rake::Task["test:prepare"].enhance(["js:routes:typescript"])
end
if Rake::Task.task_defined?("spec:prepare") && Rake::Task["spec:prepare"].prerequisites.exclude?("javascript:build")
Rake::Task["spec:prepare"].enhance(["js:routes:typescript"])
end
if Rake::Task.task_defined?("db:test:prepare") && Rake::Task["db:test:prepare"].prerequisites.exclude?("javascript:build")
Rake::Task["db:test:prepare"].enhance(["js:routes:typescript"])
end |
I think it is better to keep user level control over assets building process and tasks. Making it a blackbox may cause problems in custom assets building processes. For example, legacy apps with sprockets or when the harddrive is readonly for some reason.
On the |
Whenever jsbundling-rails is used, it is better to extend javascript:build instead of assets:precompile. See #305.
Released 2.2.6 with updated readme and generator. Thanks for help, @abinoam |
wasn't working for me. I had to do
Rake::Task["assets:precompile"].enhance(["js:routes:typescript"])
instead.The text was updated successfully, but these errors were encountered: