Skip to content

Commit

Permalink
Updated to newer read-installed
Browse files Browse the repository at this point in the history
Fixed issue with undefined check, fixes #18, #19, #20
  • Loading branch information
davglass committed Nov 20, 2014
1 parent 807507d commit 76c71ac
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
17 changes: 8 additions & 9 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ http://yuilibrary.com/license/
*/

var UNKNOWN = 'UNKNOWN';
var data = {};
var fs = require('fs');
var path = require('path');
var read = require('read-installed');
var treeify = require('treeify');
var license = require('./license');

var flatten = function(json) {
var flatten = function(json, data) {
var moduleInfo = {licenses: UNKNOWN},
licenseData, files, licenseFile;

Expand Down Expand Up @@ -76,22 +75,22 @@ var flatten = function(json) {
if (data[dependencyId]) { // already exists
return;
}
flatten(childDependency);
data = flatten(childDependency, data);
});
}
return data;
};

exports.init = function(options, callback) {

console.log('scanning' , options.start);

read(options.start, function(err, json) {
flatten(json);
var sorted = {};
read(options.start, { dev: true }, function(err, json) {
var data = flatten(json, {}),
sorted = {};
Object.keys(data).sort().forEach(function(item) {
if (options.unknown) {
if (data[item].licenses !== UNKNOWN) {
if (data[item].licenses.indexOf('*') === -1) {
if (data[item].licenses && data[item].licenses !== UNKNOWN) {
if (data[item].licenses.indexOf('*') > -1) {
delete data[item];
}
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"version": "0.0.10",
"dependencies": {
"mkdirp": "^0.3.5",
"treeify": "^1.0.1",
"nopt": "^2.2.0",
"read-installed": "^1.0.0"
"read-installed": "~3.1.3",
"treeify": "^1.0.1"
},
"devDependencies": {
"yui-lint": "~0.1.1",
Expand Down
4 changes: 3 additions & 1 deletion tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ var tests = {
});
},
'and give us results': function (d) {
assert.equal(d['vows@0.7.0'].licenses, 'BSD*');
assert.ok(d);
assert.ok(d['vows@0.8.0'], 'failed to lookup vows dep');
assert.equal(d['vows@0.8.0'].licenses, 'MIT');
assert.isTrue(Object.keys(d).length > 20);
}
}
Expand Down

0 comments on commit 76c71ac

Please sign in to comment.