Unverified Commit 45d8c93f authored by Joseph's avatar Joseph Committed by GitHub

Fix/next info experimental analyze with graph css chunking (#95542)

Fixes: https://github.com/vercel/next.js/issues/95530

- Make sure analyze sets `process.env.TURBOPACK ??= '1'`
- Gate the validation - do not run it for `next info` phase

To be honest, I am not sure about the unit test, I had also modified
`test/e2e/next-analyze/next.config.js` to include the `cssChunking`
graph option, but didn't feel like it was the right direction.

Just minimally added a unit test for the regression.
parent f51577ae
...@@ -43,6 +43,9 @@ export default async function analyze({ ...@@ -43,6 +43,9 @@ export default async function analyze({
port = 4000, port = 4000,
}: AnalyzeOptions): Promise<void> { }: AnalyzeOptions): Promise<void> {
try { try {
// analyze is Turbopack-only. Mirror what parseBundlerArgs does for build/dev
// so every process.env.TURBOPACK consumer in this run agrees with the bundler choice.
process.env.TURBOPACK ??= '1'
const config: NextConfigComplete = await loadConfig(PHASE_ANALYZE, dir, { const config: NextConfigComplete = await loadConfig(PHASE_ANALYZE, dir, {
silent: false, silent: false,
reactProductionProfiling, reactProductionProfiling,
......
import { PHASE_PRODUCTION_BUILD } from '../api/constants' import { PHASE_INFO, PHASE_PRODUCTION_BUILD } from '../api/constants'
describe('loadConfig', () => { describe('loadConfig', () => {
let loadConfig: typeof import('./config').default let loadConfig: typeof import('./config').default
...@@ -233,4 +233,13 @@ describe('loadConfig', () => { ...@@ -233,4 +233,13 @@ describe('loadConfig', () => {
expect(result.cacheHandlers?.['abc-def']).toBeDefined() expect(result.cacheHandlers?.['abc-def']).toBeDefined()
}) })
}) })
describe('experimental.cssChunking bundler validation', () => {
it('should not validate `cssChunking` during `next info`', async () => {
const result = await loadConfig(PHASE_INFO, __dirname, {
customConfig: { experimental: { cssChunking: 'graph' } },
})
expect(result.experimental.cssChunking).toBe('graph')
})
})
}) })
...@@ -10,6 +10,7 @@ import { ...@@ -10,6 +10,7 @@ import {
PHASE_EXPORT, PHASE_EXPORT,
PHASE_PRODUCTION_BUILD, PHASE_PRODUCTION_BUILD,
PHASE_PRODUCTION_SERVER, PHASE_PRODUCTION_SERVER,
PHASE_INFO,
type PHASE_TYPE, type PHASE_TYPE,
} from '../shared/lib/constants' } from '../shared/lib/constants'
import { import {
...@@ -489,7 +490,7 @@ function assignDefaultsAndValidate( ...@@ -489,7 +490,7 @@ function assignDefaultsAndValidate(
// Turbopack-only; strict mode and `false` (single-chunk-per-module) are webpack-only. // Turbopack-only; strict mode and `false` (single-chunk-per-module) are webpack-only.
// Only validate during build/dev — `next start` doesn't pick a bundler and would otherwise // Only validate during build/dev — `next start` doesn't pick a bundler and would otherwise
// see `process.env.TURBOPACK` unset and reject a valid `cssChunking: "graph"` config. // see `process.env.TURBOPACK` unset and reject a valid `cssChunking: "graph"` config.
if (phase !== PHASE_PRODUCTION_SERVER) { if (phase !== PHASE_PRODUCTION_SERVER && phase !== PHASE_INFO) {
const cssChunkingValue = result.experimental.cssChunking const cssChunkingValue = result.experimental.cssChunking
const cssChunkingMode = resolveCssChunkingMode(cssChunkingValue) const cssChunkingMode = resolveCssChunkingMode(cssChunkingValue)
if (cssChunkingMode === 'graph' && !process.env.TURBOPACK) { if (cssChunkingMode === 'graph' && !process.env.TURBOPACK) {
......
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