npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

license-lookup

v0.0.20

Published

Lightweight Package License Detector designed to run without access to the entire filesystem

Downloads

29

Readme

License Lookup

Lightweight package dependency License detector designed to run without access to the entire filesystem.

Given a list of files (such as files in a git commit) it can detect which checkers to run against select files.

Given the string contents of a package manager file the library can detect dependencies in the file and optionally attempt to lookup the license of the detected dependency.

Using the library locally

const LicenseLookup = require("license-lookup")

//File listing to match with the available license resolvers
const files = fs.readdirSync("/path");

var ll = new LicenseLookup();
var matches = ll.matchFilesToManager(files);

//each match has a filepath and the matched manager
for(const match of matches){
  var content = fs.readFileSync(match.file, "utf8");
  var detectedDependencies = await match.manager.detect(content);
  
  for(var dep of detectedDependencies){
     console.log(`Name: ${dep.name}, Found: ${dep.found}, Url: ${dep.url}, License: ${dep.license}`);
  }
}

Using with github api

As the library was designed to work with only having api access to files and the content, you can use it with octokit to check the contents of a pull request on GitHub:

const Octokit = require('@octokit/rest')
const LicenseLookup = require("license-lookup")

const octokit = new Octokit ()


//File listing from a PR
const files = await octokit.pullRequests.listFiles({repo, owner, number});

var ll = new LicenseLookup();
var matches = ll.matchFilesToManager(files);

//each match has a filepath and the matched manager
for(const match of matches){
  //compare base and head
  var base = await octokit.repos.getContents( {repo, owner, path: match.file,});
  var head = await octokit.repos.getContents( {repo, owner, path: match.file, ref: ref})
      
  const base_content = Buffer.from(base.data.content, 'base64').toString()
  const head_content = Buffer.from(head.data.content, 'base64').toString()

  var base_deps = await match.manager.detect(base_content);
  var head_deps = await match.manager.detect(head_content);
  
  var baseDepsKeys = base_deps.map(x => x.name);
  var new_deps = head_deps.filter( x => baseDepsKeys.indexOf(x.name)<0 );
  var detectedDependencies = await match.manager.lookup(new_deps);
  
  // list new dependencies introduced in PR
  for(var dep of detectedDependencies){
     console.log(`Name: ${dep.name}, Found: ${dep.found}, Url: ${dep.url}, License: ${dep.license}`);
  }
}

Todo

  • [x] Add npm support
  • [x] Add pipfile support
  • [x] Add requirements.txt support
  • [x] Add SBT support
  • [x] Add maven support
  • [x] Add gradle support
  • [x] Add pom.xml support
  • [x] Add Gemfile support
  • [x] Add Poetry support
  • [ ] Add Go Dep support
  • [ ] Add yarn support

Developing

This library is written in typescript and uses jest for testing.

Git clone and run:

npm install
npm run-script build
npm t