import { chmod, readdir, stat } from "node:fs/promises"; import path from "node:path"; /** * 13-02. dist is published as-is to a web server that may run as another OS * user, so every file in it must be readable by others. The validated JSON * writer creates files 0600 on purpose (evidence under artifacts/ stays * private); the build adds read bits to what it publishes instead of loosening * that writer. */ export async function makeDistFilesPublic(directory: string): Promise { for (const entry of await readdir(directory, { recursive: true, withFileTypes: true })) { if (!entry.isFile()) continue; const file = path.join(entry.parentPath, entry.name); const { mode } = await stat(file); if ((mode & 0o004) === 0) await chmod(file, (mode & 0o7777) | 0o444); } }