Unverified Commit 634cfd33 authored by Will Binns-Smith's avatar Will Binns-Smith Committed by GitHub

bundle analyzer: remove custom output option (#87267)

This functionality was added late in #87258 but was broken as we needed
to pass this along to the Rust side. We'd also need to be able to write
to arbitrary absolute paths there, so let's punt on it.

Test Plan: e2e tests
parent 3352f9ee
...@@ -213,8 +213,8 @@ program ...@@ -213,8 +213,8 @@ program
.option('--no-mangling', 'Disables mangling.') .option('--no-mangling', 'Disables mangling.')
.option('--profile', 'Enables production profiling for React.') .option('--profile', 'Enables production profiling for React.')
.option( .option(
'-o, --output [path]', '-o, --output',
'Only write analysis files to disk. Does not start the server. Optionally specify a custom output path (defaults to .next/diagnostics/analyze).' 'Only write analysis files to disk. Does not start the server.'
) )
.addOption( .addOption(
new Option( new Option(
......
...@@ -30,14 +30,12 @@ import { eventAnalyzeCompleted } from '../../telemetry/events' ...@@ -30,14 +30,12 @@ import { eventAnalyzeCompleted } from '../../telemetry/events'
import { traceGlobals } from '../../trace/shared' import { traceGlobals } from '../../trace/shared'
import type { RoutesManifest } from '..' import type { RoutesManifest } from '..'
const ANALYZE_PATH = '.next/diagnostics/analyze'
export type AnalyzeOptions = { export type AnalyzeOptions = {
dir: string dir: string
reactProductionProfiling?: boolean reactProductionProfiling?: boolean
noMangling?: boolean noMangling?: boolean
appDirOnly?: boolean appDirOnly?: boolean
output?: boolean | string output?: boolean
port?: number port?: number
} }
...@@ -77,36 +75,27 @@ export default async function analyze({ ...@@ -77,36 +75,27 @@ export default async function analyze({
await turbopackAnalyze(analyzeContext) await turbopackAnalyze(analyzeContext)
const durationString = durationToString(analyzeDuration) const durationString = durationToString(analyzeDuration)
const analyzeDir = path.join(distDir, 'diagnostics/analyze')
// Determine the output path: use custom path if provided, otherwise default
const outputPath = typeof output === 'string' ? output : ANALYZE_PATH
const resolvedOutputPath = path.isAbsolute(outputPath)
? outputPath
: path.join(dir, outputPath)
let logMessage = `Analyze completed in ${durationString}.`
if (output) {
logMessage += ` Results written to ${outputPath}.\nTo explore the analyze results interactively, run \`next experimental-analyze\` without \`--output\`.`
}
Log.event(logMessage)
await shutdownPromise await shutdownPromise
await cp(
path.join(__dirname, '../../bundle-analyzer'),
resolvedOutputPath,
{ recursive: true }
)
// Collect and write routes for the bundle analyzer
const routes = await collectRoutesForAnalyze(dir, config, appDirOnly) const routes = await collectRoutesForAnalyze(dir, config, appDirOnly)
await mkdir(path.join(resolvedOutputPath, 'data'), { recursive: true }) await cp(path.join(__dirname, '../../bundle-analyzer'), analyzeDir, {
recursive: true,
})
await mkdir(path.join(analyzeDir, 'data'), { recursive: true })
await writeFile( await writeFile(
path.join(resolvedOutputPath, 'data', 'routes.json'), path.join(analyzeDir, 'data', 'routes.json'),
JSON.stringify(routes, null, 2) JSON.stringify(routes, null, 2)
) )
let logMessage = `Analyze completed in ${durationString}.`
if (output) {
logMessage += ` Results written to ${analyzeDir}.\nTo explore the analyze results interactively, run \`next experimental-analyze\` without \`--output\`.`
}
Log.event(logMessage)
telemetry.record( telemetry.record(
eventAnalyzeCompleted({ eventAnalyzeCompleted({
success: true, success: true,
...@@ -116,7 +105,7 @@ export default async function analyze({ ...@@ -116,7 +105,7 @@ export default async function analyze({
) )
if (!output) { if (!output) {
await startServer(resolvedOutputPath, port) await startServer(analyzeDir, port)
} }
} catch (e) { } catch (e) {
const telemetry = traceGlobals.get('telemetry') as Telemetry | undefined const telemetry = traceGlobals.get('telemetry') as Telemetry | undefined
......
...@@ -13,7 +13,7 @@ export type NextAnalyzeOptions = { ...@@ -13,7 +13,7 @@ export type NextAnalyzeOptions = {
profile?: boolean profile?: boolean
mangling: boolean mangling: boolean
port: number port: number
output: boolean | string output: boolean
experimentalAppOnly?: boolean experimentalAppOnly?: boolean
} }
......
...@@ -49,7 +49,7 @@ describe('next experimental-analyze', () => { ...@@ -49,7 +49,7 @@ describe('next experimental-analyze', () => {
}) })
;['-o', '--output'].forEach((flag) => { ;['-o', '--output'].forEach((flag) => {
describe(`with ${flag} flag`, () => { describe(`with ${flag} flag`, () => {
it('writes output to default path when no path is specified', async () => { it('writes output to .next/diagnostics/analyze path', async () => {
const defaultOutputPath = path.join( const defaultOutputPath = path.join(
next.testDir, next.testDir,
'.next/diagnostics/analyze' '.next/diagnostics/analyze'
...@@ -69,12 +69,14 @@ describe('next experimental-analyze', () => { ...@@ -69,12 +69,14 @@ describe('next experimental-analyze', () => {
expect(stdout).toContain('.next/diagnostics/analyze') expect(stdout).toContain('.next/diagnostics/analyze')
expect(existsSync(defaultOutputPath)).toBe(true) expect(existsSync(defaultOutputPath)).toBe(true)
expect(existsSync(path.join(defaultOutputPath, 'index.html'))).toBe( for (const file of [
true 'index.html',
) 'data/routes.json',
expect( 'data/modules.data',
existsSync(path.join(defaultOutputPath, 'data', 'routes.json')) 'data/analyze.data',
).toBe(true) ]) {
expect(existsSync(path.join(defaultOutputPath, file))).toBe(true)
}
const routesJson = readFileSync( const routesJson = readFileSync(
path.join(defaultOutputPath, 'data', 'routes.json'), path.join(defaultOutputPath, 'data', 'routes.json'),
...@@ -83,39 +85,6 @@ describe('next experimental-analyze', () => { ...@@ -83,39 +85,6 @@ describe('next experimental-analyze', () => {
const routes = JSON.parse(routesJson) const routes = JSON.parse(routesJson)
expect(routes).toEqual(['/', '/_not-found']) expect(routes).toEqual(['/', '/_not-found'])
}) })
it('writes output to custom path', async () => {
const customOutputPath = path.join(
next.testDir,
'nested/output/directory'
)
const { code, stderr, stdout } = await runNextCommand(
['experimental-analyze', flag, 'nested/output/directory'],
{
cwd: next.testDir,
stderr: true,
stdout: true,
}
)
expect(code).toBe(0)
expect(stderr).not.toContain('Error')
expect(stdout).toContain('nested/output/directory')
expect(existsSync(customOutputPath)).toBe(true)
expect(existsSync(path.join(customOutputPath, 'index.html'))).toBe(true)
expect(
existsSync(path.join(customOutputPath, 'data', 'routes.json'))
).toBe(true)
const routesJson = readFileSync(
path.join(customOutputPath, 'data', 'routes.json'),
'utf-8'
)
const routes = JSON.parse(routesJson)
expect(routes).toEqual(['/', '/_not-found'])
})
}) })
}) })
}) })
......
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