You've already forked serverless-webpack
mirror of
https://github.com/encounter/serverless-webpack.git
synced 2026-03-30 11:37:58 -07:00
97d5adf963
* Add Travis configuration and fixed ESLint issues * Enabled ESLint and coverage checkboxes * Added coverage and build badges
42 lines
929 B
JavaScript
42 lines
929 B
JavaScript
'use strict';
|
|
|
|
const _ = require('lodash');
|
|
|
|
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];
|
|
});
|
|
_.forEach(_.keys(module.constructor._pathCache), function(cacheKey) {
|
|
if (cacheKey.indexOf(moduleName)>0) {
|
|
delete module.constructor._pathCache[cacheKey];
|
|
}
|
|
});
|
|
}
|
|
|
|
function searchCache(moduleName, callback) {
|
|
let mod = require.resolve(moduleName);
|
|
if (mod && ((mod = require.cache[mod]) !== undefined)) {
|
|
(function traverse(mod) {
|
|
_.forEach(mod.children, function (child) {
|
|
traverse(child);
|
|
});
|
|
callback(mod);
|
|
}(mod));
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
guid,
|
|
purgeCache,
|
|
searchCache,
|
|
};
|