react_on_rails 12.0.1 → 12.1.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 (105) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +12 -2
  3. data/.eslintrc +2 -1
  4. data/.github/workflows/lint-js-and-ruby.yml +53 -0
  5. data/.github/workflows/main.yml +178 -0
  6. data/.github/workflows/package-js-tests.yml +35 -0
  7. data/.github/workflows/rspec-package-specs.yml +45 -0
  8. data/.prettierrc +0 -3
  9. data/.rubocop.yml +46 -38
  10. data/.travis.yml +3 -1
  11. data/CHANGELOG.md +39 -11
  12. data/CONTRIBUTING.md +4 -3
  13. data/Gemfile +1 -33
  14. data/Gemfile.development_dependencies +51 -0
  15. data/NEWS.md +5 -0
  16. data/README.md +66 -57
  17. data/SUMMARY.md +1 -1
  18. data/docs/{basics → additional-details}/generator-details.md +1 -6
  19. data/docs/{outdated → additional-details}/manual-installation-overview.md +6 -6
  20. data/docs/additional-details/recommended-project-structure.md +69 -0
  21. data/docs/additional-details/upgrade-webpacker-v3-to-v4.md +10 -0
  22. data/docs/api/javascript-api.md +2 -2
  23. data/docs/api/redux-store-api.md +3 -3
  24. data/docs/api/view-helpers-api.md +7 -8
  25. data/docs/basics/client-vs-server-rendering.md +4 -2
  26. data/docs/basics/configuration.md +42 -25
  27. data/docs/basics/deployment.md +2 -2
  28. data/docs/basics/hmr-and-hot-reloading-with-the-webpack-dev-server.md +64 -9
  29. data/docs/{outdated → basics}/how-react-on-rails-works.md +8 -9
  30. data/docs/basics/installation-into-an-existing-rails-app.md +13 -6
  31. data/docs/basics/react-server-rendering.md +8 -5
  32. data/docs/basics/rspec-configuration.md +10 -10
  33. data/docs/{tutorial.md → basics/tutorial.md} +28 -30
  34. data/docs/basics/upgrading-react-on-rails.md +41 -18
  35. data/docs/basics/webpack-configuration.md +14 -22
  36. data/docs/contributor-info/linters.md +5 -6
  37. data/docs/contributor-info/pull-requests.md +2 -4
  38. data/docs/contributor-info/releasing.md +1 -1
  39. data/docs/home.md +382 -0
  40. data/docs/{outdated → javascript}/code-splitting.md +5 -5
  41. data/docs/{additional-reading → javascript}/converting-from-custom-webpack-config-to-rails-webpacker-config.md +3 -3
  42. data/docs/{additional-reading → javascript}/images.md +5 -6
  43. data/docs/{articles.md → misc/articles.md} +1 -1
  44. data/docs/misc/doctrine.md +5 -6
  45. data/docs/outdated/deferred-rendering.md +39 -0
  46. data/docs/outdated/rails-assets-relative-paths.md +3 -3
  47. data/docs/outdated/rails-assets.md +8 -8
  48. data/docs/outdated/rails3.md +2 -2
  49. data/docs/{additional-reading → rails}/convert-rails-5-api-only-app.md +1 -1
  50. data/docs/rails-webpacker-react-integration-options.md +182 -0
  51. data/docs/testimonials/testimonials.md +6 -6
  52. data/lib/generators/react_on_rails/base_generator.rb +8 -1
  53. data/lib/generators/react_on_rails/dev_tests_generator.rb +1 -1
  54. data/lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb +8 -2
  55. data/lib/generators/react_on_rails/templates/dev_tests/spec/simplecov_helper.rb +1 -1
  56. data/lib/generators/react_on_rails/templates/dev_tests/spec/{features → system}/hello_world_spec.rb +2 -2
  57. data/lib/react_on_rails/configuration.rb +2 -0
  58. data/lib/react_on_rails/git_utils.rb +3 -3
  59. data/lib/react_on_rails/helper.rb +15 -9
  60. data/lib/react_on_rails/locales/base.rb +3 -3
  61. data/lib/react_on_rails/locales/to_js.rb +0 -4
  62. data/lib/react_on_rails/locales/to_json.rb +0 -4
  63. data/lib/react_on_rails/prerender_error.rb +1 -1
  64. data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +6 -6
  65. data/lib/react_on_rails/test_helper/webpack_assets_compiler.rb +1 -1
  66. data/lib/react_on_rails/test_helper.rb +2 -0
  67. data/lib/react_on_rails/utils.rb +24 -4
  68. data/lib/react_on_rails/version.rb +1 -1
  69. data/lib/react_on_rails/webpacker_utils.rb +9 -5
  70. data/lib/tasks/assets.rake +20 -11
  71. data/package.json +24 -29
  72. data/rakelib/docker.rake +0 -5
  73. data/rakelib/lint.rake +3 -9
  74. data/rakelib/release.rake +27 -13
  75. data/rakelib/run_rspec.rake +10 -11
  76. data/rakelib/task_helpers.rb +16 -4
  77. data/react_on_rails.gemspec +3 -17
  78. data/yarn.lock +2272 -4960
  79. metadata +50 -225
  80. data/docs/additional-reading/upgrade-webpacker-v3-to-v4.md +0 -10
  81. data/docs/additional-reading/webpack-dev-server.md +0 -15
  82. data/docs/basics/recommended-project-structure.md +0 -77
  83. data/ruby-lint.yml +0 -25
  84. /data/docs/{basics → additional-details}/migrating-from-react-rails.md +0 -0
  85. /data/docs/{additional-reading → additional-details}/updating-dependencies.md +0 -0
  86. /data/docs/{additional-reading → deployment}/elastic-beanstalk.md +0 -0
  87. /data/docs/{basics → deployment}/heroku-deployment.md +0 -0
  88. /data/docs/{additional-reading → javascript}/angular-js-integration-migration.md +0 -0
  89. /data/docs/{additional-reading → javascript}/asset-pipeline.md +0 -0
  90. /data/docs/{additional-reading → javascript}/capistrano-deployment.md +0 -0
  91. /data/docs/{additional-reading → javascript}/credits.md +0 -0
  92. /data/docs/{additional-reading → javascript}/foreman-issues.md +0 -0
  93. /data/docs/{additional-reading → javascript}/node-dependencies-and-npm.md +0 -0
  94. /data/docs/{additional-reading → javascript}/react-and-redux.md +0 -0
  95. /data/docs/{additional-reading → javascript}/react-helmet.md +0 -0
  96. /data/docs/{additional-reading → javascript}/react-router.md +0 -0
  97. /data/docs/{additional-reading → javascript}/server-rendering-tips.md +0 -0
  98. /data/docs/{additional-reading → javascript}/troubleshooting-when-using-webpacker.md +0 -0
  99. /data/docs/{additional-reading → javascript}/webpack-v1-notes.md +0 -0
  100. /data/docs/{additional-reading → javascript}/webpack.md +0 -0
  101. /data/docs/{coding-style → misc}/style.md +0 -0
  102. /data/docs/{additional-reading → misc}/tips.md +0 -0
  103. /data/docs/{additional-reading → rails}/rails-engine-integration.md +0 -0
  104. /data/docs/{additional-reading → rails}/rails_view_rendering_from_inline_javascript.md +0 -0
  105. /data/docs/{additional-reading → rails}/turbolinks.md +0 -0
@@ -6,7 +6,6 @@
6
6
  require "active_support"
7
7
 
8
8
  ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
9
- ENV["NODE_ENV"] ||= "development"
10
9
 
11
10
  unless ReactOnRails::WebpackerUtils.webpacker_webpack_production_config_exists?
12
11
  # Ensure that rails/webpacker does not call bin/webpack if we're providing
@@ -20,8 +19,8 @@ unless ReactOnRails::WebpackerUtils.webpacker_webpack_production_config_exists?
20
19
  # VERSIONS is per the rails/webpacker clean method definition.
21
20
  # We set it very big so that it is not used, and then clean just
22
21
  # removes files older than 1 hour.
23
- VERSIONS = 100_000
24
- Rake::Task["webpacker:clean"].invoke(VERSIONS)
22
+ versions = 100_000
23
+ Rake::Task["webpacker:clean"].invoke(versions)
25
24
  }
26
25
 
27
26
  if Rake::Task.task_defined?("assets:precompile")
@@ -40,17 +39,27 @@ end
40
39
  namespace :react_on_rails do
41
40
  namespace :assets do
42
41
  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
42
+ Compile assets with webpack
43
+ Uses command defined with ReactOnRails.configuration.build_production_command
44
+ sh "#{ReactOnRails::Utils.prepend_cd_node_modules_directory('<ReactOnRails.configuration.build_production_command>')}"
45
+ Note: This command is not automatically added to assets:precompile if the rails/webpacker
47
46
  configuration file config/webpack/production.js exists.
48
47
  DESC
49
48
  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
49
+ build_production_command = ReactOnRails.configuration.build_production_command
50
+ if build_production_command.present?
51
+ if build_production_command.is_a?(String)
52
+ sh ReactOnRails::Utils.prepend_cd_node_modules_directory(
53
+ build_production_command
54
+ ).to_s
55
+ elsif build_production_command.methods.include?(:call)
56
+ build_production_command.call
57
+ else
58
+ msg = "ReactonRails.configuration.build_production_command is improperly configured. "\
59
+ "Value = #{build_production_command} with class #{build_production_command.class}"
60
+ puts Rainbow(msg).red
61
+ exit!(1)
62
+ end
54
63
  else
55
64
  msg = <<~MSG
56
65
  React on Rails is aborting webpack compilation from task react_on_rails:assets:webpack
data/package.json CHANGED
@@ -1,56 +1,51 @@
1
1
  {
2
2
  "name": "react-on-rails",
3
- "version": "12.0.1",
3
+ "version": "12.1.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"
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
@@ -4,6 +4,15 @@ require_relative "task_helpers"
4
4
  require_relative File.join(gem_root, "lib", "react_on_rails", "version_syntax_converter")
5
5
  require_relative File.join(gem_root, "lib", "react_on_rails", "git_utils")
6
6
  require_relative File.join(gem_root, "lib", "react_on_rails", "utils")
7
+
8
+ class RaisingMessageHandler
9
+ def add_error(error)
10
+ raise error
11
+ end
12
+ end
13
+
14
+ # rubocop:disable Metrics/BlockLength
15
+
7
16
  desc("Releases both the gem and node package using the given version.
8
17
 
9
18
  IMPORTANT: the gem version must be in valid rubygem format (no dashes).
@@ -19,19 +28,11 @@ which are installed via `bundle install` and `yarn`
19
28
  2nd argument: Perform a dry run by passing 'true' as a second argument.
20
29
 
21
30
  Example: `rake release[2.1.0,false]`")
22
-
23
- # rubocop:disable Metrics/BlockLength
24
31
  task :release, %i[gem_version dry_run tools_install] do |_t, args|
25
32
  include ReactOnRails::TaskHelpers
26
33
 
27
- class MessageHandler
28
- def add_error(error)
29
- raise error
30
- end
31
- end
32
-
33
34
  # Check if there are uncommited changes
34
- ReactOnRails::GitUtils.uncommitted_changes?(MessageHandler.new)
35
+ ReactOnRails::GitUtils.uncommitted_changes?(RaisingMessageHandler.new)
35
36
  args_hash = args.to_hash
36
37
 
37
38
  is_dry_run = ReactOnRails::Utils.object_to_boolean(args_hash[:dry_run])
@@ -56,11 +57,8 @@ task :release, %i[gem_version dry_run tools_install] do |_t, args|
56
57
  # Update dummy app's Gemfile.lock
57
58
  bundle_install_in(dummy_app_dir)
58
59
 
59
- # Stage changes so far
60
- sh_in_dir(gem_root, "git add .")
61
-
62
60
  # 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
61
+ release_it_command = +"$(yarn bin)/release-it"
64
62
  release_it_command << " #{npm_version}" unless npm_version.strip.empty?
65
63
  release_it_command << " --non-interactive --npm.publish"
66
64
  release_it_command << " --dry-run --verbose" if is_dry_run
@@ -68,5 +66,21 @@ task :release, %i[gem_version dry_run tools_install] do |_t, args|
68
66
 
69
67
  # Release the new gem version
70
68
  sh_in_dir(gem_root, "gem release") unless is_dry_run
69
+
70
+ msg = <<~MSG
71
+ Once you have successfully published, run these commands to update the spec apps:
72
+
73
+ cd #{dummy_app_dir}; bundle update react_on_rails
74
+ cd #{gem_root}#{' '}
75
+ git commit -a -m 'Update Gemfile.lock for spec app'
76
+ git push
77
+ MSG
78
+ puts msg
71
79
  end
72
80
  # rubocop:enable Metrics/BlockLength
81
+
82
+ task :test do
83
+ unbundled_sh_in_dir(gem_root, "cd #{dummy_app_dir}; bundle update react_on_rails")
84
+ sh_in_dir(gem_root, "git commit -a -m 'Update Gemfile.lock for spec app'")
85
+ sh_in_dir(gem_root, "git push")
86
+ 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)
@@ -32,27 +32,13 @@ Gem::Specification.new do |s|
32
32
  s.add_dependency "rainbow", "~> 3.0"
33
33
  s.add_dependency "webpacker", ">= 4.0"
34
34
 
35
- s.add_development_dependency "awesome_print"
36
35
  s.add_development_dependency "bundler", "~> 2"
37
- s.add_development_dependency "coveralls"
38
36
  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
37
  s.post_install_message = '
53
38
  --------------------------------------------------------------------------------
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.
39
+ Checkout https://www.shakacode.com/react-on-rails-pro for information about
40
+ "React on Rails Pro" which includes one hour a month of support and a gem for
41
+ better performance, via caching helpers, and our node rendering server.
56
42
  --------------------------------------------------------------------------------
57
43
  '
58
44
  end