UNPKG

@argos-ci/util

Version:
89 lines (84 loc) 2.27 kB
import { getMetadataPath, getScreenshotName, validateThreshold } from "./chunk-VMM7XHBS.js"; // src/git.ts import { exec } from "node:child_process"; var cached; function getGitRepositoryPath() { if (!cached) { cached = new Promise((resolve) => { exec("git rev-parse --show-toplevel", (error, stdout, stderr) => { if (error) { resolve(null); } if (stderr) { resolve(null); } resolve(stdout.trim()); }); }); } return cached; } // src/introspection.ts import { readFile } from "node:fs/promises"; var versionCache = /* @__PURE__ */ new Map(); function readVersionFromPackage(pkgPath) { const readVersion = async () => { const { version } = JSON.parse(await readFile(pkgPath, "utf-8")); if (typeof version !== "string") { throw new Error("Invalid version"); } return version; }; if (!versionCache.has(pkgPath)) { versionCache.set(pkgPath, readVersion()); } const fromCache = versionCache.get(pkgPath); if (!fromCache) { throw new Error("Invariant violation: version not in cache"); } return fromCache; } // src/metadata-io.ts import { readFile as readFile2, writeFile } from "node:fs/promises"; async function writeMetadata(screenshotPath, metadata) { await writeFile(getMetadataPath(screenshotPath), JSON.stringify(metadata)); } async function readMetadata(screenshotPath) { try { const metadata = await readFile2(getMetadataPath(screenshotPath), "utf8"); return JSON.parse(metadata); } catch (error) { if (error instanceof Error && "code" in error && error.code === "ENOENT") { return null; } throw new Error("Failed to read metadata", { cause: error }); } } // src/playwright-trace.ts import { access } from "node:fs/promises"; function getTracePath(screenshotPath) { return screenshotPath + ".pw-trace.zip"; } async function getPlaywrightTracePath(screenshotPath) { try { const tracePath = getTracePath(screenshotPath); await access(tracePath); return tracePath; } catch { return null; } } export { getGitRepositoryPath, getMetadataPath, getPlaywrightTracePath, getScreenshotName, readMetadata, readVersionFromPackage, validateThreshold, writeMetadata };