Skip to content

Commit 3ad2035

Browse files
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: Steven <[email protected]>
1 parent 1be8704 commit 3ad2035

File tree

8 files changed

+166
-5
lines changed

8 files changed

+166
-5
lines changed

.github/ISSUE_TEMPLATE/1.bug_report.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ body:
1414
- type: markdown
1515
attributes:
1616
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.'
17+
- type: textarea
18+
attributes:
19+
label: Run `next info` (available from version 12.0.8 and up)
20+
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.
21+
validations:
22+
required: false
1723
- type: input
1824
attributes:
1925
label: What version of Next.js are you using?

docs/api-reference/cli.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Usage
2121
$ next <command>
2222

2323
Available commands
24-
build, start, export, dev, lint, telemetry
24+
build, start, export, dev, lint, telemetry, info
2525

2626
Options
2727
--version, -v Version number
@@ -125,3 +125,36 @@ Next.js collects **completely anonymous** telemetry data about general usage.
125125
Participation in this anonymous program is optional, and you may opt-out if you'd not like to share any information.
126126

127127
To learn more about Telemetry, [please read this document](https://nextjs.org/telemetry/).
128+
129+
## Info
130+
131+
`next info` prints relevant details about the current system which can be used to report Next.js bugs.
132+
This information includes Operating System platform/arch/version, Binaries (Node.js, npm, Yarn, pnpm) and npm package versions (`next`, `react`, `react-dom`).
133+
134+
Running the following in your project's root directory:
135+
136+
```bash
137+
next info
138+
```
139+
140+
will give you information like this example:
141+
142+
```bash
143+
144+
Operating System:
145+
Platform: linux
146+
Arch: x64
147+
Version: #22-Ubuntu SMP Fri Nov 5 13:21:36 UTC 2021
148+
Binaries:
149+
Node: 16.13.0
150+
npm: 8.1.0
151+
Yarn: 1.22.17
152+
pnpm: 6.24.2
153+
Relevant packages:
154+
next: 12.0.8
155+
react: 17.0.2
156+
react-dom: 17.0.2
157+
158+
```
159+
160+
This information should then be pasted into GitHub Issues.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"@types/fs-extra": "8.1.0",
5757
"@types/http-proxy": "1.17.3",
5858
"@types/jest": "24.0.13",
59+
"@types/node": "13.11.0",
5960
"@types/selenium-webdriver": "4.0.15",
6061
"@types/sharp": "0.29.3",
6162
"@types/string-hash": "1.1.1",

packages/next/bin/next.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const commands: { [command: string]: () => Promise<cliCommand> } = {
2323
lint: () => Promise.resolve(require('../cli/next-lint').nextLint),
2424
telemetry: () =>
2525
Promise.resolve(require('../cli/next-telemetry').nextTelemetry),
26+
info: () => Promise.resolve(require('../cli/next-info').nextInfo),
2627
}
2728

2829
const args = arg(

packages/next/cli/next-info.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
}

packages/next/shared/lib/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,6 @@ export interface CacheFs {
456456
readFile(f: string): Promise<string>
457457
readFileSync(f: string): string
458458
writeFile(f: string, d: any): Promise<void>
459-
mkdir(dir: string): Promise<void>
459+
mkdir(dir: string): Promise<void | string>
460460
stat(f: string): Promise<{ mtime: Date }>
461461
}

test/integration/cli/test/index.test.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,4 +400,47 @@ describe('CLI Usage', () => {
400400
expect(stderr).not.toContain('UnhandledPromiseRejectionWarning')
401401
})
402402
})
403+
404+
describe('info', () => {
405+
test('--help', async () => {
406+
const help = await runNextCommand(['info', '--help'], {
407+
stdout: true,
408+
})
409+
expect(help.stdout).toMatch(
410+
/Prints relevant details about the current system which can be used to report Next\.js bugs/
411+
)
412+
})
413+
414+
test('-h', async () => {
415+
const help = await runNextCommand(['info', '-h'], {
416+
stdout: true,
417+
})
418+
expect(help.stdout).toMatch(
419+
/Prints relevant details about the current system which can be used to report Next\.js bugs/
420+
)
421+
})
422+
423+
test('should print output', async () => {
424+
const info = await runNextCommand(['info'], {
425+
stdout: true,
426+
})
427+
expect(info.stdout).toMatch(
428+
new RegExp(`
429+
Operating System:
430+
Platform: .*
431+
Arch: .*
432+
Version: .*
433+
Binaries:
434+
Node: .*
435+
npm: .*
436+
Yarn: .*
437+
pnpm: .*
438+
Relevant packages:
439+
next: .*
440+
react: .*
441+
react-dom: .*
442+
`)
443+
)
444+
})
445+
})
403446
})

yarn.lock

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4694,9 +4694,10 @@
46944694
dependencies:
46954695
"@types/node" "*"
46964696

4697-
"@types/node@*", "@types/node@>= 8":
4698-
version "13.1.4"
4699-
resolved "https://registry.yarnpkg.com/@types/node/-/node-13.1.4.tgz#4cfd90175a200ee9b02bd6b1cd19bc349741607e"
4697+
"@types/node@*", "@types/[email protected]", "@types/node@>= 8":
4698+
version "13.11.0"
4699+
resolved "https://registry.yarnpkg.com/@types/node/-/node-13.11.0.tgz#390ea202539c61c8fa6ba4428b57e05bc36dc47b"
4700+
integrity sha512-uM4mnmsIIPK/yeO+42F2RQhGUIs39K2RFmugcJANppXe6J1nvH87PvzPZYpza7Xhhs8Yn9yIAVdLZ84z61+0xQ==
47004701

47014702
47024703
version "10.12.18"

0 commit comments

Comments
 (0)