Browse files

added analyzer.findNextDir function

the last change broke most tests, so .findNextDir is what's actually
wanted for .npmAnalyze
  • Loading branch information...
1 parent 49b2d44 commit 16f22f9059485db65a28739c9adb2460d4c8be62 @fb55 fb55 committed Sep 8, 2012
Showing with 31 additions and 20 deletions.
  1. +31 −20 lib/require-analyzer.js
View
51 lib/require-analyzer.js
@@ -120,7 +120,7 @@ analyzer.npmAnalyze = function (deps, options, callback) {
return callback();
}
- analyzer.findModulesDir(options.target, function (err, root) {
+ analyzer.findNextDir(options.target, function (err, root) {
if (err) {
return callback(err);
}
@@ -562,31 +562,17 @@ analyzer.file = function(options, callback){
};
//
-// ### function findModulesDir (target)
-// #### @target {string} The directory (or file) to search up from
-// Searches up from the specified `target` until it finds a directory which contains
-// a folder called `node_modules`
+// ### function findNextDir (target)
+// #### @target {string} The path to search up from
+// Searches up from the specified `target` until it finds a directory
//
-analyzer.findModulesDir = function (target, callback) {
+analyzer.findNextDir = function(target, callback) {
fs.stat(target, function (err, stats) {
if (err) {
callback(err);
}
else if (stats.isDirectory()) {
- fs.readdir(target, function (err, files) {
- if (err) {
- callback(err);
- }
- else if (files.indexOf('node_modules') !== -1 || files.indexOf('package.json') !== -1) {
- callback(null, target);
- }
- else if (target === (target = path.dirname(target))){
- callback(new Error('Couldn\'t find a node_modules directory.'));
- }
- else {
- analyzer.findModulesDir(target, callback);
- }
- });
+ callback(null, target);
}
else if (stats.isFile()) {
analyzer.findModulesDir(path.dirname(target), callback);
@@ -598,6 +584,31 @@ analyzer.findModulesDir = function (target, callback) {
};
//
+// ### function findModulesDir (target)
+// #### @target {string} The directory (or file) to search up from
+// Searches up from the specified `target` until it finds a directory which contains
+// a folder called `node_modules`
+//
+analyzer.findModulesDir = function (target, callback) {
+ analyzer.findNextDir(target, function(err, dir){
+ fs.readdir(target, function (err, files) {
+ if (err) {
+ callback(err);
+ }
+ else if (files.indexOf('node_modules') !== -1 || files.indexOf('package.json') !== -1) {
+ callback(null, target);
+ }
+ else if (target === (target = path.dirname(target))){
+ callback(new Error('Couldn\'t find a node_modules directory.'));
+ }
+ else {
+ analyzer.findModulesDir(target, callback);
+ }
+ });
+ });
+};
+
+//
// ### function (target [arg1, arg2, ...])
// #### @target {Object} Object to merge into
// Merges all properties in `arg1 ... argn`

0 comments on commit 16f22f9

Please sign in to comment.