Sha256: c6c18484fe76c6e7656187cf375411f89ae8d58a023d0039fcec33f6d9c7a282

Contents?: true

Size: 1.96 KB

Versions: 1

Compression:

Stored size: 1.96 KB

Contents

# frozen_string_literal: true
require 'open3'
require 'uri'

module SewingKit
  module Webpack
    # Webpack manifest loading, caching & entry point retrieval
    class Manifest
      class NodeSewingKitManifestMissing < StandardError
        def initialize(node_error_message)
          super(
            "Could not fetch the sewing-kit manifest 🙀  \n" \
            "Possible next steps:\n" \
            " - If the server is still starting up, wait for a "  \
            "'Compiled with latest changes' message then refresh your browser\n" \
            " - Check the development console for compilation errors\n" \
            " - Restart your development server\n" \
            "\n" \
            "Original error #{node_error_message}"
          )
        end
      end

      # Raised if the node-generated manifest cannot be read from the filesystem.
      class ManifestLoadError < StandardError
        def initialize(path, cause)
          super "Could not load manifest from #{path} (original error #{cause})"
        end
      end

      # Raised if the node-generated manifest returns unparseable JSON.
      class ManifestParseError < StandardError
        def initialize(cause)
          super "Could not parse manifest JSON (original error #{cause})"
        end
      end

      class << self
        # :nodoc:
        def asset_dependencies(entrypoint_name, user_agent)
          instance.asset_dependencies(entrypoint_name, user_agent)
        end

        def clear_cache!
          @instance = nil
        end

        def manifest
          instance.manifest
        end

        def instance
          mode = ENV['NODE_ENV'] || Rails.env.to_s
          @instance ||= if (mode == 'development' && ENV['SK_SIMULATE_PRODUCTION'] != '1') || Rails.env.test?
            Development.new
          else
            Production.new
          end
        end
      end
    end
  end
end

require 'sewing_kit/webpack/manifest/development'
require 'sewing_kit/webpack/manifest/production'

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sewing_kit-0.92.0 lib/sewing_kit/webpack/manifest.rb