react_on_rails 16.0.1.rc.2 → 16.0.1.rc.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 447fa3382ac19a61525d8e17f67534ed0d6243cb8352512bae81b002165aef9b
4
- data.tar.gz: 26b1a80ba765de1cf379e7fddc7adda75de353c39fea0a8c8965d314099d1b91
3
+ metadata.gz: 1866bb608bf6b62df70e1ebb9e708596b59f620d08311ea8116e534bdb1180be
4
+ data.tar.gz: bc7ad5c8cca569395d3da1db1e3ee3d9a0f3a986ac8777eadae28b06d8514e6a
5
5
  SHA512:
6
- metadata.gz: ee112925a900c99b9b060e4eccf6fa18b5e249d2993b66d1a5b9ead17e989693d3dd512049a2276663616f9edb792b940f23334a600f56a4888deab47ea57ca2
7
- data.tar.gz: dc7ba94789cfda1fcfce115d6db988b523810ed146d1db71d72d5942e920c7abf798317f8644ddc2e18dead08c4eacce62fb4b1a8c7ea751caaf63c85f40d35c
6
+ metadata.gz: 5d5651560869dc69bb9a7ce4f1d5666b7cc10c3fa84827087aa9c1c2c7afb20100eee674ca2b906ca3fec49ca4558af111c38558104976ad49290e07a0751b9a
7
+ data.tar.gz: 1cabd8aea0ef8545861f325494c6c051550a463ec73d9e206dfb8548060db0c8fe78bde5359e1ce921d787c9d99ad3961858e9a5ab81d7ae9e490b150ed32cd2
data/CHANGELOG.md CHANGED
@@ -23,9 +23,59 @@ 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
+ #### Breaking Changes
27
+
28
+ - **Removed `generated_assets_dirs` configuration**: The legacy `config.generated_assets_dirs` option is no longer supported and will raise an error if used. Since Shakapacker is now required, asset paths are automatically determined from `shakapacker.yml` configuration. Remove any `config.generated_assets_dirs` from your `config/initializers/react_on_rails.rb` file. Use `public_output_path` in `config/shakapacker.yml` to customize asset output location instead. [PR 1798](https://github.com/shakacode/react_on_rails/pull/1798)
29
+
30
+ #### New Features
31
+
32
+ - **Server Bundle Security**: Added new configuration options for enhanced server bundle security and organization:
33
+
34
+ - `server_bundle_output_path`: Configurable directory (relative to the Rails root) for server bundle output (default: "ssr-generated"). If set to `nil`, the server bundle will be loaded from the same public directory as client bundles.
35
+ - `enforce_private_server_bundles`: When enabled, ensures server bundles are only loaded from private directories outside the public folder (default: false for backward compatibility)
36
+
37
+ - **Improved Bundle Path Resolution**: Bundle path resolution for server bundles now works as follows:
38
+ - If `server_bundle_output_path` is set, the server bundle is loaded from that directory.
39
+ - If `server_bundle_output_path` is not set, the server bundle falls back to the client bundle directory (typically the public output path).
40
+ - If `enforce_private_server_bundles` is enabled:
41
+ - The server bundle will only be loaded from the private directory specified by `server_bundle_output_path`.
42
+ - If the bundle is not found there, it will _not_ fall back to the public directory.
43
+ - If `enforce_private_server_bundles` is not enabled and the bundle is not found in the private directory, it will fall back to the public directory.
44
+ - This logic ensures that, when strict enforcement is enabled, server bundles are never loaded from public directories, improving security and clarity of bundle resolution.
45
+
46
+ #### API Improvements
47
+
48
+ - **Method Naming Clarification**: Added `public_bundles_full_path` method to clarify bundle path handling:
49
+ - `public_bundles_full_path`: New method specifically for webpack bundles in public directories
50
+ - `generated_assets_full_path`: Now deprecated (backwards-compatible alias)
51
+ - This eliminates confusion between webpack bundles and general Rails public assets
52
+
53
+ #### Security Enhancements
54
+
55
+ - **Private Server Bundle Enforcement**: When `enforce_private_server_bundles` is enabled, server bundles bypass public directory fallbacks and are only loaded from designated private locations
56
+ - **Path Validation**: Added validation to ensure `server_bundle_output_path` points to private directories when enforcement is enabled
57
+
58
+ #### Bug Fixes
59
+
60
+ - **Non-Packer Environment Compatibility**: Fixed potential NoMethodError when using bundle path resolution in environments without Shakapacker
61
+ - **Shakapacker version requirements**: Fixed inconsistent version requirements between basic pack generation (6.5.1+) and advanced auto-bundling features (7.0.0+). Added backward compatibility for users on Shakapacker 6.5.1-6.9.x while providing clear upgrade guidance for advanced features. Added new constants `MINIMUM_SHAKAPACKER_VERSION_FOR_AUTO_BUNDLING` and improved version checking performance with caching. [PR 1798](https://github.com/shakacode/react_on_rails/pull/1798)
62
+
63
+ ### [16.0.1-rc.2] - 2025-09-20
64
+
65
+ #### Bug Fixes
66
+
67
+ - **Packs generator**: Fixed error when `server_bundle_js_file` configuration is empty (default). Added safety check to prevent attempting operations on invalid file paths when server-side rendering is not configured. [PR 1802](https://github.com/shakacode/react_on_rails/pull/1802)
68
+
69
+ ### [16.0.1-rc.2] - 2025-09-20
70
+
26
71
  #### Bug Fixes
27
72
 
28
73
  - **Doctor rake task**: Fixed LoadError in `rake react_on_rails:doctor` when using packaged gem. The task was trying to require excluded `rakelib/task_helpers` file. [PR 1795](https://github.com/shakacode/react_on_rails/pull/1795)
74
+ - **Shakapacker version requirements**: Fixed inconsistent version requirements between basic pack generation (6.5.1+) and advanced auto-registration features (7.0.0+). Added backward compatibility for users on Shakapacker 6.5.1-6.9.x while providing clear upgrade guidance for advanced features. Added new constants `MINIMUM_SHAKAPACKER_VERSION_FOR_AUTO_REGISTRATION` and improved version checking performance with caching. [PR 1798](https://github.com/shakacode/react_on_rails/pull/1798)
75
+
76
+ #### Code Cleanup
77
+
78
+ - **PackerUtils abstraction removal**: Removed unnecessary `PackerUtils.packer` abstraction method and replaced all calls with direct `::Shakapacker` usage. This simplifies the codebase by eliminating an abstraction layer that was originally created to support multiple webpack tools but is no longer needed since we only support Shakapacker. All tests updated accordingly. [PR 1798](https://github.com/shakacode/react_on_rails/pull/1798) by [claude-code](https://claude.ai/code)
29
79
 
30
80
  ### [16.0.1-rc.0] - 2025-09-19
31
81
 
@@ -1652,7 +1702,8 @@ such as:
1652
1702
 
1653
1703
  - Fix several generator-related issues.
1654
1704
 
1655
- [Unreleased]: https://github.com/shakacode/react_on_rails/compare/16.0.1-rc.0...master
1705
+ [Unreleased]: https://github.com/shakacode/react_on_rails/compare/16.0.1-rc.2...master
1706
+ [16.0.1-rc.2]: https://github.com/shakacode/react_on_rails/compare/16.0.1-rc.0...16.0.1-rc.2
1656
1707
  [16.0.1-rc.0]: https://github.com/shakacode/react_on_rails/compare/16.0.0...16.0.1-rc.0
1657
1708
  [16.0.0]: https://github.com/shakacode/react_on_rails/compare/14.2.0...16.0.0
1658
1709
  [14.2.0]: https://github.com/shakacode/react_on_rails/compare/14.1.1...14.2.0
data/CLAUDE.md CHANGED
@@ -9,7 +9,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
9
9
  1. **ALWAYS run `bundle exec rubocop` and fix ALL violations**
10
10
  2. **ALWAYS ensure files end with a newline character**
11
11
  3. **NEVER push without running full lint check first**
12
- 4. **ALWAYS let Prettier handle ALL formatting - never manually format**
12
+ 4. **ALWAYS let Prettier and RuboCop handle ALL formatting - never manually format**
13
13
 
14
14
  These requirements are non-negotiable. CI will fail if not followed.
15
15
 
@@ -39,10 +39,11 @@ Git hooks will automatically run linting on **all changed files (staged + unstag
39
39
  - **Build**: `yarn run build` (compiles TypeScript to JavaScript in node_package/lib)
40
40
  - **Type checking**: `yarn run type-check`
41
41
  - **⚠️ MANDATORY BEFORE GIT PUSH**: `bundle exec rubocop` and fix ALL violations + ensure trailing newlines
42
+ - Never run `npm` commands, only equivalent Yarn Classic ones
42
43
 
43
44
  ## ⚠️ FORMATTING RULES
44
45
 
45
- **Prettier is the SOLE authority for formatting. NEVER manually format code.**
46
+ **Prettier is the SOLE authority for formatting non-Ruby files, and RuboCop for formatting Ruby files. NEVER manually format code.**
46
47
 
47
48
  ### Standard Workflow
48
49
  1. Make code changes
@@ -120,10 +121,10 @@ This project maintains both a Ruby gem and an NPM package:
120
121
  ## Important Notes
121
122
 
122
123
  - Use `yalc` for local development when testing with external apps
123
- - The project supports both Webpacker and Shakapacker
124
124
  - Server-side rendering uses isolated Node.js processes
125
125
  - React Server Components support available in Pro version
126
126
  - Generated examples are in `gen-examples/` (ignored by git)
127
+ - Only use `yarn` as the JS package manager, never `npm`
127
128
 
128
129
  ## IDE Configuration
129
130
 
data/CODING_AGENTS.md CHANGED
@@ -30,6 +30,7 @@ cd spec/dummy && foreman start # Start dummy app with webpack
30
30
  - [ ] No trailing whitespace
31
31
  - [ ] Line length ≤120 characters
32
32
  - [ ] Security violations properly scoped with disable comments
33
+ - [ ] No `package-lock.json` or other non-Yarn lock files (except `Gemfile.lock`)
33
34
 
34
35
  ## Development Patterns for AI Contributors
35
36
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- react_on_rails (16.0.1.rc.0)
4
+ react_on_rails (16.0.1.rc.4)
5
5
  addressable
6
6
  connection_pool
7
7
  execjs (~> 2.5)
data/NEWS.md CHANGED
@@ -21,7 +21,7 @@ _A history of the news. A few bullets at the top will also show on the [README.m
21
21
  - 2017-04-09: 8.0.0 beta work to include webpacker_lite gem has begun. See [#786](https://github.com/shakacode/react_on_rails/issues/786).
22
22
  - 2017-04-03: 6.9.3 Released! Props rendered in JSON script tag. Page size is smaller now due to less escaping!
23
23
  - 2017-03-06: Updated to Webpack v2!
24
- - 2017-03-02: Demo of internationalization (i18n) is live at [reactrails.com](https://www.reactrails.com/). Docs [here](docs/guides/i18n.md).
24
+ - 2017-03-02: Demo of internationalization (i18n) is live at [reactrails.com](https://reactrails.com/). Docs [here](docs/guides/i18n.md).
25
25
  - 2017-02-28: See [discussions here on Webpacker](https://github.com/rails/webpacker/issues/139) regarding how Webpacker will allow React on Rails to avoid using the asset pipeline in the near future.
26
26
  - 2017-02-28: Upgrade to Webpack v2 or use the `--bail` option in your Webpack script for test and production builds. See the discussion on [PR #730](https://github.com/shakacode/react_on_rails/pull/730).
27
27
  - 2016-11-03: Spoke at [LA Ruby: "React on Rails: Why, What, and How?"](http://www.meetup.com/laruby/events/234825187/). [Video and pictures in this article](https://blog.shakacode.com/my-react-on-rails-talk-at-the-la-ruby-rails-meetup-november-10-2016-eaaa83aff800#.ej6h4eglp).
data/README.md CHANGED
@@ -140,16 +140,21 @@ _Requires creating a free account._
140
140
  - Node.js >= 20 (CI tested: 20 - 22)
141
141
  - A JavaScript package manager (npm, yarn, pnpm, or bun)
142
142
 
143
- # Support
143
+ # 🆘 Get Help & Support
144
144
 
145
- - [Click to join **React + Rails Slack**](https://join.slack.com/t/reactrails/shared_invite/zt-38oicm9d0-OO0V~bdg4aYNuZuUbRFSXg).
145
+ **Need immediate help?** Here are your options, ordered by response time:
146
146
 
147
- - [**Subscribe**](https://app.mailerlite.com/webforms/landing/l1d9x5) for announcements of new releases of React on Rails and of our latest [blog articles](https://blog.shakacode.com) and tutorials.
148
- - [Discussions](https://github.com/shakacode/react_on_rails/discussions): Post your questions regarding React on Rails
149
- - **[forum.shakacode.com](https://forum.shakacode.com)**: Other discussions
150
- - **[@railsonmaui on Twitter](https://twitter.com/railsonmaui)**
151
- - _See [NEWS.md](https://github.com/shakacode/react_on_rails/tree/master/NEWS.md) for more notes over time._
152
- - See [Projects](https://github.com/shakacode/react_on_rails/tree/master/PROJECTS.md) using and [KUDOS](https://github.com/shakacode/react_on_rails/tree/master/KUDOS.md) for React on Rails. Please submit yours! Please edit either page or [email us](mailto:contact@shakacode.com) and we'll add your info. We also **love stars** as it helps us attract new users and contributors.
147
+ - 🚀 **Professional Support**: [react_on_rails@shakacode.com](mailto:react_on_rails@shakacode.com) - Fastest resolution for bugs, upgrades, and consulting
148
+ - 💬 **React + Rails Slack**: [Join our community](https://invite.reactrails.com) - Chat with other developers
149
+ - 🆓 **GitHub Issues**: [Report bugs](https://github.com/shakacode/react_on_rails/issues) - Community support
150
+ - 📖 **Discussions**: [Ask questions](https://github.com/shakacode/react_on_rails/discussions) - General help
151
+
152
+ **Additional Resources:**
153
+
154
+ - [**Subscribe**](https://app.mailerlite.com/webforms/landing/l1d9x5) for announcements of new releases and tutorials
155
+ - **[forum.shakacode.com](https://forum.shakacode.com)** - Development discussions
156
+ - **[@railsonmaui on Twitter](https://twitter.com/railsonmaui)** - Updates and tips
157
+ - [Projects using React on Rails](https://github.com/shakacode/react_on_rails/tree/master/PROJECTS.md) - Submit yours!
153
158
 
154
159
  ## Contributing
155
160
 
@@ -163,6 +168,8 @@ ShakaCode is **[hiring passionate software engineers](http://www.shakacode.com/c
163
168
 
164
169
  The gem is available as open source under the terms of the [MIT License](https://github.com/shakacode/react_on_rails/tree/master/LICENSE.md).
165
170
 
171
+ Note, some features are available only with a React on Rails Pro subscription. See [React on Rails Pro](https://www.shakacode.com/react-on-rails-pro/) for more information.
172
+
166
173
  # Supporters
167
174
 
168
175
  The following companies support our open-source projects, and ShakaCode uses their products!
@@ -24,7 +24,7 @@ module ReactOnRails
24
24
  end
25
25
 
26
26
  def create_react_directories
27
- # Create auto-registration directory structure for non-Redux components only
27
+ # Create auto-bundling directory structure for non-Redux components only
28
28
  # Redux components handle their own directory structure
29
29
  return if options.redux?
30
30
 
@@ -41,7 +41,7 @@ module ReactOnRails
41
41
  base_templates = %w[config/initializers/react_on_rails.rb]
42
42
  base_files.each { |file| copy_file("#{base_path}#{file}", file) }
43
43
  base_templates.each do |file|
44
- template("#{base_path}/#{file}.tt", file, { packer_type: ReactOnRails::PackerUtils.packer_type })
44
+ template("#{base_path}/#{file}.tt", file)
45
45
  end
46
46
  end
47
47
 
@@ -95,55 +95,22 @@ module ReactOnRails
95
95
  run "bundle"
96
96
  end
97
97
 
98
- def add_js_dependencies
99
- add_react_on_rails_package
100
- add_react_dependencies
101
- add_css_dependencies
102
- add_dev_dependencies
103
- end
104
-
105
- def install_js_dependencies
106
- # Detect which package manager to use
107
- success = if File.exist?(File.join(destination_root, "yarn.lock"))
108
- system("yarn", "install")
109
- elsif File.exist?(File.join(destination_root, "pnpm-lock.yaml"))
110
- system("pnpm", "install")
111
- elsif File.exist?(File.join(destination_root, "package-lock.json")) ||
112
- File.exist?(File.join(destination_root, "package.json"))
113
- # Use npm for package-lock.json or as default fallback
114
- system("npm", "install")
115
- else
116
- true # No package manager detected, skip
117
- end
118
-
119
- unless success
120
- GeneratorMessages.add_warning(<<~MSG.strip)
121
- ⚠️ JavaScript dependencies installation failed.
122
-
123
- This could be due to network issues or missing package manager.
124
- You can install dependencies manually later by running:
125
- • npm install (if using npm)
126
- • yarn install (if using yarn)
127
- • pnpm install (if using pnpm)
128
- MSG
129
- end
130
-
131
- success
132
- end
133
-
134
98
  def update_gitignore_for_auto_registration
135
99
  gitignore_path = File.join(destination_root, ".gitignore")
136
100
  return unless File.exist?(gitignore_path)
137
101
 
138
102
  gitignore_content = File.read(gitignore_path)
139
- return if gitignore_content.include?("**/generated/**")
140
103
 
141
- append_to_file ".gitignore" do
142
- <<~GITIGNORE
104
+ additions = []
105
+ additions << "**/generated/**" unless gitignore_content.include?("**/generated/**")
106
+ additions << "ssr-generated" unless gitignore_content.include?("ssr-generated")
107
+
108
+ return if additions.empty?
143
109
 
144
- # Generated React on Rails packs
145
- **/generated/**
146
- GITIGNORE
110
+ append_to_file ".gitignore" do
111
+ lines = ["\n# Generated React on Rails packs"]
112
+ lines.concat(additions)
113
+ "#{lines.join("\n")}\n"
147
114
  end
148
115
  end
149
116
 
@@ -157,6 +124,28 @@ module ReactOnRails
157
124
  end
158
125
  end
159
126
 
127
+ CONFIGURE_RSPEC_TO_COMPILE_ASSETS = <<-STR.strip_heredoc
128
+ RSpec.configure do |config|
129
+ # Ensure that if we are running js tests, we are using latest webpack assets
130
+ # This will use the defaults of :js and :server_rendering meta tags
131
+ ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
132
+ end
133
+ STR
134
+
135
+ private
136
+
137
+ def setup_js_dependencies
138
+ add_js_dependencies
139
+ install_js_dependencies
140
+ end
141
+
142
+ def add_js_dependencies
143
+ add_react_on_rails_package
144
+ add_react_dependencies
145
+ add_css_dependencies
146
+ add_dev_dependencies
147
+ end
148
+
160
149
  def add_react_on_rails_package
161
150
  major_minor_patch_only = /\A\d+\.\d+\.\d+\z/
162
151
 
@@ -219,15 +208,34 @@ module ReactOnRails
219
208
  handle_npm_failure("development dependencies", dev_deps, dev: true) unless success
220
209
  end
221
210
 
222
- CONFIGURE_RSPEC_TO_COMPILE_ASSETS = <<-STR.strip_heredoc
223
- RSpec.configure do |config|
224
- # Ensure that if we are running js tests, we are using latest webpack assets
225
- # This will use the defaults of :js and :server_rendering meta tags
226
- ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
211
+ def install_js_dependencies
212
+ # Detect which package manager to use
213
+ success = if File.exist?(File.join(destination_root, "yarn.lock"))
214
+ system("yarn", "install")
215
+ elsif File.exist?(File.join(destination_root, "pnpm-lock.yaml"))
216
+ system("pnpm", "install")
217
+ elsif File.exist?(File.join(destination_root, "package-lock.json")) ||
218
+ File.exist?(File.join(destination_root, "package.json"))
219
+ # Use npm for package-lock.json or as default fallback
220
+ system("npm", "install")
221
+ else
222
+ true # No package manager detected, skip
223
+ end
224
+
225
+ unless success
226
+ GeneratorMessages.add_warning(<<~MSG.strip)
227
+ ⚠️ JavaScript dependencies installation failed.
228
+
229
+ This could be due to network issues or missing package manager.
230
+ You can install dependencies manually later by running:
231
+ • npm install (if using npm)
232
+ • yarn install (if using yarn)
233
+ • pnpm install (if using pnpm)
234
+ MSG
227
235
  end
228
- STR
229
236
 
230
- private
237
+ success
238
+ end
231
239
 
232
240
  def handle_npm_failure(dependency_type, packages, dev: false)
233
241
  install_command = dev ? "npm install --save-dev" : "npm install"
@@ -40,7 +40,9 @@ module ReactOnRails
40
40
  if installation_prerequisites_met? || options.ignore_warnings?
41
41
  invoke_generators
42
42
  add_bin_scripts
43
- add_post_install_message
43
+ # Only add the post install message if not using Redux
44
+ # Redux generator handles its own messages
45
+ add_post_install_message unless options.redux?
44
46
  else
45
47
  error = <<~MSG.strip
46
48
  🚫 React on Rails generator prerequisites not met!
@@ -77,6 +79,14 @@ module ReactOnRails
77
79
  else
78
80
  invoke "react_on_rails:react_no_redux", [], { typescript: options.typescript? }
79
81
  end
82
+ setup_react_dependencies
83
+ end
84
+
85
+ def setup_react_dependencies
86
+ @added_dependencies_to_package_json ||= false
87
+ @ran_direct_installs ||= false
88
+ add_js_dependencies
89
+ install_js_dependencies if @added_dependencies_to_package_json && !@ran_direct_installs
80
90
  end
81
91
 
82
92
  # NOTE: other requirements for existing files such as .gitignore or application.
@@ -410,6 +420,134 @@ module ReactOnRails
410
420
  puts Rainbow("✅ Created tsconfig.json").green
411
421
  end
412
422
 
423
+ def add_js_dependencies
424
+ add_react_on_rails_package
425
+ add_react_dependencies
426
+ add_css_dependencies
427
+ add_dev_dependencies
428
+ end
429
+
430
+ def add_react_on_rails_package
431
+ major_minor_patch_only = /\A\d+\.\d+\.\d+\z/
432
+
433
+ # Try to use package_json gem first, fall back to direct npm commands
434
+ react_on_rails_pkg = if ReactOnRails::VERSION.match?(major_minor_patch_only)
435
+ ["react-on-rails@#{ReactOnRails::VERSION}"]
436
+ else
437
+ puts "Adding the latest react-on-rails NPM module. " \
438
+ "Double check this is correct in package.json"
439
+ ["react-on-rails"]
440
+ end
441
+
442
+ puts "Installing React on Rails package..."
443
+ if add_npm_dependencies(react_on_rails_pkg)
444
+ @added_dependencies_to_package_json = true
445
+ return
446
+ end
447
+
448
+ puts "Using direct npm commands as fallback"
449
+ success = system("npm", "install", *react_on_rails_pkg)
450
+ @ran_direct_installs = true if success
451
+ handle_npm_failure("react-on-rails package", react_on_rails_pkg) unless success
452
+ end
453
+
454
+ def add_react_dependencies
455
+ puts "Installing React dependencies..."
456
+ react_deps = %w[
457
+ react
458
+ react-dom
459
+ @babel/preset-react
460
+ prop-types
461
+ babel-plugin-transform-react-remove-prop-types
462
+ babel-plugin-macros
463
+ ]
464
+ if add_npm_dependencies(react_deps)
465
+ @added_dependencies_to_package_json = true
466
+ return
467
+ end
468
+
469
+ success = system("npm", "install", *react_deps)
470
+ @ran_direct_installs = true if success
471
+ handle_npm_failure("React dependencies", react_deps) unless success
472
+ end
473
+
474
+ def add_css_dependencies
475
+ puts "Installing CSS handling dependencies..."
476
+ css_deps = %w[
477
+ css-loader
478
+ css-minimizer-webpack-plugin
479
+ mini-css-extract-plugin
480
+ style-loader
481
+ ]
482
+ if add_npm_dependencies(css_deps)
483
+ @added_dependencies_to_package_json = true
484
+ return
485
+ end
486
+
487
+ success = system("npm", "install", *css_deps)
488
+ @ran_direct_installs = true if success
489
+ handle_npm_failure("CSS dependencies", css_deps) unless success
490
+ end
491
+
492
+ def add_dev_dependencies
493
+ puts "Installing development dependencies..."
494
+ dev_deps = %w[
495
+ @pmmmwh/react-refresh-webpack-plugin
496
+ react-refresh
497
+ ]
498
+ if add_npm_dependencies(dev_deps, dev: true)
499
+ @added_dependencies_to_package_json = true
500
+ return
501
+ end
502
+
503
+ success = system("npm", "install", "--save-dev", *dev_deps)
504
+ @ran_direct_installs = true if success
505
+ handle_npm_failure("development dependencies", dev_deps, dev: true) unless success
506
+ end
507
+
508
+ def install_js_dependencies
509
+ # Detect which package manager to use
510
+ success = if File.exist?(File.join(destination_root, "yarn.lock"))
511
+ system("yarn", "install")
512
+ elsif File.exist?(File.join(destination_root, "pnpm-lock.yaml"))
513
+ system("pnpm", "install")
514
+ elsif File.exist?(File.join(destination_root, "package-lock.json")) ||
515
+ File.exist?(File.join(destination_root, "package.json"))
516
+ # Use npm for package-lock.json or as default fallback
517
+ system("npm", "install")
518
+ else
519
+ true # No package manager detected, skip
520
+ end
521
+
522
+ unless success
523
+ GeneratorMessages.add_warning(<<~MSG.strip)
524
+ ⚠️ JavaScript dependencies installation failed.
525
+
526
+ This could be due to network issues or missing package manager.
527
+ You can install dependencies manually later by running:
528
+ • npm install (if using npm)
529
+ • yarn install (if using yarn)
530
+ • pnpm install (if using pnpm)
531
+ MSG
532
+ end
533
+
534
+ success
535
+ end
536
+
537
+ def handle_npm_failure(dependency_type, packages, dev: false)
538
+ install_command = dev ? "npm install --save-dev" : "npm install"
539
+ GeneratorMessages.add_warning(<<~MSG.strip)
540
+ ⚠️ Failed to install #{dependency_type}.
541
+
542
+ The following packages could not be installed automatically:
543
+ #{packages.map { |pkg| " • #{pkg}" }.join("\n")}
544
+
545
+ This could be due to network issues or missing package manager.
546
+ You can install them manually later by running:
547
+ #{install_command} #{packages.join(' ')}
548
+ MSG
549
+ end
550
+
413
551
  # Removed: Shakapacker auto-installation logic (now explicit dependency)
414
552
 
415
553
  # Removed: Shakapacker 8+ is now required as explicit dependency
@@ -19,7 +19,7 @@ module ReactOnRails
19
19
  aliases: "-T"
20
20
 
21
21
  def create_redux_directories
22
- # Create auto-registration directory structure for Redux
22
+ # Create auto-bundling directory structure for Redux
23
23
  empty_directory("app/javascript/src/HelloWorldApp/ror_components")
24
24
 
25
25
  # Create Redux support directories within the component directory
@@ -31,7 +31,7 @@ module ReactOnRails
31
31
  base_js_path = "redux/base"
32
32
  ext = component_extension(options)
33
33
 
34
- # Copy Redux-connected component to auto-registration structure
34
+ # Copy Redux-connected component to auto-bundling structure
35
35
  copy_file("#{base_js_path}/app/javascript/bundles/HelloWorld/startup/HelloWorldApp.client.#{ext}",
36
36
  "app/javascript/src/HelloWorldApp/ror_components/HelloWorldApp.client.#{ext}")
37
37
  copy_file("#{base_js_path}/app/javascript/bundles/HelloWorld/startup/HelloWorldApp.server.#{ext}",
@@ -89,6 +89,13 @@ module ReactOnRails
89
89
  install_packages_with_fallback(regular_packages, dev: false, package_manager: package_manager)
90
90
  end
91
91
 
92
+ def add_redux_specific_messages
93
+ # Append Redux-specific post-install instructions
94
+ GeneratorMessages.add_info(
95
+ GeneratorMessages.helpful_message_after_installation(component_name: "HelloWorldApp", route: "hello_world")
96
+ )
97
+ end
98
+
92
99
  private
93
100
 
94
101
  def install_packages_with_fallback(packages, dev:, package_manager:)
@@ -132,14 +139,6 @@ module ReactOnRails
132
139
  when "yarn", "bun" then "--dev"
133
140
  end
134
141
  end
135
-
136
- def add_redux_specific_messages
137
- # Override the generic messages with Redux-specific instructions
138
- GeneratorMessages.output.clear
139
- GeneratorMessages.add_info(
140
- GeneratorMessages.helpful_message_after_installation(component_name: "HelloWorldApp", route: "hello_world")
141
- )
142
- end
143
142
  end
144
143
  end
145
144
  end
@@ -24,8 +24,8 @@ ReactOnRails.configure do |config|
24
24
  # to automatically refresh your webpack assets on every test run.
25
25
  #
26
26
  # Alternately, you can remove the `ReactOnRails::TestHelper.configure_rspec_to_compile_assets`
27
- # and set the config/<%= config[:packer_type] %>.yml option for test to true.
28
- config.build_test_command = "RAILS_ENV=test bin/<%= config[:packer_type] %>"
27
+ # and set the config/shakapacker.yml option for test to true.
28
+ config.build_test_command = "RAILS_ENV=test bin/shakapacker"
29
29
 
30
30
  ################################################################################
31
31
  ################################################################################
@@ -43,6 +43,15 @@ ReactOnRails.configure do |config|
43
43
  #
44
44
  config.server_bundle_js_file = "server-bundle.js"
45
45
 
46
+ # Configure where server bundles are output. Defaults to "ssr-generated".
47
+ # This should match your webpack configuration for server bundles.
48
+ config.server_bundle_output_path = "ssr-generated"
49
+
50
+ # Enforce that server bundles are only loaded from private (non-public) directories.
51
+ # When true, server bundles will only be loaded from the configured server_bundle_output_path.
52
+ # This is recommended for production to prevent server-side code from being exposed.
53
+ config.enforce_private_server_bundles = true
54
+
46
55
  ################################################################################
47
56
  ################################################################################
48
57
  # FILE SYSTEM BASED COMPONENT REGISTRY
@@ -44,13 +44,14 @@ const configureServer = () => {
44
44
 
45
45
  // Custom output for the server-bundle that matches the config in
46
46
  // config/initializers/react_on_rails.rb
47
+ // Server bundles are output to a private directory (not public) for security
47
48
  serverWebpackConfig.output = {
48
49
  filename: 'server-bundle.js',
49
50
  globalObject: 'this',
50
51
  // If using the React on Rails Pro node server renderer, uncomment the next line
51
52
  // libraryTarget: 'commonjs2',
52
- path: config.outputPath,
53
- publicPath: config.publicPath,
53
+ path: require('path').resolve(__dirname, '../../ssr-generated'),
54
+ // No publicPath needed since server bundles are not served via web
54
55
  // https://webpack.js.org/configuration/output/#outputglobalobject
55
56
  };
56
57