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

Add telemetry for @next/font #42579

Merged
merged 7 commits into from Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
21 changes: 20 additions & 1 deletion packages/next/build/webpack/plugins/telemetry-plugin.ts
Expand Up @@ -24,6 +24,8 @@ export type Feature =
| 'next/legacy/image'
| 'next/script'
| 'next/dynamic'
| '@next/font/google'
| '@next/font/local'
| 'swcLoader'
| 'swcMinify'
| 'swcRelay'
Expand Down Expand Up @@ -64,6 +66,10 @@ const FEATURE_MODULE_MAP: ReadonlyMap<Feature, string> = new Map([
['next/script', '/next/script.js'],
['next/dynamic', '/next/dynamic.js'],
])
const FEATURE_MODULE_REGEXP_MAP: ReadonlyMap<Feature, RegExp> = new Map([
['@next/font/google', /\/@next\/font\/google\/target.css?.+$/],
['@next/font/local', /\/@next\/font\/local\/target.css?.+$/],
])

// List of build features used in webpack configuration
const BUILD_FEATURES: Array<Feature> = [
Expand Down Expand Up @@ -101,8 +107,14 @@ function findFeatureInModule(module: Module): Feature | undefined {
if (module.type !== 'javascript/auto') {
return
}
const normalizedIdentifier = module.identifier().replace(/\\/g, '/')
for (const [feature, path] of FEATURE_MODULE_MAP) {
if (module.identifier().replace(/\\/g, '/').endsWith(path)) {
if (normalizedIdentifier.endsWith(path)) {
return feature
}
}
for (const [feature, regexp] of FEATURE_MODULE_REGEXP_MAP) {
if (regexp.test(normalizedIdentifier)) {
return feature
}
}
Expand Down Expand Up @@ -152,6 +164,13 @@ export class TelemetryPlugin implements webpack.WebpackPluginInstance {
invocationCount: 0,
})
}

for (const featureName of FEATURE_MODULE_REGEXP_MAP.keys()) {
this.usageTracker.set(featureName, {
featureName,
invocationCount: 0,
})
}
}

apply(compiler: webpack.Compiler): void {
Expand Down
2 changes: 2 additions & 0 deletions packages/next/telemetry/events/build.ts
Expand Up @@ -136,6 +136,8 @@ export type EventBuildFeatureUsage = {
| 'next/future/image'
| 'next/script'
| 'next/dynamic'
| '@next/font/google'
| '@next/font/local'
| 'experimental/optimizeCss'
| 'experimental/nextScriptWorkers'
| 'optimizeFonts'
Expand Down