mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-16 21:56:25 -05:00
refactor: fix code review suggestions
This commit is contained in:
parent
3c157a221a
commit
e0d3223968
11 changed files with 260 additions and 261 deletions
10
src/lib/bootstrap.js
vendored
10
src/lib/bootstrap.js
vendored
|
@ -1,6 +1,4 @@
|
|||
import isFunction from 'lodash/isFunction';
|
||||
import assign from 'lodash/assign';
|
||||
import isObject from 'lodash/isObject';
|
||||
import {assign, isObject, isFunction} from 'lodash';
|
||||
import Path from 'path';
|
||||
import URL from 'url';
|
||||
import fs from 'fs';
|
||||
|
@ -36,16 +34,16 @@ function getListListenAddresses(argListen, configListen) {
|
|||
addresses = ['4873'];
|
||||
}
|
||||
addresses = addresses.map(function(addr) {
|
||||
const parsed_addr = Utils.parse_address(addr);
|
||||
const parsedAddr = Utils.parse_address(addr);
|
||||
|
||||
if (!parsed_addr) {
|
||||
if (!parsedAddr) {
|
||||
logger.logger.warn({addr: addr},
|
||||
'invalid address - @{addr}, we expect a port (e.g. "4873"),'
|
||||
+ ' host:port (e.g. "localhost:4873") or full url'
|
||||
+ ' (e.g. "http://localhost:4873/")');
|
||||
}
|
||||
|
||||
return parsed_addr;
|
||||
return parsedAddr;
|
||||
}).filter(Boolean);
|
||||
|
||||
return addresses;
|
||||
|
|
|
@ -10,7 +10,7 @@ const CONFIG_FILE = 'config.yaml';
|
|||
const XDG = 'xdg';
|
||||
const WIN = 'win';
|
||||
const WIN32 = 'win32';
|
||||
const pkgJson = require('../../package.json');
|
||||
const pkgJSON = require('../../package.json');
|
||||
|
||||
/**
|
||||
* Find and get the first config file that match.
|
||||
|
@ -63,7 +63,7 @@ function updateStorageLinks(configLocation, defaultConfig) {
|
|||
// If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used.
|
||||
let dataDir = process.env.XDG_DATA_HOME || Path.join(process.env.HOME, '.local', 'share');
|
||||
if (folder_exists(dataDir)) {
|
||||
dataDir = Path.resolve(Path.join(dataDir, pkgJson.name, 'storage'));
|
||||
dataDir = Path.resolve(Path.join(dataDir, pkgJSON.name, 'storage'));
|
||||
return defaultConfig.replace(/^storage: .\/storage$/m, `storage: ${dataDir}`);
|
||||
} else {
|
||||
return defaultConfig;
|
||||
|
@ -71,16 +71,16 @@ function updateStorageLinks(configLocation, defaultConfig) {
|
|||
}
|
||||
|
||||
function getConfigPaths() {
|
||||
return _.filter([getXDGDirectory(), getWindowsDirectory(), getRelativeDefaultDirectory(), getOldDirectory()]);
|
||||
return [getXDGDirectory(), getWindowsDirectory(), getRelativeDefaultDirectory(), getOldDirectory()].filter((path) => !!path);
|
||||
}
|
||||
|
||||
const getXDGDirectory = () => {
|
||||
const xdgConfig = getXDGHome() ||
|
||||
const XDGConfig = getXDGHome() ||
|
||||
process.env.HOME && Path.join(process.env.HOME, '.config');
|
||||
|
||||
if (xdgConfig && folder_exists(xdgConfig)) {
|
||||
if (XDGConfig && folder_exists(XDGConfig)) {
|
||||
return {
|
||||
path: Path.join(xdgConfig, pkgJson.name, CONFIG_FILE),
|
||||
path: Path.join(XDGConfig, pkgJSON.name, CONFIG_FILE),
|
||||
type: XDG,
|
||||
};
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ const getXDGHome = () => process.env.XDG_CONFIG_HOME;
|
|||
const getWindowsDirectory = () => {
|
||||
if (process.platform === WIN32 && process.env.APPDATA && folder_exists(process.env.APPDATA)) {
|
||||
return {
|
||||
path: Path.resolve(Path.join(process.env.APPDATA, pkgJson.name, CONFIG_FILE)),
|
||||
path: Path.resolve(Path.join(process.env.APPDATA, pkgJSON.name, CONFIG_FILE)),
|
||||
type: WIN,
|
||||
};
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ const getWindowsDirectory = () => {
|
|||
|
||||
const getRelativeDefaultDirectory = () => {
|
||||
return {
|
||||
path: Path.resolve(Path.join('.', pkgJson.name, CONFIG_FILE)),
|
||||
path: Path.resolve(Path.join('.', pkgJSON.name, CONFIG_FILE)),
|
||||
type: 'def',
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
// @flow
|
||||
|
||||
/* eslint prefer-rest-params: 0 */
|
||||
/* eslint spaced-comment: 0 */
|
||||
|
||||
import assert from 'assert';
|
||||
import Crypto from 'crypto';
|
||||
|
@ -24,10 +23,12 @@ import type {
|
|||
DistFile,
|
||||
Callback,
|
||||
Logger,
|
||||
Utils} from '@verdaccio/types';
|
||||
Utils,
|
||||
} from '@verdaccio/types';
|
||||
import type {
|
||||
ILocalFS,
|
||||
ILocalData} from '@verdaccio/local-storage';
|
||||
ILocalData,
|
||||
} from '@verdaccio/local-storage';
|
||||
|
||||
const pkgFileName = 'package.json';
|
||||
const fileExist = 'EEXISTS';
|
||||
|
@ -181,6 +182,7 @@ class Storage implements IStorage {
|
|||
url: version.dist.tarball,
|
||||
sha: version.dist.shasum,
|
||||
};
|
||||
/* eslint spaced-comment: 0 */
|
||||
//$FlowFixMe
|
||||
const upLink: string = version[Symbol.for('__verdaccio_uplink')];
|
||||
|
||||
|
|
|
@ -371,7 +371,7 @@ function folder_exists(path) {
|
|||
* @param {String} path
|
||||
* @return {Boolean}
|
||||
*/
|
||||
function file_exists(path) {
|
||||
function fileExists(path) {
|
||||
try {
|
||||
const stat = fs.statSync(path);
|
||||
return stat.isFile();
|
||||
|
@ -381,7 +381,7 @@ function file_exists(path) {
|
|||
}
|
||||
|
||||
module.exports.folder_exists = folder_exists;
|
||||
module.exports.file_exists = file_exists;
|
||||
module.exports.file_exists = fileExists;
|
||||
module.exports.parseInterval = parseInterval;
|
||||
module.exports.semver_sort = semverSort;
|
||||
module.exports.parse_address = parse_address;
|
||||
|
|
|
@ -23,7 +23,7 @@ export default class Server implements IServerBridge {
|
|||
request(options: any): any {
|
||||
// console.log("--->$$$$ REQUEST", options);
|
||||
assert(options.uri);
|
||||
const headers: any = options.headers || {};
|
||||
const headers = options.headers || {};
|
||||
|
||||
headers.accept = headers.accept || 'application/json';
|
||||
headers['user-agent'] = headers['user-agent'] || this.userAgent;
|
||||
|
|
|
@ -67,5 +67,4 @@ describe('Request Functional', () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
Loading…
Reference in a new issue