Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/cli/src/browser/preflight.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// fallow-ignore-file code-duplication
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { parseToolVersion, runEnvironmentChecks } from "./preflight.js";
import { checkDisk, parseToolVersion, runEnvironmentChecks } from "./preflight.js";
import * as manager from "./manager.js";
import * as linuxDeps from "./linuxDeps.js";

Expand Down Expand Up @@ -187,3 +187,15 @@ describe("parseToolVersion", () => {
);
});
});

describe("checkDisk", () => {
it("checks the requested render volume", () => {
const freeDiskMb = vi.fn(() => 512);

expect(checkDisk("/external/render-output", freeDiskMb)).toMatchObject({
ok: false,
detail: "0.5 GB free at /external/render-output",
});
expect(freeDiskMb).toHaveBeenCalledWith("/external/render-output");
});
});
15 changes: 10 additions & 5 deletions packages/cli/src/browser/preflight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface EnvironmentCheckResult {

export interface EnvironmentCheckOptions {
projectDir?: string;
diskPaths?: string[];
browserPath?: string;
includeBrowser?: boolean;
includeDisk?: boolean;
Expand Down Expand Up @@ -205,8 +206,11 @@ async function checkChrome(browserPath?: string): Promise<EnvironmentCheckOutcom
};
}

function checkDisk(projectDir = "."): EnvironmentCheckOutcome {
const freeMb = getFreeDiskMb(projectDir);
export function checkDisk(
path = ".",
freeDiskMb: (path: string) => number | null = getFreeDiskMb,
): EnvironmentCheckOutcome {
const freeMb = freeDiskMb(path);
if (freeMb === null) {
return { name: "Disk", ok: true, level: "ok", detail: "Unable to check" };
}
Expand All @@ -217,11 +221,11 @@ function checkDisk(projectDir = "."): EnvironmentCheckOutcome {
ok: false,
level: "error",
title: "Low disk space",
detail: `${freeGb} GB free`,
detail: `${freeGb} GB free at ${path}`,
hint: "Renders produce large temp files. Free disk space before rendering.",
};
}
return { name: "Disk", ok: true, level: "ok", detail: `${freeGb} GB free` };
return { name: "Disk", ok: true, level: "ok", detail: `${freeGb} GB free at ${path}` };
}

function checkWindowsUncPath(projectDir = process.cwd()): EnvironmentCheckOutcome | undefined {
Expand Down Expand Up @@ -260,7 +264,8 @@ export async function runEnvironmentChecks(
}

if (options.includeDisk) {
outcomes.push(checkDisk(options.projectDir));
const diskPaths = [...new Set(options.diskPaths ?? [options.projectDir ?? "."])];
outcomes.push(...diskPaths.map((path) => checkDisk(path)));
}

if (options.includeWindowsUnc) {
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,7 @@ export async function renderLocal(
): Promise<SingleRenderResult> {
const preflight = await runEnvironmentChecks({
projectDir,
diskPaths: [tmpdir(), dirname(outputPath)],
browserPath: options.browserPath,
includeBrowser: true,
includeDisk: true,
Expand Down
Loading