Skip to content

Commit

Permalink
chore(gatsby-telemetry): Migrate flush to TypeScript (#25886)
Browse files Browse the repository at this point in the history
  • Loading branch information
blainekasten authored and KyleAMathews committed Jul 29, 2020
1 parent 0adde08 commit b077f99
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
19 changes: 19 additions & 0 deletions packages/gatsby-telemetry/src/create-flush.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const { join } = require(`path`)
const { fork } = require(`child_process`)

export function createFlush(isTrackingEnabled: boolean): () => Promise<void> {
return async function flush(): Promise<void> {
if (!isTrackingEnabled) {
return
}

// Submit events on background w/o blocking the main process
// nor relying on it's lifecycle
const forked = fork(join(__dirname, `send.js`), {
detached: true,
stdio: `ignore`,
execArgv: [],
})
forked.unref()
}
}
17 changes: 0 additions & 17 deletions packages/gatsby-telemetry/src/flush.js

This file was deleted.

3 changes: 2 additions & 1 deletion packages/gatsby-telemetry/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { AnalyticsTracker, IAggregateStats } from "./telemetry"
import * as express from "express"
import { createFlush } from "./create-flush"

const instance = new AnalyticsTracker()

const flush = require(`./flush`)(instance.isTrackingEnabled())
const flush = createFlush(instance.isTrackingEnabled())

process.on(`exit`, flush)

Expand Down

0 comments on commit b077f99

Please sign in to comment.