Skip to content

Commit c9b9fe8

Browse files
committed
fix(utils): prevent duplicate log group prefixes in sub-processes
1 parent dd13287 commit c9b9fe8

File tree

2 files changed

+4
-49
lines changed

2 files changed

+4
-49
lines changed

packages/utils/src/lib/logger.int.test.ts

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -242,22 +242,6 @@ ${ansis.cyan('└')} ${ansis.green(`Total line coverage is ${ansis.bold('82%')}`
242242
expect(output).toContain('Completed "ESLint" plugin execution');
243243
});
244244

245-
it('should use log group prefix in child loggers', async () => {
246-
performanceNowSpy.mockReturnValueOnce(0).mockReturnValueOnce(1234); // group duration: 1.23 s
247-
248-
await new Logger().group('Running plugin "ESLint"', async () => {
249-
new Logger().info(`${ansis.blue('$')} npx eslint . --format=json`);
250-
return 'ESLint reported 4 errors and 11 warnings';
251-
});
252-
253-
expect(output).toBe(`
254-
${ansis.bold.cyan('❯ Running plugin "ESLint"')}
255-
${ansis.cyan('│')} ${ansis.blue('$')} npx eslint . --format=json
256-
${ansis.cyan('└')} ${ansis.green('ESLint reported 4 errors and 11 warnings')} ${ansis.gray('(1.23 s)')}
257-
258-
`);
259-
});
260-
261245
it('should use workflow commands to group logs in GitHub Actions environment', async () => {
262246
vi.stubEnv('CI', 'true');
263247
vi.stubEnv('GITHUB_ACTIONS', 'true');
@@ -911,20 +895,6 @@ ${ansis.red.bold('Cancelled by SIGINT')}
911895
);
912896
});
913897

914-
it('should throw if nesting groups across logger instances', async () => {
915-
await expect(
916-
new Logger().group('Outer group', async () => {
917-
await new Logger().group(
918-
'Inner group',
919-
async () => 'Inner group complete',
920-
);
921-
return 'Outer group complete';
922-
}),
923-
).rejects.toThrow(
924-
'Internal Logger error - nested groups are not supported',
925-
);
926-
});
927-
928898
it('should throw if creating group while spinner is running', async () => {
929899
const logger = new Logger();
930900

packages/utils/src/lib/logger.ts

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import { settlePromise } from './promises.js';
1111
type GroupColor = Extract<AnsiColors, 'cyan' | 'magenta'>;
1212
type CiPlatform = 'GitHub Actions' | 'GitLab CI/CD';
1313

14-
const GROUP_COLOR_ENV_VAR_NAME = 'CP_LOGGER_GROUP_COLOR';
15-
1614
/**
1715
* Rich logging implementation for Code PushUp CLI, plugins, etc.
1816
*
@@ -26,11 +24,7 @@ export class Logger {
2624
: isEnvVarEnabled('GITLAB_CI')
2725
? 'GitLab CI/CD'
2826
: undefined;
29-
#groupColor: GroupColor | undefined =
30-
process.env[GROUP_COLOR_ENV_VAR_NAME] === 'cyan' ||
31-
process.env[GROUP_COLOR_ENV_VAR_NAME] === 'magenta'
32-
? process.env[GROUP_COLOR_ENV_VAR_NAME]
33-
: undefined;
27+
#groupColor: GroupColor | undefined;
3428

3529
#groupsCount = 0;
3630
#activeSpinner: Ora | undefined;
@@ -51,7 +45,7 @@ export class Logger {
5145
text,
5246
symbol: this.#colorize(this.#groupSymbols.end, this.#groupColor),
5347
});
54-
this.#setGroupColor(undefined);
48+
this.#groupColor = undefined;
5549
} else {
5650
this.#activeSpinner.fail(text);
5751
}
@@ -271,7 +265,7 @@ export class Logger {
271265
this.newline();
272266
}
273267

274-
this.#setGroupColor(this.#groupsCount % 2 === 0 ? 'cyan' : 'magenta');
268+
this.#groupColor = this.#groupsCount % 2 === 0 ? 'cyan' : 'magenta';
275269
this.#groupsCount++;
276270

277271
const groupMarkers = this.#createGroupMarkers();
@@ -308,7 +302,7 @@ export class Logger {
308302
if (endMarker) {
309303
console.log(endMarker);
310304
}
311-
this.#setGroupColor(undefined);
305+
this.#groupColor = undefined;
312306
this.newline();
313307

314308
if (result.status === 'rejected') {
@@ -366,15 +360,6 @@ export class Logger {
366360
return ansis.bold(this.#colorize(text, this.#groupColor));
367361
}
368362

369-
#setGroupColor(groupColor: GroupColor | undefined) {
370-
this.#groupColor = groupColor;
371-
if (groupColor) {
372-
process.env[GROUP_COLOR_ENV_VAR_NAME] = groupColor;
373-
} else {
374-
delete process.env[GROUP_COLOR_ENV_VAR_NAME];
375-
}
376-
}
377-
378363
async #spinner<T>(
379364
worker: () => Promise<T>,
380365
messages: {

0 commit comments

Comments
 (0)