Sha256: 4ee7e70b3f838619013e5a4e7930f524f6dfdda9f509b3114da9f768c07f080f

Contents?: true

Size: 1.32 KB

Versions: 25

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true
require 'sewing_kit/webpack/webpack'

module SewingKit
  module Webpack
    class Manifest
      class Base
        def initialize
          @metadata = nil
        end

        def clear_cache!
          @metadata = nil
        end

        def manifest
          current_metadata = metadata

          if current_metadata.is_a?(Array)
            all_assets = current_metadata.flat_map do |data|
              data['assets']['all'].values
            end

            # sewing-kit asset manifests return a numerically indexed hash, not a true array,
            # so we need to change it back to a hash for compatibility
            asset_hash = all_assets.each_with_index
              .collect { |asset, index| [index, asset] }
              .to_h

            {
              "all" => asset_hash,
            }
          else
            current_metadata['assets']
          end
        end

        protected

        def load_metadata_from_fs(path)
          begin
            content = File.read(path)
          rescue => e
            raise ManifestLoadError.new(path, e)
          end

          parse_metadata(content)
        end

        private

        def parse_metadata(json)
          JSON.parse(json)
        rescue => e
          raise ManifestParseError, e
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
sewing_kit-0.130.0 lib/sewing_kit/webpack/manifest/base.rb
sewing_kit-0.129.0 lib/sewing_kit/webpack/manifest/base.rb
sewing_kit-0.128.0 lib/sewing_kit/webpack/manifest/base.rb
sewing_kit-0.127.0 lib/sewing_kit/webpack/manifest/base.rb
sewing_kit-0.126.0 lib/sewing_kit/webpack/manifest/base.rb
sewing_kit-0.125.0 lib/sewing_kit/webpack/manifest/base.rb
sewing_kit-0.124.0 lib/sewing_kit/webpack/manifest/base.rb
sewing_kit-0.123.0 lib/sewing_kit/webpack/manifest/base.rb
sewing_kit-0.122.1 lib/sewing_kit/webpack/manifest/base.rb
sewing_kit-0.122.0 lib/sewing_kit/webpack/manifest/base.rb
sewing_kit-0.114.2 lib/sewing_kit/webpack/manifest/base.rb
sewing_kit-0.114.0 lib/sewing_kit/webpack/manifest/base.rb
sewing_kit-0.97.2 lib/sewing_kit/webpack/manifest/base.rb
sewing_kit-0.97.1 lib/sewing_kit/webpack/manifest/base.rb
sewing_kit-0.97.0 lib/sewing_kit/webpack/manifest/base.rb
sewing_kit-0.96.0 lib/sewing_kit/webpack/manifest/base.rb
sewing_kit-0.95.4 lib/sewing_kit/webpack/manifest/base.rb
sewing_kit-0.95.3 lib/sewing_kit/webpack/manifest/base.rb
sewing_kit-0.95.2 lib/sewing_kit/webpack/manifest/base.rb
sewing_kit-0.95.1 lib/sewing_kit/webpack/manifest/base.rb