Unverified Commit a20bcfbb authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Development: Don't load Babel when it's not used (#83619)

## What?

Currently Babel always gets loaded in order to check for a babel config.
This event is no longer that useful to track so removing it in favor of
performance.
parent 22bd9dec
...@@ -1051,7 +1051,7 @@ export default async function build( ...@@ -1051,7 +1051,7 @@ export default async function build(
const hasPublicDir = existsSync(publicDir) const hasPublicDir = existsSync(publicDir)
telemetry.record( telemetry.record(
eventCliSession(dir, config, { eventCliSession(config, {
webpackVersion: 5, webpackVersion: 5,
cliCommand: 'build', cliCommand: 'build',
isSrcDir, isSrcDir,
......
...@@ -100,7 +100,7 @@ async function exportAppImpl( ...@@ -100,7 +100,7 @@ async function exportAppImpl(
if (telemetry) { if (telemetry) {
telemetry.record( telemetry.record(
eventCliSession(distDir, nextConfig, { eventCliSession(nextConfig, {
webpackVersion: null, webpackVersion: null,
cliCommand: 'export', cliCommand: 'export',
isSrcDir: null, isSrcDir: null,
......
...@@ -1193,20 +1193,16 @@ export async function setupDevBundler(opts: SetupOpts) { ...@@ -1193,20 +1193,16 @@ export async function setupDevBundler(opts: SetupOpts) {
}) })
opts.telemetry.record( opts.telemetry.record(
eventCliSession( eventCliSession(opts.nextConfig, {
path.join(opts.dir, opts.nextConfig.distDir), webpackVersion: 5,
opts.nextConfig, isSrcDir,
{ turboFlag: !!opts.turbo,
webpackVersion: 5, cliCommand: 'dev',
isSrcDir, appDir: !!opts.appDir,
turboFlag: !!opts.turbo, pagesDir: !!opts.pagesDir,
cliCommand: 'dev', isCustomServer: !!opts.isCustomServer,
appDir: !!opts.appDir, hasNowJson: !!(await findUp('now.json', { cwd: opts.dir })),
pagesDir: !!opts.pagesDir, })
isCustomServer: !!opts.isCustomServer,
hasNowJson: !!(await findUp('now.json', { cwd: opts.dir })),
}
)
) )
// Track build features for dev server here: // Track build features for dev server here:
......
import type { NextConfigComplete } from '../../server/config-shared' import type { NextConfigComplete } from '../../server/config-shared'
import path from 'path'
const EVENT_VERSION = 'NEXT_CLI_SESSION_STARTED' const EVENT_VERSION = 'NEXT_CLI_SESSION_STARTED'
...@@ -43,28 +42,7 @@ type EventCliSessionStarted = { ...@@ -43,28 +42,7 @@ type EventCliSessionStarted = {
reactCompilerPanicThreshold: string | null reactCompilerPanicThreshold: string | null
} }
function hasBabelConfig(dir: string): boolean {
try {
const noopFile = path.join(dir, 'noop.js')
const res = (
require('next/dist/compiled/babel/core') as typeof import('next/dist/compiled/babel/core')
).loadPartialConfig({
cwd: dir,
filename: noopFile,
sourceFileName: noopFile,
}) as any
const isForTooling =
res.options?.presets?.every(
(e: any) => e?.file?.request === 'next/babel'
) && res.options?.plugins?.length === 0
return res.hasFilesystemConfig() && !isForTooling
} catch {
return false
}
}
export function eventCliSession( export function eventCliSession(
dir: string,
nextConfig: NextConfigComplete, nextConfig: NextConfigComplete,
event: Omit< event: Omit<
EventCliSessionStarted, EventCliSessionStarted,
...@@ -116,7 +94,7 @@ export function eventCliSession( ...@@ -116,7 +94,7 @@ export function eventCliSession(
hasNextConfig: nextConfig.configOrigin !== 'default', hasNextConfig: nextConfig.configOrigin !== 'default',
buildTarget: 'default', buildTarget: 'default',
hasWebpackConfig: typeof nextConfig?.webpack === 'function', hasWebpackConfig: typeof nextConfig?.webpack === 'function',
hasBabelConfig: hasBabelConfig(dir), hasBabelConfig: false,
imageEnabled: !!images, imageEnabled: !!images,
imageFutureEnabled: !!images, imageFutureEnabled: !!images,
basePathEnabled: !!nextConfig?.basePath, basePathEnabled: !!nextConfig?.basePath,
......
...@@ -236,7 +236,7 @@ describe('Telemetry CLI', () => { ...@@ -236,7 +236,7 @@ describe('Telemetry CLI', () => {
expect(event).toMatch(/"hasNextConfig": false/) expect(event).toMatch(/"hasNextConfig": false/)
expect(event).toMatch(/"buildTarget": "default"/) expect(event).toMatch(/"buildTarget": "default"/)
expect(event).toMatch(/"hasWebpackConfig": false/) expect(event).toMatch(/"hasWebpackConfig": false/)
expect(event).toMatch(/"hasBabelConfig": true/) expect(event).toMatch(/"hasBabelConfig": false/)
}) })
it('cli session: package.json custom babel config (plugin)', async () => { it('cli session: package.json custom babel config (plugin)', async () => {
...@@ -262,7 +262,7 @@ describe('Telemetry CLI', () => { ...@@ -262,7 +262,7 @@ describe('Telemetry CLI', () => {
expect(event).toMatch(/"hasNextConfig": false/) expect(event).toMatch(/"hasNextConfig": false/)
expect(event).toMatch(/"buildTarget": "default"/) expect(event).toMatch(/"buildTarget": "default"/)
expect(event).toMatch(/"hasWebpackConfig": false/) expect(event).toMatch(/"hasWebpackConfig": false/)
expect(event).toMatch(/"hasBabelConfig": true/) expect(event).toMatch(/"hasBabelConfig": false/)
}) })
it('cli session: custom babel config (preset)', async () => { it('cli session: custom babel config (preset)', async () => {
...@@ -288,7 +288,7 @@ describe('Telemetry CLI', () => { ...@@ -288,7 +288,7 @@ describe('Telemetry CLI', () => {
expect(event).toMatch(/"hasNextConfig": false/) expect(event).toMatch(/"hasNextConfig": false/)
expect(event).toMatch(/"buildTarget": "default"/) expect(event).toMatch(/"buildTarget": "default"/)
expect(event).toMatch(/"hasWebpackConfig": false/) expect(event).toMatch(/"hasWebpackConfig": false/)
expect(event).toMatch(/"hasBabelConfig": true/) expect(event).toMatch(/"hasBabelConfig": false/)
}) })
it('cli session: next config with webpack', async () => { it('cli session: next config with webpack', async () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment