Skip to content

feat: add support for consola.group & consola.groupEnd #374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

kricsleo
Copy link
Member

@kricsleo kricsleo commented Mar 25, 2025

resolves #184

Preview:
image

Copy link

codecov bot commented Mar 25, 2025

Codecov Report

Attention: Patch coverage is 30.61224% with 34 lines in your changes missing coverage. Please review.

Project coverage is 29.11%. Comparing base (24c98ce) to head (d536a3e).
Report is 57 commits behind head on main.

Files with missing lines Patch % Lines
examples/group.ts 0.00% 15 Missing and 1 partial ⚠️
src/reporters/basic.ts 7.14% 13 Missing ⚠️
src/consola.ts 50.00% 4 Missing ⚠️
src/reporters/fancy.ts 66.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #374       +/-   ##
===========================================
- Coverage   61.08%   29.11%   -31.98%     
===========================================
  Files          13       44       +31     
  Lines        1380     1769      +389     
  Branches       58       92       +34     
===========================================
- Hits          843      515      -328     
- Misses        537     1226      +689     
- Partials        0       28       +28     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@@ -91,6 +95,12 @@ export const LogTypes: Record<LogType, Partial<LogObject>> = {
log: {
level: LogLevels.log,
},
group: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

group/groupEnv don't need to be a log type (like consola.prompt they can be standalone consola methods)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Treating them as log types simplifies integration with the existing logic, I suppose 🤔

  • wrap & unwrap
  • reporters can format or process .group message with the same logObj

@@ -21,6 +21,8 @@ const queue: any[] = [];
export class Consola {
options: ConsolaOptions;

private groupIndentionLevel = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am thinking instead of having an integer, we can store group titles, for example, consola.group('building..') can be displayed (or used for interceptors)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The groupIndentionLevel tracks the indentation level since .group can be nested.

If we consider .group as a log type, the current logic can display group titles correctly without further changes.

@kricsleo
Copy link
Member Author

kricsleo commented Mar 26, 2025

I plan to use indentation to display groups, consistent with native behavior. What do you think? 🤔

consola.info('0 - Hello World!')

consola.group('0 - Group')
consola.info('1 - Hello World!')
consola.warn('1 - Hello World!')
consola.error(new Error('1 - Hello World!'))

consola.group('1 - Group')
consola.info('1-1 - Hello World!')
consola.warn('1-1 - Hello World!')
consola.error(new Error('1-1 - Hello World!'))
consola.groupEnd()

consola.info('1 - Hello World!')
consola.warn('1 - Hello World!')
consola.error(new Error('1 - Hello World!'))

consola.groupEnd()

consola.info('0 - Hello World!')

Would this work for you? (vertical line added) @pi0

image

@pi0
Copy link
Member

pi0 commented Mar 26, 2025

Surely we can also use them for indentation (array.length), I am thinking to allow show a vertical line | in left to make it more organized better than what Node.js console does wdyt?

@kricsleo kricsleo marked this pull request as ready for review March 26, 2025 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for console.group
2 participants