Commit b56342b3 authored by Benjamin Woodruff's avatar Benjamin Woodruff Committed by Benjamin Woodruff

next-dev: Emit `next.config.js` warnings from child process upon restart

parent b8531670
...@@ -346,7 +346,7 @@ const nextDev = async ( ...@@ -346,7 +346,7 @@ const nextDev = async (
}) })
} }
return startServer({ ...startServerOptions, port }) return startServer({ ...startServerOptions, port, isRestart: true })
} }
// Call handler (e.g. upload telemetry). Don't try to send a signal to // Call handler (e.g. upload telemetry). Don't try to send a signal to
// the child, as it has already exited. // the child, as it has already exited.
......
...@@ -9,7 +9,6 @@ import '../require-hook' ...@@ -9,7 +9,6 @@ import '../require-hook'
import url from 'url' import url from 'url'
import path from 'path' import path from 'path'
import loadConfig from '../config'
import { serveStatic } from '../serve-static' import { serveStatic } from '../serve-static'
import setupDebug from 'next/dist/compiled/debug' import setupDebug from 'next/dist/compiled/debug'
import * as Log from '../../build/output/log' import * as Log from '../../build/output/log'
...@@ -27,11 +26,7 @@ import { signalFromNodeResponse } from '../web/spec-extension/adapters/next-requ ...@@ -27,11 +26,7 @@ import { signalFromNodeResponse } from '../web/spec-extension/adapters/next-requ
import { isPostpone } from './router-utils/is-postpone' import { isPostpone } from './router-utils/is-postpone'
import { parseUrl as parseUrlUtil } from '../../shared/lib/router/utils/parse-url' import { parseUrl as parseUrlUtil } from '../../shared/lib/router/utils/parse-url'
import { import { UNDERSCORE_NOT_FOUND_ROUTE } from '../../shared/lib/constants'
PHASE_PRODUCTION_SERVER,
PHASE_DEVELOPMENT_SERVER,
UNDERSCORE_NOT_FOUND_ROUTE,
} from '../../shared/lib/constants'
import { RedirectStatusCode } from '../../client/components/redirect-status-code' import { RedirectStatusCode } from '../../client/components/redirect-status-code'
import { DevBundlerService } from './dev-bundler-service' import { DevBundlerService } from './dev-bundler-service'
import { type Span, trace } from '../../trace' import { type Span, trace } from '../../trace'
...@@ -59,6 +54,7 @@ import { ...@@ -59,6 +54,7 @@ import {
handleChromeDevtoolsWorkspaceRequest, handleChromeDevtoolsWorkspaceRequest,
isChromeDevtoolsWorkspaceUrl, isChromeDevtoolsWorkspaceUrl,
} from './chrome-devtools-workspace' } from './chrome-devtools-workspace'
import type { NextConfigComplete } from '../config-shared'
const debug = setupDebug('next:router-server:main') const debug = setupDebug('next:router-server:main')
const isNextFont = (pathname: string | null) => const isNextFont = (pathname: string | null) =>
...@@ -80,6 +76,7 @@ const requestHandlers: Record<string, WorkerRequestHandler> = {} ...@@ -80,6 +76,7 @@ const requestHandlers: Record<string, WorkerRequestHandler> = {}
export async function initialize(opts: { export async function initialize(opts: {
dir: string dir: string
config: NextConfigComplete
port: number port: number
dev: boolean dev: boolean
onDevServerCleanup: ((listener: () => Promise<void>) => void) | undefined onDevServerCleanup: ((listener: () => Promise<void>) => void) | undefined
...@@ -92,19 +89,9 @@ export async function initialize(opts: { ...@@ -92,19 +89,9 @@ export async function initialize(opts: {
startServerSpan?: Span startServerSpan?: Span
quiet?: boolean quiet?: boolean
}): Promise<ServerInitResult> { }): Promise<ServerInitResult> {
if (!process.env.NODE_ENV) { const { config } = opts
// @ts-ignore not readonly
process.env.NODE_ENV = opts.dev ? 'development' : 'production'
}
const config = await loadConfig(
opts.dev ? PHASE_DEVELOPMENT_SERVER : PHASE_PRODUCTION_SERVER,
opts.dir,
{ silent: false }
)
let compress: ReturnType<typeof setupCompression> | undefined let compress: ReturnType<typeof setupCompression> | undefined
if (config?.compress !== false) { if (config?.compress !== false) {
compress = setupCompression() compress = setupCompression()
} }
......
...@@ -28,8 +28,12 @@ import { ...@@ -28,8 +28,12 @@ import {
getNodeDebugType, getNodeDebugType,
} from './utils' } from './utils'
import { formatHostname } from './format-hostname' import { formatHostname } from './format-hostname'
import { initialize } from './router-server' import { initialize as initializeRouterServer } from './router-server'
import { CONFIG_FILES } from '../../shared/lib/constants' import {
CONFIG_FILES,
PHASE_DEVELOPMENT_SERVER,
PHASE_PRODUCTION_SERVER,
} from '../../shared/lib/constants'
import { getStartServerInfo, logStartInfo } from './app-info-log' import { getStartServerInfo, logStartInfo } from './app-info-log'
import { validateTurboNextConfig } from '../../lib/turbopack-warning' import { validateTurboNextConfig } from '../../lib/turbopack-warning'
import { type Span, trace, flushAllTraces } from '../../trace' import { type Span, trace, flushAllTraces } from '../../trace'
...@@ -37,6 +41,7 @@ import { isIPv6 } from './is-ipv6' ...@@ -37,6 +41,7 @@ import { isIPv6 } from './is-ipv6'
import { AsyncCallbackSet } from './async-callback-set' import { AsyncCallbackSet } from './async-callback-set'
import type { NextServer } from '../next' import type { NextServer } from '../next'
import type { ConfiguredExperimentalFeature } from '../config' import type { ConfiguredExperimentalFeature } from '../config'
import loadConfig from '../config'
const debug = setupDebug('next:start-server') const debug = setupDebug('next:start-server')
let startServerSpan: Span | undefined let startServerSpan: Span | undefined
...@@ -127,44 +132,7 @@ export interface StartServerOptions { ...@@ -127,44 +132,7 @@ export interface StartServerOptions {
keepAliveTimeout?: number keepAliveTimeout?: number
// this is dev-server only // this is dev-server only
selfSignedCertificate?: SelfSignedCertificate selfSignedCertificate?: SelfSignedCertificate
} isRestart?: boolean
export async function getRequestHandlers({
dir,
port,
isDev,
onDevServerCleanup,
server,
hostname,
minimalMode,
keepAliveTimeout,
experimentalHttpsServer,
quiet,
}: {
dir: string
port: number
isDev: boolean
onDevServerCleanup: ((listener: () => Promise<void>) => void) | undefined
server?: import('http').Server
hostname?: string
minimalMode?: boolean
keepAliveTimeout?: number
experimentalHttpsServer?: boolean
quiet?: boolean
}): ReturnType<typeof initialize> {
return initialize({
dir,
port,
hostname,
onDevServerCleanup,
dev: isDev,
minimalMode,
server,
keepAliveTimeout,
experimentalHttpsServer,
startServerSpan,
quiet,
})
} }
export async function startServer( export async function startServer(
...@@ -178,6 +146,7 @@ export async function startServer( ...@@ -178,6 +146,7 @@ export async function startServer(
allowRetry, allowRetry,
keepAliveTimeout, keepAliveTimeout,
selfSignedCertificate, selfSignedCertificate,
isRestart,
} = serverOptions } = serverOptions
let { port } = serverOptions let { port } = serverOptions
...@@ -364,7 +333,29 @@ export async function startServer( ...@@ -364,7 +333,29 @@ export async function startServer(
process.env.__NEXT_EXPERIMENTAL_HTTPS = '1' process.env.__NEXT_EXPERIMENTAL_HTTPS = '1'
} }
// Only load env and config in dev to for logging purposes // @ts-ignore not readonly
process.env.NODE_ENV ||= isDev ? 'development' : 'production'
// this needs to happen before `getStartServerInfo`, which also calls `loadConfig`, so that
// the `silent` flag applies.
const config = await loadConfig(
isDev ? PHASE_DEVELOPMENT_SERVER : PHASE_PRODUCTION_SERVER,
dir,
{
// Normally, the parent process is responsible for emitting any configuration-related
// warnings.
//
// If this is a restart, the parent process cannot read the config again because there's
// no way to invalidate the node ESM import cache.
//
// Instead, we should load the config with `silent: false` so that we log any new
// warnings. This may also cause us to re-log deprecation warnings that were previously
// logged prior to the restart -- there's no way for us to re-use the `warnOnce` cache.
silent: !isRestart,
}
)
// Only load env and and experimental feature info in dev to for logging purposes
let envInfo: string[] | undefined let envInfo: string[] | undefined
let experimentalFeatures: ConfiguredExperimentalFeature[] | undefined let experimentalFeatures: ConfiguredExperimentalFeature[] | undefined
try { try {
...@@ -428,10 +419,11 @@ export async function startServer( ...@@ -428,10 +419,11 @@ export async function startServer(
process.on('SIGTERM', cleanup) process.on('SIGTERM', cleanup)
} }
const initResult = await getRequestHandlers({ const initResult = await initializeRouterServer({
dir, dir,
config,
port, port,
isDev, dev: isDev,
onDevServerCleanup: cleanupListeners onDevServerCleanup: cleanupListeners
? cleanupListeners.add.bind(cleanupListeners) ? cleanupListeners.add.bind(cleanupListeners)
: undefined, : undefined,
......
...@@ -373,8 +373,8 @@ class NextCustomServer implements NextWrapperServer { ...@@ -373,8 +373,8 @@ class NextCustomServer implements NextWrapperServer {
} }
async prepare() { async prepare() {
const { getRequestHandlers } = const { initialize } =
require('./lib/start-server') as typeof import('./lib/start-server') require('./lib/router-server') as typeof import('./lib/router-server')
let onDevServerCleanup: AsyncCallbackSet['add'] | undefined let onDevServerCleanup: AsyncCallbackSet['add'] | undefined
if (this.options.dev) { if (this.options.dev) {
...@@ -382,16 +382,26 @@ class NextCustomServer implements NextWrapperServer { ...@@ -382,16 +382,26 @@ class NextCustomServer implements NextWrapperServer {
onDevServerCleanup = this.cleanupListeners.add.bind(this.cleanupListeners) onDevServerCleanup = this.cleanupListeners.add.bind(this.cleanupListeners)
} }
const initResult = await getRequestHandlers({ let dev = !!this.options.dev
let dir = this.options.dir!
// @ts-ignore not readonly
process.env.NODE_ENV ||= dev ? 'development' : 'production'
const config = await loadConfig(
dev ? PHASE_DEVELOPMENT_SERVER : PHASE_PRODUCTION_SERVER,
dir
)
this.init = await initialize({
dir: this.options.dir!, dir: this.options.dir!,
config,
port: this.options.port || 3000, port: this.options.port || 3000,
isDev: !!this.options.dev, dev: !!this.options.dev,
onDevServerCleanup, onDevServerCleanup,
hostname: this.options.hostname || 'localhost', hostname: this.options.hostname || 'localhost',
minimalMode: this.options.minimalMode, minimalMode: this.options.minimalMode,
quiet: this.options.quiet, quiet: this.options.quiet,
}) })
this.init = initResult
} }
private setupWebSocketHandler( private setupWebSocketHandler(
......
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