react_on_rails 11.0.5 → 13.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +338 -0
  3. data/.eslintignore +2 -1
  4. data/.eslintrc +32 -3
  5. data/.github/FUNDING.yml +1 -0
  6. data/.github/ISSUE_TEMPLATE/bug_report.md +23 -0
  7. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  8. data/.github/PULL_REQUEST_TEMPLATE.md +19 -0
  9. data/.github/workflows/lint-js-and-ruby.yml +54 -0
  10. data/.github/workflows/main.yml +183 -0
  11. data/.github/workflows/package-js-tests.yml +35 -0
  12. data/.github/workflows/rspec-package-specs.yml +46 -0
  13. data/.gitignore +3 -4
  14. data/.prettierignore +14 -0
  15. data/.prettierrc +20 -0
  16. data/.rubocop.yml +76 -34
  17. data/.travis.yml +15 -22
  18. data/CHANGELOG.md +443 -55
  19. data/CONTRIBUTING.md +62 -80
  20. data/Gemfile +1 -35
  21. data/Gemfile.development_dependencies +50 -0
  22. data/KUDOS.md +4 -1
  23. data/{docs/LICENSE.md → LICENSE.md} +1 -1
  24. data/NEWS.md +14 -4
  25. data/REACT-ON-RAILS-PRO-LICENSE +95 -0
  26. data/README.md +107 -802
  27. data/Rakefile +1 -8
  28. data/SUMMARY.md +51 -29
  29. data/book.json +5 -5
  30. data/docs/{basics/generator.md → additional-details/generator-details.md} +5 -13
  31. data/docs/{basics/installation-overview.md → additional-details/manual-installation-overview.md} +9 -14
  32. data/docs/{basics → additional-details}/migrating-from-react-rails.md +1 -1
  33. data/docs/additional-details/recommended-project-structure.md +69 -0
  34. data/docs/additional-details/tips-for-usage-with-sp6.md +15 -0
  35. data/docs/additional-details/upgrade-webpacker-v3-to-v4.md +10 -0
  36. data/docs/api/javascript-api.md +35 -6
  37. data/docs/api/redux-store-api.md +102 -0
  38. data/docs/api/view-helpers-api.md +133 -0
  39. data/docs/contributor-info/errors-with-hooks.md +45 -0
  40. data/docs/contributor-info/linters.md +5 -6
  41. data/docs/contributor-info/pull-requests.md +42 -0
  42. data/docs/contributor-info/releasing.md +1 -1
  43. data/docs/deployment/heroku-deployment.md +39 -0
  44. data/docs/getting-started.md +196 -0
  45. data/docs/guides/client-vs-server-rendering.md +27 -0
  46. data/docs/guides/configuration.md +289 -0
  47. data/docs/guides/deployment.md +5 -0
  48. data/docs/guides/file-system-based-automated-bundle-generation.md +197 -0
  49. data/docs/guides/hmr-and-hot-reloading-with-the-webpack-dev-server.md +104 -0
  50. data/docs/guides/how-react-on-rails-works.md +44 -0
  51. data/docs/guides/how-to-conditionally-server-render-based-on-device-type.md +40 -0
  52. data/docs/guides/how-to-use-different-files-for-client-and-server-rendering.md +98 -0
  53. data/docs/guides/i18n.md +87 -0
  54. data/docs/guides/installation-into-an-existing-rails-app.md +66 -0
  55. data/docs/guides/minitest-configuration.md +31 -0
  56. data/docs/guides/rails-webpacker-react-integration-options.md +213 -0
  57. data/docs/guides/react-on-rails-overview.md +29 -0
  58. data/docs/guides/react-server-rendering.md +32 -0
  59. data/docs/guides/render-functions-and-railscontext.md +205 -0
  60. data/docs/guides/rspec-configuration.md +73 -0
  61. data/docs/guides/tutorial.md +371 -0
  62. data/docs/{basics → guides}/upgrading-react-on-rails.md +126 -3
  63. data/docs/guides/webpack-configuration.md +42 -0
  64. data/docs/home.md +23 -0
  65. data/docs/javascript/asset-pipeline.md +12 -0
  66. data/docs/{additional-reading → javascript}/code-splitting.md +21 -11
  67. data/docs/javascript/converting-from-custom-webpack-config-to-rails-webpacker-config.md +10 -0
  68. data/docs/javascript/credits.md +10 -0
  69. data/docs/{additional-reading → javascript}/images.md +5 -6
  70. data/docs/javascript/react-helmet.md +100 -0
  71. data/docs/javascript/react-router.md +90 -0
  72. data/docs/{additional-reading → javascript}/server-rendering-tips.md +15 -12
  73. data/docs/javascript/troubleshooting-when-using-shakapacker.md +77 -0
  74. data/docs/{additional-reading → javascript}/webpack.md +2 -2
  75. data/docs/misc/articles.md +20 -0
  76. data/docs/misc/doctrine.md +5 -6
  77. data/docs/outdated/deferred-rendering.md +39 -0
  78. data/docs/{additional-reading → outdated}/rails-assets-relative-paths.md +4 -4
  79. data/docs/{additional-reading → outdated}/rails-assets.md +12 -20
  80. data/docs/{misc → outdated}/rails3.md +2 -2
  81. data/docs/rails/convert-rails-5-api-only-app.md +19 -0
  82. data/docs/rails/rails-engine-integration.md +32 -0
  83. data/docs/{additional-reading → rails}/rails_view_rendering_from_inline_javascript.md +2 -1
  84. data/docs/{additional-reading → rails}/turbolinks.md +13 -1
  85. data/docs/react-on-rails-pro/react-on-rails-pro.md +43 -0
  86. data/docs/testimonials/hvmn.md +25 -0
  87. data/docs/testimonials/resortpass.md +13 -0
  88. data/docs/testimonials/testimonials.md +28 -0
  89. data/jest.config.js +4 -0
  90. data/lib/generators/USAGE +1 -1
  91. data/lib/generators/react_on_rails/adapt_for_older_shakapacker_generator.rb +41 -0
  92. data/lib/generators/react_on_rails/base_generator.rb +55 -43
  93. data/lib/generators/react_on_rails/bin/dev +30 -0
  94. data/lib/generators/react_on_rails/bin/dev-static +30 -0
  95. data/lib/generators/react_on_rails/dev_tests_generator.rb +4 -3
  96. data/lib/generators/react_on_rails/generator_helper.rb +8 -6
  97. data/lib/generators/react_on_rails/generator_messages.rb +40 -0
  98. data/lib/generators/react_on_rails/install_generator.rb +37 -0
  99. data/lib/generators/react_on_rails/templates/.eslintrc +3 -1
  100. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev +4 -6
  101. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-static +9 -0
  102. data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +21 -40
  103. data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.module.css +4 -0
  104. data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorldServer.js +5 -0
  105. data/lib/generators/react_on_rails/templates/base/base/app/javascript/packs/server-bundle.js +8 -0
  106. data/lib/generators/react_on_rails/templates/base/base/app/views/layouts/hello_world.html.erb +2 -1
  107. data/lib/generators/react_on_rails/templates/base/base/babel.config.js.tt +32 -0
  108. data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +20 -4
  109. data/lib/generators/react_on_rails/templates/base/base/config/shakapacker.yml +62 -0
  110. data/lib/generators/react_on_rails/templates/base/base/config/webpack/clientWebpackConfig.js.tt +17 -0
  111. data/lib/generators/react_on_rails/templates/base/base/config/webpack/commonWebpackConfig.js.tt +17 -0
  112. data/lib/generators/react_on_rails/templates/base/base/config/webpack/development.js.tt +25 -0
  113. data/lib/generators/react_on_rails/templates/base/base/config/webpack/production.js.tt +9 -0
  114. data/lib/generators/react_on_rails/templates/base/base/config/webpack/serverWebpackConfig.js.tt +117 -0
  115. data/lib/generators/react_on_rails/templates/base/base/config/webpack/test.js.tt +9 -0
  116. data/lib/generators/react_on_rails/templates/base/base/config/webpack/webpack.config.js.tt +15 -0
  117. data/lib/generators/react_on_rails/templates/base/base/config/webpack/webpackConfig.js.tt +36 -0
  118. data/lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb +8 -2
  119. data/lib/generators/react_on_rails/templates/dev_tests/spec/simplecov_helper.rb +1 -1
  120. data/lib/generators/react_on_rails/templates/dev_tests/spec/{features → system}/hello_world_spec.rb +2 -2
  121. data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +6 -9
  122. data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/store/helloWorldStore.js +1 -3
  123. data/lib/react_on_rails/configuration.rb +198 -145
  124. data/lib/react_on_rails/error.rb +2 -0
  125. data/lib/react_on_rails/git_utils.rb +5 -3
  126. data/lib/react_on_rails/{react_on_rails_helper.rb → helper.rb} +201 -190
  127. data/lib/react_on_rails/json_output.rb +1 -1
  128. data/lib/react_on_rails/json_parse_error.rb +28 -0
  129. data/lib/react_on_rails/locales/base.rb +169 -0
  130. data/lib/react_on_rails/locales/to_js.rb +33 -0
  131. data/lib/react_on_rails/locales/to_json.rb +23 -0
  132. data/lib/react_on_rails/packs_generator.rb +234 -0
  133. data/lib/react_on_rails/prerender_error.rb +35 -27
  134. data/lib/react_on_rails/react_component/render_options.rb +64 -9
  135. data/lib/react_on_rails/server_rendering_js_code.rb +55 -0
  136. data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +126 -76
  137. data/lib/react_on_rails/server_rendering_pool.rb +0 -1
  138. data/lib/react_on_rails/test_helper/ensure_assets_compiled.rb +9 -8
  139. data/lib/react_on_rails/test_helper/webpack_assets_compiler.rb +17 -0
  140. data/lib/react_on_rails/test_helper/webpack_assets_status_checker.rb +13 -12
  141. data/lib/react_on_rails/test_helper.rb +24 -3
  142. data/lib/react_on_rails/utils.rb +94 -25
  143. data/lib/react_on_rails/version.rb +1 -1
  144. data/lib/react_on_rails/version_checker.rb +5 -1
  145. data/lib/react_on_rails/version_syntax_converter.rb +14 -12
  146. data/lib/react_on_rails/webpacker_utils.rb +105 -5
  147. data/lib/react_on_rails.rb +8 -2
  148. data/lib/tasks/assets.rake +28 -60
  149. data/lib/tasks/generate_packs.rake +11 -0
  150. data/lib/tasks/locale.rake +5 -4
  151. data/package-scripts.yml +49 -0
  152. data/package.json +52 -47
  153. data/rakelib/docker.rake +0 -5
  154. data/rakelib/dummy_apps.rake +5 -8
  155. data/rakelib/example_type.rb +12 -3
  156. data/rakelib/examples.rake +5 -4
  157. data/rakelib/lint.rake +5 -16
  158. data/rakelib/node_package.rake +2 -2
  159. data/rakelib/release.rake +37 -23
  160. data/rakelib/run_rspec.rake +16 -44
  161. data/rakelib/task_helpers.rb +16 -4
  162. data/react_on_rails.gemspec +6 -22
  163. data/tsconfig.json +14 -0
  164. data/webpackConfigLoader.js +5 -4
  165. data/yarn.lock +5935 -3106
  166. metadata +122 -272
  167. data/Gemfile.rails32 +0 -74
  168. data/docs/additional-reading/asset-pipeline.md +0 -20
  169. data/docs/additional-reading/babel.md +0 -5
  170. data/docs/additional-reading/caching-and-performance.md +0 -4
  171. data/docs/additional-reading/heroku-deployment.md +0 -92
  172. data/docs/additional-reading/hot-reloading-rails-development.md +0 -57
  173. data/docs/additional-reading/node-server-rendering.md +0 -5
  174. data/docs/additional-reading/rails-engine-integration.md +0 -34
  175. data/docs/additional-reading/react-helmet.md +0 -80
  176. data/docs/additional-reading/react-router.md +0 -113
  177. data/docs/additional-reading/recommended-project-structure.md +0 -49
  178. data/docs/additional-reading/rspec-configuration.md +0 -56
  179. data/docs/additional-reading/webpack-dev-server.md +0 -15
  180. data/docs/api/ruby-api-hot-reload-view-helpers.md +0 -44
  181. data/docs/api/ruby-api.md +0 -8
  182. data/docs/basics/configuration.md +0 -163
  183. data/docs/basics/i18n.md +0 -77
  184. data/docs/tutorial.md +0 -220
  185. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-server +0 -12
  186. data/lib/react_on_rails/assets_precompile.rb +0 -150
  187. data/lib/react_on_rails/locales_to_js.rb +0 -134
  188. data/ruby-lint.yml +0 -25
  189. /data/docs/{additional-reading → additional-details}/updating-dependencies.md +0 -0
  190. /data/docs/{additional-reading → deployment}/elastic-beanstalk.md +0 -0
  191. /data/docs/{additional-reading → javascript}/angular-js-integration-migration.md +0 -0
  192. /data/docs/{additional-reading → javascript}/capistrano-deployment.md +0 -0
  193. /data/docs/{additional-reading → javascript}/foreman-issues.md +0 -0
  194. /data/docs/{additional-reading → javascript}/node-dependencies-and-npm.md +0 -0
  195. /data/docs/{additional-reading → javascript}/react-and-redux.md +0 -0
  196. /data/docs/{additional-reading → javascript}/troubleshooting-when-using-webpacker.md +0 -0
  197. /data/docs/{additional-reading → javascript}/webpack-v1-notes.md +0 -0
  198. /data/docs/{coding-style → misc}/style.md +0 -0
  199. /data/docs/{additional-reading → misc}/tips.md +0 -0
data/package.json CHANGED
@@ -1,73 +1,79 @@
1
1
  {
2
2
  "name": "react-on-rails",
3
- "version": "11.0.5",
3
+ "version": "13.4.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.20.7",
11
+ "@babel/core": "^7.20.12",
12
+ "@babel/plugin-transform-runtime": "^7.19.6",
13
+ "@babel/plugin-transform-typescript": "^7.20.13",
14
+ "@babel/preset-env": "^7.20.2",
15
+ "@babel/preset-react": "^7.18.6",
16
+ "@babel/types": "^7.20.7",
17
+ "@types/jest": "^28.1.3",
18
+ "@types/react": "^16.14.35",
19
+ "@types/react-dom": "^16.9.17",
20
+ "@types/turbolinks": "^5.2.0",
21
+ "@types/webpack-env": "^1.18.0",
22
+ "@typescript-eslint/eslint-plugin": "^4.33.0",
23
+ "@typescript-eslint/parser": "^4.33.0",
24
+ "babelify": "^10.0.0",
23
25
  "blue-tape": "^1.0.0",
24
- "create-react-class": "^15.6.0",
25
- "eslint": "^3.19.0",
26
- "eslint-config-shakacode": "^15.0.0",
27
- "eslint-plugin-import": "^2.6.1",
28
- "eslint-plugin-jsx-a11y": "^5.1.1",
29
- "eslint-plugin-react": "^7.1.0",
30
- "flow-bin": "^0.51.1",
31
- "jsdom": "^11.1.0",
32
- "prop-types": "^15.5.10",
33
- "react": "^15.6.1",
34
- "react-dom": "^15.6.1",
26
+ "create-react-class": "^15.7.0",
27
+ "eslint": "^7.32.0",
28
+ "eslint-config-prettier": "^7.0.0",
29
+ "eslint-config-shakacode": "^16.0.1",
30
+ "eslint-plugin-import": "^2.27.5",
31
+ "eslint-plugin-jsx-a11y": "^6.7.1",
32
+ "eslint-plugin-prettier": "^3.4.1",
33
+ "eslint-plugin-react": "^7.32.1",
34
+ "jest": "^28.1.3",
35
+ "jest-environment-jsdom": "^28.1.3",
36
+ "jsdom": "^16.4.0",
37
+ "nps": "^5.9.3",
38
+ "prettier": "^2.8.3",
39
+ "prettier-eslint-cli": "^5.0.0",
40
+ "prop-types": "^15.8.1",
41
+ "react": "^16.14.0",
42
+ "react-dom": "^16.14.0",
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",
40
- "webpack": "^3.4.1",
41
- "webpack-manifest-plugin": "^1.2.1"
44
+ "redux": "^4.2.0",
45
+ "ts-jest": "^28.0.8",
46
+ "typescript": "^4.9.4"
47
+ },
48
+ "dependencies": {
49
+ "@babel/runtime-corejs3": "^7.12.5",
50
+ "concurrently": "^5.1.0"
42
51
  },
43
52
  "peerDependencies": {
44
- "babel-runtime": ">= 6",
45
53
  "js-yaml": ">= 3.0.0",
46
- "react": ">= 0.14",
47
- "react-dom": ">= 0.14"
54
+ "react": ">= 16",
55
+ "react-dom": ">= 16"
48
56
  },
49
57
  "files": [
50
58
  "node_package/lib",
51
59
  "webpackConfigLoader.js"
52
60
  ],
53
61
  "scripts": {
54
- "test": "babel-tape-runner -r node_package/tests/helpers/test_helper.js node_package/tests/*.js | tap-spec",
62
+ "test": "jest node_package/tests",
55
63
  "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",
64
+ "start": "nps",
65
+ "prepare": "yarn run build",
66
+ "build": "yarn run clean && yarn run tsc --declaration",
67
+ "build-watch": "yarn run clean && yarn run tsc --watch",
68
+ "lint": "nps eslint",
69
+ "check": "yarn run lint && yarn run test && yarn run type-check",
70
+ "type-check": "yarn run tsc --noEmit --noErrorTruncation",
64
71
  "prerelease": "yarn run check && yarn run clean && yarn run build",
65
72
  "release:patch": "node_package/scripts/release patch",
66
73
  "release:minor": "node_package/scripts/release minor",
67
74
  "release:major": "node_package/scripts/release major",
68
75
  "dummy:install": "rake dummy_apps",
69
- "dummy:spec": "rake run_rspec:dummy",
70
- "install-react-on-rails": "yarn link"
76
+ "dummy:spec": "rake run_rspec:dummy"
71
77
  },
72
78
  "repository": {
73
79
  "type": "git",
@@ -86,6 +92,5 @@
86
92
  "bugs": {
87
93
  "url": "https://github.com/shakacode/react_on_rails/issues"
88
94
  },
89
- "homepage": "https://github.com/shakacode/react_on_rails#readme",
90
- "dependencies": {}
95
+ "homepage": "https://github.com/shakacode/react_on_rails#readme"
91
96
  }
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"
@@ -8,6 +8,7 @@ namespace :dummy_apps do
8
8
  task :yarn_install do
9
9
  yarn_install_cmd = "yarn install --mutex network"
10
10
  sh_in_dir(dummy_app_dir, yarn_install_cmd)
11
+ sh_in_dir(dummy_app_dir, "yalc link react-on-rails")
11
12
  end
12
13
 
13
14
  task dummy_app: [:yarn_install] do
@@ -15,16 +16,12 @@ namespace :dummy_apps do
15
16
  bundle_install_in(dummy_app_dir)
16
17
  end
17
18
 
18
- task :dummy_no_webpacker do
19
- npm_install_cmd = "npm install"
20
- install_react_on_rails_cmd = "yarn run install-react-on-rails"
21
- dummy_app_dir = File.join(gem_root, "spec/dummy_no_webpacker")
22
- sh_in_dir(File.join(gem_root, "spec/dummy_no_webpacker/client"), npm_install_cmd)
23
- sh_in_dir(dummy_app_dir, install_react_on_rails_cmd)
24
- sh_in_dir(dummy_app_dir, "BUNDLE_GEMFILE=Gemfile.rails32 bundle install")
19
+ task :generate_packs do
20
+ dummy_app_dir = File.join(gem_root, "spec/dummy")
21
+ sh_in_dir(dummy_app_dir, "bundle exec rake react_on_rails:generate_packs")
25
22
  end
26
23
 
27
- task dummy_apps: %i[dummy_app node_package] do
24
+ task dummy_apps: %i[dummy_app node_package generate_packs] do
28
25
  puts "Prepared all Dummy Apps"
29
26
  end
30
27
  end
@@ -45,12 +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.
55
+ attr_writer :rails_options
56
+
52
57
  def rails_options
53
- "--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
54
63
  end
55
64
 
56
65
  %w[gen clobber npm_install build_webpack_bundles].each do |task_type|
@@ -72,7 +81,7 @@ module ReactOnRails
72
81
  # Assumes we are inside a rails app's folder and necessary gems have been installed
73
82
  def generator_shell_commands
74
83
  shell_commands = []
75
- 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"
76
85
  shell_commands << "rails generate react_on_rails:dev_tests #{generator_options}"
77
86
  end
78
87
 
@@ -6,6 +6,8 @@
6
6
  # Also see example_type.rb
7
7
 
8
8
  require "yaml"
9
+ require "rails/version"
10
+
9
11
  require_relative "example_type"
10
12
  require_relative "task_helpers"
11
13
 
@@ -14,7 +16,7 @@ namespace :examples do # rubocop:disable Metrics/BlockLength
14
16
  # Loads data from examples_config.yml and instantiates corresponding ExampleType objects
15
17
  examples_config_file = File.expand_path("examples_config.yml", __dir__)
16
18
  examples_config = symbolize_keys(YAML.safe_load(File.read(examples_config_file)))
17
- 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)) }
18
20
 
19
21
  # Define tasks for each example type
20
22
  ExampleType.all.each do |example_type|
@@ -28,13 +30,12 @@ namespace :examples do # rubocop:disable Metrics/BlockLength
28
30
  desc "Generates #{example_type.name_pretty}"
29
31
  task example_type.gen_task_name_short => example_type.clobber_task_name do
30
32
  mkdir_p(example_type.dir)
33
+ example_type.rails_options += "--skip-javascript"
31
34
  sh_in_dir(examples_dir, "rails new #{example_type.name} #{example_type.rails_options}")
32
35
  sh_in_dir(example_type.dir, "touch .gitignore")
33
- sh_in_dir(example_type.dir, "rake webpacker:install")
34
- sh_in_dir(example_type.dir, "bundle binstubs --path=#{example_type.dir}/bin webpacker")
35
- sh_in_dir(example_type.dir, "rake webpacker:install:react")
36
36
  append_to_gemfile(example_type.gemfile, example_type.required_gems)
37
37
  bundle_install_in(example_type.dir)
38
+ sh_in_dir(example_type.dir, "rake webpacker:install")
38
39
  sh_in_dir(example_type.dir, example_type.generator_shell_commands)
39
40
  sh_in_dir(example_type.dir, "yarn")
40
41
  end
data/rakelib/lint.rake CHANGED
@@ -2,18 +2,12 @@
2
2
 
3
3
  require_relative "task_helpers"
4
4
 
5
- namespace :lint do # rubocop:disable Metrics/BlockLength
5
+ namespace :lint do
6
6
  include ReactOnRails::TaskHelpers
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,16 +17,11 @@ namespace :lint do # rubocop:disable Metrics/BlockLength
23
17
 
24
18
  desc "Run eslint as shell"
25
19
  task :eslint do
26
- sh_in_dir(gem_root, "yarn run eslint")
27
- end
28
-
29
- desc "Run flow from shell"
30
- task :flow do
31
- sh_in_dir(gem_root, "yarn run flow")
20
+ sh_in_dir(gem_root, "yarn run eslint --version", "yarn run eslint .")
32
21
  end
33
22
 
34
- desc "Run all eslint, flow, rubocop linters. Skip ruby-lint and scss"
35
- task lint: %i[eslint flow rubocop] do
23
+ desc "Run all eslint & rubocop linters. Skip scss"
24
+ task lint: %i[eslint rubocop] do
36
25
  puts "Completed all linting"
37
26
  end
38
27
  end
@@ -6,8 +6,8 @@ namespace :node_package do
6
6
  include ReactOnRails::TaskHelpers
7
7
 
8
8
  task :build do
9
- puts "Building Node Package and running 'yarn link'"
10
- sh "yarn run build && yarn link"
9
+ puts "Building Node Package and running 'yalc publish'"
10
+ sh "yarn run build && yalc publish"
11
11
  end
12
12
  end
13
13
 
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])
@@ -41,7 +45,7 @@ task :release, %i[gem_version dry_run tools_install] do |_t, args|
41
45
  npm_version = if gem_version.strip.empty?
42
46
  ""
43
47
  else
44
- VersionSyntaxConverter.new.rubygem_to_npm(gem_version)
48
+ ReactOnRails::VersionSyntaxConverter.new.rubygem_to_npm(gem_version)
45
49
  end
46
50
 
47
51
  # Having the examples prevents publishing
@@ -56,23 +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 --non-interactive --npm.publish".dup
64
- release_it_command << " --dry-run --verbose" if is_dry_run
65
+ release_it_command = +"release-it"
65
66
  release_it_command << " #{npm_version}" unless npm_version.strip.empty?
67
+ release_it_command << " --npm.publish --no-git.requireCleanWorkingDir"
68
+ release_it_command << " --dry-run --verbose" if is_dry_run
66
69
  sh_in_dir(gem_root, release_it_command)
67
70
 
68
71
  # Release the new gem version
69
- unless is_dry_run
70
- sh_in_dir(gem_root, "gem release")
71
72
 
72
- # Update master with new npm version
73
- sh_in_dir(File.join(gem_root, "spec", "dummy", "client"), "yarn add react-on-rails@#{npm_version} --exact")
74
- sh_in_dir(gem_root, "git commit -am 'Updated spec/dummy/client/package.json latest version'")
75
- sh_in_dir(gem_root, "git push")
76
- end
73
+ puts "Carefully add your OTP for Rubygems. If you get an error, run 'gem release' again."
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
77
85
  end
78
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
@@ -18,40 +18,18 @@ namespace :run_rspec do
18
18
  run_tests_in("", rspec_args: File.join("spec", "react_on_rails"))
19
19
  end
20
20
 
21
- desc "Run RSpec with rails32 gemfile"
22
- task :gem_rails32 do
23
- rspec_args = "spec/react_on_rails --tag ~webpacker --exclude-pattern "\
24
- "\"**/generators/*_spec.rb,"\
25
- "**/test_helper/webpack_*_spec.rb\""
26
- run_tests_in("",
27
- rspec_args: rspec_args,
28
- env_vars: "BUNDLE_GEMFILE=spec/dummy_no_webpacker/Gemfile.rails32")
29
- end
30
-
31
21
  desc "Runs dummy rspec with turbolinks"
32
22
  task dummy: ["dummy_apps:dummy_app"] do
33
- clean_gen_assets(spec_dummy_dir)
34
- bundle_install_in(dummy_app_dir)
35
23
  run_tests_in(spec_dummy_dir)
36
24
  end
37
25
 
38
26
  desc "Runs dummy rspec without turbolinks"
39
27
  task dummy_no_turbolinks: ["dummy_apps:dummy_app"] do
40
- clean_gen_assets(spec_dummy_dir)
41
- bundle_install_in(dummy_app_dir)
42
28
  run_tests_in(spec_dummy_dir,
43
29
  env_vars: "DISABLE_TURBOLINKS=TRUE",
44
30
  command_name: "dummy_no_turbolinks")
45
31
  end
46
32
 
47
- desc "Runs dummy_no_webpacker rspec"
48
- task :dummy_no_webpacker do
49
- dummy_app_dir = File.join(gem_root, "spec/dummy_no_webpacker")
50
- clean_gen_assets(dummy_app_dir)
51
- run_tests_in(dummy_app_dir,
52
- env_vars: "BUNDLE_GEMFILE=Gemfile.rails32")
53
- end
54
-
55
33
  # Dynamically define Rake tasks for each example app found in the examples directory
56
34
  ExampleType.all.each do |example_type|
57
35
  desc "Runs RSpec for #{example_type.name_pretty} only"
@@ -65,15 +43,15 @@ namespace :run_rspec do
65
43
  ExampleType.all.each { |example_type| Rake::Task[example_type.rspec_task_name].invoke }
66
44
  end
67
45
 
68
- desc "(HACK) Run RSpec on spec/empty_spec in order to have SimpleCov generate a coverage report from cache"
69
- task :empty do
70
- sh %(#{ENV['USE_COVERALLS'] ? 'COVERAGE=true' : ''} rspec spec/empty_spec.rb)
71
- end
72
-
73
46
  Coveralls::RakeTask.new if ENV["USE_COVERALLS"] == "TRUE"
74
47
 
75
48
  desc "run all tests no examples"
76
- task all_but_examples: %i[gem dummy_no_turbolinks dummy empty js_tests] do
49
+ task all_but_examples: %i[gem dummy_no_turbolinks dummy js_tests] do
50
+ puts "Completed all RSpec tests"
51
+ end
52
+
53
+ desc "run all dummy tests"
54
+ task all_dummy: %i[dummy_no_turbolinks dummy] do
77
55
  puts "Completed all RSpec tests"
78
56
  end
79
57
 
@@ -99,16 +77,15 @@ task run_rspec: ["run_rspec:run_rspec"]
99
77
  private
100
78
 
101
79
  def calc_path(dir)
102
- path = if dir.is_a?(String)
103
- if dir.start_with?(File::SEPARATOR)
104
- Pathname.new(dir)
105
- else
106
- Pathname.new(File.join(gem_root, dir))
107
- end
108
- else
109
- dir
110
- end
111
- path
80
+ if dir.is_a?(String)
81
+ if dir.start_with?(File::SEPARATOR)
82
+ Pathname.new(dir)
83
+ else
84
+ Pathname.new(File.join(gem_root, dir))
85
+ end
86
+ else
87
+ dir
88
+ end
112
89
  end
113
90
 
114
91
  # Runs rspec in the given directory.
@@ -120,12 +97,7 @@ def run_tests_in(dir, options = {})
120
97
 
121
98
  command_name = options.fetch(:command_name, path.basename)
122
99
  rspec_args = options.fetch(:rspec_args, "")
123
- env_vars = "#{options.fetch(:env_vars, '')} TEST_ENV_COMMAND_NAME=\"#{command_name}\"".dup
100
+ env_vars = +"#{options.fetch(:env_vars, '')} TEST_ENV_COMMAND_NAME=\"#{command_name}\""
124
101
  env_vars << "COVERAGE=true" if ENV["USE_COVERALLS"]
125
102
  sh_in_dir(path.realpath, "#{env_vars} bundle exec rspec #{rspec_args}")
126
103
  end
127
-
128
- def clean_gen_assets(dir)
129
- path = calc_path(dir)
130
- sh_in_dir(path.realpath, "yarn run build:clean")
131
- 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,37 +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.1.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
33
 
34
- s.add_development_dependency "awesome_print"
35
- s.add_development_dependency "bundler", "~> 1"
36
- s.add_development_dependency "coveralls"
34
+ s.add_development_dependency "bundler", "~> 2"
37
35
  s.add_development_dependency "gem-release"
38
- s.add_development_dependency "generator_spec"
39
- s.add_development_dependency "listen"
40
- s.add_development_dependency "pry"
41
- s.add_development_dependency "pry-byebug"
42
- s.add_development_dependency "pry-doc"
43
- s.add_development_dependency "pry-rescue"
44
- s.add_development_dependency "pry-stack_explorer"
45
- s.add_development_dependency "pry-state"
46
- s.add_development_dependency "pry-toys"
47
- s.add_development_dependency "rails", "~> 5.2"
48
-
49
- s.add_development_dependency "rake", "~> 10.0"
50
- s.add_development_dependency "rspec"
51
- s.add_development_dependency "rubocop", "0.55.0"
52
-
53
36
  s.post_install_message = '
54
37
  --------------------------------------------------------------------------------
55
- Email contact@shakacode.com for access to our slack room and information about our "pro support plan"
56
- 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.
57
41
  --------------------------------------------------------------------------------
58
42
  '
59
43
  end
data/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowJs": true,
4
+ "esModuleInterop": true,
5
+ "jsx": "react",
6
+ "lib": ["dom", "es2015"],
7
+ "module": "CommonJS",
8
+ "noImplicitAny": true,
9
+ "outDir": "node_package/lib",
10
+ "strict": true,
11
+ "target": "es5"
12
+ },
13
+ "include": ["node_package/src/**/*"]
14
+ }
@@ -1,4 +1,6 @@
1
1
  /**
2
+ * TODO: THIS SHOULD BE REMOVED
3
+ *
2
4
  * Allow defaults for the config/webpacker.yml. Thee values in this file MUST match values
3
5
  * in https://github.com/rails/webpacker/blob/master/lib/install/config/webpacker.yml
4
6
  *
@@ -11,15 +13,14 @@ const { env } = require('process');
11
13
  const { safeLoad } = require('js-yaml');
12
14
  const { readFileSync } = require('fs');
13
15
 
14
-
15
16
  function removeOuterSlashes(string) {
16
17
  return string.replace(/^\/*/, '').replace(/\/*$/, '');
17
18
  }
18
19
 
19
20
  function formatPublicPath(settings) {
20
21
  if (settings.dev_server) {
21
- const host = settings.dev_server.host;
22
- const port = settings.dev_server.port;
22
+ const { host } = settings.dev_server;
23
+ const { port } = settings.dev_server;
23
24
  const path = settings.public_output_path;
24
25
  const hostWithHttp = `http://${host}:${port}`;
25
26
 
@@ -48,7 +49,7 @@ function formatPublicPath(settings) {
48
49
  */
49
50
  const configLoader = (configPath) => {
50
51
  // Some test environments might not have the NODE_ENV set, so we'll have fallbacks.
51
- const configEnv = (env.NODE_ENV || env.RAILS_ENV || 'development');
52
+ const configEnv = env.NODE_ENV || env.RAILS_ENV || 'development';
52
53
  const ymlConfigPath = join(configPath, 'webpacker.yml');
53
54
  const settings = safeLoad(readFileSync(ymlConfigPath, 'utf8'))[configEnv];
54
55