@verdaccio/loaders 9.0.0-next-9.3 → 9.0.0-next-9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/_virtual/_rolldown/runtime.js +23 -0
- package/build/_virtual/_rolldown/runtime.mjs +7 -0
- package/build/index.js +5 -12
- package/build/index.mjs +2 -0
- package/build/plugin-async-loader.d.ts +2 -2
- package/build/plugin-async-loader.js +128 -250
- package/build/plugin-async-loader.js.map +1 -1
- package/build/plugin-async-loader.mjs +133 -0
- package/build/plugin-async-loader.mjs.map +1 -0
- package/build/utils.d.ts +1 -1
- package/build/utils.js +35 -42
- package/build/utils.js.map +1 -1
- package/build/utils.mjs +39 -0
- package/build/utils.mjs.map +1 -0
- package/package.json +22 -11
- package/build/index.js.map +0 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
//#endregion
|
|
23
|
+
exports.__toESM = __toESM;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) {
|
|
3
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
4
|
+
throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
|
|
5
|
+
});
|
|
6
|
+
//#endregion
|
|
7
|
+
export { __require };
|
package/build/index.js
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
5
4
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
get: function get() {
|
|
9
|
-
return _pluginAsyncLoader.asyncLoadPlugin;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
var _pluginAsyncLoader = require("./plugin-async-loader");
|
|
13
|
-
//# sourceMappingURL=index.js.map
|
|
5
|
+
const require_plugin_async_loader = require("./plugin-async-loader.js");
|
|
6
|
+
exports.asyncLoadPlugin = require_plugin_async_loader.asyncLoadPlugin;
|
package/build/index.mjs
ADDED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { pluginUtils } from '@verdaccio/core';
|
|
2
|
+
import { PluginType } from './utils';
|
|
3
3
|
/**
|
|
4
4
|
* The plugin loader find recursively plugins, if one plugin fails is ignored and report the error to the logger.
|
|
5
5
|
*
|
|
@@ -1,258 +1,136 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
15
|
-
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
16
|
-
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
|
|
17
|
-
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
18
|
-
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
19
|
-
var debug = (0, _debug["default"])('verdaccio:plugin:loader:async');
|
|
20
|
-
function isDirectory(_x) {
|
|
21
|
-
return _isDirectory.apply(this, arguments);
|
|
22
|
-
}
|
|
23
|
-
function _isDirectory() {
|
|
24
|
-
_isDirectory = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(pathFolder) {
|
|
25
|
-
var stat;
|
|
26
|
-
return _regenerator().w(function (_context) {
|
|
27
|
-
while (1) switch (_context.n) {
|
|
28
|
-
case 0:
|
|
29
|
-
_context.n = 1;
|
|
30
|
-
return (0, _promises.lstat)(pathFolder);
|
|
31
|
-
case 1:
|
|
32
|
-
stat = _context.v;
|
|
33
|
-
return _context.a(2, stat.isDirectory());
|
|
34
|
-
}
|
|
35
|
-
}, _callee);
|
|
36
|
-
}));
|
|
37
|
-
return _isDirectory.apply(this, arguments);
|
|
1
|
+
const require_runtime = require("./_virtual/_rolldown/runtime.js");
|
|
2
|
+
const require_utils = require("./utils.js");
|
|
3
|
+
let debug = require("debug");
|
|
4
|
+
debug = require_runtime.__toESM(debug);
|
|
5
|
+
let lodash = require("lodash");
|
|
6
|
+
lodash = require_runtime.__toESM(lodash);
|
|
7
|
+
let node_fs_promises = require("node:fs/promises");
|
|
8
|
+
let node_path = require("node:path");
|
|
9
|
+
let _verdaccio_core = require("@verdaccio/core");
|
|
10
|
+
//#region src/plugin-async-loader.ts
|
|
11
|
+
var debug$1 = (0, debug.default)("verdaccio:plugin:loader:async");
|
|
12
|
+
async function isDirectory(pathFolder) {
|
|
13
|
+
return (await (0, node_fs_promises.lstat)(pathFolder)).isDirectory();
|
|
38
14
|
}
|
|
39
15
|
function mergeConfig(appConfig, pluginConfig) {
|
|
40
|
-
|
|
16
|
+
return lodash.default.merge({}, appConfig, pluginConfig);
|
|
41
17
|
}
|
|
42
|
-
|
|
43
|
-
// type Plugins<T> =
|
|
44
|
-
// | pluginUtils.Auth<T>
|
|
45
|
-
// | pluginUtils.Storage<T>
|
|
46
|
-
// | pluginUtils.ExpressMiddleware<T, unknown, unknown>;
|
|
47
|
-
|
|
48
18
|
/**
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
function asyncLoadPlugin() {
|
|
72
|
-
|
|
19
|
+
* The plugin loader find recursively plugins, if one plugin fails is ignored and report the error to the logger.
|
|
20
|
+
*
|
|
21
|
+
* The loader follows the order:
|
|
22
|
+
* - If the at the `config.yaml` file the `plugins: ./plugins` is defined
|
|
23
|
+
* - If is absolute will use the provided path
|
|
24
|
+
* - If is relative, will use the base path of the config file. eg: /root/config.yaml the plugins folder should be
|
|
25
|
+
* hosted at /root/plugins
|
|
26
|
+
* - The next step is find at the node_modules or global based on the `require` native algorithm.
|
|
27
|
+
* - If the package is scoped eg: @scope/foo, try to load the package `@scope/foo`
|
|
28
|
+
* - If the package is not scoped, will use the default prefix: verdaccio-foo ("verdaccio-theme-" prefix for theme ui plugins).
|
|
29
|
+
* - If a custom prefix is provided, the verdaccio- is replaced by the config.server.pluginPrefix.
|
|
30
|
+
*
|
|
31
|
+
* The `sanityCheck` is the validation for the required methods to load the plugin, if the validation fails the plugin won't be loaded.
|
|
32
|
+
* The `params` is an object that contains the global configuration and the logger.
|
|
33
|
+
*
|
|
34
|
+
* @param {*} pluginConfigs the custom plugin section
|
|
35
|
+
* @param {*} pluginOptions a set of options to initialize the plugin
|
|
36
|
+
* @param {*} sanityCheck callback that check the shape that should fulfill the plugin
|
|
37
|
+
* @param {*} prefix by default is verdaccio but can be override with config.server.pluginPrefix
|
|
38
|
+
* @param {*} pluginCategory the category of the plugin, eg: auth, storage, middleware
|
|
39
|
+
* @return {Array} list of plugins
|
|
40
|
+
*/
|
|
41
|
+
async function asyncLoadPlugin(pluginConfigs = {}, pluginOptions, sanityCheck, legacyMergeConfigs = false, prefix = _verdaccio_core.PLUGIN_PREFIX, pluginCategory = "unknown") {
|
|
42
|
+
const logger = pluginOptions?.logger;
|
|
43
|
+
const pluginsIds = Object.keys(pluginConfigs || {});
|
|
44
|
+
const { config } = pluginOptions;
|
|
45
|
+
const plugins = [];
|
|
46
|
+
for (const pluginId of pluginsIds) {
|
|
47
|
+
debug$1(">>> looking for plugin %o", pluginId);
|
|
48
|
+
const isScoped = pluginId.startsWith("@") && pluginId.includes("/");
|
|
49
|
+
debug$1("is scoped plugin: %s", isScoped);
|
|
50
|
+
const pluginName = isScoped ? pluginId : `${prefix}-${pluginId}`;
|
|
51
|
+
debug$1("plugin package name %s", pluginName);
|
|
52
|
+
if (typeof config.plugins === "string") {
|
|
53
|
+
let pluginsPath = config.plugins;
|
|
54
|
+
debug$1("plugin path %s", pluginsPath);
|
|
55
|
+
if (!(0, node_path.isAbsolute)(pluginsPath)) {
|
|
56
|
+
if (typeof config.config_path === "string" && !config.configPath) logger.error("configPath is missing and the legacy config.config_path is not available for loading plugins");
|
|
57
|
+
if (!config.configPath) {
|
|
58
|
+
logger.error("config path property is required for loading plugins");
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
pluginsPath = (0, node_path.resolve)((0, node_path.join)((0, node_path.dirname)(config.configPath), pluginsPath));
|
|
62
|
+
}
|
|
63
|
+
logger.debug({ path: pluginsPath }, "plugins folder defined, loading plugins from @{path} ");
|
|
64
|
+
try {
|
|
65
|
+
await isDirectory(pluginsPath);
|
|
66
|
+
const externalFilePlugin = (0, node_path.resolve)(pluginsPath, pluginName);
|
|
67
|
+
let plugin = require_utils.tryLoad(externalFilePlugin, (a, b) => {
|
|
68
|
+
logger.error(a, b);
|
|
69
|
+
});
|
|
70
|
+
debug$1("external plugin %o", plugin);
|
|
71
|
+
if (plugin && require_utils.isValid(plugin)) {
|
|
72
|
+
plugin = executePlugin(plugin, pluginConfigs[pluginId], pluginOptions, legacyMergeConfigs);
|
|
73
|
+
if (!sanityCheck(plugin)) {
|
|
74
|
+
logger.error({ content: externalFilePlugin }, "@{content} doesn't look like a valid plugin");
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
debug$1(">>> plugin is running and passed sanity check");
|
|
78
|
+
plugins.push(plugin);
|
|
79
|
+
logger.info({
|
|
80
|
+
pluginName,
|
|
81
|
+
pluginCategory
|
|
82
|
+
}, "plugin @{pluginName} successfully loaded (@{pluginCategory})");
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
} catch (err) {
|
|
86
|
+
logger.warn({
|
|
87
|
+
err: err.message,
|
|
88
|
+
pluginsPath,
|
|
89
|
+
pluginName
|
|
90
|
+
}, "@{err} on loading plugins at @{pluginsPath} for @{pluginName}");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (typeof pluginId === "string") {
|
|
94
|
+
let plugin = require_utils.tryLoad(pluginName, (a, b) => {
|
|
95
|
+
logger.error(a, b);
|
|
96
|
+
});
|
|
97
|
+
if (plugin && require_utils.isValid(plugin)) {
|
|
98
|
+
plugin = executePlugin(plugin, pluginConfigs[pluginId], pluginOptions, legacyMergeConfigs);
|
|
99
|
+
if (!sanityCheck(plugin)) {
|
|
100
|
+
logger.error({ pluginName }, "@{pluginName} doesn't look like a valid plugin");
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
debug$1(">>> plugin is running and passed sanity check");
|
|
104
|
+
plugins.push(plugin);
|
|
105
|
+
logger.info({
|
|
106
|
+
pluginName,
|
|
107
|
+
pluginCategory
|
|
108
|
+
}, "plugin @{pluginName} successfully loaded (@{pluginCategory})");
|
|
109
|
+
continue;
|
|
110
|
+
} else {
|
|
111
|
+
logger.error({ pluginName }, "package not found, try to install @{pluginName} with a package manager");
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
debug$1("%o plugins found: %o", pluginCategory, plugins.length);
|
|
117
|
+
return plugins;
|
|
73
118
|
}
|
|
74
|
-
function
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
_pluginsIds,
|
|
88
|
-
pluginId,
|
|
89
|
-
isScoped,
|
|
90
|
-
pluginName,
|
|
91
|
-
pluginsPath,
|
|
92
|
-
pluginDir,
|
|
93
|
-
externalFilePlugin,
|
|
94
|
-
plugin,
|
|
95
|
-
_plugin,
|
|
96
|
-
_args2 = arguments,
|
|
97
|
-
_t;
|
|
98
|
-
return _regenerator().w(function (_context2) {
|
|
99
|
-
while (1) switch (_context2.p = _context2.n) {
|
|
100
|
-
case 0:
|
|
101
|
-
pluginConfigs = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {};
|
|
102
|
-
pluginOptions = _args2.length > 1 ? _args2[1] : undefined;
|
|
103
|
-
sanityCheck = _args2.length > 2 ? _args2[2] : undefined;
|
|
104
|
-
legacyMergeConfigs = _args2.length > 3 && _args2[3] !== undefined ? _args2[3] : false;
|
|
105
|
-
prefix = _args2.length > 4 && _args2[4] !== undefined ? _args2[4] : _core.PLUGIN_PREFIX;
|
|
106
|
-
pluginCategory = _args2.length > 5 && _args2[5] !== undefined ? _args2[5] : 'unknown';
|
|
107
|
-
logger = pluginOptions === null || pluginOptions === void 0 ? void 0 : pluginOptions.logger;
|
|
108
|
-
pluginsIds = Object.keys(pluginConfigs || {});
|
|
109
|
-
config = pluginOptions.config;
|
|
110
|
-
plugins = [];
|
|
111
|
-
_i = 0, _pluginsIds = pluginsIds;
|
|
112
|
-
case 1:
|
|
113
|
-
if (!(_i < _pluginsIds.length)) {
|
|
114
|
-
_context2.n = 13;
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
pluginId = _pluginsIds[_i];
|
|
118
|
-
debug('>>> looking for plugin %o', pluginId);
|
|
119
|
-
isScoped = pluginId.startsWith('@') && pluginId.includes('/');
|
|
120
|
-
debug('is scoped plugin: %s', isScoped);
|
|
121
|
-
pluginName = isScoped ? pluginId : "".concat(prefix, "-").concat(pluginId);
|
|
122
|
-
debug('plugin package name %s', pluginName);
|
|
123
|
-
|
|
124
|
-
// Try to load the plugin from the config.plugins path
|
|
125
|
-
if (!(typeof config.plugins === 'string')) {
|
|
126
|
-
_context2.n = 9;
|
|
127
|
-
break;
|
|
128
|
-
}
|
|
129
|
-
pluginsPath = config.plugins;
|
|
130
|
-
debug('plugin path %s', pluginsPath);
|
|
131
|
-
if ((0, _nodePath.isAbsolute)(pluginsPath)) {
|
|
132
|
-
_context2.n = 3;
|
|
133
|
-
break;
|
|
134
|
-
}
|
|
135
|
-
if (typeof config.config_path === 'string' && !config.configPath) {
|
|
136
|
-
logger.error('configPath is missing and the legacy config.config_path is not available for loading plugins');
|
|
137
|
-
}
|
|
138
|
-
if (config.configPath) {
|
|
139
|
-
_context2.n = 2;
|
|
140
|
-
break;
|
|
141
|
-
}
|
|
142
|
-
logger.error('config path property is required for loading plugins');
|
|
143
|
-
return _context2.a(3, 12);
|
|
144
|
-
case 2:
|
|
145
|
-
pluginsPath = (0, _nodePath.resolve)((0, _nodePath.join)((0, _nodePath.dirname)(config.configPath), pluginsPath));
|
|
146
|
-
case 3:
|
|
147
|
-
logger.debug({
|
|
148
|
-
path: pluginsPath
|
|
149
|
-
}, 'plugins folder defined, loading plugins from @{path} ');
|
|
150
|
-
// throws if is not a directory
|
|
151
|
-
_context2.p = 4;
|
|
152
|
-
_context2.n = 5;
|
|
153
|
-
return isDirectory(pluginsPath);
|
|
154
|
-
case 5:
|
|
155
|
-
pluginDir = pluginsPath;
|
|
156
|
-
externalFilePlugin = (0, _nodePath.resolve)(pluginDir, pluginName);
|
|
157
|
-
plugin = (0, _utils.tryLoad)(externalFilePlugin, function (a, b) {
|
|
158
|
-
logger.error(a, b);
|
|
159
|
-
});
|
|
160
|
-
debug('external plugin %o', plugin);
|
|
161
|
-
if (!(plugin && (0, _utils.isValid)(plugin))) {
|
|
162
|
-
_context2.n = 7;
|
|
163
|
-
break;
|
|
164
|
-
}
|
|
165
|
-
plugin = executePlugin(plugin, pluginConfigs[pluginId], pluginOptions, legacyMergeConfigs);
|
|
166
|
-
if (sanityCheck(plugin)) {
|
|
167
|
-
_context2.n = 6;
|
|
168
|
-
break;
|
|
169
|
-
}
|
|
170
|
-
logger.error({
|
|
171
|
-
content: externalFilePlugin
|
|
172
|
-
}, "@{content} doesn't look like a valid plugin");
|
|
173
|
-
return _context2.a(3, 12);
|
|
174
|
-
case 6:
|
|
175
|
-
debug('>>> plugin is running and passed sanity check');
|
|
176
|
-
plugins.push(plugin);
|
|
177
|
-
logger.info({
|
|
178
|
-
pluginName: pluginName,
|
|
179
|
-
pluginCategory: pluginCategory
|
|
180
|
-
}, 'plugin @{pluginName} successfully loaded (@{pluginCategory})');
|
|
181
|
-
return _context2.a(3, 12);
|
|
182
|
-
case 7:
|
|
183
|
-
_context2.n = 9;
|
|
184
|
-
break;
|
|
185
|
-
case 8:
|
|
186
|
-
_context2.p = 8;
|
|
187
|
-
_t = _context2.v;
|
|
188
|
-
logger.warn({
|
|
189
|
-
err: _t.message,
|
|
190
|
-
pluginsPath: pluginsPath,
|
|
191
|
-
pluginName: pluginName
|
|
192
|
-
}, '@{err} on loading plugins at @{pluginsPath} for @{pluginName}');
|
|
193
|
-
case 9:
|
|
194
|
-
if (!(typeof pluginId === 'string')) {
|
|
195
|
-
_context2.n = 12;
|
|
196
|
-
break;
|
|
197
|
-
}
|
|
198
|
-
_plugin = (0, _utils.tryLoad)(pluginName, function (a, b) {
|
|
199
|
-
logger.error(a, b);
|
|
200
|
-
});
|
|
201
|
-
if (!(_plugin && (0, _utils.isValid)(_plugin))) {
|
|
202
|
-
_context2.n = 11;
|
|
203
|
-
break;
|
|
204
|
-
}
|
|
205
|
-
_plugin = executePlugin(_plugin, pluginConfigs[pluginId], pluginOptions, legacyMergeConfigs);
|
|
206
|
-
if (sanityCheck(_plugin)) {
|
|
207
|
-
_context2.n = 10;
|
|
208
|
-
break;
|
|
209
|
-
}
|
|
210
|
-
logger.error({
|
|
211
|
-
pluginName: pluginName
|
|
212
|
-
}, "@{pluginName} doesn't look like a valid plugin");
|
|
213
|
-
return _context2.a(3, 12);
|
|
214
|
-
case 10:
|
|
215
|
-
debug('>>> plugin is running and passed sanity check');
|
|
216
|
-
plugins.push(_plugin);
|
|
217
|
-
logger.info({
|
|
218
|
-
pluginName: pluginName,
|
|
219
|
-
pluginCategory: pluginCategory
|
|
220
|
-
}, 'plugin @{pluginName} successfully loaded (@{pluginCategory})');
|
|
221
|
-
return _context2.a(3, 12);
|
|
222
|
-
case 11:
|
|
223
|
-
logger.error({
|
|
224
|
-
pluginName: pluginName
|
|
225
|
-
}, 'package not found, try to install @{pluginName} with a package manager');
|
|
226
|
-
return _context2.a(3, 12);
|
|
227
|
-
case 12:
|
|
228
|
-
_i++;
|
|
229
|
-
_context2.n = 1;
|
|
230
|
-
break;
|
|
231
|
-
case 13:
|
|
232
|
-
debug('%o plugins found: %o', pluginCategory, plugins.length);
|
|
233
|
-
return _context2.a(2, plugins);
|
|
234
|
-
}
|
|
235
|
-
}, _callee2, null, [[4, 8]]);
|
|
236
|
-
}));
|
|
237
|
-
return _asyncLoadPlugin.apply(this, arguments);
|
|
119
|
+
function executePlugin(plugin, pluginConfig, pluginOptions, legacyMergeConfigs = false) {
|
|
120
|
+
if (legacyMergeConfigs) {
|
|
121
|
+
debug$1(">>> plugin merge config enabled");
|
|
122
|
+
const originalConfig = pluginOptions.config;
|
|
123
|
+
pluginConfig = mergeConfig(originalConfig, pluginConfig);
|
|
124
|
+
}
|
|
125
|
+
if (require_utils.isES6(plugin)) {
|
|
126
|
+
debug$1("plugin is ES6");
|
|
127
|
+
return new plugin.default(pluginConfig, pluginOptions);
|
|
128
|
+
} else {
|
|
129
|
+
debug$1("plugin is commonJS");
|
|
130
|
+
return plugin(pluginConfig, pluginOptions);
|
|
131
|
+
}
|
|
238
132
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
// this is a legacy support for plugins that are not using the new API
|
|
242
|
-
if (legacyMergeConfigs) {
|
|
243
|
-
debug('>>> plugin merge config enabled');
|
|
244
|
-
var originalConfig = pluginOptions.config;
|
|
245
|
-
pluginConfig = mergeConfig(originalConfig, pluginConfig);
|
|
246
|
-
}
|
|
247
|
-
if ((0, _utils.isES6)(plugin)) {
|
|
248
|
-
debug('plugin is ES6');
|
|
249
|
-
// @ts-expect-error no relevant for the code
|
|
133
|
+
//#endregion
|
|
134
|
+
exports.asyncLoadPlugin = asyncLoadPlugin;
|
|
250
135
|
|
|
251
|
-
return new plugin["default"](pluginConfig, pluginOptions);
|
|
252
|
-
} else {
|
|
253
|
-
debug('plugin is commonJS');
|
|
254
|
-
// @ts-expect-error improve this type
|
|
255
|
-
return plugin(pluginConfig, pluginOptions);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
136
|
//# sourceMappingURL=plugin-async-loader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-async-loader.js","names":["_debug","_interopRequireDefault","require","_lodash","_promises","_nodePath","_core","_utils","e","__esModule","_regenerator","t","r","Symbol","n","iterator","o","toStringTag","i","c","prototype","Generator","u","Object","create","_regeneratorDefine2","f","p","y","G","v","a","d","bind","length","l","TypeError","call","done","value","GeneratorFunction","GeneratorFunctionPrototype","getPrototypeOf","setPrototypeOf","__proto__","displayName","w","m","defineProperty","_regeneratorDefine","_invoke","enumerable","configurable","writable","asyncGeneratorStep","Promise","resolve","then","_asyncToGenerator","arguments","apply","_next","_throw","debug","buildDebug","isDirectory","_x","_isDirectory","_callee","pathFolder","stat","_context","lstat","mergeConfig","appConfig","pluginConfig","_","merge","asyncLoadPlugin","_asyncLoadPlugin","_callee2","pluginConfigs","pluginOptions","sanityCheck","legacyMergeConfigs","prefix","pluginCategory","logger","pluginsIds","config","plugins","_i","_pluginsIds","pluginId","isScoped","pluginName","pluginsPath","pluginDir","externalFilePlugin","plugin","_plugin","_args2","_t","_context2","undefined","PLUGIN_PREFIX","keys","startsWith","includes","concat","isAbsolute","config_path","configPath","error","join","dirname","path","tryLoad","b","isValid","executePlugin","content","push","info","warn","err","message","originalConfig","isES6"],"sources":["../src/plugin-async-loader.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport _ from 'lodash';\nimport { lstat } from 'node:fs/promises';\nimport { dirname, isAbsolute, join, resolve } from 'node:path';\n\nimport type { pluginUtils } from '@verdaccio/core';\nimport { PLUGIN_PREFIX } from '@verdaccio/core';\n\nimport type { PluginType } from './utils';\nimport { isES6, isValid, tryLoad } from './utils';\n\nconst debug = buildDebug('verdaccio:plugin:loader:async');\n\nasync function isDirectory(pathFolder: string) {\n const stat = await lstat(pathFolder);\n return stat.isDirectory();\n}\n\nfunction mergeConfig(appConfig: unknown, pluginConfig: unknown) {\n return _.merge({}, appConfig, pluginConfig);\n}\n\n// type Plugins<T> =\n// | pluginUtils.Auth<T>\n// | pluginUtils.Storage<T>\n// | pluginUtils.ExpressMiddleware<T, unknown, unknown>;\n\n/**\n * The plugin loader find recursively plugins, if one plugin fails is ignored and report the error to the logger.\n *\n * The loader follows the order:\n * - If the at the `config.yaml` file the `plugins: ./plugins` is defined\n * - If is absolute will use the provided path\n * - If is relative, will use the base path of the config file. eg: /root/config.yaml the plugins folder should be\n * hosted at /root/plugins\n * - The next step is find at the node_modules or global based on the `require` native algorithm.\n * - If the package is scoped eg: @scope/foo, try to load the package `@scope/foo`\n * - If the package is not scoped, will use the default prefix: verdaccio-foo (\"verdaccio-theme-\" prefix for theme ui plugins).\n * - If a custom prefix is provided, the verdaccio- is replaced by the config.server.pluginPrefix.\n *\n * The `sanityCheck` is the validation for the required methods to load the plugin, if the validation fails the plugin won't be loaded.\n * The `params` is an object that contains the global configuration and the logger.\n *\n * @param {*} pluginConfigs the custom plugin section\n * @param {*} pluginOptions a set of options to initialize the plugin\n * @param {*} sanityCheck callback that check the shape that should fulfill the plugin\n * @param {*} prefix by default is verdaccio but can be override with config.server.pluginPrefix\n * @param {*} pluginCategory the category of the plugin, eg: auth, storage, middleware\n * @return {Array} list of plugins\n */\nexport async function asyncLoadPlugin<T extends pluginUtils.Plugin<T>>(\n pluginConfigs: any = {},\n pluginOptions: pluginUtils.PluginOptions,\n sanityCheck: (plugin: PluginType<T>) => boolean,\n legacyMergeConfigs: boolean = false,\n prefix: string = PLUGIN_PREFIX,\n pluginCategory: string = 'unknown'\n): Promise<PluginType<T>[]> {\n const logger = pluginOptions?.logger;\n const pluginsIds = Object.keys(pluginConfigs || {});\n const { config } = pluginOptions;\n const plugins: PluginType<T>[] = [];\n for (const pluginId of pluginsIds) {\n debug('>>> looking for plugin %o', pluginId);\n\n const isScoped: boolean = pluginId.startsWith('@') && pluginId.includes('/');\n debug('is scoped plugin: %s', isScoped);\n const pluginName = isScoped ? pluginId : `${prefix}-${pluginId}`;\n debug('plugin package name %s', pluginName);\n\n // Try to load the plugin from the config.plugins path\n if (typeof config.plugins === 'string') {\n let pluginsPath = config.plugins;\n debug('plugin path %s', pluginsPath);\n if (!isAbsolute(pluginsPath)) {\n if (typeof config.config_path === 'string' && !config.configPath) {\n logger.error(\n 'configPath is missing and the legacy config.config_path is not available for loading plugins'\n );\n }\n\n if (!config.configPath) {\n logger.error('config path property is required for loading plugins');\n continue;\n }\n pluginsPath = resolve(join(dirname(config.configPath), pluginsPath));\n }\n logger.debug({ path: pluginsPath }, 'plugins folder defined, loading plugins from @{path} ');\n // throws if is not a directory\n try {\n await isDirectory(pluginsPath);\n const pluginDir = pluginsPath;\n const externalFilePlugin = resolve(pluginDir, pluginName);\n let plugin = tryLoad<T>(externalFilePlugin, (a: any, b: any) => {\n logger.error(a, b);\n });\n debug('external plugin %o', plugin);\n if (plugin && isValid(plugin)) {\n plugin = executePlugin(\n plugin,\n pluginConfigs[pluginId],\n pluginOptions,\n legacyMergeConfigs\n );\n if (!sanityCheck(plugin)) {\n logger.error(\n { content: externalFilePlugin },\n \"@{content} doesn't look like a valid plugin\"\n );\n continue;\n }\n debug('>>> plugin is running and passed sanity check');\n plugins.push(plugin);\n logger.info(\n { pluginName, pluginCategory },\n 'plugin @{pluginName} successfully loaded (@{pluginCategory})'\n );\n continue;\n }\n } catch (err: any) {\n logger.warn(\n { err: err.message, pluginsPath, pluginName },\n '@{err} on loading plugins at @{pluginsPath} for @{pluginName}'\n );\n }\n }\n\n // Try to load the plugin from the node_modules or global based on the `require` native algorithm\n if (typeof pluginId === 'string') {\n let plugin = tryLoad<T>(pluginName, (a: any, b: any) => {\n logger.error(a, b);\n });\n if (plugin && isValid(plugin)) {\n plugin = executePlugin(plugin, pluginConfigs[pluginId], pluginOptions, legacyMergeConfigs);\n if (!sanityCheck(plugin)) {\n logger.error({ pluginName }, \"@{pluginName} doesn't look like a valid plugin\");\n continue;\n }\n debug('>>> plugin is running and passed sanity check');\n plugins.push(plugin);\n logger.info(\n { pluginName, pluginCategory },\n 'plugin @{pluginName} successfully loaded (@{pluginCategory})'\n );\n continue;\n } else {\n logger.error(\n { pluginName },\n 'package not found, try to install @{pluginName} with a package manager'\n );\n continue;\n }\n }\n }\n debug('%o plugins found: %o', pluginCategory, plugins.length);\n return plugins;\n}\n\nexport function executePlugin<T>(\n plugin: PluginType<T>,\n pluginConfig: unknown,\n pluginOptions: pluginUtils.PluginOptions,\n legacyMergeConfigs: boolean = false\n): PluginType<T> {\n // this is a legacy support for plugins that are not using the new API\n if (legacyMergeConfigs) {\n debug('>>> plugin merge config enabled');\n const originalConfig = pluginOptions.config;\n pluginConfig = mergeConfig(originalConfig, pluginConfig);\n }\n if (isES6(plugin)) {\n debug('plugin is ES6');\n // @ts-expect-error no relevant for the code\n\n return new plugin.default(pluginConfig, pluginOptions) as Plugin;\n } else {\n debug('plugin is commonJS');\n // @ts-expect-error improve this type\n return plugin(pluginConfig, pluginOptions) as PluginType<T>;\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AAGA,IAAAI,KAAA,GAAAJ,OAAA;AAGA,IAAAK,MAAA,GAAAL,OAAA;AAAkD,SAAAD,uBAAAO,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,gBAAAA,CAAA;AAAA,SAAAE,aAAA,IARlD,uKAAAF,CAAA,EAAAG,CAAA,EAAAC,CAAA,wBAAAC,MAAA,GAAAA,MAAA,OAAAC,CAAA,GAAAF,CAAA,CAAAG,QAAA,kBAAAC,CAAA,GAAAJ,CAAA,CAAAK,WAAA,8BAAAC,EAAAN,CAAA,EAAAE,CAAA,EAAAE,CAAA,EAAAE,CAAA,QAAAC,CAAA,GAAAL,CAAA,IAAAA,CAAA,CAAAM,SAAA,YAAAC,SAAA,GAAAP,CAAA,GAAAO,SAAA,EAAAC,CAAA,GAAAC,MAAA,CAAAC,MAAA,CAAAL,CAAA,CAAAC,SAAA,UAAAK,mBAAA,CAAAH,CAAA,uBAAAV,CAAA,EAAAE,CAAA,EAAAE,CAAA,QAAAE,CAAA,EAAAC,CAAA,EAAAG,CAAA,EAAAI,CAAA,MAAAC,CAAA,GAAAX,CAAA,QAAAY,CAAA,OAAAC,CAAA,KAAAF,CAAA,KAAAb,CAAA,KAAAgB,CAAA,EAAAtB,CAAA,EAAAuB,CAAA,EAAAC,CAAA,EAAAN,CAAA,EAAAM,CAAA,CAAAC,IAAA,CAAAzB,CAAA,MAAAwB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OAAO,CAACxD,MAAM,CAAC;UAAC,OAAAqE,SAAA,CAAAxE,CAAA,IACvD2D,OAAO;MAAA;IAAA,GAAAV,QAAA;EAAA,CACf;EAAA,OAAAD,gBAAA,CAAAnB,KAAA,OAAAD,SAAA;AAAA;AAEM,SAAS6D,aAAaA,CAC3BrB,MAAqB,EACrBxB,YAAqB,EACrBO,aAAwC,EAEzB;EAAA,IADfE,kBAA2B,GAAAzB,SAAA,CAAAzB,MAAA,QAAAyB,SAAA,QAAA6C,SAAA,GAAA7C,SAAA,MAAG,KAAK;EAEnC;EACA,IAAIyB,kBAAkB,EAAE;IACtBrB,KAAK,CAAC,iCAAiC,CAAC;IACxC,IAAMgE,cAAc,GAAG7C,aAAa,CAACO,MAAM;IAC3Cd,YAAY,GAAGF,WAAW,CAACsD,cAAc,EAAEpD,YAAY,CAAC;EAC1D;EACA,IAAI,IAAAqD,YAAK,EAAC7B,MAAM,CAAC,EAAE;IACjBpC,KAAK,CAAC,eAAe,CAAC;IACtB;;IAEA,OAAO,IAAIoC,MAAM,WAAQ,CAACxB,YAAY,EAAEO,aAAa,CAAC;EACxD,CAAC,MAAM;IACLnB,KAAK,CAAC,oBAAoB,CAAC;IAC3B;IACA,OAAOoC,MAAM,CAACxB,YAAY,EAAEO,aAAa,CAAC;EAC5C;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"plugin-async-loader.js","names":[],"sources":["../src/plugin-async-loader.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport _ from 'lodash';\nimport { lstat } from 'node:fs/promises';\nimport { dirname, isAbsolute, join, resolve } from 'node:path';\n\nimport type { pluginUtils } from '@verdaccio/core';\nimport { PLUGIN_PREFIX } from '@verdaccio/core';\n\nimport type { PluginType } from './utils';\nimport { isES6, isValid, tryLoad } from './utils';\n\nconst debug = buildDebug('verdaccio:plugin:loader:async');\n\nasync function isDirectory(pathFolder: string) {\n const stat = await lstat(pathFolder);\n return stat.isDirectory();\n}\n\nfunction mergeConfig(appConfig: unknown, pluginConfig: unknown) {\n return _.merge({}, appConfig, pluginConfig);\n}\n\n// type Plugins<T> =\n// | pluginUtils.Auth<T>\n// | pluginUtils.Storage<T>\n// | pluginUtils.ExpressMiddleware<T, unknown, unknown>;\n\n/**\n * The plugin loader find recursively plugins, if one plugin fails is ignored and report the error to the logger.\n *\n * The loader follows the order:\n * - If the at the `config.yaml` file the `plugins: ./plugins` is defined\n * - If is absolute will use the provided path\n * - If is relative, will use the base path of the config file. eg: /root/config.yaml the plugins folder should be\n * hosted at /root/plugins\n * - The next step is find at the node_modules or global based on the `require` native algorithm.\n * - If the package is scoped eg: @scope/foo, try to load the package `@scope/foo`\n * - If the package is not scoped, will use the default prefix: verdaccio-foo (\"verdaccio-theme-\" prefix for theme ui plugins).\n * - If a custom prefix is provided, the verdaccio- is replaced by the config.server.pluginPrefix.\n *\n * The `sanityCheck` is the validation for the required methods to load the plugin, if the validation fails the plugin won't be loaded.\n * The `params` is an object that contains the global configuration and the logger.\n *\n * @param {*} pluginConfigs the custom plugin section\n * @param {*} pluginOptions a set of options to initialize the plugin\n * @param {*} sanityCheck callback that check the shape that should fulfill the plugin\n * @param {*} prefix by default is verdaccio but can be override with config.server.pluginPrefix\n * @param {*} pluginCategory the category of the plugin, eg: auth, storage, middleware\n * @return {Array} list of plugins\n */\nexport async function asyncLoadPlugin<T extends pluginUtils.Plugin<T>>(\n pluginConfigs: any = {},\n pluginOptions: pluginUtils.PluginOptions,\n sanityCheck: (plugin: PluginType<T>) => boolean,\n legacyMergeConfigs: boolean = false,\n prefix: string = PLUGIN_PREFIX,\n pluginCategory: string = 'unknown'\n): Promise<PluginType<T>[]> {\n const logger = pluginOptions?.logger;\n const pluginsIds = Object.keys(pluginConfigs || {});\n const { config } = pluginOptions;\n const plugins: PluginType<T>[] = [];\n for (const pluginId of pluginsIds) {\n debug('>>> looking for plugin %o', pluginId);\n\n const isScoped: boolean = pluginId.startsWith('@') && pluginId.includes('/');\n debug('is scoped plugin: %s', isScoped);\n const pluginName = isScoped ? pluginId : `${prefix}-${pluginId}`;\n debug('plugin package name %s', pluginName);\n\n // Try to load the plugin from the config.plugins path\n if (typeof config.plugins === 'string') {\n let pluginsPath = config.plugins;\n debug('plugin path %s', pluginsPath);\n if (!isAbsolute(pluginsPath)) {\n if (typeof config.config_path === 'string' && !config.configPath) {\n logger.error(\n 'configPath is missing and the legacy config.config_path is not available for loading plugins'\n );\n }\n\n if (!config.configPath) {\n logger.error('config path property is required for loading plugins');\n continue;\n }\n pluginsPath = resolve(join(dirname(config.configPath), pluginsPath));\n }\n logger.debug({ path: pluginsPath }, 'plugins folder defined, loading plugins from @{path} ');\n // throws if is not a directory\n try {\n await isDirectory(pluginsPath);\n const pluginDir = pluginsPath;\n const externalFilePlugin = resolve(pluginDir, pluginName);\n let plugin = tryLoad<T>(externalFilePlugin, (a: any, b: any) => {\n logger.error(a, b);\n });\n debug('external plugin %o', plugin);\n if (plugin && isValid(plugin)) {\n plugin = executePlugin(\n plugin,\n pluginConfigs[pluginId],\n pluginOptions,\n legacyMergeConfigs\n );\n if (!sanityCheck(plugin)) {\n logger.error(\n { content: externalFilePlugin },\n \"@{content} doesn't look like a valid plugin\"\n );\n continue;\n }\n debug('>>> plugin is running and passed sanity check');\n plugins.push(plugin);\n logger.info(\n { pluginName, pluginCategory },\n 'plugin @{pluginName} successfully loaded (@{pluginCategory})'\n );\n continue;\n }\n } catch (err: any) {\n logger.warn(\n { err: err.message, pluginsPath, pluginName },\n '@{err} on loading plugins at @{pluginsPath} for @{pluginName}'\n );\n }\n }\n\n // Try to load the plugin from the node_modules or global based on the `require` native algorithm\n if (typeof pluginId === 'string') {\n let plugin = tryLoad<T>(pluginName, (a: any, b: any) => {\n logger.error(a, b);\n });\n if (plugin && isValid(plugin)) {\n plugin = executePlugin(plugin, pluginConfigs[pluginId], pluginOptions, legacyMergeConfigs);\n if (!sanityCheck(plugin)) {\n logger.error({ pluginName }, \"@{pluginName} doesn't look like a valid plugin\");\n continue;\n }\n debug('>>> plugin is running and passed sanity check');\n plugins.push(plugin);\n logger.info(\n { pluginName, pluginCategory },\n 'plugin @{pluginName} successfully loaded (@{pluginCategory})'\n );\n continue;\n } else {\n logger.error(\n { pluginName },\n 'package not found, try to install @{pluginName} with a package manager'\n );\n continue;\n }\n }\n }\n debug('%o plugins found: %o', pluginCategory, plugins.length);\n return plugins;\n}\n\nexport function executePlugin<T>(\n plugin: PluginType<T>,\n pluginConfig: unknown,\n pluginOptions: pluginUtils.PluginOptions,\n legacyMergeConfigs: boolean = false\n): PluginType<T> {\n // this is a legacy support for plugins that are not using the new API\n if (legacyMergeConfigs) {\n debug('>>> plugin merge config enabled');\n const originalConfig = pluginOptions.config;\n pluginConfig = mergeConfig(originalConfig, pluginConfig);\n }\n if (isES6(plugin)) {\n debug('plugin is ES6');\n // @ts-expect-error no relevant for the code\n\n return new plugin.default(pluginConfig, pluginOptions) as Plugin;\n } else {\n debug('plugin is commonJS');\n // @ts-expect-error improve this type\n return plugin(pluginConfig, pluginOptions) as PluginType<T>;\n }\n}\n"],"mappings":";;;;;;;;;;AAWA,IAAM,WAAA,GAAA,MAAA,SAAmB,gCAAgC;AAEzD,eAAe,YAAY,YAAoB;AAE7C,SADa,OAAA,GAAA,iBAAA,OAAY,WAAW,EACxB,aAAa;;AAG3B,SAAS,YAAY,WAAoB,cAAuB;AAC9D,QAAO,OAAA,QAAE,MAAM,EAAE,EAAE,WAAW,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;AA+B7C,eAAsB,gBACpB,gBAAqB,EAAE,EACvB,eACA,aACA,qBAA8B,OAC9B,SAAiB,gBAAA,eACjB,iBAAyB,WACC;CAC1B,MAAM,SAAS,eAAe;CAC9B,MAAM,aAAa,OAAO,KAAK,iBAAiB,EAAE,CAAC;CACnD,MAAM,EAAE,WAAW;CACnB,MAAM,UAA2B,EAAE;AACnC,MAAK,MAAM,YAAY,YAAY;AACjC,UAAM,6BAA6B,SAAS;EAE5C,MAAM,WAAoB,SAAS,WAAW,IA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;AACF,OAAI,UAAU,cAAA,QAAQ,OAAO,EAAE;AAC7B,aAAS,cAAc,QAAQ,cAAc,WAAW,eAAe,mBAAmB;AAC1F,QAAI,CAAC,YAAY,OAAO,EAAE;AACxB,YAAO,MAAM,EAAE,YAAY,EAAE,iDAAiD;AAC9E;;AAEF,YAAM,gDAAgD;AACtD,YAAQ,KAAK,OAAO;AACpB,WAAO,KACL;KAAE;KAAY;KAAgB,EAC9B,+DACD;AACD;UACK;AACL,WAAO,MACL,EAAE,YAAY,EACd,yEACD;AACD;;;;AAIN,SAAM,wBAAwB,gBAAgB,QAAQ,OAAO;AAC7D,QAAO;;AAGT,SAAgB,cACd,QACA,cACA,eACA,qBAA8B,OACf;AAEf,KAAI,oBAAoB;AACtB,UAAM,kCAAkC;EACxC,MAAM,iBAAiB,cAAc;AACrC,iBAAe,YAAY,gBAAgB,aAAa;;AAE1D,KAAI,cAAA,MAAM,OAAO,EAAE;AACjB,UAAM,gBAAgB;AAGtB,SAAO,IAAI,OAAO,QAAQ,cAAc,cAAc;QACjD;AACL,UAAM,qBAAqB;AAE3B,SAAO,OAAO,cAAc,cAAc"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { isES6, isValid, tryLoad } from "./utils.mjs";
|
|
2
|
+
import buildDebug from "debug";
|
|
3
|
+
import _ from "lodash";
|
|
4
|
+
import { lstat } from "node:fs/promises";
|
|
5
|
+
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
6
|
+
import { PLUGIN_PREFIX } from "@verdaccio/core";
|
|
7
|
+
//#region src/plugin-async-loader.ts
|
|
8
|
+
var debug = buildDebug("verdaccio:plugin:loader:async");
|
|
9
|
+
async function isDirectory(pathFolder) {
|
|
10
|
+
return (await lstat(pathFolder)).isDirectory();
|
|
11
|
+
}
|
|
12
|
+
function mergeConfig(appConfig, pluginConfig) {
|
|
13
|
+
return _.merge({}, appConfig, pluginConfig);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The plugin loader find recursively plugins, if one plugin fails is ignored and report the error to the logger.
|
|
17
|
+
*
|
|
18
|
+
* The loader follows the order:
|
|
19
|
+
* - If the at the `config.yaml` file the `plugins: ./plugins` is defined
|
|
20
|
+
* - If is absolute will use the provided path
|
|
21
|
+
* - If is relative, will use the base path of the config file. eg: /root/config.yaml the plugins folder should be
|
|
22
|
+
* hosted at /root/plugins
|
|
23
|
+
* - The next step is find at the node_modules or global based on the `require` native algorithm.
|
|
24
|
+
* - If the package is scoped eg: @scope/foo, try to load the package `@scope/foo`
|
|
25
|
+
* - If the package is not scoped, will use the default prefix: verdaccio-foo ("verdaccio-theme-" prefix for theme ui plugins).
|
|
26
|
+
* - If a custom prefix is provided, the verdaccio- is replaced by the config.server.pluginPrefix.
|
|
27
|
+
*
|
|
28
|
+
* The `sanityCheck` is the validation for the required methods to load the plugin, if the validation fails the plugin won't be loaded.
|
|
29
|
+
* The `params` is an object that contains the global configuration and the logger.
|
|
30
|
+
*
|
|
31
|
+
* @param {*} pluginConfigs the custom plugin section
|
|
32
|
+
* @param {*} pluginOptions a set of options to initialize the plugin
|
|
33
|
+
* @param {*} sanityCheck callback that check the shape that should fulfill the plugin
|
|
34
|
+
* @param {*} prefix by default is verdaccio but can be override with config.server.pluginPrefix
|
|
35
|
+
* @param {*} pluginCategory the category of the plugin, eg: auth, storage, middleware
|
|
36
|
+
* @return {Array} list of plugins
|
|
37
|
+
*/
|
|
38
|
+
async function asyncLoadPlugin(pluginConfigs = {}, pluginOptions, sanityCheck, legacyMergeConfigs = false, prefix = PLUGIN_PREFIX, pluginCategory = "unknown") {
|
|
39
|
+
const logger = pluginOptions?.logger;
|
|
40
|
+
const pluginsIds = Object.keys(pluginConfigs || {});
|
|
41
|
+
const { config } = pluginOptions;
|
|
42
|
+
const plugins = [];
|
|
43
|
+
for (const pluginId of pluginsIds) {
|
|
44
|
+
debug(">>> looking for plugin %o", pluginId);
|
|
45
|
+
const isScoped = pluginId.startsWith("@") && pluginId.includes("/");
|
|
46
|
+
debug("is scoped plugin: %s", isScoped);
|
|
47
|
+
const pluginName = isScoped ? pluginId : `${prefix}-${pluginId}`;
|
|
48
|
+
debug("plugin package name %s", pluginName);
|
|
49
|
+
if (typeof config.plugins === "string") {
|
|
50
|
+
let pluginsPath = config.plugins;
|
|
51
|
+
debug("plugin path %s", pluginsPath);
|
|
52
|
+
if (!isAbsolute(pluginsPath)) {
|
|
53
|
+
if (typeof config.config_path === "string" && !config.configPath) logger.error("configPath is missing and the legacy config.config_path is not available for loading plugins");
|
|
54
|
+
if (!config.configPath) {
|
|
55
|
+
logger.error("config path property is required for loading plugins");
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
pluginsPath = resolve(join(dirname(config.configPath), pluginsPath));
|
|
59
|
+
}
|
|
60
|
+
logger.debug({ path: pluginsPath }, "plugins folder defined, loading plugins from @{path} ");
|
|
61
|
+
try {
|
|
62
|
+
await isDirectory(pluginsPath);
|
|
63
|
+
const externalFilePlugin = resolve(pluginsPath, pluginName);
|
|
64
|
+
let plugin = tryLoad(externalFilePlugin, (a, b) => {
|
|
65
|
+
logger.error(a, b);
|
|
66
|
+
});
|
|
67
|
+
debug("external plugin %o", plugin);
|
|
68
|
+
if (plugin && isValid(plugin)) {
|
|
69
|
+
plugin = executePlugin(plugin, pluginConfigs[pluginId], pluginOptions, legacyMergeConfigs);
|
|
70
|
+
if (!sanityCheck(plugin)) {
|
|
71
|
+
logger.error({ content: externalFilePlugin }, "@{content} doesn't look like a valid plugin");
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
debug(">>> plugin is running and passed sanity check");
|
|
75
|
+
plugins.push(plugin);
|
|
76
|
+
logger.info({
|
|
77
|
+
pluginName,
|
|
78
|
+
pluginCategory
|
|
79
|
+
}, "plugin @{pluginName} successfully loaded (@{pluginCategory})");
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
} catch (err) {
|
|
83
|
+
logger.warn({
|
|
84
|
+
err: err.message,
|
|
85
|
+
pluginsPath,
|
|
86
|
+
pluginName
|
|
87
|
+
}, "@{err} on loading plugins at @{pluginsPath} for @{pluginName}");
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (typeof pluginId === "string") {
|
|
91
|
+
let plugin = tryLoad(pluginName, (a, b) => {
|
|
92
|
+
logger.error(a, b);
|
|
93
|
+
});
|
|
94
|
+
if (plugin && isValid(plugin)) {
|
|
95
|
+
plugin = executePlugin(plugin, pluginConfigs[pluginId], pluginOptions, legacyMergeConfigs);
|
|
96
|
+
if (!sanityCheck(plugin)) {
|
|
97
|
+
logger.error({ pluginName }, "@{pluginName} doesn't look like a valid plugin");
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
debug(">>> plugin is running and passed sanity check");
|
|
101
|
+
plugins.push(plugin);
|
|
102
|
+
logger.info({
|
|
103
|
+
pluginName,
|
|
104
|
+
pluginCategory
|
|
105
|
+
}, "plugin @{pluginName} successfully loaded (@{pluginCategory})");
|
|
106
|
+
continue;
|
|
107
|
+
} else {
|
|
108
|
+
logger.error({ pluginName }, "package not found, try to install @{pluginName} with a package manager");
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
debug("%o plugins found: %o", pluginCategory, plugins.length);
|
|
114
|
+
return plugins;
|
|
115
|
+
}
|
|
116
|
+
function executePlugin(plugin, pluginConfig, pluginOptions, legacyMergeConfigs = false) {
|
|
117
|
+
if (legacyMergeConfigs) {
|
|
118
|
+
debug(">>> plugin merge config enabled");
|
|
119
|
+
const originalConfig = pluginOptions.config;
|
|
120
|
+
pluginConfig = mergeConfig(originalConfig, pluginConfig);
|
|
121
|
+
}
|
|
122
|
+
if (isES6(plugin)) {
|
|
123
|
+
debug("plugin is ES6");
|
|
124
|
+
return new plugin.default(pluginConfig, pluginOptions);
|
|
125
|
+
} else {
|
|
126
|
+
debug("plugin is commonJS");
|
|
127
|
+
return plugin(pluginConfig, pluginOptions);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
//#endregion
|
|
131
|
+
export { asyncLoadPlugin };
|
|
132
|
+
|
|
133
|
+
//# sourceMappingURL=plugin-async-loader.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-async-loader.mjs","names":[],"sources":["../src/plugin-async-loader.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport _ from 'lodash';\nimport { lstat } from 'node:fs/promises';\nimport { dirname, isAbsolute, join, resolve } from 'node:path';\n\nimport type { pluginUtils } from '@verdaccio/core';\nimport { PLUGIN_PREFIX } from '@verdaccio/core';\n\nimport type { PluginType } from './utils';\nimport { isES6, isValid, tryLoad } from './utils';\n\nconst debug = buildDebug('verdaccio:plugin:loader:async');\n\nasync function isDirectory(pathFolder: string) {\n const stat = await lstat(pathFolder);\n return stat.isDirectory();\n}\n\nfunction mergeConfig(appConfig: unknown, pluginConfig: unknown) {\n return _.merge({}, appConfig, pluginConfig);\n}\n\n// type Plugins<T> =\n// | pluginUtils.Auth<T>\n// | pluginUtils.Storage<T>\n// | pluginUtils.ExpressMiddleware<T, unknown, unknown>;\n\n/**\n * The plugin loader find recursively plugins, if one plugin fails is ignored and report the error to the logger.\n *\n * The loader follows the order:\n * - If the at the `config.yaml` file the `plugins: ./plugins` is defined\n * - If is absolute will use the provided path\n * - If is relative, will use the base path of the config file. eg: /root/config.yaml the plugins folder should be\n * hosted at /root/plugins\n * - The next step is find at the node_modules or global based on the `require` native algorithm.\n * - If the package is scoped eg: @scope/foo, try to load the package `@scope/foo`\n * - If the package is not scoped, will use the default prefix: verdaccio-foo (\"verdaccio-theme-\" prefix for theme ui plugins).\n * - If a custom prefix is provided, the verdaccio- is replaced by the config.server.pluginPrefix.\n *\n * The `sanityCheck` is the validation for the required methods to load the plugin, if the validation fails the plugin won't be loaded.\n * The `params` is an object that contains the global configuration and the logger.\n *\n * @param {*} pluginConfigs the custom plugin section\n * @param {*} pluginOptions a set of options to initialize the plugin\n * @param {*} sanityCheck callback that check the shape that should fulfill the plugin\n * @param {*} prefix by default is verdaccio but can be override with config.server.pluginPrefix\n * @param {*} pluginCategory the category of the plugin, eg: auth, storage, middleware\n * @return {Array} list of plugins\n */\nexport async function asyncLoadPlugin<T extends pluginUtils.Plugin<T>>(\n pluginConfigs: any = {},\n pluginOptions: pluginUtils.PluginOptions,\n sanityCheck: (plugin: PluginType<T>) => boolean,\n legacyMergeConfigs: boolean = false,\n prefix: string = PLUGIN_PREFIX,\n pluginCategory: string = 'unknown'\n): Promise<PluginType<T>[]> {\n const logger = pluginOptions?.logger;\n const pluginsIds = Object.keys(pluginConfigs || {});\n const { config } = pluginOptions;\n const plugins: PluginType<T>[] = [];\n for (const pluginId of pluginsIds) {\n debug('>>> looking for plugin %o', pluginId);\n\n const isScoped: boolean = pluginId.startsWith('@') && pluginId.includes('/');\n debug('is scoped plugin: %s', isScoped);\n const pluginName = isScoped ? pluginId : `${prefix}-${pluginId}`;\n debug('plugin package name %s', pluginName);\n\n // Try to load the plugin from the config.plugins path\n if (typeof config.plugins === 'string') {\n let pluginsPath = config.plugins;\n debug('plugin path %s', pluginsPath);\n if (!isAbsolute(pluginsPath)) {\n if (typeof config.config_path === 'string' && !config.configPath) {\n logger.error(\n 'configPath is missing and the legacy config.config_path is not available for loading plugins'\n );\n }\n\n if (!config.configPath) {\n logger.error('config path property is required for loading plugins');\n continue;\n }\n pluginsPath = resolve(join(dirname(config.configPath), pluginsPath));\n }\n logger.debug({ path: pluginsPath }, 'plugins folder defined, loading plugins from @{path} ');\n // throws if is not a directory\n try {\n await isDirectory(pluginsPath);\n const pluginDir = pluginsPath;\n const externalFilePlugin = resolve(pluginDir, pluginName);\n let plugin = tryLoad<T>(externalFilePlugin, (a: any, b: any) => {\n logger.error(a, b);\n });\n debug('external plugin %o', plugin);\n if (plugin && isValid(plugin)) {\n plugin = executePlugin(\n plugin,\n pluginConfigs[pluginId],\n pluginOptions,\n legacyMergeConfigs\n );\n if (!sanityCheck(plugin)) {\n logger.error(\n { content: externalFilePlugin },\n \"@{content} doesn't look like a valid plugin\"\n );\n continue;\n }\n debug('>>> plugin is running and passed sanity check');\n plugins.push(plugin);\n logger.info(\n { pluginName, pluginCategory },\n 'plugin @{pluginName} successfully loaded (@{pluginCategory})'\n );\n continue;\n }\n } catch (err: any) {\n logger.warn(\n { err: err.message, pluginsPath, pluginName },\n '@{err} on loading plugins at @{pluginsPath} for @{pluginName}'\n );\n }\n }\n\n // Try to load the plugin from the node_modules or global based on the `require` native algorithm\n if (typeof pluginId === 'string') {\n let plugin = tryLoad<T>(pluginName, (a: any, b: any) => {\n logger.error(a, b);\n });\n if (plugin && isValid(plugin)) {\n plugin = executePlugin(plugin, pluginConfigs[pluginId], pluginOptions, legacyMergeConfigs);\n if (!sanityCheck(plugin)) {\n logger.error({ pluginName }, \"@{pluginName} doesn't look like a valid plugin\");\n continue;\n }\n debug('>>> plugin is running and passed sanity check');\n plugins.push(plugin);\n logger.info(\n { pluginName, pluginCategory },\n 'plugin @{pluginName} successfully loaded (@{pluginCategory})'\n );\n continue;\n } else {\n logger.error(\n { pluginName },\n 'package not found, try to install @{pluginName} with a package manager'\n );\n continue;\n }\n }\n }\n debug('%o plugins found: %o', pluginCategory, plugins.length);\n return plugins;\n}\n\nexport function executePlugin<T>(\n plugin: PluginType<T>,\n pluginConfig: unknown,\n pluginOptions: pluginUtils.PluginOptions,\n legacyMergeConfigs: boolean = false\n): PluginType<T> {\n // this is a legacy support for plugins that are not using the new API\n if (legacyMergeConfigs) {\n debug('>>> plugin merge config enabled');\n const originalConfig = pluginOptions.config;\n pluginConfig = mergeConfig(originalConfig, pluginConfig);\n }\n if (isES6(plugin)) {\n debug('plugin is ES6');\n // @ts-expect-error no relevant for the code\n\n return new plugin.default(pluginConfig, pluginOptions) as Plugin;\n } else {\n debug('plugin is commonJS');\n // @ts-expect-error improve this type\n return plugin(pluginConfig, pluginOptions) as PluginType<T>;\n }\n}\n"],"mappings":";;;;;;;AAWA,IAAM,QAAQ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2
2
|
export type PluginType<T> = T extends pluginUtils.Plugin<T> ? T : never;
|
|
3
3
|
export declare function isValid<T>(plugin: PluginType<T>): boolean;
|
|
4
4
|
export declare function isES6<T>(plugin: PluginType<T>): boolean;
|
package/build/utils.js
CHANGED
|
@@ -1,50 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var _debug = _interopRequireDefault(require("debug"));
|
|
10
|
-
var _lodash = _interopRequireDefault(require("lodash"));
|
|
11
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
12
|
-
var debug = (0, _debug["default"])('verdaccio:plugin:loader:utils');
|
|
13
|
-
var MODULE_NOT_FOUND = 'MODULE_NOT_FOUND';
|
|
1
|
+
const require_runtime = require("./_virtual/_rolldown/runtime.js");
|
|
2
|
+
let debug = require("debug");
|
|
3
|
+
debug = require_runtime.__toESM(debug);
|
|
4
|
+
let lodash = require("lodash");
|
|
5
|
+
lodash = require_runtime.__toESM(lodash);
|
|
6
|
+
//#region src/utils.ts
|
|
7
|
+
var debug$1 = (0, debug.default)("verdaccio:plugin:loader:utils");
|
|
8
|
+
var MODULE_NOT_FOUND = "MODULE_NOT_FOUND";
|
|
14
9
|
function isValid(plugin) {
|
|
15
|
-
|
|
16
|
-
return _lodash["default"].isFunction(plugin) || _lodash["default"].isFunction(plugin["default"]);
|
|
10
|
+
return lodash.default.isFunction(plugin) || lodash.default.isFunction(plugin.default);
|
|
17
11
|
}
|
|
18
12
|
function isES6(plugin) {
|
|
19
|
-
|
|
13
|
+
return Object.keys(plugin).includes("default");
|
|
20
14
|
}
|
|
21
|
-
|
|
22
15
|
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
16
|
+
* Requires a module.
|
|
17
|
+
* @param {*} path the module's path
|
|
18
|
+
* @return {Object}
|
|
19
|
+
*/
|
|
27
20
|
function tryLoad(path, onError) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
onError({
|
|
45
|
-
err: err.msg
|
|
46
|
-
}, 'error loading plugin @{err}');
|
|
47
|
-
throw err;
|
|
48
|
-
}
|
|
21
|
+
try {
|
|
22
|
+
debug$1("loading plugin %s", path);
|
|
23
|
+
return require(path);
|
|
24
|
+
} catch (err) {
|
|
25
|
+
if (err.code === MODULE_NOT_FOUND) {
|
|
26
|
+
debug$1("\"require\" failed for plugin %s", path);
|
|
27
|
+
const message = err.message.replace(/\\\\/g, "\\").split("\n");
|
|
28
|
+
if (!message[0].includes(path)) {
|
|
29
|
+
debug$1("%o", message[0]);
|
|
30
|
+
debug$1("%o", message.slice(1));
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
onError({ err: err.msg }, "error loading plugin @{err}");
|
|
35
|
+
throw err;
|
|
36
|
+
}
|
|
49
37
|
}
|
|
38
|
+
//#endregion
|
|
39
|
+
exports.isES6 = isES6;
|
|
40
|
+
exports.isValid = isValid;
|
|
41
|
+
exports.tryLoad = tryLoad;
|
|
42
|
+
|
|
50
43
|
//# sourceMappingURL=utils.js.map
|
package/build/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":[
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["../src/utils.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport _ from 'lodash';\n\nimport type { pluginUtils } from '@verdaccio/core';\n\nconst debug = buildDebug('verdaccio:plugin:loader:utils');\nconst MODULE_NOT_FOUND = 'MODULE_NOT_FOUND';\n\nexport type PluginType<T> = T extends pluginUtils.Plugin<T> ? T : never;\n\nexport function isValid<T>(plugin: PluginType<T>): boolean {\n // @ts-expect-error default not relevant\n return _.isFunction(plugin) || _.isFunction(plugin.default);\n}\n\nexport function isES6<T>(plugin: PluginType<T>): boolean {\n return Object.keys(plugin).includes('default');\n}\n\n/**\n * Requires a module.\n * @param {*} path the module's path\n * @return {Object}\n */\nexport function tryLoad<T>(path: string, onError: any): PluginType<T> | null {\n try {\n debug('loading plugin %s', path);\n return require(path) as PluginType<T>;\n } catch (err: any) {\n if (err.code === MODULE_NOT_FOUND) {\n debug('\"require\" failed for plugin %s', path);\n // If loading fails, because a dependency is missing,\n // we want to log the error message and require stack\n // to see where the missing dependency is.\n const message = err.message.replace(/\\\\\\\\/g, '\\\\').split('\\n');\n if (!message[0].includes(path)) {\n debug('%o', message[0]); // error message\n debug('%o', message.slice(1)); // stack trace\n }\n return null;\n }\n onError({ err: err.msg }, 'error loading plugin @{err}');\n throw err;\n }\n}\n"],"mappings":";;;;;;AAKA,IAAM,WAAA,GAAA,MAAA,SAAmB,gCAAgC;AACzD,IAAM,mBAAmB;AAIzB,SAAgB,QAAW,QAAgC;AAEzD,QAAO,OAAA,QAAE,WAAW,OAAO,IAAI,OAAA,QAAE,WAAW,OAAO,QAAQ;;AAG7D,SAAgB,MAAS,QAAgC;AACvD,QAAO,OAAO,KAAK,OAAO,CAAC,SAAS,UAAU;;;;;;;AAQhD,SAAgB,QAAW,MAAc,SAAoC;AAC3E,KAAI;AACF,UAAM,qBAAqB,KAAK;AAChC,SAAO,QAAQ,KAAK;UACb,KAAU;AACjB,MAAI,IAAI,SAAS,kBAAkB;AACjC,WAAM,oCAAkC,KAAK;GAI7C,MAAM,UAAU,IAAI,QAAQ,QAAQ,SAAS,KAAK,CAAC,MAAM,KAAK;AAC9D,OAAI,CAAC,QAAQ,GAAG,SAAS,KAAK,EAAE;AAC9B,YAAM,MAAM,QAAQ,GAAG;AACvB,YAAM,MAAM,QAAQ,MAAM,EAAE,CAAC;;AAE/B,UAAO;;AAET,UAAQ,EAAE,KAAK,IAAI,KAAK,EAAE,8BAA8B;AACxD,QAAM"}
|
package/build/utils.mjs
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { __require } from "./_virtual/_rolldown/runtime.mjs";
|
|
2
|
+
import buildDebug from "debug";
|
|
3
|
+
import _ from "lodash";
|
|
4
|
+
//#region src/utils.ts
|
|
5
|
+
var debug = buildDebug("verdaccio:plugin:loader:utils");
|
|
6
|
+
var MODULE_NOT_FOUND = "MODULE_NOT_FOUND";
|
|
7
|
+
function isValid(plugin) {
|
|
8
|
+
return _.isFunction(plugin) || _.isFunction(plugin.default);
|
|
9
|
+
}
|
|
10
|
+
function isES6(plugin) {
|
|
11
|
+
return Object.keys(plugin).includes("default");
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Requires a module.
|
|
15
|
+
* @param {*} path the module's path
|
|
16
|
+
* @return {Object}
|
|
17
|
+
*/
|
|
18
|
+
function tryLoad(path, onError) {
|
|
19
|
+
try {
|
|
20
|
+
debug("loading plugin %s", path);
|
|
21
|
+
return __require(path);
|
|
22
|
+
} catch (err) {
|
|
23
|
+
if (err.code === MODULE_NOT_FOUND) {
|
|
24
|
+
debug("\"require\" failed for plugin %s", path);
|
|
25
|
+
const message = err.message.replace(/\\\\/g, "\\").split("\n");
|
|
26
|
+
if (!message[0].includes(path)) {
|
|
27
|
+
debug("%o", message[0]);
|
|
28
|
+
debug("%o", message.slice(1));
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
onError({ err: err.msg }, "error loading plugin @{err}");
|
|
33
|
+
throw err;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
export { isES6, isValid, tryLoad };
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.mjs","names":[],"sources":["../src/utils.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport _ from 'lodash';\n\nimport type { pluginUtils } from '@verdaccio/core';\n\nconst debug = buildDebug('verdaccio:plugin:loader:utils');\nconst MODULE_NOT_FOUND = 'MODULE_NOT_FOUND';\n\nexport type PluginType<T> = T extends pluginUtils.Plugin<T> ? T : never;\n\nexport function isValid<T>(plugin: PluginType<T>): boolean {\n // @ts-expect-error default not relevant\n return _.isFunction(plugin) || _.isFunction(plugin.default);\n}\n\nexport function isES6<T>(plugin: PluginType<T>): boolean {\n return Object.keys(plugin).includes('default');\n}\n\n/**\n * Requires a module.\n * @param {*} path the module's path\n * @return {Object}\n */\nexport function tryLoad<T>(path: string, onError: any): PluginType<T> | null {\n try {\n debug('loading plugin %s', path);\n return require(path) as PluginType<T>;\n } catch (err: any) {\n if (err.code === MODULE_NOT_FOUND) {\n debug('\"require\" failed for plugin %s', path);\n // If loading fails, because a dependency is missing,\n // we want to log the error message and require stack\n // to see where the missing dependency is.\n const message = err.message.replace(/\\\\\\\\/g, '\\\\').split('\\n');\n if (!message[0].includes(path)) {\n debug('%o', message[0]); // error message\n debug('%o', message.slice(1)); // stack trace\n }\n return null;\n }\n onError({ err: err.msg }, 'error loading plugin @{err}');\n throw err;\n }\n}\n"],"mappings":";;;;AAKA,IAAM,QAAQ,WAAW,gCAAgC;AACzD,IAAM,mBAAmB;AAIzB,SAAgB,QAAW,QAAgC;AAEzD,QAAO,EAAE,WAAW,OAAO,IAAI,EAAE,WAAW,OAAO,QAAQ;;AAG7D,SAAgB,MAAS,QAAgC;AACvD,QAAO,OAAO,KAAK,OAAO,CAAC,SAAS,UAAU;;;;;;;AAQhD,SAAgB,QAAW,MAAc,SAAoC;AAC3E,KAAI;AACF,QAAM,qBAAqB,KAAK;AAChC,SAAA,UAAe,KAAK;UACb,KAAU;AACjB,MAAI,IAAI,SAAS,kBAAkB;AACjC,SAAM,oCAAkC,KAAK;GAI7C,MAAM,UAAU,IAAI,QAAQ,QAAQ,SAAS,KAAK,CAAC,MAAM,KAAK;AAC9D,OAAI,CAAC,QAAQ,GAAG,SAAS,KAAK,EAAE;AAC9B,UAAM,MAAM,QAAQ,GAAG;AACvB,UAAM,MAAM,QAAQ,MAAM,EAAE,CAAC;;AAE/B,UAAO;;AAET,UAAQ,EAAE,KAAK,IAAI,KAAK,EAAE,8BAA8B;AACxD,QAAM"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verdaccio/loaders",
|
|
3
|
-
"version": "9.0.0-next-9.
|
|
3
|
+
"version": "9.0.0-next-9.4",
|
|
4
4
|
"description": "Verdaccio Loader Logic",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -17,17 +17,17 @@
|
|
|
17
17
|
"url": "https://github.com/verdaccio/verdaccio/issues"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@verdaccio/core": "9.0.0-next-9.
|
|
20
|
+
"@verdaccio/core": "9.0.0-next-9.4",
|
|
21
21
|
"debug": "4.4.3",
|
|
22
22
|
"lodash": "4.17.23"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@verdaccio/logger": "9.0.0-next-9.
|
|
26
|
-
"@verdaccio/config": "9.0.0-next-9.
|
|
27
|
-
"@verdaccio/core": "9.0.0-next-9.
|
|
25
|
+
"@verdaccio/logger": "9.0.0-next-9.4",
|
|
26
|
+
"@verdaccio/config": "9.0.0-next-9.4",
|
|
27
|
+
"@verdaccio/core": "9.0.0-next-9.4",
|
|
28
28
|
"@verdaccio-scope/verdaccio-auth-foo": "0.0.2",
|
|
29
29
|
"customprefix-auth": "4.0.0-next-9.0",
|
|
30
|
-
"verdaccio-auth-memory": "14.0.0-next-9.
|
|
30
|
+
"verdaccio-auth-memory": "14.0.0-next-9.4",
|
|
31
31
|
"vitest": "3.2.4"
|
|
32
32
|
},
|
|
33
33
|
"homepage": "https://verdaccio.org",
|
|
@@ -50,13 +50,24 @@
|
|
|
50
50
|
"type": "opencollective",
|
|
51
51
|
"url": "https://opencollective.com/verdaccio"
|
|
52
52
|
},
|
|
53
|
+
"module": "./build/index.mjs",
|
|
54
|
+
"exports": {
|
|
55
|
+
".": {
|
|
56
|
+
"import": {
|
|
57
|
+
"types": "./build/index.d.ts",
|
|
58
|
+
"default": "./build/index.mjs"
|
|
59
|
+
},
|
|
60
|
+
"require": {
|
|
61
|
+
"types": "./build/index.d.ts",
|
|
62
|
+
"default": "./build/index.js"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"./build/*": "./build/*"
|
|
66
|
+
},
|
|
53
67
|
"scripts": {
|
|
54
68
|
"clean": "rimraf ./build",
|
|
55
69
|
"test": "vitest run",
|
|
56
|
-
"
|
|
57
|
-
"build
|
|
58
|
-
"build:js": "babel src/ --out-dir build/ --copy-files --extensions \".ts,.tsx\" --source-maps",
|
|
59
|
-
"watch": "pnpm build:js -- --watch",
|
|
60
|
-
"build": "pnpm run build:js && pnpm run build:types"
|
|
70
|
+
"watch": "vite build --watch",
|
|
71
|
+
"build": "vite build"
|
|
61
72
|
}
|
|
62
73
|
}
|
package/build/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_pluginAsyncLoader","require"],"sources":["../src/index.ts"],"sourcesContent":["export { asyncLoadPlugin } from './plugin-async-loader';\n"],"mappings":";;;;;;;;;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA","ignoreList":[]}
|