mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-16 21:56:25 -05:00
feat: use warning codes for deprecation warnings (#2595)
* feat: use warning codes for deprecation warnings * Update logger.spec.ts * Update package.json
This commit is contained in:
parent
1016fc0ff1
commit
6c1eb021ba
15 changed files with 145 additions and 29 deletions
8
.changeset/shaggy-parrots-smash.md
Normal file
8
.changeset/shaggy-parrots-smash.md
Normal file
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
'@verdaccio/cli': minor
|
||||
'@verdaccio/core': minor
|
||||
'@verdaccio/logger': minor
|
||||
'@verdaccio/node-api': minor
|
||||
---
|
||||
|
||||
feat: use warning codes for deprecation warnings
|
29
docs/warnings.md
Normal file
29
docs/warnings.md
Normal file
|
@ -0,0 +1,29 @@
|
|||
# Warning Codes
|
||||
|
||||
## VERWAR001
|
||||
|
||||
Verdaccio doesn't need superuser privileges. Don't run it under root.
|
||||
|
||||
## VERWAR002
|
||||
|
||||
logger is not defined
|
||||
|
||||
## VERWAR003
|
||||
|
||||
'rotating-file type is not longer supported, consider use [logrotate] instead'
|
||||
|
||||
## VERWAR004
|
||||
|
||||
invalid address - xxxxxx, we expect a port (e.g. "4873"),
|
||||
|
||||
## VERDEP001
|
||||
|
||||
'config.logs is deprecated, rename configuration to "config.log" in singular'
|
||||
|
||||
## VERDEP002
|
||||
|
||||
'deprecate: multiple logger configuration is deprecated, please check the migration guide.'
|
||||
|
||||
## VERDEP003
|
||||
|
||||
'multiple addresses will be deprecated in the next major, only use one'
|
|
@ -112,7 +112,7 @@
|
|||
"docker": "docker build -t verdaccio/verdaccio:local . --no-cache",
|
||||
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,yml,yaml,md}\"",
|
||||
"format:check": "prettier --check \"**/*.{js,jsx,ts,tsx,json,yml,yaml,md}\"",
|
||||
"lint": "eslint --max-warnings 45 \"**/*.{js,jsx,ts,tsx}\"",
|
||||
"lint": "eslint --max-warnings 46 \"**/*.{js,jsx,ts,tsx}\"",
|
||||
"test": "pnpm recursive test --filter ./packages",
|
||||
"test:e2e:cli": "pnpm test --filter ...@verdaccio/e2e-cli",
|
||||
"test:e2e:ui": "pnpm test --filter ...@verdaccio/e2e-ui",
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
"start": "ts-node src/index.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@verdaccio/core": "workspace:6.0.0-6-next.2",
|
||||
"@verdaccio/config": "workspace:6.0.0-6-next.9",
|
||||
"@verdaccio/logger": "workspace:6.0.0-6-next.6",
|
||||
"@verdaccio/node-api": "workspace:6.0.0-6-next.22",
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { Cli } from 'clipanion';
|
||||
|
||||
import { warningUtils } from '@verdaccio/core';
|
||||
import { InfoCommand } from './commands/info';
|
||||
import { InitCommand } from './commands/init';
|
||||
import { VersionCommand } from './commands/version';
|
||||
|
@ -7,7 +8,7 @@ import { FastifyServer } from './commands/FastifyServer';
|
|||
import { isVersionValid, MIN_NODE_VERSION } from './utils';
|
||||
|
||||
if (process.getuid && process.getuid() === 0) {
|
||||
process.emitWarning(`Verdaccio doesn't need superuser privileges. don't run it under root`);
|
||||
warningUtils.emit(warningUtils.Codes.VERWAR001);
|
||||
}
|
||||
|
||||
if (!isVersionValid(process.version)) {
|
||||
|
|
|
@ -3,6 +3,7 @@ import { findConfigFile, parseConfigFile } from '@verdaccio/config';
|
|||
import { setup, logger } from '@verdaccio/logger';
|
||||
import { initServer } from '@verdaccio/node-api';
|
||||
import { ConfigRuntime } from '@verdaccio/types';
|
||||
import { warningUtils } from '@verdaccio/core';
|
||||
|
||||
export const DEFAULT_PROCESS_NAME: string = 'verdaccio';
|
||||
|
||||
|
@ -46,9 +47,7 @@ export class InitCommand extends Command {
|
|||
private initLogger(logConfig: ConfigRuntime) {
|
||||
try {
|
||||
if (logConfig.logs) {
|
||||
process.emitWarning(
|
||||
'config.logs is deprecated, rename configuration to "config.log" in singular'
|
||||
);
|
||||
warningUtils.emit(warningUtils.Codes.VERDEP001);
|
||||
}
|
||||
// FUTURE: remove fallback when is ready
|
||||
setup(logConfig.log || logConfig.logs);
|
||||
|
|
|
@ -13,6 +13,9 @@
|
|||
{
|
||||
"path": "../core/cli-ui"
|
||||
},
|
||||
{
|
||||
"path": "../core/core"
|
||||
},
|
||||
{
|
||||
"path": "../core/server"
|
||||
},
|
||||
|
|
|
@ -36,7 +36,8 @@
|
|||
"dependencies": {
|
||||
"http-errors": "1.8.0",
|
||||
"http-status-codes": "2.1.4",
|
||||
"semver": "7.3.5"
|
||||
"semver": "7.3.5",
|
||||
"fastify-warning": "0.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@verdaccio/types": "workspace:11.0.0-6-next.9"
|
||||
|
|
|
@ -6,6 +6,7 @@ import * as constants from './constants';
|
|||
import * as pluginUtils from './plugin-utils';
|
||||
import * as fileUtils from './file-utils';
|
||||
import * as pkgUtils from './pkg-utils';
|
||||
import * as warningUtils from './warning-utils';
|
||||
|
||||
export { VerdaccioError, API_ERROR, SUPPORT_ERRORS, APP_ERROR } from './error-utils';
|
||||
export {
|
||||
|
@ -32,4 +33,5 @@ export {
|
|||
validatioUtils,
|
||||
constants,
|
||||
pluginUtils,
|
||||
warningUtils,
|
||||
};
|
||||
|
|
59
packages/core/core/src/warning-utils.ts
Normal file
59
packages/core/core/src/warning-utils.ts
Normal file
|
@ -0,0 +1,59 @@
|
|||
import warning from 'fastify-warning';
|
||||
|
||||
const warningInstance = warning();
|
||||
const verdaccioWarning = 'VerdaccioWarning';
|
||||
const verdaccioDeprecation = 'VerdaccioDeprecation';
|
||||
|
||||
export enum Codes {
|
||||
VERWAR001 = 'VERWAR001',
|
||||
VERWAR002 = 'VERWAR002',
|
||||
VERWAR003 = 'VERWAR003',
|
||||
VERWAR004 = 'VERWAR004',
|
||||
VERDEP001 = 'VERDEP001',
|
||||
VERDEP002 = 'VERDEP002',
|
||||
VERDEP003 = 'VERDEP003',
|
||||
}
|
||||
|
||||
warningInstance.create(
|
||||
verdaccioWarning,
|
||||
Codes.VERWAR001,
|
||||
`Verdaccio doesn't need superuser privileges. don't run it under root`
|
||||
);
|
||||
|
||||
warningInstance.create(verdaccioWarning, Codes.VERWAR002, 'logger is not defined');
|
||||
|
||||
warningInstance.create(
|
||||
verdaccioWarning,
|
||||
Codes.VERWAR003,
|
||||
'rotating-file type is not longer supported, consider use [logrotate] instead'
|
||||
);
|
||||
|
||||
warningInstance.create(
|
||||
verdaccioWarning,
|
||||
Codes.VERWAR004,
|
||||
`invalid address - %s, we expect a port (e.g. "4873"),
|
||||
host:port (e.g. "localhost:4873") or full url '(e.g. "http://localhost:4873/")
|
||||
https://verdaccio.org/docs/en/configuration#listen-port`
|
||||
);
|
||||
|
||||
warningInstance.create(
|
||||
verdaccioDeprecation,
|
||||
Codes.VERDEP001,
|
||||
'config.logs is deprecated, rename configuration to "config.log" in singular'
|
||||
);
|
||||
|
||||
warningInstance.create(
|
||||
verdaccioDeprecation,
|
||||
Codes.VERDEP002,
|
||||
'deprecate: multiple logger configuration is deprecated, please check the migration guide.'
|
||||
);
|
||||
|
||||
warningInstance.create(
|
||||
verdaccioDeprecation,
|
||||
Codes.VERDEP003,
|
||||
'multiple addresses will be deprecated in the next major, only use one'
|
||||
);
|
||||
|
||||
export function emit(code, a?: string, b?: string, c?: string) {
|
||||
warningInstance.emit(code, a, b, c);
|
||||
}
|
|
@ -39,6 +39,7 @@
|
|||
"build": "cross-env BABEL_ENV=registry babel src/ --out-dir build/ --copy-files --extensions \".ts,.tsx\" --source-maps"
|
||||
},
|
||||
"dependencies": {
|
||||
"@verdaccio/core": "workspace:6.0.0-6-next.2",
|
||||
"@verdaccio/logger-prettify": "workspace:6.0.0-6-next.4",
|
||||
"debug": "4.3.2",
|
||||
"lodash": "4.17.21",
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import pino from 'pino';
|
||||
import _ from 'lodash';
|
||||
import buildDebug from 'debug';
|
||||
import { warningUtils } from '@verdaccio/core';
|
||||
|
||||
const debug = buildDebug('verdaccio:logger');
|
||||
|
||||
|
@ -75,7 +76,7 @@ export function createLogger(
|
|||
export function getLogger() {
|
||||
if (_.isNil(logger)) {
|
||||
// FIXME: not sure about display here a warning
|
||||
process.emitWarning('logger is not defined');
|
||||
warningUtils.emit(warningUtils.Codes.VERWAR002);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -102,9 +103,7 @@ 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.';
|
||||
process.emitWarning(deprecateMessage);
|
||||
warningUtils.emit(warningUtils.Codes.VERDEP002);
|
||||
}
|
||||
|
||||
// verdaccio 5 does not allow multiple logger configuration
|
||||
|
@ -125,9 +124,7 @@ export function setup(options: LoggerConfig | LoggerConfigItem = DEFAULT_LOGGER_
|
|||
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'
|
||||
);
|
||||
warningUtils.emit(warningUtils.Codes.VERWAR003);
|
||||
debug('logging stdout enabled');
|
||||
logger = createLogger(pinoConfig, pino.destination(1), loggerConfig.format);
|
||||
} else {
|
||||
|
|
|
@ -1,7 +1,26 @@
|
|||
import { warningUtils } from '@verdaccio/core';
|
||||
import { logger, setup } from '../src';
|
||||
|
||||
const mockWarningUtils = jest.fn();
|
||||
|
||||
jest.mock('@verdaccio/core', () => {
|
||||
const original = jest.requireActual('@verdaccio/core');
|
||||
return {
|
||||
warningUtils: {
|
||||
...original.warningUtils,
|
||||
emit: (...args) => {
|
||||
mockWarningUtils(...args);
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
describe('logger', () => {
|
||||
test('dsadasd', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
test.skip('should write message logger', () => {
|
||||
jest.spyOn(process.stdout, 'write');
|
||||
setup([
|
||||
{
|
||||
|
@ -15,7 +34,6 @@ describe('logger', () => {
|
|||
});
|
||||
|
||||
test('throw deprecation warning if multiple loggers configured', () => {
|
||||
const spy = jest.spyOn(process, 'emitWarning');
|
||||
setup([
|
||||
{
|
||||
level: 'info',
|
||||
|
@ -24,18 +42,11 @@ describe('logger', () => {
|
|||
level: 'http',
|
||||
},
|
||||
]);
|
||||
expect(spy).toHaveBeenCalledWith(
|
||||
'deprecate: multiple logger configuration is deprecated, please check the migration guide.'
|
||||
);
|
||||
spy.mockRestore();
|
||||
expect(mockWarningUtils).toHaveBeenCalledWith(warningUtils.Codes.VERDEP002);
|
||||
});
|
||||
|
||||
test('regression: do not throw deprecation warning if no logger config is provided', () => {
|
||||
const spy = jest.spyOn(process, 'emitWarning');
|
||||
setup();
|
||||
expect(spy).not.toHaveBeenCalledWith(
|
||||
'deprecate: multiple logger configuration is deprecated, please check the migration guide.'
|
||||
);
|
||||
spy.mockRestore();
|
||||
expect(mockWarningUtils).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import { warningUtils } from '@verdaccio/core';
|
||||
|
||||
export const DEFAULT_PORT = '4873';
|
||||
export const DEFAULT_PROTOCOL = 'http';
|
||||
export const DEFAULT_DOMAIN = 'localhost';
|
||||
|
@ -71,11 +73,7 @@ export function getListListenAddresses(argListen: string | void, configListen: a
|
|||
const parsedAddr = parseAddress(addr);
|
||||
|
||||
if (!parsedAddr) {
|
||||
process.emitWarning(
|
||||
// eslint-disable-next-line max-len
|
||||
`invalid address - ${addr}, we expect a port (e.g. "4873"), host:port (e.g. "localhost:4873") or full url '(e.g. "http://localhost:4873/")`
|
||||
);
|
||||
process.emitWarning('https://verdaccio.org/docs/en/configuration#listen-port');
|
||||
warningUtils.emit(warningUtils.Codes.VERWAR004, addr);
|
||||
}
|
||||
|
||||
return parsedAddr;
|
||||
|
|
|
@ -265,6 +265,7 @@ importers:
|
|||
packages/cli:
|
||||
specifiers:
|
||||
'@verdaccio/config': workspace:6.0.0-6-next.9
|
||||
'@verdaccio/core': workspace:6.0.0-6-next.2
|
||||
'@verdaccio/fastify-migration': workspace:6.0.0-6-next.14
|
||||
'@verdaccio/logger': workspace:6.0.0-6-next.6
|
||||
'@verdaccio/node-api': workspace:6.0.0-6-next.22
|
||||
|
@ -275,6 +276,7 @@ importers:
|
|||
ts-node: 10.2.1
|
||||
dependencies:
|
||||
'@verdaccio/config': link:../config
|
||||
'@verdaccio/core': link:../core/core
|
||||
'@verdaccio/fastify-migration': link:../core/server
|
||||
'@verdaccio/logger': link:../logger
|
||||
'@verdaccio/node-api': link:../node-api
|
||||
|
@ -311,10 +313,12 @@ importers:
|
|||
packages/core/core:
|
||||
specifiers:
|
||||
'@verdaccio/types': workspace:11.0.0-6-next.9
|
||||
fastify-warning: 0.2.0
|
||||
http-errors: 1.8.0
|
||||
http-status-codes: 2.1.4
|
||||
semver: 7.3.5
|
||||
dependencies:
|
||||
fastify-warning: 0.2.0
|
||||
http-errors: 1.8.0
|
||||
http-status-codes: 2.1.4
|
||||
semver: 7.3.5
|
||||
|
@ -481,12 +485,14 @@ importers:
|
|||
packages/logger:
|
||||
specifiers:
|
||||
'@types/pino': 6.3.12
|
||||
'@verdaccio/core': workspace:6.0.0-6-next.2
|
||||
'@verdaccio/logger-prettify': workspace:6.0.0-6-next.4
|
||||
'@verdaccio/types': workspace:11.0.0-6-next.9
|
||||
debug: 4.3.2
|
||||
lodash: 4.17.21
|
||||
pino: 6.13.3
|
||||
dependencies:
|
||||
'@verdaccio/core': link:../core/core
|
||||
'@verdaccio/logger-prettify': link:../logger-prettify
|
||||
debug: 4.3.2
|
||||
lodash: 4.17.21
|
||||
|
|
Loading…
Reference in a new issue