Skip to content

Commit 50ce9fb

Browse files
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
1 parent 6857bb0 commit 50ce9fb

14 files changed

Lines changed: 90 additions & 32 deletions

File tree

‎packages/cli/src/cloud/download.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
* existing destination is replaced only after the download succeeds.
1414
*/
1515

16-
import { chmodSync, mkdirSync, mkdtempSync, renameSync, rmSync, statSync } from "node:fs";
16+
import { chmodSync, mkdtempSync, renameSync, rmSync, statSync } from "node:fs";
17+
import { makeOutputFolder } from "../utils/outputFolder.js";
1718
import { open } from "node:fs/promises";
1819
import { dirname, join } from "node:path";
1920
import { setTimeout as sleep } from "node:timers/promises";
@@ -73,7 +74,7 @@ export async function downloadToFile(
7374
const ranged = first.status === 206;
7475
const total = ranged ? contentRangeTotal(first) : contentLength(first);
7576

76-
mkdirSync(dirname(destPath), { recursive: true });
77+
makeOutputFolder(dirname(destPath));
7778

7879
// Writes through a caller-selected symlink, as before.
7980
const destination = resolveWritePath(destPath);

‎packages/cli/src/commands/batchRender.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { failCommand } from "../utils/commandResult.js";
2-
import { mkdirSync, writeFileSync } from "node:fs";
2+
import { writeFileSync } from "node:fs";
3+
import { makeOutputFolder } from "../utils/outputFolder.js";
34
import { readJsonFileText } from "../utils/jsonFlag.js";
45
import { dirname, join, resolve, sep } from "node:path";
56
import { c } from "../ui/colors.js";
@@ -319,7 +320,7 @@ function summarizeManifest(manifest: BatchManifest): void {
319320

320321
function writeManifest(manifest: BatchManifest): void {
321322
summarizeManifest(manifest);
322-
mkdirSync(dirname(manifest.manifestPath), { recursive: true });
323+
makeOutputFolder(dirname(manifest.manifestPath));
323324
writeFileSync(manifest.manifestPath, JSON.stringify(manifest, null, 2) + "\n", "utf8");
324325
}
325326

@@ -341,7 +342,7 @@ async function renderBatchRow(
341342
}
342343

343344
try {
344-
mkdirSync(dirname(row.outputPath), { recursive: true });
345+
makeOutputFolder(dirname(row.outputPath));
345346
const result = await options.renderOne(row);
346347
manifestRow.status = "completed";
347348
manifestRow.durationMs = result.durationMs ?? null;

‎packages/cli/src/commands/compare.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
rmSync,
1010
statSync,
1111
} from "node:fs";
12+
import { makeOutputFolder } from "../utils/outputFolder.js";
1213
import { tmpdir } from "node:os";
1314
import { basename, dirname, extname, join } from "node:path";
1415
import { defineCommand } from "../utils/defineCommand.js";
@@ -364,7 +365,7 @@ async function renderCompareSheet(parsed: ParsedCompareArgs): Promise<CompareSuc
364365
renderReadyTimedOut = renderReadyTimedOut || rendered.renderReadyTimedOut;
365366
}
366367

367-
mkdirSync(dirname(parsed.outPath), { recursive: true });
368+
makeOutputFolder(dirname(parsed.outPath));
368369
await createContactSheet(framePaths, parsed.outPath, {
369370
cols: parsed.cols ?? defaultCompareCols(framePaths.length),
370371
maxImages: framePaths.length,

‎packages/cli/src/commands/grade-compare.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import {
22
copyFileSync,
33
existsSync,
4-
mkdirSync,
54
mkdtempSync,
65
readFileSync,
76
rmSync,
87
writeFileSync,
98
} from "node:fs";
9+
import { makeOutputFolder } from "../utils/outputFolder.js";
1010
import { readJsonFileText } from "../utils/jsonFlag.js";
1111
import { tmpdir } from "node:os";
1212
import { basename, dirname, extname, join, resolve } from "node:path";
@@ -670,7 +670,7 @@ export default defineCommand({
670670
prepared.tempDir,
671671
parsed.timeoutMs,
672672
);
673-
mkdirSync(dirname(parsed.outPath), { recursive: true });
673+
makeOutputFolder(dirname(parsed.outPath));
674674
copyFileSync(tempSheet, parsed.outPath);
675675
trackCompareSheet({
676676
command: "grade-compare",

‎packages/cli/src/commands/measure/extract.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Pixels from the original, as project media: a still at one moment or a clip over a window, cropped to a region,
22
// frame-exact, recorded in the media ledger as cut from the original. A rebuild reuses footage, photos and people
33
// this way instead of drawing or generating them.
4-
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
4+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
5+
import { makeOutputFolder } from "../../utils/outputFolder.js";
56
import { tmpdir } from "node:os";
67
import { dirname, join, relative, resolve } from "node:path";
78
import { defineCommand } from "../../utils/defineCommand.js";
@@ -172,7 +173,7 @@ export default defineCommand({
172173
await runMeasure(async () => {
173174
const { info, roi: asked } = videoAndRoi(args.video, args.roi);
174175
const out = resolve(String(args.out));
175-
mkdirSync(dirname(out), { recursive: true });
176+
makeOutputFolder(dirname(out));
176177
if (/\.(m4a|aac|mp3|wav)$/i.test(out)) {
177178
const sound = cutSound(
178179
info,

‎packages/cli/src/commands/measure/probe.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import {
1010
type VideoInfo,
1111
} from "../../measure/media.js";
1212
import { execFileSync } from "node:child_process";
13-
import { mkdirSync } from "node:fs";
1413
import { dirname, resolve } from "node:path";
14+
import { makeOutputFolder } from "../../utils/outputFolder.js";
1515

1616
export const examples: Example[] = [
1717
[
@@ -57,7 +57,7 @@ function normalize(info: VideoInfo, out: string): { path: string; fps: string }
5757
"zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv",
5858
);
5959
}
60-
mkdirSync(dirname(out), { recursive: true });
60+
makeOutputFolder(dirname(out));
6161
runFfmpeg([
6262
...["-y", "-i", info.path, "-vf", [...filters, "format=yuv420p"].join(",")],
6363
...["-c:v", "libx264", "-crf", "12", "-preset", "medium", "-c:a", "aac", "-b:a", "192k", out],

‎packages/cli/src/commands/motionShot.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import { launchManagedBrowser, resolveManagedGpuMode } from "../browser/launch.j
1111
// exactly what it's editing. All geometry + SVG live in ./motionShotLayout.ts
1212
// (pure, tested); this file only drives the browser and SAMPLES.
1313

14-
import { mkdirSync, statSync, writeFileSync } from "node:fs";
14+
import { statSync, writeFileSync } from "node:fs";
15+
import { makeOutputFolder } from "../utils/outputFolder.js";
1516
import { dirname, resolve } from "node:path";
1617
import { pageNavigationTimeoutMs } from "../utils/renderArgs.js";
1718
import { gotoWhenSent } from "../capture/navigateForCapture.js";
@@ -59,7 +60,7 @@ export function ensureShotOutputDir(outPath: string, sourcePath?: string): void
5960
`--shot output must not overwrite the composition source: ${sourcePath}. Choose a separate .png path.`,
6061
);
6162
}
62-
mkdirSync(dirname(outPath), { recursive: true });
63+
makeOutputFolder(dirname(outPath));
6364
}
6465

6566
/** Returned by the in-browser selector resolver: which animated selectors a

‎packages/cli/src/commands/render/execute.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// fallow-ignore-file code-duplication
2-
import { mkdirSync, readFileSync } from "node:fs";
2+
import { readFileSync } from "node:fs";
33
import { tmpdir } from "node:os";
44
import type { CanvasResolution, OutputResolutionIssueKind } from "@hyperframes/core";
55
import { PRORES_PROFILES } from "@hyperframes/engine";
@@ -13,6 +13,7 @@ import {
1313
type ProjectLintResult,
1414
} from "../../utils/lintProject.js";
1515
import { normalizeErrorMessage } from "../../utils/errorMessage.js";
16+
import { makeOutputFolder } from "../../utils/outputFolder.js";
1617
import { failCommand, setCommandExitCode } from "../../utils/commandResult.js";
1718
import {
1819
reportVariableIssues,
@@ -71,7 +72,7 @@ export async function executeRenderPlan(
7172
): Promise<void> {
7273
assertRenderActive(cancellation);
7374
applyRenderEnvironment(plan);
74-
if (!plan.batchPath) mkdirSync(renderOutputDirectory(plan), { recursive: true });
75+
if (!plan.batchPath) makeOutputFolder(renderOutputDirectory(plan));
7576

7677
let batchModule: typeof import("../batchRender.js") | undefined;
7778
let preparedBatch: import("../batchRender.js").PreparedBatchRender | undefined;

‎packages/cli/src/commands/templates.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
statSync,
1313
writeFileSync,
1414
} from "node:fs";
15+
import { makeOutputFolder } from "../utils/outputFolder.js";
1516
import { dirname, join, resolve } from "node:path";
1617
import { resolveCloudAuthHeaders } from "../cloud/auth.js";
1718
import { billingBaseUrl } from "../heygen/plan.js";
@@ -110,7 +111,7 @@ const PULLED_HASH = ".template-sha256";
110111

111112
/** Unpacks the pack beside `dest` and moves it in whole, so `dest` only ever holds a complete template. */
112113
function unpack(data: Buffer, dest: string, pack: TemplatePack): void {
113-
mkdirSync(dirname(dest), { recursive: true });
114+
makeOutputFolder(dirname(dest));
114115
const work = mkdtempSync(`${dest}.part-`);
115116
try {
116117
const out = join(work, "template");

‎packages/cli/src/fileIds.windows.test.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import { join } from "node:path";
66
// Number-mode stats report one identity for every path, as Windows file ids above 2^53 can.
77
vi.mock("node:fs", async (importOriginal) => {
88
const actual = await importOriginal<typeof import("node:fs")>();
9-
const statSync = ((path: string, options?: { bigint?: boolean }) =>
10-
options?.bigint
11-
? actual.statSync(path, options as never)
12-
: { ...actual.statSync(path), dev: 1, ino: 2 ** 53 }) as typeof actual.statSync;
9+
const statSync = ((path: string, options?: { bigint?: boolean }) => {
10+
const stats = actual.statSync(path, options as never);
11+
return options?.bigint || !stats ? stats : Object.assign(stats, { dev: 1, ino: 2 ** 53 });
12+
}) as typeof actual.statSync;
1313
return { ...actual, statSync };
1414
});
1515

0 commit comments

Comments
 (0)