diff --git a/packages/nuxt/src/components/module.ts b/packages/nuxt/src/components/module.ts index 1cf145d139..f61061e5d9 100644 --- a/packages/nuxt/src/components/module.ts +++ b/packages/nuxt/src/components/module.ts @@ -1,9 +1,10 @@ import { existsSync, statSync, writeFileSync } from 'node:fs' import { isAbsolute, join, normalize, relative, resolve } from 'pathe' -import { addBuildPlugin, addPluginTemplate, addTemplate, addTypeTemplate, addVitePlugin, defineNuxtModule, findPath, logger, resolveAlias, resolvePath, updateTemplates } from '@nuxt/kit' +import { addBuildPlugin, addPluginTemplate, addTemplate, addTypeTemplate, addVitePlugin, defineNuxtModule, findPath, resolveAlias, resolvePath, updateTemplates } from '@nuxt/kit' import type { Component, ComponentsDir, ComponentsOptions } from 'nuxt/schema' import { distDir } from '../dirs' +import { logger } from '../utils' import { componentNamesTemplate, componentsIslandsTemplate, componentsMetadataTemplate, componentsPluginTemplate, componentsTypeTemplate } from './templates' import { scanComponents } from './scan' diff --git a/packages/nuxt/src/components/plugins/loader.ts b/packages/nuxt/src/components/plugins/loader.ts index 80b2b949e1..92c563ed35 100644 --- a/packages/nuxt/src/components/plugins/loader.ts +++ b/packages/nuxt/src/components/plugins/loader.ts @@ -5,9 +5,10 @@ import { pascalCase } from 'scule' import { relative } from 'pathe' import type { Component, ComponentsOptions } from 'nuxt/schema' -import { logger, tryUseNuxt } from '@nuxt/kit' +import { tryUseNuxt } from '@nuxt/kit' import { QUOTE_RE, SX_RE, isVue } from '../../core/utils' import { installNuxtModule } from '../../core/features' +import { logger } from '../../utils' interface LoaderOptions { getComponents (): Component[] diff --git a/packages/nuxt/src/components/scan.ts b/packages/nuxt/src/components/scan.ts index 30adc35a21..14cae18bc6 100644 --- a/packages/nuxt/src/components/scan.ts +++ b/packages/nuxt/src/components/scan.ts @@ -2,11 +2,12 @@ import { readdir } from 'node:fs/promises' import { basename, dirname, extname, join, relative } from 'pathe' import { globby } from 'globby' import { kebabCase, pascalCase, splitByCase } from 'scule' -import { isIgnored, logger, useNuxt } from '@nuxt/kit' +import { isIgnored, useNuxt } from '@nuxt/kit' import { withTrailingSlash } from 'ufo' import type { Component, ComponentsDir } from 'nuxt/schema' import { QUOTE_RE, resolveComponentNameSegments } from '../core/utils' +import { logger } from '../utils' const ISLAND_RE = /\.island(?:\.global)?$/ const GLOBAL_RE = /\.global(?:\.island)?$/ diff --git a/packages/nuxt/src/core/app.ts b/packages/nuxt/src/core/app.ts index ddfa14e390..887604d5e3 100644 --- a/packages/nuxt/src/core/app.ts +++ b/packages/nuxt/src/core/app.ts @@ -1,11 +1,12 @@ import { promises as fsp, mkdirSync, writeFileSync } from 'node:fs' import { dirname, join, relative, resolve } from 'pathe' import { defu } from 'defu' -import { findPath, logger, normalizePlugin, normalizeTemplate, resolveAlias, resolveFiles, resolvePath } from '@nuxt/kit' +import { findPath, normalizePlugin, normalizeTemplate, resolveAlias, resolveFiles, resolvePath } from '@nuxt/kit' import type { Nuxt, NuxtApp, NuxtPlugin, NuxtTemplate, ResolvedNuxtTemplate } from 'nuxt/schema' import type { PluginMeta } from 'nuxt/app' +import { logger } from '../utils' import * as defaultTemplates from './templates' import { getNameFromPath, hasSuffix, uniqueBy } from './utils' import { extractMetadata, orderMap } from './plugins/plugin-metadata' diff --git a/packages/nuxt/src/core/builder.ts b/packages/nuxt/src/core/builder.ts index 2a37ae8db8..6b24372b88 100644 --- a/packages/nuxt/src/core/builder.ts +++ b/packages/nuxt/src/core/builder.ts @@ -1,11 +1,12 @@ import type { EventType } from '@parcel/watcher' import type { FSWatcher } from 'chokidar' import { watch as chokidarWatch } from 'chokidar' -import { importModule, isIgnored, logger, tryResolveModule, useNuxt } from '@nuxt/kit' +import { importModule, isIgnored, tryResolveModule, useNuxt } from '@nuxt/kit' import { debounce } from 'perfect-debounce' import { normalize, relative, resolve } from 'pathe' import type { Nuxt, NuxtBuilder } from 'nuxt/schema' +import { logger } from '../utils' import { generateApp as _generateApp, createApp } from './app' import { checkForExternalConfigurationFiles } from './external-config-files' import { cleanupCaches, getVueHash } from './cache' diff --git a/packages/nuxt/src/core/external-config-files.ts b/packages/nuxt/src/core/external-config-files.ts index 1f0359cee8..247f0c60b2 100644 --- a/packages/nuxt/src/core/external-config-files.ts +++ b/packages/nuxt/src/core/external-config-files.ts @@ -1,5 +1,6 @@ -import { findPath, logger } from '@nuxt/kit' +import { findPath } from '@nuxt/kit' import { basename } from 'pathe' +import { logger } from '../utils' /** * Check for those external configuration files that are not compatible with Nuxt, diff --git a/packages/nuxt/src/core/features.ts b/packages/nuxt/src/core/features.ts index 2e1bba0106..6e22d04bff 100644 --- a/packages/nuxt/src/core/features.ts +++ b/packages/nuxt/src/core/features.ts @@ -1,7 +1,8 @@ import { addDependency } from 'nypm' import { resolvePackageJSON } from 'pkg-types' -import { logger, useNuxt } from '@nuxt/kit' +import { useNuxt } from '@nuxt/kit' import { isCI, provider } from 'std-env' +import { logger } from '../utils' const isStackblitz = provider === 'stackblitz' diff --git a/packages/nuxt/src/core/nuxt.ts b/packages/nuxt/src/core/nuxt.ts index 83eb42ad5e..957da98314 100644 --- a/packages/nuxt/src/core/nuxt.ts +++ b/packages/nuxt/src/core/nuxt.ts @@ -4,7 +4,7 @@ import { join, normalize, relative, resolve } from 'pathe' import { createDebugger, createHooks } from 'hookable' import ignore from 'ignore' import type { LoadNuxtOptions } from '@nuxt/kit' -import { addBuildPlugin, addComponent, addPlugin, addPluginTemplate, addRouteMiddleware, addServerPlugin, addTypeTemplate, addVitePlugin, addWebpackPlugin, installModule, loadNuxtConfig, logger, nuxtCtx, resolveAlias, resolveFiles, resolveIgnorePatterns, resolvePath, tryResolveModule, useNitro } from '@nuxt/kit' +import { addBuildPlugin, addComponent, addPlugin, addPluginTemplate, addRouteMiddleware, addServerPlugin, addTypeTemplate, addVitePlugin, addWebpackPlugin, installModule, loadNuxtConfig, nuxtCtx, resolveAlias, resolveFiles, resolveIgnorePatterns, resolvePath, tryResolveModule, useNitro } from '@nuxt/kit' import type { Nuxt, NuxtHooks, NuxtModule, NuxtOptions } from 'nuxt/schema' import type { PackageJson } from 'pkg-types' import { readPackageJSON } from 'pkg-types' @@ -31,6 +31,7 @@ import importsModule from '../imports/module' import { distDir, pkgDir } from '../dirs' import { version } from '../../package.json' import { scriptsStubsPreset } from '../imports/presets' +import { logger } from '../utils' import { resolveTypePath } from './utils/types' import { createImportProtectionPatterns } from './plugins/import-protection' import { UnctxTransformPlugin } from './plugins/unctx' diff --git a/packages/nuxt/src/core/plugins/plugin-metadata.ts b/packages/nuxt/src/core/plugins/plugin-metadata.ts index c6db582eb4..e3c31157ce 100644 --- a/packages/nuxt/src/core/plugins/plugin-metadata.ts +++ b/packages/nuxt/src/core/plugins/plugin-metadata.ts @@ -6,10 +6,10 @@ import type { Nuxt } from '@nuxt/schema' import { createUnplugin } from 'unplugin' import MagicString from 'magic-string' import { normalize } from 'pathe' -import { logger } from '@nuxt/kit' import type { ObjectPlugin, PluginMeta } from 'nuxt/app' import { parseAndWalk, withLocations } from '../../core/utils/parse' +import { logger } from '../../utils' const internalOrderMap = { // -50: pre-all (nuxt) diff --git a/packages/nuxt/src/core/plugins/resolve-deep-imports.ts b/packages/nuxt/src/core/plugins/resolve-deep-imports.ts index f55924c5f8..c597e2d4b0 100644 --- a/packages/nuxt/src/core/plugins/resolve-deep-imports.ts +++ b/packages/nuxt/src/core/plugins/resolve-deep-imports.ts @@ -1,10 +1,11 @@ import { parseNodeModulePath, resolvePath } from 'mlly' import { isAbsolute, normalize } from 'pathe' import type { Plugin } from 'vite' -import { logger, resolveAlias } from '@nuxt/kit' +import { resolveAlias } from '@nuxt/kit' import type { Nuxt } from '@nuxt/schema' import { pkgDir } from '../../dirs' +import { logger } from '../../utils' export function resolveDeepImportsPlugin (nuxt: Nuxt): Plugin { const exclude: string[] = ['virtual:', '\0virtual:', '/__skip_vite', '@vitest/'] diff --git a/packages/nuxt/src/core/schema.ts b/packages/nuxt/src/core/schema.ts index 5e3750bfc6..4c7e8d7ada 100644 --- a/packages/nuxt/src/core/schema.ts +++ b/packages/nuxt/src/core/schema.ts @@ -5,7 +5,7 @@ import { resolve } from 'pathe' import { watch } from 'chokidar' import { defu } from 'defu' import { debounce } from 'perfect-debounce' -import { createResolver, defineNuxtModule, importModule, logger, tryResolveModule } from '@nuxt/kit' +import { createResolver, defineNuxtModule, importModule, tryResolveModule } from '@nuxt/kit' import { generateTypes, resolveSchema as resolveUntypedSchema, @@ -13,6 +13,7 @@ import { import type { Schema, SchemaDefinition } from 'untyped' import untypedPlugin from 'untyped/babel-plugin' import { createJiti } from 'jiti' +import { logger } from '../utils' export default defineNuxtModule({ meta: { diff --git a/packages/nuxt/src/imports/module.ts b/packages/nuxt/src/imports/module.ts index 2714470a43..4854dc8677 100644 --- a/packages/nuxt/src/imports/module.ts +++ b/packages/nuxt/src/imports/module.ts @@ -1,5 +1,5 @@ import { existsSync } from 'node:fs' -import { addBuildPlugin, addTemplate, addTypeTemplate, defineNuxtModule, isIgnored, logger, resolveAlias, tryResolveModule, updateTemplates, useNuxt } from '@nuxt/kit' +import { addBuildPlugin, addTemplate, addTypeTemplate, defineNuxtModule, isIgnored, resolveAlias, tryResolveModule, updateTemplates, useNuxt } from '@nuxt/kit' import { isAbsolute, join, normalize, relative, resolve } from 'pathe' import type { Import, Unimport } from 'unimport' import { createUnimport, scanDirExports, toExports } from 'unimport' @@ -7,7 +7,7 @@ import type { ImportPresetWithDeprecation, ImportsOptions, ResolvedNuxtTemplate import escapeRE from 'escape-string-regexp' import { lookupNodeModuleSubpath, parseNodeModulePath } from 'mlly' -import { isDirectory } from '../utils' +import { isDirectory, logger } from '../utils' import { TransformPlugin } from './transform' import { defaultPresets } from './presets' diff --git a/packages/nuxt/src/pages/module.ts b/packages/nuxt/src/pages/module.ts index 6353aa76ca..44e7f527cc 100644 --- a/packages/nuxt/src/pages/module.ts +++ b/packages/nuxt/src/pages/module.ts @@ -1,6 +1,6 @@ import { existsSync, readdirSync } from 'node:fs' import { mkdir, readFile } from 'node:fs/promises' -import { addBuildPlugin, addComponent, addPlugin, addTemplate, addTypeTemplate, defineNuxtModule, findPath, logger, resolvePath, updateTemplates, useNitro } from '@nuxt/kit' +import { addBuildPlugin, addComponent, addPlugin, addTemplate, addTypeTemplate, defineNuxtModule, findPath, resolvePath, updateTemplates, useNitro } from '@nuxt/kit' import { dirname, join, relative, resolve } from 'pathe' import { genImport, genObjectFromRawEntries, genString } from 'knitwork' import { joinURL } from 'ufo' @@ -14,6 +14,7 @@ import type { NitroRouteConfig } from 'nitro/types' import { defu } from 'defu' import { distDir } from '../dirs' import { resolveTypePath } from '../core/utils/types' +import { logger } from '../utils' import { normalizeRoutes, resolvePagesRoutes, resolveRoutePaths } from './utils' import { extractRouteRules, getMappedPages } from './route-rules' import { PageMetaPlugin } from './plugins/page-meta' diff --git a/packages/nuxt/src/pages/plugins/page-meta.ts b/packages/nuxt/src/pages/plugins/page-meta.ts index 366db0848f..95350d48df 100644 --- a/packages/nuxt/src/pages/plugins/page-meta.ts +++ b/packages/nuxt/src/pages/plugins/page-meta.ts @@ -5,7 +5,6 @@ import type { StaticImport } from 'mlly' import { findExports, findStaticImports, parseStaticImport } from 'mlly' import MagicString from 'magic-string' import { isAbsolute } from 'pathe' -import { logger } from '@nuxt/kit' import { ScopeTracker, @@ -16,6 +15,7 @@ import { walk, withLocations, } from '../../core/utils/parse' +import { logger } from '../../utils' interface PageMetaPluginOptions { dev?: boolean @@ -184,7 +184,7 @@ export const PageMetaPlugin = (options: PageMetaPluginOptions = {}) => createUnp walk(decl.init, { enter: (node, parent) => { if (node.type === 'AwaitExpression') { - logger.error(`[nuxt] Await expressions are not supported in definePageMeta. File: '${id}'`) + logger.error(`Await expressions are not supported in definePageMeta. File: '${id}'`) throw new Error('await in definePageMeta') } if ( diff --git a/packages/nuxt/src/pages/utils.ts b/packages/nuxt/src/pages/utils.ts index c188e8a903..aeb524e615 100644 --- a/packages/nuxt/src/pages/utils.ts +++ b/packages/nuxt/src/pages/utils.ts @@ -2,7 +2,7 @@ import { runInNewContext } from 'node:vm' import fs from 'node:fs' import { extname, normalize, relative, resolve } from 'pathe' import { encodePath, joinURL, withLeadingSlash } from 'ufo' -import { logger, resolveFiles, resolvePath, useNuxt } from '@nuxt/kit' +import { resolveFiles, resolvePath, useNuxt } from '@nuxt/kit' import { genArrayFromRaw, genDynamicImport, genImport, genSafeVariableName } from 'knitwork' import escapeRE from 'escape-string-regexp' import { filename } from 'pathe/utils' @@ -13,7 +13,7 @@ import type { NuxtPage } from 'nuxt/schema' import { parseAndWalk } from '../core/utils/parse' import { getLoader, uniqueBy } from '../core/utils' -import { toArray } from '../utils' +import { logger, toArray } from '../utils' enum SegmentParserState { initial, @@ -252,7 +252,7 @@ export async function getRouteMeta (contents: string, absolutePath: string, extr try { extractedMeta[key] = JSON.parse(runInNewContext(`JSON.stringify(${valueString})`, {})) } catch { - console.debug(`[nuxt] Skipping extraction of \`${key}\` metadata as it is not JSON-serializable (reading \`${absolutePath}\`).`) + logger.debug(`Skipping extraction of \`${key}\` metadata as it is not JSON-serializable (reading \`${absolutePath}\`).`) dynamicProperties.add(key) continue } @@ -265,7 +265,7 @@ export async function getRouteMeta (contents: string, absolutePath: string, extr continue } if (element.type !== 'Literal' || typeof element.value !== 'string') { - console.debug(`[nuxt] Skipping extraction of \`${key}\` metadata as it is not an array of string literals (reading \`${absolutePath}\`).`) + logger.debug(`Skipping extraction of \`${key}\` metadata as it is not an array of string literals (reading \`${absolutePath}\`).`) dynamicProperties.add(key) continue } @@ -276,7 +276,7 @@ export async function getRouteMeta (contents: string, absolutePath: string, extr } if (property.value.type !== 'Literal' || (typeof property.value.value !== 'string' && typeof property.value.value !== 'boolean')) { - console.debug(`[nuxt] Skipping extraction of \`${key}\` metadata as it is not a string literal or array of string literals (reading \`${absolutePath}\`).`) + logger.debug(`Skipping extraction of \`${key}\` metadata as it is not a string literal or array of string literals (reading \`${absolutePath}\`).`) dynamicProperties.add(key) continue } diff --git a/packages/nuxt/src/utils.ts b/packages/nuxt/src/utils.ts index 03fd928135..b8dfe6c6d9 100644 --- a/packages/nuxt/src/utils.ts +++ b/packages/nuxt/src/utils.ts @@ -1,4 +1,5 @@ import { promises as fsp } from 'node:fs' +import { useLogger } from '@nuxt/kit' /** @since 3.9.0 */ export function toArray (value: T | T[]): T[] { @@ -8,3 +9,5 @@ export function toArray (value: T | T[]): T[] { export async function isDirectory (path: string) { return (await fsp.lstat(path)).isDirectory() } + +export const logger = useLogger('nuxt') diff --git a/packages/nuxt/test/scan-components.test.ts b/packages/nuxt/test/scan-components.test.ts index 65cc86aff0..e41b5d370e 100644 --- a/packages/nuxt/test/scan-components.test.ts +++ b/packages/nuxt/test/scan-components.test.ts @@ -1,5 +1,6 @@ import { fileURLToPath } from 'node:url' import { resolve } from 'pathe' +import { consola } from 'consola' import { expect, it, vi } from 'vitest' import type { ComponentsDir } from 'nuxt/schema' @@ -10,6 +11,7 @@ const rFixture = (...p: string[]) => resolve(fixtureDir, ...p) vi.mock('@nuxt/kit', () => ({ isIgnored: () => false, + useLogger: () => consola.create({}).withTag('nuxt'), })) const dirs: ComponentsDir[] = [