mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-11-08 23:25:51 +01:00
chore: fix format
This commit is contained in:
parent
08da6881db
commit
58e4ee54d1
@ -57,7 +57,6 @@ export function isVersionValid(version) {
|
|||||||
return semver.satisfies(version, `>=${MIN_NODE_VERSION}`);
|
return semver.satisfies(version, `>=${MIN_NODE_VERSION}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve all addresses defined in the config file.
|
* Retrieve all addresses defined in the config file.
|
||||||
* Verdaccio is able to listen multiple ports
|
* Verdaccio is able to listen multiple ports
|
||||||
|
@ -9,7 +9,11 @@ export type Manifest = {
|
|||||||
|
|
||||||
const debug = buildDebug('verdaccio');
|
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) => {
|
return manifestItems?.map((item) => {
|
||||||
debug('resolve item %o', item);
|
debug('resolve item %o', item);
|
||||||
const resolvedItem = `${basePath}${manifest[item]}`;
|
const resolvedItem = `${basePath}${manifest[item]}`;
|
||||||
|
@ -52,7 +52,9 @@ export default function renderTemplate(template: Template, manifest: WebpackMani
|
|||||||
<body class="body">
|
<body class="body">
|
||||||
${template?.scriptsbodyBefore ? template.scriptsbodyBefore.join('') : ''}
|
${template?.scriptsbodyBefore ? template.scriptsbodyBefore.join('') : ''}
|
||||||
<div id="root"></div>
|
<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('') : ''}
|
${template?.scriptsBodyAfter ? template.scriptsBodyAfter.join('') : ''}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -61,7 +61,8 @@ export class InitCommand extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
logger.logger.warn({ file: configPathLocation }, 'config file - @{file}');
|
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(
|
startVerdaccio(
|
||||||
verdaccioConfiguration,
|
verdaccioConfiguration,
|
||||||
|
@ -2,26 +2,26 @@ import { inspect } from 'util';
|
|||||||
import { white, red, green } from 'kleur';
|
import { white, red, green } from 'kleur';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import dayjs from 'dayjs';
|
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';
|
import { padLeft, padRight } from '../utils';
|
||||||
|
|
||||||
export const CUSTOM_PAD_LENGTH = 1;
|
export const CUSTOM_PAD_LENGTH = 1;
|
||||||
export const FORMAT_DATE = 'YYYY-MM-DD HH:mm:ss';
|
export const FORMAT_DATE = 'YYYY-MM-DD HH:mm:ss';
|
||||||
|
|
||||||
export function isObject(obj: unknown): boolean {
|
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 {
|
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 {
|
export interface PrettyOptionsExtended extends PrettyOptions {
|
||||||
prettyStamp: boolean;
|
prettyStamp: boolean;
|
||||||
}
|
}
|
||||||
let LEVEL_VALUE_MAX = 0;
|
let LEVEL_VALUE_MAX = 0;
|
||||||
// eslint-disable-next-line guard-for-in
|
// 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;
|
const templateRegex = /@{(!?[$A-Za-z_][$0-9A-Za-z\._]*)}/g;
|
||||||
|
|
||||||
return msg.replace(templateRegex, (_, name): string => {
|
return msg.replace(templateRegex, (_, name): string => {
|
||||||
|
|
||||||
let str = templateOptions;
|
let str = templateOptions;
|
||||||
let isError;
|
let isError;
|
||||||
if (name[0] === ERROR_FLAG) {
|
if (name[0] === ERROR_FLAG) {
|
||||||
@ -78,7 +77,9 @@ function getMessage(debugLevel, msg, sub, templateObjects, hasColors) {
|
|||||||
|
|
||||||
const subSystemType = subSystemLevels.color[sub ?? 'default'];
|
const subSystemType = subSystemLevels.color[sub ?? 'default'];
|
||||||
if (hasColors) {
|
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);
|
return padLeft(logString);
|
||||||
}
|
}
|
||||||
@ -88,9 +89,10 @@ function getMessage(debugLevel, msg, sub, templateObjects, hasColors) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function printMessage(
|
export function printMessage(
|
||||||
templateObjects: ObjectTemplate,
|
templateObjects: ObjectTemplate,
|
||||||
options: PrettyOptionsExtended,
|
options: PrettyOptionsExtended,
|
||||||
hasColors = true): string {
|
hasColors = true
|
||||||
|
): string {
|
||||||
const { prettyStamp } = options;
|
const { prettyStamp } = options;
|
||||||
const { level, msg, sub } = templateObjects;
|
const { level, msg, sub } = templateObjects;
|
||||||
const debugLevel = calculateLevel(level);
|
const debugLevel = calculateLevel(level);
|
||||||
|
@ -21,7 +21,7 @@ export type LogType = 'file' | 'stdout';
|
|||||||
export type LogFormat = 'json' | 'pretty-timestamped' | 'pretty';
|
export type LogFormat = 'json' | 'pretty-timestamped' | 'pretty';
|
||||||
|
|
||||||
export function createLogger(
|
export function createLogger(
|
||||||
options = {level: 'http'},
|
options = { level: 'http' },
|
||||||
destination = pino.destination(1),
|
destination = pino.destination(1),
|
||||||
format: LogFormat = DEFAULT_LOG_FORMAT,
|
format: LogFormat = DEFAULT_LOG_FORMAT,
|
||||||
prettyPrintOptions = {
|
prettyPrintOptions = {
|
||||||
@ -63,10 +63,10 @@ export function createLogger(
|
|||||||
}
|
}
|
||||||
const logger = pino(pinoConfig, destination);
|
const logger = pino(pinoConfig, destination);
|
||||||
|
|
||||||
if(process.env.DEBUG) {
|
if (process.env.DEBUG) {
|
||||||
logger.on('level-change', (lvl, val, prevLvl, prevVal) => {
|
logger.on('level-change', (lvl, val, prevLvl, prevVal) => {
|
||||||
debug('%s (%d) was changed to %s (%d)', lvl, val, prevLvl, prevVal);
|
debug('%s (%d) was changed to %s (%d)', lvl, val, prevLvl, prevVal);
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return logger;
|
return logger;
|
||||||
@ -101,7 +101,8 @@ export function setup(options: LoggerConfig | LoggerConfigItem = [DEFAULT_LOGGER
|
|||||||
debug('setup logger');
|
debug('setup logger');
|
||||||
const isLegacyConf = Array.isArray(options);
|
const isLegacyConf = Array.isArray(options);
|
||||||
if (isLegacyConf) {
|
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);
|
process.emitWarning(deprecateMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,16 +111,22 @@ export function setup(options: LoggerConfig | LoggerConfigItem = [DEFAULT_LOGGER
|
|||||||
// next major will thrown an error
|
// next major will thrown an error
|
||||||
let loggerConfig = isLegacyConf ? options[0] : options;
|
let loggerConfig = isLegacyConf ? options[0] : options;
|
||||||
if (!loggerConfig?.level) {
|
if (!loggerConfig?.level) {
|
||||||
loggerConfig = Object.assign({}, {
|
loggerConfig = Object.assign(
|
||||||
level: 'http',
|
{},
|
||||||
}, loggerConfig);
|
{
|
||||||
|
level: 'http',
|
||||||
|
},
|
||||||
|
loggerConfig
|
||||||
|
);
|
||||||
}
|
}
|
||||||
const pinoConfig = { level: loggerConfig.level };
|
const pinoConfig = { level: loggerConfig.level };
|
||||||
if (loggerConfig.type === 'file') {
|
if (loggerConfig.type === 'file') {
|
||||||
debug('logging file enabled');
|
debug('logging file enabled');
|
||||||
logger = createLogger(pinoConfig, pino.destination(loggerConfig.path), loggerConfig.format);
|
logger = createLogger(pinoConfig, pino.destination(loggerConfig.path), loggerConfig.format);
|
||||||
} else if (loggerConfig.type === 'rotating-file') {
|
} 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');
|
debug('logging stdout enabled');
|
||||||
logger = createLogger(pinoConfig, pino.destination(1), loggerConfig.format);
|
logger = createLogger(pinoConfig, pino.destination(1), loggerConfig.format);
|
||||||
} else {
|
} else {
|
||||||
|
@ -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');
|
const manifest = require('./partials/manifest/manifest.json');
|
||||||
|
|
||||||
@ -10,30 +10,55 @@ const exampleManifest = {
|
|||||||
|
|
||||||
describe('template', () => {
|
describe('template', () => {
|
||||||
test('custom render', () => {
|
test('custom render', () => {
|
||||||
expect(renderTemplate({ options: {base: 'http://domain.com'}, manifest: exampleManifest }, manifest)).toMatchSnapshot();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('custom title', () => {
|
|
||||||
expect(
|
expect(
|
||||||
renderTemplate({ options: {base: 'http://domain.com', title: 'foo title' }, manifest: exampleManifest }, manifest)
|
renderTemplate(
|
||||||
|
{ options: { base: 'http://domain.com' }, manifest: exampleManifest },
|
||||||
|
manifest
|
||||||
|
)
|
||||||
).toMatchSnapshot();
|
).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('custom title', () => {
|
test('custom title', () => {
|
||||||
expect(
|
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();
|
).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('meta scripts', () => {
|
test('meta scripts', () => {
|
||||||
expect(
|
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();
|
).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('custom body after', () => {
|
test('custom body after', () => {
|
||||||
expect(
|
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();
|
).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -41,7 +66,7 @@ describe('template', () => {
|
|||||||
expect(
|
expect(
|
||||||
renderTemplate(
|
renderTemplate(
|
||||||
{
|
{
|
||||||
options: {base: 'http://domain.com'},
|
options: { base: 'http://domain.com' },
|
||||||
scriptsbodyBefore: [`<script src="fooBefore"/>`, `<script src="barBefore"/>`],
|
scriptsbodyBefore: [`<script src="fooBefore"/>`, `<script src="barBefore"/>`],
|
||||||
manifest: exampleManifest,
|
manifest: exampleManifest,
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user