Sha256: 89bed78592e99fd9bcb3eba230002677e24293cb2dea0ee552f193cc9d7a3ca2

Contents?: true

Size: 1.31 KB

Versions: 2

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true
require 'sewing_kit/webpack/manifest/base'
require 'browserslist_useragent'

module SewingKit
  module Webpack
    class Manifest
      class Production < Base
        @metadata = nil
        @metadata_path = nil

        # :nodoc:
        def asset_dependencies(entrypoint_name, user_agent)
          metadata_for(user_agent)['entrypoints'][entrypoint_name]
        end

        def metadata
          @metadata ||= load_metadata
        end

        private

        def metadata_for(user_agent)
          if metadata.is_a?(Array)
            find_matching_metadata(metadata, user_agent)
          else
            metadata
          end
        end

        def find_matching_metadata(consolidated_metadata, user_agent)
          found = consolidated_metadata.find do |metadata|
            return nil if metadata["resolvedBrowsers"].nil?
            matcher = BrowserslistUseragent::Match.new(metadata["resolvedBrowsers"], user_agent)

            matcher.browser? && matcher.version?(allow_higher: true)
          end

          found || consolidated_metadata.last
        end

        def load_metadata
          load_metadata_from_fs(path)
        end

        def path
          File.join(Rails.root, 'public', 'bundles', SewingKit.configuration.manifest_name)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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