Last change
on this file since fa375fe was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
856 bytes
|
Line | |
---|
1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.makeStaticFileCache = makeStaticFileCache;
|
---|
7 |
|
---|
8 | var _caching = require("../caching");
|
---|
9 |
|
---|
10 | var fs = require("../../gensync-utils/fs");
|
---|
11 |
|
---|
12 | function _fs2() {
|
---|
13 | const data = require("fs");
|
---|
14 |
|
---|
15 | _fs2 = function () {
|
---|
16 | return data;
|
---|
17 | };
|
---|
18 |
|
---|
19 | return data;
|
---|
20 | }
|
---|
21 |
|
---|
22 | function makeStaticFileCache(fn) {
|
---|
23 | return (0, _caching.makeStrongCache)(function* (filepath, cache) {
|
---|
24 | const cached = cache.invalidate(() => fileMtime(filepath));
|
---|
25 |
|
---|
26 | if (cached === null) {
|
---|
27 | return null;
|
---|
28 | }
|
---|
29 |
|
---|
30 | return fn(filepath, yield* fs.readFile(filepath, "utf8"));
|
---|
31 | });
|
---|
32 | }
|
---|
33 |
|
---|
34 | function fileMtime(filepath) {
|
---|
35 | if (!_fs2().existsSync(filepath)) return null;
|
---|
36 |
|
---|
37 | try {
|
---|
38 | return +_fs2().statSync(filepath).mtime;
|
---|
39 | } catch (e) {
|
---|
40 | if (e.code !== "ENOENT" && e.code !== "ENOTDIR") throw e;
|
---|
41 | }
|
---|
42 |
|
---|
43 | return null;
|
---|
44 | } |
---|
Note:
See
TracBrowser
for help on using the repository browser.