-
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
[Request] Expose Message.details
formatter
#1058
Comments
@lukeed Check this out #920. May help answer some of your questions. You should be able to disable logs with const response = {
warnings: [],
errors: [],
}
try {
result = await esbuild.build({
// ...
})
if (result?.warnings?.length > 0) {
response.warnings = result.warnings
}
} catch (error) {
if (error?.errors?.length > 0) {
response.errors = error.errors
}
if (error?.warnings?.length > 0) {
response.warnings = error.warnings
}
}
// ... |
@zaydek thank you -- I'm aware I can do this. I'm in agreement with the other thread. My point here is that because esbuild's formatting is so good & covers so many edge cases, that I don't even want to attempt to reimplement the same coverage in my JS layer. Instead, I'm hoping esbuild's formatting is available as a new method on the Message object. |
I think the way to solve this would be to expose a top-level API to format a message object. I want to keep message objects serializable so I don't want to put a method on the messages themselves. And splitting off the detail part seems unnecessary when you can easily just remove the first line. |
Sounds good to me! |
Amazing 🙌 thanks! |
Nice work Evan. This actually solves a problem I didn’t know I had. I can defer to esbuild now for logging aesthetics, which is amazing. This essentially perfectly solves for #920. @lukeed Does this solve your problem? This look almost like a solution to a different problem if I’m not mistaken -- I thought what you were asking for is the ability to customize message UI before logging it. If this does solve your problem, do you mind sharing an example of how you’re using this feature? |
Nope, this is exactly what I was after. I wanted to access esbuild's existing formatting so that I could call it programmatically. I was hesitant to suggest a top-level API change, but this is definitely the better option. |
If you don’t mind, could you show how you plan on using the API with your original example?
Edit: Looking at the test cases I think I understand. Do you plan on calling |
@zaydek No problem. Yes, multiple times or once with all messages & then iterate thru the returned array: // errors (or warnings)
let output = `Build failed with ${err.errors.length} error(s):`;
let formatted = await esbuild.formatMessages(err.errors, { kind: 'error' });
formatted.forEach(str => {
// optionally modify the output esbuild gave me
// for example, remove the 1st line.. whatever
output += '\n ' + str;
});
console.error(output); |
@lukeed Thank you! Nice work to you and Evan in getting this implemented so quickly. Am using it myself already. |
I contributed nothing 😂 |
There's quite a bit of logic going into logging the messages, specifically the details.
Would it be possible to expose this function on the
Message
interface itself? Perhaps it only appears whenlogLevel
is silent.Specifically, I'd like to customize the "text" portion of each message & then use esbuild's formatted details.
Current
Customized
AFAIK, there's no way to catch-n-rewrite the stdout since this is
build
& esbuild writes it directly.I can (and was) reimplement the output in the JS wrapper layer, but this feels a little silly given that the code is already included.
Perhaps the usage could look something like this:
The text was updated successfully, but these errors were encountered: