Skip to content

Instantly share code, notes, and snippets.

@zaach
Created July 24, 2011 02:05
Show Gist options
  • Save zaach/1102109 to your computer and use it in GitHub Desktop.
Save zaach/1102109 to your computer and use it in GitHub Desktop.
Finds the names of all modules required in the file.
var JSONSelect = require("JSONSelect");
var Reflect = require("reflect");
var ast = Reflect.parse(read(__filename));
var required = JSONSelect.match('.callee:has(:root > .name:val("require")) ~ .arguments :first-child .value', ast);
// ["JSONSelect", "reflect", "fs", "path"]
function read (path) {
return require("fs").readFileSync(require("path").resolve(path), "utf8");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment