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

Skip "/packs" when serving static assets #436

Closed
wants to merge 0 commits into from

Conversation

ivopt
Copy link
Contributor

@ivopt ivopt commented Mar 12, 2020

When using webpacker, assets are under /packs but the app.config.assets.prefix still points to /assets (because it still exists anyway).

With this we'd stop profiling whatever we'd be serving under /packs when serving static assets.

@nateberkopec ☝️

@codecov-io
Copy link

codecov-io commented Mar 12, 2020

Codecov Report

Merging #436 into master will decrease coverage by 0.05%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #436      +/-   ##
==========================================
- Coverage   88.53%   88.48%   -0.06%     
==========================================
  Files          22       22              
  Lines        1335     1337       +2     
==========================================
+ Hits         1182     1183       +1     
- Misses        153      154       +1     
Impacted Files Coverage Δ
lib/patches/net_patches.rb 62.50% <0.00%> (-4.17%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3cb877b...06da75c. Read the comment docs.

@@ -30,6 +30,7 @@ def self.initialize!(app)

if serves_static_assets?(app)
c.skip_paths << app.config.assets.prefix
c.skip_paths << "/packs"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a rather silly solution for the problem..
A better solution here would be to find out if the app is using webpacker or not and add this if yes.

Probably, and hopefully, there is something within webpacker that would give me that "/packs" path without me needing to hardcode here...

HELP!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would if defined?(Webpacker) work?

Copy link
Contributor Author

@ivopt ivopt Mar 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would help indeed.

A simple solution with that could be:

c.skip_paths << "/packs" if defined?(Webpacker)

Problem is: You can tell Webpacker to put those anywhere else, like this:

image

Webpacker allows me to get that path with:

Webpacker.config.public_output_path # => #<Pathname:/app/public/packs/like/this>

So, I am thinking this needs to be a bit smarter and this is where I start to find my solution ugly:

if defined?(Webpacker)
  public_packs_folder = 
    Webpacker.config.public_output_path.to_s.gsub!("#{app.config.root}/public", "")
  c.skip_paths << public_packs_folder
end

Is there a cleaner way to do that "substring"?


EDIT:

if defined?(Webpacker)
  public_packs_folder = 
    Webpacker.config.public_output_path.to_s.gsub!(Webpacker.config.public_path.to_s, "")
  c.skip_paths << public_packs_folder
end

@ivopt ivopt marked this pull request as ready for review March 12, 2020 18:16
@SamSaffron
Copy link
Member

I totally support this, but there is an element of fragility, can we add webpacker to the test suite and have a test to confirm this indeed continues to work?

@nateberkopec
Copy link
Collaborator

Probably would just need to add/require Webpacker and set those methods correctly.

@ivopt
Copy link
Contributor Author

ivopt commented Mar 16, 2020

I'm a bit unsure how to add Webpacker to this..

I can't see any other tests being made to the railtie code itself, am I missing something?

@OsamaSayegh
Copy link
Collaborator

@LynxEyes testing a Railtie/initializer directly is very tricky if not impossible, but what you can do is extract your code into a small method, put it in railtie_methods.rb and simply call the method in our Railtie. Then in railtie_methods_spec.rb you can call your method as many times as you want and do your tests. You can see b15fe68 for an example.

Adding Webpacker should be as simple as adding it to the gemspec file as a development dependency, but there may be some hidden complexities 🐉 😄

If you want, I can pick this up and try to bring it over the finish line.

@ivopt
Copy link
Contributor Author

ivopt commented Jun 12, 2020

@OsamaSayegh if you have a solid idea of how to finish this, then yes, I fully accept the help! Otherwise I'll follow your tip and try to improve this.

@OsamaSayegh
Copy link
Collaborator

Lol, I updated your branch to latest and github closed the PR 😆 I'm working on it.

@OsamaSayegh
Copy link
Collaborator

Actually it looks like I pushed my local master to your fork's master, which essentially undid your commits and github closed the PR because your fork became identical and I don't think I have push permissions anymore because the PR is closed 🤦‍♂️ Silly me, sorry about that!

Anyway, I created a new PR #447 with your changes and a test case on top. Will leave to @SamSaffron to do the final review. Thank you for your work here @LynxEyes and sorry for my mess.

@ivopt
Copy link
Contributor Author

ivopt commented Jun 12, 2020

Lolol. Let that who hasn't messed up a few git merges cast the first stone.
Cool, and thank you for adding the test, I'll take it as reference for future commits I may end up making 🤗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants