Sha256: 72926cf302f91411c9beb5614a69966e9729a3cf86138a482fe62ffa7f60c45d

Contents?: true

Size: 1.79 KB

Versions: 16

Compression:

Stored size: 1.79 KB

Contents

# frozen_string_literal: true

# Internal: Raised when an entry is not found in the build manifest.
#
# NOTE: The complexity here is justified by the improved usability of providing
# a more specific error message depending on the situation.
class ViteRuby::MissingEntrypointError < ViteRuby::Error
  extend Forwardable
  def_delegators :@info, :file_name, :last_build, :manifest, :config

  def initialize(info)
    @info = info
    super <<~MSG
      Vite Ruby can't find #{ file_name } in #{ config.manifest_path.relative_path_from(config.root) } or #{ config.assets_manifest_path.relative_path_from(config.root) }.

      Possible causes:
      #{ possible_causes(last_build) }
      :troubleshooting:
      #{ "\nContent in your manifests:\n#{ JSON.pretty_generate(manifest) }\n" if last_build.success }
      #{ "Last build in #{ config.mode } mode:\n#{ last_build.to_json }\n" if last_build.success }
    MSG
  end

  def possible_causes(last_build)
    if last_build.success == false
      FAILED_BUILD_CAUSES
        .sub(':mode:', config.mode)
        .sub(':errors:', last_build.errors.to_s.gsub(/^(?!$)/, '  '))
    elsif config.auto_build
      DEFAULT_CAUSES
    else
      DEFAULT_CAUSES + NO_AUTO_BUILD_CAUSES
    end
  end

  FAILED_BUILD_CAUSES = <<~MSG
      - The last build failed. Try running `bin/vite build --clear --mode=:mode:` manually and check for errors.

    Errors:
    :errors:
  MSG

  DEFAULT_CAUSES = <<-MSG
  - The file path is incorrect.
  - The file is not in the entrypoints directory.
  - Some files are outside the sourceCodeDir, and have not been added to watchAdditionalPaths.
  MSG

  NO_AUTO_BUILD_CAUSES = <<-MSG
  - You have not run `bin/vite dev` to start Vite, or the dev server is not reachable.
  - "autoBuild" is set to `false` in your config/vite.json for this environment.
  MSG
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
vite_ruby-3.3.4 lib/vite_ruby/missing_entrypoint_error.rb
vite_ruby-3.3.3 lib/vite_ruby/missing_entrypoint_error.rb
vite_ruby-3.3.2 lib/vite_ruby/missing_entrypoint_error.rb
vite_ruby-3.3.1 lib/vite_ruby/missing_entrypoint_error.rb
vite_ruby-3.3.0 lib/vite_ruby/missing_entrypoint_error.rb
vite_ruby-3.2.15 lib/vite_ruby/missing_entrypoint_error.rb
vite_ruby-3.2.14 lib/vite_ruby/missing_entrypoint_error.rb
vite_ruby-3.2.13 lib/vite_ruby/missing_entrypoint_error.rb
vite_ruby-3.2.12 lib/vite_ruby/missing_entrypoint_error.rb
vite_ruby-3.2.11 lib/vite_ruby/missing_entrypoint_error.rb
vite_ruby-3.2.10 lib/vite_ruby/missing_entrypoint_error.rb
vite_ruby-3.2.9 lib/vite_ruby/missing_entrypoint_error.rb
vite_ruby-3.2.8 lib/vite_ruby/missing_entrypoint_error.rb
vite_ruby-3.2.7 lib/vite_ruby/missing_entrypoint_error.rb
vite_ruby-3.2.6 lib/vite_ruby/missing_entrypoint_error.rb
vite_ruby-3.2.5 lib/vite_ruby/missing_entrypoint_error.rb