react_on_rails 11.0.0 → 12.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 (130) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +320 -0
  3. data/.eslintignore +2 -1
  4. data/.eslintrc +30 -2
  5. data/.github/FUNDING.yml +1 -0
  6. data/.gitignore +3 -1
  7. data/.prettierignore +10 -0
  8. data/.prettierrc +23 -0
  9. data/.release-it.json +3 -0
  10. data/.rubocop.yml +39 -11
  11. data/.travis.yml +11 -22
  12. data/CHANGELOG.md +235 -6
  13. data/CONTRIBUTING.md +64 -84
  14. data/Gemfile +3 -5
  15. data/KUDOS.md +4 -1
  16. data/{docs/LICENSE.md → LICENSE.md} +1 -1
  17. data/PROJECTS.md +7 -1
  18. data/REACT-ON-RAILS-PRO-LICENSE +95 -0
  19. data/README.md +233 -630
  20. data/Rakefile +1 -5
  21. data/SUMMARY.md +42 -29
  22. data/book.json +5 -5
  23. data/docs/additional-reading/asset-pipeline.md +8 -16
  24. data/docs/additional-reading/convert-rails-5-api-only-app.md +19 -0
  25. data/docs/additional-reading/credits.md +10 -0
  26. data/docs/additional-reading/images.md +1 -1
  27. data/docs/additional-reading/rails-engine-integration.md +7 -0
  28. data/docs/additional-reading/rails_view_rendering_from_inline_javascript.md +2 -1
  29. data/docs/additional-reading/react-helmet.md +30 -10
  30. data/docs/additional-reading/react-router.md +52 -75
  31. data/docs/additional-reading/server-rendering-tips.md +14 -11
  32. data/docs/additional-reading/upgrade-webpacker-v3-to-v4.md +10 -0
  33. data/docs/additional-reading/webpack.md +2 -2
  34. data/docs/api/javascript-api.md +24 -4
  35. data/docs/api/redux-store-api.md +102 -0
  36. data/docs/api/view-helpers-api.md +133 -0
  37. data/docs/articles.md +20 -0
  38. data/docs/basics/client-vs-server-rendering.md +23 -0
  39. data/docs/basics/configuration.md +145 -61
  40. data/docs/basics/deployment.md +4 -0
  41. data/docs/basics/{generator.md → generator-details.md} +5 -8
  42. data/docs/basics/heroku-deployment.md +24 -0
  43. data/docs/basics/hmr-and-hot-reloading-with-the-webpack-dev-server.md +49 -0
  44. data/docs/basics/i18n.md +45 -23
  45. data/docs/basics/installation-into-an-existing-rails-app.md +59 -0
  46. data/docs/basics/minitest-configuration.md +31 -0
  47. data/docs/basics/react-server-rendering.md +29 -0
  48. data/docs/{additional-reading → basics}/recommended-project-structure.md +38 -10
  49. data/docs/basics/render-functions-and-railscontext.md +205 -0
  50. data/docs/basics/rspec-configuration.md +73 -0
  51. data/docs/basics/upgrading-react-on-rails.md +75 -4
  52. data/docs/basics/webpack-configuration.md +50 -0
  53. data/docs/contributor-info/errors-with-hooks.md +45 -0
  54. data/docs/contributor-info/pull-requests.md +44 -0
  55. data/docs/misc/doctrine.md +2 -2
  56. data/docs/{additional-reading → outdated}/code-splitting.md +19 -9
  57. data/docs/outdated/how-react-on-rails-works.md +44 -0
  58. data/docs/{basics/installation-overview.md → outdated/manual-installation-overview.md} +8 -13
  59. data/docs/{additional-reading → outdated}/rails-assets-relative-paths.md +3 -3
  60. data/docs/{additional-reading → outdated}/rails-assets.md +5 -13
  61. data/docs/testimonials/hvmn.md +25 -0
  62. data/docs/testimonials/resortpass.md +13 -0
  63. data/docs/testimonials/testimonials.md +28 -0
  64. data/docs/tutorial.md +182 -44
  65. data/jest.config.js +4 -0
  66. data/lib/generators/USAGE +1 -1
  67. data/lib/generators/react_on_rails/base_generator.rb +2 -2
  68. data/lib/generators/react_on_rails/dev_tests_generator.rb +3 -2
  69. data/lib/generators/react_on_rails/generator_helper.rb +4 -6
  70. data/lib/generators/react_on_rails/install_generator.rb +2 -0
  71. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev +3 -1
  72. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-hmr +26 -0
  73. data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +20 -40
  74. data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +4 -1
  75. data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +4 -8
  76. data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/store/helloWorldStore.js +1 -3
  77. data/lib/react_on_rails/configuration.rb +175 -102
  78. data/lib/react_on_rails/error.rb +2 -0
  79. data/lib/react_on_rails/git_utils.rb +2 -0
  80. data/lib/react_on_rails/{react_on_rails_helper.rb → helper.rb} +201 -225
  81. data/lib/react_on_rails/json_output.rb +1 -1
  82. data/lib/react_on_rails/json_parse_error.rb +28 -0
  83. data/lib/react_on_rails/locales/base.rb +150 -0
  84. data/lib/react_on_rails/locales/to_js.rb +37 -0
  85. data/lib/react_on_rails/locales/to_json.rb +27 -0
  86. data/lib/react_on_rails/prerender_error.rb +56 -18
  87. data/lib/react_on_rails/react_component/render_options.rb +98 -0
  88. data/lib/react_on_rails/server_rendering_js_code.rb +42 -0
  89. data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +139 -106
  90. data/lib/react_on_rails/server_rendering_pool.rb +4 -16
  91. data/lib/react_on_rails/test_helper/ensure_assets_compiled.rb +7 -8
  92. data/lib/react_on_rails/test_helper/webpack_assets_compiler.rb +17 -0
  93. data/lib/react_on_rails/test_helper/webpack_assets_status_checker.rb +10 -6
  94. data/lib/react_on_rails/test_helper.rb +18 -7
  95. data/lib/react_on_rails/utils.rb +66 -26
  96. data/lib/react_on_rails/version.rb +1 -1
  97. data/lib/react_on_rails/version_checker.rb +5 -1
  98. data/lib/react_on_rails/version_syntax_converter.rb +14 -12
  99. data/lib/react_on_rails/webpacker_utils.rb +44 -10
  100. data/lib/react_on_rails.rb +8 -3
  101. data/lib/tasks/assets.rake +33 -46
  102. data/lib/tasks/locale.rake +4 -2
  103. data/package-scripts.yml +49 -0
  104. data/package.json +49 -40
  105. data/rakelib/dummy_apps.rake +1 -9
  106. data/rakelib/example_type.rb +3 -1
  107. data/rakelib/examples.rake +3 -0
  108. data/rakelib/lint.rake +2 -7
  109. data/rakelib/node_package.rake +2 -2
  110. data/rakelib/release.rake +4 -8
  111. data/rakelib/run_rspec.rake +5 -18
  112. data/react_on_rails.gemspec +5 -6
  113. data/tsconfig.json +14 -0
  114. data/webpackConfigLoader.js +5 -4
  115. data/yarn.lock +7645 -1821
  116. metadata +71 -61
  117. data/Gemfile.rails32 +0 -74
  118. data/docs/additional-reading/babel.md +0 -5
  119. data/docs/additional-reading/caching-and-performance.md +0 -4
  120. data/docs/additional-reading/heroku-deployment.md +0 -92
  121. data/docs/additional-reading/hot-reloading-rails-development.md +0 -57
  122. data/docs/additional-reading/node-server-rendering.md +0 -5
  123. data/docs/additional-reading/rspec-configuration.md +0 -56
  124. data/docs/api/ruby-api-hot-reload-view-helpers.md +0 -44
  125. data/docs/api/ruby-api.md +0 -8
  126. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-server +0 -12
  127. data/lib/react_on_rails/assets_precompile.rb +0 -150
  128. data/lib/react_on_rails/locales_to_js.rb +0 -134
  129. data/lib/react_on_rails/react_component/options.rb +0 -64
  130. /data/docs/{misc → outdated}/rails3.md +0 -0
@@ -8,6 +8,8 @@ require "active_support/core_ext/string"
8
8
 
9
9
  module ReactOnRails
10
10
  module Utils
11
+ TRUNCATION_FILLER = "\n... TRUNCATED ...\n"
12
+
11
13
  # https://forum.shakacode.com/t/yak-of-the-week-ruby-2-4-pathname-empty-changed-to-look-at-file-size/901
12
14
  # return object if truthy, else return nil
13
15
  def self.truthy_presence(obj)
@@ -22,13 +24,12 @@ module ReactOnRails
22
24
  # Pass in the msg and color as a symbol.
23
25
  def self.wrap_message(msg, color = :red)
24
26
  wrapper_line = ("=" * 80).to_s
25
- # rubocop:disable Layout/IndentHeredoc
26
- fenced_msg = <<-MSG
27
- #{wrapper_line}
28
- #{msg.strip}
29
- #{wrapper_line}
27
+ fenced_msg = <<~MSG
28
+ #{wrapper_line}
29
+ #{msg.strip}
30
+ #{wrapper_line}
30
31
  MSG
31
- # rubocop:enable Layout/IndentHeredoc
32
+
32
33
  Rainbow(fenced_msg).color(color)
33
34
  end
34
35
 
@@ -46,29 +47,31 @@ module ReactOnRails
46
47
  unless status.success?
47
48
  stdout_msg = stdout.present? ? "\nstdout:\n#{stdout.strip}\n" : ""
48
49
  stderr_msg = stderr.present? ? "\nstderr:\n#{stderr.strip}\n" : ""
49
- # rubocop:disable Layout/IndentHeredoc
50
- msg = <<-MSG
51
- React on Rails FATAL ERROR!
52
- #{failure_message}
53
- cmd: #{cmd}
54
- exitstatus: #{status.exitstatus}#{stdout_msg}#{stderr_msg}
50
+ msg = <<~MSG
51
+ React on Rails FATAL ERROR!
52
+ #{failure_message}
53
+ cmd: #{cmd}
54
+ exitstatus: #{status.exitstatus}#{stdout_msg}#{stderr_msg}
55
55
  MSG
56
- # rubocop:enable Layout/IndentHeredoc
56
+
57
57
  puts wrap_message(msg)
58
- exit(1)
58
+
59
+ # Rspec catches exit without! in the exit callbacks
60
+ exit!(1)
59
61
  end
60
62
  [stdout, stderr, status]
61
63
  end
62
64
 
65
+ def self.server_bundle_path_is_http?
66
+ server_bundle_js_file_path =~ %r{https?://}
67
+ end
68
+
63
69
  def self.server_bundle_js_file_path
64
70
  # Either:
65
71
  # 1. Using same bundle for both server and client, so server bundle will be hashed in manifest
66
72
  # 2. Using a different bundle (different Webpack config), so file is not hashed, and
67
- # bundle_js_path will throw.
68
- # 3. Not using webpacker, and bundle_js_path always returns
69
-
70
- # Note, server bundle should not be in the manifest
71
- # If using webpacker gem per https://github.com/rails/webpacker/issues/571
73
+ # bundle_js_path will throw so the default path is used without a hash.
74
+ # 3. Not using webpacker, and this method returns the bundle_js_file_path
72
75
  return @server_bundle_path if @server_bundle_path && !Rails.env.development?
73
76
 
74
77
  bundle_name = ReactOnRails.configuration.server_bundle_js_file
@@ -76,8 +79,10 @@ exitstatus: #{status.exitstatus}#{stdout_msg}#{stderr_msg}
76
79
  begin
77
80
  bundle_js_file_path(bundle_name)
78
81
  rescue Webpacker::Manifest::MissingEntryError
79
- Rails.root.join(File.join(Webpacker.config.public_output_path,
80
- bundle_name)).to_s
82
+ File.expand_path(
83
+ File.join(ReactOnRails::WebpackerUtils.webpacker_public_output_path,
84
+ bundle_name)
85
+ )
81
86
  end
82
87
  else
83
88
  bundle_js_file_path(bundle_name)
@@ -86,11 +91,12 @@ exitstatus: #{status.exitstatus}#{stdout_msg}#{stderr_msg}
86
91
 
87
92
  def self.bundle_js_file_path(bundle_name)
88
93
  if ReactOnRails::WebpackerUtils.using_webpacker? && bundle_name != "manifest.json"
89
- ReactOnRails::WebpackerUtils.bundle_js_file_path_from_webpacker(bundle_name)
94
+ ReactOnRails::WebpackerUtils.bundle_js_uri_from_webpacker(bundle_name)
90
95
  else
91
96
  # Default to the non-hashed name in the specified output directory, which, for legacy
92
97
  # React on Rails, this is the output directory picked up by the asset pipeline.
93
- File.join(ReactOnRails.configuration.generated_assets_dir, bundle_name)
98
+ # For Webpacker, this is the public output path defined in the webpacker.yml file.
99
+ File.join(generated_assets_full_path, bundle_name)
94
100
  end
95
101
  end
96
102
 
@@ -114,7 +120,7 @@ exitstatus: #{status.exitstatus}#{stdout_msg}#{stderr_msg}
114
120
 
115
121
  module Required
116
122
  def required(arg_name)
117
- raise ReactOnRailsPro::Error, "#{arg_name} is required"
123
+ raise ReactOnRails::Error, "#{arg_name} is required"
118
124
  end
119
125
  end
120
126
 
@@ -130,12 +136,46 @@ exitstatus: #{status.exitstatus}#{stdout_msg}#{stderr_msg}
130
136
  end
131
137
  end
132
138
 
133
- def self.generated_assets_dir
139
+ def self.using_webpacker_source_path_is_not_defined_and_custom_node_modules?
140
+ return false unless ReactOnRails::WebpackerUtils.using_webpacker?
141
+
142
+ !ReactOnRails::WebpackerUtils.webpacker_source_path_explicit? &&
143
+ ReactOnRails.configuration.node_modules_location.present?
144
+ end
145
+
146
+ def self.generated_assets_full_path
134
147
  if ReactOnRails::WebpackerUtils.using_webpacker?
135
148
  ReactOnRails::WebpackerUtils.webpacker_public_output_path
136
149
  else
137
- ReactOnRails.configuration.generated_assets_dir
150
+ File.expand_path(ReactOnRails.configuration.generated_assets_dir)
138
151
  end
139
152
  end
153
+
154
+ def self.gem_available?(name)
155
+ Gem::Specification.find_all_by_name(name).present?
156
+ rescue Gem::LoadError
157
+ false
158
+ rescue StandardError
159
+ Gem.available?(name).present?
160
+ end
161
+
162
+ def self.react_on_rails_pro?
163
+ @react_on_rails_pro ||= gem_available?("react_on_rails_pro")
164
+ end
165
+
166
+ def self.smart_trim(str, max_length = 1000)
167
+ # From https://stackoverflow.com/a/831583/1009332
168
+ str = str.to_s
169
+ return str unless str.present? && max_length >= 1
170
+ return str if str.length <= max_length
171
+
172
+ return str[0, 1] + TRUNCATION_FILLER if max_length == 1
173
+
174
+ midpoint = (str.length / 2.0).ceil
175
+ to_remove = str.length - max_length
176
+ lstrip = (to_remove / 2.0).ceil
177
+ rstrip = to_remove - lstrip
178
+ str[0..(midpoint - lstrip - 1)] + TRUNCATION_FILLER + str[(midpoint + rstrip)..-1]
179
+ end
140
180
  end
141
181
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReactOnRails
4
- VERSION = "11.0.0".freeze
4
+ VERSION = "12.0.0"
5
5
  end
@@ -5,7 +5,8 @@ module ReactOnRails
5
5
  # against each otherat runtime.
6
6
  class VersionChecker
7
7
  attr_reader :node_package_version
8
- MAJOR_MINOR_PATCH_VERSION_REGEX = /(\d+)\.(\d+)\.(\d+)/
8
+
9
+ MAJOR_MINOR_PATCH_VERSION_REGEX = /(\d+)\.(\d+)\.(\d+)/.freeze
9
10
 
10
11
  def self.build
11
12
  new(NodePackageVersion.build)
@@ -20,6 +21,7 @@ module ReactOnRails
20
21
  # warning if they do not.
21
22
  def raise_if_gem_and_node_package_versions_differ
22
23
  return if node_package_version.relative_path?
24
+
23
25
  node_major_minor_patch = node_package_version.major_minor_patch
24
26
  gem_major_minor_patch = gem_major_minor_patch_version
25
27
  versions_match = node_major_minor_patch[0] == gem_major_minor_patch[0] &&
@@ -99,10 +101,12 @@ module ReactOnRails
99
101
 
100
102
  def major_minor_patch
101
103
  return if relative_path?
104
+
102
105
  match = raw.match(MAJOR_MINOR_PATCH_VERSION_REGEX)
103
106
  unless match
104
107
  raise ReactOnRails::Error, "Cannot parse version number '#{raw}' (wildcard versions are not supported)"
105
108
  end
109
+
106
110
  [match[1], match[2], match[3]]
107
111
  end
108
112
 
@@ -2,19 +2,21 @@
2
2
 
3
3
  require_relative "version"
4
4
 
5
- class VersionSyntaxConverter
6
- def rubygem_to_npm(rubygem_version = ReactOnRails::VERSION)
7
- regex_match = rubygem_version.match(/(\d+\.\d+\.\d+)[.\-]?(.+)?/)
8
- return "#{regex_match[1]}-#{regex_match[2]}" if regex_match[2]
5
+ module ReactOnRails
6
+ class VersionSyntaxConverter
7
+ def rubygem_to_npm(rubygem_version = ReactOnRails::VERSION)
8
+ regex_match = rubygem_version.match(/(\d+\.\d+\.\d+)[.\-]?(.+)?/)
9
+ return "#{regex_match[1]}-#{regex_match[2]}" if regex_match[2]
9
10
 
10
- regex_match[1].to_s
11
- end
11
+ regex_match[1].to_s
12
+ end
12
13
 
13
- def npm_to_rubygem(npm_version)
14
- match = npm_version
15
- .tr("-", ".")
16
- .strip
17
- .match(/(\d.*)/)
18
- match.present? ? match[0] : nil
14
+ def npm_to_rubygem(npm_version)
15
+ match = npm_version
16
+ .tr("-", ".")
17
+ .strip
18
+ .match(/(\d.*)/)
19
+ match.present? ? match[0] : nil
20
+ end
19
21
  end
20
22
  end
@@ -1,18 +1,44 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ReactOnRails
2
4
  module WebpackerUtils
3
5
  def self.using_webpacker?
4
- ActionController::Base.helpers.respond_to?(:asset_pack_path)
6
+ ReactOnRails::Utils.gem_available?("webpacker")
7
+ end
8
+
9
+ def self.webpacker_webpack_production_config_exists?
10
+ webpacker_webpack_config_abs_path = File.join(Rails.root,
11
+ "config/webpack/production.js")
12
+ File.exist?(webpacker_webpack_config_abs_path)
13
+ end
14
+
15
+ def self.dev_server_running?
16
+ return false unless using_webpacker?
17
+
18
+ Webpacker.dev_server.running?
5
19
  end
6
20
 
7
- def self.bundle_js_file_path_from_webpacker(bundle_name)
8
- possible_result = Webpacker.manifest.lookup(bundle_name)
9
- hashed_bundle_name = possible_result.nil? ? Webpacker.manifest.lookup!(bundle_name) : possible_result
10
- if Webpacker.dev_server.running?
11
- result = "#{Webpacker.dev_server.protocol}://#{Webpacker.dev_server.host_with_port}#{hashed_bundle_name}"
12
- result
21
+ # This returns either a URL for the webpack-dev-server, non-server bundle or
22
+ # the hashed server bundle if using the same bundle for the client.
23
+ # Otherwise returns a file path.
24
+ def self.bundle_js_uri_from_webpacker(bundle_name)
25
+ # Note Webpacker 3.4.3 manifest lookup is inside of the public_output_path
26
+ # [2] (pry) ReactOnRails::WebpackerUtils: 0> Webpacker.manifest.lookup("app-bundle.js")
27
+ # "/webpack/development/app-bundle-c1d2b6ab73dffa7d9c0e.js"
28
+ # Next line will throw if the file or manifest does not exist
29
+ hashed_bundle_name = Webpacker.manifest.lookup!(bundle_name)
30
+
31
+ # support for hashing the server-bundle and having that built
32
+ # by a webpack watch process and not served by the webpack-dev-server, then we
33
+ # need an extra config value "same_bundle_for_client_and_server" where a value of false
34
+ # would mean that the bundle is created by a separate webpack watch process.
35
+ is_server_bundle = bundle_name == ReactOnRails.configuration.server_bundle_js_file
36
+
37
+ if Webpacker.dev_server.running? && (!is_server_bundle ||
38
+ ReactOnRails.configuration.same_bundle_for_client_and_server)
39
+ "#{Webpacker.dev_server.protocol}://#{Webpacker.dev_server.host_with_port}#{hashed_bundle_name}"
13
40
  else
14
- # Next line will throw if the file or manifest does not exist
15
- Rails.root.join(File.join("public", hashed_bundle_name)).to_s
41
+ File.expand_path(File.join("public", hashed_bundle_name)).to_s
16
42
  end
17
43
  end
18
44
 
@@ -21,15 +47,23 @@ module ReactOnRails
21
47
  end
22
48
 
23
49
  def self.webpacker_public_output_path
24
- Webpacker.config.public_output_path
50
+ # Webpacker has the full absolute path of webpacker output files in a Pathname
51
+ Webpacker.config.public_output_path.to_s
25
52
  end
26
53
 
27
54
  def self.manifest_exists?
28
55
  Webpacker.config.public_manifest_path.exist?
29
56
  end
30
57
 
58
+ def self.webpacker_source_path_explicit?
59
+ # WARNING: Calling private method `data` on Webpacker::Configuration, lib/webpacker/configuration.rb
60
+ config_webpacker_yml = Webpacker.config.send(:data)
61
+ config_webpacker_yml[:source_path].present?
62
+ end
63
+
31
64
  def self.check_manifest_not_cached
32
65
  return unless using_webpacker? && Webpacker.config.cache_manifest?
66
+
33
67
  msg = <<-MSG.strip_heredoc
34
68
  ERROR: you have enabled cache_manifest in the #{Rails.env} env when using the
35
69
  ReactOnRails::TestHelper.configure_rspec_to_compile_assets helper
@@ -3,14 +3,17 @@
3
3
  require "rails"
4
4
 
5
5
  require "react_on_rails/error"
6
- require "react_on_rails/react_on_rails_helper"
6
+ require "react_on_rails/prerender_error"
7
+ require "react_on_rails/json_parse_error"
8
+ require "react_on_rails/helper"
7
9
  require "react_on_rails/controller"
8
10
  require "react_on_rails/version"
9
11
  require "react_on_rails/version_checker"
10
12
  require "react_on_rails/configuration"
11
13
  require "react_on_rails/server_rendering_pool"
14
+ require "react_on_rails/server_rendering_js_code"
12
15
  require "react_on_rails/engine"
13
- require "react_on_rails/react_component/options"
16
+ require "react_on_rails/react_component/render_options"
14
17
  require "react_on_rails/version_syntax_converter"
15
18
  require "react_on_rails/test_helper"
16
19
  require "react_on_rails/git_utils"
@@ -19,4 +22,6 @@ require "react_on_rails/webpacker_utils"
19
22
  require "react_on_rails/test_helper/webpack_assets_compiler"
20
23
  require "react_on_rails/test_helper/webpack_assets_status_checker"
21
24
  require "react_on_rails/test_helper/ensure_assets_compiled"
22
- require "react_on_rails/locales_to_js"
25
+ require "react_on_rails/locales/base"
26
+ require "react_on_rails/locales/to_js"
27
+ require "react_on_rails/locales/to_json"
@@ -1,69 +1,56 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "react_on_rails/assets_precompile"
4
- require "active_support"
3
+ # Important: The default assets:precompile is modified ONLY if the rails/webpacker webpack config
4
+ # does not exist!
5
5
 
6
- if defined?(Sprockets)
7
- namespace :react_on_rails do
8
- namespace :assets do
9
- desc "Creates non-digested symlinks for the assets in the public asset dir"
10
- task symlink_non_digested_assets: :"assets:environment" do
11
- ReactOnRails::AssetsPrecompile.new.symlink_non_digested_assets
12
- end
6
+ require "active_support"
13
7
 
14
- desc "Cleans all broken symlinks for the assets in the public asset dir"
15
- task delete_broken_symlinks: :"assets:environment" do
16
- ReactOnRails::AssetsPrecompile.new.delete_broken_symlinks
17
- end
8
+ ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
9
+ ENV["NODE_ENV"] ||= "development"
18
10
 
19
- # In this task, set prerequisites for the assets:precompile task
20
- desc <<-DESC.strip_heredoc
21
- Create webpack assets before calling assets:environment
22
- The webpack task must run before assets:environment task.
23
- Otherwise Sprockets cannot find the files that webpack produces.
24
- This is the secret sauce for how a Heroku deployment knows to create the webpack generated JavaScript files.
25
- DESC
26
- task compile_environment: :webpack do
27
- Rake::Task["assets:environment"].invoke
28
- end
11
+ unless ReactOnRails::WebpackerUtils.webpacker_webpack_production_config_exists?
12
+ # Ensure that rails/webpacker does not call bin/webpack if we're providing
13
+ # the build command.
14
+ ENV["WEBPACKER_PRECOMPILE"] = "false"
29
15
 
30
- desc "Delete assets created with webpack, in the generated assetst directory (/app/assets/webpack)"
31
- task clobber: :environment do
32
- ReactOnRails::AssetsPrecompile.new.clobber
33
- end
16
+ if Rake::Task.task_defined?("assets:precompile")
17
+ Rake::Task["assets:precompile"].enhance do
18
+ Rake::Task["react_on_rails:assets:webpack"].invoke
19
+ puts "Invoking task webpacker:clean from React on Rails"
20
+ Rake::Task["webpacker:clean"].invoke
34
21
  end
22
+ else
23
+ Rake::Task.define_task("assets:precompile" => ["react_on_rails:assets:webpack",
24
+ "webpacker:clean"])
35
25
  end
36
-
37
- # These tasks run as pre-requisites of assets:precompile.
38
- # Note, it's not possible to refer to ReactOnRails configuration values at this point.
39
- Rake::Task["assets:precompile"]
40
- .clear_prerequisites
41
- .enhance([:environment, "react_on_rails:assets:compile_environment"])
42
- .enhance do
43
- Rake::Task["react_on_rails:assets:symlink_non_digested_assets"].invoke
44
- Rake::Task["react_on_rails:assets:delete_broken_symlinks"].invoke
45
- end
46
26
  end
47
27
 
48
28
  # Sprockets independent tasks
49
29
  namespace :react_on_rails do
50
30
  namespace :assets do
51
31
  desc <<-DESC.strip_heredoc
52
- Compile assets with webpack
53
- Uses command defined with ReactOnRails.configuration.build_production_command
54
-
55
- sh "#{ReactOnRails::Utils.prepend_cd_node_modules_directory('<ReactOnRails.configuration.build_production_command>')}"
32
+ Compile assets with webpack
33
+ Uses command defined with ReactOnRails.configuration.build_production_command
34
+ sh "#{ReactOnRails::Utils.prepend_cd_node_modules_directory('<ReactOnRails.configuration.build_production_command>')}"
35
+ Note: This command is not automatically added to assets:precompile if the rails/webpacker
36
+ configuration file config/webpack/production.js exists.
56
37
  DESC
57
38
  task webpack: :locale do
58
- if Rake::Task.task_defined?("webpacker:compile")
59
- # TODO: Eventually, this will need reconsideration if we use any of the Webpacker compilation
60
- Rake::Task["webpacker:compile"].clear
61
- end
62
-
63
39
  if ReactOnRails.configuration.build_production_command.present?
64
40
  sh ReactOnRails::Utils.prepend_cd_node_modules_directory(
65
41
  ReactOnRails.configuration.build_production_command
66
42
  ).to_s
43
+ else
44
+ msg = <<~MSG
45
+ React on Rails is aborting webpack compilation from task react_on_rails:assets:webpack
46
+ because you do not have the `config.build_production_command` defined.
47
+
48
+ Note, this task may have run as part of `assets:precompile`. If file
49
+ config/webpack/production.js does not exist, React on Rails will modify
50
+ the default `asset:precompile` to run task `react_on_rails:assets:webpack`.
51
+ MSG
52
+ puts Rainbow(msg).red
53
+ exit!(1)
67
54
  end
68
55
  end
69
56
  end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "react_on_rails/locales_to_js"
3
+ require "react_on_rails/locales/base"
4
+ require "react_on_rails/locales/to_js"
5
+ require "react_on_rails/locales/to_json"
4
6
  require "active_support"
5
7
 
6
8
  namespace :react_on_rails do
@@ -10,6 +12,6 @@ namespace :react_on_rails do
10
12
  the "ReactOnRails.configuration.i18n_dir".
11
13
  DESC
12
14
  task locale: :environment do
13
- ReactOnRails::LocalesToJs.new
15
+ ReactOnRails::Locales.compile
14
16
  end
15
17
  end
@@ -0,0 +1,49 @@
1
+ scripts:
2
+ lint:
3
+ description: Run all linters (eslint, tsc)
4
+ script: concurrently --prefix "[{name}]" --names "ESLINT" -c "blue,yellow,magenta,orange" "nps eslint"
5
+
6
+ eslint:
7
+ default:
8
+ description: Run eslint.
9
+ script: eslint . --ext ".js,.jsx,.ts"
10
+ fix:
11
+ description: Run eslint and auto-fix.
12
+ script: nps "eslint --fix"
13
+ debug:
14
+ description: Run eslint in debug mode.
15
+ script: DEBUG=eslint:cli-engine nps eslint
16
+
17
+ format:
18
+ default:
19
+ description: Format files using prettier.
20
+ script: concurrently --prefix "[{name}]" --names "ts,js,json" -c "yellow,magenta,green" "nps format.js" "nps format.json"
21
+ listDifferent:
22
+ description: Check that all files were formatted using prettier.
23
+ script: |
24
+ concurrently \
25
+ --prefix "[{name}]" \
26
+ --names "ts,js,json" \
27
+ -c "yellow,magenta" \
28
+ "nps format.js.listDifferent" \
29
+ "nps format.json.listDifferent"
30
+ js:
31
+ default:
32
+ description: Run prettier-eslint on JS.
33
+ #script: prettier "packages/**/*.@(js|jsx)" "spec/dummy/client/app/**/*.@(js|jsx)" "webpack.config.babel.js" "webpack/**/*.js" --write
34
+ script: prettier "**/*.@(js|jsx)" --write
35
+ listDifferent:
36
+ description: Check if any JS files would change by running prettier-eslint.
37
+ # script: prettier "**/*.@(js|jsx)" "webpack.config.babel.js" "webpack/**/*.js" --list-different
38
+ script: prettier "**/*.@(js|jsx)" --list-different
39
+ json:
40
+ default:
41
+ description: Run prettier on JSON files.
42
+ script: rm -rf packages/vm-renderer/tests/tmp && prettier "**/*.json" --write
43
+ listDifferent:
44
+ description: Check if any JSON files would change by running prettier-eslint.
45
+ script: prettier "**/*.json" --list-different
46
+
47
+ renderer:
48
+ description: Starts the node renderer.
49
+ script: node renderer.js
data/package.json CHANGED
@@ -1,73 +1,83 @@
1
1
  {
2
2
  "name": "react-on-rails",
3
- "version": "11.0.0",
3
+ "version": "12.0.0",
4
4
  "description": "react-on-rails JavaScript for react_on_rails Ruby gem",
5
5
  "main": "node_package/lib/ReactOnRails.js",
6
6
  "directories": {
7
7
  "doc": "docs"
8
8
  },
9
9
  "devDependencies": {
10
- "babel-cli": "^6.24.1",
11
- "babel-core": "^6.25.0",
12
- "babel-loader": "^7.1.1",
13
- "babel-plugin-react-transform": "^2.0.2",
14
- "babel-plugin-transform-flow-strip-types": "^6.22.0",
15
- "babel-plugin-transform-runtime": "^6.23.0",
16
- "babel-preset-es2015": "^6.24.1",
17
- "babel-preset-react": "^6.24.1",
18
- "babel-preset-stage-2": "^6.24.1",
19
- "babel-runtime": "^6.25.0",
20
- "babel-tape-runner": "^2.0.1",
21
- "babel-types": "^6.25.0",
22
- "babelify": "^7.3.0",
10
+ "@babel/cli": "^7.0.0",
11
+ "@babel/core": "^7.0.0",
12
+ "@babel/plugin-transform-runtime": "^7.0.0",
13
+ "@babel/plugin-transform-typescript": "^7.8.7",
14
+ "@babel/preset-env": "^7.0.0",
15
+ "@babel/preset-react": "^7.0.0",
16
+ "@babel/types": "^7.0.0",
17
+ "@types/jest": "^25.1.4",
18
+ "@types/node": "^13.9.0",
19
+ "@types/react": "^16.9.23",
20
+ "@types/react-dom": "^16.9.5",
21
+ "@types/turbolinks": "^5.2.0",
22
+ "@typescript-eslint/eslint-plugin": "^2.23.0",
23
+ "@typescript-eslint/parser": "^2.23.0",
24
+ "babel-loader": "^8.0.2",
25
+ "babelify": "^10.0.0",
23
26
  "blue-tape": "^1.0.0",
24
27
  "create-react-class": "^15.6.0",
25
- "eslint": "^3.19.0",
26
- "eslint-config-shakacode": "^15.0.0",
28
+ "eslint": "^6.8.0",
29
+ "eslint-config-prettier": "^6.10.1",
30
+ "eslint-config-shakacode": "^16.0.1",
27
31
  "eslint-plugin-import": "^2.6.1",
28
- "eslint-plugin-jsx-a11y": "^5.1.1",
32
+ "eslint-plugin-jsx-a11y": "^6.1.2",
33
+ "eslint-plugin-prettier": "^3.0.0",
29
34
  "eslint-plugin-react": "^7.1.0",
30
- "flow-bin": "^0.51.1",
35
+ "jest": "^25.1.0",
31
36
  "jsdom": "^11.1.0",
37
+ "nps": "^5.9.3",
38
+ "prettier": "^2.0.1",
39
+ "prettier-eslint-cli": "^5.0.0",
32
40
  "prop-types": "^15.5.10",
33
- "react": "^15.6.1",
34
- "react-dom": "^15.6.1",
41
+ "react": "^16.5.2",
42
+ "react-dom": "^16.5.2",
35
43
  "react-transform-hmr": "^1.0.4",
36
- "redux": "^3.7.2",
37
- "release-it": "^2.8.2",
38
- "tap-spec": "^4.1.1",
39
- "tape": "^4.7.0",
44
+ "redux": "^4.0.1",
45
+ "release-it": "^8.2.0",
46
+ "ts-jest": "^25.2.1",
47
+ "tslint-config-prettier": "^1.18.0",
48
+ "typescript": "^3.8.3",
40
49
  "webpack": "^3.4.1",
41
50
  "webpack-manifest-plugin": "^1.2.1"
42
51
  },
52
+ "dependencies": {
53
+ "@babel/runtime-corejs3": "^7.9.6",
54
+ "concurrently": "^5.1.0"
55
+ },
43
56
  "peerDependencies": {
44
- "babel-runtime": ">= 6",
45
57
  "js-yaml": ">= 3.0.0",
46
- "react": ">= 0.14",
47
- "react-dom": ">= 0.14"
58
+ "react": ">= 16",
59
+ "react-dom": ">= 16"
48
60
  },
49
61
  "files": [
50
62
  "node_package/lib",
51
63
  "webpackConfigLoader.js"
52
64
  ],
53
65
  "scripts": {
54
- "test": "babel-tape-runner -r node_package/tests/helpers/test_helper.js node_package/tests/*.js | tap-spec",
66
+ "test": "jest node_package/tests",
55
67
  "clean": "rm -rf node_package/lib",
56
- "prepublish": "yarn run build",
57
- "babel": "babel --out-dir node_package/lib node_package/src",
58
- "build": "yarn run clean && yarn run babel",
59
- "build-watch": "babel --watch --out-dir node_package/lib node_package/src",
60
- "eslint": "eslint .",
61
- "flow": "flow check node_package",
62
- "lint": "yarn run eslint && yarn run flow",
63
- "check": "yarn run lint && yarn run flow && yarn run test",
68
+ "start": "nps",
69
+ "prepare": "yarn run build",
70
+ "build": "yarn run clean && yarn run tsc --declaration",
71
+ "build-watch": "yarn run clean && yarn run tsc --watch",
72
+ "lint": "nps eslint",
73
+ "check": "yarn run lint && yarn run test && yarn run type-check",
74
+ "type-check": "yarn run tsc --noEmit --noErrorTruncation",
64
75
  "prerelease": "yarn run check && yarn run clean && yarn run build",
65
76
  "release:patch": "node_package/scripts/release patch",
66
77
  "release:minor": "node_package/scripts/release minor",
67
78
  "release:major": "node_package/scripts/release major",
68
79
  "dummy:install": "rake dummy_apps",
69
- "dummy:spec": "rake run_rspec:dummy",
70
- "install-react-on-rails": "yarn link"
80
+ "dummy:spec": "rake run_rspec:dummy"
71
81
  },
72
82
  "repository": {
73
83
  "type": "git",
@@ -86,6 +96,5 @@
86
96
  "bugs": {
87
97
  "url": "https://github.com/shakacode/react_on_rails/issues"
88
98
  },
89
- "homepage": "https://github.com/shakacode/react_on_rails#readme",
90
- "dependencies": {}
99
+ "homepage": "https://github.com/shakacode/react_on_rails#readme"
91
100
  }