Sha256: bf1683f4d46b6312f11f92c5359834557d374700ce3d09d99647d3b43d933a8e

Contents?: true

Size: 1.1 KB

Versions: 6

Compression:

Stored size: 1.1 KB

Contents

require 'json'

module Papers
  class NpmPackage < DependencySpecification
    def self.introspected
      full_introspected_entries.map {|e| "#{e['name']}-#{e['version']}"}
    end

    def self.full_introspected_entries
      packages = (package['dependencies'] || {})
      packages.merge!((package['devDependencies'] || {})) unless Papers.config.ignore_npm_dev_dependencies
      packages.map do |name, version|
        # FIXME: This version cleanup is inadequate for npm version specifiers, which may be git or
        # tarball URLs.
        version.sub!(/^\D+/, '')
        {
          'name' => name,
          'version' => version
        }
      end
    end

    def pretty_hash
      {
        name: name_without_version,
        license: license,
        license_url: @license_url,
        project_url: @project_url
      }
    end

    def self.asset_type_name
      'npm package'
    end

    def self.manifest_key
      "npm_packages"
    end

    private

    def self.package
      pkg = File.read(Papers.config.npm_package_json_path)
      JSON.parse(pkg)
    rescue Errno::ENOENT
      {}
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
papers-2.4.4 lib/papers/dependency_specification/npm_package.rb
papers-2.4.3 lib/papers/dependency_specification/npm_package.rb
papers-2.4.2 lib/papers/dependency_specification/npm_package.rb
papers-2.4.1 lib/papers/dependency_specification/npm_package.rb
papers-2.4.0 lib/papers/dependency_specification/npm_package.rb
papers-2.3.0 lib/papers/dependency_specification/npm_package.rb