Spaces:
Sleeping
Sleeping
File size: 1,339 Bytes
b0543db | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | "use strict";
exports.__esModule = true;
exports.getPlugins = getPlugins;
exports.resolvePlugin = resolvePlugin;
exports.loadPlugin = loadPlugin;
var _pluginJsx = _interopRequireDefault(require("@svgr/plugin-jsx"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const DEFAULT_PLUGINS = [_pluginJsx.default];
function getPlugins(config, state) {
if (config.plugins) {
return config.plugins;
}
if (state.caller && state.caller.defaultPlugins) {
return state.caller.defaultPlugins;
}
return DEFAULT_PLUGINS;
}
function resolvePlugin(plugin) {
if (typeof plugin === 'function') {
return plugin;
}
if (typeof plugin === 'string') {
return loadPlugin(plugin);
}
throw new Error(`Invalid plugin "${plugin}"`);
}
const pluginCache = {};
function loadPlugin(moduleName) {
if (pluginCache[moduleName]) {
return pluginCache[moduleName];
}
try {
// eslint-disable-next-line
const plugin = require(moduleName);
if (!plugin.default || !plugin) {
throw new Error(`Invalid plugin "${moduleName}"`);
}
pluginCache[moduleName] = plugin.default || plugin;
return pluginCache[moduleName];
} catch (error) {
throw new Error(`Module "${moduleName}" missing. Maybe \`npm install ${moduleName}\` could help!`);
}
} |