From fbb8a11dbaeaebdebb3fc7b74ee04acc17292781 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Thu, 13 Jun 2024 17:17:31 +0200 Subject: [PATCH 1/5] `format-resources` needs to use strict globbing. This is because we need `format-resources` in extension to be able to move a folder and not just its content. Without strict mode, any value passed will be transformed to a smartGlob by adding `**/*` to directory to resolve all the file content. Our format-resources process copy the files to root then. We want 1.3 behavior here where this copy a folder ````yaml format-resources: folder-from-extensions-to-be-in-root-with-its-content ```` --- src/extension/extension.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/extension/extension.ts b/src/extension/extension.ts index 99e1157a66..149c521bd4 100644 --- a/src/extension/extension.ts +++ b/src/extension/extension.ts @@ -730,6 +730,7 @@ async function readExtension( extensionDir, formatMeta[kFormatResources] as string[], [], + { mode: "strict" }, ); if (resolved.include.length > 0) { formatMeta[kFormatResources] = resolved.include.map((include) => { From c77f9a0626ef52903f47d527dfe5a27a3950876c Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Thu, 13 Jun 2024 17:22:06 +0200 Subject: [PATCH 2/5] Add to changelog --- news/changelog-1.5.md | 1 + 1 file changed, 1 insertion(+) diff --git a/news/changelog-1.5.md b/news/changelog-1.5.md index f52173a35d..afc9872761 100644 --- a/news/changelog-1.5.md +++ b/news/changelog-1.5.md @@ -128,6 +128,7 @@ All changes included in 1.5: - ([#8385](https://github.com/quarto-dev/quarto-cli/issues/8385)): Properly copy project resources when extensions are installed at project level. - ([#8547](https://github.com/quarto-dev/quarto-cli/issues/8547)): Support installing extensions from github branch with forward slash in the name. +- ([#9918](https://github.com/quarto-dev/quarto-cli/issues/9918)): `format-resources` can use explicit [Quarto glob syntax](https://quarto.org/docs/reference/globs.html), e.g. `format-resources: dir/**/*` to copy all files in `dir` and its subdirectories to input root, but use `format-resources: dir` to copy `dir` and its contents to input root. - ([#9948](https://github.com/quarto-dev/quarto-cli/issues/9948)): New extension type: `metadata`. Example use case: support `pre-render` and `post-render` script lists in `project` metadata. ## Shortcodes From 784ad592324298c91b6b9edd06b11d2808ca2a68 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Thu, 13 Jun 2024 17:22:31 +0200 Subject: [PATCH 3/5] Add a test --- .../9918/_extensions/test/_extension.yml | 13 ++++++++ .../9918/_extensions/test/dummy-4.txt | 1 + .../test/files-to-root/dummy-2.txt | 1 + .../test/files-to-root/dummy-3.txt | 1 + .../_extensions/test/folder-to-root/dummy.txt | 1 + .../format-resources/9918/index.qmd | 9 +++++ .../extension-render-format-resources.test.ts | 33 +++++++++++++++++++ tests/verify.ts | 10 ++++++ 8 files changed, 69 insertions(+) create mode 100644 tests/docs/extensions/format-resources/9918/_extensions/test/_extension.yml create mode 100644 tests/docs/extensions/format-resources/9918/_extensions/test/dummy-4.txt create mode 100644 tests/docs/extensions/format-resources/9918/_extensions/test/files-to-root/dummy-2.txt create mode 100644 tests/docs/extensions/format-resources/9918/_extensions/test/files-to-root/dummy-3.txt create mode 100644 tests/docs/extensions/format-resources/9918/_extensions/test/folder-to-root/dummy.txt create mode 100644 tests/docs/extensions/format-resources/9918/index.qmd create mode 100644 tests/smoke/extensions/extension-render-format-resources.test.ts diff --git a/tests/docs/extensions/format-resources/9918/_extensions/test/_extension.yml b/tests/docs/extensions/format-resources/9918/_extensions/test/_extension.yml new file mode 100644 index 0000000000..4a064b61fb --- /dev/null +++ b/tests/docs/extensions/format-resources/9918/_extensions/test/_extension.yml @@ -0,0 +1,13 @@ +title: Test +author: Christophe Dervieux +version: 1.0.0 +quarto-required: ">=1.3" +contributes: + formats: + html: + format-resources: + - folder-to-root + - files-to-root/**/* + - dummy-4.txt + gfm: + format-resources: folder-to-root diff --git a/tests/docs/extensions/format-resources/9918/_extensions/test/dummy-4.txt b/tests/docs/extensions/format-resources/9918/_extensions/test/dummy-4.txt new file mode 100644 index 0000000000..8a5ce6cf73 --- /dev/null +++ b/tests/docs/extensions/format-resources/9918/_extensions/test/dummy-4.txt @@ -0,0 +1 @@ +This file should be copied to root project for rendering as it is included as a format-resources \ No newline at end of file diff --git a/tests/docs/extensions/format-resources/9918/_extensions/test/files-to-root/dummy-2.txt b/tests/docs/extensions/format-resources/9918/_extensions/test/files-to-root/dummy-2.txt new file mode 100644 index 0000000000..8a5ce6cf73 --- /dev/null +++ b/tests/docs/extensions/format-resources/9918/_extensions/test/files-to-root/dummy-2.txt @@ -0,0 +1 @@ +This file should be copied to root project for rendering as it is included as a format-resources \ No newline at end of file diff --git a/tests/docs/extensions/format-resources/9918/_extensions/test/files-to-root/dummy-3.txt b/tests/docs/extensions/format-resources/9918/_extensions/test/files-to-root/dummy-3.txt new file mode 100644 index 0000000000..8a5ce6cf73 --- /dev/null +++ b/tests/docs/extensions/format-resources/9918/_extensions/test/files-to-root/dummy-3.txt @@ -0,0 +1 @@ +This file should be copied to root project for rendering as it is included as a format-resources \ No newline at end of file diff --git a/tests/docs/extensions/format-resources/9918/_extensions/test/folder-to-root/dummy.txt b/tests/docs/extensions/format-resources/9918/_extensions/test/folder-to-root/dummy.txt new file mode 100644 index 0000000000..8a5ce6cf73 --- /dev/null +++ b/tests/docs/extensions/format-resources/9918/_extensions/test/folder-to-root/dummy.txt @@ -0,0 +1 @@ +This file should be copied to root project for rendering as it is included as a format-resources \ No newline at end of file diff --git a/tests/docs/extensions/format-resources/9918/index.qmd b/tests/docs/extensions/format-resources/9918/index.qmd new file mode 100644 index 0000000000..7f36b5ed36 --- /dev/null +++ b/tests/docs/extensions/format-resources/9918/index.qmd @@ -0,0 +1,9 @@ +--- +title: Untitled +format: + test-html: default + test-gfm: default +--- + +This document uses a test extension that should include nested resources + diff --git a/tests/smoke/extensions/extension-render-format-resources.test.ts b/tests/smoke/extensions/extension-render-format-resources.test.ts new file mode 100644 index 0000000000..8c8169a071 --- /dev/null +++ b/tests/smoke/extensions/extension-render-format-resources.test.ts @@ -0,0 +1,33 @@ +/* +* extension-render-doc.test.ts +* +* Copyright (C) 2020-2022 Posit Software, PBC +* +*/ + +import { safeRemoveSync } from "../../../src/core/path.ts"; +import { dirname, join } from "../../../src/deno_ral/path.ts"; +import { fileLoader } from "../../utils.ts"; +import { fileExists, folderExists, pathDoNotExists } from "../../verify.ts"; +import { testRender } from "../render/render.ts"; + +// This file uses custom formats 'test-html' provided by test extension +const input = fileLoader("extensions/format-resources/9918")("index.qmd", "test-html"); +const rootDir = dirname(input.input) +const resourcesFile = [ + join('folder-to-root', 'dummy.txt'), + 'dummy-2.txt', 'dummy-3.txt', 'dummy-4.txt', +].map((x) => join(rootDir, x)) +testRender(input.input, "test-html", false, + [ + folderExists(join(rootDir, "folder-to-root")), + ...resourcesFile.map(fileExists), + pathDoNotExists(join(rootDir, "dummy.txt")), + ], + { + teardown: () => { + resourcesFile.forEach((x) => safeRemoveSync(x)); + return Promise.resolve(); + }, + } +); \ No newline at end of file diff --git a/tests/verify.ts b/tests/verify.ts index 358ff87e44..d85a22b78b 100644 --- a/tests/verify.ts +++ b/tests/verify.ts @@ -180,6 +180,16 @@ export const fileExists = (file: string): Verify => { }; }; +export const pathDoNotExists = (path: string): Verify => { + return { + name: `path ${path} exists`, + verify: (_output: ExecuteOutput[]) => { + verifyNoPath(path); + return Promise.resolve(); + }, + }; +}; + export const directoryContainsOnlyAllowedPaths = (dir: string, paths: string[]): Verify => { return { name: `Ensure only has ${paths.length} paths in folder`, From cec214c11f81f0f3cbdadd27715a7ec4690f8843 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Thu, 13 Jun 2024 17:25:34 +0200 Subject: [PATCH 4/5] tests - verify that input exists before doing any rendering this avoid unclear tests error due to file not found error when trying to render. `quarto render` errors, but the real errors is hidden behind faild assertion message otherwise --- tests/smoke/render/render.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/smoke/render/render.ts b/tests/smoke/render/render.ts index 53a6c53fbd..f8b2d102a9 100644 --- a/tests/smoke/render/render.ts +++ b/tests/smoke/render/render.ts @@ -17,6 +17,7 @@ import { } from "../../verify.ts"; import { safeRemoveSync } from "../../../src/core/path.ts"; import { safeExistsSync } from "../../../src/core/path.ts"; +import { assert } from "../../../src/vendor/deno.land/std@0.217.0/assert/assert.ts"; export function testSimpleIsolatedRender( file: string, @@ -66,6 +67,12 @@ export function testRender( verify, { ...context, + setup: async () => { + assert(safeExistsSync(input), `Input file ${input} does not exist. Test could not be ran.`); + if (context?.setup) { + await context?.setup(); + } + }, teardown: async () => { if (context?.teardown) { await context?.teardown(); From 50b4cf15a0be98a439773ffe923e1e284301879b Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Thu, 13 Jun 2024 17:50:09 +0200 Subject: [PATCH 5/5] test - do the input assertion after any setup steps Because some step may create the input in the context.setup part --- tests/smoke/render/render.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/smoke/render/render.ts b/tests/smoke/render/render.ts index f8b2d102a9..d6ad922562 100644 --- a/tests/smoke/render/render.ts +++ b/tests/smoke/render/render.ts @@ -68,10 +68,10 @@ export function testRender( { ...context, setup: async () => { - assert(safeExistsSync(input), `Input file ${input} does not exist. Test could not be ran.`); if (context?.setup) { await context?.setup(); } + assert(safeExistsSync(input), `Input file ${input} does not exist. Test could not be ran.`); }, teardown: async () => { if (context?.teardown) {