-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Update json logger in gatsby-cli to TS #24140
Conversation
const sanitizedAction = sanitizeAction(action) | ||
|
||
process.stdout.write(JSON.stringify(sanitizedAction) + `\n`) | ||
}) |
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.
We actually want to change this module to not invoke functionality on import. So this onLogAction
should be wrapped in an exported function, which should then be executed in the parent module. Mind making these changes?
export function initializeJSONLogger() {
onLogAction(....)
}
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've changed this to named export initializeJSONLogger
import stripAnsi from "strip-ansi" | ||
import _ from "lodash" | ||
|
||
const isStringPayload = (action: ActionsUnion): action is ISetStatus => |
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.
can we get away without this action is ISetStatus
?
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 use action is ISetStatus
to filter out ISetStatus which payload is a string.
action.payload.statusText = stripAnsi(action.payload.statusText) | ||
} | ||
|
||
return action |
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 there is a functional change going on here. In the previous version, we were creating a new object and spreading values into it. This had the benefit that we weren't mutating the underlying object.
I think there is a risk here that this function in it's new state would actually be modifying values that are in redux state (thanks JS object referencing.)
Let's change this to create a new object instead of modifying the one passed in.
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 use guideline from IPC to copy new object before stripAnsi
.
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.
Thank you for this and great start! Just needs a few tweaks
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.
This looks great to me, let's merge it!
Thank you so much for contributing to our TypeScript refactor! We have more work to do and we would love to have you stay involved in our transition. Please submit more PRs! 💜
Description
This PR migrates
gatsby-cli/src/reporter/loggers/json/index.js
to TypeScript.Related Issues
Part of #21995.