source: frontend/node_modules/@svgr/core/lib/plugins.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 13 days ago

Fix frontend appearance

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