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

Rails 5.1 Webpacker Cache Support #892

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a02e583
add additional caching helpers for node_modules, ~/.yarn-cache, and t…
kpheasey Jun 14, 2019
1019fcf
use new Rails51 language pack
kpheasey Jun 14, 2019
5b53b97
remove changes to Rails 5
kpheasey Jun 14, 2019
271dee9
add some console output
kpheasey Jun 14, 2019
13a4add
add some console output
kpheasey Jun 14, 2019
bb2563f
add some console output
kpheasey Jun 14, 2019
0346e34
remove max rails version restriction
kpheasey Jun 20, 2019
95fbfbe
Merge branch 'master' into feat/yarn-cache
kpheasey Jun 21, 2019
13fac68
Merge branch 'master' into feat/yarn-cache
kpheasey Jun 27, 2019
a9781db
remove WEBPACKER_PACKS_PATH from asset cache, assets:clean does not r…
kpheasey Jul 25, 2019
e4014c0
Revert "remove WEBPACKER_PACKS_PATH from asset cache, assets:clean do…
kpheasey Sep 17, 2019
0d7a365
Merge branch 'master' into feat/yarn-cache
kpheasey Sep 18, 2019
d96a1db
Rails6 inherits Rails51
kpheasey Sep 18, 2019
20009aa
require correct language pack
kpheasey Sep 18, 2019
23ed181
fix bad merge and use var to avoid run on array line
kpheasey Sep 18, 2019
0d4270c
Merge branch 'master' into feat/yarn-cache
kpheasey Oct 9, 2019
5f25c31
Merge branch 'master' into feat/yarn-cache
kpheasey Nov 14, 2019
1d21e46
split asset/cache paths into ASSET_PATHS and ASSET_CACHE_PATHS, the l…
kpheasey Nov 14, 2019
7447374
update changelog
kpheasey Nov 14, 2019
ca89ecb
Merge branch 'master' into feat/yarn-cache
kpheasey Jan 6, 2020
2674c9c
Merge branch 'master' into feat/yarn-cache
kpheasey Apr 29, 2020
6366ff1
Merge branch 'master' into feat/yarn-cache
kpheasey Jul 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

* Vendor in libpq 5.12.1 for Heroku-18 (https://github.com/heroku/heroku-buildpack-ruby/pull/936)
* Remove possibilities of false exceptions being raised by removing `BUNDLED WITH` from the `Gemfile.lock` (https://github.com/heroku/heroku-buildpack-ruby/pull/928)
* Add webpacker support for Rails >= 5.1 (https://github.com/heroku/heroku-buildpack-ruby/pull/892)

## v206 (10/15/2019)

Expand Down
17 changes: 16 additions & 1 deletion lib/language_pack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,21 @@ def self.detect(*args)
Instrument.instrument 'detect' do
Dir.chdir(args.first)

pack = [ NoLockfile, Rails6, Rails5, Rails42, Rails41, Rails4, Rails3, Rails2, Rack, Ruby ].detect do |klass|
packs = [
NoLockfile,
Rails6,
Rails51,
Rails5,
Rails42,
Rails41,
Rails4,
Rails3,
Rails2,
Rack,
Ruby
]

pack = packs.detect do |klass|
klass.use?
end

Expand Down Expand Up @@ -49,5 +63,6 @@ def self.detect(*args)
require "language_pack/rails41"
require "language_pack/rails42"
require "language_pack/rails5"
require "language_pack/rails51"
require "language_pack/rails6"
require "language_pack/no_lockfile"
93 changes: 93 additions & 0 deletions lib/language_pack/rails51.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
require 'securerandom'
require 'language_pack'
require 'language_pack/rails5'

class LanguagePack::Rails51 < LanguagePack::Rails5
ASSET_PATHS = %w[
public/packs
~/.yarn-cache
~/.cache/yarn
]

ASSET_CACHE_PATHS = %w[
node_modules
tmp/cache/webpacker
]

# @return [Boolean] true if it's a Rails 5.1.x app
def self.use?
instrument "rails51.use" do
rails_version = bundler.gem_version('railties')
return false unless rails_version
is_rails = rails_version >= Gem::Version.new('5.1.x')
return is_rails
end
end

private

def run_assets_precompile_rake_task
instrument "rails51.run_assets_precompile_rake_task" do
log("assets_precompile") do
if Dir.glob("public/assets/{.sprockets-manifest-*.json,manifest-*.json}", File::FNM_DOTMATCH).any?
puts "Detected manifest file, assuming assets were compiled locally"
return true
end

precompile = rake.task("assets:precompile")
return true unless precompile.is_defined?

topic("Preparing app for Rails asset pipeline")

load_asset_cache

precompile.invoke(env: rake_env)

if precompile.success?
log "assets_precompile", :status => "success"
puts "Asset precompilation completed (#{"%.2f" % precompile.time}s)"

puts "Cleaning assets"
rake.task("assets:clean").invoke(env: rake_env)

cleanup_assets_cache
store_asset_cache
else
precompile_fail(precompile.output)
end
end
end
end

def load_asset_cache
puts "Loading asset cache"
@cache.load_without_overwrite public_assets_folder
@cache.load default_assets_cache

paths = (self.class::ASSET_PATHS + self.class::ASSET_CACHE_PATHS)
paths.each { |path| @cache.load path }
end

def store_asset_cache
puts "Storing asset cache"
@cache.store public_assets_folder
@cache.store default_assets_cache

paths = (self.class::ASSET_PATHS + self.class::ASSET_CACHE_PATHS)
paths.each { |path| @cache.store path }
end

def cleanup
# does not call super because it would return if default_assets_cache was missing
# child classes should call super and should not use a return statement
return if assets_compile_enabled?

puts "Removing non-essential asset cache directories"

FileUtils.remove_dir(default_assets_cache) if Dir.exist?(default_assets_cache)

self.class::ASSET_CACHE_PATHS.each do |path|
FileUtils.remove_dir(path) if Dir.exist?(path)
end
end
end
4 changes: 2 additions & 2 deletions lib/language_pack/rails6.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'securerandom'
require "language_pack"
require "language_pack/rails5"
require "language_pack/rails51"

class LanguagePack::Rails6 < LanguagePack::Rails5
class LanguagePack::Rails6 < LanguagePack::Rails51
# @return [Boolean] true if it's a Rails 6.x app
def self.use?
instrument "rails6.use" do
Expand Down