Skip to content

Commit aeb9c1d

Browse files
committed
Back-merge main into development
2 parents f8b8464 + b307621 commit aeb9c1d

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/make-env-public.spec.ts

+10
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ describe('makeEnvPublic()', () => {
7878
);
7979
});
8080

81+
it('should warn when prefixing a variable that is not available in process.env', () => {
82+
makeEnvPublic('FOO');
83+
84+
expect(warnSpy).toHaveBeenCalledWith(
85+
`${chalk.yellow(
86+
`warn`
87+
)} - [next-runtime-env] - Skipped prefixing environment variable 'FOO'. Variable not in process.env.`
88+
);
89+
});
90+
8191
it('should warn when the env var already starts with NEXT_PUBLIC_', () => {
8292
process.env.NEXT_PUBLIC_FOO = 'foo';
8393

src/make-env-public.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
import * as log from './utils/log';
22

33
function prefixKey(key: string) {
4-
// Check if the key already is already public.
4+
// Check if key is available in process.env.
5+
if (!process.env[key]) {
6+
log.warn(
7+
`Skipped prefixing environment variable '${key}'. Variable not in process.env.`
8+
);
9+
10+
return;
11+
}
12+
13+
// Check if key is already public.
514
if (/^NEXT_PUBLIC_/i.test(key)) {
615
log.warn(`Environment variable '${key}' is already public.`);
716
}

0 commit comments

Comments
 (0)