Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
paths-ignore:
- '**.md'
- 'docs/**'
workflow_dispatch:

jobs:
detect-changes:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/package-js-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ on:
- 'docs/**'
- 'lib/**'
- 'spec/react_on_rails/**'
workflow_dispatch:

jobs:
detect-changes:
Expand Down
5 changes: 5 additions & 0 deletions lib/generators/react_on_rails/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -55,6 +59,7 @@ def run_generators
GeneratorMessages.add_error(error)
end
ensure
ENV.delete("REACT_ON_RAILS_SKIP_VALIDATION")
print_generator_messages
end

Expand Down
6 changes: 6 additions & 0 deletions lib/react_on_rails/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 20 additions & 0 deletions spec/react_on_rails/engine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading