File size: 1,126 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
  isRspack: boolean
}

export function eventCliSessionStopped(
  event: Omit<
    EventCliSessionStopped,
    'nextVersion' | 'nodeVersion' | 'isRspack'
  >
): { 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,
    isRspack: process.env.NEXT_RSPACK !== undefined,
  }
  return [{ eventName: EVENT_VERSION, payload }]
}