diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 64e2eef59c..126c80b598 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -11,6 +11,7 @@ on: paths-ignore: - '**.md' - 'docs/**' + workflow_dispatch: jobs: detect-changes: diff --git a/.github/workflows/package-js-tests.yml b/.github/workflows/package-js-tests.yml index a9e6b64acb..73e1628123 100644 --- a/.github/workflows/package-js-tests.yml +++ b/.github/workflows/package-js-tests.yml @@ -15,6 +15,7 @@ on: - 'docs/**' - 'lib/**' - 'spec/react_on_rails/**' + workflow_dispatch: jobs: detect-changes: diff --git a/lib/generators/react_on_rails/install_generator.rb b/lib/generators/react_on_rails/install_generator.rb index b5769628d5..eee693f4b9 100644 --- a/lib/generators/react_on_rails/install_generator.rb +++ b/lib/generators/react_on_rails/install_generator.rb @@ -37,6 +37,10 @@ class InstallGenerator < Rails::Generators::Base # Removed: --skip-shakapacker-install (Shakapacker is now a required dependency) def run_generators + # Set environment variable to skip validation during generator run + # This is inherited by all invoked generators and persists through Rails initialization + ENV["REACT_ON_RAILS_SKIP_VALIDATION"] = "true" + if installation_prerequisites_met? || options.ignore_warnings? invoke_generators add_bin_scripts @@ -55,6 +59,7 @@ def run_generators GeneratorMessages.add_error(error) end ensure + ENV.delete("REACT_ON_RAILS_SKIP_VALIDATION") print_generator_messages end diff --git a/lib/react_on_rails/engine.rb b/lib/react_on_rails/engine.rb index f2f9c0fb93..eee194ae60 100644 --- a/lib/react_on_rails/engine.rb +++ b/lib/react_on_rails/engine.rb @@ -20,6 +20,12 @@ class Engine < ::Rails::Engine # Determine if version validation should be skipped # @return [Boolean] true if validation should be skipped def self.skip_version_validation? + # Skip if explicitly disabled via environment variable (set by generators) + if ENV["REACT_ON_RAILS_SKIP_VALIDATION"] == "true" + Rails.logger.debug "[React on Rails] Skipping validation - disabled via environment variable" + return true + end + # Check package.json first as it's cheaper and handles more cases if package_json_missing? Rails.logger.debug "[React on Rails] Skipping validation - package.json not found" diff --git a/spec/react_on_rails/engine_spec.rb b/spec/react_on_rails/engine_spec.rb index 2b2fa83545..cce8f24b88 100644 --- a/spec/react_on_rails/engine_spec.rb +++ b/spec/react_on_rails/engine_spec.rb @@ -13,6 +13,26 @@ module ReactOnRails allow(Rails.logger).to receive(:debug) end + context "when REACT_ON_RAILS_SKIP_VALIDATION is set" do + before do + ENV["REACT_ON_RAILS_SKIP_VALIDATION"] = "true" + end + + after do + ENV.delete("REACT_ON_RAILS_SKIP_VALIDATION") + end + + it "returns true" do + expect(described_class.skip_version_validation?).to be true + end + + it "logs debug message about environment variable" do + described_class.skip_version_validation? + expect(Rails.logger).to have_received(:debug) + .with("[React on Rails] Skipping validation - disabled via environment variable") + end + end + context "when package.json doesn't exist" do before do allow(File).to receive(:exist?).with(package_json_path).and_return(false)