neovim
Version:
Nvim msgpack API client and remote plugin provider
71 lines (70 loc) • 2.8 kB
JavaScript
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadPlugin = loadPlugin;
const path = __importStar(require("node:path"));
const Module = require("module");
const NvimPlugin_1 = require("./NvimPlugin");
// inspiration drawn from Module
function createPlugin(filename, nvim, options = {}) {
try {
nvim.logger.debug(`createPlugin.${filename}.clearCache: ${options && !options.cache}`);
// Clear module from cache
if (options && !options.cache) {
try {
// `as any` to access hidden API
delete Module._cache[require.resolve(filename)];
}
catch (err) {
// possible this doesn't exist in cache, ignore
}
}
// attempt to import plugin
// Require plugin to export a class
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires, import/no-dynamic-require
const defaultImport = require(filename);
const plugin = (defaultImport && defaultImport.default) || defaultImport;
if (typeof plugin === 'function') {
return new NvimPlugin_1.NvimPlugin(filename, plugin, nvim);
}
}
catch (e) {
const err = e;
const file = path.basename(filename);
nvim.logger.error(`[${file}] ${err.stack}`);
nvim.logger.error(`[${file}] Error loading child ChildPlugin ${filename}`);
}
// There may have been an error, but maybe not
return null;
}
function loadPlugin(filename, nvim, options = {}) {
try {
return createPlugin(filename, nvim, options);
}
catch (err) {
// logger.error(`Could not load plugin "${filename}":`, err, err.stack);
return null;
}
}
;