diff --git a/packages/node-api/src/cli-utils.ts b/packages/node-api/src/cli-utils.ts index ec66dc211..f3105f07f 100644 --- a/packages/node-api/src/cli-utils.ts +++ b/packages/node-api/src/cli-utils.ts @@ -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 diff --git a/src/api/web/html/manifest.ts b/src/api/web/html/manifest.ts index 6faa8861f..53bccda2a 100644 --- a/src/api/web/html/manifest.ts +++ b/src/api/web/html/manifest.ts @@ -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]}`; diff --git a/src/api/web/html/template.ts b/src/api/web/html/template.ts index 29c3f998f..e0906ac91 100644 --- a/src/api/web/html/template.ts +++ b/src/api/web/html/template.ts @@ -52,7 +52,9 @@ export default function renderTemplate(template: Template, manifest: WebpackMani ${template?.scriptsbodyBefore ? template.scriptsbodyBefore.join('') : ''}
- ${getManifestValue(template.manifest.js, manifest, template?.options.base).map((item) => ``).join('')} + ${getManifestValue(template.manifest.js, manifest, template?.options.base) + .map((item) => ``) + .join('')} ${template?.scriptsBodyAfter ? template.scriptsBodyAfter.join('') : ''} diff --git a/src/lib/cli/commands/init.ts b/src/lib/cli/commands/init.ts index 79c6fa936..6a99a4cba 100644 --- a/src/lib/cli/commands/init.ts +++ b/src/lib/cli/commands/init.ts @@ -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, diff --git a/src/lib/logger/formatter/prettifier.ts b/src/lib/logger/formatter/prettifier.ts index fb93966b7..bc3a2088e 100644 --- a/src/lib/logger/formatter/prettifier.ts +++ b/src/lib/logger/formatter/prettifier.ts @@ -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); diff --git a/src/lib/logger/logger.ts b/src/lib/logger/logger.ts index 54974fdbe..a68d50b2b 100644 --- a/src/lib/logger/logger.ts +++ b/src/lib/logger/logger.ts @@ -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 { diff --git a/test/unit/modules/web/template.spec.ts b/test/unit/modules/web/template.spec.ts index 3f3621685..46b2f16cd 100644 --- a/test/unit/modules/web/template.spec.ts +++ b/test/unit/modules/web/template.spec.ts @@ -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: [``], manifest: exampleManifest }, manifest) + renderTemplate( + { + options: { base: 'http://domain.com' }, + metaScripts: [``], + manifest: exampleManifest, + }, + manifest + ) ).toMatchSnapshot(); }); test('custom body after', () => { expect( - renderTemplate({ options: {base: 'http://domain.com'}, scriptsBodyAfter: [`