next.js
a81ecd38 - Centralize node environment setup and config-dependent global behaviors

Commit
51 days ago
Centralize node environment setup and config-dependent global behaviors Node environment extensions (AsyncLocalStorage polyfill, console patching, error formatting, etc.) were imported inconsistently — some entry points loaded them explicitly, others relied on transitive imports through downstream modules. This makes it unclear which processes have the environment set up and creates fragile ordering dependencies. This adds `import node-environment` to every process entry point that runs Next.js server, rendering, or build code. The import is idempotent so redundancy with existing transitive imports is harmless. `loadConfig` is renamed to `loadConfigFromFile` and now calls `installGlobalBehaviors` internally via lazy require, so consumers don't need to call it separately. `loadConfigForBuildWorker` does the same for workers that receive config via IPC. Direct `installGlobalBehaviors` calls are removed from `NextNodeServer` and `export/worker.ts`. Process entry points with `import node-environment`: - `bin/next.ts` — CLI dispatcher, entry for all `next` commands - `server/lib/start-server.ts` — forked child process for `next dev` - `server/lib/router-server.ts` — router server (was already there) - `server/dev/static-paths-worker.ts` — runs `generateStaticParams` in isolated process (was already there) - `export/worker.ts` — renders pages for static export (was already there) - `build/worker.ts` — build worker, re-exports rendering from export/worker - `build/collect-build-traces.ts` — file dependency tracing worker - `build/webpack-build/impl.ts` — webpack compilation worker - `build/turbopack-build/impl.ts` — turbopack compilation worker - `telemetry/detached-flush.ts` — detached telemetry flush process Process entry points without `import node-environment`: - `trace/trace-uploader.ts` — uploads trace files, doesn't load config or run server code - `lib/verify-typescript-setup.ts` — runs tsc, doesn't load config or run server code
Author
Committer
Parents
Loading