From 6f22535d1f75b53aeadd259de101c2c56bbe8ff7 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Tue, 20 Apr 2021 16:46:40 +0200 Subject: [PATCH] Add event for webpack 5 usage (#24222) --- packages/next/build/index.ts | 2 ++ packages/next/export/index.ts | 1 + packages/next/server/hot-reloader.ts | 2 ++ packages/next/server/next-dev-server.ts | 1 + packages/next/telemetry/events/version.ts | 2 ++ 5 files changed, 8 insertions(+) diff --git a/packages/next/build/index.ts b/packages/next/build/index.ts index 5ec1662b980084..019c22cbc20e05 100644 --- a/packages/next/build/index.ts +++ b/packages/next/build/index.ts @@ -90,6 +90,7 @@ import getBaseWebpackConfig from './webpack-config' import { PagesManifest } from './webpack/plugins/pages-manifest-plugin' import { writeBuildId } from './write-build-id' import { normalizeLocalePath } from '../next-server/lib/i18n/normalize-locale-path' +import { isWebpack5 } from 'next/dist/compiled/webpack/webpack' const staticCheckWorker = require.resolve('./utils') @@ -169,6 +170,7 @@ export default async function build( telemetry.record( eventCliSession(PHASE_PRODUCTION_BUILD, dir, { + webpackVersion: isWebpack5 ? 5 : 4, cliCommand: 'build', isSrcDir: path.relative(dir, pagesDir!).startsWith('src'), hasNowJson: !!(await findUp('now.json', { cwd: dir })), diff --git a/packages/next/export/index.ts b/packages/next/export/index.ts index 13177a4a0510ad..7d8cc3fca10349 100644 --- a/packages/next/export/index.ts +++ b/packages/next/export/index.ts @@ -161,6 +161,7 @@ export default async function exportApp( if (telemetry) { telemetry.record( eventCliSession(PHASE_EXPORT, distDir, { + webpackVersion: null, cliCommand: 'export', isSrcDir: null, hasNowJson: !!(await findUp('now.json', { cwd: dir })), diff --git a/packages/next/server/hot-reloader.ts b/packages/next/server/hot-reloader.ts index c13db0cec19aeb..44d1f3d9cdbeaf 100644 --- a/packages/next/server/hot-reloader.ts +++ b/packages/next/server/hot-reloader.ts @@ -144,6 +144,7 @@ export default class HotReloader { private previewProps: __ApiPreviewProps private watcher: any private rewrites: CustomRoutes['rewrites'] + public isWebpack5: any constructor( dir: string, @@ -173,6 +174,7 @@ export default class HotReloader { this.config = config this.previewProps = previewProps this.rewrites = rewrites + this.isWebpack5 = isWebpack5 } public async run( diff --git a/packages/next/server/next-dev-server.ts b/packages/next/server/next-dev-server.ts index 85979fecc73ab8..725dd63325035e 100644 --- a/packages/next/server/next-dev-server.ts +++ b/packages/next/server/next-dev-server.ts @@ -308,6 +308,7 @@ export default class DevServer extends Server { const telemetry = new Telemetry({ distDir: this.distDir }) telemetry.record( eventCliSession(PHASE_DEVELOPMENT_SERVER, this.distDir, { + webpackVersion: this.hotReloader.isWebpack5 ? 5 : 4, cliCommand: 'dev', isSrcDir: relative(this.dir, this.pagesDir!).startsWith('src'), hasNowJson: !!(await findUp('now.json', { cwd: this.dir })), diff --git a/packages/next/telemetry/events/version.ts b/packages/next/telemetry/events/version.ts index 1a8fdb403d6854..c05675e08d6b87 100644 --- a/packages/next/telemetry/events/version.ts +++ b/packages/next/telemetry/events/version.ts @@ -32,6 +32,7 @@ type EventCliSessionStarted = { imageLoader: string | null trailingSlashEnabled: boolean reactStrictMode: boolean + webpackVersion: number | null } function hasBabelConfig(dir: string): boolean { @@ -138,6 +139,7 @@ export function eventCliSession( imageLoader: images?.loader, trailingSlashEnabled: !!userConfiguration?.trailingSlash, reactStrictMode: !!userConfiguration?.reactStrictMode, + webpackVersion: event.webpackVersion || null, } return [{ eventName: EVENT_VERSION, payload }] }