You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
897 B
39 lines
897 B
'use strict';
|
|
|
|
function guid() {
|
|
function s4() {
|
|
return Math.floor((1 + Math.random()) * 0x10000)
|
|
.toString(16)
|
|
.substring(1);
|
|
}
|
|
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
|
|
}
|
|
|
|
function purgeCache(moduleName) {
|
|
searchCache(moduleName, function (mod) {
|
|
delete require.cache[mod.id];
|
|
});
|
|
Object.keys(module.constructor._pathCache).forEach(function(cacheKey) {
|
|
if (cacheKey.indexOf(moduleName)>0) {
|
|
delete module.constructor._pathCache[cacheKey];
|
|
}
|
|
});
|
|
}
|
|
|
|
function searchCache(moduleName, callback) {
|
|
var mod = require.resolve(moduleName);
|
|
if (mod && ((mod = require.cache[mod]) !== undefined)) {
|
|
(function traverse(mod) {
|
|
mod.children.forEach(function (child) {
|
|
traverse(child);
|
|
});
|
|
callback(mod);
|
|
}(mod));
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
guid,
|
|
purgeCache,
|
|
searchCache,
|
|
};
|
|
|