cache-walk
Walk a require tree for a cached module.
Installation
npm install --save cache-walk
Summary
Requiring one file typically adds more than one file to the require cache, since that file (probably) requires other files, which potentially require other files. This module let's you walk through the entire require tree of a particular module as it is in the cache.
Usage
cache-walk
exports three functions for interacting with a require tree: .get
, .walk
, and .delete
. .get
returns a list of module ids (absolute file paths), .walk
calls a function for each module encountered, and .delete
deletes an entire require tree from the cache.
.get
var foo = require('./foo');
var cache = require('cache-walk');
var requiredModules = cache.get('./foo');
.walk
var foo = require('./foo');
var cache = require('cache-walk');
cache.walk('./foo', function(mod) {
console.log(mod);
});
.delete
var foo = require('./foo');
var cache = require('cache-walk');
cache.delete('./foo');
These examples use relative paths, but absolute ones work as well.
Contributing
Please see the contribution guidelines.