Comparing version 0.4.1 to 0.4.2
50
index.js
@@ -8,18 +8,23 @@ var fs = require("fs"); | ||
var minimatch = require('minimatch'); | ||
var util = require('util'); | ||
function getModulesRequiredFromFilename(filename) { | ||
var content = fs.readFileSync(filename, "utf-8"); | ||
return detective(content, { | ||
word: '', | ||
isRequire: function(node) { | ||
var callee = node.callee; | ||
return callee && | ||
( | ||
(node.type === 'CallExpression' && callee.type === 'Identifier' | ||
&& callee.name === 'require') | ||
|| | ||
(callee.property && callee.property.name === 'loadNpmTasks') | ||
); | ||
} | ||
}); | ||
try { | ||
return detective(content, { | ||
word: '', | ||
isRequire: function(node) { | ||
var callee = node.callee; | ||
return callee && | ||
( | ||
(node.type === 'CallExpression' && callee.type === 'Identifier' | ||
&& callee.name === 'require') | ||
|| | ||
(callee.property && callee.property.name === 'loadNpmTasks') | ||
); | ||
} | ||
}); | ||
} catch (err) { | ||
return err; | ||
} | ||
} | ||
@@ -32,2 +37,3 @@ | ||
var finder = walkdir(dir, { "no_recurse": true }); | ||
var invalidFiles = {}; | ||
@@ -46,4 +52,8 @@ finder.on("directory", function (subdir) { | ||
var modulesRequired = getModulesRequiredFromFilename(filename); | ||
deps = deps.difference(modulesRequired); | ||
devDeps = devDeps.difference(modulesRequired); | ||
if (util.isError(modulesRequired)) { | ||
invalidFiles[filename] = modulesRequired; | ||
} else { | ||
deps = deps.difference(modulesRequired.valueOf()); | ||
devDeps = devDeps.difference(modulesRequired); | ||
} | ||
} | ||
@@ -57,2 +67,3 @@ }); | ||
if (result.state === 'fulfilled') { | ||
invalidFiles = _.merge(invalidFiles, result.value.invalidFiles, {}); | ||
deps = deps.intersection(result.value.dependencies); | ||
@@ -65,3 +76,5 @@ devDeps = devDeps.intersection(result.value.devDependencies); | ||
dependencies: deps.valueOf(), | ||
devDependencies: devDeps.valueOf()}; | ||
devDependencies: devDeps.valueOf(), | ||
invalidFiles: invalidFiles | ||
}; | ||
})); | ||
@@ -83,3 +96,4 @@ }); | ||
'.idea', | ||
'node_modules' | ||
'node_modules', | ||
'bower_components' | ||
]) | ||
@@ -115,2 +129,2 @@ .concat(options.ignoreDirs) | ||
module.exports = depCheck; | ||
module.exports = depCheck; |
{ | ||
"name": "depcheck", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"description": "Check dependencies in your node module", | ||
@@ -21,13 +21,12 @@ "main": "index", | ||
"detective": "^3.1.0", | ||
"esprima": "~1.0.4", | ||
"lodash": "^2.4.1", | ||
"minimatch": "^0.3.0", | ||
"minimatch": "^1.0.0", | ||
"optimist": "~0.6.0", | ||
"q": "^1.0.1", | ||
"walkdir": "0.0.7", | ||
"optimist": "~0.6.0" | ||
"walkdir": "0.0.7" | ||
}, | ||
"devDependencies": { | ||
"should": "~1.2.2", | ||
"mocha": "~1.8.1" | ||
"mocha": "^1.21.4", | ||
"should": "^4.0.4" | ||
} | ||
} |
@@ -50,2 +50,3 @@ # depcheck [![build status](https://secure.travis-ci.org/rumpl/depcheck.png)](http://travis-ci.org/rumpl/depcheck) | ||
console.log(unused.devDependencies); | ||
console.log(unused.invalidFiles); // JS files that couldn't be parsed | ||
}); | ||
@@ -52,0 +53,0 @@ ``` |
@@ -69,2 +69,12 @@ var assert = require("should"); | ||
it("should should ignore bad javascript", function testBadJS(done) { | ||
var absolutePath = path.resolve("test/fake_modules/bad_js"); | ||
depcheck(absolutePath, { }, function checked(unused) { | ||
assert.equal(unused.dependencies.length, 1); | ||
assert.deepEqual(Object.keys(unused.invalidFiles).length, 2); | ||
done(); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11685
6
24
184
67
+ Addedminimatch@1.0.0(transitive)
- Removedesprima@~1.0.4
- Removedminimatch@0.3.0(transitive)
Updatedminimatch@^1.0.0