fix(cli): an output in a drive root (D:\) no longer fails before it is written on Windows (#7151)

* fix(cli): an output in a drive root (D:\) no longer fails before it is written on Windows

* fix(cli): keep the output folder helper's reason in its test

* fix(cli): make the output folder only when nothing is there, as the producer does

* fix(cli): keep the output folder's directory check and fix the stat mock that hid isDirectory
This commit is contained in:
Miguel Ángel
2026-11-04 10:47:39 +00:00
committed by GitHub
parent 6857bb08e8
commit 50ce9fb514
14 changed files with 90 additions and 32 deletions
+3 -2
View File
@@ -13,7 +13,8 @@
* existing destination is replaced only after the download succeeds.
*/
import { chmodSync, mkdirSync, mkdtempSync, renameSync, rmSync, statSync } from "node:fs";
import { chmodSync, mkdtempSync, renameSync, rmSync, statSync } from "node:fs";
import { makeOutputFolder } from "../utils/outputFolder.js";
import { open } from "node:fs/promises";
import { dirname, join } from "node:path";
import { setTimeout as sleep } from "node:timers/promises";
@@ -73,7 +74,7 @@ export async function downloadToFile(
const ranged = first.status === 206;
const total = ranged ? contentRangeTotal(first) : contentLength(first);
mkdirSync(dirname(destPath), { recursive: true });
makeOutputFolder(dirname(destPath));
// Writes through a caller-selected symlink, as before.
const destination = resolveWritePath(destPath);
+4 -3
View File
@@ -1,5 +1,6 @@
import { failCommand } from "../utils/commandResult.js";
import { mkdirSync, writeFileSync } from "node:fs";
import { writeFileSync } from "node:fs";
import { makeOutputFolder } from "../utils/outputFolder.js";
import { readJsonFileText } from "../utils/jsonFlag.js";
import { dirname, join, resolve, sep } from "node:path";
import { c } from "../ui/colors.js";
@@ -319,7 +320,7 @@ function summarizeManifest(manifest: BatchManifest): void {
function writeManifest(manifest: BatchManifest): void {
summarizeManifest(manifest);
mkdirSync(dirname(manifest.manifestPath), { recursive: true });
makeOutputFolder(dirname(manifest.manifestPath));
writeFileSync(manifest.manifestPath, JSON.stringify(manifest, null, 2) + "\n", "utf8");
}
@@ -341,7 +342,7 @@ async function renderBatchRow(
}
try {
mkdirSync(dirname(row.outputPath), { recursive: true });
makeOutputFolder(dirname(row.outputPath));
const result = await options.renderOne(row);
manifestRow.status = "completed";
manifestRow.durationMs = result.durationMs ?? null;
+2 -1
View File
@@ -9,6 +9,7 @@ import {
rmSync,
statSync,
} from "node:fs";
import { makeOutputFolder } from "../utils/outputFolder.js";
import { tmpdir } from "node:os";
import { basename, dirname, extname, join } from "node:path";
import { defineCommand } from "../utils/defineCommand.js";
@@ -364,7 +365,7 @@ async function renderCompareSheet(parsed: ParsedCompareArgs): Promise<CompareSuc
renderReadyTimedOut = renderReadyTimedOut || rendered.renderReadyTimedOut;
}
mkdirSync(dirname(parsed.outPath), { recursive: true });
makeOutputFolder(dirname(parsed.outPath));
await createContactSheet(framePaths, parsed.outPath, {
cols: parsed.cols ?? defaultCompareCols(framePaths.length),
maxImages: framePaths.length,
+2 -2
View File
@@ -1,12 +1,12 @@
import {
copyFileSync,
existsSync,
mkdirSync,
mkdtempSync,
readFileSync,
rmSync,
writeFileSync,
} from "node:fs";
import { makeOutputFolder } from "../utils/outputFolder.js";
import { readJsonFileText } from "../utils/jsonFlag.js";
import { tmpdir } from "node:os";
import { basename, dirname, extname, join, resolve } from "node:path";
@@ -670,7 +670,7 @@ export default defineCommand({
prepared.tempDir,
parsed.timeoutMs,
);
mkdirSync(dirname(parsed.outPath), { recursive: true });
makeOutputFolder(dirname(parsed.outPath));
copyFileSync(tempSheet, parsed.outPath);
trackCompareSheet({
command: "grade-compare",
+3 -2
View File
@@ -1,7 +1,8 @@
// Pixels from the original, as project media: a still at one moment or a clip over a window, cropped to a region,
// frame-exact, recorded in the media ledger as cut from the original. A rebuild reuses footage, photos and people
// this way instead of drawing or generating them.
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { makeOutputFolder } from "../../utils/outputFolder.js";
import { tmpdir } from "node:os";
import { dirname, join, relative, resolve } from "node:path";
import { defineCommand } from "../../utils/defineCommand.js";
@@ -172,7 +173,7 @@ export default defineCommand({
await runMeasure(async () => {
const { info, roi: asked } = videoAndRoi(args.video, args.roi);
const out = resolve(String(args.out));
mkdirSync(dirname(out), { recursive: true });
makeOutputFolder(dirname(out));
if (/\.(m4a|aac|mp3|wav)$/i.test(out)) {
const sound = cutSound(
info,
+2 -2
View File
@@ -10,8 +10,8 @@ import {
type VideoInfo,
} from "../../measure/media.js";
import { execFileSync } from "node:child_process";
import { mkdirSync } from "node:fs";
import { dirname, resolve } from "node:path";
import { makeOutputFolder } from "../../utils/outputFolder.js";
export const examples: Example[] = [
[
@@ -57,7 +57,7 @@ function normalize(info: VideoInfo, out: string): { path: string; fps: string }
"zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv",
);
}
mkdirSync(dirname(out), { recursive: true });
makeOutputFolder(dirname(out));
runFfmpeg([
...["-y", "-i", info.path, "-vf", [...filters, "format=yuv420p"].join(",")],
...["-c:v", "libx264", "-crf", "12", "-preset", "medium", "-c:a", "aac", "-b:a", "192k", out],
+3 -2
View File
@@ -11,7 +11,8 @@ import { launchManagedBrowser, resolveManagedGpuMode } from "../browser/launch.j
// exactly what it's editing. All geometry + SVG live in ./motionShotLayout.ts
// (pure, tested); this file only drives the browser and SAMPLES.
import { mkdirSync, statSync, writeFileSync } from "node:fs";
import { statSync, writeFileSync } from "node:fs";
import { makeOutputFolder } from "../utils/outputFolder.js";
import { dirname, resolve } from "node:path";
import { pageNavigationTimeoutMs } from "../utils/renderArgs.js";
import { gotoWhenSent } from "../capture/navigateForCapture.js";
@@ -59,7 +60,7 @@ export function ensureShotOutputDir(outPath: string, sourcePath?: string): void
`--shot output must not overwrite the composition source: ${sourcePath}. Choose a separate .png path.`,
);
}
mkdirSync(dirname(outPath), { recursive: true });
makeOutputFolder(dirname(outPath));
}
/** Returned by the in-browser selector resolver: which animated selectors a
+3 -2
View File
@@ -1,5 +1,5 @@
// fallow-ignore-file code-duplication
import { mkdirSync, readFileSync } from "node:fs";
import { readFileSync } from "node:fs";
import { tmpdir } from "node:os";
import type { CanvasResolution, OutputResolutionIssueKind } from "@hyperframes/core";
import { PRORES_PROFILES } from "@hyperframes/engine";
@@ -13,6 +13,7 @@ import {
type ProjectLintResult,
} from "../../utils/lintProject.js";
import { normalizeErrorMessage } from "../../utils/errorMessage.js";
import { makeOutputFolder } from "../../utils/outputFolder.js";
import { failCommand, setCommandExitCode } from "../../utils/commandResult.js";
import {
reportVariableIssues,
@@ -71,7 +72,7 @@ export async function executeRenderPlan(
): Promise<void> {
assertRenderActive(cancellation);
applyRenderEnvironment(plan);
if (!plan.batchPath) mkdirSync(renderOutputDirectory(plan), { recursive: true });
if (!plan.batchPath) makeOutputFolder(renderOutputDirectory(plan));
let batchModule: typeof import("../batchRender.js") | undefined;
let preparedBatch: import("../batchRender.js").PreparedBatchRender | undefined;
+2 -1
View File
@@ -12,6 +12,7 @@ import {
statSync,
writeFileSync,
} from "node:fs";
import { makeOutputFolder } from "../utils/outputFolder.js";
import { dirname, join, resolve } from "node:path";
import { resolveCloudAuthHeaders } from "../cloud/auth.js";
import { billingBaseUrl } from "../heygen/plan.js";
@@ -110,7 +111,7 @@ const PULLED_HASH = ".template-sha256";
/** Unpacks the pack beside `dest` and moves it in whole, so `dest` only ever holds a complete template. */
function unpack(data: Buffer, dest: string, pack: TemplatePack): void {
mkdirSync(dirname(dest), { recursive: true });
makeOutputFolder(dirname(dest));
const work = mkdtempSync(`${dest}.part-`);
try {
const out = join(work, "template");
+4 -4
View File
@@ -6,10 +6,10 @@ import { join } from "node:path";
// Number-mode stats report one identity for every path, as Windows file ids above 2^53 can.
vi.mock("node:fs", async (importOriginal) => {
const actual = await importOriginal<typeof import("node:fs")>();
const statSync = ((path: string, options?: { bigint?: boolean }) =>
options?.bigint
? actual.statSync(path, options as never)
: { ...actual.statSync(path), dev: 1, ino: 2 ** 53 }) as typeof actual.statSync;
const statSync = ((path: string, options?: { bigint?: boolean }) => {
const stats = actual.statSync(path, options as never);
return options?.bigint || !stats ? stats : Object.assign(stats, { dev: 1, ino: 2 ** 53 });
}) as typeof actual.statSync;
return { ...actual, statSync };
});
+3 -10
View File
@@ -2,15 +2,8 @@
// from one photo, a voice, or music. Every call is priced first with --plan, keyed for idempotency, downloaded into
// the project and recorded in the media ledger as generated.
import { randomUUID } from "node:crypto";
import {
existsSync,
mkdirSync,
mkdtempSync,
readFileSync,
renameSync,
rmSync,
writeFileSync,
} from "node:fs";
import { existsSync, mkdtempSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
import { makeOutputFolder } from "../utils/outputFolder.js";
import { tmpdir } from "node:os";
import { basename, dirname, extname, join, relative, resolve } from "node:path";
import type {
@@ -663,7 +656,7 @@ export async function generate(
checkRequest(r);
const route = ROUTES[r.type];
const out = resolve(r.out);
mkdirSync(dirname(out), { recursive: true });
makeOutputFolder(dirname(out));
const project = projectOf(dirname(out));
const work = mkdtempSync(join(tmpdir(), "hf-generate-"));
try {
+2 -1
View File
@@ -1,6 +1,7 @@
// fallow-ignore-file complexity
import { execFileSync } from "node:child_process";
import { existsSync, mkdirSync, readdirSync, unlinkSync } from "node:fs";
import { makeOutputFolder } from "../utils/outputFolder.js";
import { join, dirname, basename } from "node:path";
import {
ensureModel,
@@ -211,7 +212,7 @@ export async function synthesize(
const scriptPath = ensureSynthScript();
// 4. Ensure output directory exists
mkdirSync(dirname(outputPath), { recursive: true });
makeOutputFolder(dirname(outputPath));
// 5. Run synthesis
options?.onProgress?.(`Generating speech with voice ${voice} (${lang})...`);
@@ -0,0 +1,50 @@
import * as fs from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, describe, expect, it, vi } from "vitest";
import { makeOutputFolder } from "./outputFolder.js";
// Windows answers a recursive mkdir of a drive root (D:\) with EPERM though the root exists, so an output there
// failed before it was written. makeOutputFolder leaves an existing folder alone; this mock stands in for Windows.
vi.mock("node:fs", async (importOriginal) => {
const real = await importOriginal<typeof import("node:fs")>();
return {
...real,
mkdirSync: vi.fn((path: string, options: fs.MakeDirectoryOptions) => {
if (real.statSync(path, { throwIfNoEntry: false })?.isDirectory())
throw Object.assign(new Error(`EPERM: operation not permitted, mkdir '${path}'`), {
code: "EPERM",
});
return real.mkdirSync(path, options);
}),
};
});
describe("makeOutputFolder", () => {
const made: string[] = [];
afterEach(() => {
for (const dir of made.splice(0)) fs.rmSync(dir, { recursive: true, force: true });
});
it("leaves a folder that is already there, as a drive root is, alone", () => {
const root = fs.mkdtempSync(join(tmpdir(), "hf-output-root-"));
made.push(root);
expect(() => makeOutputFolder(root)).not.toThrow();
});
it("makes a missing folder and the folders above it", () => {
const root = fs.mkdtempSync(join(tmpdir(), "hf-output-new-"));
made.push(root);
const dir = join(root, "renders", "today");
makeOutputFolder(dir);
expect(fs.statSync(dir).isDirectory()).toBe(true);
});
it("still refuses a path that is a file", () => {
const root = fs.mkdtempSync(join(tmpdir(), "hf-output-file-"));
made.push(root);
const file = join(root, "film.mp4");
fs.writeFileSync(file, "");
expect(() => makeOutputFolder(file)).toThrow(/EEXIST/);
});
});
+7
View File
@@ -0,0 +1,7 @@
import { mkdirSync, statSync } from "node:fs";
const isFolder = (dir: string) => statSync(dir, { throwIfNoEntry: false })?.isDirectory() === true;
export function makeOutputFolder(dir: string): void {
if (!isFolder(dir)) mkdirSync(dir, { recursive: true });
}