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

[Feature]: Support diagnostics reporting API like esbuild.formatMessages or swc HANDLER #5913

Closed
colinaaa opened this issue Mar 11, 2024 · 6 comments · Fixed by #7879
Closed
Assignees
Labels
beyond-webpack feat New feature or request

Comments

@colinaaa
Copy link
Contributor

What problem does this feature solve?

We are using esbuild as our bundler and we are trying to migrate to rspack.

esbuild has a great API esbuild.formatMessages that we use to print the compilation warnings and errors. It makes all the printed diagnostics(directly by esbuild or by our plugins) look the same.

We also made some esbuild transform plugins with swc. And we use the HANDLER API of swc a lot to print diagnostics(with a custom Emitter to print
esbuild compatible messages).

It would be nice if rspack could provide such an API so that all the ecosystems(oxc, rsbuild and third-party plugins) can make diagnostics in the same format.

What does the proposed API of configuration look like?

Rust

The swc has a great API:

use swc_core::common::errors::HANDLER;

HANDLER.with(|handler| {
  handler
    .struct_span_warn(
      n.span,
      format!("DEPRECATED: old package \"{}\" is removed", n.src.value).as_str(),
    )
    .emit()
});

Maybe rspack could provide rust API like this(in a standalone crate so than it can be used by our rust transformers).

JS

It would be nice if it has the same API as esbuild.

import * as rspack from '@rspack/core'

let formatted = await rspack.formatMessages([
  {
    text: 'This is an error',
    location: {
      file: 'app.js',
      line: 10,
      column: 4,
      length: 3,
      lineText: 'let foo = bar',
    },
  },
], {
  kind: 'error',
  color: false,
  terminalWidth: 100,
})

console.log(formatted.join('\n'))

It also LGTM if rspack uses a different data structure that is more rust-style :)

@colinaaa colinaaa added feat New feature or request pending triage The issue/PR is currently untouched. labels Mar 11, 2024
@colinaaa colinaaa changed the title [Feature]: Support diagnostics reporting API like esbuild.formatMessages or swc HANDLER [Feature]: Support diagnostics reporting API like esbuild.formatMessages or swc HANDLER Mar 11, 2024
@LingyuCoder
Copy link
Collaborator

cc @h-a-n-a

@h-a-n-a
Copy link
Collaborator

h-a-n-a commented Mar 18, 2024

Thanks for reaching out! Currently, we do have some APIs for internal error reportings. However, we haven't expose these as stable API instead its an internal API. We've put this into consideration ;-) More followups will be provided as soon as Rspack 1.0 is released.

@h-a-n-a h-a-n-a removed the pending triage The issue/PR is currently untouched. label Mar 18, 2024
@h-a-n-a h-a-n-a self-assigned this Mar 18, 2024
Copy link

stale bot commented May 17, 2024

This issue has been automatically marked as stale because it has not had recent activity. If this issue is still affecting you, please leave any comment (for example, "bump"). We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

@stale stale bot added the stale label May 17, 2024
@h-a-n-a
Copy link
Collaborator

h-a-n-a commented Jun 3, 2024

bump

@stale stale bot removed the stale label Jun 3, 2024
Copy link

stale bot commented Aug 2, 2024

This issue has been automatically marked as stale because it has not had recent activity. If this issue is still affecting you, please leave any comment (for example, "bump"). We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

@stale stale bot added the stale label Aug 2, 2024
@colinaaa
Copy link
Contributor Author

colinaaa commented Aug 3, 2024

bump

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beyond-webpack feat New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants