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

Add stream parsing and processing support #4

Open
Gelio opened this issue Nov 12, 2020 · 4 comments
Open

Add stream parsing and processing support #4

Gelio opened this issue Nov 12, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@Gelio
Copy link
Owner

Gelio commented Nov 12, 2020

At the moment, the CLI buffers all the input and waits for the end of input before proceeding with work (parsing the TSC errors).

This could be improved to let go of buffering and parse input line by line, as it comes.

Memory usage 📝

The memory usage would probably stay the same, as the CLI captures rawErrorLines for each error, to be able to later display them.

If the raw error lines were only saved for the valid TSC errors (as only those are displayed by the CLI), the memory usage would probably go down. If needed, that will be handled in another issue.

Speed 🐎

The CLI would probably be a bit more performant because parsing of lines would happen as they arrive, compared to waiting for the input to end and then parsing.

Challenges

Parsing the errors line-by-line 👀

Change the parser (parseTscErrors) to be stateful. I imagine the line processing code would look similar to:

const tscErrorParser = createTscErrorParser(); // (could be a class)

rl.on('line', line => tscErrorParser.parseLine(line));
rl.on('end', () => {
  const tscErrors = tscErrorParser.getErrors();
  
  // run the rest of the program with tscErrors
});

Processing errors one-by-one 🎰

The idea can be enhanced further. The previous approach parses errors line-by-line but processes them all at once.

We could process those errors one-by-one. The pseudocode would look like so:

const tscErrorParser = createTscErrorParser();

rl.on('line', line => tscErrorParser.parseLine(line));

const validTscErrors = [];
const ignoredTscErrors = [];
const tscErrorsThatCouldBeIgnored = [];

tscErrorParser.on('error', (tscError) => {
  classifyTscError(tscError, validTscErrors, ignoredTscErrors, tscErrorsThatCouldBeIgnored);
});

rl.on('end', () => {
  // continue with the rest of the program, using the arrays from above:
  // validTscErrors, ignoredTscErrors, tscErrorsThatCouldBeIgnored
});

We could use some kind of EventEmitter or Observable in tscErrorParser when notifying about a new error being parsed.

@nwetzel22
Copy link

@Gelio Any chance I can get permission to push a feature branch up for this so you can review it?

@Gelio
Copy link
Owner Author

Gelio commented Mar 12, 2023

I think the usual workflow for contributing to open source is:

  1. Fork the repo
  2. Push the branch to your fork
  3. Create a cross-repo pull request (you will see a button to do that when you go to your repo right after you push)

This is how you can contribute to a repository without having explicit permissions to modify the original repository. Let me know if that does not work for you

@nwetzel22
Copy link

Ah okay. Thanks for the tip. I just created the PR: #15.

@Gelio
Copy link
Owner Author

Gelio commented Mar 12, 2023

Awesome! Let's move the discussion about the implementation there

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

No branches or pull requests

2 participants