Unverified Commit e907e479 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

New logging output (#12169)

* Add new logger output

* Fix tests

* Fix tests

* Update next start log for consistency

* Fix cli tests

* Fix tsconfig tests

* Update plugins test

* Fix invalid-custom-routes tests

* Revert "Fix invalid-custom-routes tests"

This reverts commit 8e8eec11dd21feb2186163856207bb974110c13e.

* Revert "Update plugins test"

This reverts commit 3f09270509ea52a1b4f0515cee8e4e711f7e1b16.

* Revert "Fix tsconfig tests"

This reverts commit a4c23bb120e81a15ea50dc6ad1ad097368ef3be6.

* Revert "Fix cli tests"

This reverts commit ff3a321d29bd9afb09f7cf550823010a08a54ae1.

* Revert "Update next start log for consistency"

This reverts commit 481509d8f713a918b7a125e4b7f7bc5c5990c2e1.

* Revert "Fix tests"

This reverts commit 6fb2cb59f79fdf8495fc7288c1c18ece75279ed7.

* Revert "Fix tests"

This reverts commit 9d37298dbc20392a33338cf45166ad86c556de4b.

* Fix tests

* Update next start message

* Update packages/next/build/output/log.ts
Co-Authored-By: 's avatarJoe Haddad <timer@zeit.co>

* Fix tests
Co-authored-by: 's avatarJoe Haddad <timer@zeit.co>
Co-authored-by: 's avatarJoe Haddad <joe.haddad@zeit.co>
parent b0d7881c
import chalk from 'next/dist/compiled/chalk'
const prefixes = {
wait: chalk`[ {cyan wait} ] `,
error: chalk`[ {red error} ]`,
warn: chalk`[ {yellow warn} ] `,
ready: chalk`[ {green ready} ]`,
info: chalk`[ {cyan {dim info}} ] `,
event: chalk`[ {magenta event} ]`,
wait: chalk.cyan('wait') + ' -',
error: chalk.red('error') + ' -',
warn: chalk.yellow('warn') + ' -',
ready: chalk.green('ready') + ' -',
info: chalk.cyan('info') + ' -',
event: chalk.magenta('event') + ' -',
}
export function wait(...message: string[]) {
......
......@@ -39,15 +39,14 @@ store.subscribe(state => {
}
if (state.bootstrap) {
Log.wait('starting the development server ...')
if (state.appUrl) {
Log.info(`waiting on ${state.appUrl} ...`)
Log.ready(`started server on ${state.appUrl}`)
}
return
}
if (state.loading) {
Log.wait('compiling ...')
Log.wait('compiling...')
return
}
......@@ -84,8 +83,5 @@ store.subscribe(state => {
return
}
Log.ready(
'compiled successfully' +
(state.appUrl ? ` - ready on ${state.appUrl}` : '')
)
Log.event('compiled successfully')
})
......@@ -4,6 +4,7 @@ import { resolve } from 'path'
import arg from 'next/dist/compiled/arg/index.js'
import startServer from '../server/lib/start-server'
import { cliCommand } from '../bin/next'
import * as Log from '../build/output/log'
const nextStart: cliCommand = argv => {
const args = arg(
......@@ -47,8 +48,8 @@ const nextStart: cliCommand = argv => {
startServer({ dir }, port, args['--hostname'])
.then(async app => {
// tslint:disable-next-line
console.log(
`> Ready on http://${args['--hostname'] || 'localhost'}:${port}`
Log.ready(
`started server on http://${args['--hostname'] || 'localhost'}:${port}`
)
await app.prepare()
})
......
......@@ -5,6 +5,7 @@ import { basename, extname } from 'path'
import { CONFIG_FILE } from '../lib/constants'
import { execOnce } from '../lib/utils'
import * as Log from '../../build/output/log'
const targets = ['server', 'serverless', 'experimental-serverless-trace']
const reactModes = ['legacy', 'blocking', 'concurrent']
......@@ -63,11 +64,8 @@ const defaultConfig: { [key: string]: any } = {
}
const experimentalWarning = execOnce(() => {
console.warn(
chalk.yellow.bold('Warning: ') +
chalk.bold('You have enabled experimental feature(s).')
)
console.warn(
Log.warn(chalk.bold('You have enabled experimental feature(s).'))
Log.warn(
`Experimental features are not covered by semver, and may cause unexpected or broken application behavior. ` +
`Use them at your own risk.`
)
......
......@@ -79,7 +79,7 @@ describe('CLI Usage', () => {
test('custom directory', async () => {
const port = await findPort()
const output = await runNextCommandDev([dir, '--port', port], true)
expect(output).toMatch(/ready on/i)
expect(output).toMatch(/started server/i)
})
test('--port', async () => {
......@@ -95,7 +95,7 @@ describe('CLI Usage', () => {
const output = await runNextCommandDev([dir, '--port', port], true, {
env: { NODE_OPTIONS: '--inspect' },
})
expect(output).toMatch(new RegExp(`ready on http://localhost:${port}`))
expect(output).toMatch(new RegExp(`http://localhost:${port}`))
})
test('-p', async () => {
......
......@@ -20,8 +20,8 @@ describe('Promise in next config', () => {
}
`)
const { stderr } = await nextBuild(appDir, [], { stderr: true })
expect(stderr).not.toMatch(/experimental feature/)
const { stdout } = await nextBuild(appDir, [], { stdout: true })
expect(stdout).not.toMatch(/experimental feature/)
})
it('should not show warning with config from object', async () => {
......@@ -30,8 +30,8 @@ describe('Promise in next config', () => {
target: 'server'
}
`)
const { stderr } = await nextBuild(appDir, [], { stderr: true })
expect(stderr).not.toMatch(/experimental feature/)
const { stdout } = await nextBuild(appDir, [], { stdout: true })
expect(stdout).not.toMatch(/experimental feature/)
})
it('should show warning with config from object with experimental', async () => {
......@@ -43,8 +43,8 @@ describe('Promise in next config', () => {
}
}
`)
const { stderr } = await nextBuild(appDir, [], { stderr: true })
expect(stderr).toMatch(/experimental feature/)
const { stdout } = await nextBuild(appDir, [], { stdout: true })
expect(stdout).toMatch(/experimental feature/)
})
it('should show warning with config from function with experimental', async () => {
......@@ -56,7 +56,7 @@ describe('Promise in next config', () => {
}
})
`)
const { stderr } = await nextBuild(appDir, [], { stderr: true })
expect(stderr).toMatch(/experimental feature/)
const { stdout } = await nextBuild(appDir, [], { stdout: true })
expect(stdout).toMatch(/experimental feature/)
})
})
......@@ -156,12 +156,19 @@ export function runNextCommandDev(argv, stdOut, opts = {}) {
function handleStdout(data) {
const message = data.toString()
if (/ready on/i.test(message)) {
const bootupMarkers = {
dev: /compiled successfully/i,
start: /started server/i,
}
if (
bootupMarkers[opts.nextStart || stdOut ? 'start' : 'dev'].test(message)
) {
if (!didResolve) {
didResolve = true
resolve(stdOut ? message : instance)
}
}
if (typeof opts.onStdout === 'function') {
opts.onStdout(message)
}
......@@ -212,7 +219,10 @@ export function nextExportDefault(dir, opts = {}) {
}
export function nextStart(dir, port, opts = {}) {
return runNextCommandDev(['start', '-p', port, dir], undefined, opts)
return runNextCommandDev(['start', '-p', port, dir], undefined, {
...opts,
nextStart: true,
})
}
export function buildTS(args = [], cwd, env = {}) {
......
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