Sha256: c6acc02105cba4088e8730c000756fe538ea7605407350207bed8adffb6304b7
Contents?: true
Size: 1.77 KB
Versions: 7
Compression:
Stored size: 1.77 KB
Contents
require 'json' module Bibliothecary module Parsers class NPM include Bibliothecary::Analyser def self.mapping { /^(?!node_modules).*package\.json$/ => { kind: 'manifest', parser: :parse_manifest }, /^(?!node_modules).*npm-shrinkwrap\.json$/ => { kind: 'lockfile', parser: :parse_shrinkwrap }, /^(?!node_modules).*yarn\.lock$/ => { kind: 'lockfile', parser: :parse_yarn_lock }, /^(?!node_modules).*package-lock\.json$/ => { kind: 'lockfile', parser: :parse_package_lock } } end def self.parse_shrinkwrap(file_contents) manifest = JSON.parse(file_contents) manifest.fetch('dependencies',[]).map do |name, requirement| { name: name, requirement: requirement["version"], type: 'runtime' } end end def self.parse_package_lock(file_contents) manifest = JSON.parse(file_contents) manifest.fetch('dependencies',[]).map do |name, requirement| { name: name, requirement: requirement["version"], type: 'runtime' } end end def self.parse_manifest(file_contents) manifest = JSON.parse(file_contents) map_dependencies(manifest, 'dependencies', 'runtime') + map_dependencies(manifest, 'devDependencies', 'development') end def self.parse_yarn_lock(file_contents) response = Typhoeus.post("https://yarn-parser.libraries.io/parse", body: file_contents) return [] unless response.response_code == 200 JSON.parse(response.body) end end end end
Version data entries
7 entries across 7 versions & 1 rubygems