Class: ReactManifest::ApplicationAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/react_manifest/application_analyzer.rb

Overview

Analyzes existing application*.js files to classify each directive as:

:vendor   — vendor lib require (keep)
:ux_code  — UX/app code require (remove — will be served by ux_*.js bundles)
:unknown  — needs manual review

Produces a human-readable report without writing anything.

Defined Under Namespace

Classes: ClassifiedDirective, Result

Constant Summary collapse

DIRECTIVE_PATTERN =
%r{^\s*//=\s+(require(?:_tree|_directory)?)\s+(.+)$}
VENDOR_HINTS =

Libs we recognise as vendor (case-insensitive partial match on the require path)

%w[
  react react-dom react_dom reactdom
  mui material-ui
  redux redux-thunk redux-saga redux-toolkit
  axios lodash underscore
  jquery backbone handlebars
  turbo stimulus
  vendor
  bootstrap tailwind tailwindcss
  moment date-fns dayjs
  formik react-hook-form
  recharts chartjs chart.js
  framer-motion
  i18next
  classnames clsx
  uuid
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(config = ReactManifest.configuration) ⇒ ApplicationAnalyzer

Returns a new instance of ApplicationAnalyzer.



39
40
41
# File 'lib/react_manifest/application_analyzer.rb', line 39

def initialize(config = ReactManifest.configuration)
  @config = config
end

Instance Method Details

#analyzeObject

Returns array of Result objects, one per application*.js found



44
45
46
# File 'lib/react_manifest/application_analyzer.rb', line 44

def analyze
  application_files.map { |f| analyze_file(f) }
end

Pretty-print the analysis report to stdout



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/react_manifest/application_analyzer.rb', line 49

def print_report(results = analyze)
  puts "\n=== ReactManifest: Application Manifest Analysis ===\n"

  if results.empty?
    puts "No application*.js files found in #{@config.abs_output_dir}"
    return
  end

  results.each do |result|
    rel = result.file.sub("#{Rails.root}/", "")
    status = result.clean? ? "✓ already clean" : "⚠ needs migration"
    puts "\n#{rel} [#{status}]"
    puts "-" * 60

    icon_map = { vendor: "  ✓ KEEP   ", ux_code: "  ✗ REMOVE ", unknown: "  ? REVIEW " }
    result.directives.each do |d|
      icon = icon_map[d.classification]
      puts "#{icon} #{d.original_line.strip}"
      puts "#{d.note}" if d.note
    end
  end

  puts "\n"
  puts "Run `rails react_manifest:migrate_application` to apply changes."
  puts "Use `--dry-run` (or config.dry_run = true) to preview first.\n\n"
end