hardhat
Version:
Hardhat is an extensible developer tool that helps smart contract developers increase productivity by reliably bringing together the tools they want.
22 lines • 797 B
JavaScript
import path from "node:path";
import { move, readJsonFile, writeJsonFile, } from "@nomicfoundation/hardhat-utils/fs";
const CACHE_FILE_NAME = `compile-cache.json`;
export async function loadCache(cacheDirectory) {
let cache;
try {
cache = await readJsonFile(path.join(cacheDirectory, CACHE_FILE_NAME));
}
catch (_error) {
cache = {};
}
return cache;
}
export async function saveCache(cacheDirectory, cache) {
const filePath = path.join(cacheDirectory, CACHE_FILE_NAME);
const tmpPath = `${filePath}.tmp`;
// NOTE: We are writing to a temporary file first so that an interrupted
// write can't leave a corrupted file in the cache.
await writeJsonFile(tmpPath, cache);
await move(tmpPath, filePath);
}
//# sourceMappingURL=cache.js.map