Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e5f647d
chore(deps): add
balazsorban44 Jan 3, 2022
7aba961
feat(cli): introduce
balazsorban44 Jan 3, 2022
c147d85
chore(deps): remove dependency
balazsorban44 Jan 3, 2022
6e737ac
chore(deps): add lowest supporting
balazsorban44 Jan 3, 2022
b71594a
feat(cli): print OS, Binary, npm package information
balazsorban44 Jan 3, 2022
86c19a8
docs(cli): document
balazsorban44 Jan 3, 2022
5fa6543
chore: remove v
balazsorban44 Jan 3, 2022
a13ffef
chore(deps): remove
balazsorban44 Jan 3, 2022
df3dd36
docs: update bug report issue template
balazsorban44 Jan 3, 2022
b8a68e0
Apply suggestions from code review
balazsorban44 Jan 3, 2022
4aea3d1
chore: fix typo
balazsorban44 Jan 3, 2022
c2cb0c8
Apply suggestions from code review
balazsorban44 Jan 3, 2022
e86d02f
chore: simplify
balazsorban44 Jan 3, 2022
ccf943c
chore: add back issue template fields
balazsorban44 Jan 3, 2022
094b5db
chore: print node version without "v" prefix
balazsorban44 Jan 3, 2022
5c89412
fix: try/catch if fails in
balazsorban44 Jan 4, 2022
6a1bd80
chore: specify availability
balazsorban44 Jan 4, 2022
e73145b
Add @types/node to root package.json
styfle Jan 4, 2022
36b5cbf
Apply suggestions from code review
styfle Jan 4, 2022
b3da6b2
Merge branch 'canary' into feat/next-cli-info
styfle Jan 4, 2022
84902a6
chore: run Prettier
balazsorban44 Jan 4, 2022
a9d7da0
chore: rename group to "Relevant packages"
balazsorban44 Jan 4, 2022
182e9ae
chore(cli): rephrase description to match API reference
balazsorban44 Jan 4, 2022
647eee9
test(cli): add tests
balazsorban44 Jan 4, 2022
4a26e7f
Merge branch 'canary' into feat/next-cli-info
kodiakhq[bot] Jan 4, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/ISSUE_TEMPLATE/1.bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ body:
- type: markdown
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.'
- 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
attributes:
label: What version of Next.js are you using?
Expand Down
35 changes: 34 additions & 1 deletion docs/api-reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Usage
$ next <command>

Available commands
build, start, export, dev, lint, telemetry
build, start, export, dev, lint, telemetry, info

Options
--version, -v Version number
Expand Down Expand Up @@ -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.

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.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"@types/fs-extra": "8.1.0",
"@types/http-proxy": "1.17.3",
"@types/jest": "24.0.13",
"@types/node": "13.11.0",
"@types/selenium-webdriver": "4.0.15",
"@types/sharp": "0.29.3",
"@types/string-hash": "1.1.1",
Expand Down
1 change: 1 addition & 0 deletions packages/next/bin/next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const commands: { [command: string]: () => Promise<cliCommand> } = {
lint: () => Promise.resolve(require('../cli/next-lint').nextLint),
telemetry: () =>
Promise.resolve(require('../cli/next-telemetry').nextTelemetry),
info: () => Promise.resolve(require('../cli/next-info').nextInfo),
}

const args = arg(
Expand Down
76 changes: 76 additions & 0 deletions packages/next/cli/next-info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/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'
}
}
2 changes: 1 addition & 1 deletion packages/next/shared/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,6 @@ export interface CacheFs {
readFile(f: string): Promise<string>
readFileSync(f: string): string
writeFile(f: string, d: any): Promise<void>
mkdir(dir: string): Promise<void>
mkdir(dir: string): Promise<void | string>
stat(f: string): Promise<{ mtime: Date }>
}
43 changes: 43 additions & 0 deletions test/integration/cli/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,4 +400,47 @@ describe('CLI Usage', () => {
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: .*
`)
)
})
})
})
7 changes: 4 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4694,9 +4694,10 @@
dependencies:
"@types/node" "*"

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

"@types/[email protected]":
version "10.12.18"
Expand Down