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.
- checksums.yaml +5 -5
- data/.circleci/config.yml +320 -0
- data/.eslintignore +2 -1
- data/.eslintrc +30 -2
- data/.github/FUNDING.yml +1 -0
- data/.gitignore +3 -1
- data/.prettierignore +10 -0
- data/.prettierrc +23 -0
- data/.release-it.json +3 -0
- data/.rubocop.yml +39 -11
- data/.travis.yml +11 -22
- data/CHANGELOG.md +235 -6
- data/CONTRIBUTING.md +64 -84
- data/Gemfile +3 -5
- data/KUDOS.md +4 -1
- data/{docs/LICENSE.md → LICENSE.md} +1 -1
- data/PROJECTS.md +7 -1
- data/REACT-ON-RAILS-PRO-LICENSE +95 -0
- data/README.md +233 -630
- data/Rakefile +1 -5
- data/SUMMARY.md +42 -29
- data/book.json +5 -5
- data/docs/additional-reading/asset-pipeline.md +8 -16
- data/docs/additional-reading/convert-rails-5-api-only-app.md +19 -0
- data/docs/additional-reading/credits.md +10 -0
- data/docs/additional-reading/images.md +1 -1
- data/docs/additional-reading/rails-engine-integration.md +7 -0
- data/docs/additional-reading/rails_view_rendering_from_inline_javascript.md +2 -1
- data/docs/additional-reading/react-helmet.md +30 -10
- data/docs/additional-reading/react-router.md +52 -75
- data/docs/additional-reading/server-rendering-tips.md +14 -11
- data/docs/additional-reading/upgrade-webpacker-v3-to-v4.md +10 -0
- data/docs/additional-reading/webpack.md +2 -2
- data/docs/api/javascript-api.md +24 -4
- data/docs/api/redux-store-api.md +102 -0
- data/docs/api/view-helpers-api.md +133 -0
- data/docs/articles.md +20 -0
- data/docs/basics/client-vs-server-rendering.md +23 -0
- data/docs/basics/configuration.md +145 -61
- data/docs/basics/deployment.md +4 -0
- data/docs/basics/{generator.md → generator-details.md} +5 -8
- data/docs/basics/heroku-deployment.md +24 -0
- data/docs/basics/hmr-and-hot-reloading-with-the-webpack-dev-server.md +49 -0
- data/docs/basics/i18n.md +45 -23
- data/docs/basics/installation-into-an-existing-rails-app.md +59 -0
- data/docs/basics/minitest-configuration.md +31 -0
- data/docs/basics/react-server-rendering.md +29 -0
- data/docs/{additional-reading → basics}/recommended-project-structure.md +38 -10
- data/docs/basics/render-functions-and-railscontext.md +205 -0
- data/docs/basics/rspec-configuration.md +73 -0
- data/docs/basics/upgrading-react-on-rails.md +75 -4
- data/docs/basics/webpack-configuration.md +50 -0
- data/docs/contributor-info/errors-with-hooks.md +45 -0
- data/docs/contributor-info/pull-requests.md +44 -0
- data/docs/misc/doctrine.md +2 -2
- data/docs/{additional-reading → outdated}/code-splitting.md +19 -9
- data/docs/outdated/how-react-on-rails-works.md +44 -0
- data/docs/{basics/installation-overview.md → outdated/manual-installation-overview.md} +8 -13
- data/docs/{additional-reading → outdated}/rails-assets-relative-paths.md +3 -3
- data/docs/{additional-reading → outdated}/rails-assets.md +5 -13
- data/docs/testimonials/hvmn.md +25 -0
- data/docs/testimonials/resortpass.md +13 -0
- data/docs/testimonials/testimonials.md +28 -0
- data/docs/tutorial.md +182 -44
- data/jest.config.js +4 -0
- data/lib/generators/USAGE +1 -1
- data/lib/generators/react_on_rails/base_generator.rb +2 -2
- data/lib/generators/react_on_rails/dev_tests_generator.rb +3 -2
- data/lib/generators/react_on_rails/generator_helper.rb +4 -6
- data/lib/generators/react_on_rails/install_generator.rb +2 -0
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev +3 -1
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-hmr +26 -0
- data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +20 -40
- data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +4 -1
- data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +4 -8
- data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/store/helloWorldStore.js +1 -3
- data/lib/react_on_rails/configuration.rb +175 -102
- data/lib/react_on_rails/error.rb +2 -0
- data/lib/react_on_rails/git_utils.rb +2 -0
- data/lib/react_on_rails/{react_on_rails_helper.rb → helper.rb} +201 -225
- data/lib/react_on_rails/json_output.rb +1 -1
- data/lib/react_on_rails/json_parse_error.rb +28 -0
- data/lib/react_on_rails/locales/base.rb +150 -0
- data/lib/react_on_rails/locales/to_js.rb +37 -0
- data/lib/react_on_rails/locales/to_json.rb +27 -0
- data/lib/react_on_rails/prerender_error.rb +56 -18
- data/lib/react_on_rails/react_component/render_options.rb +98 -0
- data/lib/react_on_rails/server_rendering_js_code.rb +42 -0
- data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +139 -106
- data/lib/react_on_rails/server_rendering_pool.rb +4 -16
- data/lib/react_on_rails/test_helper/ensure_assets_compiled.rb +7 -8
- data/lib/react_on_rails/test_helper/webpack_assets_compiler.rb +17 -0
- data/lib/react_on_rails/test_helper/webpack_assets_status_checker.rb +10 -6
- data/lib/react_on_rails/test_helper.rb +18 -7
- data/lib/react_on_rails/utils.rb +66 -26
- data/lib/react_on_rails/version.rb +1 -1
- data/lib/react_on_rails/version_checker.rb +5 -1
- data/lib/react_on_rails/version_syntax_converter.rb +14 -12
- data/lib/react_on_rails/webpacker_utils.rb +44 -10
- data/lib/react_on_rails.rb +8 -3
- data/lib/tasks/assets.rake +33 -46
- data/lib/tasks/locale.rake +4 -2
- data/package-scripts.yml +49 -0
- data/package.json +49 -40
- data/rakelib/dummy_apps.rake +1 -9
- data/rakelib/example_type.rb +3 -1
- data/rakelib/examples.rake +3 -0
- data/rakelib/lint.rake +2 -7
- data/rakelib/node_package.rake +2 -2
- data/rakelib/release.rake +4 -8
- data/rakelib/run_rspec.rake +5 -18
- data/react_on_rails.gemspec +5 -6
- data/tsconfig.json +14 -0
- data/webpackConfigLoader.js +5 -4
- data/yarn.lock +7645 -1821
- metadata +71 -61
- data/Gemfile.rails32 +0 -74
- data/docs/additional-reading/babel.md +0 -5
- data/docs/additional-reading/caching-and-performance.md +0 -4
- data/docs/additional-reading/heroku-deployment.md +0 -92
- data/docs/additional-reading/hot-reloading-rails-development.md +0 -57
- data/docs/additional-reading/node-server-rendering.md +0 -5
- data/docs/additional-reading/rspec-configuration.md +0 -56
- data/docs/api/ruby-api-hot-reload-view-helpers.md +0 -44
- data/docs/api/ruby-api.md +0 -8
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-server +0 -12
- data/lib/react_on_rails/assets_precompile.rb +0 -150
- data/lib/react_on_rails/locales_to_js.rb +0 -134
- data/lib/react_on_rails/react_component/options.rb +0 -64
- /data/docs/{misc → outdated}/rails3.md +0 -0
data/lib/react_on_rails/utils.rb
CHANGED
|
@@ -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
|
-
|
|
26
|
-
|
|
27
|
-
#{
|
|
28
|
-
#{
|
|
29
|
-
#{wrapper_line}
|
|
27
|
+
fenced_msg = <<~MSG
|
|
28
|
+
#{wrapper_line}
|
|
29
|
+
#{msg.strip}
|
|
30
|
+
#{wrapper_line}
|
|
30
31
|
MSG
|
|
31
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
#{
|
|
53
|
-
|
|
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
|
-
|
|
56
|
+
|
|
57
57
|
puts wrap_message(msg)
|
|
58
|
-
|
|
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
|
|
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
|
-
|
|
80
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
|
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.
|
|
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
|
|
@@ -5,7 +5,8 @@ module ReactOnRails
|
|
|
5
5
|
# against each otherat runtime.
|
|
6
6
|
class VersionChecker
|
|
7
7
|
attr_reader :node_package_version
|
|
8
|
-
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
11
|
-
|
|
11
|
+
regex_match[1].to_s
|
|
12
|
+
end
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
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
|
|
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
|
data/lib/react_on_rails.rb
CHANGED
|
@@ -3,14 +3,17 @@
|
|
|
3
3
|
require "rails"
|
|
4
4
|
|
|
5
5
|
require "react_on_rails/error"
|
|
6
|
-
require "react_on_rails/
|
|
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/
|
|
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/
|
|
25
|
+
require "react_on_rails/locales/base"
|
|
26
|
+
require "react_on_rails/locales/to_js"
|
|
27
|
+
require "react_on_rails/locales/to_json"
|
data/lib/tasks/assets.rake
CHANGED
|
@@ -1,69 +1,56 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
# Important: The default assets:precompile is modified ONLY if the rails/webpacker webpack config
|
|
4
|
+
# does not exist!
|
|
5
5
|
|
|
6
|
-
|
|
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
|
-
|
|
15
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
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
|
data/lib/tasks/locale.rake
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "react_on_rails/
|
|
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::
|
|
15
|
+
ReactOnRails::Locales.compile
|
|
14
16
|
end
|
|
15
17
|
end
|
data/package-scripts.yml
ADDED
|
@@ -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": "
|
|
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
|
|
11
|
-
"babel
|
|
12
|
-
"babel-
|
|
13
|
-
"babel
|
|
14
|
-
"babel-
|
|
15
|
-
"babel-
|
|
16
|
-
"babel
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
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": "^
|
|
26
|
-
"eslint-config-
|
|
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": "^
|
|
32
|
+
"eslint-plugin-jsx-a11y": "^6.1.2",
|
|
33
|
+
"eslint-plugin-prettier": "^3.0.0",
|
|
29
34
|
"eslint-plugin-react": "^7.1.0",
|
|
30
|
-
"
|
|
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": "^
|
|
34
|
-
"react-dom": "^
|
|
41
|
+
"react": "^16.5.2",
|
|
42
|
+
"react-dom": "^16.5.2",
|
|
35
43
|
"react-transform-hmr": "^1.0.4",
|
|
36
|
-
"redux": "^
|
|
37
|
-
"release-it": "^
|
|
38
|
-
"
|
|
39
|
-
"
|
|
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": ">=
|
|
47
|
-
"react-dom": ">=
|
|
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": "
|
|
66
|
+
"test": "jest node_package/tests",
|
|
55
67
|
"clean": "rm -rf node_package/lib",
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"build": "yarn run clean && yarn run
|
|
59
|
-
"build-watch": "
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
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
|
}
|