Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/rolldown/src/app/components/RunBuildDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const stage = ref<Stage>('confirm')
const commandLine = ref('vite build')
const buildSessionId = ref<string | null>(null)
const errorMessage = ref<string | null>(null)
const errorOutput = ref<string | null>(null)
const newSessions = ref<BuildInfo[]>([])

// Reset to the confirmation step and load the exact command each time the
Expand All @@ -32,6 +33,7 @@ watch(open, async (isOpen) => {
return
stage.value = 'confirm'
errorMessage.value = null
errorOutput.value = null
newSessions.value = []
buildSessionId.value = null
try {
Expand All @@ -47,12 +49,13 @@ watch(open, async (isOpen) => {
async function confirmRun() {
stage.value = 'running'
errorMessage.value = null
errorOutput.value = null
// Snapshot existing session ids to surface only the ones this build produces.
const before = new Set((await rpc.value.call('vite:rolldown:list-sessions')).map(s => s.id))
try {
const { sessionId } = await rpc.value.call('vite:rolldown:run-build')
buildSessionId.value = sessionId
const { exitCode } = await rpc.value.call('vite:rolldown:wait-for-build')
const { exitCode, errorOutput: output } = await rpc.value.call('vite:rolldown:wait-for-build')
const list = await rpc.value.call('vite:rolldown:list-sessions')
emit('refresh', list)
newSessions.value = list.filter(s => !before.has(s.id))
Expand All @@ -63,6 +66,7 @@ async function confirmRun() {
if (exitCode != null && exitCode !== 0) {
stage.value = 'error'
errorMessage.value = `Build exited with code ${exitCode}.`
errorOutput.value = output ?? null
}
else {
stage.value = 'success'
Expand Down Expand Up @@ -177,9 +181,10 @@ async function viewInTerminal() {
<span class="i-ph-x-circle-duotone" />
Build failed.
</div>
<p v-if="errorMessage" class="m0 op70 text-sm">
<p v-if="errorMessage && !errorOutput" class="m0 op70 text-sm">
{{ errorMessage }}
</p>
<pre v-if="errorOutput" class="m0 p3 max-h-72 rounded-lg border border-base bg-code font-mono text-sm of-auto text-left whitespace-pre-wrap break-words" tabindex="0" aria-label="Build error output"><code>{{ errorOutput }}</code></pre>
<div class="flex-auto" />
<div class="flex justify-end gap-2">
<ActionButton @click="open = false">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { ROLLDOWN_DEVTOOLS_ENV } from '@vitejs/devtools-kit/constants'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { getBuildCommand, startBuild } from '../build-runner'
import { getBuildCommand, startBuild, waitForBuild } from '../build-runner'

const fixtures: string[] = []

Expand All @@ -19,6 +19,7 @@ function fakeContext() {
status: 'running',
terminate: vi.fn(async () => {}),
getResult: vi.fn(),
buffer: [] as string[],
}))
const context = {
cwd: '/project',
Expand Down Expand Up @@ -71,3 +72,36 @@ describe('startBuild', () => {
})
})
})

describe('waitForBuild', () => {
it('returns the last 20 terminal lines without ANSI escapes for a failed build', async () => {
const { context, startChildProcess } = fakeContext()
await startBuild(context)
const session = await startChildProcess.mock.results[0]!.value
session.buffer.push('earlier output\r\n', ...Array.from({ length: 25 }, (_, i) => `\u001B[31merror ${i}\u001B[0m\r\n`))
session.getResult.mockResolvedValue({ exitCode: 1, stdout: 'stdout', stderr: 'stderr' })

expect(await waitForBuild()).toEqual({
exitCode: 1,
errorOutput: Array.from({ length: 20 }, (_, i) => `error ${i + 5}`).join('\n'),
})
})

it('falls back to captured output when the terminal buffer is empty', async () => {
const { context, startChildProcess } = fakeContext()
await startBuild(context)
const session = await startChildProcess.mock.results[0]!.value
session.getResult.mockResolvedValue({ exitCode: 1, stdout: 'Building...', stderr: '\u001B[31mMissing config\u001B[0m\n' })

expect(await waitForBuild()).toEqual({ exitCode: 1, errorOutput: 'Building...\nMissing config' })
})

it('keeps successful results free of error output', async () => {
const { context, startChildProcess } = fakeContext()
await startBuild(context)
const session = await startChildProcess.mock.results[0]!.value
session.getResult.mockResolvedValue({ exitCode: 0, stdout: 'Built', stderr: '' })

expect(await waitForBuild()).toEqual({ exitCode: 0 })
})
})
13 changes: 11 additions & 2 deletions packages/rolldown/src/node/rolldown/build-runner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { DevToolsChildProcessExecuteOptions, ViteDevToolsNodeContext } from '@vitejs/devtools-kit'
import process from 'node:process'
import { stripVTControlCharacters } from 'node:util'
import { ROLLDOWN_DEVTOOLS_ENV } from '@vitejs/devtools-kit/constants'
import { isVitePlusInstalled } from '@vitejs/devtools-kit/node'
import { diagnostics } from '../diagnostics'
Expand Down Expand Up @@ -29,6 +30,8 @@ export interface RunBuildResult {
export interface WaitBuildResult {
/** Process exit code, or `null` when there is no build to await. */
exitCode: number | null
/** Last 20 lines of terminal output when the build fails, without ANSI escapes. */
errorOutput?: string
}

/**
Expand Down Expand Up @@ -94,10 +97,16 @@ export async function startBuild(context: ViteDevToolsNodeContext): Promise<RunB

/** Resolve once the spawned build exits. */
export async function waitForBuild(): Promise<WaitBuildResult> {
if (!current)
const session = current
if (!session)
return { exitCode: null }
try {
const result = await current.getResult()
const result = await session.getResult()
if (result.exitCode != null && result.exitCode !== 0) {
const output = session.buffer?.join('') || `${result.stdout}\n${result.stderr}`
const errorOutput = stripVTControlCharacters(output).trimEnd().split(/\r\n|\r|\n/).slice(-20).join('\n')
return { exitCode: result.exitCode, errorOutput }
}
return { exitCode: result.exitCode ?? null }
}
catch {
Expand Down
Loading