Unverified Commit 2c9b484f authored by Jan Kaifer's avatar Jan Kaifer Committed by GitHub

Auto-restart dev server when next.config.js changes (#47912)

This is a follow-up PR on https://github.com/vercel/next.js/pull/46577
after it got nasty conflicts.

Basically, just restart `dev` when `next.config.ts` it will just restart
instead of printing that message asking you to restart.
fix NEXT-639
parent af694f66
This diff is collapsed.
import { createNext } from 'e2e-utils' import { createNextDescribe } from 'e2e-utils'
import { check } from 'next-test-utils' import { check } from 'next-test-utils'
import { NextInstance } from 'test/lib/next-modes/base'
describe('watch-config-file', () => { createNextDescribe(
let next: NextInstance 'watch-config-file',
{
beforeAll(async () => { files: {
next = await createNext({ 'pages/index.js': `
files: {
'pages/index.js': `
export default function Page() { export default function Page() {
return <p>hello world</p> return <p>hello world</p>
} }
`, `,
'next.config.js': ` 'next.config.js': `
const nextConfig = { const nextConfig = {
reactStrictMode: true, reactStrictMode: true,
} }
module.exports = nextConfig module.exports = nextConfig
`, `,
}, },
dependencies: {}, },
skipStart: true, ({ next }) => {
}) it('should output config file change', async () => {
}) await check(
afterAll(() => next.destroy()) async () => next.cliOutput,
/compiled client and server successfully/
it('should output config file change', async () => { )
// next dev test-dir
await next.start(true)
let i = 1
await check(async () => {
await next.patchFile( await next.patchFile(
'next.config.js', 'next.config.js',
` `
/** changed - ${i} **/
const nextConfig = { const nextConfig = {
reactStrictMode: true, reactStrictMode: true,
async redirects() {
return [
{
source: '/about',
destination: '/',
permanent: true,
},
]
},
} }
module.exports = nextConfig` module.exports = nextConfig`
) )
return next.cliOutput
}, /Found a change in next.config.js. Restart the server to see the changes in effect./) await check(
}) async () => next.cliOutput,
}) /Found a change in next\.config\.js\. Restarting the server to apply the changes\.\.\./
)
await check(() => next.fetch('/about').then((res) => res.status), 200)
})
}
)
...@@ -88,7 +88,7 @@ export class NextDevInstance extends NextInstance { ...@@ -88,7 +88,7 @@ export class NextDevInstance extends NextInstance {
msg, msg,
}) })
} }
this.off('stdout', readyCb) // server might reload so we keep listening
resolve() resolve()
} }
} }
......
...@@ -551,7 +551,7 @@ export async function check( ...@@ -551,7 +551,7 @@ export async function check(
for (let tries = 0; tries < maxRetries; tries++) { for (let tries = 0; tries < maxRetries; tries++) {
try { try {
content = await contentFn() content = await contentFn()
if (typeof regex === 'string') { if (typeof regex !== typeof /regex/) {
if (regex === content) { if (regex === content) {
return true return true
} }
......
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