fix: resolve outDir against Vite root in buildApp#154
Merged
Conversation
buildApp used the configured outDir values of the rsc and client environments directly, which resolve against process.cwd() when relative. If vite build is run from a directory other than the Vite root (e.g. monorepo root with --config), the RSC entry import and output writes could target the wrong location. Resolve both against config.root, matching what serverPlugin already does. This also guarantees BuildEntryContext.outDir is absolute, as documented. Closes #141 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DEURCLVLKQvqYUrAkqcHpE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #141.
buildAppused the configuredoutDirvalues of therscandclientenvironments directly. SinceoutDirmay be a relative path, these resolved againstprocess.cwd()— so runningvite buildfrom a directory other than the Vite root (e.g. monorepo root with--config) could break the RSC entry import or write output to the wrong location. Both paths are now resolved withpath.resolve(config.root, outDir), matching whatserverPluginalready does.This also guarantees
BuildEntryContext.outDiris absolute, as its documentation promises.Note
While verifying, I found the bug is currently masked in practice:
@vitejs/plugin-rsc(0.5.28) rewrites every environment'sbuild.outDirto an absolute path in its ownconfigResolvedhook. The fix is still worthwhile — it stopsbuildAppfrom silently depending on a dependency's internal behavior, andpath.resolveis a no-op on already-absolute paths, so there is no behavior change today.Verification
rootin the Vite config while runningvite buildfrom a different working directory; output landed correctly under the Vite root with nothing leaked into the cwd.pnpm build,pnpm typecheck,pnpm lint, all 77 unit tests, and all 29 Playwright e2e tests pass.🤖 Generated with Claude Code
https://claude.ai/code/session_01DEURCLVLKQvqYUrAkqcHpE
Generated by Claude Code