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

chore(gatsby-cli): Convert reporter to TS #22252

Closed
wants to merge 3 commits into from
Closed

Conversation

ascorbic
Copy link
Contributor

@ascorbic ascorbic commented Mar 13, 2020

Description

Types the main reporter files

  • packages/gatsby-cli/src/reporter/
    • index.js
    • errors.js
    • types.js

I have switcher Reporter from being a plain object to being a class with a singleton export.

Part of #21995

@ascorbic ascorbic requested a review from a team as a code owner March 13, 2020 15:47
@ascorbic ascorbic requested a review from blainekasten March 13, 2020 15:51
@MichaelDeBoey MichaelDeBoey changed the title Type "reporter" chore(gatsby-cli): Convert reporter to TS Mar 13, 2020
format: string,
...args: unknown[]
): IStructuredError | IStructuredError[] =>
reporter.error(util.format(format, ...args))

module.exports = reporter
Copy link
Contributor

Choose a reason for hiding this comment

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

we should be changing this to a named export

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I left the export the same because it's a breaking change, and is used in so many places


/**
* Reporter module.
* @module reporter
*/
const reporter: Reporter = {
class Reporter {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the benefit of making this a class over an object?

Copy link
Contributor

@blainekasten blainekasten left a comment

Choose a reason for hiding this comment

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

This is looking really great! Just a few nit changes requested and discussions i'd like to have before approving!

@ascorbic ascorbic requested a review from blainekasten March 18, 2020 10:56
})

this.interuptActivities()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I am happy to accept this PR if you take these 2 functions out of the class. It's likely not a big deal, but we are growing the api surface of this module by putting these 2 functions on the class.

I loved your intention of removing top level side effects, but technically you haven't 😢, you just moved them. Since we instantiate this class in this file, we run the constructor on import. So it's all the same. I'm happy with that change though because it feels confined, but adding the interuptActivities and prematureEnd to the class grows the api surface and that runs the risk of someone calling those methods because they exist without it being the correct thing to do.

packages/gatsby-cli/src/reporter/index.ts Show resolved Hide resolved
@blainekasten
Copy link
Contributor

Closing in favor of #22869 💜

@blainekasten blainekasten deleted the chore/ts/reporter3 branch April 6, 2020 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants