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

Track usage of swc features #30297

Merged
merged 3 commits into from Oct 26, 2021
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
9 changes: 8 additions & 1 deletion packages/next/build/webpack-config.ts
Expand Up @@ -1307,7 +1307,14 @@ export default async function getBaseWebpackConfig(
minimized: true,
},
}),
!dev && !isServer && new TelemetryPlugin(),
!dev &&
!isServer &&
new TelemetryPlugin(
new Map([
['swcLoader', useSWCLoader],
['swcMinify', config.swcMinify],
])
),
].filter(Boolean as any as ExcludesFalse),
}

Expand Down
20 changes: 18 additions & 2 deletions packages/next/build/webpack/plugins/telemetry-plugin.ts
@@ -1,6 +1,11 @@
import type { webpack5 as webpack } from 'next/dist/compiled/webpack/webpack'

type Feature = 'next/image' | 'next/script' | 'next/dynamic'
type Feature =
| 'next/image'
| 'next/script'
| 'next/dynamic'
| 'swcLoader'
| 'swcMinify'

interface FeatureUsage {
featureName: Feature
Expand Down Expand Up @@ -29,6 +34,9 @@ const FEATURE_MODULE_MAP: ReadonlyMap<Feature, string> = new Map([
['next/dynamic', '/next/dynamic.js'],
])

// List of build features used in webpack configuration
const BUILD_FEATURES: Array<Feature> = ['swcLoader', 'swcMinify']

/**
* Plugin that queries the ModuleGraph to look for modules that correspond to
* certain features (e.g. next/image and next/script) and record how many times
Expand All @@ -37,7 +45,15 @@ const FEATURE_MODULE_MAP: ReadonlyMap<Feature, string> = new Map([
export class TelemetryPlugin implements webpack.WebpackPluginInstance {
private usageTracker = new Map<Feature, FeatureUsage>()

constructor() {
// Build feature usage is on/off and is known before the build starts
constructor(buildFeaturesMap: Map<Feature, boolean>) {
timneutkens marked this conversation as resolved.
Show resolved Hide resolved
for (const featureName of BUILD_FEATURES) {
this.usageTracker.set(featureName, {
featureName,
invocationCount: buildFeaturesMap.get(featureName) ? 1 : 0,
})
}

for (const featureName of FEATURE_MODULE_MAP.keys()) {
this.usageTracker.set(featureName, {
featureName,
Expand Down
2 changes: 2 additions & 0 deletions packages/next/telemetry/events/build.ts
Expand Up @@ -128,6 +128,8 @@ export type EventBuildFeatureUsage = {
| 'next/script'
| 'next/dynamic'
| 'experimental/optimizeCss'
| 'swcLoader'
| 'swcMinify'
invocationCount: number
}
export function eventBuildFeatureUsage(
Expand Down