From cf44c60cdaf1f94c72eb322310e6b21ab150c69e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Mon, 16 Nov 2026 03:32:25 +0000 Subject: [PATCH] fix(cli): batch outputs from a template that starts with a placeholder stay in the working folder (#7868) * fix(cli): batch outputs from a template that starts with a placeholder stay in the working folder * fix(cli): the bare {path} template is named, not commented --- docs/concepts/variables.mdx | 7 ++-- packages/cli/src/commands/batchRender.test.ts | 36 ++++++++++++++++++- packages/cli/src/commands/batchRender.ts | 7 ++-- 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/docs/concepts/variables.mdx b/docs/concepts/variables.mdx index 972337e16a..18c4ce74ff 100644 --- a/docs/concepts/variables.mdx +++ b/docs/concepts/variables.mdx @@ -248,9 +248,10 @@ npx hyperframes render \ Every output stays inside the folder written before the first placeholder (`renders/` here). A row value may name a subfolder of it, but a value that leads outside it, such as `../other`, stops the batch before anything renders. -A template that starts with a placeholder, such as `--output "{path}"`, names -no folder, so each row's value is used as the whole output path, absolute -paths included. +A template that starts with a placeholder, such as `{name}.mp4`, keeps every +output inside the folder you run the command from. Only `--output "{path}"`, +the placeholder alone, uses each row's value as the whole output path, +absolute paths included. Start with the default single-row concurrency. Increase `--batch-concurrency` only after one real render is stable and the machine has enough memory for diff --git a/packages/cli/src/commands/batchRender.test.ts b/packages/cli/src/commands/batchRender.test.ts index 3439f539a4..f1231aed84 100644 --- a/packages/cli/src/commands/batchRender.test.ts +++ b/packages/cli/src/commands/batchRender.test.ts @@ -164,6 +164,40 @@ describe("prepareBatchRender", () => { expect(error.message).toMatch(/Row 0 resolves to/); }); + it.each(["{name}.mp4", join("{name}", "out.mp4")])( + "refuses a row value that leaves the working folder when %s starts with a placeholder", + (template) => { + const batchPath = writeJson("rows.json", JSON.stringify([{ name: "../escaped" }])); + const error = expectBatchError( + () => + prepareBatchRender({ + batchPath, + outputTemplate: template, + indexPath: writeIndex(), + strictVariables: false, + quiet: true, + json: false, + }), + "Batch output outside --output folder", + ); + expect(error.message).toMatch(/Row 0 resolves to/); + }, + ); + + it("keeps a template that starts with a placeholder inside the working folder", () => { + const batchPath = writeJson("rows.json", '[{"name":"acme"}]'); + const prepared = prepareBatchRender({ + batchPath, + outputTemplate: join("{index}", "{name}.mp4"), + indexPath: writeIndex(), + strictVariables: false, + quiet: true, + json: false, + }); + + expect(prepared.rows.map((row) => row.outputPath)).toEqual([resolve("0", "acme.mp4")]); + }); + it("keeps a backslash in a row value or file name on every platform", () => { const batchPath = writeJson("rows.json", '[{"name":"a\\\\b"}]'); const outDir = join(tmpDir, "renders\\"); @@ -178,7 +212,7 @@ describe("prepareBatchRender", () => { expect(prepared.rows[0]?.outputPath).toBe(resolve(`${outDir}a\\b.mp4`)); }); - it("lets the rows name the whole path when the template starts with a placeholder", () => { + it("lets the rows name the whole path when the template is a bare {path}", () => { const elsewhere = join(tmpDir, "elsewhere", "launch.mp4"); const batchPath = writeJson("rows.json", JSON.stringify([{ path: elsewhere }])); const prepared = prepareBatchRender({ diff --git a/packages/cli/src/commands/batchRender.ts b/packages/cli/src/commands/batchRender.ts index d238010bf3..ffda3944cd 100644 --- a/packages/cli/src/commands/batchRender.ts +++ b/packages/cli/src/commands/batchRender.ts @@ -87,6 +87,7 @@ interface RunBatchRenderOptions { } const PLACEHOLDER_RE = /\{([A-Za-z0-9_.-]+)\}/g; +const ROWS_NAME_WHOLE_OUTPUT_PATH = "{path}"; function isRecord(value: unknown): value is Record { return value !== null && typeof value === "object" && !Array.isArray(value); @@ -160,9 +161,11 @@ function folderOfPrefix(prefix: string): string { } function checkOutputsInsideTemplateFolder(rows: readonly PreparedBatchRow[], template: string) { + if (template === ROWS_NAME_WHOLE_OUTPUT_PATH) return; const firstPlaceholder = template.search(PLACEHOLDER_RE); - if (firstPlaceholder <= 0) return; - const folder = folderOfPrefix(template.slice(0, firstPlaceholder)); + if (firstPlaceholder < 0) return; + const folder = + firstPlaceholder === 0 ? resolve() : folderOfPrefix(template.slice(0, firstPlaceholder)); for (const row of rows) { const rel = relative(folder, row.outputPath); const outside = rel === "" || rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel);