Sha256: a98a1a469fa90ab2529384a9a4b8aa2606ffbde153ad4aed6839d900b81d6d7a

Contents?: true

Size: 1.62 KB

Versions: 80

Compression:

Stored size: 1.62 KB

Contents

require 'json'

module Sprockets
  module Bower
    # Internal: All supported bower.json files.
    #
    # https://github.com/bower/json/blob/0.4.0/lib/json.js#L7
    POSSIBLE_BOWER_JSONS = ['bower.json', 'component.json', '.bower.json']

    # Internal: Override resolve_alternates to install bower.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

      # bower.json can only be nested one level deep
      if !logical_path.index('/')
        dirname = File.join(load_path, logical_path)

        if directory?(dirname)
          filenames = POSSIBLE_BOWER_JSONS.map { |basename| File.join(dirname, basename) }
          filename  = filenames.detect { |fn| self.file?(fn) }

          if filename
            deps << build_file_digest_uri(filename)
            read_bower_main(dirname, filename) do |path|
              candidates << path
            end
          end
        end
      end

      return candidates, deps
    end

    # Internal: Read bower.json's main directive.
    #
    # dirname  - String path to component directory.
    # filename - String path to bower.json.
    #
    # Returns nothing.
    def read_bower_main(dirname, filename)
      bower = JSON.parse(File.read(filename), create_additions: false)

      case bower['main']
      when String
        yield File.expand_path(bower['main'], dirname)
      when Array
        bower['main'].each do |name|
          yield File.expand_path(name, dirname)
        end
      end
    end
  end
end

Version data entries

80 entries across 74 versions & 15 rubygems

Version Path
sprockets-3.7.5 lib/sprockets/bower.rb
sprockets-3.7.4 lib/sprockets/bower.rb
sprockets-3.7.3 lib/sprockets/bower.rb
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/bower.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/bower.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/bower.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/bower.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/bower.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/bower.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/bower.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/bower.rb
zuora_connect_ui-0.8.2 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/bower.rb
zuora_connect_ui-0.8.1 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/bower.rb
zuora_connect_ui-0.8.0 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/bower.rb
spiral_form-0.1.1 vendor/bundle/gems/sprockets-3.7.2/lib/sprockets/bower.rb
spiral_form-0.1.0 vendor/bundle/gems/sprockets-3.7.2/lib/sprockets/bower.rb
zuora_connect_ui-0.7.1 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/bower.rb
zuora_connect_ui-0.7.0 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/bower.rb
tdiary-5.0.11 vendor/bundle/gems/sprockets-3.7.2/lib/sprockets/bower.rb
sprokovuln-0.2.0 vendor/ruby/gems/sprockets-3.7.1/lib/sprockets/bower.rb