mirror of
https://github.com/discourse/discourse.git
synced 2024-12-05 10:36:30 +08:00
61f6f53dab
When plugin spec is evaluated for the first time, it took 30 seconds to run: ``` rm -rf tmp/* && LOAD_PLUGINS=1 be rspec ./plugins/discourse-solved/spec/requests/topics_controller_spec.rb ``` Applying sprocket patch in test environment solves that issue
59 lines
1.8 KiB
Ruby
59 lines
1.8 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# This contains two patches to make sprockets more tolerable in dev
|
|
#
|
|
# 1. Stop computing asset paths which triggers sprockets to do mountains of work
|
|
# All our assets in dev are in the /assets folder anyway
|
|
#
|
|
# 2. Stop using a concatenator that does tons of work checking for semicolons when
|
|
# when rebuilding an asset
|
|
|
|
if Rails.env.development? || Rails.env.test?
|
|
module ActionView::Helpers::AssetUrlHelper
|
|
|
|
def asset_path(source, options = {})
|
|
source = source.to_s
|
|
return "" unless source.present?
|
|
return source if source =~ URI_REGEXP
|
|
|
|
tail, source = source[/([\?#].+)$/], source.sub(/([\?#].+)$/, '')
|
|
|
|
if extname = compute_asset_extname(source, options)
|
|
source = "#{source}#{extname}"
|
|
end
|
|
|
|
if source[0] != ?/
|
|
# CODE REMOVED
|
|
# source = compute_asset_path(source, options)
|
|
source = "/assets/#{source}"
|
|
end
|
|
|
|
relative_url_root = defined?(config.relative_url_root) && config.relative_url_root
|
|
if relative_url_root
|
|
source = File.join(relative_url_root, source) unless source.starts_with?("#{relative_url_root}/")
|
|
end
|
|
|
|
if host = compute_asset_host(source, options)
|
|
source = File.join(host, source)
|
|
end
|
|
|
|
"#{source}#{tail}"
|
|
end
|
|
alias_method :path_to_asset, :asset_path # aliased to avoid conflicts with an asset_path named route
|
|
end
|
|
|
|
module ::SprocketHack
|
|
def self.concat_javascript_sources(buf, source)
|
|
if buf.bytesize > 0
|
|
# CODE REMOVED HERE
|
|
buf << ";" # unless string_end_with_semicolon?(buf)
|
|
buf << "\n" # unless buf.end_with?("\n")
|
|
end
|
|
buf << source
|
|
end
|
|
end
|
|
|
|
Sprockets.register_bundle_metadata_reducer 'application/javascript', :data, proc { +"" }, ::SprocketHack.method(:concat_javascript_sources)
|
|
|
|
end
|