UNPKG

@intlayer/chokidar

Version:

Uses chokidar to scan and build Intlayer declaration files into dictionaries based on Intlayer configuration.

34 lines 924 B
import { mkdir, stat, unlink, writeFile } from "fs/promises"; import { dirname } from "path"; const runOnce = async (sentinelFilePath, callback, cacheTimeoutMs = 60 * 1e3) => { const currentTimestamp = Date.now(); const timeoutDuration = cacheTimeoutMs; try { const sentinelStats = await stat(sentinelFilePath); const sentinelAge = currentTimestamp - sentinelStats.mtime.getTime(); if (sentinelAge > timeoutDuration) { await unlink(sentinelFilePath); } else { return; } } catch (err) { if (err.code === "ENOENT") { } else { throw err; } } try { await mkdir(dirname(sentinelFilePath), { recursive: true }); await writeFile(sentinelFilePath, String(currentTimestamp), { flag: "wx" }); } catch (err) { if (err.code === "EEXIST") { return; } throw err; } await callback(); }; export { runOnce }; //# sourceMappingURL=runOnce.mjs.map