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

Commit 1496d3a

Browse files
authored
feat(nuxi): wrap and normalize all console outputs (#8846)
1 parent 4bbd261 commit 1496d3a

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

packages/nuxi/src/cli.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import mri from 'mri'
22
import { red } from 'colorette'
3-
import consola from 'consola'
3+
import consola, { ConsolaReporter } from 'consola'
44
import { checkEngines } from './utils/engines'
55
import { commands, Command, NuxtCommand } from './commands'
66
import { showHelp } from './utils/help'
@@ -39,7 +39,29 @@ async function _main () {
3939
}
4040

4141
// Wrap all console logs with consola for better DX
42-
consola.wrapConsole()
42+
consola.wrapAll()
43+
44+
// Filter out unwanted logs
45+
// TODO: Use better API from consola for intercepting logs
46+
const wrapReporter = (reporter: ConsolaReporter) => <ConsolaReporter> {
47+
log (logObj, ctx) {
48+
if (!logObj.args || !logObj.args.length) { return }
49+
const msg = logObj.args[0]
50+
if (typeof msg === 'string' && !process.env.DEBUG) {
51+
// Hide vue-router 404 warnings
52+
if (msg.startsWith('[Vue Router warn]: No match found for location with path')) {
53+
return
54+
}
55+
// Hide sourcemap warnings related to node_modules
56+
if (msg.startsWith('Sourcemap') && msg.includes('node_modules')) {
57+
return
58+
}
59+
}
60+
return reporter.log(logObj, ctx)
61+
}
62+
}
63+
// @ts-expect-error
64+
consola._reporters = consola._reporters.map(wrapReporter)
4365

4466
process.on('unhandledRejection', err => consola.error('[unhandledRejection]', err))
4567
process.on('uncaughtException', err => consola.error('[uncaughtException]', err))

0 commit comments

Comments
 (0)