UNPKG

@acromedia/sloth

Version:

Resource profiler for node, utilizing child processes

32 lines (31 loc) 1.13 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const fs_1 = __importDefault(require("fs")); const bench_1 = __importDefault(require("./bench")); /** * This function is just a bit of a shortcut to bench(). * * It bascially just keeps you from having to fork the file for yourself * and create a manual profiler. * * @param {String} path * @param {Array=} nodeOpts * @param {Array=} cliOpts */ exports.default = async (path, nodeArgs = [], cliArgs = []) => { let fullPath = path; // If our path isn't absolute, we will make it absolute using the CWD if (!path.startsWith('/')) { fullPath = `${process.cwd()}/${path}`; } const content = fs_1.default.readFileSync(fullPath).toString(); // Wrap entire thing into a JS function, then pass it to `bench()` // eslint-disable-next-line @typescript-eslint/no-implied-eval return (0, bench_1.default)(Function(content), [], { nodeArgs, cliArgs, }); };