Skip to content

Commit

Permalink
Back-merge main into development
Browse files Browse the repository at this point in the history
  • Loading branch information
expatfile-bot committed May 3, 2023
2 parents f8b8464 + b307621 commit aeb9c1d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/make-env-public.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ describe('makeEnvPublic()', () => {
);
});

it('should warn when prefixing a variable that is not available in process.env', () => {
makeEnvPublic('FOO');

expect(warnSpy).toHaveBeenCalledWith(
`${chalk.yellow(
`warn`
)} - [next-runtime-env] - Skipped prefixing environment variable 'FOO'. Variable not in process.env.`
);
});

it('should warn when the env var already starts with NEXT_PUBLIC_', () => {
process.env.NEXT_PUBLIC_FOO = 'foo';

Expand Down
11 changes: 10 additions & 1 deletion src/make-env-public.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import * as log from './utils/log';

function prefixKey(key: string) {
// Check if the key already is already public.
// Check if key is available in process.env.
if (!process.env[key]) {
log.warn(
`Skipped prefixing environment variable '${key}'. Variable not in process.env.`
);

return;
}

// Check if key is already public.
if (/^NEXT_PUBLIC_/i.test(key)) {
log.warn(`Environment variable '${key}' is already public.`);
}
Expand Down

0 comments on commit aeb9c1d

Please sign in to comment.