Sha256: 37befa24451249e40c185357993869c7ada91fd5e4d60bb9fcfd93f4c9e9f9b5

Contents?: true

Size: 920 Bytes

Versions: 8

Compression:

Stored size: 920 Bytes

Contents

# frozen_string_literal: true

module Spandx
  module Js
    module Parsers
      class Npm < ::Spandx::Core::Parser
        def matches?(filename)
          File.basename(filename) == 'package-lock.json'
        end

        def parse(file_path)
          items = Set.new
          each_metadata(file_path) do |metadata|
            items.add(map_from(metadata))
          end
          items
        end

        private

        def each_metadata(file_path)
          package_lock = JSON.parse(IO.read(file_path))
          package_lock['dependencies'].each do |name, metadata|
            yield metadata.merge('name' => name)
          end
        end

        def map_from(metadata)
          Spandx::Core::Dependency.new(
            package_manager: :npm,
            name: metadata['name'],
            version: metadata['version'],
            meta: metadata
          )
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
spandx-0.13.3 lib/spandx/js/parsers/npm.rb
spandx-0.13.2 lib/spandx/js/parsers/npm.rb
spandx-0.13.1 lib/spandx/js/parsers/npm.rb
spandx-0.13.0 lib/spandx/js/parsers/npm.rb
spandx-0.12.3 lib/spandx/js/parsers/npm.rb
spandx-0.12.2 lib/spandx/js/parsers/npm.rb
spandx-0.12.1 lib/spandx/js/parsers/npm.rb
spandx-0.12.0 lib/spandx/js/parsers/npm.rb