Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 40 additions & 6 deletions packages/nuxi/src/utils/banner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,60 @@ import { readFileSync } from 'node:fs'
import { colors } from 'consola/utils'
import { resolveModulePath } from 'exsolve'

import { tryResolveNuxt } from './kit'
import { loadKit, tryResolveNuxt } from './kit'
import { logger } from './logger'

export function showVersions(cwd: string) {
export async function showVersions(cwd: string) {
const { bold, gray, green } = colors
const nuxtDir = tryResolveNuxt(cwd)
function getPkgVersion(pkg: string) {

const kit = await loadKit(cwd)
const config = await kit.loadNuxtConfig({ cwd })
Comment on lines +13 to +14
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will likely slow down the load of nuxt by (probably) ~100ms.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danielroe The function won't be awaited. See #1021 (comment)

This shouldn't slow down the dev server then, right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danielroe is there any other way to get current builder without using the kit?


function getBuilder(): { name: string, version: string } {
switch (config.builder) {
case '@nuxt/rspack-builder':
return { name: 'Rspack', version: getPkgVersion('@rspack/core') }
case '@nuxt/webpack-builder':
return { name: 'Webpack', version: getPkgVersion('webpack') }
case '@nuxt/vite-builder':
default: {
const pkgJSON = getPkgJSON('vite')
const isRolldown = pkgJSON.name.includes('rolldown')
return { name: isRolldown ? 'Rolldown-Vite' : 'Vite', version: pkgJSON.version }
}
}
}

function getPkgJSON(pkg: string) {
for (const url of [cwd, nuxtDir]) {
if (!url) {
continue
}
const p = resolveModulePath(`${pkg}/package.json`, { from: url, try: true })
if (p) {
return JSON.parse(readFileSync(p, 'utf-8')).version as string
return JSON.parse(readFileSync(p, 'utf-8'))
}
}
return ''
return null
}

function getPkgVersion(pkg: string) {
const pkgJSON = getPkgJSON(pkg)
return pkgJSON?.version ?? ''
}

const nuxtVersion = getPkgVersion('nuxt') || getPkgVersion('nuxt-nightly') || getPkgVersion('nuxt3') || getPkgVersion('nuxt-edge')
const nitroVersion = getPkgVersion('nitropack') || getPkgVersion('nitropack-nightly') || getPkgVersion('nitropack-edge')
const builder = getBuilder()
const vueVersion = getPkgVersion('vue') || null

logger.log(gray(green(`Nuxt ${bold(nuxtVersion)}`) + (nitroVersion ? ` with Nitro ${bold(nitroVersion)}` : '')))
logger.log(
green(`Nuxt ${bold(nuxtVersion)}`)
+ gray(' (with: ')
+ (nitroVersion ? gray(`Nitro ${bold(nitroVersion)}`) : '')
+ gray(`, ${builder.name} ${bold(builder.version)}`)
+ (vueVersion ? gray(`, Vue ${bold(vueVersion)}`) : '')
+ gray(')'),
)
}
1 change: 1 addition & 0 deletions playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "nuxi dev",
"dev:prepare": "nuxt prepare",
"test": "vitest"
},
Expand Down
Loading