Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

telemetry: collect feature usage for linting during build #32022

Merged
merged 4 commits into from Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/next/build/index.ts
Expand Up @@ -243,7 +243,8 @@ export default async function build(

const ignoreESLint = Boolean(config.eslint.ignoreDuringBuilds)
const eslintCacheDir = path.join(cacheDir, 'eslint/')
if (!ignoreESLint && runLint) {
const shouldLint = !ignoreESLint && runLint
if (shouldLint) {
await nextBuildSpan
.traceChild('verify-and-lint')
.traceAsyncFn(async () => {
Expand All @@ -257,6 +258,14 @@ export default async function build(
)
})
}
const buildLintEvent: EventBuildFeatureUsage = {
featureName: 'build-lint',
invocationCount: shouldLint ? 1 : 0,
}
telemetry.record({
eventName: EVENT_BUILD_FEATURE_USAGE,
payload: buildLintEvent,
})

const buildSpinner = createSpinner({
prefixText: `${Log.prefixes.info} Creating an optimized production build`,
Expand Down
1 change: 1 addition & 0 deletions packages/next/telemetry/events/build.ts
Expand Up @@ -134,6 +134,7 @@ export type EventBuildFeatureUsage = {
| 'optimizeFonts'
| 'swcLoader'
| 'swcMinify'
| 'build-lint'
invocationCount: number
}
export function eventBuildFeatureUsage(
Expand Down
42 changes: 42 additions & 0 deletions test/integration/telemetry/test/index.test.js
Expand Up @@ -541,6 +541,46 @@ describe('Telemetry CLI', () => {
expect(event1).toMatch(/"nextEslintPluginVersion": ".*?\..*?\..*?"/)
expect(event1).toMatch(/"nextEslintPluginErrorsCount": \d{1,}/)
expect(event1).toMatch(/"nextEslintPluginWarningsCount": \d{1,}/)

const event2 = /NEXT_BUILD_FEATURE_USAGE[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop()
expect(event2).toContain(`"featureName": "build-lint"`)
expect(event2).toContain(`"invocationCount": 1`)
})

it(`emits telemetry for lint during build when '--no-lint' is specified`, async () => {
const { stderr } = await nextBuild(appDir, ['--no-lint'], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})

const event1 = /NEXT_BUILD_FEATURE_USAGE[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop()

expect(event1).toContain(`"featureName": "build-lint"`)
expect(event1).toContain(`"invocationCount": 0`)
})

it(`emits telemetry for lint during build when 'ignoreDuringBuilds' is specified`, async () => {
const nextConfig = path.join(appDir, 'next.config.js')
await fs.writeFile(
nextConfig,
`module.exports = { eslint: { ignoreDuringBuilds: true } }`
)
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
await fs.remove(nextConfig)

const event1 = /NEXT_BUILD_FEATURE_USAGE[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop()

expect(event1).toContain(`"featureName": "build-lint"`)
expect(event1).toContain(`"invocationCount": 0`)
})

it('emits telemetry for `next lint`', async () => {
Expand Down Expand Up @@ -575,6 +615,7 @@ describe('Telemetry CLI', () => {
})
const regex = /NEXT_BUILD_FEATURE_USAGE[\s\S]+?{([\s\S]+?)}/g
regex.exec(stderr).pop() // optimizeCss
regex.exec(stderr).pop() // build-lint
const optimizeFonts = regex.exec(stderr).pop()
expect(optimizeFonts).toContain(`"featureName": "optimizeFonts"`)
expect(optimizeFonts).toContain(`"invocationCount": 1`)
Expand Down Expand Up @@ -612,6 +653,7 @@ describe('Telemetry CLI', () => {
)

const regex = /NEXT_BUILD_FEATURE_USAGE[\s\S]+?{([\s\S]+?)}/g
regex.exec(stderr).pop() // build-lint
const optimizeCss = regex.exec(stderr).pop()
expect(optimizeCss).toContain(`"featureName": "experimental/optimizeCss"`)
expect(optimizeCss).toContain(`"invocationCount": 1`)
Expand Down