Skip to content

Commit c367367

Browse files
committed
fix(dev): disable timestamps on the project's consola instance
1 parent b71fbf0 commit c367367

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

packages/nuxt-cli/src/dev/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { NuxtDevContext, NuxtDevIPCMessage, NuxtParentIPCMessage } from './
66
import process from 'node:process'
77
import defu from 'defu'
88
import { resolveDotenvFileNames } from '../utils/args'
9+
import { configureProjectConsola } from '../utils/console'
910
import { overrideEnv } from '../utils/env.ts'
1011
import { isRemotePeerError } from '../utils/errors'
1112
import { debug } from '../utils/logger'
@@ -131,6 +132,8 @@ interface InitializeReturn {
131132
export async function initialize(devContext: NuxtDevContext, ctx: InitializeOptions = {}): Promise<InitializeReturn> {
132133
overrideEnv('development')
133134

135+
await configureProjectConsola(devContext.cwd)
136+
134137
const profileArg = devContext.args.profile
135138
const profiling = profileArg !== undefined
136139
const perfValue = profileArg === 'verbose' ? true : profiling ? 'quiet' : undefined

packages/nuxt-cli/src/utils/console.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import type { ConsolaReporter } from 'consola'
22

33
import process from 'node:process'
4+
import { pathToFileURL } from 'node:url'
45

56
import { consola } from 'consola'
7+
import { resolveModulePath } from 'exsolve'
68

79
import { isRemotePeerError } from './errors'
10+
import { tryResolveNuxt } from './kit'
811
import { debug } from './logger'
912
import { trackOutputSpacing } from './stdout'
1013

@@ -28,6 +31,23 @@ function wrapReporter(reporter: ConsolaReporter) {
2831
}) satisfies ConsolaReporter
2932
}
3033

34+
export async function configureProjectConsola(rootDir: string): Promise<void> {
35+
try {
36+
const path = resolveModulePath('consola', { from: tryResolveNuxt(rootDir) || rootDir, try: true })
37+
if (!path) {
38+
return
39+
}
40+
const mod = await import(pathToFileURL(path).href) as { consola?: typeof consola, default?: typeof consola }
41+
const projectConsola = mod.consola ?? mod.default
42+
if (projectConsola) {
43+
projectConsola.options.formatOptions.date = false
44+
}
45+
}
46+
catch (error) {
47+
debug('Could not configure the project consola:', error)
48+
}
49+
}
50+
3151
export function setupGlobalConsole(opts: { dev?: boolean } = {}) {
3252
consola.options.formatOptions.date = false
3353
consola.options.reporters = consola.options.reporters.map(wrapReporter)

0 commit comments

Comments
 (0)