Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion packages/nuxt-cli/src/dev/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class ForkPool {
execArgv: ['--enable-source-maps'],
stdio: pipeOutput ? ['ignore', 'pipe', 'pipe', 'ipc'] : undefined,
env: {
...process.env,
...withoutDotenvVars(process.env),
__NUXT__FORK: 'true',
...pipeOutput
? {
Expand Down Expand Up @@ -250,6 +250,19 @@ function trackServing(child: ChildProcess): Promise<void> {
})
}

/**
* The environment without the variables `.env` files set in this process, so a
* fork reads them afresh. c12 only overwrites variables it set itself, and its
* record of those does not survive into a new process.
*/
function withoutDotenvVars(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
const dotenvVars = (globalThis as { __c12_dotenv_vars__?: Map<object, Set<string>> }).__c12_dotenv_vars__?.get(env)
if (!dotenvVars?.size) {
return env
}
return Object.fromEntries(Object.entries(env).filter(([key]) => !dotenvVars.has(key)))
}

/** Colour settings for a piped fork, which cannot detect colour support itself. */
function forcedColorEnv(): Record<string, string> {
if (process.env.NO_COLOR || process.env.FORCE_COLOR) {
Expand Down
Loading