mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
* fix(cli): staging folders beside a project path no longer fail past 260 characters on Windows mkdtemp does not get the long-path prefix that mkdir does, so every staging folder made beside a project or output path failed once its full path passed 260 characters. They now come from one helper, createStagingDir in @hyperframes/core/atomic-file, and a scan test fails on a new mkdtemp beside a path. * fix(cli): give mkdtemp the long-path form instead of replacing it CodeQL treats mkdtemp as the safe way to make a folder under the system temp dir and flagged every file written into a folder from the mkdir-based helper. createStagingDir now calls mkdtemp with the long-path form of the path on Windows, so both hold. * fix(cli): leave non-Windows paths alone when making a staging folder The long-path form is now chosen by the shape of the path, not process.platform, so tests that pretend to be Windows keep working and the comment share does not rise. * fix(core): a staging folder keeps a Windows path that already names its namespace * fix(core): a staging folder keeps a Windows device path as the caller gave it * fix(core): the staging folder helper's comment fits the line limit
49 lines
1.8 KiB
TypeScript
49 lines
1.8 KiB
TypeScript
import { readdirSync, readFileSync, statSync } from "node:fs";
|
|
import { dirname, join, relative } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { expect, it } from "vitest";
|
|
|
|
const packagesDir = join(dirname(fileURLToPath(import.meta.url)), "..", "..");
|
|
const SOURCE = /\.(ts|mjs)$/;
|
|
const NOT_SOURCE = /\.(test|fixture)\.|[\\/](tests?|node_modules|dist)[\\/]/;
|
|
const MKDTEMP = /\bmkdtemp(Sync)?\(/;
|
|
|
|
// Not beside a project or output path: a system temp root, a standalone skill script, a cloud function's scratch root.
|
|
const ALLOWED = new Set([
|
|
"core/src/atomicFile.ts",
|
|
"cli/src/media-use/lib/lut-preset-provider.mjs",
|
|
"producer/src/server.ts",
|
|
"producer/src/regression-harness.ts",
|
|
"aws-lambda/src/s3PlanV2Publisher.ts",
|
|
"gcp-cloud-run/src/gcsPlanV2Publisher.ts",
|
|
]);
|
|
|
|
function sources(dir: string): string[] {
|
|
return readdirSync(dir).flatMap((name) => {
|
|
const path = join(dir, name);
|
|
if (NOT_SOURCE.test(path)) return [];
|
|
return statSync(path).isDirectory() ? sources(path) : SOURCE.test(name) ? [path] : [];
|
|
});
|
|
}
|
|
|
|
it("no package makes a staging folder beside a project path with mkdtemp, which fails past 260 characters on Windows", () => {
|
|
const offenders = readdirSync(packagesDir).flatMap((pkg) => {
|
|
const src = join(packagesDir, pkg, "src");
|
|
try {
|
|
statSync(src);
|
|
} catch {
|
|
return [];
|
|
}
|
|
return sources(src).flatMap((file) => {
|
|
const rel = relative(packagesDir, file).split("\\").join("/");
|
|
if (ALLOWED.has(rel)) return [];
|
|
return readFileSync(file, "utf8")
|
|
.split("\n")
|
|
.flatMap((line, i) =>
|
|
MKDTEMP.test(line) && !/tmpdir|^\s*(\/\/|\*)/.test(line) ? [`${rel}:${i + 1}`] : [],
|
|
);
|
|
});
|
|
});
|
|
expect(offenders, "use createStagingDir from @hyperframes/core/atomic-file").toEqual([]);
|
|
});
|