Unverified Commit 3ad2035a authored by Balázs Orbán's avatar Balázs Orbán Committed by GitHub

feat(cli): introduce `next info` CLI command (#32972)

This PR adds a new command to the `next` CLI.

Running `next info` will print useful information to the terminal about how/where Next.js is run. This information can be added to the Bug report when opening an issue in the repository.

This makes reporting issues more accurate and doesn't require the user to guess certain details, the command will retrieve it on their behalf.

Example output:

```sh
$ npx --no-install next info

    Operating System:
      Platform: linux
      Version: #22-Ubuntu SMP Fri Nov 5 13:21:36 UTC 2021
    Binaries:
      Node: 16.13.0
      npm: 8.1.0
      Yarn: 1.22.17
      pnpm: 6.24.2
    Relevant packages:
      next: 12.0.8-canary.14
      react: 17.0.2
      react-dom: 17.0.2


```

The idea is based on #32858

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
Co-authored-by: 's avatarSteven <229881+styfle@users.noreply.github.com>
parent 1be87040
...@@ -14,6 +14,12 @@ body: ...@@ -14,6 +14,12 @@ body:
- type: markdown - type: markdown
attributes: attributes:
value: 'next@canary is the beta version of Next.js. It includes all features and fixes that are pending to land on the stable release line.' value: 'next@canary is the beta version of Next.js. It includes all features and fixes that are pending to land on the stable release line.'
- type: textarea
attributes:
label: Run `next info` (available from version 12.0.8 and up)
description: Please run `next info` in the root directory of your project and paste the results. You might need to use `npx --no-install next info` if next is not in the current PATH.
validations:
required: false
- type: input - type: input
attributes: attributes:
label: What version of Next.js are you using? label: What version of Next.js are you using?
......
...@@ -21,7 +21,7 @@ Usage ...@@ -21,7 +21,7 @@ Usage
$ next <command> $ next <command>
Available commands Available commands
build, start, export, dev, lint, telemetry build, start, export, dev, lint, telemetry, info
Options Options
--version, -v Version number --version, -v Version number
...@@ -125,3 +125,36 @@ Next.js collects **completely anonymous** telemetry data about general usage. ...@@ -125,3 +125,36 @@ Next.js collects **completely anonymous** telemetry data about general usage.
Participation in this anonymous program is optional, and you may opt-out if you'd not like to share any information. Participation in this anonymous program is optional, and you may opt-out if you'd not like to share any information.
To learn more about Telemetry, [please read this document](https://nextjs.org/telemetry/). To learn more about Telemetry, [please read this document](https://nextjs.org/telemetry/).
## Info
`next info` prints relevant details about the current system which can be used to report Next.js bugs.
This information includes Operating System platform/arch/version, Binaries (Node.js, npm, Yarn, pnpm) and npm package versions (`next`, `react`, `react-dom`).
Running the following in your project's root directory:
```bash
next info
```
will give you information like this example:
```bash
Operating System:
Platform: linux
Arch: x64
Version: #22-Ubuntu SMP Fri Nov 5 13:21:36 UTC 2021
Binaries:
Node: 16.13.0
npm: 8.1.0
Yarn: 1.22.17
pnpm: 6.24.2
Relevant packages:
next: 12.0.8
react: 17.0.2
react-dom: 17.0.2
```
This information should then be pasted into GitHub Issues.
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
"@types/fs-extra": "8.1.0", "@types/fs-extra": "8.1.0",
"@types/http-proxy": "1.17.3", "@types/http-proxy": "1.17.3",
"@types/jest": "24.0.13", "@types/jest": "24.0.13",
"@types/node": "13.11.0",
"@types/selenium-webdriver": "4.0.15", "@types/selenium-webdriver": "4.0.15",
"@types/sharp": "0.29.3", "@types/sharp": "0.29.3",
"@types/string-hash": "1.1.1", "@types/string-hash": "1.1.1",
......
...@@ -23,6 +23,7 @@ const commands: { [command: string]: () => Promise<cliCommand> } = { ...@@ -23,6 +23,7 @@ const commands: { [command: string]: () => Promise<cliCommand> } = {
lint: () => Promise.resolve(require('../cli/next-lint').nextLint), lint: () => Promise.resolve(require('../cli/next-lint').nextLint),
telemetry: () => telemetry: () =>
Promise.resolve(require('../cli/next-telemetry').nextTelemetry), Promise.resolve(require('../cli/next-telemetry').nextTelemetry),
info: () => Promise.resolve(require('../cli/next-info').nextInfo),
} }
const args = arg( const args = arg(
......
#!/usr/bin/env node
import os from 'os'
import childProcess from 'child_process'
import chalk from 'next/dist/compiled/chalk'
import arg from 'next/dist/compiled/arg/index.js'
import { printAndExit } from '../server/lib/utils'
import { cliCommand } from '../bin/next'
import isError from '../lib/is-error'
const nextInfo: cliCommand = async (argv) => {
const validArgs: arg.Spec = {
// Types
'--help': Boolean,
// Aliases
'-h': '--help',
}
let args: arg.Result<arg.Spec>
try {
args = arg(validArgs, { argv })
} catch (error) {
if (isError(error) && error.code === 'ARG_UNKNOWN_OPTION') {
return printAndExit(error.message, 1)
}
throw error
}
if (args['--help']) {
console.log(
`
Description
Prints relevant details about the current system which can be used to report Next.js bugs
Usage
$ next info
Learn more: ${chalk.cyan(
'https://nextjs.org/docs/api-reference/cli#info'
)}`
)
return
}
console.log(`
Operating System:
Platform: ${os.platform()}
Arch: ${os.arch()}
Version: ${os.version()}
Binaries:
Node: ${process.versions.node}
npm: ${getBinaryVersion('npm')}
Yarn: ${getBinaryVersion('yarn')}
pnpm: ${getBinaryVersion('pnpm')}
Relevant packages:
next: ${getPackageVersion('next')}
react: ${getPackageVersion('react')}
react-dom: ${getPackageVersion('react-dom')}`)
}
export { nextInfo }
function getPackageVersion(packageName: string) {
try {
return require(`${packageName}/package.json`).version
} catch {
return 'N/A'
}
}
function getBinaryVersion(binaryName: string) {
try {
return childProcess.execSync(`${binaryName} --version`).toString().trim()
} catch {
return 'N/A'
}
}
...@@ -456,6 +456,6 @@ export interface CacheFs { ...@@ -456,6 +456,6 @@ export interface CacheFs {
readFile(f: string): Promise<string> readFile(f: string): Promise<string>
readFileSync(f: string): string readFileSync(f: string): string
writeFile(f: string, d: any): Promise<void> writeFile(f: string, d: any): Promise<void>
mkdir(dir: string): Promise<void> mkdir(dir: string): Promise<void | string>
stat(f: string): Promise<{ mtime: Date }> stat(f: string): Promise<{ mtime: Date }>
} }
...@@ -400,4 +400,47 @@ describe('CLI Usage', () => { ...@@ -400,4 +400,47 @@ describe('CLI Usage', () => {
expect(stderr).not.toContain('UnhandledPromiseRejectionWarning') expect(stderr).not.toContain('UnhandledPromiseRejectionWarning')
}) })
}) })
describe('info', () => {
test('--help', async () => {
const help = await runNextCommand(['info', '--help'], {
stdout: true,
})
expect(help.stdout).toMatch(
/Prints relevant details about the current system which can be used to report Next\.js bugs/
)
})
test('-h', async () => {
const help = await runNextCommand(['info', '-h'], {
stdout: true,
})
expect(help.stdout).toMatch(
/Prints relevant details about the current system which can be used to report Next\.js bugs/
)
})
test('should print output', async () => {
const info = await runNextCommand(['info'], {
stdout: true,
})
expect(info.stdout).toMatch(
new RegExp(`
Operating System:
Platform: .*
Arch: .*
Version: .*
Binaries:
Node: .*
npm: .*
Yarn: .*
pnpm: .*
Relevant packages:
next: .*
react: .*
react-dom: .*
`)
)
})
})
}) })
...@@ -4694,9 +4694,10 @@ ...@@ -4694,9 +4694,10 @@
dependencies: dependencies:
"@types/node" "*" "@types/node" "*"
"@types/node@*", "@types/node@>= 8": "@types/node@*", "@types/node@13.11.0", "@types/node@>= 8":
version "13.1.4" version "13.11.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-13.1.4.tgz#4cfd90175a200ee9b02bd6b1cd19bc349741607e" resolved "https://registry.yarnpkg.com/@types/node/-/node-13.11.0.tgz#390ea202539c61c8fa6ba4428b57e05bc36dc47b"
integrity sha512-uM4mnmsIIPK/yeO+42F2RQhGUIs39K2RFmugcJANppXe6J1nvH87PvzPZYpza7Xhhs8Yn9yIAVdLZ84z61+0xQ==
"@types/node@10.12.18": "@types/node@10.12.18":
version "10.12.18" version "10.12.18"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment