Skip to content

Commit 81e717e

Browse files
justin808claude
andcommitted
Fix beta/RC version handling in generator
The regex for detecting valid npm package versions only matched stable releases (e.g., 16.2.0) but not pre-release versions (e.g., 16.2.0-beta.10). This caused the generator to install 'react-on-rails' (latest stable) instead of '[email protected]', leading to version mismatch errors when running the generator with beta versions. Changes: - Updated regex from /\A\d+\.\d+\.\d+\z/ to /\A\d+\.\d+\.\d+(-[a-zA-Z0-9.]+)?\z/ - Now matches stable (16.2.0), beta (16.2.0-beta.10), RC (16.1.0-rc.1), etc. - Updated comments to explain the regex and why exact versions are needed - Improved warning message when version format is unrecognized This fixes the version mismatch error seen in CI: Package: 16.1.2 (latest stable from npm) Gem: 16.2.0.beta.10 (current beta version) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 311d3a1 commit 81e717e

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

lib/generators/react_on_rails/js_dependency_manager.rb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,20 @@ def add_js_dependencies
123123
end
124124

125125
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)
126+
# Use exact version match between gem and npm package for all versions including pre-releases
127+
# The regex matches:
128+
# - Stable: 16.2.0
129+
# - Beta: 16.2.0-beta.10
130+
# - RC: 16.1.0-rc.1
131+
# - Alpha: 16.0.0-alpha.5
132+
# This ensures beta/rc versions use the exact version instead of "latest" which would
133+
# install the latest stable release and cause version mismatches.
134+
version_with_optional_prerelease = /\A\d+\.\d+\.\d+(-[a-zA-Z0-9.]+)?\z/
135+
react_on_rails_pkg = if ReactOnRails::VERSION.match?(version_with_optional_prerelease)
131136
"react-on-rails@#{ReactOnRails::VERSION}"
132137
else
133-
puts "Adding the latest react-on-rails NPM module. " \
138+
puts "WARNING: Unrecognized version format #{ReactOnRails::VERSION}. " \
139+
"Adding the latest react-on-rails NPM module. " \
134140
"Double check this is correct in package.json"
135141
"react-on-rails"
136142
end

0 commit comments

Comments
 (0)