Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

depcheck

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

depcheck - npm Package Compare versions

Comparing version 0.4.1 to 0.4.2

test/fake_modules/bad_js/deeper/also_bad_js.js

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();
});
});
});
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