diff --git a/.changeset/happy-donuts-taste.md b/.changeset/happy-donuts-taste.md new file mode 100644 index 000000000..2751d1dd0 --- /dev/null +++ b/.changeset/happy-donuts-taste.md @@ -0,0 +1,20 @@ +--- +'astro': minor +--- + +Adds a new command `astro info`, useful for sharing debugging information about your current environment when you need help! + +```shell +astro info +``` + +Output + +``` +Astro version v2.6.6 +Package manager pnpm +Platform darwin +Architecture arm64 +Adapter @astrojs/vercel/serverless +Integrations None +``` diff --git a/packages/astro/package.json b/packages/astro/package.json index 63410c2de..eba193727 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -166,6 +166,7 @@ "vfile": "^5.3.7", "vite": "^4.3.9", "vitefu": "^0.2.4", + "which-pm": "^2.0.0", "yargs-parser": "^21.1.1", "zod": "^3.20.6" }, diff --git a/packages/astro/src/cli/index.ts b/packages/astro/src/cli/index.ts index 4f0fa941c..cee50ac92 100644 --- a/packages/astro/src/cli/index.ts +++ b/packages/astro/src/cli/index.ts @@ -19,6 +19,7 @@ import { formatConfigErrorMessage, formatErrorMessage, printHelp } from '../core import * as event from '../events/index.js'; import { eventConfigError, eventError, telemetry } from '../events/index.js'; import { openInBrowser } from './open.js'; +import { arch, platform } from 'node:os'; type Arguments = yargs.Arguments; type CLICommand = @@ -32,6 +33,7 @@ type CLICommand = | 'reload' | 'sync' | 'check' + | 'info' | 'telemetry'; /** Display --help flag */ @@ -47,6 +49,7 @@ function printAstroHelp() { ['check', 'Check your project for errors.'], ['dev', 'Start the development server.'], ['docs', 'Open documentation in your web browser.'], + ['info', 'List info about your current Astro setup.'], ['preview', 'Preview your build locally.'], ['sync', 'Generate content collection types.'], ['telemetry', 'Configure telemetry settings.'], @@ -71,6 +74,56 @@ async function printVersion() { console.log(` ${colors.bgGreen(colors.black(` astro `))} ${colors.green(`v${ASTRO_VERSION}`)}`); } +async function printInfo({ + cwd, + flags, + logging, +}: { + cwd?: string; + flags?: Flags; + logging: LogOptions; +}) { + const whichPm = await import('which-pm'); + const packageManager = await whichPm.default(process.cwd()); + let adapter = "Couldn't determine."; + let integrations = []; + + const MAX_PADDING = 25; + function printRow(label: string, value: string) { + const padding = MAX_PADDING - label.length; + console.log(`${colors.bold(label)}` + ' '.repeat(padding) + `${colors.green(value)}`); + } + + try { + const { userConfig } = await openConfig({ + cwd, + flags, + cmd: 'info', + logging, + }); + if (userConfig.adapter?.name) { + adapter = userConfig.adapter.name; + } + if (userConfig.integrations) { + integrations = (userConfig?.integrations ?? []) + .filter(Boolean) + .flat() + .map((i: any) => i?.name); + } + } catch (_e) {} + console.log(); + printRow('Astro version', `v${ASTRO_VERSION}`); + printRow('Package manager', packageManager.name); + printRow('Platform', platform()); + printRow('Architecture', arch()); + printRow('Adapter', adapter); + let integrationsString = "None or couldn't determine."; + if (integrations.length > 0) { + integrationsString = integrations.join(', '); + } + printRow('Integrations', integrationsString); +} + /** Determine which command the user requested */ function resolveCommand(flags: Arguments): CLICommand { const cmd = flags._[2] as string; @@ -85,6 +138,7 @@ function resolveCommand(flags: Arguments): CLICommand { 'preview', 'check', 'docs', + 'info', ]); if (supportedCommands.has(cmd)) { return cmd as CLICommand; @@ -116,7 +170,11 @@ async function handleConfigError( **/ async function runCommand(cmd: string, flags: yargs.Arguments) { const root = flags.root; - + // logLevel + let logging: LogOptions = { + dest: nodeLogDestination, + level: 'info', + }; switch (cmd) { case 'help': printAstroHelp(); @@ -124,13 +182,12 @@ async function runCommand(cmd: string, flags: yargs.Arguments) { case 'version': await printVersion(); return process.exit(0); + case 'info': { + await printInfo({ cwd: root, flags, logging }); + return process.exit(0); + } } - // logLevel - let logging: LogOptions = { - dest: nodeLogDestination, - level: 'info', - }; if (flags.verbose) { logging.level = 'debug'; enableVerboseLogging(); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0ee9cf674..3ede0d921 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -643,6 +643,9 @@ importers: vitefu: specifier: ^0.2.4 version: 0.2.4(vite@4.3.9) + which-pm: + specifier: ^2.0.0 + version: 2.0.0 yargs-parser: specifier: ^21.1.1 version: 21.1.1