1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | 'use strict';
|
11 |
|
12 | var _defineProperty2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/defineProperty"));
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | var RelayCompilerCache =
|
19 |
|
20 | function () {
|
21 | |
22 |
|
23 |
|
24 |
|
25 |
|
26 | function RelayCompilerCache(name, cacheBreaker) {
|
27 | (0, _defineProperty2["default"])(this, "_dir", null);
|
28 | this._name = name;
|
29 | this._cacheBreaker = cacheBreaker;
|
30 | }
|
31 |
|
32 | var _proto = RelayCompilerCache.prototype;
|
33 |
|
34 | _proto._getFile = function _getFile(key) {
|
35 | if (this._dir == null) {
|
36 |
|
37 |
|
38 | var username = require("os").userInfo().username;
|
39 |
|
40 | var cacheID = require("crypto").createHash('md5').update(this._cacheBreaker).update(username).digest('hex');
|
41 |
|
42 | var dir = require("path").join(require("os").tmpdir(), "".concat(this._name, "-").concat(cacheID));
|
43 |
|
44 | if (!require("fs").existsSync(dir)) {
|
45 | try {
|
46 | require("fs").mkdirSync(dir);
|
47 | } catch (error) {
|
48 | if (error.code !== 'EEXIST') {
|
49 | throw error;
|
50 | }
|
51 | }
|
52 | }
|
53 |
|
54 | this._dir = dir;
|
55 | }
|
56 |
|
57 | return require("path").join(this._dir, key);
|
58 | };
|
59 |
|
60 | _proto.getOrCompute = function getOrCompute(key, compute) {
|
61 | var _this = this;
|
62 |
|
63 | return require("./GraphQLCompilerProfiler").run('RelayCompilerCache.getOrCompute', function () {
|
64 | var cacheFile = _this._getFile(key);
|
65 |
|
66 | if (require("fs").existsSync(cacheFile)) {
|
67 | try {
|
68 | return JSON.parse(require("fs").readFileSync(cacheFile, 'utf8'));
|
69 | } catch (_unused) {
|
70 | }
|
71 | }
|
72 |
|
73 | var value = compute();
|
74 |
|
75 | try {
|
76 | require("fs").writeFileSync(cacheFile, JSON.stringify(value), 'utf8');
|
77 | } catch (_unused2) {
|
78 | }
|
79 |
|
80 | return value;
|
81 | });
|
82 | };
|
83 |
|
84 | return RelayCompilerCache;
|
85 | }();
|
86 |
|
87 | module.exports = RelayCompilerCache; |
\ | No newline at end of file |