mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-01-06 22:40:26 -05:00
refactor: improve plugin system to load es6 modules
This commit is contained in:
parent
dcbd1e9db8
commit
9a6adc62b6
2 changed files with 12 additions and 3 deletions
|
@ -55,7 +55,7 @@ class LocalStorage implements IStorage {
|
||||||
if (_.isNil(Storage)) {
|
if (_.isNil(Storage)) {
|
||||||
return new LocalDatabase(this.config, logger);
|
return new LocalDatabase(this.config, logger);
|
||||||
} else {
|
} else {
|
||||||
return new Storage(this.config, logger);
|
return Storage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
|
||||||
import Path from 'path';
|
import Path from 'path';
|
||||||
|
import _ from 'lodash';
|
||||||
import logger from './logger';
|
import logger from './logger';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,6 +19,14 @@ function tryLoad(path) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isValid(plugin) {
|
||||||
|
return (_.isFunction(plugin) === false || _.isFunction(plugin.default) === false);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isES6(plugin) {
|
||||||
|
return Object.keys(plugin).includes('default');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load a plugin following the rules
|
* Load a plugin following the rules
|
||||||
* - First try to load from the internal directory plugins (which will disappear soon or later).
|
* - First try to load from the internal directory plugins (which will disappear soon or later).
|
||||||
|
@ -59,12 +68,12 @@ function loadPlugin(config, plugin_configs, params, sanity_check) {
|
||||||
throw Error('"' + p + '" plugin not found\ntry "npm install verdaccio-' + p + '"');
|
throw Error('"' + p + '" plugin not found\ntry "npm install verdaccio-' + p + '"');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof(plugin) !== 'function') {
|
if (isValid(plugin) === false) {
|
||||||
logger.logger.error({content: p}, '@{content} doesn\'t look like a valid plugin');
|
logger.logger.error({content: p}, '@{content} doesn\'t look like a valid plugin');
|
||||||
throw Error('"' + p + '" doesn\'t look like a valid plugin');
|
throw Error('"' + p + '" doesn\'t look like a valid plugin');
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin = plugin(plugin_configs[p], params);
|
plugin = isES6(plugin) ? new plugin.default(plugin_configs[p], params) : plugin(plugin_configs[p], params);
|
||||||
|
|
||||||
if (plugin === null || !sanity_check(plugin)) {
|
if (plugin === null || !sanity_check(plugin)) {
|
||||||
logger.logger.error({content: p}, '@{content} doesn\'t look like a valid plugin');
|
logger.logger.error({content: p}, '@{content} doesn\'t look like a valid plugin');
|
||||||
|
|
Loading…
Reference in a new issue