2020-02-04 19:55:43 +01:00
|
|
|
const REGEXP_DIRECTORY_DUNDER = /[\\/]__[^\\/]+(?<![\\/]__(?:tests|mocks))__[\\/]/i
|
|
|
|
const REGEXP_DIRECTORY_TESTS = /[\\/]__(tests|mocks)__[\\/]/i
|
|
|
|
const REGEXP_FILE_TEST = /\.(?:spec|test)\.[^.]+$/i
|
|
|
|
|
2019-09-05 02:31:35 +02:00
|
|
|
const EVENT_BUILD_DURATION = 'NEXT_BUILD_COMPLETED'
|
|
|
|
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 {
|
2019-08-29 18:43:06 +02:00
|
|
|
eventName: EVENT_BUILD_DURATION,
|
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
|
|
|
}
|
|
|
|
|
2019-09-05 02:31:35 +02:00
|
|
|
const EVENT_BUILD_OPTIMIZE = 'NEXT_BUILD_OPTIMIZED'
|
|
|
|
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
|
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 {
|
2019-08-29 18:43:06 +02:00
|
|
|
eventName: EVENT_BUILD_OPTIMIZE,
|
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
|
|
|
}
|