diff --git a/.travis.yml b/.travis.yml index 019df864f..59f894770 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ sudo: required language: ruby rvm: - - 2.2.4 + - 2.3.1 services: - docker diff --git a/app/helpers/react_on_rails_helper.rb b/app/helpers/react_on_rails_helper.rb index ba48c3c7b..9ebb15dca 100644 --- a/app/helpers/react_on_rails_helper.rb +++ b/app/helpers/react_on_rails_helper.rb @@ -4,6 +4,7 @@ # 1. The white spacing in this file matters! # 2. Keep all #{some_var} fully to the left so that all indentation is done evenly in that var require "react_on_rails/prerender_error" +require "addressable/uri" module ReactOnRailsHelper # The env_javascript_include_tag and env_stylesheet_link_tag support the usage of a webpack diff --git a/lib/react_on_rails/test_helper.rb b/lib/react_on_rails/test_helper.rb index d831750ec..1fcb50b17 100644 --- a/lib/react_on_rails/test_helper.rb +++ b/lib/react_on_rails/test_helper.rb @@ -64,8 +64,7 @@ def self.ensure_assets_compiled(webpack_assets_status_checker: nil, webpack_assets_status_checker ||= WebpackAssetsStatusChecker.new(client_dir: client_dir, generated_assets_dir: generated_assets_dir, - webpack_generated_files: webpack_generated_files - ) + webpack_generated_files: webpack_generated_files) unless @printed_once puts diff --git a/lib/react_on_rails/test_helper/ensure_assets_compiled.rb b/lib/react_on_rails/test_helper/ensure_assets_compiled.rb index 80c97cc8f..187fac313 100644 --- a/lib/react_on_rails/test_helper/ensure_assets_compiled.rb +++ b/lib/react_on_rails/test_helper/ensure_assets_compiled.rb @@ -35,7 +35,7 @@ def call # Inform the developer that we're ensuring gen assets are ready. puts_start_compile_check_message(stale_gen_files) - webpack_assets_compiler.compile_assets + webpack_assets_compiler.compile_asseta end def puts_start_compile_check_message(stale_files) diff --git a/lib/react_on_rails/version.rb b/lib/react_on_rails/version.rb index 253630b89..ca9815d7c 100644 --- a/lib/react_on_rails/version.rb +++ b/lib/react_on_rails/version.rb @@ -1,4 +1,4 @@ # frozen_string_literal: true module ReactOnRails - VERSION = "5.2.0".freeze + VERSION = "6.0.0.beta.2".freeze end diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake index 1ace9d05f..f0f1184bc 100644 --- a/lib/tasks/assets.rake +++ b/lib/tasks/assets.rake @@ -21,10 +21,9 @@ end namespace :react_on_rails do namespace :assets do - - if ReactOnRails.configuration.symlink_non_digested_assets_regex - desc "Creates non-digested symlinks for the assets in the public asset dir" - task symlink_non_digested_assets: :"assets:environment" do + desc "Creates non-digested symlinks for the assets in the public asset dir" + task symlink_non_digested_assets: :"assets:environment" do + if ReactOnRails.configuration.symlink_non_digested_assets_regex manifest_path = Dir.glob(ReactOnRails::assets_path.join(".sprockets-manifest-*.json")) .first manifest_data = JSON.load(File.new(manifest_path)) @@ -42,74 +41,78 @@ namespace :react_on_rails do end end end + end - desc "Cleans all broken symlinks for the assets in the public asset dir" - task delete_broken_symlinks: :"assets:environment" do - Dir.glob(ReactOnRails::assets_path.join("*")).each do |filename| - if File.lstat(filename).symlink? - begin - target = File.readlink(filename) - rescue - puts "React on Rails: Warning: your platform doesn't support File::readlink method."/ - "Skipping broken link check." - return - end - path = Pathname.new(File.dirname(filename)) - target_path = path.join(target) - unless File.exist?(target_path) - puts "React on Rails: Deleting broken link: #{filename}" - File.delete(filename) - end + desc "Cleans all broken symlinks for the assets in the public asset dir" + task delete_broken_symlinks: :"assets:environment" do + Dir.glob(ReactOnRails::assets_path.join("*")).each do |filename| + if File.lstat(filename).symlink? + begin + target = File.readlink(filename) + rescue + puts "React on Rails: Warning: your platform doesn't support File::readlink method."/ + "Skipping broken link check." + return + end + path = Pathname.new(File.dirname(filename)) + target_path = path.join(target) + unless File.exist?(target_path) + puts "React on Rails: Deleting broken link: #{filename}" + File.delete(filename) end end end end - - # We might need the clear_prerequisites (delete after testing without) - # Rake::Task["assets:precompile"] - # .clear_prerequisites - # .enhance(["assets:compile_environment"]) - - if ReactOnRails.configuration.npm_build_production_command.present? - # In this task, set prerequisites for the assets:precompile task - desc <<-DESC + # In this task, set prerequisites for the assets:precompile task + desc <<-DESC Create webpack assets before calling assets:environment The webpack task must run before assets:environment task. Otherwise Sprockets cannot find the files that webpack produces. This is the secret sauce for how a Heroku deployment knows to create the webpack generated JavaScript files. - DESC - task compile_environment: :webpack do - Rake::Task["assets:environment"].invoke - end + DESC + task compile_environment: :webpack do + Rake::Task["assets:environment"].invoke + end - desc <<-DESC + desc <<-DESC Compile assets with webpack Uses command defined with ReactOnRails.configuration.npm_build_production_command -sh "cd client && #{ReactOnRails.configuration.npm_build_production_command}" - DESC - task :webpack do +sh "cd client && `ReactOnRails.configuration.npm_build_production_command`" + DESC + task webpack: :environment do + if ReactOnRails.configuration.npm_build_production_command.present? sh "cd client && #{ReactOnRails.configuration.npm_build_production_command}" end + end - desc "Delete assets created with webpack, in #{ReactOnRails.configuration.generated_assets_dir}" - task :clobber do + desc "Delete assets created with webpack, in the generated assetst directory (/app/assets/webpack)" + task clobber: :environment do + dir = Rails.root.join(ReactOnRails.configuration.generated_assets_dir) + if dir.present? && File.directory?(dir) + puts "Deleting files in directory #{dir}" rm_r Dir.glob(Rails.root.join("#{ReactOnRails.configuration.generated_assets_dir}/*")) + else + puts "Could not find dir #{dir}" end end end end -if ReactOnRails.configuration.symlink_non_digested_assets_regex - Rake::Task["assets:precompile"].enhance do - Rake::Task["react_on_rails:assets:symlink_non_digested_assets"].invoke - Rake::Task["react_on_rails:assets:delete_broken_symlinks"].invoke - end -end - -if ReactOnRails.configuration.npm_build_production_command.present? - Rake::Task["assets:precompile"].enhance do - Rake::Task["react_on_rails:assets:compile_environment"].invoke - end -end +# These tasks run as pre-requisites of assets:precompile. +# Note, it's not possible to refer to ReactOnRails configuration values at this point. +Rake::Task["assets:precompile"] + .clear_prerequisites + .enhance([:environment, + "react_on_rails:assets:compile_environment", + "react_on_rails:assets:symlink_non_digested_assets", + "react_on_rails:assets:delete_broken_symlinks"]) +# puts "Enhancing assets:precompile with react_on_rails:assets:compile_environment" +# Rake::Task["assets:precompile"] +# .clear_prerequisites +# .enhance([:environment]) do +# Rake::Task["react_on_rails:assets:compile_environment"].invoke +# Rake::Task["react_on_rails:assets:symlink_non_digested_assets"].invoke +# Rake::Task["react_on_rails:assets:delete_broken_symlinks"].invoke +# end diff --git a/package.json b/package.json index a0415bd3d..c15a67098 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-on-rails", - "version": "5.2.0", + "version": "6.0.0-beta.2", "description": "react-on-rails JavaScript for react_on_rails Ruby gem", "main": "node_package/lib/ReactOnRails.js", "directories": { diff --git a/spec/dummy/Gemfile.lock b/spec/dummy/Gemfile.lock index d74e863d3..cba94d3e3 100644 --- a/spec/dummy/Gemfile.lock +++ b/spec/dummy/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: ../.. specs: - react_on_rails (5.2.0) + react_on_rails (6.0.0.beta.2) addressable connection_pool execjs (~> 2.5) diff --git a/spec/dummy/config/initializers/react_on_rails.rb b/spec/dummy/config/initializers/react_on_rails.rb index 9cf9c9714..6e2e87ec5 100644 --- a/spec/dummy/config/initializers/react_on_rails.rb +++ b/spec/dummy/config/initializers/react_on_rails.rb @@ -27,11 +27,6 @@ def self.custom_context(view_context) # to automatically refresh your webpack assets on every test run. config.npm_build_test_command = "npm run build:test" - # If you are using the ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config) - # with rspec then this controls what npm command is run - # to automatically refresh your webpack assets on every test run. - config.npm_build_test_command = "npm run build:test" - # This configures the script to run to build the production assets by webpack. Set this to nil # if you don't want react_on_rails building this file for you. config.npm_build_production_command = "npm run build:production" diff --git a/spec/react_on_rails/test_helper/ensure_assets_compiled_spec.rb b/spec/react_on_rails/test_helper/ensure_assets_compiled_spec.rb index 7a9eb664b..4898f4500 100644 --- a/spec/react_on_rails/test_helper/ensure_assets_compiled_spec.rb +++ b/spec/react_on_rails/test_helper/ensure_assets_compiled_spec.rb @@ -29,7 +29,8 @@ def invoke_ensurer_with_doubles ReactOnRails::TestHelper.ensure_assets_compiled( webpack_assets_status_checker: assets_checker, - webpack_assets_compiler: compiler) + webpack_assets_compiler: compiler + ) end def double_assets_checker(args = {})