UNPKG

@aikidosec/firewall

Version:

Zen by Aikido is an embedded Application Firewall that autonomously protects Node.js apps against common and critical attacks, provides rate limiting, detects malicious traffic (including bots), and more.

24 lines (23 loc) 754 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getPackageVersionFromPath = getPackageVersionFromPath; const fs_1 = require("fs"); const cache = new Map(); /** * Get the installed version of a package */ function getPackageVersionFromPath(basePath) { // This function is called for every file of an imported package, so we cache the result if (cache.has(basePath)) { return cache.get(basePath); } try { const version = JSON.parse((0, fs_1.readFileSync)(`${basePath}/package.json`, "utf8")).version; cache.set(basePath, version); return version; } catch { // Return undefined if the package is not found cache.set(basePath, undefined); } }