|
| 1 | +#!/usr/bin/env node |
| 2 | +import os from 'os' |
| 3 | +import childProcess from 'child_process' |
| 4 | + |
| 5 | +import chalk from 'next/dist/compiled/chalk' |
| 6 | +import arg from 'next/dist/compiled/arg/index.js' |
| 7 | +import { printAndExit } from '../server/lib/utils' |
| 8 | +import { cliCommand } from '../bin/next' |
| 9 | +import isError from '../lib/is-error' |
| 10 | + |
| 11 | +const nextInfo: cliCommand = async (argv) => { |
| 12 | + const validArgs: arg.Spec = { |
| 13 | + // Types |
| 14 | + '--help': Boolean, |
| 15 | + // Aliases |
| 16 | + '-h': '--help', |
| 17 | + } |
| 18 | + let args: arg.Result<arg.Spec> |
| 19 | + try { |
| 20 | + args = arg(validArgs, { argv }) |
| 21 | + } catch (error) { |
| 22 | + if (isError(error) && error.code === 'ARG_UNKNOWN_OPTION') { |
| 23 | + return printAndExit(error.message, 1) |
| 24 | + } |
| 25 | + throw error |
| 26 | + } |
| 27 | + |
| 28 | + if (args['--help']) { |
| 29 | + console.log( |
| 30 | + ` |
| 31 | + Description |
| 32 | + Prints relevant details about the current system which can be used to report Next.js bugs |
| 33 | + |
| 34 | + Usage |
| 35 | + $ next info |
| 36 | +
|
| 37 | + Learn more: ${chalk.cyan( |
| 38 | + 'https://nextjs.org/docs/api-reference/cli#info' |
| 39 | + )}` |
| 40 | + ) |
| 41 | + return |
| 42 | + } |
| 43 | + |
| 44 | + console.log(` |
| 45 | + Operating System: |
| 46 | + Platform: ${os.platform()} |
| 47 | + Arch: ${os.arch()} |
| 48 | + Version: ${os.version()} |
| 49 | + Binaries: |
| 50 | + Node: ${process.versions.node} |
| 51 | + npm: ${getBinaryVersion('npm')} |
| 52 | + Yarn: ${getBinaryVersion('yarn')} |
| 53 | + pnpm: ${getBinaryVersion('pnpm')} |
| 54 | + Relevant packages: |
| 55 | + next: ${getPackageVersion('next')} |
| 56 | + react: ${getPackageVersion('react')} |
| 57 | + react-dom: ${getPackageVersion('react-dom')}`) |
| 58 | +} |
| 59 | + |
| 60 | +export { nextInfo } |
| 61 | + |
| 62 | +function getPackageVersion(packageName: string) { |
| 63 | + try { |
| 64 | + return require(`${packageName}/package.json`).version |
| 65 | + } catch { |
| 66 | + return 'N/A' |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +function getBinaryVersion(binaryName: string) { |
| 71 | + try { |
| 72 | + return childProcess.execSync(`${binaryName} --version`).toString().trim() |
| 73 | + } catch { |
| 74 | + return 'N/A' |
| 75 | + } |
| 76 | +} |
0 commit comments