mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-03-11 02:15:57 -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",
|
"docker": "docker build -t verdaccio/verdaccio:local . --no-cache",
|
||||||
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,yml,yaml,md}\"",
|
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,yml,yaml,md}\"",
|
||||||
"format:check": "prettier --check \"**/*.{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": "pnpm recursive test --filter ./packages",
|
||||||
"test:e2e:cli": "pnpm test --filter ...@verdaccio/e2e-cli",
|
"test:e2e:cli": "pnpm test --filter ...@verdaccio/e2e-cli",
|
||||||
"test:e2e:ui": "pnpm test --filter ...@verdaccio/e2e-ui",
|
"test:e2e:ui": "pnpm test --filter ...@verdaccio/e2e-ui",
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
"start": "ts-node src/index.ts"
|
"start": "ts-node src/index.ts"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@verdaccio/core": "workspace:6.0.0-6-next.2",
|
||||||
"@verdaccio/config": "workspace:6.0.0-6-next.9",
|
"@verdaccio/config": "workspace:6.0.0-6-next.9",
|
||||||
"@verdaccio/logger": "workspace:6.0.0-6-next.6",
|
"@verdaccio/logger": "workspace:6.0.0-6-next.6",
|
||||||
"@verdaccio/node-api": "workspace:6.0.0-6-next.22",
|
"@verdaccio/node-api": "workspace:6.0.0-6-next.22",
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { Cli } from 'clipanion';
|
import { Cli } from 'clipanion';
|
||||||
|
|
||||||
|
import { warningUtils } from '@verdaccio/core';
|
||||||
import { InfoCommand } from './commands/info';
|
import { InfoCommand } from './commands/info';
|
||||||
import { InitCommand } from './commands/init';
|
import { InitCommand } from './commands/init';
|
||||||
import { VersionCommand } from './commands/version';
|
import { VersionCommand } from './commands/version';
|
||||||
|
@ -7,7 +8,7 @@ import { FastifyServer } from './commands/FastifyServer';
|
||||||
import { isVersionValid, MIN_NODE_VERSION } from './utils';
|
import { isVersionValid, MIN_NODE_VERSION } from './utils';
|
||||||
|
|
||||||
if (process.getuid && process.getuid() === 0) {
|
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)) {
|
if (!isVersionValid(process.version)) {
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { findConfigFile, parseConfigFile } from '@verdaccio/config';
|
||||||
import { setup, logger } from '@verdaccio/logger';
|
import { setup, logger } from '@verdaccio/logger';
|
||||||
import { initServer } from '@verdaccio/node-api';
|
import { initServer } from '@verdaccio/node-api';
|
||||||
import { ConfigRuntime } from '@verdaccio/types';
|
import { ConfigRuntime } from '@verdaccio/types';
|
||||||
|
import { warningUtils } from '@verdaccio/core';
|
||||||
|
|
||||||
export const DEFAULT_PROCESS_NAME: string = 'verdaccio';
|
export const DEFAULT_PROCESS_NAME: string = 'verdaccio';
|
||||||
|
|
||||||
|
@ -46,9 +47,7 @@ export class InitCommand extends Command {
|
||||||
private initLogger(logConfig: ConfigRuntime) {
|
private initLogger(logConfig: ConfigRuntime) {
|
||||||
try {
|
try {
|
||||||
if (logConfig.logs) {
|
if (logConfig.logs) {
|
||||||
process.emitWarning(
|
warningUtils.emit(warningUtils.Codes.VERDEP001);
|
||||||
'config.logs is deprecated, rename configuration to "config.log" in singular'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
// FUTURE: remove fallback when is ready
|
// FUTURE: remove fallback when is ready
|
||||||
setup(logConfig.log || logConfig.logs);
|
setup(logConfig.log || logConfig.logs);
|
||||||
|
|
|
@ -13,6 +13,9 @@
|
||||||
{
|
{
|
||||||
"path": "../core/cli-ui"
|
"path": "../core/cli-ui"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"path": "../core/core"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"path": "../core/server"
|
"path": "../core/server"
|
||||||
},
|
},
|
||||||
|
|
|
@ -36,7 +36,8 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"http-errors": "1.8.0",
|
"http-errors": "1.8.0",
|
||||||
"http-status-codes": "2.1.4",
|
"http-status-codes": "2.1.4",
|
||||||
"semver": "7.3.5"
|
"semver": "7.3.5",
|
||||||
|
"fastify-warning": "0.2.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@verdaccio/types": "workspace:11.0.0-6-next.9"
|
"@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 pluginUtils from './plugin-utils';
|
||||||
import * as fileUtils from './file-utils';
|
import * as fileUtils from './file-utils';
|
||||||
import * as pkgUtils from './pkg-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 { VerdaccioError, API_ERROR, SUPPORT_ERRORS, APP_ERROR } from './error-utils';
|
||||||
export {
|
export {
|
||||||
|
@ -32,4 +33,5 @@ export {
|
||||||
validatioUtils,
|
validatioUtils,
|
||||||
constants,
|
constants,
|
||||||
pluginUtils,
|
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"
|
"build": "cross-env BABEL_ENV=registry babel src/ --out-dir build/ --copy-files --extensions \".ts,.tsx\" --source-maps"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@verdaccio/core": "workspace:6.0.0-6-next.2",
|
||||||
"@verdaccio/logger-prettify": "workspace:6.0.0-6-next.4",
|
"@verdaccio/logger-prettify": "workspace:6.0.0-6-next.4",
|
||||||
"debug": "4.3.2",
|
"debug": "4.3.2",
|
||||||
"lodash": "4.17.21",
|
"lodash": "4.17.21",
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import pino from 'pino';
|
import pino from 'pino';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import buildDebug from 'debug';
|
import buildDebug from 'debug';
|
||||||
|
import { warningUtils } from '@verdaccio/core';
|
||||||
|
|
||||||
const debug = buildDebug('verdaccio:logger');
|
const debug = buildDebug('verdaccio:logger');
|
||||||
|
|
||||||
|
@ -75,7 +76,7 @@ export function createLogger(
|
||||||
export function getLogger() {
|
export function getLogger() {
|
||||||
if (_.isNil(logger)) {
|
if (_.isNil(logger)) {
|
||||||
// FIXME: not sure about display here a warning
|
// FIXME: not sure about display here a warning
|
||||||
process.emitWarning('logger is not defined');
|
warningUtils.emit(warningUtils.Codes.VERWAR002);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,9 +103,7 @@ 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 =
|
warningUtils.emit(warningUtils.Codes.VERDEP002);
|
||||||
'deprecate: multiple logger configuration is deprecated, please check the migration guide.';
|
|
||||||
process.emitWarning(deprecateMessage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// verdaccio 5 does not allow multiple logger configuration
|
// verdaccio 5 does not allow multiple logger configuration
|
||||||
|
@ -125,9 +124,7 @@ export function setup(options: LoggerConfig | LoggerConfigItem = DEFAULT_LOGGER_
|
||||||
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(
|
warningUtils.emit(warningUtils.Codes.VERWAR003);
|
||||||
'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,7 +1,26 @@
|
||||||
|
import { warningUtils } from '@verdaccio/core';
|
||||||
import { logger, setup } from '../src';
|
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', () => {
|
describe('logger', () => {
|
||||||
test('dsadasd', () => {
|
beforeEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
test.skip('should write message logger', () => {
|
||||||
jest.spyOn(process.stdout, 'write');
|
jest.spyOn(process.stdout, 'write');
|
||||||
setup([
|
setup([
|
||||||
{
|
{
|
||||||
|
@ -15,7 +34,6 @@ describe('logger', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('throw deprecation warning if multiple loggers configured', () => {
|
test('throw deprecation warning if multiple loggers configured', () => {
|
||||||
const spy = jest.spyOn(process, 'emitWarning');
|
|
||||||
setup([
|
setup([
|
||||||
{
|
{
|
||||||
level: 'info',
|
level: 'info',
|
||||||
|
@ -24,18 +42,11 @@ describe('logger', () => {
|
||||||
level: 'http',
|
level: 'http',
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
expect(spy).toHaveBeenCalledWith(
|
expect(mockWarningUtils).toHaveBeenCalledWith(warningUtils.Codes.VERDEP002);
|
||||||
'deprecate: multiple logger configuration is deprecated, please check the migration guide.'
|
|
||||||
);
|
|
||||||
spy.mockRestore();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('regression: do not throw deprecation warning if no logger config is provided', () => {
|
test('regression: do not throw deprecation warning if no logger config is provided', () => {
|
||||||
const spy = jest.spyOn(process, 'emitWarning');
|
|
||||||
setup();
|
setup();
|
||||||
expect(spy).not.toHaveBeenCalledWith(
|
expect(mockWarningUtils).not.toHaveBeenCalled();
|
||||||
'deprecate: multiple logger configuration is deprecated, please check the migration guide.'
|
|
||||||
);
|
|
||||||
spy.mockRestore();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { warningUtils } from '@verdaccio/core';
|
||||||
|
|
||||||
export const DEFAULT_PORT = '4873';
|
export const DEFAULT_PORT = '4873';
|
||||||
export const DEFAULT_PROTOCOL = 'http';
|
export const DEFAULT_PROTOCOL = 'http';
|
||||||
export const DEFAULT_DOMAIN = 'localhost';
|
export const DEFAULT_DOMAIN = 'localhost';
|
||||||
|
@ -71,11 +73,7 @@ export function getListListenAddresses(argListen: string | void, configListen: a
|
||||||
const parsedAddr = parseAddress(addr);
|
const parsedAddr = parseAddress(addr);
|
||||||
|
|
||||||
if (!parsedAddr) {
|
if (!parsedAddr) {
|
||||||
process.emitWarning(
|
warningUtils.emit(warningUtils.Codes.VERWAR004, addr);
|
||||||
// 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');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return parsedAddr;
|
return parsedAddr;
|
||||||
|
|
6
pnpm-lock.yaml
generated
6
pnpm-lock.yaml
generated
|
@ -265,6 +265,7 @@ importers:
|
||||||
packages/cli:
|
packages/cli:
|
||||||
specifiers:
|
specifiers:
|
||||||
'@verdaccio/config': workspace:6.0.0-6-next.9
|
'@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/fastify-migration': workspace:6.0.0-6-next.14
|
||||||
'@verdaccio/logger': workspace:6.0.0-6-next.6
|
'@verdaccio/logger': workspace:6.0.0-6-next.6
|
||||||
'@verdaccio/node-api': workspace:6.0.0-6-next.22
|
'@verdaccio/node-api': workspace:6.0.0-6-next.22
|
||||||
|
@ -275,6 +276,7 @@ importers:
|
||||||
ts-node: 10.2.1
|
ts-node: 10.2.1
|
||||||
dependencies:
|
dependencies:
|
||||||
'@verdaccio/config': link:../config
|
'@verdaccio/config': link:../config
|
||||||
|
'@verdaccio/core': link:../core/core
|
||||||
'@verdaccio/fastify-migration': link:../core/server
|
'@verdaccio/fastify-migration': link:../core/server
|
||||||
'@verdaccio/logger': link:../logger
|
'@verdaccio/logger': link:../logger
|
||||||
'@verdaccio/node-api': link:../node-api
|
'@verdaccio/node-api': link:../node-api
|
||||||
|
@ -311,10 +313,12 @@ importers:
|
||||||
packages/core/core:
|
packages/core/core:
|
||||||
specifiers:
|
specifiers:
|
||||||
'@verdaccio/types': workspace:11.0.0-6-next.9
|
'@verdaccio/types': workspace:11.0.0-6-next.9
|
||||||
|
fastify-warning: 0.2.0
|
||||||
http-errors: 1.8.0
|
http-errors: 1.8.0
|
||||||
http-status-codes: 2.1.4
|
http-status-codes: 2.1.4
|
||||||
semver: 7.3.5
|
semver: 7.3.5
|
||||||
dependencies:
|
dependencies:
|
||||||
|
fastify-warning: 0.2.0
|
||||||
http-errors: 1.8.0
|
http-errors: 1.8.0
|
||||||
http-status-codes: 2.1.4
|
http-status-codes: 2.1.4
|
||||||
semver: 7.3.5
|
semver: 7.3.5
|
||||||
|
@ -481,12 +485,14 @@ importers:
|
||||||
packages/logger:
|
packages/logger:
|
||||||
specifiers:
|
specifiers:
|
||||||
'@types/pino': 6.3.12
|
'@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/logger-prettify': workspace:6.0.0-6-next.4
|
||||||
'@verdaccio/types': workspace:11.0.0-6-next.9
|
'@verdaccio/types': workspace:11.0.0-6-next.9
|
||||||
debug: 4.3.2
|
debug: 4.3.2
|
||||||
lodash: 4.17.21
|
lodash: 4.17.21
|
||||||
pino: 6.13.3
|
pino: 6.13.3
|
||||||
dependencies:
|
dependencies:
|
||||||
|
'@verdaccio/core': link:../core/core
|
||||||
'@verdaccio/logger-prettify': link:../logger-prettify
|
'@verdaccio/logger-prettify': link:../logger-prettify
|
||||||
debug: 4.3.2
|
debug: 4.3.2
|
||||||
lodash: 4.17.21
|
lodash: 4.17.21
|
||||||
|
|
Loading…
Add table
Reference in a new issue