-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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: make error format configurable #9441
base: main
Are you sure you want to change the base?
Conversation
|
Mert Can Altin seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
|
CodSpeed Performance ReportMerging #9441 will degrade performances by 6.34%Comparing Summary
Benchmarks breakdown
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Build in CI failed
cc @kwonoj Do you have any idea about this? |
@@ -16,6 +17,12 @@ use swc_core::{ | |||
|
|||
use crate::{get_compiler, util::try_with}; | |||
|
|||
#[derive(Debug, Deserialize)] | |||
pub enum ErrorFormatConfig { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this option in binding?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ErrorFormatConfig was introduced to provide flexibility in formatting error outputs, allowing different representations (e.g., JSON) depending on the user's needs. It was included here to streamline error handling directly within the minification process
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, why is it stored in bindings/*
? I think it's a quite general option and I believe swc_error_reporters
is the better place to store this type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now I understand better thank you I will make an update
pub fn minify_sync( | ||
code: Buffer, | ||
opts: Buffer, | ||
error_format: Option<ErrorFormatConfig>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, why is this an additional parameter, instead of additional field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think reasoning behind using an additional parameter instead of a field was to maintain the separation of concerns. By keeping ErrorFormatConfig as a separate argument, it avoids bloating the existing options structure and allows for easier future extensions or modifications
Sorry, checking in late. Mind elaborate what you have in mind? the config option itself? |
Yeap, and it being an additional parameter instead of a field. |
Yes, curious if there's a reason it have to be a 3rd arg instead of extending existing option. |
decision to introduce it as a third argument rather than extending the existing options was to avoid coupling the error formatting configuration with the core minify options. This modular approach allows users to control error output separately, which can be more intuitive and flexible |
thank you for your suggestions I sent a commit |
I wonder if you have a suggestion about this error @kdy1 I think it's because it's in string type
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please patch
swc/bindings/binding_core_node/src/minify.rs
Lines 62 to 66 in b0b5e36
try_with(self.c.cm.clone(), false, ErrorFormat::Normal, |handler| { | |
let fm = input.to_file(self.c.cm.clone()); | |
self.c.minify(fm, handler, &options) | |
}) |
ErrorFormatConfig
enum to allow configuration of theErrorFormat
used in theminify_sync
function.minify_sync
to accept an optionalerror_format
parameter, which can be set to "normal", "json", or "color".error_format
parameter defaults toErrorFormat::Normal
if not provided.ErrorFormat
configurable, providing greater flexibility in error reporting formats.can be used in the typeScript field :
const result = minify_sync(codeBuffer, optsBuffer, "json");