Skip to content

Commit

Permalink
Add critical next config value to github info (#51715)
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
huozhi committed Jun 24, 2023
1 parent 385e6fd commit e19e9e3
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 57 deletions.
19 changes: 18 additions & 1 deletion packages/next/src/cli/next-info.ts
@@ -1,4 +1,5 @@
#!/usr/bin/env node

import os from 'os'
import childProcess from 'child_process'

Expand All @@ -10,6 +11,10 @@ const { fetch } = require('next/dist/compiled/undici') as {
import { printAndExit } from '../server/lib/utils'
import { CliCommand } from '../lib/commands'
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) {
try {
Expand All @@ -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) {
try {
return childProcess
Expand Down Expand Up @@ -67,6 +80,7 @@ const nextInfo: CliCommand = async (argv) => {
}

const installedRelease = getPackageVersion('next')
const nextConfig = await getNextConfig()

console.log(`
Operating System:
Expand All @@ -78,12 +92,15 @@ const nextInfo: CliCommand = async (argv) => {
npm: ${getBinaryVersion('npm')}
Yarn: ${getBinaryVersion('yarn')}
pnpm: ${getBinaryVersion('pnpm')}
Relevant packages:
Relevant Packages:
next: ${installedRelease}
eslint-config-next: ${getPackageVersion('eslint-config-next')}
react: ${getPackageVersion('react')}
react-dom: ${getPackageVersion('react-dom')}
typescript: ${getPackageVersion('typescript')}
Next.js Config:
output: ${nextConfig.output}
`)

try {
Expand Down
1 change: 1 addition & 0 deletions packages/next/src/shared/lib/constants.ts
Expand Up @@ -25,6 +25,7 @@ export const PHASE_PRODUCTION_BUILD = 'phase-production-build'
export const PHASE_PRODUCTION_SERVER = 'phase-production-server'
export const PHASE_DEVELOPMENT_SERVER = 'phase-development-server'
export const PHASE_TEST = 'phase-test'
export const PHASE_INFO = 'phase-info'
export const PAGES_MANIFEST = 'pages-manifest.json'
export const APP_PATHS_MANIFEST = 'app-paths-manifest.json'
export const APP_PATH_ROUTES_MANIFEST = 'app-path-routes-manifest.json'
Expand Down
File renamed without changes.
163 changes: 107 additions & 56 deletions test/integration/cli/test/index.test.js
Expand Up @@ -15,7 +15,7 @@ import pkg from 'next/package'
import http from 'http'
import stripAnsi from 'strip-ansi'

const dir = join(__dirname, '..')
const dirBasic = join(__dirname, '../basic')
const dirDuplicateSass = join(__dirname, '../duplicate-sass')

const testExitSignal = async (
Expand Down Expand Up @@ -52,8 +52,8 @@ describe('CLI Usage', () => {
describe('start', () => {
test('should exit when SIGINT is signalled', async () => {
require('console').log('before build')
await fs.remove(join(dir, '.next'))
await nextBuild(dir, undefined, {
await fs.remove(join(dirBasic, '.next'))
await nextBuild(dirBasic, undefined, {
onStdout(msg) {
console.log(msg)
},
Expand All @@ -66,13 +66,13 @@ describe('CLI Usage', () => {
const port = await findPort()
await testExitSignal(
'SIGINT',
['start', dir, '-p', port],
['start', dirBasic, '-p', port],
/started server on/
)
})
test('should exit when SIGTERM is signalled', async () => {
await fs.remove(join(dir, '.next'))
await nextBuild(dir, undefined, {
await fs.remove(join(dirBasic, '.next'))
await nextBuild(dirBasic, undefined, {
onStdout(msg) {
console.log(msg)
},
Expand All @@ -83,7 +83,7 @@ describe('CLI Usage', () => {
const port = await findPort()
await testExitSignal(
'SIGTERM',
['start', dir, '-p', port],
['start', dirBasic, '-p', port],
/started server on/
)
})
Expand Down Expand Up @@ -299,11 +299,11 @@ describe('CLI Usage', () => {
})

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 () => {
await testExitSignal('SIGTERM', ['build', dir])
await testExitSignal('SIGTERM', ['build', dirBasic])
})

test('invalid directory', async () => {
Expand Down Expand Up @@ -334,11 +334,15 @@ describe('CLI Usage', () => {
test('custom directory', async () => {
const port = await findPort()
let output = ''
const app = await runNextCommandDev([dir, '--port', port], undefined, {
onStdout(msg) {
output += stripAnsi(msg)
},
})
const app = await runNextCommandDev(
[dirBasic, '--port', port],
undefined,
{
onStdout(msg) {
output += stripAnsi(msg)
},
}
)
try {
await check(() => output, /started server/i)
} finally {
Expand All @@ -349,11 +353,15 @@ describe('CLI Usage', () => {
test('--port', async () => {
const port = await findPort()
let output = ''
const app = await runNextCommandDev([dir, '--port', port], undefined, {
onStdout(msg) {
output += stripAnsi(msg)
},
})
const app = await runNextCommandDev(
[dirBasic, '--port', port],
undefined,
{
onStdout(msg) {
output += stripAnsi(msg)
},
}
)
try {
await check(() => output, new RegExp(`on 0.0.0.0:${port}`))
await check(() => output, new RegExp(`http://localhost:${port}`))
Expand All @@ -365,11 +373,15 @@ describe('CLI Usage', () => {
test('--port 0', async () => {
const port = await findPort()
let output = ''
const app = await runNextCommandDev([dir, '--port', port], undefined, {
onStdout(msg) {
output += stripAnsi(msg)
},
})
const app = await runNextCommandDev(
[dirBasic, '--port', port],
undefined,
{
onStdout(msg) {
output += stripAnsi(msg)
},
}
)
try {
await check(() => output, new RegExp(`on 0.0.0.0:${port}`))
await check(() => output, new RegExp(`http://localhost:${port}`))
Expand All @@ -387,7 +399,7 @@ describe('CLI Usage', () => {

test('PORT=0', async () => {
let output = ''
const app = await runNextCommandDev([dir], undefined, {
const app = await runNextCommandDev([dirBasic], undefined, {
env: {
PORT: 0,
},
Expand All @@ -411,12 +423,16 @@ describe('CLI Usage', () => {
test("NODE_OPTIONS='--inspect'", async () => {
const port = await findPort()
let output = ''
const app = await runNextCommandDev([dir, '--port', port], undefined, {
onStdout(msg) {
output += stripAnsi(msg)
},
env: { NODE_OPTIONS: '--inspect' },
})
const app = await runNextCommandDev(
[dirBasic, '--port', port],
undefined,
{
onStdout(msg) {
output += stripAnsi(msg)
},
env: { NODE_OPTIONS: '--inspect' },
}
)
try {
await check(() => output, new RegExp(`on 0.0.0.0:${port}`))
await check(() => output, new RegExp(`http://localhost:${port}`))
Expand All @@ -428,7 +444,7 @@ describe('CLI Usage', () => {
test('-p', async () => {
const port = await findPort()
let output = ''
const app = await runNextCommandDev([dir, '-p', port], undefined, {
const app = await runNextCommandDev([dirBasic, '-p', port], undefined, {
onStdout(msg) {
output += stripAnsi(msg)
},
Expand Down Expand Up @@ -457,7 +473,7 @@ describe('CLI Usage', () => {
})
let stdout = '',
stderr = ''
await launchApp(dir, port, {
await launchApp(dirBasic, port, {
stdout: true,
stderr: true,
onStdout(msg) {
Expand All @@ -479,7 +495,7 @@ describe('CLI Usage', () => {
const port = await findPort()
let output = ''
const app = await runNextCommandDev(
[dir, '--hostname', '0.0.0.0', '--port', port],
[dirBasic, '--hostname', '0.0.0.0', '--port', port],
undefined,
{
onStdout(msg) {
Expand All @@ -499,7 +515,7 @@ describe('CLI Usage', () => {
const port = await findPort()
let output = ''
const app = await runNextCommandDev(
[dir, '-H', '0.0.0.0', '--port', port],
[dirBasic, '-H', '0.0.0.0', '--port', port],
undefined,
{
onStdout(msg) {
Expand All @@ -519,7 +535,7 @@ describe('CLI Usage', () => {
const port = await findPort()
let output = ''
const app = await runNextCommandDev(
[dir, '--hostname', '::', '--port', port],
[dirBasic, '--hostname', '::', '--port', port],
undefined,
{
onStdout(msg) {
Expand Down Expand Up @@ -552,15 +568,15 @@ describe('CLI Usage', () => {
const port = await findPort()
await testExitSignal(
'SIGINT',
['dev', dir, '-p', port],
['dev', dirBasic, '-p', port],
/started server on/
)
})
test('should exit when SIGTERM is signalled', async () => {
const port = await findPort()
await testExitSignal(
'SIGTERM',
['dev', dir, '-p', port],
['dev', dirBasic, '-p', port],
/started server on/
)
})
Expand Down Expand Up @@ -647,6 +663,30 @@ describe('CLI Usage', () => {
})

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 () => {
const help = await runNextCommand(['info', '--help'], {
stdout: true,
Expand All @@ -670,26 +710,37 @@ describe('CLI Usage', () => {
stdout: true,
stderr: true,
})

expect((info.stderr || '').toLowerCase()).not.toContain('error')
matchInfoOutput(info.stdout)
})

expect(info.stdout).toMatch(
new RegExp(`
Operating System:
Platform: .*
Arch: .*
Version: .*
Binaries:
Node: .*
npm: .*
Yarn: .*
pnpm: .*
Relevant packages:
next: .*
eslint-config-next: .*
react: .*
react-dom: .*
`)
)
test('should print output with next.config.mjs', async () => {
let info = { stdout: '', stderr: '' }

try {
await fs.writeFile(
join(dirBasic, 'next.config.mjs'),
`export default { output: 'standalone' }`
)
await fs.writeFile(
join(dirBasic, 'package.json'),
JSON.stringify({
type: 'module',
})
)
info = await runNextCommand(['info'], {
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' })
})
})
})

0 comments on commit e19e9e3

Please sign in to comment.