From 623cf13aa97c6d0e039b1ae9461442f3fb7f2063 Mon Sep 17 00:00:00 2001 From: Charlie McConnell Date: Sun, 18 Sep 2011 10:42:58 -0700 Subject: [PATCH] [bin] Added node-detective fallback on require errors. --- bin/find-dependencies | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/bin/find-dependencies b/bin/find-dependencies index 2b18756..4704bb4 100644 --- a/bin/find-dependencies +++ b/bin/find-dependencies @@ -2,6 +2,8 @@ var Module = require('module').Module, __load = Module._load, + detective = require('detective'), + fs = require('fs'), packages = {}; // @@ -26,8 +28,9 @@ 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. @@ -35,8 +38,10 @@ catch (ex) { // 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) {