@verdaccio/loaders 8.0.0-next-8.3 → 8.0.0-next-8.5

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.
Files changed (38) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +30 -25
  3. package/build/plugin-async-loader.d.ts +4 -8
  4. package/build/plugin-async-loader.js +17 -13
  5. package/build/plugin-async-loader.js.map +1 -1
  6. package/build/utils.js +9 -1
  7. package/build/utils.js.map +1 -1
  8. package/package.json +13 -9
  9. package/.babelrc +0 -3
  10. package/CHANGELOG.md +0 -900
  11. package/src/index.ts +0 -1
  12. package/src/plugin-async-loader.ts +0 -158
  13. package/src/utils.ts +0 -37
  14. package/test/partials/config/custom-prefix-auth.yaml +0 -3
  15. package/test/partials/config/npm-plugin-auth.yaml +0 -3
  16. package/test/partials/config/npm-plugin-not-found.yaml +0 -3
  17. package/test/partials/config/plugins-folder-fake.yaml +0 -4
  18. package/test/partials/config/relative-plugins.yaml +0 -4
  19. package/test/partials/config/scope-auth.yaml +0 -3
  20. package/test/partials/config/valid-plugin.yaml +0 -3
  21. package/test/partials/plugin/authenticate.fail.js +0 -11
  22. package/test/partials/plugin/authenticate.passthroug.js +0 -9
  23. package/test/partials/plugin/authenticate.success.js +0 -9
  24. package/test/partials/test-plugin-storage/.eslintrc +0 -6
  25. package/test/partials/test-plugin-storage/invalid-package/package.json +0 -11
  26. package/test/partials/test-plugin-storage/invalid-plugin/index.js +0 -1
  27. package/test/partials/test-plugin-storage/invalid-plugin/package.json +0 -11
  28. package/test/partials/test-plugin-storage/invalid-plugin-sanity/index.js +0 -9
  29. package/test/partials/test-plugin-storage/invalid-plugin-sanity/package.json +0 -11
  30. package/test/partials/test-plugin-storage/verdaccio-es6-plugin/dummy.js +0 -51
  31. package/test/partials/test-plugin-storage/verdaccio-es6-plugin/index.js +0 -18
  32. package/test/partials/test-plugin-storage/verdaccio-plugin/index.js +0 -7
  33. package/test/partials/test-plugin-storage/verdaccio-plugin/package.json +0 -11
  34. package/test/partials/test-plugin-storage/verdaccio-scope/index.js +0 -7
  35. package/test/partials/test-plugin-storage/verdaccio-scope/package.json +0 -11
  36. package/test/plugin_loader_async.spec.ts +0 -184
  37. package/tsconfig.build.json +0 -10
  38. package/tsconfig.json +0 -21
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 Verdaccio contributors
3
+ Copyright (c) 2025 Verdaccio contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,13 +1,19 @@
1
- # @verdaccio/loaders
1
+ # @verdaccio/loaders - Verdaccio Loader Logic
2
2
 
3
- [![backers](https://opencollective.com/verdaccio/tiers/backer/badge.svg?label=Backer&color=brightgreen)](https://opencollective.com/verdaccio)
4
- [![stackshare](https://img.shields.io/badge/Follow%20on-StackShare-blue.svg?logo=stackshare&style=flat)](https://stackshare.io/verdaccio)
5
- [![MIT](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/verdaccio/verdaccio/blob/master/LICENSE)
6
- [![Crowdin](https://d322cqt584bo4o.cloudfront.net/verdaccio/localized.svg)](https://crowdin.com/project/verdaccio)
7
- [![TODOs](https://badgen.net/https/api.tickgit.com/badgen/github.com/verdaccio/verdaccio)](https://www.tickgit.com/browse?repo=github.com/verdaccio/verdaccio)
3
+ [![Verdaccio Home](https://img.shields.io/badge/Homepage-Verdaccio-405236?style=flat)](https://verdaccio.org)
4
+ [![MIT License](https://img.shields.io/github/license/verdaccio/verdaccio?label=License&color=405236)](https://github.com/verdaccio/verdaccio/blob/master/LICENSE)
5
+ [![Verdaccio Latest](https://img.shields.io/npm/v/verdaccio?label=Latest%20Version&color=405236)](https://github.com/verdaccio/verdaccio)
6
+ [![This Package Latest](https://img.shields.io/npm/v/@verdaccio/loaders?label=@verdaccio/loaders&color=405236)](https://npmjs.com/package/@verdaccio/loaders)
8
7
 
9
- [![Twitter followers](https://img.shields.io/twitter/follow/verdaccio_npm.svg?style=social&label=Follow)](https://twitter.com/verdaccio_npm)
10
- [![Github](https://img.shields.io/github/stars/verdaccio/verdaccio.svg?style=social&label=Stars)](https://github.com/verdaccio/verdaccio/stargazers)
8
+ [![Documentation](https://img.shields.io/badge/Help-Verdaccio?style=flat&logo=Verdaccio&label=Verdaccio&color=cd4000)](https://verdaccio.org/docs)
9
+ [![Discord](https://img.shields.io/badge/Chat-Discord?style=flat&logo=Discord&label=Discord&color=cd4000)](https://discord.com/channels/388674437219745793)
10
+ [![Bluesky](https://img.shields.io/badge/Follow-Bluesky?style=flat&logo=Bluesky&label=Bluesky&color=cd4000)](https://bsky.app/profile/verdaccio.org)
11
+ [![Backers](https://img.shields.io/opencollective/backers/verdaccio?style=flat&logo=opencollective&label=Join%20Backers&color=cd4000)](https://opencollective.com/verdaccio/contribute)
12
+ [![Sponsors](https://img.shields.io/opencollective/sponsors/verdaccio?style=flat&logo=opencollective&label=Sponsor%20Us&color=cd4000)](https://opencollective.com/verdaccio/contribute)
13
+
14
+ [![Verdaccio Downloads](https://img.shields.io/npm/dm/verdaccio?style=flat&logo=npm&label=Npm%20Downloads&color=lightgrey)](https://www.npmjs.com/package/verdaccio)
15
+ [![Docker Pulls](https://img.shields.io/docker/pulls/verdaccio/verdaccio?style=flat&logo=docker&label=Docker%20Pulls&color=lightgrey)](https://hub.docker.com/r/verdaccio/verdaccio)
16
+ [![GitHub Stars](https://img.shields.io/github/stars/verdaccio?style=flat&logo=github&label=GitHub%20Stars%20%E2%AD%90&color=lightgrey)](https://github.com/verdaccio/verdaccio/stargazers)
11
17
 
12
18
  ## Donations
13
19
 
@@ -21,7 +27,7 @@ If you want to report a security vulnerability, please follow the steps which we
21
27
 
22
28
  ## Open Collective Sponsors
23
29
 
24
- Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/verdaccio#sponsor)]
30
+ Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/verdaccio/contribute)]
25
31
 
26
32
  [![sponsor](https://opencollective.com/verdaccio/sponsor/0/avatar.svg)](https://opencollective.com/verdaccio/sponsor/0/website)
27
33
  [![sponsor](https://opencollective.com/verdaccio/sponsor/1/avatar.svg)](https://opencollective.com/verdaccio/sponsor/1/website)
@@ -36,40 +42,39 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
36
42
 
37
43
  ## Open Collective Backers
38
44
 
39
- Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/verdaccio#backer)]
45
+ Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/verdaccio/contribute)]
40
46
 
41
- [![backers](https://opencollective.com/verdaccio/backers.svg?width=890)](https://opencollective.com/verdaccio#backers)
47
+ [![backers](https://opencollective.com/verdaccio/backers.svg?width=890)](https://opencollective.com/verdaccio/contributes)
42
48
 
43
49
  ## Special Thanks
44
50
 
45
51
  Thanks to the following companies to help us to achieve our goals providing free open source licenses.
46
52
 
47
- [![jetbrain](assets/thanks/jetbrains/logo.png)](https://www.jetbrains.com/)
48
- [![crowdin](assets/thanks/crowdin/logo.png)](https://crowdin.com/)
49
- [![balsamiq](assets/thanks/balsamiq/logo.jpg)](https://balsamiq.com/)
53
+ [![jetbrains](https://github.com/verdaccio/verdaccio/blob/master/assets/thanks/jetbrains/logo.jpg?raw=true)](https://www.jetbrains.com/)
54
+ [![crowdin](https://github.com/verdaccio/verdaccio/blob/master/assets/thanks/crowdin/logo.png?raw=true)](https://crowdin.com/)
50
55
 
51
56
  ## Contributors
52
57
 
53
- This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
58
+ This project exists thanks to all the people who contribute. [[Contribute](https://github.com/verdaccio/verdaccio/blob/master/CONTRIBUTING.md)].
54
59
 
55
- [![contributors](https://opencollective.com/verdaccio/contributors.svg?width=890&button=true)](../../graphs/contributors)
60
+ [![contributors](https://opencollective.com/verdaccio/contributors.svg?width=890&button=true)](https://github.com/verdaccio/verdaccio/graphs/contributors)
56
61
 
57
- ### FAQ / Contact / Troubleshoot
62
+ ## FAQ / Contact / Troubleshoot
58
63
 
59
- If you have any issue you can try the following options, do no desist to ask or check our issues database, perhaps someone has asked already what you are looking for.
64
+ If you have any issue you can try the following options. Do not hesitate to ask or check our issues database. Perhaps someone has asked already what you are looking for.
60
65
 
61
66
  - [Blog](https://verdaccio.org/blog/)
62
67
  - [Donations](https://opencollective.com/verdaccio)
63
68
  - [Reporting an issue](https://github.com/verdaccio/verdaccio/blob/master/CONTRIBUTING.md#reporting-a-bug)
64
- - [Running discussions](https://github.com/verdaccio/verdaccio/issues?q=is%3Aissue+is%3Aopen+label%3Adiscuss)
65
- - [Chat](http://chat.verdaccio.org/)
66
- - [Logos](https://verdaccio.org/docs/en/logo)
67
- - [Docker Examples](https://github.com/verdaccio/docker-examples)
69
+ - [Running discussions](https://github.com/orgs/verdaccio/discussions)
70
+ - [Chat](https://discord.com/channels/388674437219745793)
71
+ - [Logos](https://verdaccio.org/docs/logo)
72
+ - [Docker Examples](https://github.com/verdaccio/verdaccio/tree/master/docker-examples)
68
73
  - [FAQ](https://github.com/verdaccio/verdaccio/issues?utf8=%E2%9C%93&q=is%3Aissue%20label%3Aquestion%20)
69
74
 
70
- ### License
75
+ ## License
71
76
 
72
77
  Verdaccio is [MIT licensed](https://github.com/verdaccio/verdaccio/blob/master/LICENSE)
73
78
 
74
- The Verdaccio documentation and logos (excluding /thanks, e.g., .md, .png, .sketch) files within the /assets folder) is
75
- [Creative Commons licensed](https://github.com/verdaccio/verdaccio/blob/master/LICENSE-docs).
79
+ The Verdaccio documentation and logos (excluding /thanks, e.g., .md, .png, .sketch files within the /assets folder) are
80
+ [Creative Commons licensed](https://creativecommons.org/licenses/by/4.0/).
@@ -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>;
@@ -18,6 +18,7 @@ async function isDirectory(pathFolder) {
18
18
  const stat = await lstat(pathFolder);
19
19
  return stat.isDirectory();
20
20
  }
21
+
21
22
  // type Plugins<T> =
22
23
  // | pluginUtils.Auth<T>
23
24
  // | pluginUtils.Storage<T>
@@ -40,20 +41,21 @@ async function isDirectory(pathFolder) {
40
41
  * The `params` is an object that contains the global configuration and the logger.
41
42
  *
42
43
  * @param {*} pluginConfigs the custom plugin section
43
- * @param {*} params a set of params to initialize the plugin
44
+ * @param {*} pluginOptions a set of options to initialize the plugin
44
45
  * @param {*} sanityCheck callback that check the shape that should fulfill the plugin
45
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
46
48
  * @return {Array} list of plugins
47
49
  */
48
- async function asyncLoadPlugin(pluginConfigs = {}, params, sanityCheck, prefix = 'verdaccio', pluginCategory = '') {
49
- const logger = params?.logger;
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);
@@ -79,13 +81,14 @@ async function asyncLoadPlugin(pluginConfigs = {}, params, sanityCheck, prefix =
79
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
86
  logger.error({
85
87
  content: externalFilePlugin
86
88
  }, "@{content} doesn't look like a valid plugin");
87
89
  continue;
88
90
  }
91
+ debug('>>> plugin is running and passed sanity check');
89
92
  plugins.push(plugin);
90
93
  logger.info({
91
94
  prefix,
@@ -104,20 +107,21 @@ async function asyncLoadPlugin(pluginConfigs = {}, params, sanityCheck, prefix =
104
107
  }
105
108
  if (typeof pluginId === 'string') {
106
109
  const isScoped = pluginId.startsWith('@') && pluginId.includes('/');
107
- debug('is scoped plugin %s', isScoped);
110
+ debug('is scoped plugin: %s', isScoped);
108
111
  const pluginName = isScoped ? pluginId : `${prefix}-${pluginId}`;
109
- debug('plugin pkg name %s', pluginName);
112
+ debug('plugin package name %s', pluginName);
110
113
  let plugin = (0, _utils.tryLoad)(pluginName, (a, b) => {
111
114
  logger.error(a, b);
112
115
  });
113
116
  if (plugin && (0, _utils.isValid)(plugin)) {
114
- plugin = executePlugin(plugin, pluginConfigs[pluginId], params);
117
+ plugin = executePlugin(plugin, pluginConfigs[pluginId], pluginOptions);
115
118
  if (!sanityCheck(plugin)) {
116
119
  logger.error({
117
120
  content: pluginName
118
121
  }, "@{content} doesn't look like a valid plugin");
119
122
  continue;
120
123
  }
124
+ debug('>>> plugin is running and passed sanity check');
121
125
  plugins.push(plugin);
122
126
  logger.info({
123
127
  prefix,
@@ -133,19 +137,19 @@ async function asyncLoadPlugin(pluginConfigs = {}, params, sanityCheck, prefix =
133
137
  }
134
138
  }
135
139
  }
136
- debug('plugin found %s', plugins.length);
140
+ debug('%o plugins found: %o', pluginCategory, plugins.length);
137
141
  return plugins;
138
142
  }
139
- function executePlugin(plugin, pluginConfig, params) {
143
+ function executePlugin(plugin, pluginConfig, pluginOptions) {
140
144
  if ((0, _utils.isES6)(plugin)) {
141
145
  debug('plugin is ES6');
142
146
  // @ts-expect-error no relevant for the code
143
147
  // eslint-disable-next-line new-cap
144
- return new plugin.default(pluginConfig, params);
148
+ return new plugin.default(pluginConfig, pluginOptions);
145
149
  } else {
146
150
  debug('plugin is commonJS');
147
151
  // @ts-expect-error improve this type
148
- return plugin(pluginConfig, params);
152
+ return plugin(pluginConfig, pluginOptions);
149
153
  }
150
154
  }
151
155
  //# sourceMappingURL=plugin-async-loader.js.map
@@ -1 +1 @@
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","params","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';\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 logger = params?.logger;\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 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;AAKA,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;AAIA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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U,CAAC;MACvC,IAAIf,MAAM,GAAG,IAAAC,cAAO,EAAIc,UAAU,EAAE,CAACb,CAAM,EAAEC,CAAM,KAAK;QACtDrB,MAAM,CAACW,KAAK,CAACS,CAAC,EAAEC,CAAC,CAAC;MACpB,CAAC,CAAC;MACF,IAAIH,MAAM,IAAI,IAAAI,cAAO,EAACJ,MAAM,CAAC,EAAE;QAC7BA,MAAM,GAAGK,aAAa,CAACL,MAAM,EAAEvB,aAAa,CAACW,QAAQ,CAAC,EAAEV,MAAM,CAAC;QAC/D,IAAI,CAACC,WAAW,CAACqB,MAAM,CAAC,EAAE;UACxBlB,MAAM,CAACW,KAAK,CAAC;YAAEa,OAAO,EAAES;UAAW,CAAC,EAAE,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,iBAAiB,EAAEmB,OAAO,CAAC6B,MAAM,CAAC;EACxC,OAAO7B,OAAO;AAChB;AAEO,SAASkB,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 debug('>>> plugin is running and passed sanity check');\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 debug('>>> plugin is running and passed sanity check');\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('%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): 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,IA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AAC6B,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/build/utils.js CHANGED
@@ -30,7 +30,15 @@ function tryLoad(path, onError) {
30
30
  return require(path);
31
31
  } catch (err) {
32
32
  if (err.code === MODULE_NOT_FOUND) {
33
- debug('plugin %s not found', path);
33
+ debug('"require" failed for plugin %s', path);
34
+ // If loading fails, because a dependency is missing,
35
+ // we want to log the error message and require stack
36
+ // to see where the missing dependency is.
37
+ const message = err.message.replace(/\\\\/g, '\\').split('\n');
38
+ if (!message[0].includes(path)) {
39
+ debug('%o', message[0]); // error message
40
+ debug('%o', message.slice(1)); // stack trace
41
+ }
34
42
  return null;
35
43
  }
36
44
  onError({
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","names":["_debug","_interopRequireDefault","require","_lodash","e","__esModule","default","debug","buildDebug","MODULE_NOT_FOUND","isValid","plugin","_","isFunction","isES6","Object","keys","includes","tryLoad","path","onError","err","code","msg"],"sources":["../src/utils.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport _ from 'lodash';\n\nimport { 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('plugin %s not found', path);\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;AAAuB,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAIvB,MAAMG,KAAK,GAAG,IAAAC,cAAU,EAAC,+BAA+B,CAAC;AACzD,MAAMC,gBAAgB,GAAG,kBAAkB;AAIpC,SAASC,OAAOA,CAAIC,MAAqB,EAAW;EACzD;EACA,OAAOC,eAAC,CAACC,UAAU,CAACF,MAAM,CAAC,IAAIC,eAAC,CAACC,UAAU,CAACF,MAAM,CAACL,OAAO,CAAC;AAC7D;AAEO,SAASQ,KAAKA,CAAIH,MAAqB,EAAW;EACvD,OAAOI,MAAM,CAACC,IAAI,CAACL,MAAM,CAAC,CAACM,QAAQ,CAAC,SAAS,CAAC;AAChD;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASC,OAAOA,CAAIC,IAAY,EAAEC,OAAY,EAAwB;EAC3E,IAAI;IACFb,KAAK,CAAC,mBAAmB,EAAEY,IAAI,CAAC;IAChC,OAAOjB,OAAO,CAACiB,IAAI,CAAC;EACtB,CAAC,CAAC,OAAOE,GAAQ,EAAE;IACjB,IAAIA,GAAG,CAACC,IAAI,KAAKb,gBAAgB,EAAE;MACjCF,KAAK,CAAC,qBAAqB,EAAEY,IAAI,CAAC;MAClC,OAAO,IAAI;IACb;IACAC,OAAO,CAAC;MAAEC,GAAG,EAAEA,GAAG,CAACE;IAAI,CAAC,EAAE,6BAA6B,CAAC;IACxD,MAAMF,GAAG;EACX;AACF","ignoreList":[]}
1
+ {"version":3,"file":"utils.js","names":["_debug","_interopRequireDefault","require","_lodash","e","__esModule","default","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 { 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;AA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EC,GAAG,EAAEA,GAAG,CAACM;IAAI,CAAC,EAAE,6BAA6B,CAAC;IACxD,MAAMN,GAAG;EACX;AACF","ignoreList":[]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@verdaccio/loaders",
3
- "version": "8.0.0-next-8.3",
4
- "description": "loaders logic",
3
+ "version": "8.0.0-next-8.5",
4
+ "description": "Verdaccio Loader Logic",
5
5
  "main": "./build/index.js",
6
6
  "types": "build/index.d.ts",
7
7
  "author": {
@@ -10,20 +10,24 @@
10
10
  },
11
11
  "repository": {
12
12
  "type": "https",
13
- "url": "https://github.com/verdaccio/verdaccio"
13
+ "url": "https://github.com/verdaccio/verdaccio",
14
+ "directory": "packages/loaders"
15
+ },
16
+ "bugs": {
17
+ "url": "https://github.com/verdaccio/verdaccio/issues"
14
18
  },
15
19
  "dependencies": {
16
- "debug": "4.3.7",
20
+ "debug": "4.4.0",
17
21
  "lodash": "4.17.21"
18
22
  },
19
23
  "devDependencies": {
20
- "@verdaccio/logger": "8.0.0-next-8.3",
21
- "@verdaccio/core": "8.0.0-next-8.3",
22
- "@verdaccio/config": "8.0.0-next-8.3",
23
- "@verdaccio/types": "13.0.0-next-8.1",
24
+ "@verdaccio/logger": "8.0.0-next-8.13",
25
+ "@verdaccio/core": "8.0.0-next-8.13",
26
+ "@verdaccio/config": "8.0.0-next-8.13",
27
+ "@verdaccio/types": "13.0.0-next-8.4",
24
28
  "@verdaccio-scope/verdaccio-auth-foo": "0.0.2",
25
29
  "customprefix-auth": "2.0.0",
26
- "verdaccio-auth-memory": "13.0.0-next-8.3"
30
+ "verdaccio-auth-memory": "13.0.0-next-8.13"
27
31
  },
28
32
  "homepage": "https://verdaccio.org",
29
33
  "keywords": [
package/.babelrc DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "extends": "../../.babelrc"
3
- }