-
Notifications
You must be signed in to change notification settings - Fork 109
feat(build,dev): add vite and vue version to banner #1021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
71e6ebd
97d4efd
5e7eb73
7fd9283
21c18a9
588f267
2ef2001
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this will likely slow down the load of nuxt by (probably) ~100ms.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(')'), | ||
| ) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.