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
0a3b64d2
Unverified
Commit
0a3b64d2
authored
Apr 23, 2020
by
JJ Kasper
Committed by
GitHub
Apr 23, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for dotenv-expand behavior (#12140)
parent
29f86d90
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
25 additions
and
38 deletions
+25
-38
load-env-config.ts
packages/next/lib/load-env-config.ts
+6
-2
.env
test/integration/env-config/app/.env
+4
-1
all.js
test/integration/env-config/app/pages/api/all.js
+3
-0
index.js
test/integration/env-config/app/pages/index.js
+3
-0
some-ssg.js
test/integration/env-config/app/pages/some-ssg.js
+3
-0
some-ssp.js
test/integration/env-config/app/pages/some-ssp.js
+3
-0
ssp.js
test/integration/env-config/app/pages/ssp.js
+0
-35
index.test.js
test/integration/env-config/test/index.test.js
+3
-0
No files found.
packages/next/lib/load-env-config.ts
View file @
0a3b64d2
...
@@ -17,7 +17,11 @@ const packageJsonHasDep = (packageJsonPath: string, dep: string): boolean => {
...
@@ -17,7 +17,11 @@ const packageJsonHasDep = (packageJsonPath: string, dep: string): boolean => {
return
allPackages
.
some
(
pkg
=>
pkg
===
dep
)
return
allPackages
.
some
(
pkg
=>
pkg
===
dep
)
}
}
let
combinedEnv
:
Env
|
undefined
=
undefined
export
function
loadEnvConfig
(
dir
:
string
,
dev
?:
boolean
):
Env
|
false
{
export
function
loadEnvConfig
(
dir
:
string
,
dev
?:
boolean
):
Env
|
false
{
if
(
combinedEnv
)
return
combinedEnv
const
packageJson
=
findUp
.
sync
(
'package.json'
,
{
cwd
:
dir
})
const
packageJson
=
findUp
.
sync
(
'package.json'
,
{
cwd
:
dir
})
// only do new env loading if dotenv isn't installed since we
// only do new env loading if dotenv isn't installed since we
...
@@ -61,9 +65,9 @@ export function loadEnvConfig(dir: string, dev?: boolean): Env | false {
...
@@ -61,9 +65,9 @@ export function loadEnvConfig(dir: string, dev?: boolean): Env | false {
'.env'
,
'.env'
,
].
filter
(
Boolean
)
as
string
[]
].
filter
(
Boolean
)
as
string
[]
co
nst
combinedEnv
:
Env
=
{
co
mbined
Env
=
{
...(
process
.
env
as
any
),
...(
process
.
env
as
any
),
}
}
as
Env
for
(
const
envFile
of
dotenvFiles
)
{
for
(
const
envFile
of
dotenvFiles
)
{
// only load .env if the user provided has an env config file
// only load .env if the user provided has an env config file
...
...
test/integration/env-config/app/.env
View file @
0a3b64d2
...
@@ -7,4 +7,7 @@ ENV_FILE_PRODUCTION_OVERRIDEOVERRIDE_TEST=env
...
@@ -7,4 +7,7 @@ ENV_FILE_PRODUCTION_OVERRIDEOVERRIDE_TEST=env
ENV_FILE_PRODUCTION_LOCAL_OVERRIDEOVERRIDE_TEST=env
ENV_FILE_PRODUCTION_LOCAL_OVERRIDEOVERRIDE_TEST=env
ENV_FILE_TEST_OVERRIDE_TEST=env
ENV_FILE_TEST_OVERRIDE_TEST=env
ENV_FILE_TEST_LOCAL_OVERRIDEOVERRIDE_TEST=env
ENV_FILE_TEST_LOCAL_OVERRIDEOVERRIDE_TEST=env
NEXT_PUBLIC_TEST_DEST=another
NEXT_PUBLIC_TEST_DEST=another
\ No newline at end of file
ENV_FILE_EXPANDED=$ENV_FILE_KEY
ENV_FILE_EXPANDED_CONCAT=hello-${ENV_FILE_KEY}
ENV_FILE_EXPANDED_ESCAPED=\$ENV_FILE_KEY
\ No newline at end of file
test/integration/env-config/app/pages/api/all.js
View file @
0a3b64d2
...
@@ -15,6 +15,9 @@ const variables = [
...
@@ -15,6 +15,9 @@ const variables = [
'LOCAL_TEST_ENV_FILE_KEY'
,
'LOCAL_TEST_ENV_FILE_KEY'
,
'ENV_FILE_TEST_OVERRIDE_TEST'
,
'ENV_FILE_TEST_OVERRIDE_TEST'
,
'ENV_FILE_TEST_LOCAL_OVERRIDEOVERRIDE_TEST'
,
'ENV_FILE_TEST_LOCAL_OVERRIDEOVERRIDE_TEST'
,
'ENV_FILE_EXPANDED'
,
'ENV_FILE_EXPANDED_CONCAT'
,
'ENV_FILE_EXPANDED_ESCAPED'
,
]
]
const
items
=
{}
const
items
=
{}
...
...
test/integration/env-config/app/pages/index.js
View file @
0a3b64d2
...
@@ -15,6 +15,9 @@ const variables = [
...
@@ -15,6 +15,9 @@ const variables = [
'LOCAL_TEST_ENV_FILE_KEY'
,
'LOCAL_TEST_ENV_FILE_KEY'
,
'ENV_FILE_TEST_OVERRIDE_TEST'
,
'ENV_FILE_TEST_OVERRIDE_TEST'
,
'ENV_FILE_TEST_LOCAL_OVERRIDEOVERRIDE_TEST'
,
'ENV_FILE_TEST_LOCAL_OVERRIDEOVERRIDE_TEST'
,
'ENV_FILE_EXPANDED'
,
'ENV_FILE_EXPANDED_CONCAT'
,
'ENV_FILE_EXPANDED_ESCAPED'
,
]
]
export
async
function
getStaticProps
()
{
export
async
function
getStaticProps
()
{
...
...
test/integration/env-config/app/pages/some-ssg.js
View file @
0a3b64d2
...
@@ -15,6 +15,9 @@ const variables = [
...
@@ -15,6 +15,9 @@ const variables = [
'LOCAL_TEST_ENV_FILE_KEY'
,
'LOCAL_TEST_ENV_FILE_KEY'
,
'ENV_FILE_TEST_OVERRIDE_TEST'
,
'ENV_FILE_TEST_OVERRIDE_TEST'
,
'ENV_FILE_TEST_LOCAL_OVERRIDEOVERRIDE_TEST'
,
'ENV_FILE_TEST_LOCAL_OVERRIDEOVERRIDE_TEST'
,
'ENV_FILE_EXPANDED'
,
'ENV_FILE_EXPANDED_CONCAT'
,
'ENV_FILE_EXPANDED_ESCAPED'
,
]
]
export
async
function
getStaticProps
()
{
export
async
function
getStaticProps
()
{
...
...
test/integration/env-config/app/pages/some-ssp.js
View file @
0a3b64d2
...
@@ -15,6 +15,9 @@ const variables = [
...
@@ -15,6 +15,9 @@ const variables = [
'LOCAL_TEST_ENV_FILE_KEY'
,
'LOCAL_TEST_ENV_FILE_KEY'
,
'ENV_FILE_TEST_OVERRIDE_TEST'
,
'ENV_FILE_TEST_OVERRIDE_TEST'
,
'ENV_FILE_TEST_LOCAL_OVERRIDEOVERRIDE_TEST'
,
'ENV_FILE_TEST_LOCAL_OVERRIDEOVERRIDE_TEST'
,
'ENV_FILE_EXPANDED'
,
'ENV_FILE_EXPANDED_CONCAT'
,
'ENV_FILE_EXPANDED_ESCAPED'
,
]
]
export
async
function
getServerSideProps
()
{
export
async
function
getServerSideProps
()
{
...
...
test/integration/env-config/app/pages/ssp.js
deleted
100644 → 0
View file @
29f86d90
const
variables
=
[
'PROCESS_ENV_KEY'
,
'ENV_FILE_KEY'
,
'LOCAL_ENV_FILE_KEY'
,
'ENV_FILE_LOCAL_OVERRIDE_TEST'
,
'PRODUCTION_ENV_FILE_KEY'
,
'LOCAL_PRODUCTION_ENV_FILE_KEY'
,
'DEVELOPMENT_ENV_FILE_KEY'
,
'LOCAL_DEVELOPMENT_ENV_FILE_KEY'
,
'ENV_FILE_DEVELOPMENT_OVERRIDE_TEST'
,
'ENV_FILE_DEVELOPMENT_LOCAL_OVERRIDEOVERRIDE_TEST'
,
'ENV_FILE_PRODUCTION_OVERRIDEOVERRIDE_TEST'
,
'ENV_FILE_PRODUCTION_LOCAL_OVERRIDEOVERRIDE_TEST'
,
'TEST_ENV_FILE_KEY'
,
'LOCAL_TEST_ENV_FILE_KEY'
,
'ENV_FILE_TEST_OVERRIDE_TEST'
,
'ENV_FILE_TEST_LOCAL_OVERRIDEOVERRIDE_TEST'
,
]
export
async
function
getServerSideProps
()
{
const
items
=
{}
variables
.
forEach
(
variable
=>
{
if
(
process
.
env
[
variable
])
{
items
[
variable
]
=
process
.
env
[
variable
]
}
})
return
{
// Do not pass any sensitive values here as they will
// be made PUBLICLY available in `pageProps`
props
:
{
env
:
items
},
}
}
export
default
({
env
})
=>
<
p
>
{
JSON
.
stringify
(
env
)}
<
/p
>
test/integration/env-config/test/index.test.js
View file @
0a3b64d2
...
@@ -52,6 +52,9 @@ const runTests = (mode = 'dev') => {
...
@@ -52,6 +52,9 @@ const runTests = (mode = 'dev') => {
expect
(
data
.
LOCAL_PRODUCTION_ENV_FILE_KEY
).
toBe
(
expect
(
data
.
LOCAL_PRODUCTION_ENV_FILE_KEY
).
toBe
(
isDev
?
undefined
:
'localproduction'
isDev
?
undefined
:
'localproduction'
)
)
expect
(
data
.
ENV_FILE_EXPANDED
).
toBe
(
'env'
)
expect
(
data
.
ENV_FILE_EXPANDED_CONCAT
).
toBe
(
'hello-env'
)
expect
(
data
.
ENV_FILE_EXPANDED_ESCAPED
).
toBe
(
'$ENV_FILE_KEY'
)
}
}
it
(
'should have process environment override .env'
,
async
()
=>
{
it
(
'should have process environment override .env'
,
async
()
=>
{
...
...
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