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(
return Object.assign(process.env, parsed)
}
export function resetEnv() {
if (initialEnv) {
replaceProcessEnv(initialEnv)
}
}
export function loadEnvConfig(
dir: string,
dev?: boolean,
......
......@@ -23,6 +23,7 @@ import { getNpxCommand } from '../lib/helpers/get-npx-command'
import Watchpack from 'watchpack'
import stripAnsi from 'next/dist/compiled/strip-ansi'
import { getPossibleInstrumentationHookFilenames } from '../build/worker'
import { resetEnv } from '@next/env'
let dir: string
let isTurboSession = false
......@@ -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 server = bindings.turbo.startDev({
...devServerOptions,
......
......@@ -8,7 +8,7 @@ createNextDescribe(
{
files: __dirname,
},
({ next, isTurbopack }) => {
({ next }) => {
describe('filesystem changes', () => {
it('should not break when renaming a folder', async () => {
const browser = await next.browser('/folder')
......@@ -35,39 +35,37 @@ createNextDescribe(
}
})
if (!isTurbopack) {
it('should update server components pages when env files is changed (nodejs)', async () => {
const envContent = await next.readFile(envFile)
const browser = await next.browser('/env/node')
expect(await browser.elementByCss('p').text()).toBe('mac')
await next.patchFile(envFile, 'MY_DEVICE="ipad"')
it('should update server components pages when env files is changed (nodejs)', async () => {
const envContent = await next.readFile(envFile)
const browser = await next.browser('/env/node')
expect(await browser.elementByCss('p').text()).toBe('mac')
await next.patchFile(envFile, 'MY_DEVICE="ipad"')
try {
await check(async () => {
expect(await browser.elementByCss('p').text()).toBe('ipad')
return 'success'
}, /success/)
} finally {
await next.patchFile(envFile, envContent)
}
})
try {
await check(async () => {
expect(await browser.elementByCss('p').text()).toBe('ipad')
return 'success'
}, /success/)
} finally {
await next.patchFile(envFile, envContent)
}
})
it('should update server components pages when env files is changed (edge)', async () => {
const envContent = await next.readFile(envFile)
const browser = await next.browser('/env/edge')
expect(await browser.elementByCss('p').text()).toBe('mac')
await next.patchFile(envFile, 'MY_DEVICE="ipad"')
it('should update server components pages when env files is changed (edge)', async () => {
const envContent = await next.readFile(envFile)
const browser = await next.browser('/env/edge')
expect(await browser.elementByCss('p').text()).toBe('mac')
await next.patchFile(envFile, 'MY_DEVICE="ipad"')
try {
await check(async () => {
expect(await browser.elementByCss('p').text()).toBe('ipad')
return 'success'
}, /success/)
} finally {
await next.patchFile(envFile, envContent)
}
})
}
try {
await check(async () => {
expect(await browser.elementByCss('p').text()).toBe('ipad')
return 'success'
}, /success/)
} finally {
await next.patchFile(envFile, envContent)
}
})
it('should have no unexpected action error for hmr', async () => {
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