Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
fd508b08
Unverified
Commit
fd508b08
authored
Jul 04, 2023
by
Tobias Koppers
Committed by
GitHub
Jul 04, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix env reloading for turbopack (#52194)
### What? fixes WEB-1258
parent
8aa9a52c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
31 deletions
+39
-31
index.ts
packages/next-env/index.ts
+6
-0
next-dev.ts
packages/next/src/cli/next-dev.ts
+4
-0
hmr.test.ts
test/development/app-hmr/hmr.test.ts
+29
-31
No files found.
packages/next-env/index.ts
View file @
fd508b08
...
@@ -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
,
...
...
packages/next/src/cli/next-dev.ts
View file @
fd508b08
...
@@ -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
,
...
...
test/development/app-hmr/hmr.test.ts
View file @
fd508b08
...
@@ -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,39 +35,37 @@ createNextDescribe(
...
@@ -35,39 +35,37 @@ 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'
)
expect
(
await
browser
.
elementByCss
(
'p'
).
text
()).
toBe
(
'mac'
)
expect
(
await
browser
.
elementByCss
(
'p'
).
text
()).
toBe
(
'mac'
)
await
next
.
patchFile
(
envFile
,
'MY_DEVICE="ipad"'
)
await
next
.
patchFile
(
envFile
,
'MY_DEVICE="ipad"'
)
try
{
try
{
await
check
(
async
()
=>
{
await
check
(
async
()
=>
{
expect
(
await
browser
.
elementByCss
(
'p'
).
text
()).
toBe
(
'ipad'
)
expect
(
await
browser
.
elementByCss
(
'p'
).
text
()).
toBe
(
'ipad'
)
return
'success'
return
'success'
},
/success/
)
},
/success/
)
}
finally
{
}
finally
{
await
next
.
patchFile
(
envFile
,
envContent
)
await
next
.
patchFile
(
envFile
,
envContent
)
}
}
})
})
it
(
'should update server components pages when env files is changed (edge)'
,
async
()
=>
{
it
(
'should update server components pages when env files is changed (edge)'
,
async
()
=>
{
const
envContent
=
await
next
.
readFile
(
envFile
)
const
envContent
=
await
next
.
readFile
(
envFile
)
const
browser
=
await
next
.
browser
(
'/env/edge'
)
const
browser
=
await
next
.
browser
(
'/env/edge'
)
expect
(
await
browser
.
elementByCss
(
'p'
).
text
()).
toBe
(
'mac'
)
expect
(
await
browser
.
elementByCss
(
'p'
).
text
()).
toBe
(
'mac'
)
await
next
.
patchFile
(
envFile
,
'MY_DEVICE="ipad"'
)
await
next
.
patchFile
(
envFile
,
'MY_DEVICE="ipad"'
)
try
{
try
{
await
check
(
async
()
=>
{
await
check
(
async
()
=>
{
expect
(
await
browser
.
elementByCss
(
'p'
).
text
()).
toBe
(
'ipad'
)
expect
(
await
browser
.
elementByCss
(
'p'
).
text
()).
toBe
(
'ipad'
)
return
'success'
return
'success'
},
/success/
)
},
/success/
)
}
finally
{
}
finally
{
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'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment