Skip to content

Commit b602d66

Browse files
justin808claude
andcommitted
Add package manager prerequisite check and improve error handling
- Add cli_exists? helper method to check if CLI commands are available - Add missing_package_manager? method that checks for npm/pnpm/yarn/bun - Update installation_prerequisites_met? to include package manager check - Replace exit(1) calls with Thor::Error exceptions for better error handling - Ensure clear error messages are provided when package managers are missing The generator will now verify that at least one JavaScript package manager is available before proceeding with installation, preventing confusing failures later in the process. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent afcb7ac commit b602d66

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

lib/generators/react_on_rails/install_generator.rb

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def invoke_generators
7070
# js(.coffee) are not checked by this method, but instead produce warning messages
7171
# and allow the build to continue
7272
def installation_prerequisites_met?
73-
!(missing_node? || ReactOnRails::GitUtils.uncommitted_changes?(GeneratorMessages))
73+
!(missing_node? || missing_package_manager? || ReactOnRails::GitUtils.uncommitted_changes?(GeneratorMessages))
7474
end
7575

7676
def missing_node?
@@ -143,7 +143,7 @@ def ensure_shakapacker_installed
143143
Then re-run: rails generate react_on_rails:install
144144
MSG
145145
GeneratorMessages.add_error(error)
146-
exit(1)
146+
raise Thor::Error, error
147147
end
148148
puts Rainbow("✅ Shakapacker added to Gemfile successfully!").green
149149
end
@@ -171,7 +171,7 @@ def ensure_shakapacker_installed
171171
Need help? Visit: https://github.com/shakacode/shakapacker/blob/main/docs/installation.md
172172
MSG
173173
GeneratorMessages.add_error(error)
174-
exit(1)
174+
raise Thor::Error, error
175175
end
176176

177177
puts Rainbow("✅ Shakapacker installed successfully!").green
@@ -239,6 +239,35 @@ def shakapacker_in_gemfile_text?(gem_name)
239239
File.foreach(gemfile).any? { |l| l.match?(/^\s*gem\s+['"]#{Regexp.escape(gem_name)}['"]/) }
240240
end
241241

242+
def cli_exists?(command)
243+
system("which #{command} > /dev/null 2>&1")
244+
end
245+
246+
def missing_package_manager?
247+
package_managers = %w[npm pnpm yarn bun]
248+
missing = package_managers.none? { |pm| cli_exists?(pm) }
249+
250+
if missing
251+
error = <<~MSG.strip
252+
🚫 No JavaScript package manager found on your system.
253+
254+
React on Rails requires a JavaScript package manager to install dependencies.
255+
Please install one of the following:
256+
257+
• npm: Usually comes with Node.js (https://nodejs.org/en/)
258+
• yarn: npm install -g yarn (https://yarnpkg.com/)
259+
• pnpm: npm install -g pnpm (https://pnpm.io/)
260+
• bun: Install from https://bun.sh/
261+
262+
After installation, restart your terminal and try again.
263+
MSG
264+
GeneratorMessages.add_error(error)
265+
return true
266+
end
267+
268+
false
269+
end
270+
242271
# Removed: Shakapacker auto-installation logic (now explicit dependency)
243272

244273
# Removed: Shakapacker 8+ is now required as explicit dependency

0 commit comments

Comments
 (0)