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.7 to 0.0.9

7

github.js

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

'license',
'licence',
'readme',

@@ -38,3 +39,3 @@ ].concat([

].reduce(function flatten(slim, extension) {
slim.push('license.'+ extension, 'readme.'+ extension);
slim.push('license.'+ extension, 'readme.'+ extension, 'licence.'+ extension);
return slim;

@@ -92,2 +93,6 @@ }, [])),

});
}).sort(function sort(a, b) {
if (a.name > b.name) return 1;
if (b.name < b.name) return -1;
return 0;
});

@@ -94,0 +99,0 @@

59

index.js
'use strict';
var debug = require('debug')('licenses::parse')
, request = require('request')
, Registry = require('npm.js')
, async = require('async')

@@ -9,3 +9,12 @@ , url = require('url');

/**
* @param {String} name The module name or the package.json contents.
* Start searching for license information for the given module name.
*
* Options:
*
* - githulk: A pre-configured githulk instance.
* - order: The order of resolving license information.
* - npmjs: A pre-configured npm.js instance.
* - registry: A registry to use for the npmjs instance.
*
* @param {Mixed} name The module name or the package.json contents.
* @param {Object} options Configuration of the parse process.

@@ -22,5 +31,9 @@ * @param {Function} fn Callback.

options = options || {};
options.registry = options.registry || 'http://registry.nodejitsu.com';
options.order = options.order || ['registry', 'content', 'github'];
options.githulk = options.githulk || null;
options.order = options.order || ['registry', 'github', 'content'];
options.registry = options.registy || Registry.mirrors.nodejitsu;
options.npmjs = options.npmjs || new Registry({
registry: options.registry,
githulk: options.githulk
});

@@ -35,33 +48,3 @@ async.waterfall([

debug('was given a string, retreiving package from npm : %s', options.registry);
request({
uri: url.resolve(options.registry, name),
method: 'GET',
json: true
}, function fetched(err, res, data) {
if (err) return next(err);
if (res.statusCode !== 200) return next(new Error('Invalid statusCode: '+ res.statusCode));
//
// With npm you can never be sure of the data structure. We want to get
// the latest package from the data structure so we need double, triple
// checks.
//
if (
'object' === typeof data
&& 'dist-tags' in data
&& 'object' === typeof data.versions
&& 'latest' in data['dist-tags']
&& data['dist-tags'].latest in data.versions
) {
var readme = data.readme;
data = data.versions[data['dist-tags'].latest];
data.readme = data.readme || readme;
debug('found "dist-tags" updating data to latest version');
}
next(err, data);
});
options.npmjs.packages.get(name, next);
},

@@ -74,3 +57,6 @@

if (!options.order.length) return next();
if (Array.isArray(data)) data = data[0];
debug('searching for licensing information for %s', data.name);
var parser, result, name;

@@ -96,3 +82,4 @@

return !result && options.order.length;
}, function done(err) {
}, function cleanup(err) {
options = null;
next(err, result, name);

@@ -99,0 +86,0 @@ });

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

@@ -24,3 +24,3 @@ "main": "index.js",

"githulk": "0.0.x",
"request": "2.33.x"
"npm.js": "0.0.x"
},

@@ -27,0 +27,0 @@ "devDependencies": {

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

Parser.readable('async', require('async'));
Parser.readable('request', require('request'));

@@ -35,0 +34,0 @@ /**

@@ -50,2 +50,4 @@ 'use strict';

/**
* Return the possible location of license information.
*
* @param {Object} data The object that should contain the license.

@@ -52,0 +54,0 @@ * @returns {String}

@@ -7,5 +7,9 @@ describe('Parser', function () {

var Parser = require('../').Parser
var licenses = require('../')
, Parser = licenses.Parser
, parser = new Parser();
var Registry = require('npm.js')
, npmjs = new Registry({ registry: Registry.mirrors.npmjs });
it('exposes the `async` module', function () {

@@ -15,6 +19,2 @@ expect(parser.async).to.equal(require('async'));

it('exposes the `request` module', function () {
expect(parser.request).to.equal(require('request'));
});
describe('#test', function () {

@@ -111,2 +111,35 @@ it('provides basic checks of license fragments');

});
describe('actual detection', function () {
//
// Bump the timeout limit for these tests as we need to resolve a lot of
// information and API endpoints in order to get accurate information.
//
this.timeout(20000);
it('detects multiple licenses for metawidget', function (next) {
licenses('metawidget', { npmjs: npmjs }, function resolved(err, licenses) {
if (err) return next(err);
expect(licenses.length).to.equal(3);
expect(licenses).to.include('LGPL');
expect(licenses).to.include('EPL');
expect(licenses).to.include('Commercial');
next();
});
});
it('detects MIT for eventemitter3', function (next) {
licenses('eventemitter3', { npmjs: npmjs }, function resolved(err, licenses) {
if (err) return next(err);
expect(licenses.length).to.equal(1);
expect(licenses).to.include('MIT');
next();
});
});
});
});

Sorry, the diff of this file is not supported yet

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