chore: fix format

This commit is contained in:
Juan Picado 2021-04-03 21:06:26 +02:00
parent 08da6881db
commit 58e4ee54d1
7 changed files with 74 additions and 34 deletions

View File

@ -57,7 +57,6 @@ export function isVersionValid(version) {
return semver.satisfies(version, `>=${MIN_NODE_VERSION}`);
}
/**
* Retrieve all addresses defined in the config file.
* Verdaccio is able to listen multiple ports

View File

@ -9,7 +9,11 @@ export type Manifest = {
const debug = buildDebug('verdaccio');
export function getManifestValue(manifestItems: string[], manifest, basePath: string = ''): string[] {
export function getManifestValue(
manifestItems: string[],
manifest,
basePath: string = ''
): string[] {
return manifestItems?.map((item) => {
debug('resolve item %o', item);
const resolvedItem = `${basePath}${manifest[item]}`;

View File

@ -52,7 +52,9 @@ export default function renderTemplate(template: Template, manifest: WebpackMani
<body class="body">
${template?.scriptsbodyBefore ? template.scriptsbodyBefore.join('') : ''}
<div id="root"></div>
${getManifestValue(template.manifest.js, manifest, template?.options.base).map((item) => `<script defer="defer" src="${item}"></script>`).join('')}
${getManifestValue(template.manifest.js, manifest, template?.options.base)
.map((item) => `<script defer="defer" src="${item}"></script>`)
.join('')}
${template?.scriptsBodyAfter ? template.scriptsBodyAfter.join('') : ''}
</body>
</html>

View File

@ -61,7 +61,8 @@ export class InitCommand extends Command {
}
logger.logger.warn({ file: configPathLocation }, 'config file - @{file}');
process.title = (verdaccioConfiguration.web && verdaccioConfiguration.web.title) || 'verdaccio';
process.title =
(verdaccioConfiguration.web && verdaccioConfiguration.web.title) || 'verdaccio';
startVerdaccio(
verdaccioConfiguration,

View File

@ -2,26 +2,26 @@ import { inspect } from 'util';
import { white, red, green } from 'kleur';
import _ from 'lodash';
import dayjs from 'dayjs';
import {PrettyOptions} from "pino";
import { PrettyOptions } from 'pino';
import {calculateLevel, LevelCode, levelsColors, subSystemLevels} from "../levels";
import { calculateLevel, LevelCode, levelsColors, subSystemLevels } from '../levels';
import { padLeft, padRight } from '../utils';
export const CUSTOM_PAD_LENGTH = 1;
export const FORMAT_DATE = 'YYYY-MM-DD HH:mm:ss';
export function isObject(obj: unknown): boolean {
return _.isObject(obj) && _.isNull(obj) === false && _.isArray(obj) === false;
return _.isObject(obj) && _.isNull(obj) === false && _.isArray(obj) === false;
}
export function formatLoggingDate(time: number, message): string {
const timeFormatted = dayjs(time).format(FORMAT_DATE);
const timeFormatted = dayjs(time).format(FORMAT_DATE);
return `[${timeFormatted}]${message}`;
return `[${timeFormatted}]${message}`;
}
export interface PrettyOptionsExtended extends PrettyOptions {
prettyStamp: boolean;
export interface PrettyOptionsExtended extends PrettyOptions {
prettyStamp: boolean;
}
let LEVEL_VALUE_MAX = 0;
// eslint-disable-next-line guard-for-in
@ -42,7 +42,6 @@ export function fillInMsgTemplate(msg, templateOptions: ObjectTemplate, colors):
const templateRegex = /@{(!?[$A-Za-z_][$0-9A-Za-z\._]*)}/g;
return msg.replace(templateRegex, (_, name): string => {
let str = templateOptions;
let isError;
if (name[0] === ERROR_FLAG) {
@ -78,7 +77,9 @@ function getMessage(debugLevel, msg, sub, templateObjects, hasColors) {
const subSystemType = subSystemLevels.color[sub ?? 'default'];
if (hasColors) {
const logString = `${levelsColors[debugLevel](padRight(debugLevel, LEVEL_VALUE_MAX))}${white(`${subSystemType} ${finalMessage}`)}`;
const logString = `${levelsColors[debugLevel](padRight(debugLevel, LEVEL_VALUE_MAX))}${white(
`${subSystemType} ${finalMessage}`
)}`;
return padLeft(logString);
}
@ -88,9 +89,10 @@ function getMessage(debugLevel, msg, sub, templateObjects, hasColors) {
}
export function printMessage(
templateObjects: ObjectTemplate,
options: PrettyOptionsExtended,
hasColors = true): string {
templateObjects: ObjectTemplate,
options: PrettyOptionsExtended,
hasColors = true
): string {
const { prettyStamp } = options;
const { level, msg, sub } = templateObjects;
const debugLevel = calculateLevel(level);

View File

@ -21,7 +21,7 @@ export type LogType = 'file' | 'stdout';
export type LogFormat = 'json' | 'pretty-timestamped' | 'pretty';
export function createLogger(
options = {level: 'http'},
options = { level: 'http' },
destination = pino.destination(1),
format: LogFormat = DEFAULT_LOG_FORMAT,
prettyPrintOptions = {
@ -63,10 +63,10 @@ export function createLogger(
}
const logger = pino(pinoConfig, destination);
if(process.env.DEBUG) {
if (process.env.DEBUG) {
logger.on('level-change', (lvl, val, prevLvl, prevVal) => {
debug('%s (%d) was changed to %s (%d)', lvl, val, prevLvl, prevVal);
})
});
}
return logger;
@ -101,7 +101,8 @@ export function setup(options: LoggerConfig | LoggerConfigItem = [DEFAULT_LOGGER
debug('setup logger');
const isLegacyConf = Array.isArray(options);
if (isLegacyConf) {
const deprecateMessage = 'deprecate: multiple logger configuration is deprecated, please check the migration guide.';
const deprecateMessage =
'deprecate: multiple logger configuration is deprecated, please check the migration guide.';
process.emitWarning(deprecateMessage);
}
@ -110,16 +111,22 @@ export function setup(options: LoggerConfig | LoggerConfigItem = [DEFAULT_LOGGER
// next major will thrown an error
let loggerConfig = isLegacyConf ? options[0] : options;
if (!loggerConfig?.level) {
loggerConfig = Object.assign({}, {
level: 'http',
}, loggerConfig);
loggerConfig = Object.assign(
{},
{
level: 'http',
},
loggerConfig
);
}
const pinoConfig = { level: loggerConfig.level };
if (loggerConfig.type === 'file') {
debug('logging file enabled');
logger = createLogger(pinoConfig, pino.destination(loggerConfig.path), loggerConfig.format);
} else if (loggerConfig.type === 'rotating-file') {
process.emitWarning('rotating-file type is not longer supported, consider use [logrotate] instead');
process.emitWarning(
'rotating-file type is not longer supported, consider use [logrotate] instead'
);
debug('logging stdout enabled');
logger = createLogger(pinoConfig, pino.destination(1), loggerConfig.format);
} else {

View File

@ -1,4 +1,4 @@
import renderTemplate from "../../../../src/api/web/html/template";
import renderTemplate from '../../../../src/api/web/html/template';
const manifest = require('./partials/manifest/manifest.json');
@ -10,30 +10,55 @@ const exampleManifest = {
describe('template', () => {
test('custom render', () => {
expect(renderTemplate({ options: {base: 'http://domain.com'}, manifest: exampleManifest }, manifest)).toMatchSnapshot();
});
test('custom title', () => {
expect(
renderTemplate({ options: {base: 'http://domain.com', title: 'foo title' }, manifest: exampleManifest }, manifest)
renderTemplate(
{ options: { base: 'http://domain.com' }, manifest: exampleManifest },
manifest
)
).toMatchSnapshot();
});
test('custom title', () => {
expect(
renderTemplate({ options: {base: 'http://domain.com', title: 'foo title' }, manifest: exampleManifest }, manifest)
renderTemplate(
{ options: { base: 'http://domain.com', title: 'foo title' }, manifest: exampleManifest },
manifest
)
).toMatchSnapshot();
});
test('custom title', () => {
expect(
renderTemplate(
{ options: { base: 'http://domain.com', title: 'foo title' }, manifest: exampleManifest },
manifest
)
).toMatchSnapshot();
});
test('meta scripts', () => {
expect(
renderTemplate({ options: {base: 'http://domain.com'}, metaScripts: [`<style>.someclass{font-size:10px;}</style>`], manifest: exampleManifest }, manifest)
renderTemplate(
{
options: { base: 'http://domain.com' },
metaScripts: [`<style>.someclass{font-size:10px;}</style>`],
manifest: exampleManifest,
},
manifest
)
).toMatchSnapshot();
});
test('custom body after', () => {
expect(
renderTemplate({ options: {base: 'http://domain.com'}, scriptsBodyAfter: [`<script src="foo"/>`], manifest: exampleManifest }, manifest)
renderTemplate(
{
options: { base: 'http://domain.com' },
scriptsBodyAfter: [`<script src="foo"/>`],
manifest: exampleManifest,
},
manifest
)
).toMatchSnapshot();
});
@ -41,7 +66,7 @@ describe('template', () => {
expect(
renderTemplate(
{
options: {base: 'http://domain.com'},
options: { base: 'http://domain.com' },
scriptsbodyBefore: [`<script src="fooBefore"/>`, `<script src="barBefore"/>`],
manifest: exampleManifest,
},