Sha256: 40bf70df92af60f4114139aa3dc30417e8225f9f38e3dd27968906451b07ad1f

Contents?: true

Size: 1.38 KB

Versions: 17

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true
require 'json'

module Sprockets
  module Npm
    # Internal: Override resolve_alternates to install package.json behavior.
    #
    # load_path    - String environment path
    # logical_path - String path relative to base
    #
    # Returns candiate filenames.
    def resolve_alternates(load_path, logical_path)
      candidates, deps = super

      dirname = File.join(load_path, logical_path)

      if directory?(dirname)
        filename = File.join(dirname, 'package.json')

        if self.file?(filename)
          deps << build_file_digest_uri(filename)
          read_package_directives(dirname, filename) do |path|
            if file?(path)
              candidates << path
            end
          end
        end
      end

      return candidates, deps
    end

    # Internal: Read package.json's main and style directives.
    #
    # dirname  - String path to component directory.
    # filename - String path to package.json.
    #
    # Returns nothing.
    def read_package_directives(dirname, filename)
      package = JSON.parse(File.read(filename), create_additions: false)

      case package['main']
      when String
        yield File.expand_path(package['main'], dirname)
      when nil
        yield File.expand_path('index.js', dirname)
      end

      yield File.expand_path(package['style'], dirname) if package['style']
    end
  end
end

Version data entries

17 entries across 17 versions & 6 rubygems

Version Path
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/npm.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/npm.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/npm.rb
sprockets-4.0.2 lib/sprockets/npm.rb
sprockets-4.0.1 lib/sprockets/npm.rb
argon-1.3.1 vendor/bundle/ruby/2.7.0/gems/sprockets-4.0.0/lib/sprockets/npm.rb
symbolic_enum-1.1.5 vendor/bundle/ruby/2.7.0/gems/sprockets-4.0.0/lib/sprockets/npm.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/npm.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/npm.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/npm.rb
sprockets-4.0.0 lib/sprockets/npm.rb
sprockets-4.0.0.beta10 lib/sprockets/npm.rb
sprockets-4.0.0.beta9 lib/sprockets/npm.rb
sprockets-4.0.0.beta8 lib/sprockets/npm.rb
sprockets-4.0.0.beta7 lib/sprockets/npm.rb
sprockets-4.0.0.beta6 lib/sprockets/npm.rb
sprockets-4.0.0.beta5 lib/sprockets/npm.rb