fix(nuxt): set nitro log level to match nuxt options (#25213)

This commit is contained in:
kongmoumou 2024-01-16 02:08:50 +08:00 committed by GitHub
parent 97db0fada7
commit 2de774d95a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,7 +11,7 @@ import escapeRE from 'escape-string-regexp'
import { defu } from 'defu' import { defu } from 'defu'
import fsExtra from 'fs-extra' import fsExtra from 'fs-extra'
import { dynamicEventHandler } from 'h3' import { dynamicEventHandler } from 'h3'
import type { Nuxt, RuntimeConfig } from 'nuxt/schema' import type { Nuxt, NuxtOptions, RuntimeConfig } from 'nuxt/schema'
// @ts-expect-error TODO: add legacy type support for subpath imports // @ts-expect-error TODO: add legacy type support for subpath imports
import { template as defaultSpaLoadingTemplate } from '@nuxt/ui-templates/templates/spa-loading-icon.mjs' import { template as defaultSpaLoadingTemplate } from '@nuxt/ui-templates/templates/spa-loading-icon.mjs'
import { version as nuxtVersion } from '../../package.json' import { version as nuxtVersion } from '../../package.json'
@ -19,6 +19,12 @@ import { distDir } from '../dirs'
import { toArray } from '../utils' import { toArray } from '../utils'
import { ImportProtectionPlugin, nuxtImportProtections } from './plugins/import-protection' import { ImportProtectionPlugin, nuxtImportProtections } from './plugins/import-protection'
const logLevelMapReverse = {
silent: 0,
info: 3,
verbose: 3
} satisfies Record<NuxtOptions['logLevel'], NitroConfig['logLevel']>
export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
// Resolve config // Resolve config
const _nitroConfig = ((nuxt.options as any).nitro || {}) as NitroConfig const _nitroConfig = ((nuxt.options as any).nitro || {}) as NitroConfig
@ -218,7 +224,8 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
rollupConfig: { rollupConfig: {
output: {}, output: {},
plugins: [] plugins: []
} },
logLevel: logLevelMapReverse[nuxt.options.logLevel],
} satisfies NitroConfig) } satisfies NitroConfig)
// Resolve user-provided paths // Resolve user-provided paths