Skip to content

Commit

Permalink
telemetry: track usage of 'experimental/nextScriptWorkers'
Browse files Browse the repository at this point in the history
  • Loading branch information
housseindjirdeh committed May 11, 2022
1 parent 22c0b65 commit 5c8555b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/next/build/index.ts
Expand Up @@ -1523,6 +1523,10 @@ export default async function build(
featureName: 'experimental/optimizeCss',
invocationCount: config.experimental.optimizeCss ? 1 : 0,
},
{
featureName: 'experimental/nextScriptWorkers',
invocationCount: config.experimental.nextScriptWorkers ? 1 : 0,
},
{
featureName: 'optimizeFonts',
invocationCount: config.optimizeFonts ? 1 : 0,
Expand Down
1 change: 1 addition & 0 deletions packages/next/telemetry/events/build.ts
Expand Up @@ -135,6 +135,7 @@ export type EventBuildFeatureUsage = {
| 'next/script'
| 'next/dynamic'
| 'experimental/optimizeCss'
| 'experimental/nextScriptWorkers'
| 'optimizeFonts'
| 'swcLoader'
| 'swcMinify'
Expand Down
5 changes: 5 additions & 0 deletions test/integration/telemetry/next.config.next-script-workers
@@ -0,0 +1,5 @@
module.exports = {
experimental: {
nextScriptWorkers: true
}
}
28 changes: 28 additions & 0 deletions test/integration/telemetry/test/index.test.js
Expand Up @@ -647,6 +647,7 @@ describe('Telemetry CLI', () => {
})
const regex = /NEXT_BUILD_FEATURE_USAGE[\s\S]+?{([\s\S]+?)}/g
regex.exec(stderr).pop() // optimizeCss
regex.exec(stderr).pop() // nextScriptWorkers
regex.exec(stderr).pop() // build-lint
const optimizeFonts = regex.exec(stderr).pop()
expect(optimizeFonts).toContain(`"featureName": "optimizeFonts"`)
Expand Down Expand Up @@ -704,6 +705,7 @@ describe('Telemetry CLI', () => {

const regex = /NEXT_BUILD_FEATURE_USAGE[\s\S]+?{([\s\S]+?)}/g
regex.exec(stderr).pop() // optimizeCss
regex.exec(stderr).pop() // nextScriptWorkers
regex.exec(stderr).pop() // build-lint
regex.exec(stderr).pop() // optimizeFonts
const swcLoader = regex.exec(stderr).pop()
Expand Down Expand Up @@ -761,6 +763,32 @@ describe('Telemetry CLI', () => {
expect(optimizeCss).toContain(`"invocationCount": 1`)
})

it('emits telemetry for usage of `nextScriptWorkers`', async () => {
await fs.rename(
path.join(appDir, 'next.config.next-script-workers'),
path.join(appDir, 'next.config.js')
)

const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})

await fs.rename(
path.join(appDir, 'next.config.js'),
path.join(appDir, 'next.config.next-script-workers')
)

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

it('emits telemetry for usage of _middleware', async () => {
await fs.writeFile(
path.join(appDir, 'pages/ssg/_middleware.js'),
Expand Down

0 comments on commit 5c8555b

Please sign in to comment.