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): Migrate reporter to TypeScript #22869

Merged
merged 5 commits into from
Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@types/babel__code-frame": "^7.0.1",
"@types/bluebird": "^3.5.30",
"@types/cache-manager": "^2.10.2",
"@types/common-tags": "^1.8.0",
"@types/eslint": "^6.1.8",
"@types/express": "^4.17.3",
"@types/fast-levenshtein": "^0.0.1",
Expand All @@ -18,6 +19,8 @@
"@types/lodash": "^4.14.149",
"@types/node": "^12.12.30",
"@types/node-fetch": "^2.5.5",
"@types/semver": "^7.1.0",
"@types/signal-exit": "^3.0.0",
"@types/react": "^16.9.31",
"@types/stack-trace": "^0.0.29",
"@types/webpack": "^4.41.7",
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ process.on(`unhandledRejection`, reason => {
reason = new Error(util.format(reason))
}

report.panic(`UNHANDLED REJECTION`, reason)
report.panic(`UNHANDLED REJECTION`, reason as Error)
})

process.on(`uncaughtException`, error => {
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-cli/src/reporter/__tests__/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const reporter = require(`../index.js`)
const reporter = require(`../`)
const reporterActions = require(`../redux/actions`)

// TODO: report.error now DOES return something. Get rid of this spying mocking stuff
Expand Down
42 changes: 42 additions & 0 deletions packages/gatsby-cli/src/reporter/catch-exit-signals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* This module is used to catch if the user kills the gatsby process via cmd+c
* When this happens, there is some clean up logic we need to fire offf
*/
import signalExit from "signal-exit"
import { getStore } from "./redux"
import reporterActions from "./redux/actions"
import { ActivityStatuses } from "./constants"
import { reporter } from "./reporter"

const interruptActivities = (): void => {
const { activities } = getStore().getState().logs
Object.keys(activities).forEach(activityId => {
const activity = activities[activityId]
if (
activity.status === ActivityStatuses.InProgress ||
activity.status === ActivityStatuses.NotStarted
) {
reporter.completeActivity(activityId, ActivityStatuses.Interrupted)
}
})
}

export const prematureEnd = (): void => {
// hack so at least one activity is surely failed, so
// we are guaranteed to generate FAILED status
// if none of activity did explicitly fail
reporterActions.createPendingActivity({
id: `panic`,
status: ActivityStatuses.Failed,
})

interruptActivities()
}

export const catchExitSignals = (): void => {
signalExit((code, signal) => {
if (code !== 0 && signal !== `SIGINT` && signal !== `SIGTERM`)
prematureEnd()
else interruptActivities()
})
}
Loading