@verdaccio/loaders 8.0.5 → 8.1.0
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/index.js +5 -12
- package/build/index.mjs +2 -0
- package/build/plugin-async-loader.d.ts +1 -1
- 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 +7 -0
- package/build/utils.js +112 -42
- package/build/utils.js.map +1 -1
- package/build/utils.mjs +115 -0
- package/build/utils.mjs.map +1 -0
- package/package.json +25 -12
- 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;
|
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
|
@@ -23,5 +23,5 @@ import type { PluginType } from './utils';
|
|
|
23
23
|
* @param {*} pluginCategory the category of the plugin, eg: auth, storage, middleware
|
|
24
24
|
* @return {Array} list of plugins
|
|
25
25
|
*/
|
|
26
|
-
export declare function asyncLoadPlugin<T extends pluginUtils.Plugin<T>>(pluginConfigs: any, pluginOptions: pluginUtils.PluginOptions, sanityCheck: (plugin: PluginType<T>) => boolean, legacyMergeConfigs?: boolean, prefix?: string, pluginCategory?: string): Promise<PluginType<T>[]>;
|
|
26
|
+
export declare function asyncLoadPlugin<T extends pluginUtils.Plugin<T>>(pluginConfigs: any | undefined, pluginOptions: pluginUtils.PluginOptions, sanityCheck: (plugin: PluginType<T>) => boolean, legacyMergeConfigs?: boolean, prefix?: string, pluginCategory?: string): Promise<PluginType<T>[]>;
|
|
27
27
|
export declare function executePlugin<T>(plugin: PluginType<T>, pluginConfig: unknown, pluginOptions: pluginUtils.PluginOptions, legacyMergeConfigs?: boolean): PluginType<T>;
|
|
@@ -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 = await require_utils.tryLoadAsync(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 = await require_utils.tryLoadAsync(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,CAAA,WAAAA,EAAArB,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AC;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, tryLoadAsync } 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 = await tryLoadAsync<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 = await tryLoadAsync<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,+BAA+B;AAExD,eAAe,YAAY,YAAoB;CAE7C,QAAO,OAAA,GAAA,iBAAA,OADkB,UAAU,GACvB,YAAY;AAC1B;AAEA,SAAS,YAAY,WAAoB,cAAuB;CAC9D,OAAO,OAAA,QAAE,MAAM,CAAC,GAAG,WAAW,YAAY;AAC5C;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,eAAsB,gBACpB,gBAAqB,CAAC,GACtB,eACA,aACA,qBAA8B,OAC9B,SAAiB,gBAAA,eACjB,iBAAyB,WACC;CAC1B,MAAM,SAAS,eAAe;CAC9B,MAAM,aAAa,OAAO,KAAK,iBAAiB,CAAC,CAAC;CAClD,MAAM,EAAE,WAAW;CACnB,MAAM,UAA2B,CAAC;CAClC,KAAK,MAAM,YAAY,YAAY;EACjC,QAAM,6BAA6B,QAAQ;EAE3C,MAAM,WAAoB,SAAS,WAAW,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Q,MAAW;IACjE,OAAO,MAAM,GAAG,CAAC;GACnB,CAAC;GACD,IAAI,UAAU,cAAA,QAAQ,MAAM,GAAG;IAC7B,SAAS,cAAc,QAAQ,cAAc,WAAW,eAAe,kBAAkB;IACzF,IAAI,CAAC,YAAY,MAAM,GAAG;KACxB,OAAO,MAAM,EAAE,WAAW,GAAG,gDAAgD;KAC7E;IACF;IACA,QAAM,+CAA+C;IACrD,QAAQ,KAAK,MAAM;IACnB,OAAO,KACL;KAAE;KAAY;IAAe,GAC7B,8DACF;IACA;GACF,OAAO;IACL,OAAO,MACL,EAAE,WAAW,GACb,wEACF;IACA;GACF;EACF;CACF;CACA,QAAM,wBAAwB,gBAAgB,QAAQ,MAAM;CAC5D,OAAO;AACT;AAEA,SAAgB,cACd,QACA,cACA,eACA,qBAA8B,OACf;CAEf,IAAI,oBAAoB;EACtB,QAAM,iCAAiC;EACvC,MAAM,iBAAiB,cAAc;EACrC,eAAe,YAAY,gBAAgB,YAAY;CACzD;CACA,IAAI,cAAA,MAAM,MAAM,GAAG;EACjB,QAAM,eAAe;EAGrB,OAAO,IAAI,OAAO,QAAQ,cAAc,aAAa;CACvD,OAAO;EACL,QAAM,oBAAoB;EAE1B,OAAO,OAAO,cAAc,aAAa;CAC3C;AACF"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { isES6, isValid, tryLoadAsync } 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 = await tryLoadAsync(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 = await tryLoadAsync(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, tryLoadAsync } 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 = await tryLoadAsync<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 = await tryLoadAsync<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,WAAW,+BAA+B;AAExD,eAAe,YAAY,YAAoB;CAE7C,QAAO,MADY,MAAM,UAAU,GACvB,YAAY;AAC1B;AAEA,SAAS,YAAY,WAAoB,cAAuB;CAC9D,OAAO,EAAE,MAAM,CAAC,GAAG,WAAW,YAAY;AAC5C;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,eAAsB,gBACpB,gBAAqB,CAAC,GACtB,eACA,aACA,qBAA8B,OAC9B,SAAiB,eACjB,iBAAyB,WACC;CAC1B,MAAM,SAAS,eAAe;CAC9B,MAAM,aAAa,OAAO,KAAK,iBAAiB,CAAC,CAAC;CAClD,MAAM,EAAE,WAAW;CACnB,MAAM,UAA2B,CAAC;CAClC,KAAK,MAAM,YAAY,YAAY;EACjC,MAAM,6BAA6B,QAAQ;EAE3C,MAAM,WAAoB,SAAS,WAAW,GAAG,KAAK,SAAS,SAAS,GAAG;EAC3E,MAAM,wBAAwB,QAAQ;EACtC,MAAM,aAAa,WAAW,WAAW,GAAG,OAAO,GAAG;EACtD,MAAM,0BAA0B,UAAU;EAG1C,IAAI,OAAO,OAAO,YAAY,UAAU;GACtC,IAAI,cAAc,OAAO;GACzB,MAAM,kBAAkB,WAAW;GACnC,IAAI,CAAC,WAAW,WAAW,GAAG;IAC5B,IAAI,OAAO,OAAO,gBAAgB,YAAY,CAAC,OAAO,YACpD,OAAO,MACL,8FACF;IAGF,IAAI,CAAC,OAAO,YAAY;KACtB,OAAO,MAAM,sDAAsD;KACnE;IACF;IACA,cAAc,QAAQ,KAAK,QAAQ,OAAO,UAAU,GAAG,WAAW,CAAC;GACrE;GACA,OAAO,MAAM,EAAE,MAAM,YAAY,GAAG,uDAAuD;GAE3F,IAAI;IACF,MAAM,YAAY,WAAW;IAE7B,MAAM,qBAAqB,QAAQ,aAAW,UAAU;IACxD,I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OAAO,QAAQ,cAAc,aAAa;CACvD,OAAO;EACL,MAAM,oBAAoB;EAE1B,OAAO,OAAO,cAAc,aAAa;CAC3C;AACF"}
|
package/build/utils.d.ts
CHANGED
|
@@ -8,3 +8,10 @@ export declare function isES6<T>(plugin: PluginType<T>): boolean;
|
|
|
8
8
|
* @return {Object}
|
|
9
9
|
*/
|
|
10
10
|
export declare function tryLoad<T>(path: string, onError: any): PluginType<T> | null;
|
|
11
|
+
/**
|
|
12
|
+
* Dynamically imports a module (supports ESM plugins).
|
|
13
|
+
* Falls back from require() to import() for ESM compatibility.
|
|
14
|
+
* @param {*} path the module's path
|
|
15
|
+
* @return {Object}
|
|
16
|
+
*/
|
|
17
|
+
export declare function tryLoadAsync<T>(path: string, onError: any): Promise<PluginType<T> | null>;
|
package/build/utils.js
CHANGED
|
@@ -1,50 +1,120 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var
|
|
13
|
-
var
|
|
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
|
+
let node_path = require("node:path");
|
|
7
|
+
let node_fs = require("node:fs");
|
|
8
|
+
let node_module = require("node:module");
|
|
9
|
+
let node_url = require("node:url");
|
|
10
|
+
//#region src/utils.ts
|
|
11
|
+
var debug$1 = (0, debug.default)("verdaccio:plugin:loader:utils");
|
|
12
|
+
var MODULE_NOT_FOUND = "MODULE_NOT_FOUND";
|
|
13
|
+
var ERR_REQUIRE_ESM = "ERR_REQUIRE_ESM";
|
|
14
|
+
var ERR_REQUIRE_ASYNC_MODULE = "ERR_REQUIRE_ASYNC_MODULE";
|
|
15
|
+
var requireModule = {}.url ? (0, node_module.createRequire)({}.url) : (0, node_module.createRequire)(__filename);
|
|
14
16
|
function isValid(plugin) {
|
|
15
|
-
|
|
16
|
-
return _lodash["default"].isFunction(plugin) || _lodash["default"].isFunction(plugin["default"]);
|
|
17
|
+
return lodash.default.isFunction(plugin) || lodash.default.isFunction(plugin.default);
|
|
17
18
|
}
|
|
18
19
|
function isES6(plugin) {
|
|
19
|
-
|
|
20
|
+
return Object.keys(plugin).includes("default");
|
|
20
21
|
}
|
|
21
|
-
|
|
22
22
|
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
* Requires a module.
|
|
24
|
+
* @param {*} path the module's path
|
|
25
|
+
* @return {Object}
|
|
26
|
+
*/
|
|
27
27
|
function tryLoad(path, onError) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
28
|
+
try {
|
|
29
|
+
debug$1("loading plugin %s", path);
|
|
30
|
+
return requireModule(path);
|
|
31
|
+
} catch (err) {
|
|
32
|
+
if (err.code === MODULE_NOT_FOUND) {
|
|
33
|
+
debug$1("\"require\" failed for plugin %s", path);
|
|
34
|
+
const message = err.message.replace(/\\\\/g, "\\").split("\n");
|
|
35
|
+
if (!message[0].includes(path)) {
|
|
36
|
+
debug$1("%o", message[0]);
|
|
37
|
+
debug$1("%o", message.slice(1));
|
|
38
|
+
onError({ err: err.message }, "error loading plugin @{err}");
|
|
39
|
+
throw err;
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
if (err.code === ERR_REQUIRE_ESM || err.code === ERR_REQUIRE_ASYNC_MODULE) {
|
|
44
|
+
debug$1("\"require\" failed for ESM plugin %s, will try dynamic import", path);
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
onError({ err: err.message }, "error loading plugin @{err}");
|
|
48
|
+
throw err;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Resolve the entry point for a directory-based plugin.
|
|
53
|
+
* dynamic import() does not support directory imports, so we need to
|
|
54
|
+
* find the actual file to import (via package.json "main"/"exports" or index.js).
|
|
55
|
+
*/
|
|
56
|
+
function resolveEntryPoint(dirPath) {
|
|
57
|
+
const pkgPath = (0, node_path.join)(dirPath, "package.json");
|
|
58
|
+
if ((0, node_fs.existsSync)(pkgPath)) try {
|
|
59
|
+
const pkg = JSON.parse((0, node_fs.readFileSync)(pkgPath, "utf-8"));
|
|
60
|
+
if (pkg.exports) {
|
|
61
|
+
const dotExport = pkg.exports["."] ?? pkg.exports;
|
|
62
|
+
if (typeof dotExport === "string") return (0, node_path.join)(dirPath, dotExport);
|
|
63
|
+
if (typeof dotExport?.import === "string") return (0, node_path.join)(dirPath, dotExport.import);
|
|
64
|
+
if (typeof dotExport?.import?.default === "string") return (0, node_path.join)(dirPath, dotExport.import.default);
|
|
65
|
+
if (typeof dotExport?.default === "string") return (0, node_path.join)(dirPath, dotExport.default);
|
|
66
|
+
}
|
|
67
|
+
if (pkg.module) return (0, node_path.join)(dirPath, pkg.module);
|
|
68
|
+
if (pkg.main) return (0, node_path.join)(dirPath, pkg.main);
|
|
69
|
+
} catch {}
|
|
70
|
+
return (0, node_path.join)(dirPath, "index.js");
|
|
49
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Dynamically imports a module (supports ESM plugins).
|
|
74
|
+
* Falls back from require() to import() for ESM compatibility.
|
|
75
|
+
* @param {*} path the module's path
|
|
76
|
+
* @return {Object}
|
|
77
|
+
*/
|
|
78
|
+
async function tryLoadAsync(path, onError) {
|
|
79
|
+
try {
|
|
80
|
+
const cjsResult = tryLoad(path, onError);
|
|
81
|
+
if (cjsResult !== null) return cjsResult;
|
|
82
|
+
} catch (err) {
|
|
83
|
+
debug$1("require() threw a real load error for %s: %s", path, err.message);
|
|
84
|
+
throw err;
|
|
85
|
+
}
|
|
86
|
+
let importPath = path;
|
|
87
|
+
try {
|
|
88
|
+
if ((0, node_path.isAbsolute)(path) && ((0, node_fs.existsSync)((0, node_path.join)(path, "package.json")) || (0, node_fs.existsSync)((0, node_path.join)(path, "index.js")))) {
|
|
89
|
+
importPath = resolveEntryPoint(path);
|
|
90
|
+
debug$1("resolved ESM entry point: %s", importPath);
|
|
91
|
+
}
|
|
92
|
+
const importUrl = (0, node_path.isAbsolute)(importPath) ? (0, node_url.pathToFileURL)(importPath).href : importPath;
|
|
93
|
+
debug$1("trying dynamic import for plugin %s", importUrl);
|
|
94
|
+
const module = await import(importUrl);
|
|
95
|
+
debug$1("dynamic import succeeded for plugin %s", importUrl);
|
|
96
|
+
return module;
|
|
97
|
+
} catch (err) {
|
|
98
|
+
if (err.code === "ERR_UNSUPPORTED_DIR_IMPORT") {
|
|
99
|
+
debug$1("\"import\" failed for plugin %s", path);
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
if (err.code === MODULE_NOT_FOUND || err.code === "ERR_MODULE_NOT_FOUND") {
|
|
103
|
+
const missingRaw = /Cannot find (?:module|package) '([^']+)'/.exec(err.message)?.[1];
|
|
104
|
+
const missing = missingRaw?.startsWith("file://") ? (0, node_url.fileURLToPath)(missingRaw) : missingRaw;
|
|
105
|
+
if (missing === void 0 || missing === path || missing === importPath || missing.startsWith(path)) {
|
|
106
|
+
debug$1("\"import\" failed for plugin %s", path);
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
debug$1("plugin %s exists but its dependency %s is missing", path, missing);
|
|
110
|
+
}
|
|
111
|
+
onError({ err: err.message }, "error loading plugin @{err}");
|
|
112
|
+
throw err;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
//#endregion
|
|
116
|
+
exports.isES6 = isES6;
|
|
117
|
+
exports.isValid = isValid;
|
|
118
|
+
exports.tryLoadAsync = tryLoadAsync;
|
|
119
|
+
|
|
50
120
|
//# sourceMappingURL=utils.js.map
|
package/build/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":["_debug","_interopRequireDefault","require","_lodash","e","__esModule","debug","buildDebug","MODULE_NOT_FOUND","isValid","plugin","_","isFunction","isES6","Object","keys","includes","tryLoad","path","onError","err","code","message","replace","split","slice","msg"],"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":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAF,sBAAA,CAAAC,OAAA;AAA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GAAG,CAACM;IAAI,CAAC,EAAE,6BAA6B,CAAC;IACxD,MAAMN,GAAG;EACX;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["../src/utils.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport _ from 'lodash';\nimport { existsSync, readFileSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport { isAbsolute, join } from 'node:path';\nimport { fileURLToPath, pathToFileURL } from 'node:url';\n\nimport type { pluginUtils } from '@verdaccio/core';\n\nconst debug = buildDebug('verdaccio:plugin:loader:utils');\nconst MODULE_NOT_FOUND = 'MODULE_NOT_FOUND';\nconst ERR_REQUIRE_ESM = 'ERR_REQUIRE_ESM';\n// thrown by require(esm) when the module uses top-level await\nconst ERR_REQUIRE_ASYNC_MODULE = 'ERR_REQUIRE_ASYNC_MODULE';\n\n// the ESM build has no ambient require; create one so CJS plugins keep loading.\n// rolldown rewrites bare `require` to a throwing stub in the ESM output and\n// lowers `import.meta` to `{}` in the CJS output, so `import.meta.url` is only\n// truthy in the ESM build; module-scoped __filename covers the CJS build\n// (checking `typeof __filename`/`typeof require` instead is unsafe: node -e and\n// the REPL leak both as globals into ESM modules)\nconst requireModule = import.meta.url ? createRequire(import.meta.url) : createRequire(__filename);\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 requireModule(path) as PluginType<T>;\n } catch (err: any) {\n if (err.code === MODULE_NOT_FOUND) {\n debug('\"require\" failed for plugin %s', path);\n const message = err.message.replace(/\\\\\\\\/g, '\\\\').split('\\n');\n if (!message[0].includes(path)) {\n // the plugin itself was found but one of its own dependencies is\n // missing: that is a real load error — reporting \"not found\" (and\n // re-evaluating the plugin through the import() fallback) would mask\n // the actual cause and run its side effects twice\n debug('%o', message[0]); // error message\n debug('%o', message.slice(1)); // stack trace\n onError({ err: err.message }, 'error loading plugin @{err}');\n throw err;\n }\n return null;\n }\n if (err.code === ERR_REQUIRE_ESM || err.code === ERR_REQUIRE_ASYNC_MODULE) {\n debug('\"require\" failed for ESM plugin %s, will try dynamic import', path);\n return null;\n }\n onError({ err: err.message }, 'error loading plugin @{err}');\n throw err;\n }\n}\n\n/**\n * Resolve the entry point for a directory-based plugin.\n * dynamic import() does not support directory imports, so we need to\n * find the actual file to import (via package.json \"main\"/\"exports\" or index.js).\n */\nfunction resolveEntryPoint(dirPath: string): string {\n const pkgPath = join(dirPath, 'package.json');\n if (existsSync(pkgPath)) {\n try {\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));\n // Check exports first, then module, then main; only string entries are\n // usable paths — condition objects without them fall through to the\n // next field (otherwise we would return the directory itself, which\n // dynamic import() rejects)\n if (pkg.exports) {\n // exports may use the sugar form with conditions at the top level\n // instead of a '.' subpath map\n const dotExport = pkg.exports['.'] ?? pkg.exports;\n if (typeof dotExport === 'string') {\n return join(dirPath, dotExport);\n }\n if (typeof dotExport?.import === 'string') {\n return join(dirPath, dotExport.import);\n }\n if (typeof dotExport?.import?.default === 'string') {\n return join(dirPath, dotExport.import.default);\n }\n if (typeof dotExport?.default === 'string') {\n return join(dirPath, dotExport.default);\n }\n }\n if (pkg.module) {\n return join(dirPath, pkg.module);\n }\n if (pkg.main) {\n return join(dirPath, pkg.main);\n }\n } catch {\n // fall through to index.js\n }\n }\n return join(dirPath, 'index.js');\n}\n\n/**\n * Dynamically imports a module (supports ESM plugins).\n * Falls back from require() to import() for ESM compatibility.\n * @param {*} path the module's path\n * @return {Object}\n */\nexport async function tryLoadAsync<T>(path: string, onError: any): Promise<PluginType<T> | null> {\n // Try require first (handles CJS and will be fast)\n try {\n const cjsResult = tryLoad<T>(path, onError);\n if (cjsResult !== null) {\n return cjsResult;\n }\n } catch (err: any) {\n // tryLoad() returns null for the not-found / ESM cases and only throws on\n // a real load error (the plugin itself failed to evaluate); retrying via\n // import() would run the plugin's side effects twice and mask the error\n debug('require() threw a real load error for %s: %s', path, err.message);\n throw err;\n }\n\n // Fallback to dynamic import for ESM modules\n // import() doesn't support directory imports — resolve the entry point,\n // also for manifest-less directory plugins that only ship an index.js\n let importPath = path;\n try {\n if (\n isAbsolute(path) &&\n (existsSync(join(path, 'package.json')) || existsSync(join(path, 'index.js')))\n ) {\n importPath = resolveEntryPoint(path);\n debug('resolved ESM entry point: %s', importPath);\n }\n\n // Convert to file URL for import() compatibility (isAbsolute also covers\n // Windows paths like C:\\..., which startsWith('/') would miss)\n const importUrl = isAbsolute(importPath) ? pathToFileURL(importPath).href : importPath;\n debug('trying dynamic import for plugin %s', importUrl);\n const module = await import(importUrl);\n debug('dynamic import succeeded for plugin %s', importUrl);\n return module as PluginType<T>;\n } catch (err: any) {\n if (err.code === 'ERR_UNSUPPORTED_DIR_IMPORT') {\n // only the plugin path itself is ever imported as a directory\n debug('\"import\" failed for plugin %s', path);\n return null;\n }\n if (err.code === MODULE_NOT_FOUND || err.code === 'ERR_MODULE_NOT_FOUND') {\n // \"not found\" may refer to the plugin itself (plugin not installed:\n // return null) or to a missing dependency inside an existing plugin —\n // a real load error that must surface, mirroring the require() path\n // the missing specifier may be reported as a file:// URL\n const missingRaw = /Cannot find (?:module|package) '([^']+)'/.exec(err.message)?.[1];\n const missing = missingRaw?.startsWith('file://') ? fileURLToPath(missingRaw) : missingRaw;\n const refersToPlugin =\n missing === undefined ||\n missing === path ||\n missing === importPath ||\n missing.startsWith(path);\n if (refersToPlugin) {\n debug('\"import\" failed for plugin %s', path);\n return null;\n }\n debug('plugin %s exists but its dependency %s is missing', path, missing);\n }\n onError({ err: err.message }, 'error loading plugin @{err}');\n throw err;\n }\n}\n"],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EACzD,OAAO;CACT,SAAS,KAAU;EACjB,IAAI,IAAI,SAAS,8BAA8B;GAE7C,QAAM,mCAAiC,IAAI;GAC3C,OAAO;EACT;EACA,IAAI,IAAI,SAAS,oBAAoB,IAAI,SAAS,wBAAwB;GAKxE,MAAM,aAAa,2CAA2C,KAAK,IAAI,OAAO,IAAI;GAClF,MAAM,UAAU,YAAY,WAAW,SAAS,KAAA,GAAA,SAAA,eAAkB,UAAU,IAAI;GAMhF,IAJE,YAAY,KAAA,KACZ,YAAY,QACZ,YAAY,cACZ,QAAQ,WAAW,IAAI,GACL;IAClB,QAAM,mCAAiC,IAAI;IAC3C,OAAO;GACT;GACA,QAAM,qDAAqD,MAAM,OAAO;EAC1E;EACA,QAAQ,EAAE,KAAK,IAAI,QAAQ,GAAG,6BAA6B;EAC3D,MAAM;CACR;AACF"}
|
package/build/utils.mjs
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import buildDebug from "debug";
|
|
2
|
+
import _ from "lodash";
|
|
3
|
+
import { isAbsolute, join } from "node:path";
|
|
4
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
5
|
+
import { createRequire } from "node:module";
|
|
6
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
7
|
+
//#region src/utils.ts
|
|
8
|
+
var debug = buildDebug("verdaccio:plugin:loader:utils");
|
|
9
|
+
var MODULE_NOT_FOUND = "MODULE_NOT_FOUND";
|
|
10
|
+
var ERR_REQUIRE_ESM = "ERR_REQUIRE_ESM";
|
|
11
|
+
var ERR_REQUIRE_ASYNC_MODULE = "ERR_REQUIRE_ASYNC_MODULE";
|
|
12
|
+
var requireModule = import.meta.url ? createRequire(import.meta.url) : createRequire(__filename);
|
|
13
|
+
function isValid(plugin) {
|
|
14
|
+
return _.isFunction(plugin) || _.isFunction(plugin.default);
|
|
15
|
+
}
|
|
16
|
+
function isES6(plugin) {
|
|
17
|
+
return Object.keys(plugin).includes("default");
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Requires a module.
|
|
21
|
+
* @param {*} path the module's path
|
|
22
|
+
* @return {Object}
|
|
23
|
+
*/
|
|
24
|
+
function tryLoad(path, onError) {
|
|
25
|
+
try {
|
|
26
|
+
debug("loading plugin %s", path);
|
|
27
|
+
return requireModule(path);
|
|
28
|
+
} catch (err) {
|
|
29
|
+
if (err.code === MODULE_NOT_FOUND) {
|
|
30
|
+
debug("\"require\" failed for plugin %s", path);
|
|
31
|
+
const message = err.message.replace(/\\\\/g, "\\").split("\n");
|
|
32
|
+
if (!message[0].includes(path)) {
|
|
33
|
+
debug("%o", message[0]);
|
|
34
|
+
debug("%o", message.slice(1));
|
|
35
|
+
onError({ err: err.message }, "error loading plugin @{err}");
|
|
36
|
+
throw err;
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
if (err.code === ERR_REQUIRE_ESM || err.code === ERR_REQUIRE_ASYNC_MODULE) {
|
|
41
|
+
debug("\"require\" failed for ESM plugin %s, will try dynamic import", path);
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
onError({ err: err.message }, "error loading plugin @{err}");
|
|
45
|
+
throw err;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Resolve the entry point for a directory-based plugin.
|
|
50
|
+
* dynamic import() does not support directory imports, so we need to
|
|
51
|
+
* find the actual file to import (via package.json "main"/"exports" or index.js).
|
|
52
|
+
*/
|
|
53
|
+
function resolveEntryPoint(dirPath) {
|
|
54
|
+
const pkgPath = join(dirPath, "package.json");
|
|
55
|
+
if (existsSync(pkgPath)) try {
|
|
56
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
57
|
+
if (pkg.exports) {
|
|
58
|
+
const dotExport = pkg.exports["."] ?? pkg.exports;
|
|
59
|
+
if (typeof dotExport === "string") return join(dirPath, dotExport);
|
|
60
|
+
if (typeof dotExport?.import === "string") return join(dirPath, dotExport.import);
|
|
61
|
+
if (typeof dotExport?.import?.default === "string") return join(dirPath, dotExport.import.default);
|
|
62
|
+
if (typeof dotExport?.default === "string") return join(dirPath, dotExport.default);
|
|
63
|
+
}
|
|
64
|
+
if (pkg.module) return join(dirPath, pkg.module);
|
|
65
|
+
if (pkg.main) return join(dirPath, pkg.main);
|
|
66
|
+
} catch {}
|
|
67
|
+
return join(dirPath, "index.js");
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Dynamically imports a module (supports ESM plugins).
|
|
71
|
+
* Falls back from require() to import() for ESM compatibility.
|
|
72
|
+
* @param {*} path the module's path
|
|
73
|
+
* @return {Object}
|
|
74
|
+
*/
|
|
75
|
+
async function tryLoadAsync(path, onError) {
|
|
76
|
+
try {
|
|
77
|
+
const cjsResult = tryLoad(path, onError);
|
|
78
|
+
if (cjsResult !== null) return cjsResult;
|
|
79
|
+
} catch (err) {
|
|
80
|
+
debug("require() threw a real load error for %s: %s", path, err.message);
|
|
81
|
+
throw err;
|
|
82
|
+
}
|
|
83
|
+
let importPath = path;
|
|
84
|
+
try {
|
|
85
|
+
if (isAbsolute(path) && (existsSync(join(path, "package.json")) || existsSync(join(path, "index.js")))) {
|
|
86
|
+
importPath = resolveEntryPoint(path);
|
|
87
|
+
debug("resolved ESM entry point: %s", importPath);
|
|
88
|
+
}
|
|
89
|
+
const importUrl = isAbsolute(importPath) ? pathToFileURL(importPath).href : importPath;
|
|
90
|
+
debug("trying dynamic import for plugin %s", importUrl);
|
|
91
|
+
const module = await import(importUrl);
|
|
92
|
+
debug("dynamic import succeeded for plugin %s", importUrl);
|
|
93
|
+
return module;
|
|
94
|
+
} catch (err) {
|
|
95
|
+
if (err.code === "ERR_UNSUPPORTED_DIR_IMPORT") {
|
|
96
|
+
debug("\"import\" failed for plugin %s", path);
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
if (err.code === MODULE_NOT_FOUND || err.code === "ERR_MODULE_NOT_FOUND") {
|
|
100
|
+
const missingRaw = /Cannot find (?:module|package) '([^']+)'/.exec(err.message)?.[1];
|
|
101
|
+
const missing = missingRaw?.startsWith("file://") ? fileURLToPath(missingRaw) : missingRaw;
|
|
102
|
+
if (missing === void 0 || missing === path || missing === importPath || missing.startsWith(path)) {
|
|
103
|
+
debug("\"import\" failed for plugin %s", path);
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
debug("plugin %s exists but its dependency %s is missing", path, missing);
|
|
107
|
+
}
|
|
108
|
+
onError({ err: err.message }, "error loading plugin @{err}");
|
|
109
|
+
throw err;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
//#endregion
|
|
113
|
+
export { isES6, isValid, tryLoadAsync };
|
|
114
|
+
|
|
115
|
+
//# 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';\nimport { existsSync, readFileSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport { isAbsolute, join } from 'node:path';\nimport { fileURLToPath, pathToFileURL } from 'node:url';\n\nimport type { pluginUtils } from '@verdaccio/core';\n\nconst debug = buildDebug('verdaccio:plugin:loader:utils');\nconst MODULE_NOT_FOUND = 'MODULE_NOT_FOUND';\nconst ERR_REQUIRE_ESM = 'ERR_REQUIRE_ESM';\n// thrown by require(esm) when the module uses top-level await\nconst ERR_REQUIRE_ASYNC_MODULE = 'ERR_REQUIRE_ASYNC_MODULE';\n\n// the ESM build has no ambient require; create one so CJS plugins keep loading.\n// rolldown rewrites bare `require` to a throwing stub in the ESM output and\n// lowers `import.meta` to `{}` in the CJS output, so `import.meta.url` is only\n// truthy in the ESM build; module-scoped __filename covers the CJS build\n// (checking `typeof __filename`/`typeof require` instead is unsafe: node -e and\n// the REPL leak both as globals into ESM modules)\nconst requireModule = import.meta.url ? createRequire(import.meta.url) : createRequire(__filename);\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 requireModule(path) as PluginType<T>;\n } catch (err: any) {\n if (err.code === MODULE_NOT_FOUND) {\n debug('\"require\" failed for plugin %s', path);\n const message = err.message.replace(/\\\\\\\\/g, '\\\\').split('\\n');\n if (!message[0].includes(path)) {\n // the plugin itself was found but one of its own dependencies is\n // missing: that is a real load error — reporting \"not found\" (and\n // re-evaluating the plugin through the import() fallback) would mask\n // the actual cause and run its side effects twice\n debug('%o', message[0]); // error message\n debug('%o', message.slice(1)); // stack trace\n onError({ err: err.message }, 'error loading plugin @{err}');\n throw err;\n }\n return null;\n }\n if (err.code === ERR_REQUIRE_ESM || err.code === ERR_REQUIRE_ASYNC_MODULE) {\n debug('\"require\" failed for ESM plugin %s, will try dynamic import', path);\n return null;\n }\n onError({ err: err.message }, 'error loading plugin @{err}');\n throw err;\n }\n}\n\n/**\n * Resolve the entry point for a directory-based plugin.\n * dynamic import() does not support directory imports, so we need to\n * find the actual file to import (via package.json \"main\"/\"exports\" or index.js).\n */\nfunction resolveEntryPoint(dirPath: string): string {\n const pkgPath = join(dirPath, 'package.json');\n if (existsSync(pkgPath)) {\n try {\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));\n // Check exports first, then module, then main; only string entries are\n // usable paths — condition objects without them fall through to the\n // next field (otherwise we would return the directory itself, which\n // dynamic import() rejects)\n if (pkg.exports) {\n // exports may use the sugar form with conditions at the top level\n // instead of a '.' subpath map\n const dotExport = pkg.exports['.'] ?? pkg.exports;\n if (typeof dotExport === 'string') {\n return join(dirPath, dotExport);\n }\n if (typeof dotExport?.import === 'string') {\n return join(dirPath, dotExport.import);\n }\n if (typeof dotExport?.import?.default === 'string') {\n return join(dirPath, dotExport.import.default);\n }\n if (typeof dotExport?.default === 'string') {\n return join(dirPath, dotExport.default);\n }\n }\n if (pkg.module) {\n return join(dirPath, pkg.module);\n }\n if (pkg.main) {\n return join(dirPath, pkg.main);\n }\n } catch {\n // fall through to index.js\n }\n }\n return join(dirPath, 'index.js');\n}\n\n/**\n * Dynamically imports a module (supports ESM plugins).\n * Falls back from require() to import() for ESM compatibility.\n * @param {*} path the module's path\n * @return {Object}\n */\nexport async function tryLoadAsync<T>(path: string, onError: any): Promise<PluginType<T> | null> {\n // Try require first (handles CJS and will be fast)\n try {\n const cjsResult = tryLoad<T>(path, onError);\n if (cjsResult !== null) {\n return cjsResult;\n }\n } catch (err: any) {\n // tryLoad() returns null for the not-found / ESM cases and only throws on\n // a real load error (the plugin itself failed to evaluate); retrying via\n // import() would run the plugin's side effects twice and mask the error\n debug('require() threw a real load error for %s: %s', path, err.message);\n throw err;\n }\n\n // Fallback to dynamic import for ESM modules\n // import() doesn't support directory imports — resolve the entry point,\n // also for manifest-less directory plugins that only ship an index.js\n let importPath = path;\n try {\n if (\n isAbsolute(path) &&\n (existsSync(join(path, 'package.json')) || existsSync(join(path, 'index.js')))\n ) {\n importPath = resolveEntryPoint(path);\n debug('resolved ESM entry point: %s', importPath);\n }\n\n // Convert to file URL for import() compatibility (isAbsolute also covers\n // Windows paths like C:\\..., which startsWith('/') would miss)\n const importUrl = isAbsolute(importPath) ? pathToFileURL(importPath).href : importPath;\n debug('trying dynamic import for plugin %s', importUrl);\n const module = await import(importUrl);\n debug('dynamic import succeeded for plugin %s', importUrl);\n return module as PluginType<T>;\n } catch (err: any) {\n if (err.code === 'ERR_UNSUPPORTED_DIR_IMPORT') {\n // only the plugin path itself is ever imported as a directory\n debug('\"import\" failed for plugin %s', path);\n return null;\n }\n if (err.code === MODULE_NOT_FOUND || err.code === 'ERR_MODULE_NOT_FOUND') {\n // \"not found\" may refer to the plugin itself (plugin not installed:\n // return null) or to a missing dependency inside an existing plugin —\n // a real load error that must surface, mirroring the require() path\n // the missing specifier may be reported as a file:// URL\n const missingRaw = /Cannot find (?:module|package) '([^']+)'/.exec(err.message)?.[1];\n const missing = missingRaw?.startsWith('file://') ? fileURLToPath(missingRaw) : missingRaw;\n const refersToPlugin =\n missing === undefined ||\n missing === path ||\n missing === importPath ||\n missing.startsWith(path);\n if (refersToPlugin) {\n debug('\"import\" failed for plugin %s', path);\n return null;\n }\n debug('plugin %s exists but its dependency %s is missing', path, missing);\n }\n onError({ err: err.message }, 'error loading plugin @{err}');\n throw err;\n }\n}\n"],"mappings":";;;;;;;AASA,IAAM,QAAQ,WAAW,+BAA+B;AACxD,IAAM,mBAAmB;AACzB,IAAM,kBAAkB;AAExB,IAAM,2BAA2B;AAQjC,IAAM,gBAAgB,OAAO,KAAK,MAAM,cAAc,OAAO,KAAK,GAAG,IAAI,cAAc,UAAU;AAIjG,SAAgB,QAAW,QAAgC;CAEzD,OAAO,EAAE,WAAW,MAAM,KAAK,EAAE,WAAW,OAAO,OAAO;AAC5D;AAEA,SAAgB,MAAS,QAAgC;CACvD,OAAO,OAAO,KAAK,MAAM,EAAE,SAAS,SAAS;AAC/C;;;;;;AAOA,SAAgB,QAAW,MAAc,SAAoC;CAC3E,IAAI;EACF,MAAM,qBAAqB,IAAI;EAC/B,OAAO,cAAc,IAAI;CAC3B,SAAS,KAAU;EACjB,IAAI,IAAI,SAAS,kBAAkB;GACjC,MAAM,oCAAkC,IAAI;GAC5C,MAAM,UAAU,IAAI,QAAQ,QAAQ,SAAS,IAAI,EAAE,MAAM,IAAI;GAC7D,IAAI,CAAC,QAAQ,GAAG,SAAS,IAAI,GAAG;IAK9B,MAAM,MAAM,QAAQ,EAAE;IACtB,MAAM,MAAM,QAAQ,MAAM,CAAC,CAAC;IAC5B,QAAQ,EAAE,KAAK,IAAI,QAAQ,GAAG,6BAA6B;IAC3D,MAAM;GACR;GACA,OAAO;E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MAAM,YAAY,WAAW,UAAU,IAAI,cAAc,UAAU,EAAE,OAAO;EAC5E,MAAM,uCAAuC,SAAS;EACtD,MAAM,SAAS,MAAM,OAAO;EAC5B,MAAM,0CAA0C,SAAS;EACzD,OAAO;CACT,SAAS,KAAU;EACjB,IAAI,IAAI,SAAS,8BAA8B;GAE7C,MAAM,mCAAiC,IAAI;GAC3C,OAAO;EACT;EACA,IAAI,IAAI,SAAS,oBAAoB,IAAI,SAAS,wBAAwB;GAKxE,MAAM,aAAa,2CAA2C,KAAK,IAAI,OAAO,IAAI;GAClF,MAAM,UAAU,YAAY,WAAW,SAAS,IAAI,cAAc,UAAU,IAAI;GAMhF,IAJE,YAAY,KAAA,KACZ,YAAY,QACZ,YAAY,cACZ,QAAQ,WAAW,IAAI,GACL;IAClB,MAAM,mCAAiC,IAAI;IAC3C,OAAO;GACT;GACA,MAAM,qDAAqD,MAAM,OAAO;EAC1E;EACA,QAAQ,EAAE,KAAK,IAAI,QAAQ,GAAG,6BAA6B;EAC3D,MAAM;CACR;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verdaccio/loaders",
|
|
3
|
-
"version": "8.0
|
|
3
|
+
"version": "8.1.0",
|
|
4
4
|
"description": "Verdaccio Loader Logic",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"enterprise",
|
|
@@ -32,30 +32,43 @@
|
|
|
32
32
|
"url": "https://opencollective.com/verdaccio"
|
|
33
33
|
},
|
|
34
34
|
"main": "./build/index.js",
|
|
35
|
-
"
|
|
35
|
+
"module": "./build/index.mjs",
|
|
36
|
+
"types": "./build/index.d.ts",
|
|
37
|
+
"exports": {
|
|
38
|
+
".": {
|
|
39
|
+
"import": {
|
|
40
|
+
"types": "./build/index.d.ts",
|
|
41
|
+
"default": "./build/index.mjs"
|
|
42
|
+
},
|
|
43
|
+
"require": {
|
|
44
|
+
"types": "./build/index.d.ts",
|
|
45
|
+
"default": "./build/index.js"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"./build/*": "./build/*"
|
|
49
|
+
},
|
|
36
50
|
"dependencies": {
|
|
37
|
-
"@verdaccio/core": "8.
|
|
51
|
+
"@verdaccio/core": "8.2.0",
|
|
38
52
|
"debug": "4.4.3",
|
|
39
53
|
"lodash": "4.18.1"
|
|
40
54
|
},
|
|
41
55
|
"devDependencies": {
|
|
42
56
|
"@verdaccio-scope/verdaccio-auth-foo": "0.0.2",
|
|
43
|
-
"@verdaccio/config": "8.
|
|
44
|
-
"@verdaccio/core": "8.
|
|
45
|
-
"@verdaccio/logger": "8.0
|
|
57
|
+
"@verdaccio/config": "8.2.0",
|
|
58
|
+
"@verdaccio/core": "8.2.0",
|
|
59
|
+
"@verdaccio/logger": "8.1.0",
|
|
60
|
+
"vite": "8.0.16",
|
|
46
61
|
"vitest": "4.1.2",
|
|
47
|
-
"verdaccio-auth-memory": "13.0
|
|
62
|
+
"verdaccio-auth-memory": "13.1.0"
|
|
48
63
|
},
|
|
49
64
|
"engines": {
|
|
50
|
-
"node": ">=
|
|
65
|
+
"node": ">=22"
|
|
51
66
|
},
|
|
52
67
|
"scripts": {
|
|
53
68
|
"clean": "rimraf ./build",
|
|
54
69
|
"test": "vitest run",
|
|
55
70
|
"type-check": "tsc --noEmit -p tsconfig.build.json",
|
|
56
|
-
"
|
|
57
|
-
"build
|
|
58
|
-
"watch": "pnpm build:js -- --watch",
|
|
59
|
-
"build": "pnpm run build:js && pnpm run build:types"
|
|
71
|
+
"watch": "vite build --watch",
|
|
72
|
+
"build": "vite build && tsc --emitDeclarationOnly -p tsconfig.build.json"
|
|
60
73
|
}
|
|
61
74
|
}
|
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":[]}
|