feat: rename debug keys

This commit is contained in:
Anthony Fu 2025-01-14 20:43:35 +08:00
parent 4457fc2a97
commit fb27f3f37d
No known key found for this signature in database
GPG Key ID: 179936958CD423FF
12 changed files with 56 additions and 19 deletions

View File

@ -120,7 +120,7 @@ function _defineNuxtModule<
// Measure setup time
if (setupTime > 5000 && uniqueKey !== '@nuxt/telemetry') {
logger.warn(`Slow module \`${uniqueKey || '<no name>'}\` took \`${setupTime}ms\` to setup.`)
} else if (nuxt.options.debug && nuxt.options.debug.log) {
} else if (nuxt.options.debug && nuxt.options.debug.modules) {
logger.info(`Module \`${uniqueKey || '<no name>'}\` took \`${setupTime}ms\` to setup.`)
}

View File

@ -2,7 +2,7 @@ import { createDebugger } from 'hookable'
import { defineNuxtPlugin } from '../nuxt'
export default defineNuxtPlugin({
name: 'nuxt:debug',
name: 'nuxt:debug:hooks',
enforce: 'pre',
setup (nuxtApp) {
createDebugger(nuxtApp.hooks, { tag: 'nuxt-app' })

View File

@ -87,7 +87,7 @@ export async function generateApp (nuxt: Nuxt, app: NuxtApp, options: { filter?:
const perf = performance.now() - start
const setupTime = Math.round((perf * 100)) / 100
if ((nuxt.options.debug && nuxt.options.debug.log) || setupTime > 500) {
if ((nuxt.options.debug && nuxt.options.debug.templates) || setupTime > 500) {
logger.info(`Compiled \`${template.filename}\` in ${setupTime}ms`)
}

View File

@ -119,7 +119,7 @@ function createWatcher () {
function createGranularWatcher () {
const nuxt = useNuxt()
if (nuxt.options.debug && nuxt.options.debug.log) {
if (nuxt.options.debug && nuxt.options.debug.watchers) {
// eslint-disable-next-line no-console
console.time('[nuxt] builder:chokidar:watch')
}
@ -164,7 +164,7 @@ function createGranularWatcher () {
})
watcher.on('ready', () => {
pending--
if (nuxt.options.debug && nuxt.options.debug.log && !pending) {
if (nuxt.options.debug && nuxt.options.debug.watchers && !pending) {
// eslint-disable-next-line no-console
console.timeEnd('[nuxt] builder:chokidar:watch')
}
@ -175,7 +175,7 @@ function createGranularWatcher () {
async function createParcelWatcher () {
const nuxt = useNuxt()
if (nuxt.options.debug && nuxt.options.debug.log) {
if (nuxt.options.debug && nuxt.options.debug.watchers) {
// eslint-disable-next-line no-console
console.time('[nuxt] builder:parcel:watch')
}
@ -201,7 +201,7 @@ async function createParcelWatcher () {
],
})
watcher.then((subscription) => {
if (nuxt.options.debug && nuxt.options.debug.log) {
if (nuxt.options.debug && nuxt.options.debug.watchers) {
// eslint-disable-next-line no-console
console.timeEnd('[nuxt] builder:parcel:watch')
}

View File

@ -52,7 +52,7 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
const isNuxtV4 = nuxt.options.future?.compatibilityVersion === 4
const nitroConfig: NitroConfig = defu(nuxt.options.nitro, {
debug: nuxt.options.debug && nuxt.options.debug.nitro,
debug: nuxt.options.debug ? nuxt.options.debug.nitro : false,
rootDir: nuxt.options.rootDir,
workspaceDir: nuxt.options.workspaceDir,
srcDir: nuxt.options.serverDir,

View File

@ -551,9 +551,13 @@ async function initNuxt (nuxt: Nuxt) {
addPlugin(resolve(nuxt.options.appDir, 'plugins/preload.server'))
}
// Add nuxt app debugger
if (nuxt.options.debug && nuxt.options.debug.browser) {
addPlugin(resolve(nuxt.options.appDir, 'plugins/debug'))
// Add nuxt app hooks debugger
if (
nuxt.options.debug
&& nuxt.options.debug.hooks
&& (nuxt.options.debug.hooks === true || nuxt.options.debug.hooks.client)
) {
addPlugin(resolve(nuxt.options.appDir, 'plugins/debug-hooks'))
}
// Add experimental Chrome devtools timings support
@ -811,7 +815,11 @@ export async function loadNuxt (opts: LoadNuxtOptions): Promise<Nuxt> {
nuxt.hooks.addHooks(opts.overrides.hooks)
}
if (nuxt.options.debug && nuxt.options.debug.hooks) {
if (
nuxt.options.debug
&& nuxt.options.debug.hooks
&& (nuxt.options.debug.hooks === true || nuxt.options.debug.hooks.server)
) {
createDebugger(nuxt.hooks, { tag: 'nuxt' })
}

View File

@ -176,7 +176,7 @@ export default defineNuxtModule({
const options: TypedRouterOptions = {
routesFolder: [],
dts: resolve(nuxt.options.buildDir, declarationFile),
logs: nuxt.options.debug && nuxt.options.debug.log,
logs: nuxt.options.debug && nuxt.options.debug.router,
async beforeWriteFiles (rootPage) {
rootPage.children.forEach(child => child.delete())
const pages = nuxt.apps.default?.pages || await resolvePagesRoutes(nuxt)

View File

@ -8,6 +8,7 @@ import { defu } from 'defu'
import { findWorkspaceDir } from 'pkg-types'
import type { RuntimeConfig } from '../types/config'
import type { NuxtDebugOptions } from '../types/debug'
export default defineUntypedSchema({
/**
@ -271,16 +272,27 @@ export default defineUntypedSchema({
* }
* ```
*
* @type {boolean | { log?: boolean, hooks?: boolean, nitro?: boolean, browser?: boolean, prod?: boolean }}
* @type {boolean | (typeof import('../src/types/debug').NuxtDebugOptions) | undefined}
*/
debug: {
$resolve: (val: boolean | { log?: boolean, hooks?: boolean, nitro?: boolean, browser?: boolean, prod?: boolean } | undefined) => {
$resolve: (val: boolean | NuxtDebugOptions | undefined) => {
val ??= isDebug
if (val === false) {
return val
}
if (val === true) {
return { log: true, hooks: true, nitro: true, browser: true, prod: true }
return {
templates: true,
modules: true,
watchers: true,
hooks: {
client: true,
server: true,
},
nitro: true,
router: true,
hydration: true,
} satisfies Required<NuxtDebugOptions>
}
return val
},

View File

@ -2,6 +2,7 @@ import { consola } from 'consola'
import { resolve } from 'pathe'
import { isTest } from 'std-env'
import { defineUntypedSchema } from 'untyped'
import type { NuxtDebugOptions } from '../types/debug'
export default defineUntypedSchema({
/**
@ -20,9 +21,10 @@ export default defineUntypedSchema({
},
define: {
$resolve: async (val: Record<string, any> | undefined, get) => {
const [isDev, isDebug] = await Promise.all([get('dev'), get('debug')]) as [boolean, boolean]
const [isDev, debug] = await Promise.all([get('dev'), get('debug')]) as [boolean, boolean | NuxtDebugOptions]
return {
'__VUE_PROD_HYDRATION_MISMATCH_DETAILS__': isDebug,
'__VUE_PROD_HYDRATION_MISMATCH_DETAILS__': Boolean(debug && (debug === true || debug.hydration)),
'process.dev': isDev,
'import.meta.dev': isDev,
'process.test': isTest,

View File

@ -8,6 +8,7 @@ export type { AppHeadMetaObject, MetaObject, MetaObjectRaw, HeadAugmentations }
export type { ModuleDefinition, ModuleMeta, ModuleOptions, ModuleSetupInstallResult, ModuleSetupReturn, NuxtModule, ResolvedModuleOptions } from './types/module'
export type { Nuxt, NuxtApp, NuxtPlugin, NuxtPluginTemplate, NuxtTemplate, NuxtTypeTemplate, NuxtServerTemplate, ResolvedNuxtTemplate } from './types/nuxt'
export type { RouterConfig, RouterConfigSerializable, RouterOptions } from './types/router'
export type { NuxtDebugOptions } from './types/debug'
// Schema
export { default as NuxtConfigSchema } from './config/index'

View File

@ -0,0 +1,14 @@
import type { NitroOptions } from 'nitro/types'
export interface NuxtDebugOptions {
templates?: boolean
modules?: boolean
watchers?: boolean
nitro?: NitroOptions['debug']
hydration?: boolean
router?: boolean
hooks?: boolean | {
server?: boolean
client?: boolean
}
}

View File

@ -33,6 +33,6 @@ export function vue (ctx: WebpackConfigContext) {
ctx.config.plugins!.push(new webpack.DefinePlugin({
'__VUE_OPTIONS_API__': 'true',
'__VUE_PROD_DEVTOOLS__': 'false',
'__VUE_PROD_HYDRATION_MISMATCH_DETAILS__': ctx.nuxt.options.debug && ctx.nuxt.options.debug.prod,
'__VUE_PROD_HYDRATION_MISMATCH_DETAILS__': ctx.nuxt.options.debug && ctx.nuxt.options.debug.hydration,
}))
}