react_on_rails 16.7.0.rc.2 → 17.0.0.rc.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 +4 -4
- data/Gemfile.development_dependencies +7 -3
- data/Gemfile.lock +14 -6
- data/lib/generators/react_on_rails/generator_helper.rb +23 -6
- data/lib/generators/react_on_rails/install_generator.rb +5 -3
- data/lib/generators/react_on_rails/js_dependency_manager.rb +7 -0
- data/lib/generators/react_on_rails/pro_setup.rb +139 -45
- data/lib/generators/react_on_rails/rsc_setup/client_references.rb +1362 -0
- data/lib/generators/react_on_rails/rsc_setup/layouts.rb +229 -0
- data/lib/generators/react_on_rails/rsc_setup.rb +103 -232
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/clientWebpackConfig.js.tt +11 -1
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/serverWebpackConfig.js.tt +10 -1
- data/lib/generators/react_on_rails/templates/pro/base/config/initializers/react_on_rails_pro.rb.tt +6 -1
- data/lib/generators/react_on_rails/templates/pro/base/renderer/{node-renderer.js → node-renderer.js.tt} +6 -1
- data/lib/react_on_rails/dev/server_manager.rb +19 -1
- data/lib/react_on_rails/doctor.rb +77 -9
- data/lib/react_on_rails/engine.rb +117 -0
- data/lib/react_on_rails/helper.rb +35 -1
- data/lib/react_on_rails/node_renderer_procfile.rb +43 -0
- data/lib/react_on_rails/prerender_error.rb +14 -6
- data/lib/react_on_rails/test_helper/webpack_assets_compiler.rb +4 -4
- data/lib/react_on_rails/version.rb +1 -1
- data/rakelib/lint.rake +1 -1
- data/rakelib/task_helpers.rb +0 -4
- data/rakelib/update_changelog.rake +61 -6
- metadata +6 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 02f0fa1befbed99b17f624249398f47b5a1395ed5407079a472ad39218d2cfc1
|
|
4
|
+
data.tar.gz: f8b4e5a3abf309b98f7b244d1a807acb29096ff7ae1ea115e780eefd35f2d609
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c594211d78c05817226dd5d4ff06e7bb4f377b57320cdb824de7a8902ec40d66473b28da64e0f6d2df5b445786a050d1c6b61779af3fea0c1c4793f3955efa63
|
|
7
|
+
data.tar.gz: e86d35866011de451f725c441539bc7f8400e83d9702a4a3b9058d385e483a926229b4e33e18685636d73700bc7a9a1106246d78174a726327b47b8b0f1645d9
|
|
@@ -2,18 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
eval_gemfile File.expand_path("../Gemfile.shared_dev_dependencies", __dir__)
|
|
4
4
|
|
|
5
|
-
gem "shakapacker", "
|
|
5
|
+
gem "shakapacker", "10.1.0"
|
|
6
6
|
gem "bootsnap", require: false
|
|
7
7
|
gem "rails", "~> 7.1.0"
|
|
8
8
|
|
|
9
|
-
gem "sqlite3", "~>
|
|
9
|
+
gem "sqlite3", "~> 2.0"
|
|
10
10
|
gem "sass-rails", "~> 6.0"
|
|
11
11
|
gem "uglifier"
|
|
12
12
|
gem "jquery-rails"
|
|
13
13
|
gem "puma", "~> 6.0"
|
|
14
14
|
|
|
15
15
|
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
|
|
16
|
-
|
|
16
|
+
# Declared unconditionally so the gemset always matches Gemfile.lock. DISABLE_TURBOLINKS
|
|
17
|
+
# toggles Turbolinks at the application layer (the require_asset in
|
|
18
|
+
# spec/dummy/app/assets/javascripts/application_non_webpack.js.erb), not gem inclusion.
|
|
19
|
+
# A conditional declaration broke `bundle install --frozen` in CI (see AGENTS.md).
|
|
20
|
+
gem "turbolinks"
|
|
17
21
|
|
|
18
22
|
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
|
|
19
23
|
gem "jbuilder"
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
react_on_rails (
|
|
4
|
+
react_on_rails (17.0.0.rc.0)
|
|
5
5
|
addressable
|
|
6
6
|
connection_pool
|
|
7
7
|
execjs (~> 2.5)
|
|
@@ -201,6 +201,10 @@ GEM
|
|
|
201
201
|
nokogiri (1.19.2)
|
|
202
202
|
mini_portile2 (~> 2.8.2)
|
|
203
203
|
racc (~> 1.4)
|
|
204
|
+
nokogiri (1.19.2-arm64-darwin)
|
|
205
|
+
racc (~> 1.4)
|
|
206
|
+
nokogiri (1.19.2-x86_64-linux-gnu)
|
|
207
|
+
racc (~> 1.4)
|
|
204
208
|
ostruct (0.6.1)
|
|
205
209
|
package_json (0.2.0)
|
|
206
210
|
parallel (1.24.0)
|
|
@@ -233,7 +237,7 @@ GEM
|
|
|
233
237
|
nio4r (~> 2.0)
|
|
234
238
|
racc (1.8.1)
|
|
235
239
|
rack (3.2.5)
|
|
236
|
-
rack-proxy (0.
|
|
240
|
+
rack-proxy (0.8.2)
|
|
237
241
|
rack
|
|
238
242
|
rack-session (2.1.1)
|
|
239
243
|
base64 (>= 0.1.0)
|
|
@@ -356,7 +360,7 @@ GEM
|
|
|
356
360
|
rubyzip (>= 1.2.2, < 3.0)
|
|
357
361
|
websocket (~> 1.0)
|
|
358
362
|
semantic_range (3.1.1)
|
|
359
|
-
shakapacker (
|
|
363
|
+
shakapacker (10.1.0)
|
|
360
364
|
activesupport (>= 5.2)
|
|
361
365
|
package_json
|
|
362
366
|
rack-proxy (>= 0.6.1)
|
|
@@ -375,8 +379,10 @@ GEM
|
|
|
375
379
|
actionpack (>= 5.2)
|
|
376
380
|
activesupport (>= 5.2)
|
|
377
381
|
sprockets (>= 3.0.0)
|
|
378
|
-
sqlite3 (
|
|
382
|
+
sqlite3 (2.9.4)
|
|
379
383
|
mini_portile2 (~> 2.8.0)
|
|
384
|
+
sqlite3 (2.9.4-arm64-darwin)
|
|
385
|
+
sqlite3 (2.9.4-x86_64-linux-gnu)
|
|
380
386
|
steep (1.9.4)
|
|
381
387
|
activesupport (>= 5.1)
|
|
382
388
|
concurrent-ruby (>= 1.1.10)
|
|
@@ -428,7 +434,9 @@ GEM
|
|
|
428
434
|
zeitwerk (2.7.5)
|
|
429
435
|
|
|
430
436
|
PLATFORMS
|
|
437
|
+
arm64-darwin
|
|
431
438
|
ruby
|
|
439
|
+
x86_64-linux
|
|
432
440
|
|
|
433
441
|
DEPENDENCIES
|
|
434
442
|
amazing_print
|
|
@@ -467,11 +475,11 @@ DEPENDENCIES
|
|
|
467
475
|
sass-rails (~> 6.0)
|
|
468
476
|
sdoc
|
|
469
477
|
selenium-webdriver (= 4.9.0)
|
|
470
|
-
shakapacker (=
|
|
478
|
+
shakapacker (= 10.1.0)
|
|
471
479
|
simplecov (~> 0.16.1)
|
|
472
480
|
spring (~> 4.0)
|
|
473
481
|
sprockets (~> 4.0)
|
|
474
|
-
sqlite3 (~>
|
|
482
|
+
sqlite3 (~> 2.0)
|
|
475
483
|
steep
|
|
476
484
|
turbo-rails
|
|
477
485
|
turbolinks
|
|
@@ -84,12 +84,16 @@ module GeneratorHelper
|
|
|
84
84
|
false
|
|
85
85
|
end
|
|
86
86
|
|
|
87
|
-
# Check if React on Rails Pro gem is installed
|
|
87
|
+
# Check if React on Rails Pro gem is installed (real state — never "scheduled to be installed").
|
|
88
88
|
#
|
|
89
89
|
# Detection priority:
|
|
90
90
|
# 1. Gem.loaded_specs - gem is loaded in current Ruby process (most reliable)
|
|
91
91
|
# 2. Gemfile.lock - gem is resolved and installed
|
|
92
92
|
#
|
|
93
|
+
# Use {#pro_gem_install_deferred?} for the broader "present, or will be installed by this
|
|
94
|
+
# generator run" meaning. Use {#invalidate_pro_gem_installed_cache!} after an operation
|
|
95
|
+
# that changes real state (e.g., bundle add) so the next call re-reads the lockfile.
|
|
96
|
+
#
|
|
93
97
|
# @return [Boolean] true if react_on_rails_pro gem is installed
|
|
94
98
|
def pro_gem_installed?
|
|
95
99
|
return @pro_gem_installed if defined?(@pro_gem_installed)
|
|
@@ -97,11 +101,6 @@ module GeneratorHelper
|
|
|
97
101
|
@pro_gem_installed = Gem.loaded_specs.key?("react_on_rails_pro") || gem_in_lockfile?("react_on_rails_pro")
|
|
98
102
|
end
|
|
99
103
|
|
|
100
|
-
# TODO: CQS smell: mark_pro_gem_installed! makes pro_gem_installed? return true before install. See #3303.
|
|
101
|
-
def mark_pro_gem_installed!
|
|
102
|
-
@pro_gem_installed = true
|
|
103
|
-
end
|
|
104
|
-
|
|
105
104
|
# Check if Pro features should be enabled.
|
|
106
105
|
# Returns true if --pro or --rsc is set (RSC implies Pro).
|
|
107
106
|
#
|
|
@@ -252,6 +251,24 @@ module GeneratorHelper
|
|
|
252
251
|
|
|
253
252
|
private
|
|
254
253
|
|
|
254
|
+
# Clear the memoized {#pro_gem_installed?} result so the next call re-checks
|
|
255
|
+
# Gem.loaded_specs / Gemfile.lock. Call after any operation that may change real state.
|
|
256
|
+
def invalidate_pro_gem_installed_cache!
|
|
257
|
+
remove_instance_variable(:@pro_gem_installed) if defined?(@pro_gem_installed)
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
# True when a later step in this generator run will install the Pro gem
|
|
261
|
+
# (e.g., the Gemfile swap performed by ProGenerator). Distinct from
|
|
262
|
+
# {#pro_gem_installed?}, which only reports real present state.
|
|
263
|
+
def pro_gem_install_deferred?
|
|
264
|
+
@pro_gem_install_deferred == true
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
# Record that a later step in this generator run will install the Pro gem.
|
|
268
|
+
def defer_pro_gem_install!
|
|
269
|
+
@pro_gem_install_deferred = true
|
|
270
|
+
end
|
|
271
|
+
|
|
255
272
|
# NOTE: only the `default:` section is inspected — same assumption as
|
|
256
273
|
# rspack_configured_in_project?. Projects that set `javascript_transpiler`
|
|
257
274
|
# only in per-environment sections (without a `default:` block) will not be
|
|
@@ -138,11 +138,13 @@ module ReactOnRails
|
|
|
138
138
|
# version because `pnpm/action-setup` requires one unless package.json declares
|
|
139
139
|
# `packageManager`. Match the repo's own packageManager version so generated
|
|
140
140
|
# CI defaults to the pnpm major this codebase tests with. Track the exact release
|
|
141
|
-
# used for this fallback at https://github.com/pnpm/pnpm/releases/tag/
|
|
141
|
+
# used for this fallback at https://github.com/pnpm/pnpm/releases/tag/v10.33.4;
|
|
142
142
|
# update this URL with the constant when bumping. Users who need exact
|
|
143
143
|
# reproducibility should commit `packageManager` to their package.json instead.
|
|
144
|
-
#
|
|
145
|
-
|
|
144
|
+
# Bump checklist: heading text below is spec-asserted.
|
|
145
|
+
# CONTRIBUTING.md > "Updating the pnpm Fallback Version for Scaffolded CI".
|
|
146
|
+
# renovate: datasource=github-releases depName=pnpm/pnpm extractVersion=^v(?<version>.+)$ allowedVersions=<11
|
|
147
|
+
CI_PNPM_FALLBACK_VERSION = "10.33.4"
|
|
146
148
|
private_constant :CI_PNPM_FALLBACK_VERSION
|
|
147
149
|
|
|
148
150
|
# Main generator entry point
|
|
@@ -578,12 +578,19 @@ module ReactOnRails
|
|
|
578
578
|
end
|
|
579
579
|
|
|
580
580
|
File.write("package.json", "#{JSON.pretty_generate(content)}\n")
|
|
581
|
+
GeneratorMessages.add_warning(package_json_pin_fallback_warning(versioned_packages))
|
|
581
582
|
true
|
|
582
583
|
rescue StandardError => e
|
|
583
584
|
GeneratorMessages.add_warning("⚠️ Could not write dependency pins to package.json: #{e.message}")
|
|
584
585
|
false
|
|
585
586
|
end
|
|
586
587
|
|
|
588
|
+
def package_json_pin_fallback_warning(versioned_packages)
|
|
589
|
+
pinned_list = versioned_packages.map { |name, version| "#{name}@#{version}" }.join(", ")
|
|
590
|
+
"⚠️ Package manager install failed. Wrote the following version pins to package.json " \
|
|
591
|
+
"so you can rerun your package manager manually: #{pinned_list}"
|
|
592
|
+
end
|
|
593
|
+
|
|
587
594
|
def fallback_package_manager
|
|
588
595
|
package_manager = GeneratorMessages.detect_package_manager(app_root: destination_root)
|
|
589
596
|
return package_manager if GeneratorMessages.supported_package_manager?(package_manager)
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "securerandom"
|
|
3
4
|
require_relative "generator_messages"
|
|
5
|
+
require "react_on_rails/node_renderer_procfile"
|
|
4
6
|
require "react_on_rails/pro_migration"
|
|
5
7
|
|
|
6
8
|
module ReactOnRails
|
|
@@ -19,7 +21,9 @@ module ReactOnRails
|
|
|
19
21
|
#
|
|
20
22
|
# Including classes must also include GeneratorHelper which provides:
|
|
21
23
|
# - use_pro?, use_rsc?: Feature flag helpers
|
|
22
|
-
# - pro_gem_installed?: Pro gem detection
|
|
24
|
+
# - pro_gem_installed?: Pro gem detection (real lockfile / loaded-specs state)
|
|
25
|
+
# - pro_gem_install_deferred?, defer_pro_gem_install!: deferred-install tracking
|
|
26
|
+
# - invalidate_pro_gem_installed_cache!: invalidate memoized pro_gem_installed?
|
|
23
27
|
#
|
|
24
28
|
# rubocop:disable Metrics/ModuleLength
|
|
25
29
|
module ProSetup
|
|
@@ -43,16 +47,58 @@ module ReactOnRails
|
|
|
43
47
|
say set_color("🚀 REACT ON RAILS PRO SETUP", :cyan, :bold)
|
|
44
48
|
say set_color("=" * 80, :cyan)
|
|
45
49
|
|
|
46
|
-
|
|
50
|
+
# The Rails initializer and Node renderer bootstrap must share the same
|
|
51
|
+
# password literal. Only mint a fresh random password when BOTH files will
|
|
52
|
+
# be created — otherwise nil so each template falls back to the env-only
|
|
53
|
+
# branch, avoiding a literal mismatch with any existing file.
|
|
54
|
+
# Always reassign so a stale value from a prior invocation on the same
|
|
55
|
+
# instance can't leak into a later partial-install run.
|
|
56
|
+
@generated_renderer_password = nil
|
|
57
|
+
if pro_initializer_will_be_created? && node_renderer_will_be_created?
|
|
58
|
+
@generated_renderer_password = SecureRandom.hex(32)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
initializer_created = create_pro_initializer
|
|
47
62
|
legacy_renderer_detected = create_node_renderer
|
|
48
|
-
|
|
63
|
+
add_pro_to_procfiles unless legacy_renderer_detected
|
|
49
64
|
update_webpack_config_for_pro
|
|
50
65
|
|
|
66
|
+
say_renderer_password_setup_summary(initializer_created)
|
|
67
|
+
|
|
51
68
|
say set_color("=" * 80, :cyan)
|
|
52
69
|
say "✅ React on Rails Pro setup complete!", :green
|
|
53
70
|
say set_color("=" * 80, :cyan)
|
|
54
71
|
end
|
|
55
72
|
|
|
73
|
+
def say_renderer_password_setup_summary(initializer_created)
|
|
74
|
+
if @generated_renderer_password
|
|
75
|
+
say ""
|
|
76
|
+
say set_color("🔐 A random renderer password was written into your config files.", :yellow, :bold)
|
|
77
|
+
say " For production, set RENDERER_PASSWORD as an env var instead and"
|
|
78
|
+
say " remove the literal value from version control."
|
|
79
|
+
say " See: https://www.shakacode.com/react-on-rails/docs/pro/node-renderer/"
|
|
80
|
+
say ""
|
|
81
|
+
elsif initializer_created
|
|
82
|
+
# Initializer was newly created but the Node renderer file already exists;
|
|
83
|
+
# the new initializer falls back to ENV["RENDERER_PASSWORD"] only so it doesn't
|
|
84
|
+
# disagree with whatever literal the existing renderer file contains.
|
|
85
|
+
say ""
|
|
86
|
+
say set_color("⚠️ Existing Node renderer detected — Rails initializer uses " \
|
|
87
|
+
"ENV[\"RENDERER_PASSWORD\"] only.", :yellow, :bold)
|
|
88
|
+
say " Set RENDERER_PASSWORD in your environment to match the password in your existing renderer."
|
|
89
|
+
say ""
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def pro_initializer_will_be_created?
|
|
94
|
+
!File.exist?(File.join(destination_root, "config/initializers/react_on_rails_pro.rb"))
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def node_renderer_will_be_created?
|
|
98
|
+
!File.exist?(File.join(destination_root, "renderer/node-renderer.js")) &&
|
|
99
|
+
!File.exist?(File.join(destination_root, "client/node-renderer.js"))
|
|
100
|
+
end
|
|
101
|
+
|
|
56
102
|
# Check if the Pro gem is missing. When the base react_on_rails gem is in
|
|
57
103
|
# the Gemfile, installation is deferred to the later Gemfile swap (which
|
|
58
104
|
# preserves the user's version pin); otherwise auto-install via `bundle
|
|
@@ -63,7 +109,7 @@ module ReactOnRails
|
|
|
63
109
|
# is deferred to the Gemfile swap.
|
|
64
110
|
def missing_pro_gem?(force: false)
|
|
65
111
|
return false unless force || use_pro?
|
|
66
|
-
return false if pro_gem_installed?
|
|
112
|
+
return false if pro_gem_installed? || pro_gem_install_deferred?
|
|
67
113
|
return false if defer_pro_gem_install_to_gemfile_swap
|
|
68
114
|
return false if attempt_pro_gem_auto_install
|
|
69
115
|
|
|
@@ -126,7 +172,8 @@ module ReactOnRails
|
|
|
126
172
|
|
|
127
173
|
# The gem is now in Gemfile/lockfile but not loaded in the current Ruby process.
|
|
128
174
|
# Generator code that follows must not reference ReactOnRailsPro constants directly.
|
|
129
|
-
|
|
175
|
+
# The lockfile changed, so the memoized pro_gem_installed? must be refreshed.
|
|
176
|
+
invalidate_pro_gem_installed_cache!
|
|
130
177
|
true
|
|
131
178
|
rescue StandardError => e
|
|
132
179
|
say "⚠️ Failed to run bundle add: #{e.message}", :red
|
|
@@ -201,27 +248,57 @@ module ReactOnRails
|
|
|
201
248
|
|
|
202
249
|
if File.exist?(File.join(destination_root, initializer_path))
|
|
203
250
|
say "ℹ️ #{initializer_path} already exists, skipping", :yellow
|
|
204
|
-
return
|
|
251
|
+
return false
|
|
205
252
|
end
|
|
206
253
|
|
|
207
254
|
say "📝 Creating React on Rails Pro initializer...", :yellow
|
|
208
255
|
|
|
256
|
+
# @generated_renderer_password is set by setup_pro only when both this
|
|
257
|
+
# file and the Node renderer bootstrap will be created together; nil here
|
|
258
|
+
# means the template emits the env-only fallback (no literal password).
|
|
209
259
|
template("templates/pro/base/config/initializers/react_on_rails_pro.rb.tt", initializer_path)
|
|
210
260
|
|
|
211
261
|
say "✅ Created #{initializer_path}", :green
|
|
262
|
+
true
|
|
212
263
|
end
|
|
213
264
|
|
|
214
|
-
# Matches active (uncommented) Procfile.dev node-renderer lines
|
|
215
|
-
#
|
|
216
|
-
#
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
265
|
+
# Matches active (uncommented) Procfile.dev node-renderer lines that
|
|
266
|
+
# both set RENDERER_PORT and launch renderer/node-renderer.js (optionally
|
|
267
|
+
# prefixed with `./`). Entries missing RENDERER_PORT are intentionally
|
|
268
|
+
# not matched here so they fall through to NODE_RENDERER_PROCESS_REGEX
|
|
269
|
+
# and surface the "Update it manually" warning, keeping the generator's
|
|
270
|
+
# accept/skip decision aligned with the doctor's RENDERER_PORT check in
|
|
271
|
+
# NodeRendererProcfile::PROCESS_WITH_RENDERER_PORT_REGEX.
|
|
272
|
+
NEW_RENDERER_COMMAND_REGEX = %r{
|
|
273
|
+
^[ \t]*(?:node-)?renderer:
|
|
274
|
+
(?=[^\n]*\bRENDERER_PORT\b)
|
|
275
|
+
[^\n]*\bnode\s+\.?/?renderer/node-renderer\.js\b
|
|
276
|
+
}x
|
|
277
|
+
LEGACY_RENDERER_COMMAND_REGEX = %r{^[ \t]*(?:node-)?renderer:[^\n]*\bnode\s+\.?/?client/node-renderer\.js\b}
|
|
278
|
+
# Detects an existing Node Renderer process entry. The dedicated
|
|
279
|
+
# `node-renderer:` label is reserved for the Pro Node Renderer, so any
|
|
280
|
+
# entry with that label is treated as the user's renderer regardless of
|
|
281
|
+
# the command (avoiding duplicate-label appends). A bare `renderer:`
|
|
282
|
+
# label could be anything (e.g. `renderer: vite ...`), so it only counts
|
|
283
|
+
# when the command actually launches a node-renderer — otherwise the
|
|
284
|
+
# generator would emit a misleading "update it manually" warning for an
|
|
285
|
+
# unrelated process.
|
|
286
|
+
NODE_RENDERER_PROCESS_REGEX = %r{
|
|
287
|
+
^[ \t]*(?:
|
|
288
|
+
node-renderer:
|
|
289
|
+
|
|
|
290
|
+
renderer:[^\n]*(?:
|
|
291
|
+
\bnode\s+\.?/?(?:renderer|client)/node-renderer\.js\b
|
|
292
|
+
|
|
|
293
|
+
\b(?:pnpm|npm|yarn)\s+(?:run\s+)?node-renderer\b
|
|
294
|
+
)
|
|
295
|
+
)
|
|
296
|
+
}x
|
|
220
297
|
# Creates renderer/node-renderer.js unless either the new path or the legacy
|
|
221
298
|
# client/node-renderer.js already exists.
|
|
222
299
|
#
|
|
223
300
|
# @return [Boolean] true when a legacy client/node-renderer.js was detected
|
|
224
|
-
# (caller should skip
|
|
301
|
+
# (caller should skip add_pro_to_procfiles to avoid pointing Procfile.dev
|
|
225
302
|
# at a file that wasn't created); false otherwise.
|
|
226
303
|
def create_node_renderer
|
|
227
304
|
node_renderer_path = "renderer/node-renderer.js"
|
|
@@ -236,8 +313,12 @@ module ReactOnRails
|
|
|
236
313
|
say "ℹ️ #{legacy_node_renderer_path} detected, keeping existing renderer; " \
|
|
237
314
|
"to migrate, move it to #{node_renderer_path} and update any references " \
|
|
238
315
|
"(e.g. Procfile.dev, Procfile.prod, Docker CMD / command):", :yellow
|
|
239
|
-
say "
|
|
240
|
-
|
|
316
|
+
say " #{node_renderer_procfile_command('Procfile.dev')}", :yellow
|
|
317
|
+
say set_color(
|
|
318
|
+
"⚠️ Ensure the password in #{legacy_node_renderer_path} matches " \
|
|
319
|
+
"config/initializers/react_on_rails_pro.rb. Both must use the same RENDERER_PASSWORD.",
|
|
320
|
+
:yellow
|
|
321
|
+
)
|
|
241
322
|
warn_on_stale_legacy_procfile_entry
|
|
242
323
|
return true
|
|
243
324
|
end
|
|
@@ -246,41 +327,55 @@ module ReactOnRails
|
|
|
246
327
|
|
|
247
328
|
empty_directory("renderer")
|
|
248
329
|
|
|
249
|
-
template_path = "templates/pro/base/renderer/node-renderer.js"
|
|
250
|
-
|
|
330
|
+
template_path = "templates/pro/base/renderer/node-renderer.js.tt"
|
|
331
|
+
template(template_path, node_renderer_path)
|
|
251
332
|
|
|
252
333
|
say "✅ Created #{node_renderer_path}", :green
|
|
253
334
|
false
|
|
254
335
|
end
|
|
255
336
|
|
|
256
|
-
# When a legacy client/node-renderer.js is detected,
|
|
257
|
-
# skipped, so surface a pointed warning
|
|
258
|
-
# legacy entry. This nudges the user to update the exact
|
|
259
|
-
# touch rather than leaving them to diff the generic
|
|
260
|
-
# their
|
|
337
|
+
# When a legacy client/node-renderer.js is detected, add_pro_to_procfiles is
|
|
338
|
+
# skipped, so surface a pointed warning for each Procfile that still
|
|
339
|
+
# launches the legacy entry. This nudges the user to update the exact
|
|
340
|
+
# line(s) they need to touch rather than leaving them to diff the generic
|
|
341
|
+
# migration hint against their Procfiles themselves.
|
|
261
342
|
def warn_on_stale_legacy_procfile_entry
|
|
262
|
-
|
|
263
|
-
|
|
343
|
+
ReactOnRails::NodeRendererProcfile::DEFAULT_COMMANDS.each_key do |procfile|
|
|
344
|
+
procfile_path = File.join(destination_root, procfile)
|
|
345
|
+
next unless File.exist?(procfile_path)
|
|
264
346
|
|
|
265
|
-
|
|
266
|
-
|
|
347
|
+
procfile_content = File.read(procfile_path)
|
|
348
|
+
next unless procfile_content.match?(LEGACY_RENDERER_COMMAND_REGEX)
|
|
267
349
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
350
|
+
GeneratorMessages.add_warning(<<~MSG.strip)
|
|
351
|
+
⚠️ #{procfile} still launches the legacy client/node-renderer.js.
|
|
352
|
+
After migrating the renderer file, update that line to:
|
|
353
|
+
#{node_renderer_procfile_command(procfile)}
|
|
354
|
+
MSG
|
|
355
|
+
end
|
|
273
356
|
end
|
|
274
357
|
|
|
275
|
-
def
|
|
276
|
-
|
|
358
|
+
def node_renderer_procfile_command(procfile)
|
|
359
|
+
ReactOnRails::NodeRendererProcfile.command_for(procfile)
|
|
360
|
+
end
|
|
361
|
+
|
|
362
|
+
def add_pro_to_procfiles
|
|
363
|
+
ReactOnRails::NodeRendererProcfile::DEFAULT_COMMANDS.each do |procfile, command|
|
|
364
|
+
add_node_renderer_to_procfile(procfile, command, warn_if_missing: procfile == "Procfile.dev")
|
|
365
|
+
end
|
|
366
|
+
end
|
|
367
|
+
|
|
368
|
+
def add_node_renderer_to_procfile(procfile, command, warn_if_missing:)
|
|
369
|
+
procfile_path = File.join(destination_root, procfile)
|
|
277
370
|
|
|
278
371
|
unless File.exist?(procfile_path)
|
|
372
|
+
return unless warn_if_missing
|
|
373
|
+
|
|
279
374
|
GeneratorMessages.add_warning(<<~MSG.strip)
|
|
280
|
-
⚠️
|
|
375
|
+
⚠️ #{procfile} not found. Skipping Node Renderer process addition.
|
|
281
376
|
|
|
282
377
|
You'll need to add the Node Renderer to your process manager manually:
|
|
283
|
-
|
|
378
|
+
#{command}
|
|
284
379
|
MSG
|
|
285
380
|
return
|
|
286
381
|
end
|
|
@@ -288,29 +383,28 @@ module ReactOnRails
|
|
|
288
383
|
procfile_content = File.read(procfile_path)
|
|
289
384
|
|
|
290
385
|
if procfile_content.match?(NEW_RENDERER_COMMAND_REGEX)
|
|
291
|
-
say "ℹ️ Node Renderer already in
|
|
386
|
+
say "ℹ️ Node Renderer already in #{procfile}, skipping", :yellow
|
|
292
387
|
return
|
|
293
388
|
end
|
|
294
389
|
|
|
295
|
-
if procfile_content.match?(
|
|
296
|
-
say "⚠️
|
|
390
|
+
if procfile_content.match?(NODE_RENDERER_PROCESS_REGEX)
|
|
391
|
+
say "⚠️ #{procfile} has a renderer entry that doesn't reference " \
|
|
297
392
|
"renderer/node-renderer.js. Update it manually to:", :yellow
|
|
298
|
-
say "
|
|
299
|
-
"node renderer/node-renderer.js", :yellow
|
|
393
|
+
say " #{command}", :yellow
|
|
300
394
|
return
|
|
301
395
|
end
|
|
302
396
|
|
|
303
|
-
say "📝 Adding Node Renderer to
|
|
397
|
+
say "📝 Adding Node Renderer to #{procfile}...", :yellow
|
|
304
398
|
|
|
305
399
|
node_renderer_line = <<~PROCFILE
|
|
306
400
|
|
|
307
401
|
# React on Rails Pro - Node Renderer for SSR
|
|
308
|
-
|
|
402
|
+
#{command}
|
|
309
403
|
PROCFILE
|
|
310
404
|
|
|
311
|
-
append_to_file(
|
|
405
|
+
append_to_file(procfile, node_renderer_line)
|
|
312
406
|
|
|
313
|
-
say "✅ Added Node Renderer to
|
|
407
|
+
say "✅ Added Node Renderer to #{procfile}", :green
|
|
314
408
|
end
|
|
315
409
|
|
|
316
410
|
# Update webpack configs to enable Pro settings.
|
|
@@ -542,7 +636,7 @@ module ReactOnRails
|
|
|
542
636
|
def defer_pro_gem_install_to_gemfile_swap
|
|
543
637
|
return false unless base_react_on_rails_gem_in_gemfile?
|
|
544
638
|
|
|
545
|
-
|
|
639
|
+
defer_pro_gem_install!
|
|
546
640
|
true
|
|
547
641
|
end
|
|
548
642
|
|