From 1be1b313caa1ed5f277d6feb2e67fb67feacbf86 Mon Sep 17 00:00:00 2001 From: productdevbook Date: Sat, 3 Oct 2026 18:42:29 +0200 Subject: [PATCH] perf: print `--version` without loading the command graph `nuxt --version` imported dist/index.mjs (citty, every command stub, consola, clack) only to print the version from package.json, which made it 21% slower than v3.37.0. Answer it in the bin before that import, matching citty's own rule: `--version` or `-v` as the only argument. Co-Authored-By: Claude Opus 5.5 --- packages/nuxt-cli/bin/nuxi.mjs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/nuxt-cli/bin/nuxi.mjs b/packages/nuxt-cli/bin/nuxi.mjs index ce33c31a9..d8d7fa54f 100755 --- a/packages/nuxt-cli/bin/nuxi.mjs +++ b/packages/nuxt-cli/bin/nuxi.mjs @@ -74,7 +74,15 @@ if (process.argv[2] === 'dev') { await import('../dist/boot.mjs').then(({ bootDevUI }) => bootDevUI()).catch(() => {}) } -// eslint-disable-next-line antfu/no-top-level-await -const { runMain } = await import('../dist/index.mjs') +// Mirrors citty's built-in version flag without loading the command graph. +const args = process.argv.slice(2) +if (args.length === 1 && (args[0] === '--version' || args[0] === '-v')) { + // eslint-disable-next-line no-console + console.log(nodeModule.createRequire(import.meta.url)('../package.json').version) +} +else { + // eslint-disable-next-line antfu/no-top-level-await + const { runMain } = await import('../dist/index.mjs') -runMain() + runMain() +}