Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

always return an object in npmAnalyze

also moved the creation of the find-dependencies path to the
surrounding scope
  • Loading branch information...
commit 7ede4628e5310412e1b2b3425ce4d9aeb4d352c6 1 parent 48a34e0
@fb55 fb55 authored
Showing with 18 additions and 5 deletions.
  1. +18 −5 lib/require-analyzer.js
View
23 lib/require-analyzer.js
@@ -136,7 +136,15 @@ analyzer.npmAnalyze = function (deps, options, callback) {
}
else if (!result || !result.dependencies || Object.keys(result.dependencies).length === 0) {
// When no dependencies were found, return what we got
- return callback(null, deps);
+ if(Array.isArray(deps)){
+ return callback(null, deps.reduce(function(obj, prop){
+ obj[prop] = "*";
+ return obj;
+ }, {}));
+ }
+ else {
+ return callback(null, deps);
+ }
}
Object.keys(result.dependencies).forEach(function (pkg) {
@@ -463,6 +471,8 @@ function analyzeFile (options, callback) {
});
}
+var findDepsPath = path.join(__dirname, '..', 'bin', 'find-dependencies');
+
function spawnWorker (options, callback) {
//
// Spawn the `find-dependencies` bin helper to ensure that we are able to
@@ -470,7 +480,7 @@ function spawnWorker (options, callback) {
//
var packages = options.packages,
errs = options.errors,
- deps = fork(path.join(__dirname, '..', 'bin', 'find-dependencies'), [options.target], {silent: true});
+ deps = fork(findDepsPath, [options.target], {silent: true});
deps.send(options.target);
@@ -503,7 +513,6 @@ function spawnWorker (options, callback) {
// Remove the timeout now that we have exited.
//
clearTimeout(timeoutId);
-
callback();
});
}
@@ -518,8 +527,9 @@ function spawnWorker (options, callback) {
//
analyzer.file = function(options, callback){
- options.packages = options.packages || {};
- options.errors = options.errors || [];
+ if(!options.packages) options.packages = {};
+ if(!options.errors) options.errors = [];
+
analyzeFile(options, function(err){
if(options.errors.length > 0){
callback(options.errors); //TODO call with real error object
@@ -581,6 +591,9 @@ analyzer.findModulesDir = function (target, callback) {
else if (stats.isFile()) {
analyzer.findModulesDir(path.dirname(target), callback);
}
+ else {
+ callback(new Error(target + ' is not a file or a directory.'));
+ }
});
};
Please sign in to comment.
Something went wrong with that request. Please try again.