UNPKG

aki-plugin-manager

Version:

Lightweight at-runtime plugin manager and loader

15 lines (14 loc) 590 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.load = void 0; const fs_1 = require("fs"); const path_1 = require("path"); // eslint-disable-next-line @typescript-eslint/no-explicit-any const load = (baseDir, name, requireFn = require) => { const pluginDir = path_1.join(baseDir, name); const packageFile = path_1.join(pluginDir, 'package.json'); const { main } = JSON.parse(fs_1.readFileSync(packageFile, 'utf-8')); const mainPath = path_1.resolve(pluginDir, main || 'index.js'); return requireFn(mainPath); }; exports.load = load;