Unverified Commit fd508b08 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

fix env reloading for turbopack (#52194)

### What?

fixes WEB-1258
parent 8aa9a52c
...@@ -93,6 +93,12 @@ export function processEnv( ...@@ -93,6 +93,12 @@ export function processEnv(
return Object.assign(process.env, parsed) return Object.assign(process.env, parsed)
} }
export function resetEnv() {
if (initialEnv) {
replaceProcessEnv(initialEnv)
}
}
export function loadEnvConfig( export function loadEnvConfig(
dir: string, dir: string,
dev?: boolean, dev?: boolean,
......
...@@ -23,6 +23,7 @@ import { getNpxCommand } from '../lib/helpers/get-npx-command' ...@@ -23,6 +23,7 @@ import { getNpxCommand } from '../lib/helpers/get-npx-command'
import Watchpack from 'watchpack' import Watchpack from 'watchpack'
import stripAnsi from 'next/dist/compiled/strip-ansi' import stripAnsi from 'next/dist/compiled/strip-ansi'
import { getPossibleInstrumentationHookFilenames } from '../build/worker' import { getPossibleInstrumentationHookFilenames } from '../build/worker'
import { resetEnv } from '@next/env'
let dir: string let dir: string
let isTurboSession = false let isTurboSession = false
...@@ -293,6 +294,9 @@ const nextDev: CliCommand = async (argv) => { ...@@ -293,6 +294,9 @@ const nextDev: CliCommand = async (argv) => {
} }
} }
// Turbopack need to be in control over reading the .env files and watching them.
// So we need to start with a initial env to know which env vars are coming from the user.
resetEnv()
let bindings: any = await loadBindings() let bindings: any = await loadBindings()
let server = bindings.turbo.startDev({ let server = bindings.turbo.startDev({
...devServerOptions, ...devServerOptions,
......
...@@ -8,7 +8,7 @@ createNextDescribe( ...@@ -8,7 +8,7 @@ createNextDescribe(
{ {
files: __dirname, files: __dirname,
}, },
({ next, isTurbopack }) => { ({ next }) => {
describe('filesystem changes', () => { describe('filesystem changes', () => {
it('should not break when renaming a folder', async () => { it('should not break when renaming a folder', async () => {
const browser = await next.browser('/folder') const browser = await next.browser('/folder')
...@@ -35,7 +35,6 @@ createNextDescribe( ...@@ -35,7 +35,6 @@ createNextDescribe(
} }
}) })
if (!isTurbopack) {
it('should update server components pages when env files is changed (nodejs)', async () => { it('should update server components pages when env files is changed (nodejs)', async () => {
const envContent = await next.readFile(envFile) const envContent = await next.readFile(envFile)
const browser = await next.browser('/env/node') const browser = await next.browser('/env/node')
...@@ -67,7 +66,6 @@ createNextDescribe( ...@@ -67,7 +66,6 @@ createNextDescribe(
await next.patchFile(envFile, envContent) await next.patchFile(envFile, envContent)
} }
}) })
}
it('should have no unexpected action error for hmr', async () => { it('should have no unexpected action error for hmr', async () => {
expect(next.cliOutput).not.toContain('Unexpected action') expect(next.cliOutput).not.toContain('Unexpected action')
......
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