UNPKG

nuxi

Version:
135 lines (134 loc) 6.35 kB
import { t as defineCommand } from "./dist-B03QHgrC.mjs"; import { n as colors } from "./consola.DXBYu-KD-qSGefJ79.mjs"; import "./utils-MaFlCoS1.mjs"; import { a as k, s as x, t as A } from "./dist-BkNIIgFa.mjs"; import { r as version } from "./package-CptHM_tu.mjs"; import { a as legacyRootDirArgs, t as cwdArgs } from "./_shared-D6pJgr6t.mjs"; import { n as logger, p as oe } from "./logger-CtlB9piy.mjs"; import { c as resolve } from "./pathe.M-eThtNZ-BfnU2wdd.mjs"; import { n as tryResolveNuxt } from "./kit-Bx45zdA5.mjs"; import { r as readPackageJSON } from "./dist-BPzTdxaO.mjs"; import { t as getBuilder } from "./banner-1xgvoFgm.mjs"; import { writeText } from "./dist-CXuRnu3A.mjs"; import { r as detectPackageManager } from "./dist-bPNZE3kQ.mjs"; import { t as formatInfoBox } from "./formatting-D0TdF_6l.mjs"; import { t as getPackageManagerVersion } from "./packageManagers-BdTDSXBz.mjs"; import process from "node:process"; import os from "node:os"; //#region src/commands/info.ts const LEADING_SLASH_RE = /^\//; var info_default = defineCommand({ meta: { name: "info", description: "Get information about Nuxt project" }, args: { ...cwdArgs, ...legacyRootDirArgs }, async run(ctx) { const cwd = resolve(ctx.args.cwd || ctx.args.rootDir); const nuxtConfig = await getNuxtConfig(cwd); const { dependencies = {}, devDependencies = {} } = await readPackageJSON(cwd).catch(() => ({})); const nuxtPath = tryResolveNuxt(cwd); async function getDepVersion(name) { for (const url of [cwd, nuxtPath]) { if (!url) continue; const pkg = await readPackageJSON(name, { url }).catch(() => null); if (pkg) return pkg.version; } return dependencies[name] || devDependencies[name]; } async function listModules(arr = []) { const info = []; for (let m of arr) { if (Array.isArray(m)) m = m[0]; const name = normalizeConfigModule(m, cwd); if (name) { const v = await getDepVersion(name.split("/").splice(0, 2).join("/")); info.push(`\`${v ? `${name}@${v}` : name}\``); } } return info.join(", "); } const nuxtVersion = await getDepVersion("nuxt") || await getDepVersion("nuxt-nightly") || await getDepVersion("nuxt-edge") || await getDepVersion("nuxt3") || "-"; const isLegacy = nuxtVersion.startsWith("2"); const builder = !isLegacy ? nuxtConfig.builder || "vite" : nuxtConfig.bridge?.vite ? "vite" : nuxtConfig.buildModules?.includes("nuxt-vite") ? "vite" : "webpack"; let packageManager = (await detectPackageManager(cwd))?.name; if (packageManager) packageManager += `@${getPackageManagerVersion(packageManager)}`; const osType = os.type(); const builderInfo = typeof builder === "string" ? getBuilder(cwd, builder) : { name: "custom", version: "0.0.0" }; const infoObj = { "Operating system": osType === "Darwin" ? `macOS ${os.release()}` : osType === "Windows_NT" ? `Windows ${os.release()}` : `${osType} ${os.release()}`, "CPU": `${os.cpus()[0]?.model || "unknown"} (${os.cpus().length} cores)`, ...k ? { "Bun version": Bun?.version } : A ? { "Deno version": Deno?.version.deno } : { "Node.js version": process.version }, "nuxt/cli version": version, "Package manager": packageManager ?? "unknown", "Nuxt version": nuxtVersion, "Nitro version": await getDepVersion("nitropack") || await getDepVersion("nitro"), "Builder": builderInfo.name === "custom" ? "custom" : `${builderInfo.name.toLowerCase()}@${builderInfo.version}`, "Config": Object.keys(nuxtConfig).map((key) => `\`${key}\``).sort().join(", "), "Modules": await listModules(nuxtConfig.modules), ...isLegacy ? { "Build modules": await listModules(nuxtConfig.buildModules || []) } : {} }; logger.info(`Nuxt root directory: ${colors.cyan(nuxtConfig.rootDir || cwd)}\n`); const boxStr = formatInfoBox(infoObj); let firstColumnLength = 0; let secondColumnLength = 0; const entries = Object.entries(infoObj).map(([label, val]) => { if (label.length > firstColumnLength) firstColumnLength = label.length + 4; if ((val || "").length > secondColumnLength) secondColumnLength = (val || "").length + 2; return [label, val || "-"]; }); let copyStr = `| ${" ".repeat(firstColumnLength)} | ${" ".repeat(secondColumnLength)} |\n| ${"-".repeat(firstColumnLength)} | ${"-".repeat(secondColumnLength)} |\n`; for (const [label, value] of entries) if (!x) copyStr += `| ${`**${label}**`.padEnd(firstColumnLength)} | ${(value.includes("`") ? value : `\`${value}\``).padEnd(secondColumnLength)} |\n`; if (!x && await writeText(copyStr).then(() => true).catch(() => false)) oe(`\n${boxStr}`, ` Nuxt project info ${colors.gray("(copied to clipboard) ")}`, { contentAlign: "left", titleAlign: "left", width: "auto", titlePadding: 2, contentPadding: 2, rounded: true }); else logger.info(`Nuxt project info:\n${copyStr}`, { withGuide: false }); const isNuxt3 = !isLegacy; const isBridge = !isNuxt3 && infoObj["Build modules"]?.includes("bridge"); const repo = isBridge ? "nuxt/bridge" : "nuxt/nuxt"; const docsURL = isNuxt3 || isBridge ? "https://nuxt.com" : "https://v2.nuxt.com"; logger.info(`👉 Read documentation: ${colors.cyan(docsURL)}`); if (isNuxt3 || isBridge) { logger.info(`👉 Report an issue: ${colors.cyan(`https://github.com/${repo}/issues/new?template=bug-report.yml`)}`, { spacing: 0 }); logger.info(`👉 Suggest an improvement: ${colors.cyan(`https://github.com/${repo}/discussions/new`)}`, { spacing: 0 }); } } }); function normalizeConfigModule(module, rootDir) { if (!module) return null; if (typeof module === "string") return module.split(rootDir).pop().split("node_modules").pop().replace(LEADING_SLASH_RE, ""); if (typeof module === "function") return `${module.name}()`; if (Array.isArray(module)) return normalizeConfigModule(module[0], rootDir); return null; } async function getNuxtConfig(rootDir) { try { const { createJiti } = await import("./jiti-BfsRAE30.mjs").then((n) => n.t); const jiti = createJiti(rootDir, { interopDefault: true, alias: { "~": rootDir, "@": rootDir } }); globalThis.defineNuxtConfig = (c) => c; const result = await jiti.import("./nuxt.config", { default: true }); delete globalThis.defineNuxtConfig; return result; } catch { return {}; } } //#endregion export { info_default as default };