Skip to content

Commit

Permalink
[bin] Added node-detective fallback on require errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
AvianFlu committed Sep 18, 2011
1 parent 4d51d89 commit 623cf13
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions bin/find-dependencies
Expand Up @@ -2,6 +2,8 @@

var Module = require('module').Module,
__load = Module._load,
detective = require('detective'),
fs = require('fs'),
packages = {};

//
Expand All @@ -26,17 +28,20 @@ catch (ex) {
// Log errors and attempt to log as many packages as we can.
//
var eStr = '' + (ex
? (ex.stack ? ex.stack : ex)
: 'falsey error: ' + ex);
? (ex.stack ? ex.stack : ex)
: 'falsey error: ' + ex),
notFound = /^Error: Cannot find module '(.*)'/.test(eStr);

//
// However, 'cannot find module' errors should be squashed.
// In cases with no node_modules present, this is not an indication of failure.
// This should perhaps be replaced with a node-detective fallback.
//

if (/^Error: Cannot find module '(.*)'/.exec(eStr)) {
console.log('__!load::' + $1);
if (notFound) {
detective(fs.readFileSync(process.argv[2])).forEach(function (dep) {
console.log('__!load::' + dep);
});
}
else {
eStr.split('\n').forEach(function (line) {
Expand Down

0 comments on commit 623cf13

Please sign in to comment.