Skip to content

Commit

Permalink
Collect telemetry for next/future/image
Browse files Browse the repository at this point in the history
Track adoption of next/future/image and add relevant test.
  • Loading branch information
kyliau committed Jul 26, 2022
1 parent 2dda7cf commit c492519
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/next/build/webpack/plugins/telemetry-plugin.ts
Expand Up @@ -23,6 +23,7 @@ export type SWC_TARGET_TRIPLE =

export type Feature =
| 'next/image'
| 'next/future/image'
| 'next/script'
| 'next/dynamic'
| 'swcLoader'
Expand Down Expand Up @@ -59,6 +60,7 @@ interface Connection {
// Map of a feature module to the file it belongs in the next package.
const FEATURE_MODULE_MAP: ReadonlyMap<Feature, string> = new Map([
['next/image', '/next/image.js'],
['next/future/image', '/next/future/image.js'],
['next/script', '/next/script.js'],
['next/dynamic', '/next/dynamic.js'],
])
Expand Down
1 change: 1 addition & 0 deletions packages/next/telemetry/events/build.ts
Expand Up @@ -132,6 +132,7 @@ export type EventBuildFeatureUsage = {
// *before* you make changes here.
featureName:
| 'next/image'
| 'next/future/image'
| 'next/script'
| 'next/dynamic'
| 'experimental/optimizeCss'
Expand Down
5 changes: 5 additions & 0 deletions test/integration/telemetry/pages/about.js
@@ -1,4 +1,5 @@
import Image from 'next/image'
import { Image as FutureImage } from 'next/future/image'
import profilePic from '../public/small.jpg'

function About() {
Expand All @@ -12,3 +13,7 @@ function About() {
}

export default About

export function AboutFutureImage() {
return <FutureImage src={profilePic} alt="Picture of the author" />
}
12 changes: 12 additions & 0 deletions test/integration/telemetry/test/index.test.js
Expand Up @@ -837,6 +837,18 @@ describe('Telemetry CLI', () => {
},
])
})

it('emits telemetry for usage of next/future/image', async () => {
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
const featureUsageEvents = findAllEvents(stderr, 'NEXT_BUILD_FEATURE_USAGE')
expect(featureUsageEvents).toContainEqual({
featureName: 'next/future/image',
invocationCount: 1,
})
})
})

/**
Expand Down

0 comments on commit c492519

Please sign in to comment.