Sha256: 89a022803d87ac66c47e67d14b8923fa1bd6f2486c5176eaf6eb00755303cda5

Contents?: true

Size: 892 Bytes

Versions: 11

Compression:

Stored size: 892 Bytes

Contents

# frozen_string_literal: true

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

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

        private

        def each_metadata(path)
          package_lock = Oj.load(path.read)
          package_lock['dependencies'].each do |name, metadata|
            yield metadata.merge('name' => name)
          end
        end

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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
spandx-0.18.3 lib/spandx/js/parsers/npm.rb
spandx-0.18.2 lib/spandx/js/parsers/npm.rb
spandx-0.18.1 lib/spandx/js/parsers/npm.rb
spandx-0.18.0 lib/spandx/js/parsers/npm.rb
spandx-0.17.0 lib/spandx/js/parsers/npm.rb
spandx-0.16.1 lib/spandx/js/parsers/npm.rb
spandx-0.16.0 lib/spandx/js/parsers/npm.rb
spandx-0.15.1 lib/spandx/js/parsers/npm.rb
spandx-0.15.0 lib/spandx/js/parsers/npm.rb
spandx-0.14.0 lib/spandx/js/parsers/npm.rb
spandx-0.13.5 lib/spandx/js/parsers/npm.rb