react_on_rails 10.0.0 → 11.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc +4 -0
  3. data/.rubocop.yml +2 -2
  4. data/.travis.yml +3 -0
  5. data/CHANGELOG.md +81 -88
  6. data/CONTRIBUTING.md +0 -7
  7. data/Dockerfile_tests +12 -0
  8. data/Gemfile +8 -13
  9. data/NEWS.md +2 -0
  10. data/PROJECTS.md +10 -2
  11. data/README.md +137 -121
  12. data/app/helpers/react_on_rails_helper.rb +1 -533
  13. data/docker-compose.yml +11 -0
  14. data/docs/additional-reading/caching-and-performance.md +4 -0
  15. data/docs/additional-reading/capistrano-deployment.md +18 -0
  16. data/docs/additional-reading/elastic-beanstalk.md +53 -33
  17. data/docs/additional-reading/server-rendering-tips.md +4 -4
  18. data/docs/additional-reading/troubleshooting-when-using-webpacker.md +90 -0
  19. data/docs/api/ruby-api.md +7 -2
  20. data/docs/basics/configuration.md +23 -9
  21. data/docs/basics/i18n.md +4 -0
  22. data/docs/basics/upgrading-react-on-rails.md +181 -0
  23. data/docs/tutorial.md +7 -11
  24. data/lib/generators/react_on_rails/base_generator.rb +6 -3
  25. data/lib/generators/react_on_rails/dev_tests_generator.rb +1 -1
  26. data/lib/generators/react_on_rails/install_generator.rb +1 -1
  27. data/lib/generators/react_on_rails/react_no_redux_generator.rb +1 -1
  28. data/lib/generators/react_on_rails/react_with_redux_generator.rb +2 -2
  29. data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +1 -1
  30. data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +3 -2
  31. data/lib/generators/react_on_rails/templates/dev_tests/spec/simplecov_helper.rb +2 -2
  32. data/lib/react_on_rails/assets_precompile.rb +8 -4
  33. data/lib/react_on_rails/configuration.rb +34 -20
  34. data/lib/react_on_rails/error.rb +4 -0
  35. data/lib/react_on_rails/locales_to_js.rb +2 -2
  36. data/lib/react_on_rails/prerender_error.rb +2 -2
  37. data/lib/react_on_rails/react_on_rails_helper.rb +547 -0
  38. data/lib/react_on_rails/server_rendering_pool/{exec.rb → ruby_embedded_java_script.rb} +37 -40
  39. data/lib/react_on_rails/server_rendering_pool.rb +21 -10
  40. data/lib/react_on_rails/test_helper/webpack_assets_status_checker.rb +2 -2
  41. data/lib/react_on_rails/test_helper.rb +1 -1
  42. data/lib/react_on_rails/utils.rb +14 -52
  43. data/lib/react_on_rails/version.rb +1 -1
  44. data/lib/react_on_rails/version_checker.rb +33 -12
  45. data/lib/react_on_rails/webpacker_utils.rb +42 -0
  46. data/lib/react_on_rails.rb +3 -2
  47. data/package.json +2 -5
  48. data/rakelib/dummy_apps.rake +2 -1
  49. data/rakelib/example_type.rb +1 -1
  50. data/rakelib/examples.rake +3 -2
  51. data/rakelib/lint.rake +3 -2
  52. data/rakelib/node_package.rake +2 -1
  53. data/rakelib/release.rake +4 -5
  54. data/rakelib/run_rspec.rake +3 -4
  55. data/rakelib/task_helpers.rb +1 -1
  56. data/react_on_rails.gemspec +23 -13
  57. data/yarn.lock +3 -39
  58. metadata +75 -49
  59. data/lib/react_on_rails/server_rendering_pool/node.rb +0 -83
  60. data/lib/react_on_rails/test_helper/node_process_launcher.rb +0 -14
@@ -18,24 +18,43 @@ module ReactOnRails
18
18
  ensure_server_bundle_js_file_has_no_path
19
19
  check_i18n_directory_exists
20
20
  check_i18n_yml_directory_exists
21
+ check_server_render_method_is_only_execjs
22
+ end
23
+
24
+ def self.check_server_render_method_is_only_execjs
25
+ return if @configuration.server_render_method.blank? ||
26
+ @configuration.server_render_method == "ExecJS"
27
+
28
+ msg = <<-MSG.strip_heredoc
29
+ Error configuring /config/react_on_rails.rb: invalid value for `config.server_render_method`.
30
+ If you wish to use a server render method other than ExecJS, contact justin@shakacode.com
31
+ for details.
32
+ MSG
33
+ raise ReactOnRails::Error, msg
21
34
  end
22
35
 
23
36
  def self.check_i18n_directory_exists
24
- return if @configuration.i18n_dir.blank?
37
+ return if @configuration.i18n_dir.nil?
25
38
  return if Dir.exist?(@configuration.i18n_dir)
26
39
 
27
- raise "Error configuring /config/react_on_rails.rb: invalid value for `config.i18n_dir`. "\
28
- "Directory does not exist: #{@configuration.i18n_dir}. Set to value to nil or comment it "\
29
- "out if not using the React on Rails i18n feature."
40
+ msg = <<-MSG.strip_heredoc
41
+ Error configuring /config/react_on_rails.rb: invalid value for `config.i18n_dir`.
42
+ Directory does not exist: #{@configuration.i18n_dir}. Set to value to nil or comment it
43
+ out if not using the React on Rails i18n feature.
44
+ MSG
45
+ raise ReactOnRails::Error, msg
30
46
  end
31
47
 
32
48
  def self.check_i18n_yml_directory_exists
33
- return if @configuration.i18n_yml_dir.blank?
49
+ return if @configuration.i18n_yml_dir.nil?
34
50
  return if Dir.exist?(@configuration.i18n_yml_dir)
35
51
 
36
- raise "Error configuring /config/react_on_rails.rb: invalid value for `config.i18n_yml_dir`. "\
37
- "Directory does not exist: #{@configuration.i18n_yml_dir}. Set to value to nil or comment it "\
38
- "out if not using this i18n with React on Rails, or if you want to use all translation files."
52
+ msg = <<-MSG.strip_heredoc
53
+ Error configuring /config/react_on_rails.rb: invalid value for `config.i18n_yml_dir`.
54
+ Directory does not exist: #{@configuration.i18n_yml_dir}. Set to value to nil or comment it
55
+ out if not using this i18n with React on Rails, or if you want to use all translation files.
56
+ MSG
57
+ raise ReactOnRails::Error, msg
39
58
  end
40
59
 
41
60
  def self.ensure_generated_assets_dir_present
@@ -62,9 +81,8 @@ module ReactOnRails
62
81
  return unless @configuration.webpack_generated_files.empty?
63
82
 
64
83
  files = ["hello-world-bundle.js"]
65
- if @configuration.server_bundle_js_file.present?
66
- files << @configuration.server_bundle_js_file
67
- end
84
+ files << @configuration.server_bundle_js_file if @configuration.server_bundle_js_file.present?
85
+
68
86
  @configuration.webpack_generated_files = files
69
87
  end
70
88
 
@@ -83,9 +101,8 @@ module ReactOnRails
83
101
 
84
102
  def self.configuration
85
103
  @configuration ||= Configuration.new(
86
- node_modules_location: "",
104
+ node_modules_location: nil,
87
105
  generated_assets_dirs: nil,
88
-
89
106
  # generated_assets_dirs is deprecated
90
107
  generated_assets_dir: "",
91
108
  server_bundle_js_file: "",
@@ -98,15 +115,12 @@ module ReactOnRails
98
115
  server_renderer_pool_size: 1,
99
116
  server_renderer_timeout: 20,
100
117
  skip_display_none: nil,
101
-
102
118
  # skip_display_none is deprecated
103
119
  webpack_generated_files: %w[manifest.json],
104
120
  rendering_extension: nil,
105
- server_render_method: "ExecJS",
121
+ server_render_method: nil,
106
122
  symlink_non_digested_assets_regex: nil,
107
123
  build_test_command: "",
108
- i18n_dir: "",
109
- i18n_yml_dir: "",
110
124
  build_production_command: ""
111
125
  )
112
126
  end
@@ -122,7 +136,7 @@ module ReactOnRails
122
136
  :i18n_dir, :i18n_yml_dir,
123
137
  :server_render_method, :symlink_non_digested_assets_regex
124
138
 
125
- def initialize(node_modules_location: "", server_bundle_js_file: nil, prerender: nil,
139
+ def initialize(node_modules_location: nil, server_bundle_js_file: nil, prerender: nil,
126
140
  replay_console: nil,
127
141
  trace: nil, development_mode: nil,
128
142
  logging_on_server: nil, server_renderer_pool_size: nil,
@@ -132,8 +146,8 @@ module ReactOnRails
132
146
  rendering_extension: nil, build_test_command: nil,
133
147
  build_production_command: nil,
134
148
  i18n_dir: nil, i18n_yml_dir: nil,
135
- server_render_method: "ExecJS", symlink_non_digested_assets_regex: nil)
136
- self.node_modules_location = node_modules_location
149
+ server_render_method: nil, symlink_non_digested_assets_regex: nil)
150
+ self.node_modules_location = node_modules_location.present? ? node_modules_location : Rails.root
137
151
  self.server_bundle_js_file = server_bundle_js_file
138
152
  self.generated_assets_dirs = generated_assets_dirs
139
153
  self.generated_assets_dir = generated_assets_dir
@@ -0,0 +1,4 @@
1
+ module ReactOnRails
2
+ class Error < StandardError
3
+ end
4
+ end
@@ -5,7 +5,7 @@ require "erb"
5
5
  module ReactOnRails
6
6
  class LocalesToJs
7
7
  def initialize
8
- return if i18n_dir.blank?
8
+ return if i18n_dir.nil?
9
9
  return unless obsolete?
10
10
  @translations, @defaults = generate_translations
11
11
  convert
@@ -108,7 +108,7 @@ module ReactOnRails
108
108
  if v.is_a? Hash
109
109
  flatten(v).map { |hk, hv| h["#{k}.#{hk}".to_sym] = hv }
110
110
  else
111
- h[k] = v
111
+ h[k] = v.gsub("%{", "{")
112
112
  end
113
113
  end
114
114
  end
@@ -2,11 +2,11 @@
2
2
 
3
3
  # rubocop:disable: Layout/IndentHeredoc
4
4
  module ReactOnRails
5
- class PrerenderError < RuntimeError
5
+ class PrerenderError < StandardError
6
6
  # err might be nil if JS caught the error
7
7
  def initialize(component_name: nil, err: nil, props: nil,
8
8
  js_code: nil, console_messages: nil)
9
- message = "ERROR in SERVER PRERENDERING\n".dup # rubocop:disable Performance/UnfreezeString
9
+ message = "ERROR in SERVER PRERENDERING\n".dup
10
10
  if err
11
11
  # rubocop:disable Layout/IndentHeredoc
12
12
  message << <<-MSG