Skip to content
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

feat: support Rollup logging functions #13757

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

Conversation

mato533
Copy link

@mato533 mato533 commented Jul 9, 2023

Description

This PR contains feature of supporting Rollup logging function.
Originally, the Vite used onWarn to handle only warnings, but this pull request uses onLog to add handling for info, debug, and error log levels.

Additional context


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the PR Title Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@stackblitz
Copy link

stackblitz bot commented Jul 9, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@mato533 mato533 changed the title Feature/Support Rollup logging functions feat: Support Rollup logging functions Jul 10, 2023
@sapphi-red sapphi-red added enhancement New feature or request rollup plugin compat p3-significant High priority enhancement (priority) labels Jul 13, 2023
@mato533 mato533 changed the title feat: Support Rollup logging functions feat: support Rollup logging functions Jul 14, 2023
Copy link
Member

@sapphi-red sapphi-red left a comment

Choose a reason for hiding this comment

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

Comment on lines 933 to 937
config.logger.info(
`${colors.bold(
colors.gray(`[plugin:${logging.plugin}]`),
)} ${colors.gray(logging.message)}`,
)
Copy link
Member

Choose a reason for hiding this comment

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

We use debug function for debug logs in other places. Let's use it here as well.
https://github.com/vitejs/vite/blob/1292ad08a06e2ae8c44307797ba533f64a602759/packages/vite/src/node/utils.ts#L157C17-L157C31

Copy link
Author

Choose a reason for hiding this comment

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

@sapphi-red
Thank you for your review.
I missed vite's debugger implementation. I pushed the commit fixing it to use Vite's debugger.
Please check it.

Comment on lines -549 to +550
onwarn(warning, warn) {
onRollupWarning(warning, warn, config)
onLog(level, log, defaultHandler) {
onRollupLog(level, log, defaultHandler, config)
Copy link
Member

Choose a reason for hiding this comment

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

Would you check if onwarn is called before onLog or not? If onLog is called before onwarn, I think we'll need to pass both onwarn and onLog.

Copy link
Author

Choose a reason for hiding this comment

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

@sapphi-red
Thank you for your review!

When rollup calls the logger with warn, onwarn is called after onLog. And my understanding is that onwarn is only called when the default handler is called at onLog.

In the event of a warning, only logs that are not handled by the handling implemented in onRollupLog (ignoring specific warning logs or handling plugin logs) will be passed to the default handler and onwarn will be called. On that premise, passing the same implementation to onLog and onwarn does not make sense because the same handling (which is also executed in onlog) is executed.

What do you think about this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request p3-significant High priority enhancement (priority) rollup plugin compat
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants