Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
feat(nuxi): wrap and normalize all console outputs (#8846)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored Nov 9, 2022
1 parent 4bbd261 commit 1496d3a
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions packages/nuxi/src/cli.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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) => <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))
Expand Down

0 comments on commit 1496d3a

Please sign in to comment.