# File lib/sprockets/manifest.rb, line 27
    def initialize(*args)
      if args.first.is_a?(Base) || args.first.nil?
        @environment = args.shift
      end

      @dir, @path = args[0], args[1]

      # Expand paths
      @dir  = File.expand_path(@dir) if @dir
      @path = File.expand_path(@path) if @path

      # If path is given as the second arg
      if @dir && File.extname(@dir) != ""
        @dir, @path = nil, @dir
      end

      # Default dir to the directory of the path
      @dir ||= File.dirname(@path) if @path

      # If directory is given w/o path, pick a random manifest.json location
      if @dir && @path.nil?
        # Find the first manifest.json in the directory
        paths = Dir[File.join(@dir, "manifest*.json")]
        if paths.any?
          @path = paths.first
        else
          @path = File.join(@dir, "manifest-#{SecureRandom.hex(16)}.json")
        end
      end

      unless @dir && @path
        raise ArgumentError, "manifest requires output path"
      end

      data = nil

      begin
        if File.exist?(@path)
          data = json_decode(File.read(@path))
        end
      rescue MultiJson::DecodeError => e
        logger.error "#{@path} is invalid: #{e.class} #{e.message}"
      end

      @data = data.is_a?(Hash) ? data : {}
    end