@verdaccio/loaders 8.0.0-next-8.2 → 8.0.0-next-8.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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @verdaccio/loaders
2
2
 
3
+ ## 8.0.0-next-8.4
4
+
5
+ ### Patch Changes
6
+
7
+ - ba71932: chore(loader): fix types for plugin options
8
+
9
+ ## 8.0.0-next-8.3
10
+
11
+ ### Minor Changes
12
+
13
+ - 4afca90: chore: remove logger as dependency
14
+
3
15
  ## 8.0.0-next-8.2
4
16
 
5
17
  ### Minor Changes
@@ -1,10 +1,5 @@
1
1
  import { pluginUtils } from '@verdaccio/core';
2
- import { Config, Logger } from '@verdaccio/types';
3
2
  import { PluginType } from './utils';
4
- export type Params = {
5
- config: Config;
6
- logger: Logger;
7
- };
8
3
  /**
9
4
  * The plugin loader find recursively plugins, if one plugin fails is ignored and report the error to the logger.
10
5
  *
@@ -22,10 +17,11 @@ export type Params = {
22
17
  * The `params` is an object that contains the global configuration and the logger.
23
18
  *
24
19
  * @param {*} pluginConfigs the custom plugin section
25
- * @param {*} params a set of params to initialize the plugin
20
+ * @param {*} pluginOptions a set of options to initialize the plugin
26
21
  * @param {*} sanityCheck callback that check the shape that should fulfill the plugin
27
22
  * @param {*} prefix by default is verdaccio but can be override with config.server.pluginPrefix
23
+ * @param {*} pluginCategory the category of the plugin, eg: auth, storage, middleware
28
24
  * @return {Array} list of plugins
29
25
  */
30
- export declare function asyncLoadPlugin<T extends pluginUtils.Plugin<T>>(pluginConfigs: any, params: Params, sanityCheck: (plugin: PluginType<T>) => boolean, prefix?: string, pluginCategory?: string): Promise<PluginType<T>[]>;
31
- export declare function executePlugin<T>(plugin: PluginType<T>, pluginConfig: unknown, params: Params): PluginType<T>;
26
+ export declare function asyncLoadPlugin<T extends pluginUtils.Plugin<T>>(pluginConfigs: any, pluginOptions: pluginUtils.PluginOptions, sanityCheck: (plugin: PluginType<T>) => boolean, prefix?: string, pluginCategory?: string): Promise<PluginType<T>[]>;
27
+ export declare function executePlugin<T>(plugin: PluginType<T>, pluginConfig: unknown, pluginOptions: pluginUtils.PluginOptions): PluginType<T>;
@@ -8,7 +8,6 @@ exports.executePlugin = executePlugin;
8
8
  var _debug = _interopRequireDefault(require("debug"));
9
9
  var _fs = _interopRequireDefault(require("fs"));
10
10
  var _path = require("path");
11
- var _logger = require("@verdaccio/logger");
12
11
  var _utils = require("./utils");
13
12
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
13
  const debug = (0, _debug.default)('verdaccio:plugin:loader:async');
@@ -19,6 +18,7 @@ async function isDirectory(pathFolder) {
19
18
  const stat = await lstat(pathFolder);
20
19
  return stat.isDirectory();
21
20
  }
21
+
22
22
  // type Plugins<T> =
23
23
  // | pluginUtils.Auth<T>
24
24
  // | pluginUtils.Storage<T>
@@ -41,33 +41,35 @@ async function isDirectory(pathFolder) {
41
41
  * The `params` is an object that contains the global configuration and the logger.
42
42
  *
43
43
  * @param {*} pluginConfigs the custom plugin section
44
- * @param {*} params a set of params to initialize the plugin
44
+ * @param {*} pluginOptions a set of options to initialize the plugin
45
45
  * @param {*} sanityCheck callback that check the shape that should fulfill the plugin
46
46
  * @param {*} prefix by default is verdaccio but can be override with config.server.pluginPrefix
47
+ * @param {*} pluginCategory the category of the plugin, eg: auth, storage, middleware
47
48
  * @return {Array} list of plugins
48
49
  */
49
- async function asyncLoadPlugin(pluginConfigs = {}, params, sanityCheck, prefix = 'verdaccio', pluginCategory = '') {
50
+ async function asyncLoadPlugin(pluginConfigs = {}, pluginOptions, sanityCheck, prefix = 'verdaccio', pluginCategory = '') {
51
+ const logger = pluginOptions?.logger;
50
52
  const pluginsIds = Object.keys(pluginConfigs);
51
53
  const {
52
54
  config
53
- } = params;
55
+ } = pluginOptions;
54
56
  let plugins = [];
55
57
  for (let pluginId of pluginsIds) {
56
- debug('plugin %s', pluginId);
58
+ debug('looking for plugin %o', pluginId);
57
59
  if (typeof config.plugins === 'string') {
58
60
  let pluginsPath = config.plugins;
59
61
  debug('plugin path %s', pluginsPath);
60
62
  if (!(0, _path.isAbsolute)(pluginsPath)) {
61
63
  if (typeof config.config_path === 'string' && !config.configPath) {
62
- _logger.logger.error('configPath is missing and the legacy config.config_path is not available for loading plugins');
64
+ logger.error('configPath is missing and the legacy config.config_path is not available for loading plugins');
63
65
  }
64
66
  if (!config.configPath) {
65
- _logger.logger.error('config path property is required for loading plugins');
67
+ logger.error('config path property is required for loading plugins');
66
68
  continue;
67
69
  }
68
70
  pluginsPath = (0, _path.resolve)((0, _path.join)((0, _path.dirname)(config.configPath), pluginsPath));
69
71
  }
70
- _logger.logger.debug({
72
+ logger.debug({
71
73
  path: pluginsPath
72
74
  }, 'plugins folder defined, loading plugins from @{path} ');
73
75
  // throws if is not a directory
@@ -76,18 +78,18 @@ async function asyncLoadPlugin(pluginConfigs = {}, params, sanityCheck, prefix =
76
78
  const pluginDir = pluginsPath;
77
79
  const externalFilePlugin = (0, _path.resolve)(pluginDir, `${prefix}-${pluginId}`);
78
80
  let plugin = (0, _utils.tryLoad)(externalFilePlugin, (a, b) => {
79
- _logger.logger.error(a, b);
81
+ logger.error(a, b);
80
82
  });
81
83
  if (plugin && (0, _utils.isValid)(plugin)) {
82
- plugin = executePlugin(plugin, pluginConfigs[pluginId], params);
84
+ plugin = executePlugin(plugin, pluginConfigs[pluginId], pluginOptions);
83
85
  if (!sanityCheck(plugin)) {
84
- _logger.logger.error({
86
+ logger.error({
85
87
  content: externalFilePlugin
86
88
  }, "@{content} doesn't look like a valid plugin");
87
89
  continue;
88
90
  }
89
91
  plugins.push(plugin);
90
- _logger.logger.info({
92
+ logger.info({
91
93
  prefix,
92
94
  pluginId,
93
95
  pluginCategory
@@ -95,7 +97,7 @@ async function asyncLoadPlugin(pluginConfigs = {}, params, sanityCheck, prefix =
95
97
  continue;
96
98
  }
97
99
  } catch (err) {
98
- _logger.logger.warn({
100
+ logger.warn({
99
101
  err: err.message,
100
102
  pluginsPath,
101
103
  pluginId
@@ -104,48 +106,48 @@ async function asyncLoadPlugin(pluginConfigs = {}, params, sanityCheck, prefix =
104
106
  }
105
107
  if (typeof pluginId === 'string') {
106
108
  const isScoped = pluginId.startsWith('@') && pluginId.includes('/');
107
- debug('is scoped plugin %s', isScoped);
109
+ debug('is scoped plugin: %s', isScoped);
108
110
  const pluginName = isScoped ? pluginId : `${prefix}-${pluginId}`;
109
- debug('plugin pkg name %s', pluginName);
111
+ debug('plugin package name %s', pluginName);
110
112
  let plugin = (0, _utils.tryLoad)(pluginName, (a, b) => {
111
- _logger.logger.error(a, b);
113
+ logger.error(a, b);
112
114
  });
113
115
  if (plugin && (0, _utils.isValid)(plugin)) {
114
- plugin = executePlugin(plugin, pluginConfigs[pluginId], params);
116
+ plugin = executePlugin(plugin, pluginConfigs[pluginId], pluginOptions);
115
117
  if (!sanityCheck(plugin)) {
116
- _logger.logger.error({
118
+ logger.error({
117
119
  content: pluginName
118
120
  }, "@{content} doesn't look like a valid plugin");
119
121
  continue;
120
122
  }
121
123
  plugins.push(plugin);
122
- _logger.logger.info({
124
+ logger.info({
123
125
  prefix,
124
126
  pluginId,
125
127
  pluginCategory
126
128
  }, 'plugin @{prefix}-@{pluginId} successfully loaded (@{pluginCategory})');
127
129
  continue;
128
130
  } else {
129
- _logger.logger.error({
131
+ logger.error({
130
132
  pluginName
131
133
  }, 'package not found, try to install @{pluginName} with a package manager');
132
134
  continue;
133
135
  }
134
136
  }
135
137
  }
136
- debug('plugin found %s', plugins.length);
138
+ debug('%s plugins found: %s', pluginCategory, plugins.length);
137
139
  return plugins;
138
140
  }
139
- function executePlugin(plugin, pluginConfig, params) {
141
+ function executePlugin(plugin, pluginConfig, pluginOptions) {
140
142
  if ((0, _utils.isES6)(plugin)) {
141
143
  debug('plugin is ES6');
142
144
  // @ts-expect-error no relevant for the code
143
145
  // eslint-disable-next-line new-cap
144
- return new plugin.default(pluginConfig, params);
146
+ return new plugin.default(pluginConfig, pluginOptions);
145
147
  } else {
146
148
  debug('plugin is commonJS');
147
149
  // @ts-expect-error improve this type
148
- return plugin(pluginConfig, params);
150
+ return plugin(pluginConfig, pluginOptions);
149
151
  }
150
152
  }
151
153
  //# sourceMappingURL=plugin-async-loader.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin-async-loader.js","names":["_debug","_interopRequireDefault","require","_fs","_path","_logger","_utils","e","__esModule","default","debug","buildDebug","lstat","fs","promises","isDirectory","pathFolder","stat","asyncLoadPlugin","pluginConfigs","params","sanityCheck","prefix","pluginCategory","pluginsIds","Object","keys","config","plugins","pluginId","pluginsPath","isAbsolute","config_path","configPath","logger","error","resolve","join","dirname","path","pluginDir","externalFilePlugin","plugin","tryLoad","a","b","isValid","executePlugin","content","push","info","err","warn","message","isScoped","startsWith","includes","pluginName","length","pluginConfig","isES6"],"sources":["../src/plugin-async-loader.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport fs from 'fs';\nimport { dirname, isAbsolute, join, resolve } from 'path';\n\nimport { pluginUtils } from '@verdaccio/core';\nimport { logger } from '@verdaccio/logger';\nimport { Config, Logger } from '@verdaccio/types';\n\nimport { PluginType, isES6, isValid, tryLoad } from './utils';\n\nconst debug = buildDebug('verdaccio:plugin:loader:async');\n\nconst { lstat } = fs.promises ? fs.promises : require('fs/promises');\n\nasync function isDirectory(pathFolder: string) {\n const stat = await lstat(pathFolder);\n return stat.isDirectory();\n}\n\nexport type Params = { config: Config; logger: Logger };\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.\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 {*} params a set of params 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 * @return {Array} list of plugins\n */\nexport async function asyncLoadPlugin<T extends pluginUtils.Plugin<T>>(\n pluginConfigs: any = {},\n params: Params,\n sanityCheck: (plugin: PluginType<T>) => boolean,\n prefix: string = 'verdaccio',\n pluginCategory: string = ''\n): Promise<PluginType<T>[]> {\n const pluginsIds = Object.keys(pluginConfigs);\n const { config } = params;\n let plugins: PluginType<T>[] = [];\n for (let pluginId of pluginsIds) {\n debug('plugin %s', pluginId);\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\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, `${prefix}-${pluginId}`);\n let plugin = tryLoad<T>(externalFilePlugin, (a: any, b: any) => {\n logger.error(a, b);\n });\n if (plugin && isValid(plugin)) {\n plugin = executePlugin(plugin, pluginConfigs[pluginId], params);\n if (!sanityCheck(plugin)) {\n logger.error(\n { content: externalFilePlugin },\n \"@{content} doesn't look like a valid plugin\"\n );\n continue;\n }\n plugins.push(plugin);\n logger.info(\n { prefix, pluginId, pluginCategory },\n 'plugin @{prefix}-@{pluginId} successfully loaded (@{pluginCategory})'\n );\n continue;\n }\n } catch (err: any) {\n logger.warn(\n { err: err.message, pluginsPath, pluginId },\n '@{err} on loading plugins at @{pluginsPath} for @{pluginId}'\n );\n }\n }\n\n if (typeof pluginId === 'string') {\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 pkg name %s', pluginName);\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], params);\n if (!sanityCheck(plugin)) {\n logger.error({ content: pluginName }, \"@{content} doesn't look like a valid plugin\");\n continue;\n }\n plugins.push(plugin);\n logger.info(\n { prefix, pluginId, pluginCategory },\n 'plugin @{prefix}-@{pluginId} 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('plugin found %s', plugins.length);\n return plugins;\n}\n\nexport function executePlugin<T>(\n plugin: PluginType<T>,\n pluginConfig: unknown,\n params: Params\n): PluginType<T> {\n if (isES6(plugin)) {\n debug('plugin is ES6');\n // @ts-expect-error no relevant for the code\n // eslint-disable-next-line new-cap\n return new plugin.default(pluginConfig, params) as Plugin;\n } else {\n debug('plugin is commonJS');\n // @ts-expect-error improve this type\n return plugin(pluginConfig, params) as PluginType<T>;\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,GAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AAGA,IAAAG,OAAA,GAAAH,OAAA;AAGA,IAAAI,MA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AAC8B,MAAM,CAAC;EACxC,OAAO9B,OAAO;AAChB;AAEO,SAASmB,aAAaA,CAC3BL,MAAqB,EACrBiB,YAAqB,EACrBvC,MAAc,EACC;EACf,IAAI,IAAAwC,YAAK,EAAClB,MAAM,CAAC,EAAE;IACjBhC,KAAK,CAAC,eAAe,CAAC;IACtB;IACA;IACA,OAAO,IAAIgC,MAAM,CAACjC,OAAO,CAACkD,YAAY,EAAEvC,MAAM,CAAC;EACjD,CAAC,MAAM;IACLV,KAAK,CAAC,oBAAoB,CAAC;IAC3B;IACA,OAAOgC,MAAM,CAACiB,YAAY,EAAEvC,MAAM,CAAC;EACrC;AACF","ignoreList":[]}
1
+ {"version":3,"file":"plugin-async-loader.js","names":["_debug","_interopRequireDefault","require","_fs","_path","_utils","e","__esModule","default","debug","buildDebug","lstat","fs","promises","isDirectory","pathFolder","stat","asyncLoadPlugin","pluginConfigs","pluginOptions","sanityCheck","prefix","pluginCategory","logger","pluginsIds","Object","keys","config","plugins","pluginId","pluginsPath","isAbsolute","config_path","configPath","error","resolve","join","dirname","path","pluginDir","externalFilePlugin","plugin","tryLoad","a","b","isValid","executePlugin","content","push","info","err","warn","message","isScoped","startsWith","includes","pluginName","length","pluginConfig","isES6"],"sources":["../src/plugin-async-loader.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport fs from 'fs';\nimport { dirname, isAbsolute, join, resolve } from 'path';\n\nimport { pluginUtils } from '@verdaccio/core';\n\nimport { PluginType, isES6, isValid, tryLoad } from './utils';\n\nconst debug = buildDebug('verdaccio:plugin:loader:async');\n\nconst { lstat } = fs.promises ? fs.promises : require('fs/promises');\n\nasync function isDirectory(pathFolder: string) {\n const stat = await lstat(pathFolder);\n return stat.isDirectory();\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.\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 prefix: string = 'verdaccio',\n pluginCategory: string = ''\n): Promise<PluginType<T>[]> {\n const logger = pluginOptions?.logger;\n const pluginsIds = Object.keys(pluginConfigs);\n const { config } = pluginOptions;\n let plugins: PluginType<T>[] = [];\n for (let pluginId of pluginsIds) {\n debug('looking for plugin %o', pluginId);\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, `${prefix}-${pluginId}`);\n let plugin = tryLoad<T>(externalFilePlugin, (a: any, b: any) => {\n logger.error(a, b);\n });\n if (plugin && isValid(plugin)) {\n plugin = executePlugin(plugin, pluginConfigs[pluginId], pluginOptions);\n if (!sanityCheck(plugin)) {\n logger.error(\n { content: externalFilePlugin },\n \"@{content} doesn't look like a valid plugin\"\n );\n continue;\n }\n plugins.push(plugin);\n logger.info(\n { prefix, pluginId, pluginCategory },\n 'plugin @{prefix}-@{pluginId} successfully loaded (@{pluginCategory})'\n );\n continue;\n }\n } catch (err: any) {\n logger.warn(\n { err: err.message, pluginsPath, pluginId },\n '@{err} on loading plugins at @{pluginsPath} for @{pluginId}'\n );\n }\n }\n\n if (typeof pluginId === 'string') {\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 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);\n if (!sanityCheck(plugin)) {\n logger.error({ content: pluginName }, \"@{content} doesn't look like a valid plugin\");\n continue;\n }\n plugins.push(plugin);\n logger.info(\n { prefix, pluginId, pluginCategory },\n 'plugin @{prefix}-@{pluginId} 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('%s plugins found: %s', pluginCategory, plugins.length);\n return plugins;\n}\n\nexport function executePlugin<T>(\n plugin: PluginType<T>,\n pluginConfig: unknown,\n pluginOptions: pluginUtils.PluginOptions\n): PluginType<T> {\n if (isES6(plugin)) {\n debug('plugin is ES6');\n // @ts-expect-error no relevant for the code\n // eslint-disable-next-line new-cap\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,GAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AAIA,IAAAG,MAAA,GAAAH,OAAA;AAA8D,SAAAD,uBAAAK,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAE9D,MAAMG,KAAK,GAAG,IAAAC,cAAU,EAAC,+BAA+B,CAAC;AAEzD,MAAM;EAAEC;AAAM,CAAC,GAAGC,WAAE,CAACC,QAAQ,GAAGD,WAAE,CAACC,QAAQ,GAAGX,OAAO,CAAC,aAAa,CAAC;AAEpE,eAAeY,WAAWA,CAACC,UAAkB,EAAE;EAC7C,MAAMC,IAAI,GAAG,MAAML,KAAK,CAACI,UAAU,CAAC;EACpC,OAAOC,IAAI,CAACF,WAAW,CAAC,CAAC;AAC3B;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAeG,eAAeA,CACnCC,aAAkB,GAAG,CAAC,CAAC,EACvBC,aAAwC,EACxCC,WAA+C,EAC/CC,MAAc,GAAG,WAAW,EAC5BC,cAAsB,GAAG,EAAE,EACD;EAC1B,MAAMC,MAAM,GAAGJ,aAAa,EAAEI,MAAM;EACpC,MAAMC,UAAU,GAAGC,MAAM,CAACC,IAAI,CAACR,aAAa,CAAC;EAC7C,MAAM;IAAES;EAAO,CAAC,GAAGR,aAAa;EAChC,IAAIS,OAAwB,GAAG,EAAE;EACjC,KAAK,IAAIC,QAAQ,IAAIL,UAAU,EAAE;IAC/Bf,KAAK,CAAC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AE,6CAA6C,CAAC;UACpF;QACF;QACA5B,OAAO,CAACoB,IAAI,CAACP,MAAM,CAAC;QACpBlB,MAAM,CAAC0B,IAAI,CACT;UAAE5B,MAAM;UAAEQ,QAAQ;UAAEP;QAAe,CAAC,EACpC,sEACF,CAAC;QACD;MACF,CAAC,MAAM;QACLC,MAAM,CAACW,KAAK,CACV;UAAEsB;QAAW,CAAC,EACd,wEACF,CAAC;QACD;MACF;IACF;EACF;EACA/C,KAAK,CAAC,sBAAsB,EAAEa,cAAc,EAAEM,OAAO,CAAC6B,MAAM,CAAC;EAC7D,OAAO7B,OAAO;AAChB;AAEO,SAASkB,aAAaA,CAC3BL,MAAqB,EACrBiB,YAAqB,EACrBvC,aAAwC,EACzB;EACf,IAAI,IAAAwC,YAAK,EAAClB,MAAM,CAAC,EAAE;IACjBhC,KAAK,CAAC,eAAe,CAAC;IACtB;IACA;IACA,OAAO,IAAIgC,MAAM,CAACjC,OAAO,CAACkD,YAAY,EAAEvC,aAAa,CAAC;EACxD,CAAC,MAAM;IACLV,KAAK,CAAC,oBAAoB,CAAC;IAC3B;IACA,OAAOgC,MAAM,CAACiB,YAAY,EAAEvC,aAAa,CAAC;EAC5C;AACF","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verdaccio/loaders",
3
- "version": "8.0.0-next-8.2",
3
+ "version": "8.0.0-next-8.4",
4
4
  "description": "loaders logic",
5
5
  "main": "./build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -13,17 +13,17 @@
13
13
  "url": "https://github.com/verdaccio/verdaccio"
14
14
  },
15
15
  "dependencies": {
16
- "@verdaccio/logger": "8.0.0-next-8.2",
17
16
  "debug": "4.3.7",
18
17
  "lodash": "4.17.21"
19
18
  },
20
19
  "devDependencies": {
21
- "@verdaccio/core": "8.0.0-next-8.2",
22
- "@verdaccio/config": "8.0.0-next-8.2",
23
- "@verdaccio/types": "13.0.0-next-8.1",
20
+ "@verdaccio/logger": "8.0.0-next-8.5",
21
+ "@verdaccio/core": "8.0.0-next-8.5",
22
+ "@verdaccio/config": "8.0.0-next-8.5",
23
+ "@verdaccio/types": "13.0.0-next-8.2",
24
24
  "@verdaccio-scope/verdaccio-auth-foo": "0.0.2",
25
25
  "customprefix-auth": "2.0.0",
26
- "verdaccio-auth-memory": "13.0.0-next-8.2"
26
+ "verdaccio-auth-memory": "13.0.0-next-8.5"
27
27
  },
28
28
  "homepage": "https://verdaccio.org",
29
29
  "keywords": [
@@ -3,8 +3,6 @@ import fs from 'fs';
3
3
  import { dirname, isAbsolute, join, resolve } from 'path';
4
4
 
5
5
  import { pluginUtils } from '@verdaccio/core';
6
- import { logger } from '@verdaccio/logger';
7
- import { Config, Logger } from '@verdaccio/types';
8
6
 
9
7
  import { PluginType, isES6, isValid, tryLoad } from './utils';
10
8
 
@@ -17,8 +15,6 @@ async function isDirectory(pathFolder: string) {
17
15
  return stat.isDirectory();
18
16
  }
19
17
 
20
- export type Params = { config: Config; logger: Logger };
21
-
22
18
  // type Plugins<T> =
23
19
  // | pluginUtils.Auth<T>
24
20
  // | pluginUtils.Storage<T>
@@ -41,23 +37,25 @@ export type Params = { config: Config; logger: Logger };
41
37
  * The `params` is an object that contains the global configuration and the logger.
42
38
  *
43
39
  * @param {*} pluginConfigs the custom plugin section
44
- * @param {*} params a set of params to initialize the plugin
40
+ * @param {*} pluginOptions a set of options to initialize the plugin
45
41
  * @param {*} sanityCheck callback that check the shape that should fulfill the plugin
46
42
  * @param {*} prefix by default is verdaccio but can be override with config.server.pluginPrefix
43
+ * @param {*} pluginCategory the category of the plugin, eg: auth, storage, middleware
47
44
  * @return {Array} list of plugins
48
45
  */
49
46
  export async function asyncLoadPlugin<T extends pluginUtils.Plugin<T>>(
50
47
  pluginConfigs: any = {},
51
- params: Params,
48
+ pluginOptions: pluginUtils.PluginOptions,
52
49
  sanityCheck: (plugin: PluginType<T>) => boolean,
53
50
  prefix: string = 'verdaccio',
54
51
  pluginCategory: string = ''
55
52
  ): Promise<PluginType<T>[]> {
53
+ const logger = pluginOptions?.logger;
56
54
  const pluginsIds = Object.keys(pluginConfigs);
57
- const { config } = params;
55
+ const { config } = pluginOptions;
58
56
  let plugins: PluginType<T>[] = [];
59
57
  for (let pluginId of pluginsIds) {
60
- debug('plugin %s', pluginId);
58
+ debug('looking for plugin %o', pluginId);
61
59
  if (typeof config.plugins === 'string') {
62
60
  let pluginsPath = config.plugins;
63
61
  debug('plugin path %s', pluginsPath);
@@ -74,7 +72,6 @@ export async function asyncLoadPlugin<T extends pluginUtils.Plugin<T>>(
74
72
  }
75
73
  pluginsPath = resolve(join(dirname(config.configPath), pluginsPath));
76
74
  }
77
-
78
75
  logger.debug({ path: pluginsPath }, 'plugins folder defined, loading plugins from @{path} ');
79
76
  // throws if is not a directory
80
77
  try {
@@ -85,7 +82,7 @@ export async function asyncLoadPlugin<T extends pluginUtils.Plugin<T>>(
85
82
  logger.error(a, b);
86
83
  });
87
84
  if (plugin && isValid(plugin)) {
88
- plugin = executePlugin(plugin, pluginConfigs[pluginId], params);
85
+ plugin = executePlugin(plugin, pluginConfigs[pluginId], pluginOptions);
89
86
  if (!sanityCheck(plugin)) {
90
87
  logger.error(
91
88
  { content: externalFilePlugin },
@@ -110,14 +107,14 @@ export async function asyncLoadPlugin<T extends pluginUtils.Plugin<T>>(
110
107
 
111
108
  if (typeof pluginId === 'string') {
112
109
  const isScoped: boolean = pluginId.startsWith('@') && pluginId.includes('/');
113
- debug('is scoped plugin %s', isScoped);
110
+ debug('is scoped plugin: %s', isScoped);
114
111
  const pluginName = isScoped ? pluginId : `${prefix}-${pluginId}`;
115
- debug('plugin pkg name %s', pluginName);
112
+ debug('plugin package name %s', pluginName);
116
113
  let plugin = tryLoad<T>(pluginName, (a: any, b: any) => {
117
114
  logger.error(a, b);
118
115
  });
119
116
  if (plugin && isValid(plugin)) {
120
- plugin = executePlugin(plugin, pluginConfigs[pluginId], params);
117
+ plugin = executePlugin(plugin, pluginConfigs[pluginId], pluginOptions);
121
118
  if (!sanityCheck(plugin)) {
122
119
  logger.error({ content: pluginName }, "@{content} doesn't look like a valid plugin");
123
120
  continue;
@@ -137,23 +134,23 @@ export async function asyncLoadPlugin<T extends pluginUtils.Plugin<T>>(
137
134
  }
138
135
  }
139
136
  }
140
- debug('plugin found %s', plugins.length);
137
+ debug('%s plugins found: %s', pluginCategory, plugins.length);
141
138
  return plugins;
142
139
  }
143
140
 
144
141
  export function executePlugin<T>(
145
142
  plugin: PluginType<T>,
146
143
  pluginConfig: unknown,
147
- params: Params
144
+ pluginOptions: pluginUtils.PluginOptions
148
145
  ): PluginType<T> {
149
146
  if (isES6(plugin)) {
150
147
  debug('plugin is ES6');
151
148
  // @ts-expect-error no relevant for the code
152
149
  // eslint-disable-next-line new-cap
153
- return new plugin.default(pluginConfig, params) as Plugin;
150
+ return new plugin.default(pluginConfig, pluginOptions) as Plugin;
154
151
  } else {
155
152
  debug('plugin is commonJS');
156
153
  // @ts-expect-error improve this type
157
- return plugin(pluginConfig, params) as PluginType<T>;
154
+ return plugin(pluginConfig, pluginOptions) as PluginType<T>;
158
155
  }
159
156
  }
@@ -0,0 +1,3 @@
1
+ store:
2
+ plugin-store:
3
+ enabled: true
@@ -0,0 +1,7 @@
1
+ function ValidVerdaccioPlugin() {
2
+ return {
3
+ getPackageStorage: function () {},
4
+ };
5
+ }
6
+
7
+ module.exports = ValidVerdaccioPlugin;
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "verdaccio-plugin",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "author": "",
10
+ "license": "ISC"
11
+ }
@@ -15,6 +15,9 @@ function getConfig(file: string) {
15
15
  const authSanitize = function (plugin) {
16
16
  return plugin.authenticate || plugin.allow_access || plugin.allow_publish;
17
17
  };
18
+ const storeSanitize = function (plugin) {
19
+ return typeof plugin.getPackageStorage !== 'undefined';
20
+ };
18
21
 
19
22
  const pluginsPartialsFolder = path.join(__dirname, './partials/test-plugin-storage');
20
23
 
@@ -31,13 +34,17 @@ describe('plugin loader', () => {
31
34
  expect(plugins).toHaveLength(1);
32
35
  });
33
36
 
37
+ test('testing storage valid plugin loader', async () => {
38
+ const config = getConfig('valid-plugin-store.yaml');
39
+ config.plugins = pluginsPartialsFolder;
40
+ const plugins = await asyncLoadPlugin(config.store, { config, logger }, storeSanitize);
41
+
42
+ expect(plugins).toHaveLength(1);
43
+ });
44
+
34
45
  test('should handle does not exist plugin folder', async () => {
35
46
  const config = getConfig('plugins-folder-fake.yaml');
36
- const plugins = await asyncLoadPlugin(
37
- config.auth,
38
- { logger: logger, config: config },
39
- authSanitize
40
- );
47
+ const plugins = await asyncLoadPlugin(config.auth, { config, logger }, authSanitize);
41
48
 
42
49
  expect(plugins).toHaveLength(0);
43
50
  });
@@ -59,11 +66,7 @@ describe('plugin loader', () => {
59
66
  const config = getConfig('plugins-folder-fake.yaml');
60
67
  // force file instead a folder.
61
68
  config.plugins = path.join(__dirname, 'just-a-file.js');
62
- const plugins = await asyncLoadPlugin(
63
- config.auth,
64
- { logger: logger, config: config },
65
- authSanitize
66
- );
69
+ const plugins = await asyncLoadPlugin(config.auth, { config, logger }, authSanitize);
67
70
 
68
71
  expect(plugins).toHaveLength(0);
69
72
  });
@@ -72,11 +75,7 @@ describe('plugin loader', () => {
72
75
  test('should resolve plugin based on relative path', async () => {
73
76
  const config = getConfig('relative-plugins.yaml');
74
77
  // force file instead a folder.
75
- const plugins = await asyncLoadPlugin(
76
- config.auth,
77
- { logger: logger, config: config },
78
- authSanitize
79
- );
78
+ const plugins = await asyncLoadPlugin(config.auth, { config, logger }, authSanitize);
80
79
 
81
80
  expect(plugins).toHaveLength(1);
82
81
  });
@@ -88,11 +87,7 @@ describe('plugin loader', () => {
88
87
  // @ts-expect-error
89
88
  config.config_path = undefined;
90
89
  // force file instead a folder.
91
- const plugins = await asyncLoadPlugin(
92
- config.auth,
93
- { logger: logger, config: config },
94
- authSanitize
95
- );
90
+ const plugins = await asyncLoadPlugin(config.auth, { config, logger }, authSanitize);
96
91
 
97
92
  expect(plugins).toHaveLength(0);
98
93
  });
@@ -103,11 +98,7 @@ describe('plugin loader', () => {
103
98
  // @ts-expect-error
104
99
  config.configPath = undefined;
105
100
  // force file instead a folder.
106
- const plugins = await asyncLoadPlugin(
107
- config.auth,
108
- { logger: logger, config: config },
109
- authSanitize
110
- );
101
+ const plugins = await asyncLoadPlugin(config.auth, { config, logger }, authSanitize);
111
102
 
112
103
  expect(plugins).toHaveLength(0);
113
104
  });