Permalink
Browse files

Don't compile nondigest assets in separate process

Before this patch rake task for compiling assets was running separate
process to compile nondigest assets, instead of just invoking the task
in the same process. In order to make it work without having 2 processes
we need to clear sprockets cache, which is impossible with
`Sprockets::Index` - it's immutable. That's why I'm making a copy of
`Environment` before converting it to index, to be able to clear the
cache and use it for nondigest version. It's a bit hacky, but since
`Index` just references most of the things in `Environment` it should
work just fine.
  • Loading branch information...
1 parent fa8a2bc commit 5dea208e64fbf9fabd0f132b4e1a2e255c2e2211 @drogus committed May 12, 2012
Showing with 14 additions and 7 deletions.
  1. +3 −0 lib/sprockets/rails/bootstrap.rb
  2. +11 −7 lib/tasks/assets.rake
@@ -1,6 +1,8 @@
module Sprockets
module Rails
class Bootstrap
+ cattr_accessor :original_assets
+
def initialize(app)
@app = app
end
@@ -33,6 +35,7 @@ def run
end
if config.assets.digest
+ self.class.original_assets = app.assets
app.assets = app.assets.index
end
end
View
@@ -45,7 +45,16 @@ namespace :assets do
config.assets.digest = digest unless digest.nil?
config.assets.digests = {}
- env = ::Rails.application.assets
+ original_assets = Sprockets::Rails::Bootstrap.original_assets
+ env = if !config.assets.digest && original_assets
+ original_assets.cache.clear
+ # Expire index
+ original_assets.version = original_assets.version
+ original_assets
+ else
+ Rails.application.assets
+ end
+
target = File.join(::Rails.public_path, config.assets.prefix)
compiler = Sprockets::Rails::StaticCompiler.new(env,
target,
@@ -58,12 +67,7 @@ namespace :assets do
task :all do
Rake::Task["assets:precompile:primary"].invoke
- # We need to reinvoke in order to run the secondary digestless
- # asset compilation run - a fresh Sprockets environment is
- # required in order to compile digestless assets as the
- # environment has already cached the assets on the primary
- # run.
- ruby_rake_task("assets:precompile:nondigest", false) if ::Rails.application.config.assets.digest
+ Rake::Task["assets:precompile:nondigest"].invoke if ::Rails.application.config.assets.digest
end
task :primary => ["assets:cache:clean"] do

0 comments on commit 5dea208

Please sign in to comment.