mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-16 21:56:25 -05:00
refactor: set plugin only plugin conf params
This commit is contained in:
parent
ed4c3cad29
commit
98ebd9ac5d
1 changed files with 17 additions and 21 deletions
|
@ -29,10 +29,6 @@ function isES6(plugin) {
|
|||
return Object.keys(plugin).includes('default');
|
||||
}
|
||||
|
||||
function mergeConfig(appConfig, pluginConfig) {
|
||||
return _.merge(appConfig, pluginConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a plugin following the rules
|
||||
* - First try to load from the internal directory plugins (which will disappear soon or later).
|
||||
|
@ -45,49 +41,49 @@ function mergeConfig(appConfig, pluginConfig) {
|
|||
* @return {Array} list of plugins
|
||||
*/
|
||||
function loadPlugin(config: Config, pluginConfigs: any, params: any, sanityCheck: Function) {
|
||||
return Object.keys(pluginConfigs || {}).map(function(p) {
|
||||
return Object.keys(pluginConfigs || {}).map(function(pluginId) {
|
||||
let plugin;
|
||||
|
||||
// try local plugins first
|
||||
plugin = tryLoad(Path.resolve(__dirname + '/..//plugins', p));
|
||||
plugin = tryLoad(Path.resolve(__dirname + '/..//plugins', pluginId));
|
||||
|
||||
// npm package
|
||||
if (plugin === null && p.match(/^[^\.\/]/)) {
|
||||
plugin = tryLoad(`verdaccio-${p}`);
|
||||
if (plugin === null && pluginId.match(/^[^\.\/]/)) {
|
||||
plugin = tryLoad(`verdaccio-${pluginId}`);
|
||||
// compatibility for old sinopia plugins
|
||||
if (!plugin) {
|
||||
plugin = tryLoad(`sinopia-${p}`);
|
||||
plugin = tryLoad(`sinopia-${pluginId}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (plugin === null) {
|
||||
plugin = tryLoad(p);
|
||||
plugin = tryLoad(pluginId);
|
||||
}
|
||||
|
||||
// relative to config path
|
||||
if (plugin === null && p.match(/^\.\.?($|\/)/)) {
|
||||
plugin = tryLoad(Path.resolve(Path.dirname(config.self_path), p));
|
||||
if (plugin === null && pluginId.match(/^\.\.?($|\/)/)) {
|
||||
plugin = tryLoad(Path.resolve(Path.dirname(config.self_path), pluginId));
|
||||
}
|
||||
|
||||
if (plugin === null) {
|
||||
logger.logger.error({content: p}, 'plugin not found. try npm install verdaccio-@{content}');
|
||||
throw Error('"' + p + '" plugin not found\ntry "npm install verdaccio-' + p + '"');
|
||||
logger.logger.error({content: pluginId}, 'plugin not found. try npm install verdaccio-@{content}');
|
||||
throw Error('"' + pluginId + '" plugin not found\ntry "npm install verdaccio-' + pluginId + '"');
|
||||
}
|
||||
|
||||
if (!isValid(plugin)) {
|
||||
logger.logger.error({content: p}, '@{content} doesn\'t look like a valid plugin');
|
||||
throw Error('"' + p + '" doesn\'t look like a valid plugin');
|
||||
logger.logger.error({content: pluginId}, '@{content} doesn\'t look like a valid plugin');
|
||||
throw Error('"' + pluginId + '" doesn\'t look like a valid plugin');
|
||||
}
|
||||
|
||||
const pluginConfiguration = pluginConfigs[pluginId];
|
||||
/* eslint new-cap:off */
|
||||
plugin = isES6(plugin) ? new plugin.default(mergeConfig(config, pluginConfigs[p]), params) : plugin(pluginConfigs[p], params);
|
||||
plugin = isES6(plugin) ? new plugin.default(pluginConfiguration, params) : plugin(pluginConfiguration, params);
|
||||
/* eslint new-cap:off */
|
||||
|
||||
if (plugin === null || !sanityCheck(plugin)) {
|
||||
logger.logger.error({content: p}, '@{content} doesn\'t look like a valid plugin');
|
||||
throw Error('"' + p + '" doesn\'t look like a valid plugin');
|
||||
logger.logger.error({content: pluginId}, '@{content} doesn\'t look like a valid plugin');
|
||||
throw Error('"' + pluginId + '" doesn\'t look like a valid plugin');
|
||||
}
|
||||
logger.logger.warn({content: p}, 'Plugin successfully loaded: @{content}');
|
||||
logger.logger.warn({content: pluginId}, 'Plugin successfully loaded: @{content}');
|
||||
return plugin;
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue