2021-10-05 21:31:48 +02:00
|
|
|
import { TelemetryPlugin } from '../../build/webpack/plugins/telemetry-plugin'
|
|
|
|
|
2021-08-17 09:18:08 +02:00
|
|
|
const REGEXP_DIRECTORY_DUNDER =
|
|
|
|
/[\\/]__[^\\/]+(?<![\\/]__(?:tests|mocks))__[\\/]/i
|
2020-02-04 19:55:43 +01:00
|
|
|
const REGEXP_DIRECTORY_TESTS = /[\\/]__(tests|mocks)__[\\/]/i
|
|
|
|
const REGEXP_FILE_TEST = /\.(?:spec|test)\.[^.]+$/i
|
|
|
|
|
2021-05-04 10:41:01 +02:00
|
|
|
const EVENT_TYPE_CHECK_COMPLETED = 'NEXT_TYPE_CHECK_COMPLETED'
|
|
|
|
type EventTypeCheckCompleted = {
|
|
|
|
durationInSeconds: number
|
|
|
|
typescriptVersion: string | null
|
|
|
|
inputFilesCount?: number
|
|
|
|
totalFilesCount?: number
|
|
|
|
incremental?: boolean
|
|
|
|
}
|
|
|
|
|
2021-08-17 09:18:08 +02:00
|
|
|
export function eventTypeCheckCompleted(event: EventTypeCheckCompleted): {
|
|
|
|
eventName: string
|
|
|
|
payload: EventTypeCheckCompleted
|
|
|
|
} {
|
2021-05-04 10:41:01 +02:00
|
|
|
return {
|
|
|
|
eventName: EVENT_TYPE_CHECK_COMPLETED,
|
|
|
|
payload: event,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-15 03:31:40 +02:00
|
|
|
const EVENT_LINT_CHECK_COMPLETED = 'NEXT_LINT_CHECK_COMPLETED'
|
|
|
|
export type EventLintCheckCompleted = {
|
|
|
|
durationInSeconds: number
|
|
|
|
eslintVersion: string | null
|
|
|
|
lintedFilesCount?: number
|
|
|
|
lintFix?: boolean
|
|
|
|
buildLint?: boolean
|
|
|
|
nextEslintPluginVersion?: string | null
|
|
|
|
nextEslintPluginErrorsCount?: number
|
|
|
|
nextEslintPluginWarningsCount?: number
|
|
|
|
}
|
|
|
|
|
2021-08-17 09:18:08 +02:00
|
|
|
export function eventLintCheckCompleted(event: EventLintCheckCompleted): {
|
|
|
|
eventName: string
|
|
|
|
payload: EventLintCheckCompleted
|
|
|
|
} {
|
2021-06-15 03:31:40 +02:00
|
|
|
return {
|
|
|
|
eventName: EVENT_LINT_CHECK_COMPLETED,
|
|
|
|
payload: event,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-04 10:41:01 +02:00
|
|
|
const EVENT_BUILD_COMPLETED = 'NEXT_BUILD_COMPLETED'
|
2019-09-05 02:31:35 +02:00
|
|
|
type EventBuildCompleted = {
|
2019-08-29 18:43:06 +02:00
|
|
|
durationInSeconds: number
|
2019-09-05 02:31:35 +02:00
|
|
|
totalPageCount: number
|
2020-02-04 19:55:43 +01:00
|
|
|
hasDunderPages: boolean
|
|
|
|
hasTestPages: boolean
|
2019-08-29 18:43:06 +02:00
|
|
|
}
|
|
|
|
|
2020-02-04 19:55:43 +01:00
|
|
|
export function eventBuildCompleted(
|
|
|
|
pagePaths: string[],
|
|
|
|
event: Omit<
|
|
|
|
EventBuildCompleted,
|
|
|
|
'totalPageCount' | 'hasDunderPages' | 'hasTestPages'
|
|
|
|
>
|
2019-10-10 19:18:07 +02:00
|
|
|
): { eventName: string; payload: EventBuildCompleted } {
|
|
|
|
return {
|
2021-05-04 10:41:01 +02:00
|
|
|
eventName: EVENT_BUILD_COMPLETED,
|
2020-02-04 19:55:43 +01:00
|
|
|
payload: {
|
|
|
|
...event,
|
|
|
|
totalPageCount: pagePaths.length,
|
2020-05-18 21:24:37 +02:00
|
|
|
hasDunderPages: pagePaths.some((path) =>
|
2020-02-04 19:55:43 +01:00
|
|
|
REGEXP_DIRECTORY_DUNDER.test(path)
|
|
|
|
),
|
|
|
|
hasTestPages: pagePaths.some(
|
2020-05-18 21:24:37 +02:00
|
|
|
(path) =>
|
|
|
|
REGEXP_DIRECTORY_TESTS.test(path) || REGEXP_FILE_TEST.test(path)
|
2020-02-04 19:55:43 +01:00
|
|
|
),
|
|
|
|
},
|
2019-10-10 19:18:07 +02:00
|
|
|
}
|
2019-08-29 18:43:06 +02:00
|
|
|
}
|
|
|
|
|
2021-05-04 10:41:01 +02:00
|
|
|
const EVENT_BUILD_OPTIMIZED = 'NEXT_BUILD_OPTIMIZED'
|
2019-09-05 02:31:35 +02:00
|
|
|
type EventBuildOptimized = {
|
2019-08-29 18:43:06 +02:00
|
|
|
durationInSeconds: number
|
|
|
|
totalPageCount: number
|
2019-09-05 02:31:35 +02:00
|
|
|
staticPageCount: number
|
2020-03-03 01:01:12 +01:00
|
|
|
staticPropsPageCount: number
|
|
|
|
serverPropsPageCount: number
|
2019-09-05 02:31:35 +02:00
|
|
|
ssrPageCount: number
|
2020-02-04 16:46:22 +01:00
|
|
|
hasDunderPages: boolean
|
|
|
|
hasTestPages: boolean
|
2020-02-04 21:10:40 +01:00
|
|
|
hasStatic404: boolean
|
2020-05-20 20:44:39 +02:00
|
|
|
hasReportWebVitals: boolean
|
2020-10-27 14:46:18 +01:00
|
|
|
headersCount: number
|
|
|
|
rewritesCount: number
|
|
|
|
redirectsCount: number
|
2021-03-24 17:50:16 +01:00
|
|
|
headersWithHasCount: number
|
|
|
|
rewritesWithHasCount: number
|
|
|
|
redirectsWithHasCount: number
|
2019-08-29 18:43:06 +02:00
|
|
|
}
|
|
|
|
|
2019-10-10 19:18:07 +02:00
|
|
|
export function eventBuildOptimize(
|
2020-02-04 16:46:22 +01:00
|
|
|
pagePaths: string[],
|
|
|
|
event: Omit<
|
|
|
|
EventBuildOptimized,
|
|
|
|
'totalPageCount' | 'hasDunderPages' | 'hasTestPages'
|
|
|
|
>
|
2019-10-10 19:18:07 +02:00
|
|
|
): { eventName: string; payload: EventBuildOptimized } {
|
|
|
|
return {
|
2021-05-04 10:41:01 +02:00
|
|
|
eventName: EVENT_BUILD_OPTIMIZED,
|
2020-02-04 16:46:22 +01:00
|
|
|
payload: {
|
|
|
|
...event,
|
|
|
|
totalPageCount: pagePaths.length,
|
2020-05-18 21:24:37 +02:00
|
|
|
hasDunderPages: pagePaths.some((path) =>
|
2020-02-04 16:46:22 +01:00
|
|
|
REGEXP_DIRECTORY_DUNDER.test(path)
|
|
|
|
),
|
|
|
|
hasTestPages: pagePaths.some(
|
2020-05-18 21:24:37 +02:00
|
|
|
(path) =>
|
|
|
|
REGEXP_DIRECTORY_TESTS.test(path) || REGEXP_FILE_TEST.test(path)
|
2020-02-04 16:46:22 +01:00
|
|
|
),
|
|
|
|
},
|
2019-10-10 19:18:07 +02:00
|
|
|
}
|
2019-08-29 18:43:06 +02:00
|
|
|
}
|
2021-10-05 21:31:48 +02:00
|
|
|
|
|
|
|
const EVENT_BUILD_FEATURE_USAGE = 'NEXT_BUILD_FEATURE_USAGE'
|
|
|
|
type EventBuildFeatureUsage = {
|
|
|
|
featureName: string
|
|
|
|
invocationCount: number
|
|
|
|
}
|
|
|
|
export function eventBuildFeatureUsage(
|
|
|
|
telemetryPlugin: TelemetryPlugin
|
|
|
|
): Array<{ eventName: string; payload: EventBuildFeatureUsage }> {
|
|
|
|
return telemetryPlugin.usages().map(({ featureName, invocationCount }) => ({
|
|
|
|
eventName: EVENT_BUILD_FEATURE_USAGE,
|
|
|
|
payload: {
|
|
|
|
featureName,
|
|
|
|
invocationCount,
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
}
|