779434731ee97a4436a20a5784850460ba7b6da8e1728b6c67fcf154fb9cd117ea8041050281ebf36da13af0ffe9e38af84ea7793586f215aab7210317be14 895 B

123456789101112131415161718192021222324252627282930313233343536
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.makeStaticFileCache = makeStaticFileCache;
  6. var _caching = require("../caching.js");
  7. var fs = require("../../gensync-utils/fs.js");
  8. function _fs2() {
  9. const data = require("fs");
  10. _fs2 = function () {
  11. return data;
  12. };
  13. return data;
  14. }
  15. function makeStaticFileCache(fn) {
  16. return (0, _caching.makeStrongCache)(function* (filepath, cache) {
  17. const cached = cache.invalidate(() => fileMtime(filepath));
  18. if (cached === null) {
  19. return null;
  20. }
  21. return fn(filepath, yield* fs.readFile(filepath, "utf8"));
  22. });
  23. }
  24. function fileMtime(filepath) {
  25. if (!_fs2().existsSync(filepath)) return null;
  26. try {
  27. return +_fs2().statSync(filepath).mtime;
  28. } catch (e) {
  29. if (e.code !== "ENOENT" && e.code !== "ENOTDIR") throw e;
  30. }
  31. return null;
  32. }
  33. 0 && 0;
  34. //# sourceMappingURL=utils.js.map