From 1496d3a07d30df4faa378f840cd342c557e9e4d9 Mon Sep 17 00:00:00 2001 From: pooya parsa Date: Wed, 9 Nov 2022 11:55:40 +0100 Subject: [PATCH] feat(nuxi): wrap and normalize all console outputs (#8846) --- packages/nuxi/src/cli.ts | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/packages/nuxi/src/cli.ts b/packages/nuxi/src/cli.ts index 4796dec7fe..cd6cddf210 100755 --- a/packages/nuxi/src/cli.ts +++ b/packages/nuxi/src/cli.ts @@ -1,6 +1,6 @@ import mri from 'mri' import { red } from 'colorette' -import consola from 'consola' +import consola, { ConsolaReporter } from 'consola' import { checkEngines } from './utils/engines' import { commands, Command, NuxtCommand } from './commands' import { showHelp } from './utils/help' @@ -39,7 +39,29 @@ async function _main () { } // Wrap all console logs with consola for better DX -consola.wrapConsole() +consola.wrapAll() + +// Filter out unwanted logs +// TODO: Use better API from consola for intercepting logs +const wrapReporter = (reporter: ConsolaReporter) => { + log (logObj, ctx) { + if (!logObj.args || !logObj.args.length) { return } + const msg = logObj.args[0] + if (typeof msg === 'string' && !process.env.DEBUG) { + // Hide vue-router 404 warnings + if (msg.startsWith('[Vue Router warn]: No match found for location with path')) { + return + } + // Hide sourcemap warnings related to node_modules + if (msg.startsWith('Sourcemap') && msg.includes('node_modules')) { + return + } + } + return reporter.log(logObj, ctx) + } +} +// @ts-expect-error +consola._reporters = consola._reporters.map(wrapReporter) process.on('unhandledRejection', err => consola.error('[unhandledRejection]', err)) process.on('uncaughtException', err => consola.error('[uncaughtException]', err))