rsnext/packages/next/telemetry/events/session-stopped.ts
JJ Kasper 2a9e2f18e3
Update dev process exit handling (#42367)
Follow-up to https://github.com/vercel/next.js/pull/42255

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2022-11-02 11:09:56 -07:00

35 lines
1,021 B
TypeScript

const EVENT_VERSION = 'NEXT_CLI_SESSION_STOPPED'
export type EventCliSessionStopped = {
cliCommand: string
nextVersion: string
nodeVersion: string
turboFlag?: boolean | null
durationMilliseconds?: number | null
pagesDir?: boolean
appDir?: boolean
}
export function eventCliSession(
event: Omit<EventCliSessionStopped, 'nextVersion' | 'nodeVersion'>
): { eventName: string; payload: EventCliSessionStopped }[] {
// This should be an invariant, if it fails our build tooling is broken.
if (typeof process.env.__NEXT_VERSION !== 'string') {
return []
}
const payload: EventCliSessionStopped = {
nextVersion: process.env.__NEXT_VERSION,
nodeVersion: process.version,
cliCommand: event.cliCommand,
durationMilliseconds: event.durationMilliseconds,
...(typeof event.turboFlag !== 'undefined'
? {
turboFlag: !!event.turboFlag,
}
: {}),
pagesDir: event.pagesDir,
appDir: event.appDir,
}
return [{ eventName: EVENT_VERSION, payload }]
}