fix(preview): restore --output-dir for single-file preview without _quarto.yml#14491
Merged
fix(preview): restore --output-dir for single-file preview without _quarto.yml#14491
Conversation
…uarto.yml When `quarto preview file.qmd --output-dir <dir>` runs in a directory without _quarto.yml, preview pre-creates a single-file ProjectContext and passes it to render() as pContext. The synthetic-project trigger in render-shared only fired when context was null, bypassing it for the preview path and surfacing the project-only-flag check. Extend the trigger to also fire when pContext is a single-file context. Discarded single-file context cleans up via globalTempContext. Adds a unit test that exercises the exact preview pattern, and an llm-docs note describing the synthetic-project mechanism + history. Fixes #14489. Preview side of posit-dev/positron#13370.
Collaborator
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
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 a regression introduced in v1.9.18 where
quarto preview file.qmd --output-dir <dir>fails withThe --output-dir flag can only be used when rendering projects.when run in a directory without_quarto.yml. This is how the Quarto VS Code extension/Positron drives single-file preview inside R packages (DESCRIPTIONpresent, no_quarto.yml), so the bug surfaces in those workflows even though the underlying CLI behavior has nothing to do withDESCRIPTION— anyquarto preview --output-diragainst a single file outside a project hits it.Fixes #14489. Reported via
posit-dev/positron#13370.Root cause
preview.tspre-creates asingleFileProjectContextand passes it torender()aspContext. The 1.4-era synthetic-project trigger inrender-shared.tsonly fires whenpContextis null:Preview always supplies a context, so the trigger is skipped and the path falls through to
validateDocumentRenderFlags, which throws.quarto render foo.qmd --output-dir baz/works because therepContextis null and the trigger fires.Fix
Extend the trigger to also fire when
pContextis a single-file context:The discarded
singleFileProjectContextcleans up throughglobalTempContext. The synthetic project produced byprojectContextForDirectorypopulatesfiles.input, so the existingisProjectInputFilearm at line 100 takes over and the path proceeds viarenderProjectas for any other project render.A regression unit test exercises the exact preview pattern (
tests/unit/render-shared-output-dir.test.ts).llm-docs/synthetic-project-context.mddocuments the synthetic-project mechanism and the history of the two single-file context shapes (singleFileProjectContextfor extensions,projectContextForDirectoryfor--output-dir).Test plan
tests/unit/render-shared-output-dir.test.ts)tests/smoke/render/render-output-dir.test.tsstill passestests/smoke/render/render-minimal.test.tsstill passes_quarto.yml+test.qmd,quarto preview test.qmd --no-browser --no-watch-inputs --output-dir <tmp> --embed-resourcesno longer throws and produces outputBackport
This will be backported to v1.9 separately.