Skip to content

feat(optimizer): improve the esbuild plugin converter to pass some properties of build result to onEnd#22357

Merged
sapphi-red merged 4 commits into
vitejs:mainfrom
lyzno1:codex/fix-esbuild-onend-build-result
May 14, 2026
Merged

feat(optimizer): improve the esbuild plugin converter to pass some properties of build result to onEnd#22357
sapphi-red merged 4 commits into
vitejs:mainfrom
lyzno1:codex/fix-esbuild-onend-build-result

Conversation

@lyzno1
Copy link
Copy Markdown
Contributor

@lyzno1 lyzno1 commented Apr 29, 2026

Description

Fixes #22356.

convertEsbuildPluginToRolldownPlugin() currently passes a throwing proxy to esbuild onEnd callbacks. That means normal esbuild-style code such as if (!result.metafile) return throws instead of seeing undefined when no metafile is available.

This PR passes a minimal valid esbuild.BuildResult instead, with empty errors and warnings and optional result fields set to undefined.

Tests

  • pnpm exec vitest run packages/vite/src/node/__tests__/optimizer/pluginConverter.spec.ts
  • pnpm exec vitest run packages/vite/src/node/__tests__/optimizer
  • pnpm exec eslint --cache --concurrency auto packages/vite/src/node/optimizer/pluginConverter.ts packages/vite/src/node/__tests__/optimizer/pluginConverter.spec.ts
  • pnpm exec oxfmt --check packages/vite/src/node/optimizer/pluginConverter.ts packages/vite/src/node/__tests__/optimizer/pluginConverter.spec.ts
  • pnpm --filter vite typecheck

@sapphi-red sapphi-red changed the title fix(optimizer): pass valid build result to onEnd feat(optimizer): improve the esbuild plugin converter to pass valid build result to onEnd May 14, 2026
@sapphi-red sapphi-red changed the title feat(optimizer): improve the esbuild plugin converter to pass valid build result to onEnd feat(optimizer): improve the esbuild plugin converter to pass valid build result to onEnd May 14, 2026
@sapphi-red sapphi-red added p2-nice-to-have Not breaking anything but nice to have (priority) feat: deps optimizer Esbuild Dependencies Optimization labels May 14, 2026
@sapphi-red sapphi-red changed the title feat(optimizer): improve the esbuild plugin converter to pass valid build result to onEnd feat(optimizer): improve the esbuild plugin converter to pass some properties of build result to onEnd May 14, 2026
@sapphi-red
Copy link
Copy Markdown
Member

I've kept errors and warnings to throw an error if accessed because if it's accessed it's commonly incompatible.

@sapphi-red sapphi-red merged commit 47071ce into vitejs:main May 14, 2026
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat: deps optimizer Esbuild Dependencies Optimization p2-nice-to-have Not breaking anything but nice to have (priority)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

optimizeDeps esbuild plugin onEnd receives throwing BuildResult

2 participants