From 93f06f015151c47f22cc854e22f669926d0e8c94 Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Tue, 15 Oct 2024 13:53:14 -0700 Subject: [PATCH 1/7] do not change directory of stdout rendering to avoid embed-resources failing --- src/command/render/output.ts | 16 +++++++++++----- src/command/render/render.ts | 6 +++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/command/render/output.ts b/src/command/render/output.ts index fdf2e1a0c40..017284974d3 100644 --- a/src/command/render/output.ts +++ b/src/command/render/output.ts @@ -181,7 +181,7 @@ export function outputRecipe( }); } - if (!recipe.output) { + const deriveAutoOutput = () => { // no output specified: derive an output path from the extension // derive new output file @@ -200,11 +200,17 @@ export function outputRecipe( // assign output updateOutput(output); + }; + + if (!recipe.output) { + deriveAutoOutput(); } else if (recipe.output === kStdOut) { - // output to stdout: direct pandoc to write to a temp file then we'll - // forward to stdout (necessary b/c a postprocesor may need to act on - // the output before its complete) - updateOutput(options.services.temp.createFile({ suffix: "." + ext })); + deriveAutoOutput(); + + // https://github.com/quarto-dev/quarto-cli/issues/11068 + // we need the output to be in the same directory or + // embed-resources doesn't work. + recipe.isOutputTransient = true; completeActions.push(() => { writeFileToStdout(recipe.output); diff --git a/src/command/render/render.ts b/src/command/render/render.ts index 195bdd693cf..9cf86b32d9d 100644 --- a/src/command/render/render.ts +++ b/src/command/render/render.ts @@ -277,9 +277,6 @@ export async function renderPandoc( // ensure flags const flags = context.options.flags || {}; - // call complete handler (might e.g. run latexmk to complete the render) - finalOutput = await recipe.complete(pandocOptions) || recipe.output; - // determine whether this is self-contained output selfContained = isSelfContainedOutput( flags, @@ -295,6 +292,9 @@ export async function renderPandoc( format.pandoc[kResourcePath], ); } + + // call complete handler (might e.g. run latexmk to complete the render) + finalOutput = await recipe.complete(pandocOptions) || recipe.output; }); // compute the relative path to the files dir From ec9855ab5cb7d158722e88c403bc625c01f3d1ba Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Tue, 15 Oct 2024 14:05:37 -0700 Subject: [PATCH 2/7] respect inputDir if it's not . --- src/command/render/output.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/command/render/output.ts b/src/command/render/output.ts index 017284974d3..cf08086e6f1 100644 --- a/src/command/render/output.ts +++ b/src/command/render/output.ts @@ -206,15 +206,10 @@ export function outputRecipe( deriveAutoOutput(); } else if (recipe.output === kStdOut) { deriveAutoOutput(); - - // https://github.com/quarto-dev/quarto-cli/issues/11068 - // we need the output to be in the same directory or - // embed-resources doesn't work. - recipe.isOutputTransient = true; completeActions.push(() => { - writeFileToStdout(recipe.output); - Deno.removeSync(recipe.output); + writeFileToStdout(join(inputDir, recipe.output)); + Deno.removeSync(join(inputDir, recipe.output)); }); } else if (!isAbsolute(recipe.output)) { // relatve output file on the command line: make it relative to the input dir From eb746a23f3fcc28e2ab630f8b6241d33c4a1ce16 Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Tue, 15 Oct 2024 14:06:03 -0700 Subject: [PATCH 3/7] regression test --- tests/smoke/self-contained/stdout.test.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 tests/smoke/self-contained/stdout.test.ts diff --git a/tests/smoke/self-contained/stdout.test.ts b/tests/smoke/self-contained/stdout.test.ts new file mode 100644 index 00000000000..f03a8e6c730 --- /dev/null +++ b/tests/smoke/self-contained/stdout.test.ts @@ -0,0 +1,14 @@ +import { quarto } from "../../../src/quarto.ts"; +import { test } from "../../test.ts"; + +test({ + name: "https://github.com/quarto-dev/quarto-cli/issues/11068", + context: { + setup: async() => { + await quarto(["render", "docs/self-contained/simple.qmd", "-o", "-"]); + } + }, + execute: async () => {}, + verify: [], + type: "smoke" +}); From f3ee7dc1ad9bd92cbb6903bf9f72b87e218e276d Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Tue, 15 Oct 2024 14:07:47 -0700 Subject: [PATCH 4/7] changelog --- news/changelog-1.6.md | 1 + 1 file changed, 1 insertion(+) diff --git a/news/changelog-1.6.md b/news/changelog-1.6.md index 2d4b8a89d66..39f8b03b73d 100644 --- a/news/changelog-1.6.md +++ b/news/changelog-1.6.md @@ -90,6 +90,7 @@ All changes included in 1.6: - Upgrade `mermaidjs` to 11.2.0. - Upgrade Pandoc to 3.4. - Upgrade `deno` to 1.46.3. +- ([#11068](https://github.com/quarto-dev/quarto-cli/issues/11068)): use standard location when writing to standard output to avoid breakage under `self-contained: true`. - ([#10162](https://github.com/quarto-dev/quarto-cli/issues/10162)): Use Edge on `macOS` as a Chromium browser when available. - ([#10235](https://github.com/quarto-dev/quarto-cli/issues/10235)): Configure the CI schedule trigger to activate exclusively for the upstream repository. - ([#10295](https://github.com/quarto-dev/quarto-cli/issues/10235)): Fix regression to return error status to shell when `CommandError` is thrown. From 195c638f1e13c6527a0fda8c43c5a1ce2f3b7bc7 Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Tue, 15 Oct 2024 14:21:22 -0700 Subject: [PATCH 5/7] use recipe.output instead of finalOutput --- src/command/render/render.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/command/render/render.ts b/src/command/render/render.ts index 9cf86b32d9d..b5868a07367 100644 --- a/src/command/render/render.ts +++ b/src/command/render/render.ts @@ -276,12 +276,11 @@ export async function renderPandoc( await withTimingAsync("postprocess-selfcontained", async () => { // ensure flags const flags = context.options.flags || {}; - // determine whether this is self-contained output selfContained = isSelfContainedOutput( flags, format, - finalOutput, + recipe.output, ); // If this is self-contained, run pandoc to 'suck in' the dependencies From e5386c65d3784f53434dd5e89f28560b791e1c62 Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Tue, 15 Oct 2024 15:31:57 -0700 Subject: [PATCH 6/7] check for selfContained twice --- src/command/render/render.ts | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/command/render/render.ts b/src/command/render/render.ts index b5868a07367..80986a16016 100644 --- a/src/command/render/render.ts +++ b/src/command/render/render.ts @@ -277,14 +277,18 @@ export async function renderPandoc( // ensure flags const flags = context.options.flags || {}; // determine whether this is self-contained output + finalOutput = recipe.output; + + // note that we intentionally call isSelfContainedOutput twice + // the first needs to happen before recipe completion + // because ingestion of self-contained output needs + // to happen before recipe completion (which cleans up some files) selfContained = isSelfContainedOutput( flags, format, - recipe.output, + finalOutput, ); - // If this is self-contained, run pandoc to 'suck in' the dependencies - // which may have been added in the post processor if (selfContained && isHtmlFileOutput(format.pandoc)) { await pandocIngestSelfContainedContent( outputFile, @@ -293,7 +297,17 @@ export async function renderPandoc( } // call complete handler (might e.g. run latexmk to complete the render) - finalOutput = await recipe.complete(pandocOptions) || recipe.output; + finalOutput = (await recipe.complete(pandocOptions)) || recipe.output; + + // note that we intentionally call isSelfContainedOutput twice + // the second call happens because some recipes change + // their output extension on completion (notably, .pdf files) + // and become self-contained for purposes of cleanup + selfContained = isSelfContainedOutput( + flags, + format, + finalOutput, + ); }); // compute the relative path to the files dir From 1da6a5d0e7680f09e9aeb0ab07c7a5afe7b35824 Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Tue, 15 Oct 2024 15:49:19 -0700 Subject: [PATCH 7/7] add missing file --- tests/docs/self-contained/simple.qmd | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 tests/docs/self-contained/simple.qmd diff --git a/tests/docs/self-contained/simple.qmd b/tests/docs/self-contained/simple.qmd new file mode 100644 index 00000000000..dea0a3fa2f5 --- /dev/null +++ b/tests/docs/self-contained/simple.qmd @@ -0,0 +1,7 @@ +--- +format: + html: + self-contained: true +--- + +## Hello \ No newline at end of file