Unverified Commit e19e9e3c authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Add critical next config value to github info (#51715)

Adding `nextConfig.output` to next-info output so that we could determine if users're using standalone mode if the reproduction is not clear or missing sometimes

Example output

```
    Relevant Packages:
      next: 13.4.8-canary.1
      eslint-config-next: 13.4.8-canary.1
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.1.3
    Next.js Config:
      output: standalone
```
parent 385e6fdb
#!/usr/bin/env node #!/usr/bin/env node
import os from 'os' import os from 'os'
import childProcess from 'child_process' import childProcess from 'child_process'
...@@ -10,6 +11,10 @@ const { fetch } = require('next/dist/compiled/undici') as { ...@@ -10,6 +11,10 @@ const { fetch } = require('next/dist/compiled/undici') as {
import { printAndExit } from '../server/lib/utils' import { printAndExit } from '../server/lib/utils'
import { CliCommand } from '../lib/commands' import { CliCommand } from '../lib/commands'
import isError from '../lib/is-error' import isError from '../lib/is-error'
import { PHASE_INFO } from '../shared/lib/constants'
import loadConfig from '../server/config'
const dir = process.cwd()
function getPackageVersion(packageName: string) { function getPackageVersion(packageName: string) {
try { try {
...@@ -19,6 +24,14 @@ function getPackageVersion(packageName: string) { ...@@ -19,6 +24,14 @@ function getPackageVersion(packageName: string) {
} }
} }
async function getNextConfig() {
const config = await loadConfig(PHASE_INFO, dir, undefined, undefined, true)
return {
output: config.output ?? 'N/A',
}
}
function getBinaryVersion(binaryName: string) { function getBinaryVersion(binaryName: string) {
try { try {
return childProcess return childProcess
...@@ -67,6 +80,7 @@ const nextInfo: CliCommand = async (argv) => { ...@@ -67,6 +80,7 @@ const nextInfo: CliCommand = async (argv) => {
} }
const installedRelease = getPackageVersion('next') const installedRelease = getPackageVersion('next')
const nextConfig = await getNextConfig()
console.log(` console.log(`
Operating System: Operating System:
...@@ -78,12 +92,15 @@ const nextInfo: CliCommand = async (argv) => { ...@@ -78,12 +92,15 @@ const nextInfo: CliCommand = async (argv) => {
npm: ${getBinaryVersion('npm')} npm: ${getBinaryVersion('npm')}
Yarn: ${getBinaryVersion('yarn')} Yarn: ${getBinaryVersion('yarn')}
pnpm: ${getBinaryVersion('pnpm')} pnpm: ${getBinaryVersion('pnpm')}
Relevant packages: Relevant Packages:
next: ${installedRelease} next: ${installedRelease}
eslint-config-next: ${getPackageVersion('eslint-config-next')} eslint-config-next: ${getPackageVersion('eslint-config-next')}
react: ${getPackageVersion('react')} react: ${getPackageVersion('react')}
react-dom: ${getPackageVersion('react-dom')} react-dom: ${getPackageVersion('react-dom')}
typescript: ${getPackageVersion('typescript')} typescript: ${getPackageVersion('typescript')}
Next.js Config:
output: ${nextConfig.output}
`) `)
try { try {
......
...@@ -25,6 +25,7 @@ export const PHASE_PRODUCTION_BUILD = 'phase-production-build' ...@@ -25,6 +25,7 @@ export const PHASE_PRODUCTION_BUILD = 'phase-production-build'
export const PHASE_PRODUCTION_SERVER = 'phase-production-server' export const PHASE_PRODUCTION_SERVER = 'phase-production-server'
export const PHASE_DEVELOPMENT_SERVER = 'phase-development-server' export const PHASE_DEVELOPMENT_SERVER = 'phase-development-server'
export const PHASE_TEST = 'phase-test' export const PHASE_TEST = 'phase-test'
export const PHASE_INFO = 'phase-info'
export const PAGES_MANIFEST = 'pages-manifest.json' export const PAGES_MANIFEST = 'pages-manifest.json'
export const APP_PATHS_MANIFEST = 'app-paths-manifest.json' export const APP_PATHS_MANIFEST = 'app-paths-manifest.json'
export const APP_PATH_ROUTES_MANIFEST = 'app-path-routes-manifest.json' export const APP_PATH_ROUTES_MANIFEST = 'app-path-routes-manifest.json'
......
...@@ -15,7 +15,7 @@ import pkg from 'next/package' ...@@ -15,7 +15,7 @@ import pkg from 'next/package'
import http from 'http' import http from 'http'
import stripAnsi from 'strip-ansi' import stripAnsi from 'strip-ansi'
const dir = join(__dirname, '..') const dirBasic = join(__dirname, '../basic')
const dirDuplicateSass = join(__dirname, '../duplicate-sass') const dirDuplicateSass = join(__dirname, '../duplicate-sass')
const testExitSignal = async ( const testExitSignal = async (
...@@ -52,8 +52,8 @@ describe('CLI Usage', () => { ...@@ -52,8 +52,8 @@ describe('CLI Usage', () => {
describe('start', () => { describe('start', () => {
test('should exit when SIGINT is signalled', async () => { test('should exit when SIGINT is signalled', async () => {
require('console').log('before build') require('console').log('before build')
await fs.remove(join(dir, '.next')) await fs.remove(join(dirBasic, '.next'))
await nextBuild(dir, undefined, { await nextBuild(dirBasic, undefined, {
onStdout(msg) { onStdout(msg) {
console.log(msg) console.log(msg)
}, },
...@@ -66,13 +66,13 @@ describe('CLI Usage', () => { ...@@ -66,13 +66,13 @@ describe('CLI Usage', () => {
const port = await findPort() const port = await findPort()
await testExitSignal( await testExitSignal(
'SIGINT', 'SIGINT',
['start', dir, '-p', port], ['start', dirBasic, '-p', port],
/started server on/ /started server on/
) )
}) })
test('should exit when SIGTERM is signalled', async () => { test('should exit when SIGTERM is signalled', async () => {
await fs.remove(join(dir, '.next')) await fs.remove(join(dirBasic, '.next'))
await nextBuild(dir, undefined, { await nextBuild(dirBasic, undefined, {
onStdout(msg) { onStdout(msg) {
console.log(msg) console.log(msg)
}, },
...@@ -83,7 +83,7 @@ describe('CLI Usage', () => { ...@@ -83,7 +83,7 @@ describe('CLI Usage', () => {
const port = await findPort() const port = await findPort()
await testExitSignal( await testExitSignal(
'SIGTERM', 'SIGTERM',
['start', dir, '-p', port], ['start', dirBasic, '-p', port],
/started server on/ /started server on/
) )
}) })
...@@ -299,11 +299,11 @@ describe('CLI Usage', () => { ...@@ -299,11 +299,11 @@ describe('CLI Usage', () => {
}) })
test('should exit when SIGINT is signalled', async () => { test('should exit when SIGINT is signalled', async () => {
await testExitSignal('SIGINT', ['build', dir]) await testExitSignal('SIGINT', ['build', dirBasic])
}) })
test('should exit when SIGTERM is signalled', async () => { test('should exit when SIGTERM is signalled', async () => {
await testExitSignal('SIGTERM', ['build', dir]) await testExitSignal('SIGTERM', ['build', dirBasic])
}) })
test('invalid directory', async () => { test('invalid directory', async () => {
...@@ -334,11 +334,15 @@ describe('CLI Usage', () => { ...@@ -334,11 +334,15 @@ describe('CLI Usage', () => {
test('custom directory', async () => { test('custom directory', async () => {
const port = await findPort() const port = await findPort()
let output = '' let output = ''
const app = await runNextCommandDev([dir, '--port', port], undefined, { const app = await runNextCommandDev(
onStdout(msg) { [dirBasic, '--port', port],
output += stripAnsi(msg) undefined,
}, {
}) onStdout(msg) {
output += stripAnsi(msg)
},
}
)
try { try {
await check(() => output, /started server/i) await check(() => output, /started server/i)
} finally { } finally {
...@@ -349,11 +353,15 @@ describe('CLI Usage', () => { ...@@ -349,11 +353,15 @@ describe('CLI Usage', () => {
test('--port', async () => { test('--port', async () => {
const port = await findPort() const port = await findPort()
let output = '' let output = ''
const app = await runNextCommandDev([dir, '--port', port], undefined, { const app = await runNextCommandDev(
onStdout(msg) { [dirBasic, '--port', port],
output += stripAnsi(msg) undefined,
}, {
}) onStdout(msg) {
output += stripAnsi(msg)
},
}
)
try { try {
await check(() => output, new RegExp(`on 0.0.0.0:${port}`)) await check(() => output, new RegExp(`on 0.0.0.0:${port}`))
await check(() => output, new RegExp(`http://localhost:${port}`)) await check(() => output, new RegExp(`http://localhost:${port}`))
...@@ -365,11 +373,15 @@ describe('CLI Usage', () => { ...@@ -365,11 +373,15 @@ describe('CLI Usage', () => {
test('--port 0', async () => { test('--port 0', async () => {
const port = await findPort() const port = await findPort()
let output = '' let output = ''
const app = await runNextCommandDev([dir, '--port', port], undefined, { const app = await runNextCommandDev(
onStdout(msg) { [dirBasic, '--port', port],
output += stripAnsi(msg) undefined,
}, {
}) onStdout(msg) {
output += stripAnsi(msg)
},
}
)
try { try {
await check(() => output, new RegExp(`on 0.0.0.0:${port}`)) await check(() => output, new RegExp(`on 0.0.0.0:${port}`))
await check(() => output, new RegExp(`http://localhost:${port}`)) await check(() => output, new RegExp(`http://localhost:${port}`))
...@@ -387,7 +399,7 @@ describe('CLI Usage', () => { ...@@ -387,7 +399,7 @@ describe('CLI Usage', () => {
test('PORT=0', async () => { test('PORT=0', async () => {
let output = '' let output = ''
const app = await runNextCommandDev([dir], undefined, { const app = await runNextCommandDev([dirBasic], undefined, {
env: { env: {
PORT: 0, PORT: 0,
}, },
...@@ -411,12 +423,16 @@ describe('CLI Usage', () => { ...@@ -411,12 +423,16 @@ describe('CLI Usage', () => {
test("NODE_OPTIONS='--inspect'", async () => { test("NODE_OPTIONS='--inspect'", async () => {
const port = await findPort() const port = await findPort()
let output = '' let output = ''
const app = await runNextCommandDev([dir, '--port', port], undefined, { const app = await runNextCommandDev(
onStdout(msg) { [dirBasic, '--port', port],
output += stripAnsi(msg) undefined,
}, {
env: { NODE_OPTIONS: '--inspect' }, onStdout(msg) {
}) output += stripAnsi(msg)
},
env: { NODE_OPTIONS: '--inspect' },
}
)
try { try {
await check(() => output, new RegExp(`on 0.0.0.0:${port}`)) await check(() => output, new RegExp(`on 0.0.0.0:${port}`))
await check(() => output, new RegExp(`http://localhost:${port}`)) await check(() => output, new RegExp(`http://localhost:${port}`))
...@@ -428,7 +444,7 @@ describe('CLI Usage', () => { ...@@ -428,7 +444,7 @@ describe('CLI Usage', () => {
test('-p', async () => { test('-p', async () => {
const port = await findPort() const port = await findPort()
let output = '' let output = ''
const app = await runNextCommandDev([dir, '-p', port], undefined, { const app = await runNextCommandDev([dirBasic, '-p', port], undefined, {
onStdout(msg) { onStdout(msg) {
output += stripAnsi(msg) output += stripAnsi(msg)
}, },
...@@ -457,7 +473,7 @@ describe('CLI Usage', () => { ...@@ -457,7 +473,7 @@ describe('CLI Usage', () => {
}) })
let stdout = '', let stdout = '',
stderr = '' stderr = ''
await launchApp(dir, port, { await launchApp(dirBasic, port, {
stdout: true, stdout: true,
stderr: true, stderr: true,
onStdout(msg) { onStdout(msg) {
...@@ -479,7 +495,7 @@ describe('CLI Usage', () => { ...@@ -479,7 +495,7 @@ describe('CLI Usage', () => {
const port = await findPort() const port = await findPort()
let output = '' let output = ''
const app = await runNextCommandDev( const app = await runNextCommandDev(
[dir, '--hostname', '0.0.0.0', '--port', port], [dirBasic, '--hostname', '0.0.0.0', '--port', port],
undefined, undefined,
{ {
onStdout(msg) { onStdout(msg) {
...@@ -499,7 +515,7 @@ describe('CLI Usage', () => { ...@@ -499,7 +515,7 @@ describe('CLI Usage', () => {
const port = await findPort() const port = await findPort()
let output = '' let output = ''
const app = await runNextCommandDev( const app = await runNextCommandDev(
[dir, '-H', '0.0.0.0', '--port', port], [dirBasic, '-H', '0.0.0.0', '--port', port],
undefined, undefined,
{ {
onStdout(msg) { onStdout(msg) {
...@@ -519,7 +535,7 @@ describe('CLI Usage', () => { ...@@ -519,7 +535,7 @@ describe('CLI Usage', () => {
const port = await findPort() const port = await findPort()
let output = '' let output = ''
const app = await runNextCommandDev( const app = await runNextCommandDev(
[dir, '--hostname', '::', '--port', port], [dirBasic, '--hostname', '::', '--port', port],
undefined, undefined,
{ {
onStdout(msg) { onStdout(msg) {
...@@ -552,7 +568,7 @@ describe('CLI Usage', () => { ...@@ -552,7 +568,7 @@ describe('CLI Usage', () => {
const port = await findPort() const port = await findPort()
await testExitSignal( await testExitSignal(
'SIGINT', 'SIGINT',
['dev', dir, '-p', port], ['dev', dirBasic, '-p', port],
/started server on/ /started server on/
) )
}) })
...@@ -560,7 +576,7 @@ describe('CLI Usage', () => { ...@@ -560,7 +576,7 @@ describe('CLI Usage', () => {
const port = await findPort() const port = await findPort()
await testExitSignal( await testExitSignal(
'SIGTERM', 'SIGTERM',
['dev', dir, '-p', port], ['dev', dirBasic, '-p', port],
/started server on/ /started server on/
) )
}) })
...@@ -647,6 +663,30 @@ describe('CLI Usage', () => { ...@@ -647,6 +663,30 @@ describe('CLI Usage', () => {
}) })
describe('info', () => { describe('info', () => {
function matchInfoOutput(stdout, { nextConfigOutput = '.*' } = {}) {
expect(stdout).toMatch(
new RegExp(`
Operating System:
Platform: .*
Arch: .*
Version: .*
Binaries:
Node: .*
npm: .*
Yarn: .*
pnpm: .*
Relevant Packages:
next: .*
eslint-config-next: .*
react: .*
react-dom: .*
typescript: .*
Next.js Config:
output: ${nextConfigOutput}
`)
)
}
test('--help', async () => { test('--help', async () => {
const help = await runNextCommand(['info', '--help'], { const help = await runNextCommand(['info', '--help'], {
stdout: true, stdout: true,
...@@ -670,26 +710,37 @@ describe('CLI Usage', () => { ...@@ -670,26 +710,37 @@ describe('CLI Usage', () => {
stdout: true, stdout: true,
stderr: true, stderr: true,
}) })
expect((info.stderr || '').toLowerCase()).not.toContain('error') expect((info.stderr || '').toLowerCase()).not.toContain('error')
matchInfoOutput(info.stdout)
})
expect(info.stdout).toMatch( test('should print output with next.config.mjs', async () => {
new RegExp(` let info = { stdout: '', stderr: '' }
Operating System:
Platform: .* try {
Arch: .* await fs.writeFile(
Version: .* join(dirBasic, 'next.config.mjs'),
Binaries: `export default { output: 'standalone' }`
Node: .* )
npm: .* await fs.writeFile(
Yarn: .* join(dirBasic, 'package.json'),
pnpm: .* JSON.stringify({
Relevant packages: type: 'module',
next: .* })
eslint-config-next: .* )
react: .* info = await runNextCommand(['info'], {
react-dom: .* cwd: dirBasic,
`) stdout: true,
) stderr: true,
})
} finally {
await fs.remove(join(dirBasic, 'next.config.mjs'))
await fs.remove(join(dirBasic, 'package.json'))
}
expect((info.stderr || '').toLowerCase()).not.toContain('error')
matchInfoOutput(info.stdout, { nextConfigOutput: 'standalone' })
}) })
}) })
}) })
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