Class: Shakapacker::Doctor

Inherits:
Object
  • Object
show all
Defined in:
lib/shakapacker/doctor.rb

Defined Under Namespace

Classes: Reporter

Constant Summary collapse

CATEGORY_ACTION_REQUIRED =

Warning categories for better organization

:action_required
:recommended
CATEGORY_INFO =
:info
REQUIRED_BINSTUBS =
{
  "bin/shakapacker" => "Main Shakapacker binstub",
  "bin/shakapacker-dev-server" => "Development server binstub",
  "bin/shakapacker-config" => "Config export binstub"
}.freeze
OPTIONAL_BINSTUBS =
%w[
  bin/shakapacker-watch
  bin/diff-bundler-config
].freeze
PACKAGE_MANAGER_LOCKFILES =
{
  "bun.lockb" => "bun",
  "pnpm-lock.yaml" => "pnpm",
  "yarn.lock" => "yarn",
  "package-lock.json" => "npm"
}.freeze
SASS_IMPLEMENTATION_PACKAGES =
%w[
  sass
  sass-embedded
].freeze
SASS_IMPLEMENTATION_DEPENDENCY_MESSAGE =
(
  "Missing required dependency 'sass' or 'sass-embedded' " \
  "for Sass/SCSS implementation"
).freeze
REQUIRED_RSPACK_DEPS =
{
  "@rspack/core" => "^2.0.0",
  "@rspack/cli" => "^2.0.0",
  "rspack-manifest-plugin" => "^5.2.2"
}.freeze
RSPACK_DEV_SERVER_DEP =
{
  "@rspack/dev-server" => "^2.0.0"
}.freeze
RSPACK_V2_ONLY_DEPS =
REQUIRED_RSPACK_DEPS
.slice("@rspack/core", "@rspack/cli")
.merge(RSPACK_DEV_SERVER_DEP)
.freeze
OPTIONAL_RSPACK_V2_ONLY_DEPS =
{
  "@rspack/plugin-react-refresh" => "^2.0.0"
}.freeze
CUSTOM_HYBRID_LOADER_DEPS =
%w[
  babel-loader
  esbuild-loader
  ts-loader
].freeze
BUNDLER_CONFIG_EXTENSIONS =
%w[
  ts
  js
].freeze
PACKAGE_ROOT_MARKERS =
(["package.json"] + PACKAGE_MANAGER_LOCKFILES.keys + ["node_modules"]).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = nil, root_path = nil, options = {}) ⇒ Doctor

Returns a new instance of Doctor.



75
76
77
78
79
80
81
82
# File 'lib/shakapacker/doctor.rb', line 75

def initialize(config = nil, root_path = nil, options = {})
  @config = config || Shakapacker.config
  @root_path = root_path || (defined?(Rails) ? Rails.root : Pathname.new(Dir.pwd))
  @issues = []
  @warnings = []  # Now stores hashes: { category: :symbol, message: "..." }
  @info = []
  @options = options
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'lib/shakapacker/doctor.rb', line 8

def config
  @config
end

#infoObject (readonly)

Returns the value of attribute info.



8
9
10
# File 'lib/shakapacker/doctor.rb', line 8

def info
  @info
end

#issuesObject (readonly)

Returns the value of attribute issues.



8
9
10
# File 'lib/shakapacker/doctor.rb', line 8

def issues
  @issues
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/shakapacker/doctor.rb', line 8

def options
  @options
end

#root_pathObject (readonly)

Returns the value of attribute root_path.



8
9
10
# File 'lib/shakapacker/doctor.rb', line 8

def root_path
  @root_path
end

#warningsObject (readonly)

Returns the value of attribute warnings.



8
9
10
# File 'lib/shakapacker/doctor.rb', line 8

def warnings
  @warnings
end

Instance Method Details

#runObject



84
85
86
87
88
89
90
91
92
# File 'lib/shakapacker/doctor.rb', line 84

def run
  if options[:help]
    print_help
    return
  end

  perform_checks
  report_results
end

#success?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/shakapacker/doctor.rb', line 94

def success?
  @issues.empty?
end