0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-30 22:34:10 -05:00

fix: restore logger on init (#2202)

* chore: restore logger on init

* chore: changeset
This commit is contained in:
Juan Picado 2021-04-26 07:42:25 +02:00 committed by GitHub
parent 6e21bee204
commit 19d272d10e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 62 additions and 147 deletions

View file

@ -0,0 +1,21 @@
---
'@verdaccio/cli': patch
'@verdaccio/types': patch
'@verdaccio/node-api': patch
'@verdaccio/server': patch
---
fix: restore logger on init
Enable logger after parse configuration and log the very first step on startup phase.
```bash
warn --- experiments are enabled, it is recommended do not use experiments in production comment out this section to disable it
info --- support for experiment [token] is disabled
info --- support for experiment [search] is disabled
(node:50831) Warning: config.logs is deprecated, rename configuration to "config.log"
(Use `node --trace-warnings ...` to show where the warning was created)
info --- http address http://localhost:4873/
info --- version: 6.0.0-6-next.11
info --- server started
```

View file

@ -38,7 +38,6 @@
"@verdaccio/e2e-cli": "1.0.0",
"@verdaccio/e2e-ui": "1.0.0",
"@verdaccio/cli-standalone": "6.0.0-alpha.3",
"@verdaccio/cli-ui": "6.0.0-alpha.3",
"@verdaccio/tarball": "11.0.0-alpha.3",
"@verdaccio/url": "11.0.0-alpha.3"
},

View file

@ -44,7 +44,7 @@
},
"dependencies": {
"@verdaccio/config": "workspace:6.0.0-6-next.5",
"@verdaccio/cli-ui": "workspace:6.0.0-alpha.3",
"@verdaccio/logger": "workspace:6.0.0-6-next.4",
"@verdaccio/node-api": "workspace:6.0.0-6-next.11",
"@verdaccio/fastify-migration": "workspace:6.0.0-6-next.9",
"commander": "6.2.0",

View file

@ -1,5 +1,5 @@
import { displayError } from '@verdaccio/cli-ui';
import { Cli } from 'clipanion';
import { InfoCommand } from './commands/info';
import { InitCommand } from './commands/init';
import { VersionCommand } from './commands/version';
@ -32,7 +32,7 @@ cli.register(NewServer);
cli.runExit(args, Cli.defaultContext);
process.on('uncaughtException', function (err) {
displayError(
console.error(
// eslint-disable-next-line max-len
`uncaught exception, please report (https://github.com/verdaccio/verdaccio/issues) this: \n${err.stack}`
);

View file

@ -1,6 +1,8 @@
import { Command, Option } from 'clipanion';
import { findConfigFile, parseConfigFile } from '@verdaccio/config';
import { setup, logger } from '@verdaccio/logger';
import { initServer } from '@verdaccio/node-api';
import { ConfigRuntime } from '@verdaccio/types';
export const DEFAULT_PROCESS_NAME: string = 'verdaccio';
@ -41,10 +43,23 @@ export class InitCommand extends Command {
description: 'use this configuration file (default: ./config.yaml)',
});
private initLogger(logConfig: ConfigRuntime) {
try {
if (logConfig.logs) {
process.emitWarning('config.logs is deprecated, rename configuration to "config.log"');
}
// FUTURE: remove fallback when is ready
setup(logConfig.log || logConfig.logs);
} catch {
throw new Error('error on init logger');
}
}
public async execute() {
try {
const configPathLocation = findConfigFile(this.config as string);
const configParsed = parseConfigFile(configPathLocation);
this.initLogger(configParsed);
const { web } = configParsed;
process.title = web?.title || DEFAULT_PROCESS_NAME;
@ -52,6 +67,7 @@ export class InitCommand extends Command {
const { version, name } = require('../../package.json');
await initServer(configParsed, this.port as string, version, name);
logger.info('server started');
} catch (err) {
console.error(err);
process.exit(1);

View file

@ -18,6 +18,9 @@
},
{
"path": "../node-api"
},
{
"path": "../logger"
}
]
}

View file

@ -1,6 +0,0 @@
{
"extends": "../../../.babelrc",
"presets": [
"@babel/preset-react"
]
}

View file

@ -1,5 +0,0 @@
{
"rules": {
"no-console": 0
}
}

View file

@ -1,3 +0,0 @@
const config = require('../../../jest/config');
module.exports = Object.assign({}, config, {});

View file

@ -1,55 +0,0 @@
{
"name": "@verdaccio/cli-ui",
"version": "6.0.0-alpha.3",
"description": "cli ui components",
"keywords": [
"private",
"package",
"repository",
"registry",
"enterprise",
"modules",
"proxy",
"server",
"verdaccio"
],
"author": "Juan Picado <juanpicado19@gmail.com>",
"license": "MIT",
"homepage": "https://verdaccio.org",
"repository": {
"type": "https",
"url": "https://github.com/verdaccio/verdaccio",
"directory": "packages/core/cli-ui"
},
"bugs": {
"url": "https://github.com/verdaccio/verdaccio/issues"
},
"publishConfig": {
"access": "public"
},
"main": "build/index.js",
"types": "build/index.d.ts",
"files": [
"build"
],
"engines": {
"node": ">=10",
"npm": ">=6"
},
"dependencies": {
"chalk": "^4.1.0",
"terminal-link": "^2.1.1"
},
"scripts": {
"clean": "rimraf ./build",
"test": "cross-env NODE_ENV=test BABEL_ENV=test jest",
"build:types": "tsc --emitDeclarationOnly -p tsconfig.build.json",
"build:js": "babel src/ --out-dir build/ --copy-files --extensions \".ts,.tsx\" --source-maps",
"watch": "pnpm build:js -- --watch",
"build": "pnpm run build:js && pnpm run build:types"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/verdaccio"
}
}

View file

@ -1 +0,0 @@
export * from './messages';

View file

@ -1,25 +0,0 @@
import chalk from 'chalk';
import terminalLink from 'terminal-link';
export const PRIMARY_COLOR = `#24394e`;
export function displayMessage(message: string) {
console.log(chalk.hex(PRIMARY_COLOR).bold(message));
}
export function displayWarning(message: string) {
console.log(chalk.yellow.bold(message));
}
export function displayError(message: string) {
console.log(chalk.red.bold(message));
}
export function displayLink(url: string) {
if (terminalLink.isSupported) {
const link = terminalLink(url, url);
return chalk.blue.underline(link);
}
return url;
}

View file

@ -1,3 +0,0 @@
describe('cli ui', () => {
test.todo('add required test for this module');
});

View file

@ -1,9 +0,0 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./build"
},
"include": ["src/**/*"],
"exclude": ["src/**/*.test.ts"]
}

View file

@ -1,11 +0,0 @@
{
"extends": "../../../tsconfig.reference.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./build",
"composite": true,
"declaration": true
},
"include": ["src/**/*.ts"],
"exclude": ["src/**/*.test.ts"]
}

View file

@ -371,7 +371,9 @@ declare module '@verdaccio/types' {
storage?: string | void;
packages: PackageList;
uplinks: UpLinksConfList;
// @deprecated in favor of log
logs?: LoggerConf[];
log?: LoggerConf[];
web?: WebConf;
auth?: AuthConf;
security: Security;

View file

@ -41,7 +41,6 @@
"dependencies": {
"@verdaccio/commons-api": "workspace:11.0.0-alpha.3",
"@verdaccio/config": "workspace:6.0.0-6-next.5",
"@verdaccio/cli-ui": "workspace:6.0.0-alpha.3",
"@verdaccio/server": "workspace:6.0.0-6-next.10",
"@verdaccio/logger": "workspace:6.0.0-6-next.4",
"core-js": "^3.6.5",

View file

@ -1,4 +1,4 @@
import { displayWarning, displayMessage } from '@verdaccio/cli-ui';
import { logger } from '@verdaccio/logger';
export function displayExperimentsInfoBox(flags) {
if (!flags) {
@ -7,14 +7,16 @@ export function displayExperimentsInfoBox(flags) {
const experimentList = Object.keys(flags);
if (experimentList.length >= 1) {
displayWarning(
'⚠️ experiments are enabled, we recommend do not use experiments in production, ' +
'comment out this section to disable it'
logger.warn(
// eslint-disable-next-line max-len
`experiments are enabled, it is recommended do not use experiments in production comment out this section to disable it`
);
experimentList.forEach((experiment) => {
displayMessage(
` - support for ${experiment} ${flags[experiment] ? 'is enabled' : ' is disabled'}
`
// eslint-disable-next-line max-len
logger.info(
`support for experiment [${experiment}] ${
flags[experiment] ? 'is enabled' : ' is disabled'
}`
);
});
}

View file

@ -10,7 +10,7 @@ import url from 'url';
import { findConfigFile, parseConfigFile } from '@verdaccio/config';
import { API_ERROR } from '@verdaccio/commons-api';
import { ConfigRuntime, HttpsConfKeyCert, HttpsConfPfx } from '@verdaccio/types';
import { setup } from '@verdaccio/logger';
import { setup, logger } from '@verdaccio/logger';
import server from '@verdaccio/server';
import { getListListenAddresses } from './cli-utils';
import { displayExperimentsInfoBox } from './experiments';
@ -132,8 +132,8 @@ export async function initServer(
pathname: '/',
})
}`;
console.log(`http address ${addressServer}`);
console.log(`${pkgName} / ${version}`);
logger.info(`http address ${addressServer}`);
logger.info(`version: ${version}`);
resolve();
})
.on('error', function (err): void {

View file

@ -18,7 +18,7 @@ import { ConfigRuntime } from '@verdaccio/types';
import { IAuth, IBasicAuth } from '@verdaccio/auth';
import { IStorageHandler } from '@verdaccio/store';
import { setup, logger } from '@verdaccio/logger';
import { logger } from '@verdaccio/logger';
import { log, final, errorReportingMiddleware } from '@verdaccio/middleware';
import AuditMiddleware from 'verdaccio-audit';
@ -143,7 +143,6 @@ const defineAPI = function (config: IConfig, storage: IStorageHandler): any {
};
export default (async function (configHash: ConfigRuntime): Promise<any> {
setup(configHash.logs);
const config: IConfig = new AppConfig(_.cloneDeep(configHash));
// register middleware plugins
const plugin_params = {

View file

@ -290,9 +290,9 @@ importers:
packages/cli:
specifiers:
'@verdaccio/cli-ui': workspace:6.0.0-alpha.3
'@verdaccio/config': workspace:6.0.0-6-next.5
'@verdaccio/fastify-migration': workspace:6.0.0-6-next.9
'@verdaccio/logger': workspace:6.0.0-6-next.4
'@verdaccio/node-api': workspace:6.0.0-6-next.11
clipanion: 3.0.0-rc.11
commander: 6.2.0
@ -300,9 +300,9 @@ importers:
kleur: 3.0.3
semver: 7.3.2
dependencies:
'@verdaccio/cli-ui': link:../core/cli-ui
'@verdaccio/config': link:../config
'@verdaccio/fastify-migration': link:../core/server
'@verdaccio/logger': link:../logger
'@verdaccio/node-api': link:../node-api
clipanion: 3.0.0-rc.11
commander: 6.2.0
@ -335,14 +335,6 @@ importers:
'@types/minimatch': 3.0.3
'@types/yup': 0.29.9
packages/core/cli-ui:
specifiers:
chalk: ^4.1.0
terminal-link: ^2.1.1
dependencies:
chalk: 4.1.0
terminal-link: 2.1.1
packages/core/commons-api:
specifiers:
http-errors: ^1.8.0
@ -607,7 +599,6 @@ importers:
packages/node-api:
specifiers:
'@verdaccio/cli-ui': workspace:6.0.0-alpha.3
'@verdaccio/commons-api': workspace:11.0.0-alpha.3
'@verdaccio/config': workspace:6.0.0-6-next.5
'@verdaccio/logger': workspace:6.0.0-6-next.4
@ -621,7 +612,6 @@ importers:
selfsigned: 1.10.7
supertest: ^6.1.3
dependencies:
'@verdaccio/cli-ui': link:../core/cli-ui
'@verdaccio/commons-api': link:../core/commons-api
'@verdaccio/config': link:../config
'@verdaccio/logger': link:../logger
@ -25207,6 +25197,7 @@ packages:
dependencies:
has-flag: 4.0.0
supports-color: 7.2.0
dev: true
/svg-tag-names/2.0.1:
resolution: {integrity: sha512-BEZ508oR+X/b5sh7bT0RqDJ7GhTpezjj3P1D4kugrOaPs6HijviWksoQ63PS81vZn0QCjZmVKjHDBniTo+Domg==}
@ -25390,6 +25381,7 @@ packages:
dependencies:
ansi-escapes: 4.3.1
supports-hyperlinks: 2.1.0
dev: true
/terser-webpack-plugin/1.4.5_webpack@4.43.0:
resolution: {integrity: sha512-04Rfe496lN8EYruwi6oPQkG0vo8C+HT49X687FZnpPF0qMAIHONI6HEXYPKDOE8e5HjXTyKfqRd/agHtH0kOtw==}