Created
July 24, 2011 02:05
-
-
Save zaach/1102109 to your computer and use it in GitHub Desktop.
Finds the names of all modules required in the file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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