diff --git a/packages/nuxi/src/commands/build.ts b/packages/nuxi/src/commands/build.ts index ddb7d8bf11c..3a410ded4b3 100644 --- a/packages/nuxi/src/commands/build.ts +++ b/packages/nuxi/src/commands/build.ts @@ -4,6 +4,7 @@ import { writeTypes } from '../utils/prepare' import { loadKit } from '../utils/kit' import { clearDir } from '../utils/fs' import { overrideEnv } from '../utils/env' +import { showVersions } from '../utils/banner' import { defineNuxtCommand } from './index' export default defineNuxtCommand({ @@ -16,6 +17,7 @@ export default defineNuxtCommand({ overrideEnv('production') const rootDir = resolve(args._[0] || '.') + showVersions(rootDir) const { loadNuxt, buildNuxt } = await loadKit(rootDir) diff --git a/packages/nuxi/src/commands/dev.ts b/packages/nuxi/src/commands/dev.ts index aa8edeb4509..d7fa5270586 100644 --- a/packages/nuxi/src/commands/dev.ts +++ b/packages/nuxi/src/commands/dev.ts @@ -7,7 +7,7 @@ import type { Nuxt } from '@nuxt/schema' import consola from 'consola' import { withTrailingSlash } from 'ufo' import { setupDotenv } from 'c12' -import { showBanner } from '../utils/banner' +import { showBanner, showVersions } from '../utils/banner' import { writeTypes } from '../utils/prepare' import { loadKit } from '../utils/kit' import { importModule } from '../utils/cjs' @@ -38,6 +38,8 @@ export default defineNuxtCommand({ } const rootDir = resolve(args._[0] || '.') + showVersions(rootDir) + await setupDotenv({ cwd: rootDir }) const listener = await listen(serverHandler, { diff --git a/packages/nuxi/src/commands/info.ts b/packages/nuxi/src/commands/info.ts index 06ce952edd4..8dac49d71b0 100644 --- a/packages/nuxi/src/commands/info.ts +++ b/packages/nuxi/src/commands/info.ts @@ -63,6 +63,7 @@ export default defineNuxtCommand({ OperatingSystem: os.type(), NodeVersion: process.version, NuxtVersion: nuxtVersion, + NitroVersion: getDepVersion('nitropack'), PackageManager: packageManager, Builder: builder, UserConfig: Object.keys(nuxtConfig).map(key => '`' + key + '`').join(', '), diff --git a/packages/nuxi/src/utils/banner.ts b/packages/nuxi/src/utils/banner.ts index 13410e1eb8a..0fc480f31ab 100644 --- a/packages/nuxi/src/utils/banner.ts +++ b/packages/nuxi/src/utils/banner.ts @@ -1,8 +1,26 @@ +import { createRequire } from 'node:module' import clear from 'clear' -import { green } from 'colorette' +import { bold, gray, green } from 'colorette' import { version } from '../../package.json' export function showBanner (_clear?: boolean) { if (_clear) { clear() } - console.log(green(`Nuxt CLI v${version}`)) + console.log(gray(`Nuxi ${(bold(version))}`)) +} + +export function showVersions (cwd: string) { + const _require = createRequire(cwd) + const getPkgVersion = (pkg: string) => { + try { + const { version } = _require(`${pkg}/package.json`) + return version || '' + } catch { /* not found */ } + return '' + } + const nuxtVersion = getPkgVersion('nuxt') || getPkgVersion('nuxt-edge') + const nitroVersion = getPkgVersion('nitropack') + console.log(gray( + green(`Nuxt ${bold(nuxtVersion)}`) + + (nitroVersion ? ` with Nitro ${(bold(nitroVersion))}` : '') + )) }