Fix eslint issues, add jsdoc

This commit is contained in:
Juan Picado 2017-04-27 05:52:46 +02:00
parent 09c60e68e0
commit acfd865bb0
No known key found for this signature in database
GPG Key ID: 18AC54485952D158
4 changed files with 29 additions and 8 deletions

View File

@ -1,7 +1,12 @@
'use strict'; 'use strict';
let Path = require('path'); const Path = require('path');
/**
* Requires a module.
* @param {*} path the module's path
* @return {Object}
*/
function try_load(path) { function try_load(path) {
try { try {
return require(path); return require(path);
@ -13,6 +18,17 @@ function try_load(path) {
} }
} }
/**
* Load a plugin following the rules
* - First try to load from the internal directory plugins (which will disappear soon or later).
* - A seccond attempt from node_modules, in case to have multiple match as for instance verdaccio-ldap
* and sinopia-ldap. All verdaccio prefix will have preferences.
* @param {*} config a reference of the configuration settings
* @param {*} plugin_configs
* @param {*} params a set of params to initialise the plugin
* @param {*} sanity_check callback that check the shape that should fulfill the plugin
* @return {Array} list of plugins
*/
function load_plugins(config, plugin_configs, params, sanity_check) { function load_plugins(config, plugin_configs, params, sanity_check) {
let plugins = Object.keys(plugin_configs || {}).map(function(p) { let plugins = Object.keys(plugin_configs || {}).map(function(p) {
let plugin; let plugin;

View File

@ -1,3 +1,5 @@
/* eslint no-invalid-this: "off" */
'use strict'; 'use strict';
const lunr = require('lunr'); const lunr = require('lunr');

View File

@ -1,3 +1,5 @@
/* eslint prefer-rest-params: "off" */
'use strict'; 'use strict';
// see https://secure.flickr.com/photos/girliemac/sets/72157628409467125 // see https://secure.flickr.com/photos/girliemac/sets/72157628409467125

View File

@ -97,21 +97,23 @@ function filter_tarball_urls(pkg, req, config) {
if (!req.headers.host) { if (!req.headers.host) {
return _url; return _url;
} }
let filename = URL.parse(_url).pathname.replace(/^.*\//, ''); const filename = URL.parse(_url).pathname.replace(/^.*\//, '');
let result; let result;
if (config.url_prefix != null) { if (config.url_prefix != null) {
result = config.url_prefix.replace(/\/$/, ''); result = config.url_prefix.replace(/\/$/, '');
} else { } else {
result = req.protocol + '://' + req.headers.host; result = `${req.protocol}://${req.headers.host}`;
} }
return `${result}/${pkg.name.replace(/\//g, '%2f')}/-/${filename}`; return `${result}/${pkg.name.replace(/\//g, '%2f')}/-/${filename}`;
}; };
for (let ver in pkg.versions) { for (let ver in pkg.versions) {
let dist = pkg.versions[ver].dist; if (Object.prototype.hasOwnProperty.call(pkg.versions, ver)) {
if (dist != null && dist.tarball != null) { const dist = pkg.versions[ver].dist;
// dist.__verdaccio_orig_tarball = dist.tarball if (dist != null && dist.tarball != null) {
dist.tarball = filter(dist.tarball); // dist.__verdaccio_orig_tarball = dist.tarball
dist.tarball = filter(dist.tarball);
}
} }
} }
return pkg; return pkg;
@ -227,7 +229,6 @@ function semver_sort(array) {
*/ */
function normalize_dist_tags(data) { function normalize_dist_tags(data) {
let sorted; let sorted;
if (!data['dist-tags'].latest) { if (!data['dist-tags'].latest) {
// overwrite latest with highest known version based on semver sort // overwrite latest with highest known version based on semver sort
sorted = module.exports.semver_sort(Object.keys(data.versions)); sorted = module.exports.semver_sort(Object.keys(data.versions));