react_on_rails 16.2.0.beta.8 → 16.2.0.beta.10
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 +19 -10
- data/Gemfile.lock +1 -1
- data/knip.ts +1 -1
- data/lib/generators/react_on_rails/base_generator.rb +3 -118
- data/lib/generators/react_on_rails/install_generator.rb +5 -180
- data/lib/generators/react_on_rails/js_dependency_manager.rb +332 -0
- data/lib/generators/react_on_rails/templates/base/base/config/shakapacker.yml +9 -2
- data/lib/react_on_rails/engine.rb +2 -5
- data/lib/react_on_rails/version.rb +1 -1
- data/react_on_rails_pro/Gemfile.lock +3 -3
- data/react_on_rails_pro/lib/react_on_rails_pro/version.rb +1 -1
- data/react_on_rails_pro/package.json +1 -1
- data/react_on_rails_pro/spec/dummy/Gemfile.lock +3 -3
- data/react_on_rails_pro/spec/dummy/bin/shakapacker-precompile-hook +19 -0
- data/react_on_rails_pro/spec/dummy/config/shakapacker.yml +5 -0
- data/sig/react_on_rails/generators/js_dependency_manager.rbs +123 -0
- metadata +5 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: da10987e43490e2a8da60fccb2033038aa9fa6a9b5ccce9add3f9d0da795474c
|
|
4
|
+
data.tar.gz: 9e7a3a46c8bb8e0fcc57142b5a1218ea58d5155d54614038d035e2e6b39fdf47
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d9f6d5be2b5bf2437adc711b6ac77e64fb7c6540d34bdce6380e98bf919872ec59e897b87869e25221f1f461ac91b25fc146c48701eb161630cb9bea7c44c7a1
|
|
7
|
+
data.tar.gz: 5ec66977d53c808a8983277c6534e24fe966123105c4738e20995a9bb45be34a139030fe3e70ffe3251bb9961470371841bea040e558deb3fc974c154d6bdb7d
|
data/CHANGELOG.md
CHANGED
|
@@ -23,17 +23,11 @@ After a release, please make sure to run `bundle exec rake update_changelog`. Th
|
|
|
23
23
|
|
|
24
24
|
Changes since the last non-beta release.
|
|
25
25
|
|
|
26
|
-
####
|
|
27
|
-
|
|
28
|
-
- **Generator Configuration Modernization**: Updated the generator to enable recommended configurations by default for new applications:
|
|
29
|
-
|
|
30
|
-
- `config.build_test_command` is now uncommented and set to `"RAILS_ENV=test bin/shakapacker"` by default, enabling automatic asset building during tests for better integration test reliability
|
|
31
|
-
- `config.auto_load_bundle = true` is now set by default, enabling automatic loading of component bundles
|
|
32
|
-
- `config.components_subdirectory = "ror_components"` is now set by default, organizing React components in a dedicated subdirectory
|
|
26
|
+
#### Fixed
|
|
33
27
|
|
|
34
|
-
|
|
28
|
+
- **Duplicate Rake Task Execution**: Fixed rake tasks executing twice during asset precompilation and other rake operations. Rails Engine was loading task files twice: once via explicit `load` calls in the `rake_tasks` block (Railtie layer) and once via automatic file loading from `lib/tasks/` (Engine layer). This caused `react_on_rails:assets:webpack`, `react_on_rails:generate_packs`, and `react_on_rails:locale` tasks to run twice, significantly increasing build times. Removed explicit `load` calls and now rely on Rails Engine's standard auto-loading behavior. [PR 2052](https://github.com/shakacode/react_on_rails/pull/2052) by [justin808](https://github.com/justin808).
|
|
35
29
|
|
|
36
|
-
### [
|
|
30
|
+
### [v16.2.0.beta.8] - 2025-11-16
|
|
37
31
|
|
|
38
32
|
#### Added
|
|
39
33
|
|
|
@@ -49,6 +43,8 @@ Changes since the last non-beta release.
|
|
|
49
43
|
|
|
50
44
|
- **Use as Git dependency**: All packages can now be installed as Git dependencies. This is useful for development and testing purposes. See [CONTRIBUTING.md](./CONTRIBUTING.md#git-dependencies) for documentation. [PR #1873](https://github.com/shakacode/react_on_rails/pull/1873) by [alexeyr-ci2](https://github.com/alexeyr-ci2).
|
|
51
45
|
|
|
46
|
+
- **Doctor Checks for :async Loading Strategy**: Added proactive diagnostic checks to the React on Rails doctor tool to detect usage of the `:async` loading strategy in projects without React on Rails Pro. The feature scans view files and initializer configuration, providing clear guidance to either upgrade to Pro or use alternative loading strategies like `:defer` or `:sync` to avoid component registration race conditions. [PR 2010](https://github.com/shakacode/react_on_rails/pull/2010) by [justin808](https://github.com/justin808).
|
|
47
|
+
|
|
52
48
|
#### Changed
|
|
53
49
|
|
|
54
50
|
- **Shakapacker 9.0.0 Upgrade**: Upgraded Shakapacker from 8.2.0 to 9.0.0 with Babel transpiler configuration for compatibility. Key changes include:
|
|
@@ -63,6 +59,10 @@ Changes since the last non-beta release.
|
|
|
63
59
|
|
|
64
60
|
- **`generated_component_packs_loading_strategy` now defaults based on Pro license**: When using Shakapacker >= 8.2.0, the default loading strategy is now `:async` for Pro users and `:defer` for non-Pro users. This provides optimal performance for Pro users while maintaining compatibility for non-Pro users. You can still explicitly set the strategy in your configuration. [PR #1993](https://github.com/shakacode/react_on_rails/pull/1993) by [AbanoubGhadban](https://github.com/AbanoubGhadban).
|
|
65
61
|
|
|
62
|
+
- **Generator Configuration Modernization**: Updated the generator to enable recommended configurations by default for new applications. `config.build_test_command` is now uncommented and set to `"RAILS_ENV=test bin/shakapacker"` by default, enabling automatic asset building during tests for better integration test reliability. `config.auto_load_bundle = true` is now set by default, enabling automatic loading of component bundles. `config.components_subdirectory = "ror_components"` is now set by default, organizing React components in a dedicated subdirectory. **Note:** These changes only affect newly generated applications. Existing applications are unaffected and do not need to make any changes. If you want to adopt these settings in an existing app, you can manually add them to your `config/initializers/react_on_rails.rb` file. [PR 2039](https://github.com/shakacode/react_on_rails/pull/2039) by [justin808](https://github.com/justin808).
|
|
63
|
+
|
|
64
|
+
- **Removed Babel Dependency Installation**: The generator no longer installs `@babel/preset-react` or `@babel/preset-typescript` packages. Shakapacker handles JavaScript transpiler configuration (Babel, SWC, or esbuild) via the `javascript_transpiler` setting in `shakapacker.yml`. SWC is now the default transpiler and includes built-in support for React and TypeScript. Users who explicitly choose Babel will need to manually install and configure the required presets. This change reduces unnecessary dependencies and aligns with Shakapacker's modular transpiler approach. [PR 2051](https://github.com/shakacode/react_on_rails/pull/2051) by [justin808](https://github.com/justin808).
|
|
65
|
+
|
|
66
66
|
#### Documentation
|
|
67
67
|
|
|
68
68
|
- **Simplified Configuration Files**: Improved configuration documentation and generator template for better clarity and usability. Reduced generator template from 67 to 42 lines (37% reduction). Added comprehensive testing configuration guide. Reorganized configuration docs into Essential vs Advanced sections. Enhanced Doctor program with diagnostics for server rendering and test compilation consistency. [PR #2011](https://github.com/shakacode/react_on_rails/pull/2011) by [justin808](https://github.com/justin808).
|
|
@@ -77,6 +77,14 @@ Changes since the last non-beta release.
|
|
|
77
77
|
|
|
78
78
|
- **Body Duplication Bug On Streaming**: Fixed a bug that happens while streaming if the node renderer connection closed after streaming some chunks to the client. [PR #1995](https://github.com/shakacode/react_on_rails/pull/1995) by [AbanoubGhadban](https://github.com/AbanoubGhadban).
|
|
79
79
|
|
|
80
|
+
- **bin/dev --verbose Option**: Fixed `OptionParser::InvalidOption` error that occurred when using the `--verbose`/`-v` flag. The flag was documented in help text but not functional. Now properly implemented with flag parsing and passing verbose option through method calls. [PR 2023](https://github.com/shakacode/react_on_rails/pull/2023) by [justin808](https://github.com/justin808).
|
|
81
|
+
|
|
82
|
+
- **Shakapacker Template Configuration**: Fixed shakapacker.yml template to prevent unnecessary "Slow setup for development" warnings by setting `compile: false` as the default configuration. This allows development environments to inherit the setting instead of forcing on-demand compilation when using Procfiles with `bin/dev` that already run the shakapacker dev server or watch mode. [PR 2021](https://github.com/shakacode/react_on_rails/pull/2021) by [justin808](https://github.com/justin808).
|
|
83
|
+
|
|
84
|
+
#### Improved
|
|
85
|
+
|
|
86
|
+
- **Concurrent Streaming Performance**: Implemented concurrent draining of streamed React components using the async gem. Instead of processing components sequentially, the system now uses a producer-consumer pattern with bounded buffering to allow multiple components to stream simultaneously while maintaining per-component chunk ordering. [PR 2015](https://github.com/shakacode/react_on_rails/pull/2015) by [ihabadham](https://github.com/ihabadham).
|
|
87
|
+
|
|
80
88
|
#### Breaking Changes
|
|
81
89
|
|
|
82
90
|
- **`config.immediate_hydration` configuration removed**: The `config.immediate_hydration` setting in `config/initializers/react_on_rails.rb` has been removed. Immediate hydration is now automatically enabled for React on Rails Pro users and automatically disabled for non-Pro users.
|
|
@@ -1837,7 +1845,8 @@ such as:
|
|
|
1837
1845
|
|
|
1838
1846
|
- Fix several generator-related issues.
|
|
1839
1847
|
|
|
1840
|
-
[unreleased]: https://github.com/shakacode/react_on_rails/compare/
|
|
1848
|
+
[unreleased]: https://github.com/shakacode/react_on_rails/compare/v16.2.0.beta.8...master
|
|
1849
|
+
[v16.2.0.beta.8]: https://github.com/shakacode/react_on_rails/compare/16.2.0.beta.4...v16.2.0.beta.8
|
|
1841
1850
|
[16.2.0.beta.4]: https://github.com/shakacode/react_on_rails/compare/16.1.1...16.2.0.beta.4
|
|
1842
1851
|
[16.1.1]: https://github.com/shakacode/react_on_rails/compare/16.1.0...16.1.1
|
|
1843
1852
|
[16.1.0]: https://github.com/shakacode/react_on_rails/compare/16.0.0...16.1.0
|
data/Gemfile.lock
CHANGED
data/knip.ts
CHANGED
|
@@ -162,7 +162,7 @@ const config: KnipConfig = {
|
|
|
162
162
|
'url-loader',
|
|
163
163
|
// Transitive dependency of shakapacker but listed as direct dependency
|
|
164
164
|
'webpack-merge',
|
|
165
|
-
// Dependencies not detected in production mode
|
|
165
|
+
// Dependencies not detected in production mode (runtime injected or dynamic imports)
|
|
166
166
|
'@babel/runtime',
|
|
167
167
|
'mini-css-extract-plugin',
|
|
168
168
|
'css-loader',
|
|
@@ -4,10 +4,12 @@ require "rails/generators"
|
|
|
4
4
|
require "fileutils"
|
|
5
5
|
require_relative "generator_messages"
|
|
6
6
|
require_relative "generator_helper"
|
|
7
|
+
require_relative "js_dependency_manager"
|
|
7
8
|
module ReactOnRails
|
|
8
9
|
module Generators
|
|
9
10
|
class BaseGenerator < Rails::Generators::Base
|
|
10
11
|
include GeneratorHelper
|
|
12
|
+
include JsDependencyManager
|
|
11
13
|
|
|
12
14
|
Rails::Generators.hide_namespace(namespace)
|
|
13
15
|
source_root(File.expand_path("templates", __dir__))
|
|
@@ -107,7 +109,7 @@ module ReactOnRails
|
|
|
107
109
|
run "bundle"
|
|
108
110
|
end
|
|
109
111
|
|
|
110
|
-
def
|
|
112
|
+
def update_gitignore_for_auto_registration
|
|
111
113
|
gitignore_path = File.join(destination_root, ".gitignore")
|
|
112
114
|
return unless File.exist?(gitignore_path)
|
|
113
115
|
|
|
@@ -146,123 +148,6 @@ module ReactOnRails
|
|
|
146
148
|
|
|
147
149
|
private
|
|
148
150
|
|
|
149
|
-
def setup_js_dependencies
|
|
150
|
-
add_js_dependencies
|
|
151
|
-
install_js_dependencies
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
def add_js_dependencies
|
|
155
|
-
add_react_on_rails_package
|
|
156
|
-
add_react_dependencies
|
|
157
|
-
add_css_dependencies
|
|
158
|
-
add_dev_dependencies
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
def add_react_on_rails_package
|
|
162
|
-
major_minor_patch_only = /\A\d+\.\d+\.\d+\z/
|
|
163
|
-
|
|
164
|
-
# Try to use package_json gem first, fall back to direct npm commands
|
|
165
|
-
react_on_rails_pkg = if ReactOnRails::VERSION.match?(major_minor_patch_only)
|
|
166
|
-
["react-on-rails@#{ReactOnRails::VERSION}"]
|
|
167
|
-
else
|
|
168
|
-
puts "Adding the latest react-on-rails NPM module. " \
|
|
169
|
-
"Double check this is correct in package.json"
|
|
170
|
-
["react-on-rails"]
|
|
171
|
-
end
|
|
172
|
-
|
|
173
|
-
puts "Installing React on Rails package..."
|
|
174
|
-
return if add_npm_dependencies(react_on_rails_pkg)
|
|
175
|
-
|
|
176
|
-
puts "Using direct npm commands as fallback"
|
|
177
|
-
success = system("npm", "install", *react_on_rails_pkg)
|
|
178
|
-
handle_npm_failure("react-on-rails package", react_on_rails_pkg) unless success
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
def add_react_dependencies
|
|
182
|
-
puts "Installing React dependencies..."
|
|
183
|
-
react_deps = %w[
|
|
184
|
-
react
|
|
185
|
-
react-dom
|
|
186
|
-
@babel/preset-react
|
|
187
|
-
prop-types
|
|
188
|
-
babel-plugin-transform-react-remove-prop-types
|
|
189
|
-
babel-plugin-macros
|
|
190
|
-
]
|
|
191
|
-
return if add_npm_dependencies(react_deps)
|
|
192
|
-
|
|
193
|
-
success = system("npm", "install", *react_deps)
|
|
194
|
-
handle_npm_failure("React dependencies", react_deps) unless success
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
def add_css_dependencies
|
|
198
|
-
puts "Installing CSS handling dependencies..."
|
|
199
|
-
css_deps = %w[
|
|
200
|
-
css-loader
|
|
201
|
-
css-minimizer-webpack-plugin
|
|
202
|
-
mini-css-extract-plugin
|
|
203
|
-
style-loader
|
|
204
|
-
]
|
|
205
|
-
return if add_npm_dependencies(css_deps)
|
|
206
|
-
|
|
207
|
-
success = system("npm", "install", *css_deps)
|
|
208
|
-
handle_npm_failure("CSS dependencies", css_deps) unless success
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
def add_dev_dependencies
|
|
212
|
-
puts "Installing development dependencies..."
|
|
213
|
-
dev_deps = %w[
|
|
214
|
-
@pmmmwh/react-refresh-webpack-plugin
|
|
215
|
-
react-refresh
|
|
216
|
-
]
|
|
217
|
-
return if add_npm_dependencies(dev_deps, dev: true)
|
|
218
|
-
|
|
219
|
-
success = system("npm", "install", "--save-dev", *dev_deps)
|
|
220
|
-
handle_npm_failure("development dependencies", dev_deps, dev: true) unless success
|
|
221
|
-
end
|
|
222
|
-
|
|
223
|
-
def install_js_dependencies
|
|
224
|
-
# Detect which package manager to use
|
|
225
|
-
success = if File.exist?(File.join(destination_root, "yarn.lock"))
|
|
226
|
-
system("yarn", "install")
|
|
227
|
-
elsif File.exist?(File.join(destination_root, "pnpm-lock.yaml"))
|
|
228
|
-
system("pnpm", "install")
|
|
229
|
-
elsif File.exist?(File.join(destination_root, "package-lock.json")) ||
|
|
230
|
-
File.exist?(File.join(destination_root, "package.json"))
|
|
231
|
-
# Use npm for package-lock.json or as default fallback
|
|
232
|
-
system("npm", "install")
|
|
233
|
-
else
|
|
234
|
-
true # No package manager detected, skip
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
unless success
|
|
238
|
-
GeneratorMessages.add_warning(<<~MSG.strip)
|
|
239
|
-
⚠️ JavaScript dependencies installation failed.
|
|
240
|
-
|
|
241
|
-
This could be due to network issues or missing package manager.
|
|
242
|
-
You can install dependencies manually later by running:
|
|
243
|
-
• npm install (if using npm)
|
|
244
|
-
• yarn install (if using yarn)
|
|
245
|
-
• pnpm install (if using pnpm)
|
|
246
|
-
MSG
|
|
247
|
-
end
|
|
248
|
-
|
|
249
|
-
success
|
|
250
|
-
end
|
|
251
|
-
|
|
252
|
-
def handle_npm_failure(dependency_type, packages, dev: false)
|
|
253
|
-
install_command = dev ? "npm install --save-dev" : "npm install"
|
|
254
|
-
GeneratorMessages.add_warning(<<~MSG.strip)
|
|
255
|
-
⚠️ Failed to install #{dependency_type}.
|
|
256
|
-
|
|
257
|
-
The following packages could not be installed automatically:
|
|
258
|
-
#{packages.map { |pkg| " • #{pkg}" }.join("\n")}
|
|
259
|
-
|
|
260
|
-
This could be due to network issues or missing package manager.
|
|
261
|
-
You can install them manually later by running:
|
|
262
|
-
#{install_command} #{packages.join(' ')}
|
|
263
|
-
MSG
|
|
264
|
-
end
|
|
265
|
-
|
|
266
151
|
def copy_webpack_main_config(base_path, config)
|
|
267
152
|
webpack_config_path = "config/webpack/webpack.config.js"
|
|
268
153
|
|
|
@@ -4,12 +4,14 @@ require "rails/generators"
|
|
|
4
4
|
require "json"
|
|
5
5
|
require_relative "generator_helper"
|
|
6
6
|
require_relative "generator_messages"
|
|
7
|
+
require_relative "js_dependency_manager"
|
|
7
8
|
|
|
8
9
|
module ReactOnRails
|
|
9
10
|
module Generators
|
|
10
11
|
# rubocop:disable Metrics/ClassLength
|
|
11
12
|
class InstallGenerator < Rails::Generators::Base
|
|
12
13
|
include GeneratorHelper
|
|
14
|
+
include JsDependencyManager
|
|
13
15
|
|
|
14
16
|
# fetch USAGE file for details generator description
|
|
15
17
|
source_root(File.expand_path(__dir__))
|
|
@@ -113,10 +115,7 @@ module ReactOnRails
|
|
|
113
115
|
end
|
|
114
116
|
|
|
115
117
|
def setup_react_dependencies
|
|
116
|
-
|
|
117
|
-
@ran_direct_installs ||= false
|
|
118
|
-
add_js_dependencies
|
|
119
|
-
install_js_dependencies if @added_dependencies_to_package_json && !@ran_direct_installs
|
|
118
|
+
setup_js_dependencies
|
|
120
119
|
end
|
|
121
120
|
|
|
122
121
|
# NOTE: other requirements for existing files such as .gitignore or application.
|
|
@@ -366,29 +365,8 @@ module ReactOnRails
|
|
|
366
365
|
|
|
367
366
|
def install_typescript_dependencies
|
|
368
367
|
puts Rainbow("📝 Installing TypeScript dependencies...").yellow
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
typescript_packages = %w[
|
|
372
|
-
typescript
|
|
373
|
-
@types/react
|
|
374
|
-
@types/react-dom
|
|
375
|
-
@babel/preset-typescript
|
|
376
|
-
]
|
|
377
|
-
|
|
378
|
-
# Try using GeneratorHelper first (package manager agnostic)
|
|
379
|
-
return if add_npm_dependencies(typescript_packages, dev: true)
|
|
380
|
-
|
|
381
|
-
# Fallback to npm if GeneratorHelper fails
|
|
382
|
-
success = system("npm", "install", "--save-dev", *typescript_packages)
|
|
383
|
-
return if success
|
|
384
|
-
|
|
385
|
-
warning = <<~MSG.strip
|
|
386
|
-
⚠️ Failed to install TypeScript dependencies automatically.
|
|
387
|
-
|
|
388
|
-
Please run manually:
|
|
389
|
-
npm install --save-dev #{typescript_packages.join(' ')}
|
|
390
|
-
MSG
|
|
391
|
-
GeneratorMessages.add_warning(warning)
|
|
368
|
+
# Delegate to shared module for consistent dependency management
|
|
369
|
+
add_typescript_dependencies
|
|
392
370
|
end
|
|
393
371
|
|
|
394
372
|
def create_css_module_types
|
|
@@ -450,159 +428,6 @@ module ReactOnRails
|
|
|
450
428
|
puts Rainbow("✅ Created tsconfig.json").green
|
|
451
429
|
end
|
|
452
430
|
|
|
453
|
-
def add_js_dependencies
|
|
454
|
-
add_react_on_rails_package
|
|
455
|
-
add_react_dependencies
|
|
456
|
-
add_css_dependencies
|
|
457
|
-
add_rspack_dependencies if options.rspack?
|
|
458
|
-
add_dev_dependencies
|
|
459
|
-
end
|
|
460
|
-
|
|
461
|
-
def add_react_on_rails_package
|
|
462
|
-
major_minor_patch_only = /\A\d+\.\d+\.\d+\z/
|
|
463
|
-
|
|
464
|
-
# Try to use package_json gem first, fall back to direct npm commands
|
|
465
|
-
react_on_rails_pkg = if ReactOnRails::VERSION.match?(major_minor_patch_only)
|
|
466
|
-
["react-on-rails@#{ReactOnRails::VERSION}"]
|
|
467
|
-
else
|
|
468
|
-
puts "Adding the latest react-on-rails NPM module. " \
|
|
469
|
-
"Double check this is correct in package.json"
|
|
470
|
-
["react-on-rails"]
|
|
471
|
-
end
|
|
472
|
-
|
|
473
|
-
puts "Installing React on Rails package..."
|
|
474
|
-
if add_npm_dependencies(react_on_rails_pkg)
|
|
475
|
-
@added_dependencies_to_package_json = true
|
|
476
|
-
return
|
|
477
|
-
end
|
|
478
|
-
|
|
479
|
-
puts "Using direct npm commands as fallback"
|
|
480
|
-
success = system("npm", "install", *react_on_rails_pkg)
|
|
481
|
-
@ran_direct_installs = true if success
|
|
482
|
-
handle_npm_failure("react-on-rails package", react_on_rails_pkg) unless success
|
|
483
|
-
end
|
|
484
|
-
|
|
485
|
-
def add_react_dependencies
|
|
486
|
-
puts "Installing React dependencies..."
|
|
487
|
-
react_deps = %w[
|
|
488
|
-
react
|
|
489
|
-
react-dom
|
|
490
|
-
@babel/preset-react
|
|
491
|
-
prop-types
|
|
492
|
-
babel-plugin-transform-react-remove-prop-types
|
|
493
|
-
babel-plugin-macros
|
|
494
|
-
]
|
|
495
|
-
if add_npm_dependencies(react_deps)
|
|
496
|
-
@added_dependencies_to_package_json = true
|
|
497
|
-
return
|
|
498
|
-
end
|
|
499
|
-
|
|
500
|
-
success = system("npm", "install", *react_deps)
|
|
501
|
-
@ran_direct_installs = true if success
|
|
502
|
-
handle_npm_failure("React dependencies", react_deps) unless success
|
|
503
|
-
end
|
|
504
|
-
|
|
505
|
-
def add_css_dependencies
|
|
506
|
-
puts "Installing CSS handling dependencies..."
|
|
507
|
-
css_deps = %w[
|
|
508
|
-
css-loader
|
|
509
|
-
css-minimizer-webpack-plugin
|
|
510
|
-
mini-css-extract-plugin
|
|
511
|
-
style-loader
|
|
512
|
-
]
|
|
513
|
-
if add_npm_dependencies(css_deps)
|
|
514
|
-
@added_dependencies_to_package_json = true
|
|
515
|
-
return
|
|
516
|
-
end
|
|
517
|
-
|
|
518
|
-
success = system("npm", "install", *css_deps)
|
|
519
|
-
@ran_direct_installs = true if success
|
|
520
|
-
handle_npm_failure("CSS dependencies", css_deps) unless success
|
|
521
|
-
end
|
|
522
|
-
|
|
523
|
-
def add_rspack_dependencies
|
|
524
|
-
puts "Installing Rspack core dependencies..."
|
|
525
|
-
rspack_deps = %w[
|
|
526
|
-
@rspack/core
|
|
527
|
-
rspack-manifest-plugin
|
|
528
|
-
]
|
|
529
|
-
if add_npm_dependencies(rspack_deps)
|
|
530
|
-
@added_dependencies_to_package_json = true
|
|
531
|
-
return
|
|
532
|
-
end
|
|
533
|
-
|
|
534
|
-
success = system("npm", "install", *rspack_deps)
|
|
535
|
-
@ran_direct_installs = true if success
|
|
536
|
-
handle_npm_failure("Rspack dependencies", rspack_deps) unless success
|
|
537
|
-
end
|
|
538
|
-
|
|
539
|
-
def add_dev_dependencies
|
|
540
|
-
puts "Installing development dependencies..."
|
|
541
|
-
dev_deps = if options.rspack?
|
|
542
|
-
%w[
|
|
543
|
-
@rspack/cli
|
|
544
|
-
@rspack/plugin-react-refresh
|
|
545
|
-
react-refresh
|
|
546
|
-
]
|
|
547
|
-
else
|
|
548
|
-
%w[
|
|
549
|
-
@pmmmwh/react-refresh-webpack-plugin
|
|
550
|
-
react-refresh
|
|
551
|
-
]
|
|
552
|
-
end
|
|
553
|
-
if add_npm_dependencies(dev_deps, dev: true)
|
|
554
|
-
@added_dependencies_to_package_json = true
|
|
555
|
-
return
|
|
556
|
-
end
|
|
557
|
-
|
|
558
|
-
success = system("npm", "install", "--save-dev", *dev_deps)
|
|
559
|
-
@ran_direct_installs = true if success
|
|
560
|
-
handle_npm_failure("development dependencies", dev_deps, dev: true) unless success
|
|
561
|
-
end
|
|
562
|
-
|
|
563
|
-
def install_js_dependencies
|
|
564
|
-
# Detect which package manager to use
|
|
565
|
-
success = if File.exist?(File.join(destination_root, "yarn.lock"))
|
|
566
|
-
system("yarn", "install")
|
|
567
|
-
elsif File.exist?(File.join(destination_root, "pnpm-lock.yaml"))
|
|
568
|
-
system("pnpm", "install")
|
|
569
|
-
elsif File.exist?(File.join(destination_root, "package-lock.json")) ||
|
|
570
|
-
File.exist?(File.join(destination_root, "package.json"))
|
|
571
|
-
# Use npm for package-lock.json or as default fallback
|
|
572
|
-
system("npm", "install")
|
|
573
|
-
else
|
|
574
|
-
true # No package manager detected, skip
|
|
575
|
-
end
|
|
576
|
-
|
|
577
|
-
unless success
|
|
578
|
-
GeneratorMessages.add_warning(<<~MSG.strip)
|
|
579
|
-
⚠️ JavaScript dependencies installation failed.
|
|
580
|
-
|
|
581
|
-
This could be due to network issues or missing package manager.
|
|
582
|
-
You can install dependencies manually later by running:
|
|
583
|
-
• npm install (if using npm)
|
|
584
|
-
• yarn install (if using yarn)
|
|
585
|
-
• pnpm install (if using pnpm)
|
|
586
|
-
MSG
|
|
587
|
-
end
|
|
588
|
-
|
|
589
|
-
success
|
|
590
|
-
end
|
|
591
|
-
|
|
592
|
-
def handle_npm_failure(dependency_type, packages, dev: false)
|
|
593
|
-
install_command = dev ? "npm install --save-dev" : "npm install"
|
|
594
|
-
GeneratorMessages.add_warning(<<~MSG.strip)
|
|
595
|
-
⚠️ Failed to install #{dependency_type}.
|
|
596
|
-
|
|
597
|
-
The following packages could not be installed automatically:
|
|
598
|
-
#{packages.map { |pkg| " • #{pkg}" }.join("\n")}
|
|
599
|
-
|
|
600
|
-
This could be due to network issues or missing package manager.
|
|
601
|
-
You can install them manually later by running:
|
|
602
|
-
#{install_command} #{packages.join(' ')}
|
|
603
|
-
MSG
|
|
604
|
-
end
|
|
605
|
-
|
|
606
431
|
# Removed: Shakapacker auto-installation logic (now explicit dependency)
|
|
607
432
|
|
|
608
433
|
# Removed: Shakapacker 8+ is now required as explicit dependency
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "generator_messages"
|
|
4
|
+
|
|
5
|
+
# rubocop:disable Metrics/ModuleLength
|
|
6
|
+
module ReactOnRails
|
|
7
|
+
module Generators
|
|
8
|
+
# Shared module for managing JavaScript dependencies across generators
|
|
9
|
+
# This module provides common functionality for adding and installing
|
|
10
|
+
# JS dependencies to avoid code duplication between generators.
|
|
11
|
+
#
|
|
12
|
+
# Since react_on_rails requires shakapacker, and shakapacker includes
|
|
13
|
+
# package_json as a dependency, the package_json gem is always available.
|
|
14
|
+
#
|
|
15
|
+
# == Required Methods
|
|
16
|
+
# Including classes must include GeneratorHelper module which provides:
|
|
17
|
+
# - add_npm_dependencies(packages, dev: false): Add packages via package_json gem
|
|
18
|
+
# - package_json: Access to PackageJson instance (always available via shakapacker)
|
|
19
|
+
# - destination_root: Generator destination directory
|
|
20
|
+
#
|
|
21
|
+
# == Optional Methods
|
|
22
|
+
# Including classes may define:
|
|
23
|
+
# - options.rspack?: Returns true if --rspack flag is set (for Rspack support)
|
|
24
|
+
# - options.typescript?: Returns true if --typescript flag is set (for TypeScript support)
|
|
25
|
+
#
|
|
26
|
+
# == Installation Behavior
|
|
27
|
+
# The module ALWAYS runs package manager install after adding dependencies.
|
|
28
|
+
# This is safe because package_json gem's install method is idempotent - it only
|
|
29
|
+
# installs what's actually needed from package.json. This prevents edge cases
|
|
30
|
+
# where package.json was modified but dependencies weren't installed.
|
|
31
|
+
#
|
|
32
|
+
# == Error Handling Philosophy
|
|
33
|
+
# All dependency addition methods use a graceful degradation approach:
|
|
34
|
+
# - Methods return false on failure instead of raising exceptions
|
|
35
|
+
# - StandardError is caught at the lowest level (add_package) and higher levels (add_*_dependencies)
|
|
36
|
+
# - Failures trigger user-facing warnings via GeneratorMessages
|
|
37
|
+
# - Warnings provide clear manual installation instructions
|
|
38
|
+
#
|
|
39
|
+
# This ensures the generator ALWAYS completes successfully, even when:
|
|
40
|
+
# - Network connectivity issues prevent package downloads
|
|
41
|
+
# - Package manager (npm/yarn/pnpm) has permission errors
|
|
42
|
+
# - package_json gem encounters unexpected states
|
|
43
|
+
#
|
|
44
|
+
# Users can manually run package installation commands after generator completion.
|
|
45
|
+
# This is preferable to generator crashes that leave Rails apps in incomplete states.
|
|
46
|
+
#
|
|
47
|
+
# == Usage
|
|
48
|
+
# Include this module in generator classes and call setup_js_dependencies
|
|
49
|
+
# to handle all JS dependency installation via package_json gem.
|
|
50
|
+
module JsDependencyManager
|
|
51
|
+
# Core React dependencies required for React on Rails
|
|
52
|
+
# Note: @babel/preset-react and babel plugins are NOT included here because:
|
|
53
|
+
# - Shakapacker handles JavaScript transpiler configuration (babel, swc, or esbuild)
|
|
54
|
+
# - Users configure their preferred transpiler via shakapacker.yml javascript_transpiler setting
|
|
55
|
+
# - SWC is now the default and doesn't need Babel presets
|
|
56
|
+
# - For Babel users, shakapacker will install babel-loader and its dependencies
|
|
57
|
+
REACT_DEPENDENCIES = %w[
|
|
58
|
+
react
|
|
59
|
+
react-dom
|
|
60
|
+
prop-types
|
|
61
|
+
].freeze
|
|
62
|
+
|
|
63
|
+
# CSS processing dependencies for webpack
|
|
64
|
+
CSS_DEPENDENCIES = %w[
|
|
65
|
+
css-loader
|
|
66
|
+
css-minimizer-webpack-plugin
|
|
67
|
+
mini-css-extract-plugin
|
|
68
|
+
style-loader
|
|
69
|
+
].freeze
|
|
70
|
+
|
|
71
|
+
# Development-only dependencies for hot reloading (Webpack)
|
|
72
|
+
DEV_DEPENDENCIES = %w[
|
|
73
|
+
@pmmmwh/react-refresh-webpack-plugin
|
|
74
|
+
react-refresh
|
|
75
|
+
].freeze
|
|
76
|
+
|
|
77
|
+
# Rspack core dependencies (only installed when --rspack flag is used)
|
|
78
|
+
RSPACK_DEPENDENCIES = %w[
|
|
79
|
+
@rspack/core
|
|
80
|
+
rspack-manifest-plugin
|
|
81
|
+
].freeze
|
|
82
|
+
|
|
83
|
+
# Rspack development dependencies for hot reloading
|
|
84
|
+
RSPACK_DEV_DEPENDENCIES = %w[
|
|
85
|
+
@rspack/cli
|
|
86
|
+
@rspack/plugin-react-refresh
|
|
87
|
+
react-refresh
|
|
88
|
+
].freeze
|
|
89
|
+
|
|
90
|
+
# TypeScript dependencies (only installed when --typescript flag is used)
|
|
91
|
+
# Note: @babel/preset-typescript is NOT included because:
|
|
92
|
+
# - SWC is now the default javascript_transpiler (has built-in TypeScript support)
|
|
93
|
+
# - Shakapacker handles the transpiler configuration via shakapacker.yml
|
|
94
|
+
# - If users choose javascript_transpiler: 'babel', they should manually add @babel/preset-typescript
|
|
95
|
+
# and configure it in their babel.config.js
|
|
96
|
+
TYPESCRIPT_DEPENDENCIES = %w[
|
|
97
|
+
typescript
|
|
98
|
+
@types/react
|
|
99
|
+
@types/react-dom
|
|
100
|
+
].freeze
|
|
101
|
+
|
|
102
|
+
private
|
|
103
|
+
|
|
104
|
+
def setup_js_dependencies
|
|
105
|
+
add_js_dependencies
|
|
106
|
+
|
|
107
|
+
# Always run install to ensure all dependencies are properly installed.
|
|
108
|
+
# The package_json gem's install method is idempotent and safe to call
|
|
109
|
+
# even if packages were already added - it will only install what's needed.
|
|
110
|
+
# This ensures edge cases where package.json was modified but install wasn't
|
|
111
|
+
# run are handled correctly.
|
|
112
|
+
install_js_dependencies
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def add_js_dependencies
|
|
116
|
+
add_react_on_rails_package
|
|
117
|
+
add_react_dependencies
|
|
118
|
+
add_css_dependencies
|
|
119
|
+
# Rspack dependencies are only added when --rspack flag is used
|
|
120
|
+
add_rspack_dependencies if respond_to?(:options) && options&.rspack?
|
|
121
|
+
# Dev dependencies vary based on bundler choice
|
|
122
|
+
add_dev_dependencies
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def add_react_on_rails_package
|
|
126
|
+
# Use exact version match between gem and npm package for stable releases
|
|
127
|
+
# For pre-release versions (e.g., 16.1.0-rc.1), use latest to avoid installing
|
|
128
|
+
# a version that may not exist in the npm registry
|
|
129
|
+
major_minor_patch_only = /\A\d+\.\d+\.\d+\z/
|
|
130
|
+
react_on_rails_pkg = if ReactOnRails::VERSION.match?(major_minor_patch_only)
|
|
131
|
+
"react-on-rails@#{ReactOnRails::VERSION}"
|
|
132
|
+
else
|
|
133
|
+
puts "Adding the latest react-on-rails NPM module. " \
|
|
134
|
+
"Double check this is correct in package.json"
|
|
135
|
+
"react-on-rails"
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
puts "Installing React on Rails package..."
|
|
139
|
+
return if add_package(react_on_rails_pkg)
|
|
140
|
+
|
|
141
|
+
GeneratorMessages.add_warning(<<~MSG.strip)
|
|
142
|
+
⚠️ Failed to add react-on-rails package.
|
|
143
|
+
|
|
144
|
+
You can install it manually by running:
|
|
145
|
+
npm install #{react_on_rails_pkg}
|
|
146
|
+
MSG
|
|
147
|
+
rescue StandardError => e
|
|
148
|
+
GeneratorMessages.add_warning(<<~MSG.strip)
|
|
149
|
+
⚠️ Error adding react-on-rails package: #{e.message}
|
|
150
|
+
|
|
151
|
+
You can install it manually by running:
|
|
152
|
+
npm install #{react_on_rails_pkg}
|
|
153
|
+
MSG
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def add_react_dependencies
|
|
157
|
+
puts "Installing React dependencies..."
|
|
158
|
+
return if add_packages(REACT_DEPENDENCIES)
|
|
159
|
+
|
|
160
|
+
GeneratorMessages.add_warning(<<~MSG.strip)
|
|
161
|
+
⚠️ Failed to add React dependencies.
|
|
162
|
+
|
|
163
|
+
You can install them manually by running:
|
|
164
|
+
npm install #{REACT_DEPENDENCIES.join(' ')}
|
|
165
|
+
MSG
|
|
166
|
+
rescue StandardError => e
|
|
167
|
+
GeneratorMessages.add_warning(<<~MSG.strip)
|
|
168
|
+
⚠️ Error adding React dependencies: #{e.message}
|
|
169
|
+
|
|
170
|
+
You can install them manually by running:
|
|
171
|
+
npm install #{REACT_DEPENDENCIES.join(' ')}
|
|
172
|
+
MSG
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def add_css_dependencies
|
|
176
|
+
puts "Installing CSS handling dependencies..."
|
|
177
|
+
return if add_packages(CSS_DEPENDENCIES)
|
|
178
|
+
|
|
179
|
+
GeneratorMessages.add_warning(<<~MSG.strip)
|
|
180
|
+
⚠️ Failed to add CSS dependencies.
|
|
181
|
+
|
|
182
|
+
You can install them manually by running:
|
|
183
|
+
npm install #{CSS_DEPENDENCIES.join(' ')}
|
|
184
|
+
MSG
|
|
185
|
+
rescue StandardError => e
|
|
186
|
+
GeneratorMessages.add_warning(<<~MSG.strip)
|
|
187
|
+
⚠️ Error adding CSS dependencies: #{e.message}
|
|
188
|
+
|
|
189
|
+
You can install them manually by running:
|
|
190
|
+
npm install #{CSS_DEPENDENCIES.join(' ')}
|
|
191
|
+
MSG
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def add_rspack_dependencies
|
|
195
|
+
puts "Installing Rspack core dependencies..."
|
|
196
|
+
return if add_packages(RSPACK_DEPENDENCIES)
|
|
197
|
+
|
|
198
|
+
GeneratorMessages.add_warning(<<~MSG.strip)
|
|
199
|
+
⚠️ Failed to add Rspack dependencies.
|
|
200
|
+
|
|
201
|
+
You can install them manually by running:
|
|
202
|
+
npm install #{RSPACK_DEPENDENCIES.join(' ')}
|
|
203
|
+
MSG
|
|
204
|
+
rescue StandardError => e
|
|
205
|
+
GeneratorMessages.add_warning(<<~MSG.strip)
|
|
206
|
+
⚠️ Error adding Rspack dependencies: #{e.message}
|
|
207
|
+
|
|
208
|
+
You can install them manually by running:
|
|
209
|
+
npm install #{RSPACK_DEPENDENCIES.join(' ')}
|
|
210
|
+
MSG
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
def add_typescript_dependencies
|
|
214
|
+
puts "Installing TypeScript dependencies..."
|
|
215
|
+
return if add_packages(TYPESCRIPT_DEPENDENCIES, dev: true)
|
|
216
|
+
|
|
217
|
+
GeneratorMessages.add_warning(<<~MSG.strip)
|
|
218
|
+
⚠️ Failed to add TypeScript dependencies.
|
|
219
|
+
|
|
220
|
+
You can install them manually by running:
|
|
221
|
+
npm install --save-dev #{TYPESCRIPT_DEPENDENCIES.join(' ')}
|
|
222
|
+
MSG
|
|
223
|
+
rescue StandardError => e
|
|
224
|
+
GeneratorMessages.add_warning(<<~MSG.strip)
|
|
225
|
+
⚠️ Error adding TypeScript dependencies: #{e.message}
|
|
226
|
+
|
|
227
|
+
You can install them manually by running:
|
|
228
|
+
npm install --save-dev #{TYPESCRIPT_DEPENDENCIES.join(' ')}
|
|
229
|
+
MSG
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
def add_dev_dependencies
|
|
233
|
+
puts "Installing development dependencies..."
|
|
234
|
+
|
|
235
|
+
# Use Rspack-specific dev dependencies if --rspack flag is set
|
|
236
|
+
dev_deps = if respond_to?(:options) && options&.rspack?
|
|
237
|
+
RSPACK_DEV_DEPENDENCIES
|
|
238
|
+
else
|
|
239
|
+
DEV_DEPENDENCIES
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
return if add_packages(dev_deps, dev: true)
|
|
243
|
+
|
|
244
|
+
GeneratorMessages.add_warning(<<~MSG.strip)
|
|
245
|
+
⚠️ Failed to add development dependencies.
|
|
246
|
+
|
|
247
|
+
You can install them manually by running:
|
|
248
|
+
npm install --save-dev #{dev_deps.join(' ')}
|
|
249
|
+
MSG
|
|
250
|
+
rescue StandardError => e
|
|
251
|
+
GeneratorMessages.add_warning(<<~MSG.strip)
|
|
252
|
+
⚠️ Error adding development dependencies: #{e.message}
|
|
253
|
+
|
|
254
|
+
You can install them manually by running:
|
|
255
|
+
npm install --save-dev #{dev_deps.join(' ')}
|
|
256
|
+
MSG
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
# Add a single dependency using package_json gem
|
|
260
|
+
#
|
|
261
|
+
# This method is used internally for adding the react-on-rails package
|
|
262
|
+
# with version-specific handling (react-on-rails@VERSION).
|
|
263
|
+
# For batch operations, use add_packages instead.
|
|
264
|
+
#
|
|
265
|
+
# The exact: true flag ensures version pinning aligns with the gem version,
|
|
266
|
+
# preventing version mismatches between the Ruby gem and NPM package.
|
|
267
|
+
#
|
|
268
|
+
# @param package [String] Package specifier (e.g., "react-on-rails@16.0.0")
|
|
269
|
+
# @param dev [Boolean] Whether to add as dev dependency
|
|
270
|
+
# @return [Boolean] true if successful, false otherwise
|
|
271
|
+
def add_package(package, dev: false)
|
|
272
|
+
pj = package_json
|
|
273
|
+
return false unless pj
|
|
274
|
+
|
|
275
|
+
begin
|
|
276
|
+
# Ensure package is in array format for package_json gem
|
|
277
|
+
packages_array = [package]
|
|
278
|
+
if dev
|
|
279
|
+
pj.manager.add(packages_array, type: :dev, exact: true)
|
|
280
|
+
else
|
|
281
|
+
pj.manager.add(packages_array, exact: true)
|
|
282
|
+
end
|
|
283
|
+
true
|
|
284
|
+
rescue StandardError
|
|
285
|
+
# Return false to trigger warning in calling method
|
|
286
|
+
false
|
|
287
|
+
end
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
# Add multiple dependencies at once using package_json gem
|
|
291
|
+
#
|
|
292
|
+
# This method delegates to GeneratorHelper's add_npm_dependencies for
|
|
293
|
+
# better package manager abstraction and batch processing efficiency.
|
|
294
|
+
#
|
|
295
|
+
# @param packages [Array<String>] Package names to add
|
|
296
|
+
# @param dev [Boolean] Whether to add as dev dependencies
|
|
297
|
+
# @return [Boolean] true if successful, false otherwise
|
|
298
|
+
def add_packages(packages, dev: false)
|
|
299
|
+
# Use the add_npm_dependencies helper from GeneratorHelper
|
|
300
|
+
add_npm_dependencies(packages, dev: dev)
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
def install_js_dependencies
|
|
304
|
+
# Use package_json gem's install method (always available via shakapacker)
|
|
305
|
+
# package_json is guaranteed to be available because:
|
|
306
|
+
# 1. react_on_rails gemspec requires shakapacker
|
|
307
|
+
# 2. shakapacker gemspec requires package_json
|
|
308
|
+
# 3. GeneratorHelper provides package_json method
|
|
309
|
+
pj = package_json
|
|
310
|
+
unless pj
|
|
311
|
+
GeneratorMessages.add_warning("package_json not available, skipping dependency installation")
|
|
312
|
+
return false
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
pj.manager.install
|
|
316
|
+
true
|
|
317
|
+
rescue StandardError => e
|
|
318
|
+
GeneratorMessages.add_warning(<<~MSG.strip)
|
|
319
|
+
⚠️ JavaScript dependencies installation failed: #{e.message}
|
|
320
|
+
|
|
321
|
+
This could be due to network issues or package manager problems.
|
|
322
|
+
You can install dependencies manually later by running:
|
|
323
|
+
• npm install (if using npm)
|
|
324
|
+
• yarn install (if using yarn)
|
|
325
|
+
• pnpm install (if using pnpm)
|
|
326
|
+
MSG
|
|
327
|
+
false
|
|
328
|
+
end
|
|
329
|
+
end
|
|
330
|
+
end
|
|
331
|
+
end
|
|
332
|
+
# rubocop:enable Metrics/ModuleLength
|
|
@@ -36,8 +36,15 @@ default: &default
|
|
|
36
36
|
# Reload manifest.json on all requests so we reload latest compiled packs
|
|
37
37
|
cache_manifest: false
|
|
38
38
|
|
|
39
|
-
# Select
|
|
40
|
-
|
|
39
|
+
# Select JavaScript transpiler to use
|
|
40
|
+
# Available options: 'swc' (default, 20x faster), 'babel', 'esbuild', or 'none'
|
|
41
|
+
# Use 'none' when providing a completely custom webpack configuration
|
|
42
|
+
# Note: When using rspack, swc is used automatically regardless of this setting
|
|
43
|
+
javascript_transpiler: "swc"
|
|
44
|
+
|
|
45
|
+
# Select assets bundler to use
|
|
46
|
+
# Available options: 'webpack' (default) or 'rspack'
|
|
47
|
+
assets_bundler: "webpack"
|
|
41
48
|
|
|
42
49
|
# Raises an error if there is a mismatch in the shakapacker gem and npm package being used
|
|
43
50
|
ensure_consistent_versioning: true
|
|
@@ -83,10 +83,7 @@ module ReactOnRails
|
|
|
83
83
|
ReactOnRails::ServerRenderingPool.reset_pool
|
|
84
84
|
end
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
load File.expand_path("../tasks/assets.rake", __dir__)
|
|
89
|
-
load File.expand_path("../tasks/locale.rake", __dir__)
|
|
90
|
-
end
|
|
86
|
+
# Rake tasks are automatically loaded from lib/tasks/*.rake by Rails::Engine
|
|
87
|
+
# No need to explicitly load them here to avoid duplicate loading
|
|
91
88
|
end
|
|
92
89
|
end
|
|
@@ -9,7 +9,7 @@ GIT
|
|
|
9
9
|
PATH
|
|
10
10
|
remote: ..
|
|
11
11
|
specs:
|
|
12
|
-
react_on_rails (16.2.0.beta.
|
|
12
|
+
react_on_rails (16.2.0.beta.10)
|
|
13
13
|
addressable
|
|
14
14
|
connection_pool
|
|
15
15
|
execjs (~> 2.5)
|
|
@@ -20,7 +20,7 @@ PATH
|
|
|
20
20
|
PATH
|
|
21
21
|
remote: .
|
|
22
22
|
specs:
|
|
23
|
-
react_on_rails_pro (16.2.0.beta.
|
|
23
|
+
react_on_rails_pro (16.2.0.beta.10)
|
|
24
24
|
addressable
|
|
25
25
|
async (>= 2.6)
|
|
26
26
|
connection_pool
|
|
@@ -28,7 +28,7 @@ PATH
|
|
|
28
28
|
httpx (~> 1.5)
|
|
29
29
|
jwt (~> 2.7)
|
|
30
30
|
rainbow
|
|
31
|
-
react_on_rails (= 16.2.0.beta.
|
|
31
|
+
react_on_rails (= 16.2.0.beta.10)
|
|
32
32
|
|
|
33
33
|
GEM
|
|
34
34
|
remote: https://rubygems.org/
|
|
@@ -9,7 +9,7 @@ GIT
|
|
|
9
9
|
PATH
|
|
10
10
|
remote: ../../..
|
|
11
11
|
specs:
|
|
12
|
-
react_on_rails (16.2.0.beta.
|
|
12
|
+
react_on_rails (16.2.0.beta.10)
|
|
13
13
|
addressable
|
|
14
14
|
connection_pool
|
|
15
15
|
execjs (~> 2.5)
|
|
@@ -20,7 +20,7 @@ PATH
|
|
|
20
20
|
PATH
|
|
21
21
|
remote: ../..
|
|
22
22
|
specs:
|
|
23
|
-
react_on_rails_pro (16.2.0.beta.
|
|
23
|
+
react_on_rails_pro (16.2.0.beta.10)
|
|
24
24
|
addressable
|
|
25
25
|
async (>= 2.6)
|
|
26
26
|
connection_pool
|
|
@@ -28,7 +28,7 @@ PATH
|
|
|
28
28
|
httpx (~> 1.5)
|
|
29
29
|
jwt (~> 2.7)
|
|
30
30
|
rainbow
|
|
31
|
-
react_on_rails (= 16.2.0.beta.
|
|
31
|
+
react_on_rails (= 16.2.0.beta.10)
|
|
32
32
|
|
|
33
33
|
GEM
|
|
34
34
|
remote: https://rubygems.org/
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
# Shakapacker precompile hook for React on Rails Pro test dummy app
|
|
5
|
+
#
|
|
6
|
+
# This script loads the shared test helper implementation.
|
|
7
|
+
# For production apps, use the generator template which includes a standalone implementation.
|
|
8
|
+
|
|
9
|
+
# Find the gem root directory (four levels up from react_on_rails_pro/spec/dummy/bin)
|
|
10
|
+
gem_root = File.expand_path("../../../..", __dir__)
|
|
11
|
+
shared_hook = File.join(gem_root, "spec", "support", "shakapacker_precompile_hook_shared.rb")
|
|
12
|
+
|
|
13
|
+
unless File.exist?(shared_hook)
|
|
14
|
+
warn "❌ Error: Shared precompile hook not found at #{shared_hook}"
|
|
15
|
+
exit 1
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Load and execute the shared hook
|
|
19
|
+
load shared_hook
|
|
@@ -19,6 +19,11 @@ default: &default
|
|
|
19
19
|
# Reload manifest.json on all requests so we reload latest compiled packs
|
|
20
20
|
cache_manifest: false
|
|
21
21
|
|
|
22
|
+
# Hook to run before webpack compilation (e.g., for generating dynamic entry points)
|
|
23
|
+
# SECURITY: Only reference trusted scripts within your project. Ensure the hook path
|
|
24
|
+
# points to a file within the project root that you control.
|
|
25
|
+
precompile_hook: 'bin/shakapacker-precompile-hook'
|
|
26
|
+
|
|
22
27
|
# Extract and emit a css file
|
|
23
28
|
extract_css: true
|
|
24
29
|
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ReactOnRails
|
|
4
|
+
module Generators
|
|
5
|
+
# Type signatures for JsDependencyManager module
|
|
6
|
+
#
|
|
7
|
+
# This module provides common functionality for managing JavaScript dependencies
|
|
8
|
+
# in Rails generators using the package_json gem (available via shakapacker).
|
|
9
|
+
module JsDependencyManager
|
|
10
|
+
# Core React dependencies required for React on Rails
|
|
11
|
+
REACT_DEPENDENCIES: Array[String]
|
|
12
|
+
|
|
13
|
+
# CSS processing dependencies for webpack
|
|
14
|
+
CSS_DEPENDENCIES: Array[String]
|
|
15
|
+
|
|
16
|
+
# Development-only dependencies for hot reloading (Webpack)
|
|
17
|
+
DEV_DEPENDENCIES: Array[String]
|
|
18
|
+
|
|
19
|
+
# Rspack core dependencies (only installed when --rspack flag is used)
|
|
20
|
+
RSPACK_DEPENDENCIES: Array[String]
|
|
21
|
+
|
|
22
|
+
# Rspack development dependencies for hot reloading
|
|
23
|
+
RSPACK_DEV_DEPENDENCIES: Array[String]
|
|
24
|
+
|
|
25
|
+
# TypeScript dependencies (only installed when --typescript flag is used)
|
|
26
|
+
TYPESCRIPT_DEPENDENCIES: Array[String]
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
# Sets up JavaScript dependencies by adding and installing packages
|
|
31
|
+
#
|
|
32
|
+
# This method orchestrates the entire dependency setup process:
|
|
33
|
+
# 1. Adds all required packages to package.json
|
|
34
|
+
# 2. Runs package manager install
|
|
35
|
+
#
|
|
36
|
+
# @return [void]
|
|
37
|
+
def setup_js_dependencies: () -> void
|
|
38
|
+
|
|
39
|
+
# Adds all JavaScript dependencies to package.json
|
|
40
|
+
#
|
|
41
|
+
# This method calls individual add_*_dependencies methods in sequence.
|
|
42
|
+
# All errors are handled gracefully with warnings rather than exceptions.
|
|
43
|
+
#
|
|
44
|
+
# @return [void]
|
|
45
|
+
def add_js_dependencies: () -> void
|
|
46
|
+
|
|
47
|
+
# Adds the react-on-rails package to package.json
|
|
48
|
+
#
|
|
49
|
+
# Uses version matching for stable releases, or latest for pre-releases.
|
|
50
|
+
# Adds error message to GeneratorMessages if package addition fails.
|
|
51
|
+
#
|
|
52
|
+
# @return [void]
|
|
53
|
+
def add_react_on_rails_package: () -> void
|
|
54
|
+
|
|
55
|
+
# Adds React dependencies to package.json
|
|
56
|
+
#
|
|
57
|
+
# Adds error message to GeneratorMessages if package addition fails.
|
|
58
|
+
#
|
|
59
|
+
# @return [void]
|
|
60
|
+
def add_react_dependencies: () -> void
|
|
61
|
+
|
|
62
|
+
# Adds CSS processing dependencies to package.json
|
|
63
|
+
#
|
|
64
|
+
# Adds error message to GeneratorMessages if package addition fails.
|
|
65
|
+
#
|
|
66
|
+
# @return [void]
|
|
67
|
+
def add_css_dependencies: () -> void
|
|
68
|
+
|
|
69
|
+
# Adds Rspack dependencies to package.json
|
|
70
|
+
#
|
|
71
|
+
# Only called when --rspack flag is set.
|
|
72
|
+
# Adds error message to GeneratorMessages if package addition fails.
|
|
73
|
+
#
|
|
74
|
+
# @return [void]
|
|
75
|
+
def add_rspack_dependencies: () -> void
|
|
76
|
+
|
|
77
|
+
# Adds TypeScript dependencies to package.json as dev dependencies
|
|
78
|
+
#
|
|
79
|
+
# Only called when --typescript flag is set.
|
|
80
|
+
# Adds error message to GeneratorMessages if package addition fails.
|
|
81
|
+
#
|
|
82
|
+
# @return [void]
|
|
83
|
+
def add_typescript_dependencies: () -> void
|
|
84
|
+
|
|
85
|
+
# Adds development dependencies to package.json
|
|
86
|
+
#
|
|
87
|
+
# Chooses between Webpack or Rspack dev dependencies based on --rspack flag.
|
|
88
|
+
# Adds error message to GeneratorMessages if package addition fails.
|
|
89
|
+
#
|
|
90
|
+
# @return [void]
|
|
91
|
+
def add_dev_dependencies: () -> void
|
|
92
|
+
|
|
93
|
+
# Adds a single package using package_json gem
|
|
94
|
+
#
|
|
95
|
+
# This method is used internally for adding the react-on-rails package
|
|
96
|
+
# with version-specific handling (react-on-rails@VERSION).
|
|
97
|
+
# For batch operations, use add_packages instead.
|
|
98
|
+
#
|
|
99
|
+
# @param package [String] Package specifier (e.g., "react-on-rails@16.0.0")
|
|
100
|
+
# @param dev [bool] Whether to add as dev dependency
|
|
101
|
+
# @return [bool] true if successful, false otherwise
|
|
102
|
+
def add_package: (String package, ?dev: bool) -> bool
|
|
103
|
+
|
|
104
|
+
# Adds multiple packages at once using package_json gem
|
|
105
|
+
#
|
|
106
|
+
# Delegates to GeneratorHelper's add_npm_dependencies for better
|
|
107
|
+
# package manager abstraction and batch processing efficiency.
|
|
108
|
+
#
|
|
109
|
+
# @param packages [Array<String>] Package names to add
|
|
110
|
+
# @param dev [bool] Whether to add as dev dependencies
|
|
111
|
+
# @return [bool] true if successful, false otherwise
|
|
112
|
+
def add_packages: (Array[String] packages, ?dev: bool) -> bool
|
|
113
|
+
|
|
114
|
+
# Installs JavaScript dependencies using package_json gem
|
|
115
|
+
#
|
|
116
|
+
# Always available via shakapacker dependency chain.
|
|
117
|
+
# Adds warning to GeneratorMessages if installation fails.
|
|
118
|
+
#
|
|
119
|
+
# @return [bool] true if successful, false otherwise
|
|
120
|
+
def install_js_dependencies: () -> bool
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
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: 16.2.0.beta.
|
|
4
|
+
version: 16.2.0.beta.10
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Justin Gordon
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-11-
|
|
11
|
+
date: 2025-11-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: addressable
|
|
@@ -167,6 +167,7 @@ files:
|
|
|
167
167
|
- lib/generators/react_on_rails/generator_helper.rb
|
|
168
168
|
- lib/generators/react_on_rails/generator_messages.rb
|
|
169
169
|
- lib/generators/react_on_rails/install_generator.rb
|
|
170
|
+
- lib/generators/react_on_rails/js_dependency_manager.rb
|
|
170
171
|
- lib/generators/react_on_rails/react_no_redux_generator.rb
|
|
171
172
|
- lib/generators/react_on_rails/react_with_redux_generator.rb
|
|
172
173
|
- lib/generators/react_on_rails/templates/.eslintrc
|
|
@@ -606,6 +607,7 @@ files:
|
|
|
606
607
|
- react_on_rails_pro/spec/dummy/bin/setup
|
|
607
608
|
- react_on_rails_pro/spec/dummy/bin/shakapacker
|
|
608
609
|
- react_on_rails_pro/spec/dummy/bin/shakapacker-dev-server
|
|
610
|
+
- react_on_rails_pro/spec/dummy/bin/shakapacker-precompile-hook
|
|
609
611
|
- react_on_rails_pro/spec/dummy/bin/spring
|
|
610
612
|
- react_on_rails_pro/spec/dummy/bin/sprockets
|
|
611
613
|
- react_on_rails_pro/spec/dummy/bin/term_display
|
|
@@ -973,6 +975,7 @@ files:
|
|
|
973
975
|
- sig/react_on_rails/configuration.rbs
|
|
974
976
|
- sig/react_on_rails/controller.rbs
|
|
975
977
|
- sig/react_on_rails/error.rbs
|
|
978
|
+
- sig/react_on_rails/generators/js_dependency_manager.rbs
|
|
976
979
|
- sig/react_on_rails/git_utils.rbs
|
|
977
980
|
- sig/react_on_rails/helper.rbs
|
|
978
981
|
- sig/react_on_rails/json_parse_error.rbs
|