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
4d193ea3
Unverified
Commit
4d193ea3
authored
Apr 20, 2020
by
JJ Kasper
Committed by
GitHub
Apr 20, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update to only apply experimental process.env stub in developm… (#12055)
parent
5592e64c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
121 additions
and
46 deletions
+121
-46
webpack-config.ts
packages/next/build/webpack-config.ts
+3
-8
hello.js
test/integration/process-env-stub/components/hello.js
+11
-0
missing.js
test/integration/process-env-stub/pages/missing.js
+13
-2
index.test.js
test/integration/process-env-stub/test/index.test.js
+94
-36
No files found.
packages/next/build/webpack-config.ts
View file @
4d193ea3
...
...
@@ -867,15 +867,10 @@ export default async function getBaseWebpackConfig(
}
:
undefined
),
// stub process.env with proxy to warn a missing value is
// being accessed
...(
config
.
experimental
.
pageEnv
// being accessed
in development mode
...(
config
.
experimental
.
pageEnv
&&
process
.
env
.
NODE_ENV
!==
'production'
?
{
'process.env'
:
process
.
env
.
NODE_ENV
===
'production'
?
isServer
?
'process.env'
:
'{}'
:
`
'process.env'
:
`
new Proxy(
${
isServer
?
'process.env'
:
'{}'
}
, {
get(target, prop) {
if (typeof target[prop] === 'undefined') {
...
...
test/integration/process-env-stub/components/hello.js
0 → 100644
View file @
4d193ea3
import
{
PHASE_PRODUCTION_BUILD
}
from
'next/constants'
const
{
NODE_ENV
}
=
process
.
env
const
{
NEXT_PHASE
}
=
process
.
env
const
SENTRY_DSN
=
process
.
env
.
NEXT_PUBLIC_SENTRY_DSN
if
(
NODE_ENV
!==
'development'
&&
NEXT_PHASE
!==
PHASE_PRODUCTION_BUILD
)
{
console
.
log
(
'next start'
,
SENTRY_DSN
)
}
export
default
()
=>
process
.
env
.
HELLO
||
'hi'
test/integration/process-env-stub/pages/missing.js
View file @
4d193ea3
import
dynamic
from
'next/dynamic'
const
Hello
=
dynamic
(()
=>
import
(
'../components/hello'
),
{
ssr
:
true
})
export
default
()
=>
{
console
.
log
(
process
.
env
.
hi
)
return
<
p
>
hi
there
👋
<
/p
>
// make sure we handle this syntax correctly
const
{
hi
}
=
process
.
env
console
.
log
(
hi
)
return
(
<>
<
p
>
hi
there
👋
<
/p
>
<
Hello
/>
<
/
>
)
}
test/integration/process-env-stub/test/index.test.js
View file @
4d193ea3
...
...
@@ -6,6 +6,8 @@ import {
launchApp
,
renderViaHTTP
,
waitFor
,
nextBuild
,
nextStart
,
}
from
'next-test-utils'
import
{
join
}
from
'path'
import
webdriver
from
'next-webdriver'
...
...
@@ -54,57 +56,113 @@ const checkMissingClient = async (pathname, prop, shouldWarn = false) => {
}
describe
(
'process.env stubbing'
,
()
=>
{
beforeAll
(
async
()
=>
{
appPort
=
await
findPort
()
app
=
await
launchApp
(
appDir
,
appPort
,
{
env
:
{
NEXT_PUBLIC_HI
:
'hi'
,
I_SHOULD_BE_HERE
:
'hello'
,
},
onStderr
(
msg
)
{
stderr
+=
msg
||
''
},
describe
(
'dev mode'
,
()
=>
{
beforeAll
(
async
()
=>
{
appPort
=
await
findPort
()
app
=
await
launchApp
(
appDir
,
appPort
,
{
env
:
{
NEXT_PUBLIC_HI
:
'hi'
,
I_SHOULD_BE_HERE
:
'hello'
,
},
onStderr
(
msg
)
{
stderr
+=
msg
||
''
},
})
})
})
afterAll
(()
=>
killApp
(
app
))
afterAll
(()
=>
killApp
(
app
))
describe
(
'server side'
,
()
=>
{
it
(
'should not show missing env value when its not missing public'
,
async
()
=>
{
await
checkMissing
(
'/not-missing'
,
'NEXT_PUBLIC_HI'
)
})
describe
(
'server side'
,
()
=>
{
it
(
'should not show missing env value when its not missing public'
,
async
()
=>
{
await
checkMissing
(
'/not-missing'
,
'NEXT_PUBLIC_HI'
)
})
it
(
'should not show missing env value when its not missing runtime'
,
async
()
=>
{
await
checkMissing
(
'/also-not-missing'
,
'I_SHOULD_BE_HERE'
)
})
it
(
'should not show missing env value when its not missing runtime'
,
async
()
=>
{
await
checkMissing
(
'/also-not-missing'
,
'I_SHOULD_BE_HERE'
)
})
it
(
'should show missing env value when its missing normal'
,
async
()
=>
{
await
checkMissing
(
'/missing'
,
'hi'
,
true
)
})
it
(
'should show missing env value when its missing normal'
,
async
()
=>
{
await
checkMissing
(
'/missing'
,
'hi'
,
true
)
})
it
(
'should show missing env value when its missing GSP'
,
async
()
=>
{
await
checkMissing
(
'/missing-gsp'
,
'SECRET'
,
true
)
})
it
(
'should show missing env value when its missing GSP'
,
async
()
=>
{
await
checkMissing
(
'/missing-gsp'
,
'SECRET'
,
true
)
})
it
(
'should show missing env value when its missing GSSP'
,
async
()
=>
{
await
checkMissing
(
'/missing-gssp'
,
'SECRET'
,
true
)
})
it
(
'should show missing env value when its missing GSSP'
,
async
()
=>
{
await
checkMissing
(
'/missing-gssp'
,
'SECRET'
,
true
)
it
(
'should show missing env value when its missing API'
,
async
()
=>
{
await
checkMissing
(
'/api/hi'
,
'where_is_it'
,
true
)
})
})
it
(
'should show missing env value when its missing API'
,
async
()
=>
{
await
checkMissing
(
'/api/hi'
,
'where_is_it'
,
true
)
describe
(
'client side'
,
()
=>
{
it
(
'should not show missing env value when its not missing public'
,
async
()
=>
{
await
checkMissingClient
(
'/not-missing'
,
'NEXT_PUBLIC_HI'
)
})
it
(
'should show missing env value when its missing runtime'
,
async
()
=>
{
await
checkMissingClient
(
'/also-not-missing'
,
'I_SHOULD_BE_HERE'
,
true
)
})
it
(
'should show missing env value when its missing normal'
,
async
()
=>
{
await
checkMissingClient
(
'/missing'
,
'hi'
,
true
)
})
})
})
describe
(
'client side'
,
()
=>
{
it
(
'should not show missing env value when its not missing public'
,
async
()
=>
{
await
checkMissingClient
(
'/not-missing'
,
'NEXT_PUBLIC_HI'
)
describe
(
'production mode'
,
()
=>
{
beforeAll
(
async
()
=>
{
const
{
code
}
=
await
nextBuild
(
appDir
)
if
(
code
!==
0
)
throw
new
Error
(
`build failed with code
${
code
}
`
)
appPort
=
await
findPort
()
app
=
await
nextStart
(
appDir
,
appPort
,
{
onStderr
(
msg
)
{
stderr
+=
msg
||
''
},
})
})
afterAll
(()
=>
killApp
(
app
))
it
(
'should show missing env value when its missing runtime'
,
async
()
=>
{
await
checkMissingClient
(
'/also-not-missing'
,
'I_SHOULD_BE_HERE'
,
true
)
describe
(
'server side'
,
()
=>
{
it
(
'should not show missing env value when its not missing public'
,
async
()
=>
{
await
checkMissing
(
'/not-missing'
,
'NEXT_PUBLIC_HI'
)
})
it
(
'should not show missing env value when its not missing runtime'
,
async
()
=>
{
await
checkMissing
(
'/also-not-missing'
,
'I_SHOULD_BE_HERE'
)
})
it
(
'should not show missing env value when its missing normal'
,
async
()
=>
{
await
checkMissing
(
'/missing'
,
'hi'
)
})
it
(
'should not show missing env value when its missing GSP'
,
async
()
=>
{
await
checkMissing
(
'/missing-gsp'
,
'SECRET'
)
})
it
(
'should not show missing env value when its missing GSSP'
,
async
()
=>
{
await
checkMissing
(
'/missing-gssp'
,
'SECRET'
)
})
it
(
'should not show missing env value when its missing API'
,
async
()
=>
{
await
checkMissing
(
'/api/hi'
,
'where_is_it'
)
})
})
it
(
'should show missing env value when its missing normal'
,
async
()
=>
{
await
checkMissingClient
(
'/missing'
,
'hi'
,
true
)
describe
(
'client side'
,
()
=>
{
it
(
'should not show missing env value when its not missing public'
,
async
()
=>
{
await
checkMissingClient
(
'/not-missing'
,
'NEXT_PUBLIC_HI'
)
})
it
(
'should not show missing env value when its missing runtime'
,
async
()
=>
{
await
checkMissingClient
(
'/also-not-missing'
,
'I_SHOULD_BE_HERE'
)
})
it
(
'should not show missing env value when its missing normal'
,
async
()
=>
{
await
checkMissingClient
(
'/missing'
,
'hi'
)
})
})
})
})
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