-
Notifications
You must be signed in to change notification settings - Fork 26.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <229881+styfle@users.noreply.github.com>
- Loading branch information
1 parent
1be8704
commit 3ad2035
Showing
8 changed files
with
166 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters