0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-16 21:56:25 -05:00

fix: add storage es6 plugin suport and fix plugin logic

This commit is contained in:
Juan Picado @jotadeveloper 2017-12-25 12:27:35 +01:00 committed by juanpicado
parent 9a6adc62b6
commit 84b810e68a
4 changed files with 119 additions and 60 deletions

View file

@ -20,7 +20,7 @@ function tryLoad(path) {
}
function isValid(plugin) {
return (_.isFunction(plugin) === false || _.isFunction(plugin.default) === false);
return (_.isFunction(plugin) || _.isFunction(plugin.default));
}
function isES6(plugin) {
@ -68,12 +68,14 @@ function loadPlugin(config, plugin_configs, params, sanity_check) {
throw Error('"' + p + '" plugin not found\ntry "npm install verdaccio-' + p + '"');
}
if (isValid(plugin) === false) {
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');
}
/* eslint new-cap:off */
plugin = isES6(plugin) ? new plugin.default(plugin_configs[p], params) : plugin(plugin_configs[p], params);
/* eslint new-cap:off */
if (plugin === null || !sanity_check(plugin)) {
logger.logger.error({content: p}, '@{content} doesn\'t look like a valid plugin');

View file

@ -0,0 +1,28 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Dummy = function () {
function Dummy(config, logger) {
_classCallCheck(this, Dummy);
this.config = config;
this.logger = logger;
this.data = [];
}
_createClass(Dummy, [{
key: "getPackageStorage",
value: function getPackageStorage(packageInfo, packagePath) {}
}]);
return Dummy;
}();
exports.default = Dummy;

View file

@ -0,0 +1,15 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Dummy = undefined;
var _dummy = require('./dummy');
var _dummy2 = _interopRequireDefault(_dummy);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.Dummy = _dummy2.default;
exports.default = _dummy2.default;

View file

@ -7,66 +7,80 @@ require('../../src/lib/logger').setup([]);
describe('plugin loader', () => {
test('testing auth valid plugin loader', () => {
let _config = {
self_path: path.join(__dirname, './'),
max_users: 0,
auth: {
'./unit/partials/test-plugin-storage/verdaccio-plugin': {}
}
}
let plugins = loadPlugin(_config, _config.auth, {}, function (p) {
return p.authenticate || p.allow_access || p.allow_publish;
});
assert(plugins.length === 1);
});
test('testing auth valid plugin loader', () => {
let _config = {
self_path: path.join(__dirname, './'),
max_users: 0,
auth: {
'./unit/partials/test-plugin-storage/verdaccio-plugin': {}
}
}
let plugins = loadPlugin(_config, _config.auth, {}, function (p) {
return p.authenticate || p.allow_access || p.allow_publish;
});
assert(plugins.length === 1);
});
test('testing auth plugin invalid plugin', () => {
let _config = {
self_path: path.join(__dirname, './'),
auth: {
'./unit/partials/test-plugin-storage/invalid-plugin': {}
}
}
try {
loadPlugin(_config, _config.auth, {}, function (p) {
return p.authenticate || p.allow_access || p.allow_publish;
});
} catch(e) {
assert(e.message === '"./unit/partials/test-plugin-storage/invalid-plugin" doesn\'t look like a valid plugin');
}
});
test('testing storage valid plugin loader', () => {
let _config = {
self_path: path.join(__dirname, './'),
max_users: 0,
auth: {
'./unit/partials/test-plugin-storage/verdaccio-es6-plugin': {}
}
}
let plugins = loadPlugin(_config, _config.auth, {}, function (p) {
return p.getPackageStorage;
});
assert(plugins.length === 1);
});
test('testing auth plugin invalid plugin sanityCheck', () => {
let _config = {
self_path: path.join(__dirname, './'),
auth: {
'./unit/partials/test-plugin-storage/invalid-plugin-sanity': {}
}
}
try {
loadPlugin(_config, _config.auth, {}, function (plugin) {
return plugin.authenticate || plugin.allow_access || plugin.allow_publish;
});
} catch(err) {
assert(err.message === '"./unit/partials/test-plugin-storage/invalid-plugin-sanity" doesn\'t look like a valid plugin');
}
});
test('testing auth plugin invalid plugin', () => {
let _config = {
self_path: path.join(__dirname, './'),
auth: {
'./unit/partials/test-plugin-storage/invalid-plugin': {}
}
}
try {
loadPlugin(_config, _config.auth, {}, function (p) {
return p.authenticate || p.allow_access || p.allow_publish;
});
} catch(e) {
assert(e.message === '"./unit/partials/test-plugin-storage/invalid-plugin" doesn\'t look like a valid plugin');
}
});
test('testing auth plugin no plugins', () => {
let _config = {
self_path: path.join(__dirname, './'),
auth: {
'./unit/partials/test-plugin-storage/invalid-package': {}
}
}
try {
loadPlugin(_config, _config.auth, {}, function (plugin) {
return plugin.authenticate || plugin.allow_access || plugin.allow_publish;
});
} catch(e) {
assert(e.message === `"./unit/partials/test-plugin-storage/invalid-package" plugin not found\ntry "npm install verdaccio-./unit/partials/test-plugin-storage/invalid-package"`);
}
});
test('testing auth plugin invalid plugin sanityCheck', () => {
let _config = {
self_path: path.join(__dirname, './'),
auth: {
'./unit/partials/test-plugin-storage/invalid-plugin-sanity': {}
}
}
try {
loadPlugin(_config, _config.auth, {}, function (plugin) {
return plugin.authenticate || plugin.allow_access || plugin.allow_publish;
});
} catch(err) {
assert(err.message === '"./unit/partials/test-plugin-storage/invalid-plugin-sanity" doesn\'t look like a valid plugin');
}
});
test('testing auth plugin no plugins', () => {
let _config = {
self_path: path.join(__dirname, './'),
auth: {
'./unit/partials/test-plugin-storage/invalid-package': {}
}
}
try {
loadPlugin(_config, _config.auth, {}, function (plugin) {
return plugin.authenticate || plugin.allow_access || plugin.allow_publish;
});
} catch(e) {
assert(e.message === `"./unit/partials/test-plugin-storage/invalid-package" plugin not found\ntry "npm install verdaccio-./unit/partials/test-plugin-storage/invalid-package"`);
}
});
});