@aikidosec/firewall
Version:
Zen by Aikido is an embedded Web Application Firewall that autonomously protects Node.js apps against common and critical attacks
19 lines (18 loc) • 810 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isAnyPkgAlreadyRequired = isAnyPkgAlreadyRequired;
const getModuleInfoFromPath_1 = require("../agent/hooks/getModuleInfoFromPath");
/**
* Checks if any passed package was already required in the current process.
*/
function isAnyPkgAlreadyRequired(supportedPkgs) {
const supportedPkgNames = supportedPkgs.map((pkg) => pkg.getName());
const alreadyRequiredModuleFiles = Object.keys(require.cache).filter((pkg) => pkg.includes("node_modules"));
for (const file of alreadyRequiredModuleFiles) {
const moduleInfo = (0, getModuleInfoFromPath_1.getModuleInfoFromPath)(file);
if (moduleInfo && supportedPkgNames.includes(moduleInfo.name)) {
return true;
}
}
return false;
}