Sha256: 57b8442ad4efe19c30d871c01d86f9503816ec2205608f7e294f9c0d31145e64

Contents?: true

Size: 702 Bytes

Versions: 4

Compression:

Stored size: 702 Bytes

Contents

# frozen_string_literal: true

require "json"

module CobraCommander
  module Dependencies
    module Yarn
      # Represents an Yarn package.json file
      class Package
        attr_reader :path

        def initialize(path)
          @path = Pathname.new(File.join(path, "package.json")).realpath
        end

        def project_tag
          name.match(%r{^@[\w-]+\/}).to_s
        end

        def name
          json["name"]
        end

        def dependencies
          json.fetch("dependencies", {})
              .merge(json.fetch("devDependencies", {}))
        end

      private

        def json
          @json ||= JSON.parse(File.read(@path))
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cobra_commander-0.9.0 lib/cobra_commander/dependencies/yarn/package.rb
cobra_commander-0.8.1 lib/cobra_commander/dependencies/yarn/package.rb
cobra_commander-0.8.0 lib/cobra_commander/dependencies/yarn/package.rb
cobra_commander-0.7.0 lib/cobra_commander/dependencies/yarn/package.rb