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 #447

Merged
merged 4 commits into from Jun 23, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/mini_profiler_rails/railtie.rb
Expand Up @@ -30,6 +30,8 @@ def self.initialize!(app)

if serves_static_assets?(app)
c.skip_paths << app.config.assets.prefix
wp_assets_path = get_webpacker_assets_path()
c.skip_paths << wp_assets_path if wp_assets_path
end

unless Rails.env.development? || Rails.env.test?
Expand Down
6 changes: 6 additions & 0 deletions lib/mini_profiler_rails/railtie_methods.rb
Expand Up @@ -51,5 +51,11 @@ def should_move?(child, node)
child[start] + child[duration] <= node[start] + node[duration]
end

def get_webpacker_assets_path
if defined?(Webpacker)
Webpacker.config.public_output_path.to_s.gsub(Webpacker.config.public_path.to_s, "")
end
end

extend self
end
3 changes: 2 additions & 1 deletion rack-mini-profiler.gemspec
Expand Up @@ -30,7 +30,6 @@ Gem::Specification.new do |s|

s.add_development_dependency 'rake', '< 11'
s.add_development_dependency 'rack-test'
s.add_development_dependency 'activerecord', '~> 3.0'
s.add_development_dependency 'dalli'
s.add_development_dependency 'rspec', '~> 3.6.0'
s.add_development_dependency 'redis'
Expand All @@ -41,6 +40,8 @@ Gem::Specification.new do |s|
s.add_development_dependency 'nokogiri'
s.add_development_dependency 'rubocop-discourse'
s.add_development_dependency 'listen'
s.add_development_dependency 'webpacker', '~> 5.1'
s.add_development_dependency 'rails', '~> 5.1'

s.require_paths = ["lib"]
end
2 changes: 2 additions & 0 deletions spec/fixtures/webpacker.yml
@@ -0,0 +1,2 @@
development:
public_output_path: some/assets/path
15 changes: 15 additions & 0 deletions spec/integration/railtie_methods_spec.rb
Expand Up @@ -178,4 +178,19 @@ def to_seconds(array)
expect(@current_timer[cts]).to eq({})
end
end

it '#get_webpacker_assets_path returns webpacker public_output_path if webpacker exists' do
expect(described_class.get_webpacker_assets_path()).to eq(nil)
require 'rails'
require 'webpacker'
tmp_path = Pathname.new("/tmp/rails_root_#{SecureRandom.hex}")
FileUtils.mkdir(tmp_path)
Webpacker.instance = Webpacker::Instance.new(
root_path: tmp_path,
config_path: Pathname.new(File.expand_path("../fixtures/webpacker.yml", __dir__))
)
expect(described_class.get_webpacker_assets_path()).to eq("/some/assets/path")
ensure
FileUtils.rm_rf(tmp_path)
end
end