Class: ReactOnRails::Doctor

Inherits:
Object
  • Object
show all
Includes:
ConfigPathResolver
Defined in:
lib/react_on_rails/doctor.rb

Overview

rubocop:disable Metrics/ClassLength, Metrics/AbcSize

Constant Summary collapse

MESSAGE_COLORS =
{
  error: :red,
  warning: :yellow,
  success: :green,
  info: :blue
}.freeze
RSPEC_HELPER_FILES =
["spec/rails_helper.rb", "spec/spec_helper.rb"].freeze
MINITEST_HELPER_FILE =
"test/test_helper.rb"
DEFAULT_BUILD_TEST_COMMAND =
'config.build_test_command = "RAILS_ENV=test bin/shakapacker"'
DEFAULT_SHAKAPACKER_CONFIG_PATH =
"config/shakapacker.yml"
SERVER_BUNDLE_SOURCE_EXTENSIONS =
%w[.js .jsx .ts .tsx .mjs .cjs].freeze
CUSTOM_LAUNCHER_INDICATOR_FILES =
%w[dev].freeze
DEPRECATED_RENDERER_CACHE_TASK =

Deprecated-renderer-cache scan (used by check_deprecated_renderer_cache_task): look for references to the old pre_stage_bundle_for_node_renderer task in common deploy-script locations so users on older Procfile/Dockerfile entries get a migration nudge before the task is removed.

"pre_stage_bundle_for_node_renderer"
RENDERER_CACHE_DEPLOY_SCRIPT_PATHS =

Fixed allowlist of single-file deploy-script paths. Each entry is a literal path that may host a deploy hook referencing the deprecated task. Directory globs (e.g., per-stage Capistrano files or per-workflow GitHub Actions YAML) live in RENDERER_CACHE_DEPLOY_SCRIPT_GLOBS so they stay bounded.

[
  "Procfile",
  "Procfile.dev",
  "Procfile.dev-static-assets",
  "Procfile.production",
  "Dockerfile",
  "Dockerfile.production",
  "Dockerfile.staging",
  "Dockerfile.review",
  "docker-compose.yml",
  "docker-compose.yaml",
  "compose.yml",
  "compose.yaml",
  "bin/deploy",
  "bin/release",
  "bin/docker-entrypoint",
  "config/deploy.rb",
  "config/deploy/production.rb",
  "config/deploy/staging.rb",
  ".kamal/deploy.yml",
  "scripts/deploy.sh",
  ".circleci/config.yml",
  ".gitlab-ci.yml",
  "bitbucket-pipelines.yml"
].freeze
RENDERER_CACHE_DEPLOY_SCRIPT_GLOBS =

Bounded glob allowlist for deploy manifests that live in a known directory but use per-environment or per-workflow filenames. Each pattern matches only one directory level (no ‘**`) so the scan never recurses into the project tree, and the expansion is capped by RENDERER_CACHE_DEPLOY_SCRIPT_GLOB_MAX_MATCHES.

[
  ".github/workflows/*.yml",
  ".github/workflows/*.yaml",
  "config/deploy/*.rb"
].freeze
RENDERER_CACHE_DEPLOY_SCRIPT_MAX_BYTES =

Per-file safety gate to bound IO during the scan, not a meaningful size limit.

1_048_576
RENDERER_CACHE_DEPLOY_SCRIPT_GLOB_MAX_MATCHES =

Defense-in-depth cap on how many files a single glob may contribute. Realistic repos have a handful of workflow / deploy-stage files; far more than this is a sign of an unexpectedly broad pattern, not legitimate config.

100

Constants included from ConfigPathResolver

ConfigPathResolver::ALL_DEFAULT_CONFIG_CANDIDATES, ConfigPathResolver::RSPACK_DEFAULT_CONFIG_CANDIDATES, ConfigPathResolver::WEBPACK_DEFAULT_CONFIG_CANDIDATES

Instance Method Summary collapse

Constructor Details

#initialize(verbose: false, fix: false) ⇒ Doctor

Returns a new instance of Doctor.



114
115
116
117
118
119
120
# File 'lib/react_on_rails/doctor.rb', line 114

def initialize(verbose: false, fix: false)
  @verbose = verbose
  @fix = fix
  @checker = SystemChecker.new
  @test_output_path_strategy = :unknown
  @rails_environment_loaded = false
end

Instance Method Details

#run_diagnosisObject



122
123
124
125
126
127
128
129
# File 'lib/react_on_rails/doctor.rb', line 122

def run_diagnosis
  print_header
  run_all_checks
  print_summary
  print_recommendations if should_show_recommendations?

  exit_with_status
end