Reduce duplication by using withTmpDir in withTmpFile

This commit is contained in:
Mario Campos
2026-09-10 15:37:39 -05:00
parent 4375107b7e
commit f6491d646e

View File

@@ -95,16 +95,11 @@ export async function withTmpFile<T>(
contents: string,
body: (filePath: string) => Promise<T> | T,
): Promise<T> {
const tmpDir = fs.mkdtempSync(
path.join(os.tmpdir(), "changetool-validate-test-"),
);
try {
return withTmpDir(async (tmpDir) => {
const filePath = path.join(tmpDir, baseFileName);
fs.writeFileSync(filePath, contents);
return await body(filePath);
} finally {
fs.rmSync(tmpDir, { recursive: true, force: true });
}
return body(filePath);
});
}
/**