Skip to content

Commit 77a1b18

Browse files
committed
feat: 🔊 adjust logs to match new nextjs style
1 parent 8a55476 commit 77a1b18

7 files changed

+42
-33
lines changed

src/helpers/get-public-env.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ describe('getPublicEnv()', () => {
7171
getPublicEnv();
7272

7373
expect(infoSpy).toHaveBeenCalledWith(
74-
`${chalk.cyan(
75-
`info`
76-
)} - [next-runtime-env] - Read environment variables prefixed with 'NEXT_PUBLIC_' from process.env.`
74+
`- ${chalk.magenta(
75+
`event`
76+
)} [next-runtime-env] read environment variables prefixed with 'NEXT_PUBLIC_' from process.env.`
7777
);
7878
});
7979
});

src/helpers/get-public-env.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export function getPublicEnv() {
1414
{} as NodeJS.ProcessEnv
1515
);
1616

17-
log.info(
18-
`Read environment variables prefixed with 'NEXT_PUBLIC_' from process.env.`
17+
log.event(
18+
`read environment variables prefixed with 'NEXT_PUBLIC_' from process.env.`
1919
);
2020

2121
return publicEnv;

src/helpers/write-browser-env.spec.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ const infoSpy = jest.spyOn(console, 'info');
88
const base = fs.realpathSync(process.cwd());
99
const path = `${base}/public`;
1010
const file = `${path}/__ENV.js`;
11-
const message = `${chalk.cyan(
12-
`info`
13-
)} - [next-runtime-env] - Wrote browser runtime environment variables to '${file}'.`;
11+
const message = `- ${chalk.green(
12+
`ready`
13+
)} [next-runtime-env] wrote browser runtime environment variables to '${file}'.`;
1414

1515
beforeAll(() => {
1616
infoSpy.mockImplementation();
@@ -71,9 +71,9 @@ describe('writeBrowserEnv()', () => {
7171

7272
it('should write to a subdirectory', () => {
7373
const fileInSubdirectory = `${path}/subdirectory/__ENV.js`;
74-
const messageWithSubdirectory = `${chalk.cyan(
75-
`info`
76-
)} - [next-runtime-env] - Wrote browser runtime environment variables to '${fileInSubdirectory}'.`;
74+
const messageWithSubdirectory = `- ${chalk.green(
75+
`ready`
76+
)} [next-runtime-env] wrote browser runtime environment variables to '${fileInSubdirectory}'.`;
7777

7878
writeBrowserEnv({}, 'subdirectory/');
7979

src/helpers/write-browser-env.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ export function writeBrowserEnv(env: NodeJS.ProcessEnv, subdirectory = '') {
2121

2222
fs.writeFileSync(file, content);
2323

24-
log.info(`Wrote browser runtime environment variables to '${file}'.`);
24+
log.ready(`wrote browser runtime environment variables to '${file}'.`);
2525
}

src/make-env-public.spec.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -60,31 +60,31 @@ describe('makeEnvPublic()', () => {
6060
makeEnvPublic(['BAR', 'BAZ']);
6161

6262
expect(infoSpy).toHaveBeenCalledWith(
63-
`${chalk.cyan(
64-
`info`
65-
)} - [next-runtime-env] - Prefixed environment variable 'FOO'.`
63+
`- ${chalk.magenta(
64+
`event`
65+
)} [next-runtime-env] prefixed environment variable 'FOO'.`
6666
);
6767

6868
expect(infoSpy).toHaveBeenCalledWith(
69-
`${chalk.cyan(
70-
`info`
71-
)} - [next-runtime-env] - Prefixed environment variable 'BAR'.`
69+
`- ${chalk.magenta(
70+
`event`
71+
)} [next-runtime-env] prefixed environment variable 'BAR'.`
7272
);
7373

7474
expect(infoSpy).toHaveBeenCalledWith(
75-
`${chalk.cyan(
76-
`info`
77-
)} - [next-runtime-env] - Prefixed environment variable 'BAZ'.`
75+
`- ${chalk.magenta(
76+
`event`
77+
)} [next-runtime-env] prefixed environment variable 'BAZ'.`
7878
);
7979
});
8080

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

8484
expect(warnSpy).toHaveBeenCalledWith(
85-
`${chalk.yellow(
85+
`- ${chalk.yellow(
8686
`warn`
87-
)} - [next-runtime-env] - Skipped prefixing environment variable 'FOO'. Variable not in process.env.`
87+
)} [next-runtime-env] skipped prefixing environment variable 'FOO'. Variable not in process.env.`
8888
);
8989
});
9090

@@ -94,9 +94,9 @@ describe('makeEnvPublic()', () => {
9494
makeEnvPublic('NEXT_PUBLIC_FOO');
9595

9696
expect(warnSpy).toHaveBeenCalledWith(
97-
`${chalk.yellow(
97+
`- ${chalk.yellow(
9898
`warn`
99-
)} - [next-runtime-env] - Environment variable 'NEXT_PUBLIC_FOO' is already public.`
99+
)} [next-runtime-env] environment variable 'NEXT_PUBLIC_FOO' is already public.`
100100
);
101101
});
102102
});

src/make-env-public.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ function prefixKey(key: string) {
44
// Check if key is available in process.env.
55
if (!process.env[key]) {
66
log.warn(
7-
`Skipped prefixing environment variable '${key}'. Variable not in process.env.`
7+
`skipped prefixing environment variable '${key}'. Variable not in process.env.`
88
);
99

1010
return;
1111
}
1212

1313
// Check if key is already public.
1414
if (/^NEXT_PUBLIC_/i.test(key)) {
15-
log.warn(`Environment variable '${key}' is already public.`);
15+
log.warn(`environment variable '${key}' is already public.`);
1616
}
1717

1818
const prefixedKey = `NEXT_PUBLIC_${key}`;
1919

2020
process.env[prefixedKey] = process.env[key];
2121

22-
log.info(`Prefixed environment variable '${key}'.`);
22+
log.event(`prefixed environment variable '${key}'.`);
2323
}
2424

2525
/**

src/utils/log.ts

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import chalk from 'chalk';
22

33
const libraryName = '[next-runtime-env]';
4-
const librarySeparator = '-';
5-
const libraryPrefix = `${libraryName} ${librarySeparator}`;
64

75
const prefixes = {
8-
// Double space before the dash aligns messages in the terminal and improves readability.
9-
warn: `${chalk.yellow(`warn`)} - ${libraryPrefix}`,
10-
info: `${chalk.cyan(`info`)} - ${libraryPrefix}`,
6+
info: `- ${chalk.cyan(`info`)} ${libraryName}`,
7+
warn: `- ${chalk.yellow(`warn`)} ${libraryName}`,
8+
event: `- ${chalk.magenta(`event`)} ${libraryName}`,
9+
ready: `- ${chalk.green(`ready`)} ${libraryName}`,
1110
};
1211

1312
export function warn(message: string) {
@@ -19,3 +18,13 @@ export function info(message: string) {
1918
// eslint-disable-next-line no-console
2019
console.info(`${prefixes.info} ${message}`);
2120
}
21+
22+
export function event(message: string) {
23+
// eslint-disable-next-line no-console
24+
console.info(`${prefixes.event} ${message}`);
25+
}
26+
27+
export function ready(message: string) {
28+
// eslint-disable-next-line no-console
29+
console.info(`${prefixes.ready} ${message}`);
30+
}

0 commit comments

Comments
 (0)