Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

51 lines (45 sloc) 1.299 kb
#!/usr/bin/env node
var Module = require('module').Module,
__load = Module._load,
detective = require('detective'),
fs = require('fs'),
packages = {};
//
// Monkey punch `Module._load()` to observe the names
// of packages as they are loaded.
//
Module._load = function (name, parent) {
console.log('__!load::' + name);
name = /^[./]/.test(name) ? Module._resolveFilename(name, parent)[1] : name;
return __load.apply(Module, arguments);
}
try {
process.nextTick(function () {
process.exit(0);
});
Module._load(process.argv[2], null, true);
}
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),
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 (notFound) {
detective(fs.readFileSync(process.argv[2])).forEach(function (dep) {
console.log('__!load::' + dep);
});
}
else {
eStr.split('\n').forEach(function (line) {
console.error('__!err::' + line);
});
}
}
Jump to Line
Something went wrong with that request. Please try again.