forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display where the env was loaded from when enabled
typedEnv
(vercel…
…#70951) ### Why? This PR added an indication of where the env was loaded from when `experimental.typedEnv` was enabled. Also, it allows the user to set `NODE_ENV=production` to enable the `typedEnv` feature for `.env.production*` files. ![CleanShot 2024-11-21 at 19 48 20](https://github.com/user-attachments/assets/ce3c7180-f26a-4378-a74f-a5998a363211) ### How? Modified `@next/env` to pass parsed envs along with the `loadedEnvFiles` value and used the location to indicate via JSDoc.
- Loading branch information
1 parent
7885f88
commit 73f547a
Showing
11 changed files
with
207 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 17 additions & 7 deletions
24
packages/next/src/server/lib/experimental/create-env-definitions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
FROM_ENV_DEV="FROM_ENV_DEV" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
FROM_DEV_ENV_LOCAL="FROM_DEV_ENV_LOCAL" | ||
FROM_ENV_DEV_LOCAL="FROM_ENV_DEV_LOCAL" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
FROM_ENV_PROD="FROM_ENV_PROD" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
FROM_PROD_ENV_LOCAL="FROM_PROD_ENV_LOCAL" | ||
FROM_ENV_PROD_LOCAL="FROM_ENV_PROD_LOCAL" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { nextTestSetup } from 'e2e-utils' | ||
import { retry } from 'next-test-utils' | ||
|
||
describe('typed-env', () => { | ||
const { next } = nextTestSetup({ | ||
files: __dirname, | ||
env: { | ||
NODE_ENV: 'production', | ||
}, | ||
}) | ||
|
||
it('should have env types from next config', async () => { | ||
await retry(async () => { | ||
const envDTS = await next.readFile('.next/types/env.d.ts') | ||
// since NODE_ENV is production, env types will | ||
// not include development-specific env | ||
expect(envDTS).not.toContain('FROM_ENV_DEV') | ||
expect(envDTS).not.toContain('FROM_ENV_DEV_LOCAL') | ||
|
||
expect(envDTS).toMatchInlineSnapshot(` | ||
"// Type definitions for Next.js environment variables | ||
declare global { | ||
namespace NodeJS { | ||
interface ProcessEnv { | ||
/** Loaded from \`.env.production.local\` */ | ||
FROM_ENV_PROD_LOCAL?: string | ||
/** Loaded from \`.env.local\` */ | ||
FROM_ENV_LOCAL?: string | ||
/** Loaded from \`.env.production\` */ | ||
FROM_ENV_PROD?: string | ||
/** Loaded from \`.env\` */ | ||
FROM_ENV?: string | ||
/** Loaded from \`next.config.js\` */ | ||
FROM_NEXT_CONFIG?: string | ||
} | ||
} | ||
} | ||
export {}" | ||
`) | ||
}) | ||
}) | ||
|
||
// TODO: test for deleting .env & updating env.d.ts | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters