react_on_rails 15.0.0.alpha.1 → 15.0.0.alpha.2
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 +4 -4
- data/CHANGELOG.md +46 -5
- data/CONTRIBUTING.md +10 -14
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/knip.ts +91 -0
- data/lib/react_on_rails/configuration.rb +35 -10
- data/lib/react_on_rails/engine.rb +1 -3
- data/lib/react_on_rails/helper.rb +169 -53
- data/lib/react_on_rails/locales/base.rb +7 -1
- data/lib/react_on_rails/packer_utils.rb +23 -3
- data/lib/react_on_rails/packs_generator.rb +89 -10
- data/lib/react_on_rails/prerender_error.rb +10 -2
- data/lib/react_on_rails/react_component/render_options.rb +26 -2
- data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +6 -2
- data/lib/react_on_rails/test_helper/webpack_assets_status_checker.rb +2 -2
- data/lib/react_on_rails/utils.rb +44 -23
- data/lib/react_on_rails/version.rb +1 -1
- data/lib/react_on_rails/version_checker.rb +34 -23
- data/react_on_rails.gemspec +2 -2
- data/tsconfig.json +9 -6
- metadata +6 -5
data/lib/react_on_rails/utils.rb
CHANGED
@@ -8,7 +8,9 @@ require "active_support/core_ext/string"
|
|
8
8
|
|
9
9
|
module ReactOnRails
|
10
10
|
module Utils
|
11
|
-
TRUNCATION_FILLER = "\n... TRUNCATED
|
11
|
+
TRUNCATION_FILLER = "\n... TRUNCATED #{
|
12
|
+
Rainbow('To see the full output, set FULL_TEXT_ERRORS=true.').red
|
13
|
+
} ...\n".freeze
|
12
14
|
|
13
15
|
# https://forum.shakacode.com/t/yak-of-the-week-ruby-2-4-pathname-empty-changed-to-look-at-file-size/901
|
14
16
|
# return object if truthy, else return nil
|
@@ -66,7 +68,7 @@ module ReactOnRails
|
|
66
68
|
server_bundle_js_file_path =~ %r{https?://}
|
67
69
|
end
|
68
70
|
|
69
|
-
def self.
|
71
|
+
def self.bundle_js_file_path(bundle_name)
|
70
72
|
# Either:
|
71
73
|
# 1. Using same bundle for both server and client, so server bundle will be hashed in manifest
|
72
74
|
# 2. Using a different bundle (different Webpack config), so file is not hashed, and
|
@@ -76,28 +78,17 @@ module ReactOnRails
|
|
76
78
|
# a. The webpack manifest plugin would have a race condition where the same manifest.json
|
77
79
|
# is edited by both the webpack-dev-server
|
78
80
|
# b. There is no good reason to hash the server bundle name.
|
79
|
-
return @server_bundle_path if @server_bundle_path && !Rails.env.development?
|
80
|
-
|
81
|
-
bundle_name = ReactOnRails.configuration.server_bundle_js_file
|
82
|
-
@server_bundle_path = if ReactOnRails::PackerUtils.using_packer?
|
83
|
-
begin
|
84
|
-
bundle_js_file_path(bundle_name)
|
85
|
-
rescue Object.const_get(
|
86
|
-
ReactOnRails::PackerUtils.packer_type.capitalize
|
87
|
-
)::Manifest::MissingEntryError
|
88
|
-
File.expand_path(
|
89
|
-
File.join(ReactOnRails::PackerUtils.packer_public_output_path,
|
90
|
-
bundle_name)
|
91
|
-
)
|
92
|
-
end
|
93
|
-
else
|
94
|
-
bundle_js_file_path(bundle_name)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def self.bundle_js_file_path(bundle_name)
|
99
81
|
if ReactOnRails::PackerUtils.using_packer? && bundle_name != "manifest.json"
|
100
|
-
|
82
|
+
begin
|
83
|
+
ReactOnRails::PackerUtils.bundle_js_uri_from_packer(bundle_name)
|
84
|
+
rescue Object.const_get(
|
85
|
+
ReactOnRails::PackerUtils.packer_type.capitalize
|
86
|
+
)::Manifest::MissingEntryError
|
87
|
+
File.expand_path(
|
88
|
+
File.join(ReactOnRails::PackerUtils.packer_public_output_path,
|
89
|
+
bundle_name)
|
90
|
+
)
|
91
|
+
end
|
101
92
|
else
|
102
93
|
# Default to the non-hashed name in the specified output directory, which, for legacy
|
103
94
|
# React on Rails, this is the output directory picked up by the asset pipeline.
|
@@ -106,6 +97,31 @@ module ReactOnRails
|
|
106
97
|
end
|
107
98
|
end
|
108
99
|
|
100
|
+
def self.server_bundle_js_file_path
|
101
|
+
return @server_bundle_path if @server_bundle_path && !Rails.env.development?
|
102
|
+
|
103
|
+
bundle_name = ReactOnRails.configuration.server_bundle_js_file
|
104
|
+
@server_bundle_path = bundle_js_file_path(bundle_name)
|
105
|
+
end
|
106
|
+
|
107
|
+
def self.rsc_bundle_js_file_path
|
108
|
+
return @rsc_bundle_path if @rsc_bundle_path && !Rails.env.development?
|
109
|
+
|
110
|
+
bundle_name = ReactOnRails.configuration.rsc_bundle_js_file
|
111
|
+
@rsc_bundle_path = bundle_js_file_path(bundle_name)
|
112
|
+
end
|
113
|
+
|
114
|
+
def self.react_client_manifest_file_path
|
115
|
+
return @react_client_manifest_path if @react_client_manifest_path && !Rails.env.development?
|
116
|
+
|
117
|
+
file_name = ReactOnRails.configuration.react_client_manifest_file
|
118
|
+
@react_client_manifest_path = if ReactOnRails::PackerUtils.using_packer?
|
119
|
+
ReactOnRails::PackerUtils.asset_uri_from_packer(file_name)
|
120
|
+
else
|
121
|
+
File.join(generated_assets_full_path, file_name)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
109
125
|
def self.running_on_windows?
|
110
126
|
(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
|
111
127
|
end
|
@@ -183,9 +199,14 @@ module ReactOnRails
|
|
183
199
|
end
|
184
200
|
end
|
185
201
|
|
202
|
+
def self.full_text_errors_enabled?
|
203
|
+
ENV["FULL_TEXT_ERRORS"] == "true"
|
204
|
+
end
|
205
|
+
|
186
206
|
def self.smart_trim(str, max_length = 1000)
|
187
207
|
# From https://stackoverflow.com/a/831583/1009332
|
188
208
|
str = str.to_s
|
209
|
+
return str if full_text_errors_enabled?
|
189
210
|
return str unless str.present? && max_length >= 1
|
190
211
|
return str if str.length <= max_length
|
191
212
|
|
@@ -19,8 +19,9 @@ module ReactOnRails
|
|
19
19
|
# For compatibility, the gem and the node package versions should always match,
|
20
20
|
# unless the user really knows what they're doing. So we will give a
|
21
21
|
# warning if they do not.
|
22
|
-
def
|
23
|
-
return if node_package_version.
|
22
|
+
def log_if_gem_and_node_package_versions_differ
|
23
|
+
return if node_package_version.raw.nil? || node_package_version.local_path_or_url?
|
24
|
+
return log_node_semver_version_warning if node_package_version.semver_wildcard?
|
24
25
|
|
25
26
|
node_major_minor_patch = node_package_version.major_minor_patch
|
26
27
|
gem_major_minor_patch = gem_major_minor_patch_version
|
@@ -28,9 +29,7 @@ module ReactOnRails
|
|
28
29
|
node_major_minor_patch[1] == gem_major_minor_patch[1] &&
|
29
30
|
node_major_minor_patch[2] == gem_major_minor_patch[2]
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
raise_node_semver_version_warning if node_package_version.semver_wildcard?
|
32
|
+
log_differing_versions_warning unless versions_match
|
34
33
|
end
|
35
34
|
|
36
35
|
private
|
@@ -46,15 +45,15 @@ module ReactOnRails
|
|
46
45
|
MSG
|
47
46
|
end
|
48
47
|
|
49
|
-
def
|
50
|
-
msg = "**
|
51
|
-
|
48
|
+
def log_differing_versions_warning
|
49
|
+
msg = "**WARNING** ReactOnRails: ReactOnRails gem and node package versions do not match\n#{common_error_msg}"
|
50
|
+
Rails.logger.warn(msg)
|
52
51
|
end
|
53
52
|
|
54
|
-
def
|
55
|
-
msg = "**
|
53
|
+
def log_node_semver_version_warning
|
54
|
+
msg = "**WARNING** ReactOnRails: Your node package version for react-on-rails contains a " \
|
56
55
|
"^ or ~\n#{common_error_msg}"
|
57
|
-
|
56
|
+
Rails.logger.warn(msg)
|
58
57
|
end
|
59
58
|
|
60
59
|
def gem_version
|
@@ -74,7 +73,7 @@ module ReactOnRails
|
|
74
73
|
end
|
75
74
|
|
76
75
|
def self.package_json_path
|
77
|
-
Rails.root.join(
|
76
|
+
Rails.root.join(ReactOnRails.configuration.node_modules_location, "package.json")
|
78
77
|
end
|
79
78
|
|
80
79
|
def initialize(package_json)
|
@@ -82,29 +81,41 @@ module ReactOnRails
|
|
82
81
|
end
|
83
82
|
|
84
83
|
def raw
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
parsed_package_contents
|
89
|
-
|
90
|
-
|
84
|
+
return @raw if defined?(@raw)
|
85
|
+
|
86
|
+
if File.exist?(package_json)
|
87
|
+
parsed_package_contents = JSON.parse(package_json_contents)
|
88
|
+
if parsed_package_contents.key?("dependencies") &&
|
89
|
+
parsed_package_contents["dependencies"].key?("react-on-rails")
|
90
|
+
return @raw = parsed_package_contents["dependencies"]["react-on-rails"]
|
91
|
+
end
|
91
92
|
end
|
93
|
+
msg = "No 'react-on-rails' entry in the dependencies of #{NodePackageVersion.package_json_path}, " \
|
94
|
+
"which is the expected location according to ReactOnRails.configuration.node_modules_location"
|
95
|
+
Rails.logger.warn(msg)
|
96
|
+
@raw = nil
|
92
97
|
end
|
93
98
|
|
94
99
|
def semver_wildcard?
|
95
|
-
|
100
|
+
# See https://docs.npmjs.com/cli/v10/configuring-npm/package-json#dependencies
|
101
|
+
# We want to disallow all expressions other than exact versions
|
102
|
+
# and the ones allowed by local_path_or_url?
|
103
|
+
raw.blank? || raw.match(/[~^><|*-]/).present?
|
96
104
|
end
|
97
105
|
|
98
|
-
def
|
99
|
-
|
106
|
+
def local_path_or_url?
|
107
|
+
# See https://docs.npmjs.com/cli/v10/configuring-npm/package-json#dependencies
|
108
|
+
# All path and protocol "version ranges" include / somewhere,
|
109
|
+
# but we want to make an exception for npm:@scope/pkg@version.
|
110
|
+
!raw.nil? && raw.include?("/") && !raw.start_with?("npm:")
|
100
111
|
end
|
101
112
|
|
102
113
|
def major_minor_patch
|
103
|
-
return if
|
114
|
+
return if local_path_or_url?
|
104
115
|
|
105
116
|
match = raw.match(MAJOR_MINOR_PATCH_VERSION_REGEX)
|
106
117
|
unless match
|
107
|
-
raise ReactOnRails::Error, "Cannot parse version number '#{raw}' (
|
118
|
+
raise ReactOnRails::Error, "Cannot parse version number '#{raw}' (only exact versions are supported)"
|
108
119
|
end
|
109
120
|
|
110
121
|
[match[1], match[2], match[3]]
|
data/react_on_rails.gemspec
CHANGED
@@ -36,8 +36,8 @@ Gem::Specification.new do |s|
|
|
36
36
|
s.post_install_message = '
|
37
37
|
--------------------------------------------------------------------------------
|
38
38
|
Checkout https://www.shakacode.com/react-on-rails-pro for information about
|
39
|
-
"React on Rails Pro" which includes
|
40
|
-
|
39
|
+
"React on Rails Pro" which includes a gem for better performance, via caching helpers, and our
|
40
|
+
node rendering server, support for React 19, and much more.
|
41
41
|
--------------------------------------------------------------------------------
|
42
42
|
'
|
43
43
|
end
|
data/tsconfig.json
CHANGED
@@ -1,15 +1,18 @@
|
|
1
1
|
{
|
2
|
+
"extends": "@tsconfig/node14",
|
2
3
|
"compilerOptions": {
|
3
4
|
"allowJs": true,
|
4
|
-
"esModuleInterop":
|
5
|
-
|
6
|
-
"
|
7
|
-
"
|
5
|
+
"esModuleInterop": false,
|
6
|
+
// needed for Jest tests even though we don't use .tsx
|
7
|
+
"jsx": "react-jsx",
|
8
|
+
"lib": ["dom", "es2020"],
|
9
|
+
"module": "node16",
|
8
10
|
"noImplicitAny": true,
|
9
11
|
"outDir": "node_package/lib",
|
10
12
|
"strict": true,
|
11
13
|
"incremental": true,
|
12
|
-
"target": "es5"
|
14
|
+
"target": "es5",
|
15
|
+
"typeRoots": ["./node_modules/@types", "./node_package/types"]
|
13
16
|
},
|
14
|
-
"include": ["node_package/src/**/*"]
|
17
|
+
"include": ["node_package/src/**/*", "node_package/types/**/*"]
|
15
18
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: react_on_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 15.0.0.alpha.
|
4
|
+
version: 15.0.0.alpha.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Gordon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- SUMMARY.md
|
118
118
|
- app/helpers/react_on_rails_helper.rb
|
119
119
|
- docker-compose.yml
|
120
|
+
- knip.ts
|
120
121
|
- lib/generators/USAGE
|
121
122
|
- lib/generators/react_on_rails/adapt_for_older_shakapacker_generator.rb
|
122
123
|
- lib/generators/react_on_rails/base_generator.rb
|
@@ -203,8 +204,8 @@ post_install_message: |2
|
|
203
204
|
|
204
205
|
--------------------------------------------------------------------------------
|
205
206
|
Checkout https://www.shakacode.com/react-on-rails-pro for information about
|
206
|
-
"React on Rails Pro" which includes
|
207
|
-
|
207
|
+
"React on Rails Pro" which includes a gem for better performance, via caching helpers, and our
|
208
|
+
node rendering server, support for React 19, and much more.
|
208
209
|
--------------------------------------------------------------------------------
|
209
210
|
rdoc_options: []
|
210
211
|
require_paths:
|
@@ -220,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
220
221
|
- !ruby/object:Gem::Version
|
221
222
|
version: '0'
|
222
223
|
requirements: []
|
223
|
-
rubygems_version: 3.5.
|
224
|
+
rubygems_version: 3.5.11
|
224
225
|
signing_key:
|
225
226
|
specification_version: 4
|
226
227
|
summary: Rails with react server rendering with webpack.
|