New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

licenses

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

licenses - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

8

content.js

@@ -18,8 +18,14 @@ 'use strict';

* @param {Object} data The package.json or npm package contents.
* @param {Object} options Optional options.
* @param {Function} next Continuation.
* @api public
*/
parse: function parse(data, next) {
parse: function parse(data, options, next) {
data = this.get(data);
if ('function' === typeof options) {
next = options;
options = {};
}
//

@@ -26,0 +32,0 @@ // We cannot detect a license so we call the callback without any arguments

152

github.js

@@ -45,8 +45,14 @@ 'use strict';

* @param {Object} data The package.json or npm package contents.
* @param {Object} options Optional options.
* @param {Function} next Continuation.
* @api public
*/
parse: function parse(data, next) {
parse: function parse(data, options, next) {
data = this.get(data);
if ('function' === typeof options) {
next = options;
options = {};
}
//

@@ -58,13 +64,39 @@ // We cannot detect a license so we call the callback without any arguments

var parser = this;
var githulk = options.githulk || this.githulk
, project = data.user +'/'+ data.repo
, parser = this;
this.exists(data, function exists(err, github) {
if (err || !github) return next(err);
githulk.repository.moved(project, function moved(err, github, changed) {
if (err) return next(err);
if (changed) project = github.user +'/'+ github.repo;
var license;
parser.root(github, function root(err, files) {
githulk.repository.contents(project, function contents(err, files) {
if (err || !files || !files.length) return next(err);
//
// Check if we have any compatible.
//
files = files.filter(function filter(file) {
var name = file.name.toLowerCase();
// No size, not really useful for matching.
if (file.size <= 0) return false;
// Fast case, direct match.
if (!!~parser.filenames.indexOf(name)) return true;
// Slow case, partial match.
return parser.filenames.some(function some(filename) {
return !!~name.indexOf(filename);
});
});
if (!files.length) return next();
//
// Stored the matching license.
//
var license;
//
// Fetch and parse the 'raw' content of the file so we can parse it.

@@ -77,7 +109,9 @@ //

parser.raw(github, file.name, function raw(err, data) {
githulk.repository.raw(project, {
path: file.name
}, function raw(err, data) {
if (err) return next(err);
parser.parsers.content.parse({
content: data,
content: Array.isArray(data) ? data[0] : data,
file: file.name

@@ -101,98 +135,2 @@ }, function parse(err, data) {

/**
* Get the raw data from github.
*
* @param {Object} github The parsed repository information.
* @param {String} file The file name.
* @param {Function} next Continuation.
* @api private
*/
raw: function raw(github, file, next) {
this.request({
uri: 'https://raw.github.com/'+ github.user +'/'+ github.repo +'/master/'+ file,
method: 'GET'
}, function fetched(err, res, body) {
if (err || res.statusCode === 404) return next(err);
if (res.statusCode !== 200) return next(new Error('Invalid status code (raw:'+ res.statusCode +')'));
next(undefined, body);
});
},
/**
* Get the root directory from github and try to search for files that matches
* our supported license files.
*
* @param {Object} github The parsed repository information.
* @param {Function} next Continuation.
* @api private
*/
root: function root(github, next) {
var url = 'https://api.github.com/repos/'+ github.user +'/'+ github.repo +'/contents'
, parser = this;
debug('retrieving file list from %s', url);
this.request({
uri: url,
method: 'GET',
headers: {
'User-Agent': 'npm.im/licenses'
},
json: true
}, function fetched(err, res, files) {
if (err || res.statusCode === 404) return next(err);
if (res.statusCode !== 200) return next(new Error('Invalid status code (root:'+ res.statusCode +')'));
//
// Check if we have any compatible.
//
files = files.filter(function filter(file) {
var name = file.name.toLowerCase();
// No size, not really useful for matching.
if (file.size <= 0) return false;
// Fast case, direct match.
if (!!~parser.filenames.indexOf(name)) return true;
// Slow case, partial match.
return parser.filenames.some(function some(filename) {
return !!~name.indexOf(filename);
});
});
if (!files.length) return next();
return next(undefined, files);
});
},
/**
* It's possible that a user has moved the repository to a new location.
* Github automatically redirects you when you access the old page. But it
* doesn't provide any redirection for API calls causing them to fail with
* 404's.
*
* In order to detect the correct repository location we need to do a HEAD
* check of the public github URL and use the location header as source URL
* when we're presented with a 301 status code.
*
*
* @param {String} url The possible location of the repository.
* @param {Function} next Continuation
* @api private
*/
exists: function exists(github, next) {
var parser = this;
this.request({
uri: 'https://github.com/'+ github.user +'/'+ github.repo,
method: 'HEAD'
}, function fetched(err, res, data) {
if (err) return next(err);
next(undefined, parser.get(res.request.href) || github);
});
},
/**
* Is github based license detection an option for this package.

@@ -216,3 +154,5 @@ *

*/
get: require('extract-github')
get: function get() {
return this.githulk.project.apply(this, arguments);
}
});

@@ -23,2 +23,3 @@ 'use strict';

options.order = options.order || ['registry', 'content', 'github'];
options.githulk = options.githulk || null;

@@ -25,0 +26,0 @@ async.waterfall([

{
"name": "licenses",
"version": "0.0.5",
"version": "0.0.6",
"description": "A small tool that detects licensing information for a given Node.js module",

@@ -22,4 +22,4 @@ "main": "index.js",

"debug": "0.7.x",
"extract-github": "0.0.x",
"fusing": "0.0.x",
"githulk": "0.0.x",
"request": "2.33.x"

@@ -26,0 +26,0 @@ },

@@ -5,2 +5,3 @@ 'use strict';

, normalized = require('./normalize')
, GitHulk = require('githulk')
, fuse = require('fusing')

@@ -100,3 +101,13 @@ , fs = require('fs');

var githulk = new GitHulk();
/**
* Reference to our githulk.
*
* @type {GitHulk}
* @api public
*/
Parser.readable('githulk', githulk);
/**
* Find an URL in the data structure.

@@ -108,3 +119,3 @@ *

*/
Parser.readable('url', require('extract-github').url);
Parser.readable('url', githulk.project.url);

@@ -111,0 +122,0 @@ /**

@@ -24,8 +24,14 @@ 'use strict';

* @param {Object} data The package.json or npm package contents.
* @param {Object} options Optional options.
* @param {Function} next Continuation.
* @api public
*/
parse: function parse(data, next) {
parse: function parse(data, options, next) {
data = this.get(data);
if ('function' === typeof options) {
next = options;
options = {};
}
//

@@ -32,0 +38,0 @@ // We cannot detect a license so we call the callback without any arguments

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc