react_on_rails 12.0.1 → 13.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 (152) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +27 -13
  3. data/.eslintrc +2 -1
  4. data/.github/ISSUE_TEMPLATE/bug_report.md +23 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  6. data/.github/workflows/lint-js-and-ruby.yml +53 -0
  7. data/.github/workflows/main.yml +178 -0
  8. data/.github/workflows/package-js-tests.yml +35 -0
  9. data/.github/workflows/rspec-package-specs.yml +45 -0
  10. data/.gitignore +0 -3
  11. data/.prettierignore +2 -0
  12. data/.prettierrc +0 -3
  13. data/.rubocop.yml +48 -39
  14. data/.travis.yml +3 -1
  15. data/CHANGELOG.md +112 -25
  16. data/CONTRIBUTING.md +4 -3
  17. data/Gemfile +1 -33
  18. data/Gemfile.development_dependencies +52 -0
  19. data/NEWS.md +14 -4
  20. data/REACT-ON-RAILS-PRO-LICENSE +1 -1
  21. data/README.md +42 -324
  22. data/Rakefile +1 -1
  23. data/SUMMARY.md +22 -13
  24. data/docs/{basics → additional-details}/generator-details.md +1 -6
  25. data/docs/{outdated → additional-details}/manual-installation-overview.md +6 -6
  26. data/docs/additional-details/recommended-project-structure.md +69 -0
  27. data/docs/additional-details/upgrade-webpacker-v3-to-v4.md +10 -0
  28. data/docs/api/javascript-api.md +2 -2
  29. data/docs/api/redux-store-api.md +3 -3
  30. data/docs/api/view-helpers-api.md +7 -8
  31. data/docs/contributor-info/linters.md +5 -6
  32. data/docs/contributor-info/pull-requests.md +2 -4
  33. data/docs/contributor-info/releasing.md +1 -1
  34. data/docs/{basics → deployment}/heroku-deployment.md +16 -5
  35. data/docs/{basics → guides}/client-vs-server-rendering.md +4 -2
  36. data/docs/{basics → guides}/configuration.md +65 -31
  37. data/docs/guides/deployment.md +4 -0
  38. data/docs/guides/getting-started.md +183 -0
  39. data/docs/guides/hmr-and-hot-reloading-with-the-webpack-dev-server.md +104 -0
  40. data/docs/{outdated → guides}/how-react-on-rails-works.md +10 -10
  41. data/docs/guides/how-to-conditionally-server-render-based-on-device-type.md +39 -0
  42. data/docs/guides/how-to-use-different-files-for-client-and-server-rendering.md +98 -0
  43. data/docs/{basics → guides}/installation-into-an-existing-rails-app.md +14 -7
  44. data/docs/guides/rails-webpacker-react-integration-options.md +182 -0
  45. data/docs/guides/react-on-rails-overview.md +30 -0
  46. data/docs/{basics → guides}/react-server-rendering.md +8 -5
  47. data/docs/{basics → guides}/rspec-configuration.md +11 -11
  48. data/docs/{tutorial.md → guides/tutorial.md} +46 -50
  49. data/docs/{basics → guides}/upgrading-react-on-rails.md +56 -18
  50. data/docs/guides/webpack-configuration.md +42 -0
  51. data/docs/home.md +23 -0
  52. data/docs/{outdated → javascript}/code-splitting.md +5 -5
  53. data/docs/{additional-reading → javascript}/converting-from-custom-webpack-config-to-rails-webpacker-config.md +4 -4
  54. data/docs/{additional-reading → javascript}/images.md +5 -6
  55. data/docs/{articles.md → misc/articles.md} +1 -1
  56. data/docs/misc/doctrine.md +5 -6
  57. data/docs/outdated/deferred-rendering.md +39 -0
  58. data/docs/outdated/rails-assets-relative-paths.md +3 -3
  59. data/docs/outdated/rails-assets.md +8 -8
  60. data/docs/outdated/rails3.md +2 -2
  61. data/docs/{additional-reading → rails}/convert-rails-5-api-only-app.md +1 -1
  62. data/docs/{additional-reading → rails}/rails-engine-integration.md +3 -12
  63. data/docs/{additional-reading → rails}/turbolinks.md +13 -1
  64. data/docs/react-on-rails-pro/react-on-rails-pro.md +43 -0
  65. data/docs/testimonials/testimonials.md +6 -6
  66. data/lib/generators/react_on_rails/base_generator.rb +64 -12
  67. data/lib/generators/react_on_rails/dev_tests_generator.rb +1 -1
  68. data/lib/generators/react_on_rails/generator_helper.rb +4 -0
  69. data/lib/generators/react_on_rails/templates/.eslintrc +3 -1
  70. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev +4 -8
  71. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-static +9 -0
  72. data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +2 -1
  73. data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.module.css +4 -0
  74. data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorldServer.js +5 -0
  75. data/lib/generators/react_on_rails/templates/base/base/app/javascript/packs/server-bundle.js +8 -0
  76. data/lib/generators/react_on_rails/templates/base/base/app/views/layouts/hello_world.html.erb +1 -0
  77. data/lib/generators/react_on_rails/templates/base/base/babel.config.js.tt +32 -0
  78. data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +3 -3
  79. data/lib/generators/react_on_rails/templates/base/base/config/webpack/clientWebpackConfig.js.tt +17 -0
  80. data/lib/generators/react_on_rails/templates/base/base/config/webpack/commonWebpackConfig.js.tt +15 -0
  81. data/lib/generators/react_on_rails/templates/base/base/config/webpack/development.js.tt +25 -0
  82. data/lib/generators/react_on_rails/templates/base/base/config/webpack/production.js.tt +9 -0
  83. data/lib/generators/react_on_rails/templates/base/base/config/webpack/serverWebpackConfig.js.tt +117 -0
  84. data/lib/generators/react_on_rails/templates/base/base/config/webpack/test.js.tt +6 -0
  85. data/lib/generators/react_on_rails/templates/base/base/config/webpack/webpack.config.js.tt +15 -0
  86. data/lib/generators/react_on_rails/templates/base/base/config/webpack/webpackConfig.js.tt +36 -0
  87. data/lib/generators/react_on_rails/templates/base/base/config/webpacker.yml +62 -0
  88. data/lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb +8 -2
  89. data/lib/generators/react_on_rails/templates/dev_tests/spec/simplecov_helper.rb +1 -1
  90. data/lib/generators/react_on_rails/templates/dev_tests/spec/{features → system}/hello_world_spec.rb +2 -2
  91. data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +2 -1
  92. data/lib/react_on_rails/configuration.rb +42 -41
  93. data/lib/react_on_rails/git_utils.rb +3 -3
  94. data/lib/react_on_rails/helper.rb +54 -28
  95. data/lib/react_on_rails/json_parse_error.rb +1 -1
  96. data/lib/react_on_rails/locales/base.rb +11 -15
  97. data/lib/react_on_rails/locales/to_js.rb +0 -4
  98. data/lib/react_on_rails/locales/to_json.rb +0 -4
  99. data/lib/react_on_rails/prerender_error.rb +6 -3
  100. data/lib/react_on_rails/react_component/render_options.rb +30 -7
  101. data/lib/react_on_rails/server_rendering_js_code.rb +13 -0
  102. data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +41 -13
  103. data/lib/react_on_rails/test_helper/webpack_assets_compiler.rb +1 -1
  104. data/lib/react_on_rails/test_helper/webpack_assets_status_checker.rb +3 -3
  105. data/lib/react_on_rails/test_helper.rb +4 -2
  106. data/lib/react_on_rails/utils.rb +24 -4
  107. data/lib/react_on_rails/version.rb +1 -1
  108. data/lib/react_on_rails/webpacker_utils.rb +9 -10
  109. data/lib/tasks/assets.rake +19 -50
  110. data/lib/tasks/locale.rake +1 -2
  111. data/package.json +24 -29
  112. data/rakelib/docker.rake +0 -5
  113. data/rakelib/example_type.rb +10 -3
  114. data/rakelib/examples.rake +3 -5
  115. data/rakelib/lint.rake +3 -9
  116. data/rakelib/release.rake +35 -15
  117. data/rakelib/run_rspec.rake +10 -11
  118. data/rakelib/task_helpers.rb +16 -4
  119. data/react_on_rails.gemspec +5 -20
  120. data/yarn.lock +2616 -5190
  121. metadata +86 -256
  122. data/.release-it.json +0 -3
  123. data/docs/additional-reading/upgrade-webpacker-v3-to-v4.md +0 -10
  124. data/docs/additional-reading/webpack-dev-server.md +0 -15
  125. data/docs/basics/deployment.md +0 -4
  126. data/docs/basics/hmr-and-hot-reloading-with-the-webpack-dev-server.md +0 -49
  127. data/docs/basics/recommended-project-structure.md +0 -77
  128. data/docs/basics/webpack-configuration.md +0 -50
  129. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-hmr +0 -26
  130. data/ruby-lint.yml +0 -25
  131. /data/docs/{basics → additional-details}/migrating-from-react-rails.md +0 -0
  132. /data/docs/{additional-reading → additional-details}/updating-dependencies.md +0 -0
  133. /data/docs/{additional-reading → deployment}/elastic-beanstalk.md +0 -0
  134. /data/docs/{basics → guides}/i18n.md +0 -0
  135. /data/docs/{basics → guides}/minitest-configuration.md +0 -0
  136. /data/docs/{basics → guides}/render-functions-and-railscontext.md +0 -0
  137. /data/docs/{additional-reading → javascript}/angular-js-integration-migration.md +0 -0
  138. /data/docs/{additional-reading → javascript}/asset-pipeline.md +0 -0
  139. /data/docs/{additional-reading → javascript}/capistrano-deployment.md +0 -0
  140. /data/docs/{additional-reading → javascript}/credits.md +0 -0
  141. /data/docs/{additional-reading → javascript}/foreman-issues.md +0 -0
  142. /data/docs/{additional-reading → javascript}/node-dependencies-and-npm.md +0 -0
  143. /data/docs/{additional-reading → javascript}/react-and-redux.md +0 -0
  144. /data/docs/{additional-reading → javascript}/react-helmet.md +0 -0
  145. /data/docs/{additional-reading → javascript}/react-router.md +0 -0
  146. /data/docs/{additional-reading → javascript}/server-rendering-tips.md +0 -0
  147. /data/docs/{additional-reading → javascript}/troubleshooting-when-using-webpacker.md +0 -0
  148. /data/docs/{additional-reading → javascript}/webpack-v1-notes.md +0 -0
  149. /data/docs/{additional-reading → javascript}/webpack.md +0 -0
  150. /data/docs/{coding-style → misc}/style.md +0 -0
  151. /data/docs/{additional-reading → misc}/tips.md +0 -0
  152. /data/docs/{additional-reading → rails}/rails_view_rendering_from_inline_javascript.md +0 -0
@@ -34,7 +34,7 @@ module ReactOnRails
34
34
  end
35
35
 
36
36
  def self.object_to_boolean(value)
37
- [true, "true", "yes", 1, "1", "t"].include?(value.class == String ? value.downcase : value)
37
+ [true, "true", "yes", 1, "1", "t"].include?(value.instance_of?(String) ? value.downcase : value)
38
38
  end
39
39
 
40
40
  def self.server_rendering_is_enabled?
@@ -71,7 +71,11 @@ module ReactOnRails
71
71
  # 1. Using same bundle for both server and client, so server bundle will be hashed in manifest
72
72
  # 2. Using a different bundle (different Webpack config), so file is not hashed, and
73
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
74
+ # 3. The third option of having the server bundle hashed and a different configuration than
75
+ # the client bundle is not supported for 2 reasons:
76
+ # a. The webpack manifest plugin would have a race condition where the same manifest.json
77
+ # is edited by both the webpack-dev-server
78
+ # b. There is no good reason to hash the server bundle name.
75
79
  return @server_bundle_path if @server_bundle_path && !Rails.env.development?
76
80
 
77
81
  bundle_name = ReactOnRails.configuration.server_bundle_js_file
@@ -114,9 +118,11 @@ module ReactOnRails
114
118
  end
115
119
  end
116
120
 
121
+ # rubocop:disable Naming/VariableNumber
117
122
  def self.rails_version_less_than_4_1_1
118
123
  rails_version_less_than("4.1.1")
119
124
  end
125
+ # rubocop:enable Naming/VariableNumber
120
126
 
121
127
  module Required
122
128
  def required(arg_name)
@@ -152,15 +158,29 @@ module ReactOnRails
152
158
  end
153
159
 
154
160
  def self.gem_available?(name)
155
- Gem::Specification.find_all_by_name(name).present?
161
+ Gem.loaded_specs[name].present?
156
162
  rescue Gem::LoadError
157
163
  false
158
164
  rescue StandardError
159
165
  Gem.available?(name).present?
160
166
  end
161
167
 
168
+ # Todo -- remove this for v13, as we don't need both boolean and number
162
169
  def self.react_on_rails_pro?
163
- @react_on_rails_pro ||= gem_available?("react_on_rails_pro")
170
+ return @react_on_rails_pro if defined?(@react_on_rails_pro)
171
+
172
+ @react_on_rails_pro = gem_available?("react_on_rails_pro")
173
+ end
174
+
175
+ # Return an empty string if React on Rails Pro is not installed
176
+ def self.react_on_rails_pro_version
177
+ return @react_on_rails_pro_version if defined?(@react_on_rails_pro_version)
178
+
179
+ @react_on_rails_pro_version = if react_on_rails_pro?
180
+ Gem.loaded_specs["react_on_rails_pro"].version.to_s
181
+ else
182
+ ""
183
+ end
164
184
  end
165
185
 
166
186
  def self.smart_trim(str, max_length = 1000)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReactOnRails
4
- VERSION = "12.0.1"
4
+ VERSION = "13.0.0"
5
5
  end
@@ -2,14 +2,13 @@
2
2
 
3
3
  module ReactOnRails
4
4
  module WebpackerUtils
5
+ # TODO: V13 code should be cleaned up so that the webpacker gem is required.
6
+ # This check should only be done at startup.
5
7
  def self.using_webpacker?
6
- ReactOnRails::Utils.gem_available?("webpacker")
7
- end
8
+ return @using_webpacker if defined?(@using_webpacker)
8
9
 
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)
10
+ @using_webpacker = ReactOnRails::Utils.gem_available?("webpacker") ||
11
+ ReactOnRails::Utils.gem_available?("shakapacker")
13
12
  end
14
13
 
15
14
  def self.dev_server_running?
@@ -28,10 +27,10 @@ module ReactOnRails
28
27
  # Next line will throw if the file or manifest does not exist
29
28
  hashed_bundle_name = Webpacker.manifest.lookup!(bundle_name)
30
29
 
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.
30
+ # Support for hashing the server-bundle and having that built
31
+ # the webpack-dev-server is provided by the config value
32
+ # "same_bundle_for_client_and_server" where a value of true
33
+ # would mean that the bundle is created by the webpack-dev-server
35
34
  is_server_bundle = bundle_name == ReactOnRails.configuration.server_bundle_js_file
36
35
 
37
36
  if Webpacker.dev_server.running? && (!is_server_bundle ||
@@ -1,64 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Important: The default assets:precompile is modified ONLY if the rails/webpacker webpack config
4
- # does not exist!
5
-
6
- require "active_support"
7
-
8
- ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
9
- ENV["NODE_ENV"] ||= "development"
10
-
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"
15
-
16
- precompile_tasks = lambda {
17
- Rake::Task["react_on_rails:assets:webpack"].invoke
18
- puts "Invoking task webpacker:clean from React on Rails"
19
-
20
- # VERSIONS is per the rails/webpacker clean method definition.
21
- # We set it very big so that it is not used, and then clean just
22
- # removes files older than 1 hour.
23
- VERSIONS = 100_000
24
- Rake::Task["webpacker:clean"].invoke(VERSIONS)
25
- }
26
-
27
- if Rake::Task.task_defined?("assets:precompile")
28
- Rake::Task["assets:precompile"].enhance do
29
- precompile_tasks.call
30
- end
31
- else
32
- Rake::Task.define_task("assets:precompile") do
33
- precompile_tasks.call
34
- end
35
- end
36
- end
37
-
38
- # Sprockets independent tasks
39
3
  # rubocop:disable Metrics/BlockLength
40
4
  namespace :react_on_rails do
41
5
  namespace :assets do
42
- desc <<-DESC.strip_heredoc
43
- Compile assets with webpack
44
- Uses command defined with ReactOnRails.configuration.build_production_command
45
- sh "#{ReactOnRails::Utils.prepend_cd_node_modules_directory('<ReactOnRails.configuration.build_production_command>')}"
46
- Note: This command is not automatically added to assets:precompile if the rails/webpacker
47
- configuration file config/webpack/production.js exists.
6
+ desc <<~DESC
7
+ If config.build_production_command is defined, this command is automatically
8
+ added to task assets:precompile and the regular webpacker compile will not run.
9
+ The defined command is either a script or a module with a method `call`.
48
10
  DESC
49
11
  task webpack: :locale do
50
- if ReactOnRails.configuration.build_production_command.present?
51
- sh ReactOnRails::Utils.prepend_cd_node_modules_directory(
52
- ReactOnRails.configuration.build_production_command
53
- ).to_s
12
+ build_production_command = ReactOnRails.configuration.build_production_command
13
+ if build_production_command.present?
14
+ if build_production_command.is_a?(String)
15
+ sh ReactOnRails::Utils.prepend_cd_node_modules_directory(
16
+ build_production_command
17
+ ).to_s
18
+ elsif build_production_command.methods.include?(:call)
19
+ build_production_command.call
20
+ else
21
+ msg = "ReactonRails.configuration.build_production_command is improperly configured. "\
22
+ "Value = #{build_production_command} with class #{build_production_command.class}"
23
+ puts Rainbow(msg).red
24
+ exit!(1)
25
+ end
54
26
  else
27
+ # Left in this warning message in case this rake task is run directly
55
28
  msg = <<~MSG
56
29
  React on Rails is aborting webpack compilation from task react_on_rails:assets:webpack
57
30
  because you do not have the `config.build_production_command` defined.
58
-
59
- Note, this task may have run as part of `assets:precompile`. If file
60
- config/webpack/production.js does not exist, React on Rails will modify
61
- the default `asset:precompile` to run task `react_on_rails:assets:webpack`.
62
31
  MSG
63
32
  puts Rainbow(msg).red
64
33
  exit!(1)
@@ -3,10 +3,9 @@
3
3
  require "react_on_rails/locales/base"
4
4
  require "react_on_rails/locales/to_js"
5
5
  require "react_on_rails/locales/to_json"
6
- require "active_support"
7
6
 
8
7
  namespace :react_on_rails do
9
- desc <<-DESC.strip_heredoc
8
+ desc <<~DESC
10
9
  Generate i18n javascript files
11
10
  This task generates javascript locale files: `translations.js` & `default.js` and places them in
12
11
  the "ReactOnRails.configuration.i18n_dir".
data/package.json CHANGED
@@ -1,56 +1,51 @@
1
1
  {
2
2
  "name": "react-on-rails",
3
- "version": "12.0.1",
3
+ "version": "13.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": "^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",
10
+ "@babel/cli": "^7.12.10",
11
+ "@babel/core": "^7.12.10",
12
+ "@babel/plugin-transform-runtime": "^7.12.10",
13
+ "@babel/plugin-transform-typescript": "^7.12.1",
14
+ "@babel/preset-env": "^7.12.10",
15
+ "@babel/preset-react": "^7.12.10",
16
+ "@babel/types": "^7.12.10",
17
+ "@types/jest": "^26.0.18",
18
+ "@types/node": "^14.14.11",
19
19
  "@types/react": "^16.9.23",
20
20
  "@types/react-dom": "^16.9.5",
21
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",
22
+ "@typescript-eslint/eslint-plugin": "^4.10.0",
23
+ "@typescript-eslint/parser": "^4.10.0",
25
24
  "babelify": "^10.0.0",
26
25
  "blue-tape": "^1.0.0",
27
26
  "create-react-class": "^15.6.0",
28
- "eslint": "^6.8.0",
29
- "eslint-config-prettier": "^6.10.1",
27
+ "eslint": "^7.15.0",
28
+ "eslint-config-prettier": "^7.0.0",
30
29
  "eslint-config-shakacode": "^16.0.1",
31
- "eslint-plugin-import": "^2.6.1",
32
- "eslint-plugin-jsx-a11y": "^6.1.2",
33
- "eslint-plugin-prettier": "^3.0.0",
34
- "eslint-plugin-react": "^7.1.0",
35
- "jest": "^25.1.0",
36
- "jsdom": "^11.1.0",
30
+ "eslint-plugin-import": "^2.22.1",
31
+ "eslint-plugin-jsx-a11y": "^6.4.1",
32
+ "eslint-plugin-prettier": "^3.3.0",
33
+ "eslint-plugin-react": "^7.21.5",
34
+ "jest": "^26.6.3",
35
+ "jsdom": "^16.4.0",
37
36
  "nps": "^5.9.3",
38
- "prettier": "^2.0.1",
37
+ "prettier": "^2.2.1",
39
38
  "prettier-eslint-cli": "^5.0.0",
40
39
  "prop-types": "^15.5.10",
41
40
  "react": "^16.5.2",
42
41
  "react-dom": "^16.5.2",
43
42
  "react-transform-hmr": "^1.0.4",
44
43
  "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",
49
- "webpack": "^3.4.1",
50
- "webpack-manifest-plugin": "^1.2.1"
44
+ "ts-jest": "^26.4.4",
45
+ "typescript": "^4.1.2"
51
46
  },
52
47
  "dependencies": {
53
- "@babel/runtime-corejs3": "^7.9.6",
48
+ "@babel/runtime-corejs3": "^7.12.5",
54
49
  "concurrently": "^5.1.0"
55
50
  },
56
51
  "peerDependencies": {
data/rakelib/docker.rake CHANGED
@@ -6,11 +6,6 @@ namespace :docker do
6
6
  sh "docker-compose run lint rake lint:rubocop"
7
7
  end
8
8
 
9
- desc "Run ruby-lint linter from docker"
10
- task :ruby do
11
- sh "docker-compose run lint rake lint:ruby"
12
- end
13
-
14
9
  desc "Run scss-lint linter from docker"
15
10
  task :scss do
16
11
  sh "docker-compose run lint rake lint:scss"
@@ -45,14 +45,21 @@ module ReactOnRails
45
45
  # Gems we need to add to the Gemfile before bundle installing
46
46
  def required_gems
47
47
  relative_gem_root = Pathname(gem_root).relative_path_from(Pathname(dir))
48
- ["gem 'react_on_rails', path: '#{relative_gem_root}'"]
48
+ [
49
+ "gem 'react_on_rails', path: '#{relative_gem_root}'",
50
+ "gem 'shakapacker'"
51
+ ]
49
52
  end
50
53
 
51
54
  # Options we pass when running `rails new` from the command-line.
52
55
  attr_writer :rails_options
53
56
 
54
57
  def rails_options
55
- @rails_options ||= "--skip-bundle --skip-spring --skip-git --skip-test-unit --skip-active-record"
58
+ @rails_options ||= if ReactOnRails::Utils.rails_version_less_than("7.0")
59
+ "--skip-bundle --skip-spring --skip-git --skip-test-unit --skip-active-record -J"
60
+ else
61
+ "--skip-bundle --skip-spring --skip-git --skip-test-unit --skip-active-record -j webpack"
62
+ end
56
63
  end
57
64
 
58
65
  %w[gen clobber npm_install build_webpack_bundles].each do |task_type|
@@ -74,7 +81,7 @@ module ReactOnRails
74
81
  # Assumes we are inside a rails app's folder and necessary gems have been installed
75
82
  def generator_shell_commands
76
83
  shell_commands = []
77
- shell_commands << "rails generate react_on_rails:install #{generator_options} --ignore-warnings"
84
+ shell_commands << "rails generate react_on_rails:install #{generator_options} --ignore-warnings --force"
78
85
  shell_commands << "rails generate react_on_rails:dev_tests #{generator_options}"
79
86
  end
80
87
 
@@ -16,7 +16,7 @@ namespace :examples do # rubocop:disable Metrics/BlockLength
16
16
  # Loads data from examples_config.yml and instantiates corresponding ExampleType objects
17
17
  examples_config_file = File.expand_path("examples_config.yml", __dir__)
18
18
  examples_config = symbolize_keys(YAML.safe_load(File.read(examples_config_file)))
19
- examples_config[:example_type_data].each { |example_type_data| ExampleType.new(symbolize_keys(example_type_data)) }
19
+ examples_config[:example_type_data].each { |example_type_data| ExampleType.new(**symbolize_keys(example_type_data)) }
20
20
 
21
21
  # Define tasks for each example type
22
22
  ExampleType.all.each do |example_type|
@@ -30,14 +30,12 @@ namespace :examples do # rubocop:disable Metrics/BlockLength
30
30
  desc "Generates #{example_type.name_pretty}"
31
31
  task example_type.gen_task_name_short => example_type.clobber_task_name do
32
32
  mkdir_p(example_type.dir)
33
- example_type.rails_options += " --webpack" if Rails.version >= "5.1" && Rails.version < "6"
33
+ example_type.rails_options += "--skip-javascript"
34
34
  sh_in_dir(examples_dir, "rails new #{example_type.name} #{example_type.rails_options}")
35
35
  sh_in_dir(example_type.dir, "touch .gitignore")
36
- sh_in_dir(example_type.dir, "rake webpacker:install")
37
- sh_in_dir(example_type.dir, "bundle binstubs --path=#{example_type.dir}/bin webpacker")
38
- sh_in_dir(example_type.dir, "rake webpacker:install:react")
39
36
  append_to_gemfile(example_type.gemfile, example_type.required_gems)
40
37
  bundle_install_in(example_type.dir)
38
+ sh_in_dir(example_type.dir, "rake webpacker:install")
41
39
  sh_in_dir(example_type.dir, example_type.generator_shell_commands)
42
40
  sh_in_dir(example_type.dir, "yarn")
43
41
  end
data/rakelib/lint.rake CHANGED
@@ -7,13 +7,7 @@ namespace :lint do
7
7
 
8
8
  desc "Run Rubocop as shell"
9
9
  task :rubocop do
10
- sh_in_dir(gem_root, "bundle exec rubocop .")
11
- end
12
-
13
- desc "Run ruby-lint as shell"
14
- task :ruby do
15
- puts "See /ruby-lint.yml for what directories are included."
16
- sh_in_dir(gem_root, "bundle exec ruby-lint .")
10
+ sh_in_dir(gem_root, "bundle exec rubocop --version", "bundle exec rubocop .")
17
11
  end
18
12
 
19
13
  desc "Run scss-lint as shell"
@@ -23,10 +17,10 @@ namespace :lint do
23
17
 
24
18
  desc "Run eslint as shell"
25
19
  task :eslint do
26
- sh_in_dir(gem_root, "yarn run eslint")
20
+ sh_in_dir(gem_root, "yarn run eslint --version", "yarn run eslint .")
27
21
  end
28
22
 
29
- desc "Run all eslint & rubocop linters. Skip ruby-lint and scss"
23
+ desc "Run all eslint & rubocop linters. Skip scss"
30
24
  task lint: %i[eslint rubocop] do
31
25
  puts "Completed all linting"
32
26
  end
data/rakelib/release.rake CHANGED
@@ -1,9 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "bundler"
3
4
  require_relative "task_helpers"
4
5
  require_relative File.join(gem_root, "lib", "react_on_rails", "version_syntax_converter")
5
6
  require_relative File.join(gem_root, "lib", "react_on_rails", "git_utils")
6
7
  require_relative File.join(gem_root, "lib", "react_on_rails", "utils")
8
+
9
+ class RaisingMessageHandler
10
+ def add_error(error)
11
+ raise error
12
+ end
13
+ end
14
+
15
+ # rubocop:disable Metrics/BlockLength
16
+
7
17
  desc("Releases both the gem and node package using the given version.
8
18
 
9
19
  IMPORTANT: the gem version must be in valid rubygem format (no dashes).
@@ -12,26 +22,20 @@ for the node package version. This only makes a difference for pre-release
12
22
  versions such as `3.0.0.beta.1` (yarn version would be `3.0.0-beta.1`).
13
23
 
14
24
  This task depends on the gem-release (ruby gem) and release-it (node package)
15
- which are installed via `bundle install` and `yarn`
25
+ which are installed via `bundle install` and `yarn global add release-it`
16
26
 
17
27
  1st argument: The new version in rubygem format (no dashes). Pass no argument to
18
28
  automatically perform a patch version bump.
19
29
  2nd argument: Perform a dry run by passing 'true' as a second argument.
20
30
 
21
- Example: `rake release[2.1.0,false]`")
31
+ Note, accept defaults for npmjs options. Script will pause to get 2FA tokens.
22
32
 
23
- # rubocop:disable Metrics/BlockLength
33
+ Example: `rake release[2.1.0,false]`")
24
34
  task :release, %i[gem_version dry_run tools_install] do |_t, args|
25
35
  include ReactOnRails::TaskHelpers
26
36
 
27
- class MessageHandler
28
- def add_error(error)
29
- raise error
30
- end
31
- end
32
-
33
37
  # Check if there are uncommited changes
34
- ReactOnRails::GitUtils.uncommitted_changes?(MessageHandler.new)
38
+ ReactOnRails::GitUtils.uncommitted_changes?(RaisingMessageHandler.new)
35
39
  args_hash = args.to_hash
36
40
 
37
41
  is_dry_run = ReactOnRails::Utils.object_to_boolean(args_hash[:dry_run])
@@ -56,17 +60,33 @@ task :release, %i[gem_version dry_run tools_install] do |_t, args|
56
60
  # Update dummy app's Gemfile.lock
57
61
  bundle_install_in(dummy_app_dir)
58
62
 
59
- # Stage changes so far
60
- sh_in_dir(gem_root, "git add .")
61
-
63
+ puts "Carefully add your OTP for NPM. If you get an error, 'git reset --hard' and start over."
62
64
  # Will bump the yarn version, commit, tag the commit, push to repo, and release on yarn
63
- release_it_command = "$(yarn bin)/release-it".dup
65
+ release_it_command = +"release-it"
64
66
  release_it_command << " #{npm_version}" unless npm_version.strip.empty?
65
- release_it_command << " --non-interactive --npm.publish"
67
+ release_it_command << " --npm.publish --no-git.requireCleanWorkingDir"
66
68
  release_it_command << " --dry-run --verbose" if is_dry_run
67
69
  sh_in_dir(gem_root, release_it_command)
68
70
 
69
71
  # Release the new gem version
72
+
73
+ puts "Carefully add your OTP for Rubygems. If you get an error, run 'gem release' again."
70
74
  sh_in_dir(gem_root, "gem release") unless is_dry_run
75
+
76
+ msg = <<~MSG
77
+ Once you have successfully published, run these commands to update the spec apps:
78
+
79
+ cd #{dummy_app_dir}; bundle update react_on_rails
80
+ cd #{gem_root}#{' '}
81
+ git commit -a -m 'Update Gemfile.lock for spec app'
82
+ git push
83
+ MSG
84
+ puts msg
71
85
  end
72
86
  # rubocop:enable Metrics/BlockLength
87
+
88
+ task :test do
89
+ unbundled_sh_in_dir(gem_root, "cd #{dummy_app_dir}; bundle update react_on_rails")
90
+ sh_in_dir(gem_root, "git commit -a -m 'Update Gemfile.lock for spec app'")
91
+ sh_in_dir(gem_root, "git push")
92
+ end
@@ -86,16 +86,15 @@ task run_rspec: ["run_rspec:run_rspec"]
86
86
  private
87
87
 
88
88
  def calc_path(dir)
89
- path = if dir.is_a?(String)
90
- if dir.start_with?(File::SEPARATOR)
91
- Pathname.new(dir)
92
- else
93
- Pathname.new(File.join(gem_root, dir))
94
- end
95
- else
96
- dir
97
- end
98
- path
89
+ if dir.is_a?(String)
90
+ if dir.start_with?(File::SEPARATOR)
91
+ Pathname.new(dir)
92
+ else
93
+ Pathname.new(File.join(gem_root, dir))
94
+ end
95
+ else
96
+ dir
97
+ end
99
98
  end
100
99
 
101
100
  # Runs rspec in the given directory.
@@ -107,7 +106,7 @@ def run_tests_in(dir, options = {})
107
106
 
108
107
  command_name = options.fetch(:command_name, path.basename)
109
108
  rspec_args = options.fetch(:rspec_args, "")
110
- env_vars = "#{options.fetch(:env_vars, '')} TEST_ENV_COMMAND_NAME=\"#{command_name}\"".dup
109
+ env_vars = +"#{options.fetch(:env_vars, '')} TEST_ENV_COMMAND_NAME=\"#{command_name}\""
111
110
  env_vars << "COVERAGE=true" if ENV["USE_COVERALLS"]
112
111
  sh_in_dir(path.realpath, "#{env_vars} bundle exec rspec #{rspec_args}")
113
112
  end
@@ -16,14 +16,26 @@ module ReactOnRails
16
16
  File.join(gem_root, "spec/dummy")
17
17
  end
18
18
 
19
+ # Executes a string or an array of strings in a shell in the given directory in an unbundled environment
20
+ def sh_in_dir(dir, *shell_commands)
21
+ shell_commands.flatten.each { |shell_command| sh %(cd #{dir} && #{shell_command.strip}) }
22
+ end
23
+
19
24
  # Executes a string or an array of strings in a shell in the given directory
20
- def sh_in_dir(dir, shell_commands)
21
- shell_commands = [shell_commands] if shell_commands.is_a?(String)
22
- shell_commands.each { |shell_command| sh %(cd #{dir} && #{shell_command.strip}) }
25
+ def unbundled_sh_in_dir(dir, *shell_commands)
26
+ Dir.chdir(dir) do
27
+ # Without `with_unbundled_env`, running bundle in the child directories won't correctly
28
+ # update the Gemfile.lock
29
+ Bundler.with_unbundled_env do
30
+ shell_commands.flatten.each do |shell_command|
31
+ sh(shell_command.strip)
32
+ end
33
+ end
34
+ end
23
35
  end
24
36
 
25
37
  def bundle_install_in(dir)
26
- sh_in_dir(dir, "bundle install")
38
+ unbundled_sh_in_dir(dir, "bundle install")
27
39
  end
28
40
 
29
41
  def bundle_install_in_no_turbolinks(dir)
@@ -23,36 +23,21 @@ Gem::Specification.new do |s|
23
23
  s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
24
  s.require_paths = ["lib"]
25
25
 
26
- s.required_ruby_version = ">= 2.5.0"
26
+ s.required_ruby_version = ">= 2.7.0"
27
27
 
28
28
  s.add_dependency "addressable"
29
29
  s.add_dependency "connection_pool"
30
30
  s.add_dependency "execjs", "~> 2.5"
31
- s.add_dependency "rails", ">= 3.2"
31
+ s.add_dependency "rails", ">= 5.2"
32
32
  s.add_dependency "rainbow", "~> 3.0"
33
- s.add_dependency "webpacker", ">= 4.0"
34
33
 
35
- s.add_development_dependency "awesome_print"
36
34
  s.add_development_dependency "bundler", "~> 2"
37
- s.add_development_dependency "coveralls"
38
35
  s.add_development_dependency "gem-release"
39
- s.add_development_dependency "generator_spec"
40
- s.add_development_dependency "listen"
41
- s.add_development_dependency "pry"
42
- s.add_development_dependency "pry-byebug"
43
- s.add_development_dependency "pry-doc"
44
- s.add_development_dependency "pry-rescue"
45
- s.add_development_dependency "pry-state"
46
- s.add_development_dependency "rails", "~> 5.2"
47
-
48
- s.add_development_dependency "rake", "~> 10.0"
49
- s.add_development_dependency "rspec"
50
- s.add_development_dependency "rubocop", "0.85.0"
51
-
52
36
  s.post_install_message = '
53
37
  --------------------------------------------------------------------------------
54
- Email contact@shakacode.com for access to our slack room and information about our "pro support plan"
55
- which supports better performance, via caching helpers and our node rendering server.
38
+ Checkout https://www.shakacode.com/react-on-rails-pro for information about
39
+ "React on Rails Pro" which includes one hour a month of support and a gem for
40
+ better performance, via caching helpers, and our node rendering server.
56
41
  --------------------------------------------------------------------------------
57
42
  '
58
43
  end