@modern-js/prod-server 2.0.0-beta.2 → 2.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +132 -0
- package/dist/js/modern/constants.js +32 -25
- package/dist/js/modern/index.js +11 -6
- package/dist/js/modern/libs/context/context.js +52 -84
- package/dist/js/modern/libs/context/index.js +5 -2
- package/dist/js/modern/libs/hook-api/index.js +42 -35
- package/dist/js/modern/libs/hook-api/route.js +6 -7
- package/dist/js/modern/libs/hook-api/template.js +20 -34
- package/dist/js/modern/libs/loadConfig.js +45 -24
- package/dist/js/modern/libs/metrics.js +3 -4
- package/dist/js/modern/libs/proxy.js +68 -37
- package/dist/js/modern/libs/render/cache/__tests__/cache.fun.test.js +112 -67
- package/dist/js/modern/libs/render/cache/__tests__/cache.test.js +246 -216
- package/dist/js/modern/libs/render/cache/__tests__/cacheable.js +43 -49
- package/dist/js/modern/libs/render/cache/__tests__/error-configuration.js +36 -34
- package/dist/js/modern/libs/render/cache/__tests__/matched-cache.js +83 -113
- package/dist/js/modern/libs/render/cache/index.js +88 -54
- package/dist/js/modern/libs/render/cache/page-caches/index.js +31 -8
- package/dist/js/modern/libs/render/cache/page-caches/lru.js +6 -6
- package/dist/js/modern/libs/render/cache/spr.js +133 -117
- package/dist/js/modern/libs/render/cache/type.js +0 -1
- package/dist/js/modern/libs/render/cache/util.js +71 -39
- package/dist/js/modern/libs/render/index.js +76 -56
- package/dist/js/modern/libs/render/measure.js +38 -27
- package/dist/js/modern/libs/render/reader.js +65 -62
- package/dist/js/modern/libs/render/ssr.js +50 -32
- package/dist/js/modern/libs/render/static.js +50 -33
- package/dist/js/modern/libs/render/type.js +9 -6
- package/dist/js/modern/libs/route/index.js +8 -15
- package/dist/js/modern/libs/route/matcher.js +20 -34
- package/dist/js/modern/libs/route/route.js +9 -18
- package/dist/js/modern/libs/serve-file.js +33 -20
- package/dist/js/modern/server/index.js +144 -145
- package/dist/js/modern/server/modern-server-split.js +46 -12
- package/dist/js/modern/server/modern-server.js +377 -419
- package/dist/js/modern/type.js +0 -1
- package/dist/js/modern/utils.js +62 -43
- package/dist/js/modern/worker-server.js +34 -14
- package/dist/js/node/constants.js +45 -30
- package/dist/js/node/index.js +31 -57
- package/dist/js/node/libs/context/context.js +79 -94
- package/dist/js/node/libs/context/index.js +23 -13
- package/dist/js/node/libs/hook-api/index.js +69 -48
- package/dist/js/node/libs/hook-api/route.js +22 -11
- package/dist/js/node/libs/hook-api/template.js +36 -39
- package/dist/js/node/libs/loadConfig.js +69 -35
- package/dist/js/node/libs/metrics.js +21 -9
- package/dist/js/node/libs/proxy.js +86 -44
- package/dist/js/node/libs/render/cache/__tests__/cache.fun.test.js +132 -70
- package/dist/js/node/libs/render/cache/__tests__/cache.test.js +268 -218
- package/dist/js/node/libs/render/cache/__tests__/cacheable.js +61 -55
- package/dist/js/node/libs/render/cache/__tests__/error-configuration.js +54 -40
- package/dist/js/node/libs/render/cache/__tests__/matched-cache.js +101 -119
- package/dist/js/node/libs/render/cache/index.js +110 -64
- package/dist/js/node/libs/render/cache/page-caches/index.js +50 -14
- package/dist/js/node/libs/render/cache/page-caches/lru.js +29 -12
- package/dist/js/node/libs/render/cache/spr.js +156 -129
- package/dist/js/node/libs/render/cache/type.js +0 -5
- package/dist/js/node/libs/render/cache/util.js +88 -45
- package/dist/js/node/libs/render/index.js +102 -67
- package/dist/js/node/libs/render/measure.js +55 -31
- package/dist/js/node/libs/render/reader.js +87 -70
- package/dist/js/node/libs/render/ssr.js +76 -47
- package/dist/js/node/libs/render/static.js +75 -40
- package/dist/js/node/libs/render/type.js +27 -12
- package/dist/js/node/libs/route/index.js +26 -26
- package/dist/js/node/libs/route/matcher.js +36 -41
- package/dist/js/node/libs/route/route.js +25 -22
- package/dist/js/node/libs/serve-file.js +61 -32
- package/dist/js/node/server/index.js +160 -160
- package/dist/js/node/server/modern-server-split.js +68 -22
- package/dist/js/node/server/modern-server.js +395 -443
- package/dist/js/node/type.js +0 -3
- package/dist/js/node/utils.js +74 -52
- package/dist/js/node/worker-server.js +53 -21
- package/dist/js/treeshaking/constants.js +26 -25
- package/dist/js/treeshaking/index.js +10 -10
- package/dist/js/treeshaking/libs/context/context.js +268 -237
- package/dist/js/treeshaking/libs/context/index.js +3 -3
- package/dist/js/treeshaking/libs/hook-api/index.js +265 -143
- package/dist/js/treeshaking/libs/hook-api/route.js +65 -30
- package/dist/js/treeshaking/libs/hook-api/template.js +121 -85
- package/dist/js/treeshaking/libs/loadConfig.js +80 -37
- package/dist/js/treeshaking/libs/metrics.js +4 -10
- package/dist/js/treeshaking/libs/proxy.js +240 -76
- package/dist/js/treeshaking/libs/render/cache/__tests__/cache.fun.test.js +288 -121
- package/dist/js/treeshaking/libs/render/cache/__tests__/cache.test.js +772 -455
- package/dist/js/treeshaking/libs/render/cache/__tests__/cacheable.js +65 -51
- package/dist/js/treeshaking/libs/render/cache/__tests__/error-configuration.js +45 -35
- package/dist/js/treeshaking/libs/render/cache/__tests__/matched-cache.js +144 -118
- package/dist/js/treeshaking/libs/render/cache/index.js +337 -175
- package/dist/js/treeshaking/libs/render/cache/page-caches/index.js +151 -27
- package/dist/js/treeshaking/libs/render/cache/page-caches/lru.js +80 -42
- package/dist/js/treeshaking/libs/render/cache/spr.js +470 -340
- package/dist/js/treeshaking/libs/render/cache/type.js +1 -1
- package/dist/js/treeshaking/libs/render/cache/util.js +271 -92
- package/dist/js/treeshaking/libs/render/index.js +228 -95
- package/dist/js/treeshaking/libs/render/measure.js +142 -57
- package/dist/js/treeshaking/libs/render/reader.js +325 -177
- package/dist/js/treeshaking/libs/render/ssr.js +220 -95
- package/dist/js/treeshaking/libs/render/static.js +210 -78
- package/dist/js/treeshaking/libs/render/type.js +7 -6
- package/dist/js/treeshaking/libs/route/index.js +125 -89
- package/dist/js/treeshaking/libs/route/matcher.js +132 -107
- package/dist/js/treeshaking/libs/route/route.js +40 -26
- package/dist/js/treeshaking/libs/serve-file.js +177 -68
- package/dist/js/treeshaking/server/index.js +468 -327
- package/dist/js/treeshaking/server/modern-server-split.js +352 -144
- package/dist/js/treeshaking/server/modern-server.js +1046 -911
- package/dist/js/treeshaking/type.js +1 -1
- package/dist/js/treeshaking/utils.js +138 -81
- package/dist/js/treeshaking/worker-server.js +176 -55
- package/dist/types/index.d.ts +2 -0
- package/dist/types/libs/context/context.d.ts +4 -1
- package/dist/types/libs/loadConfig.d.ts +1 -0
- package/dist/types/libs/render/cache/index.d.ts +2 -0
- package/dist/types/libs/render/cache/spr.d.ts +2 -0
- package/dist/types/libs/route/route.d.ts +0 -1
- package/dist/types/server/index.d.ts +3 -0
- package/dist/types/utils.d.ts +1 -1
- package/dist/types/worker-server.d.ts +1 -2
- package/package.json +7 -14
- package/dist/js/modern/libs/render/modern/browser-list.js +0 -7
- package/dist/js/modern/libs/render/modern/index.js +0 -37
- package/dist/js/node/libs/render/modern/browser-list.js +0 -14
- package/dist/js/node/libs/render/modern/index.js +0 -46
- package/dist/js/treeshaking/libs/render/modern/browser-list.js +0 -7
- package/dist/js/treeshaking/libs/render/modern/index.js +0 -39
- package/dist/types/libs/render/modern/browser-list.d.ts +0 -1
- package/dist/types/libs/render/modern/index.d.ts +0 -3
|
@@ -1,191 +1,339 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
+
try {
|
|
3
|
+
var info = gen[key](arg);
|
|
4
|
+
var value = info.value;
|
|
5
|
+
} catch (error) {
|
|
6
|
+
reject(error);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (info.done) {
|
|
10
|
+
resolve(value);
|
|
11
|
+
} else {
|
|
12
|
+
Promise.resolve(value).then(_next, _throw);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function _asyncToGenerator(fn) {
|
|
16
|
+
return function() {
|
|
17
|
+
var self = this, args = arguments;
|
|
18
|
+
return new Promise(function(resolve, reject) {
|
|
19
|
+
var gen = fn.apply(self, args);
|
|
20
|
+
function _next(value) {
|
|
21
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
+
}
|
|
23
|
+
function _throw(err) {
|
|
24
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
+
}
|
|
26
|
+
_next(undefined);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function _classCallCheck(instance, Constructor) {
|
|
31
|
+
if (!(instance instanceof Constructor)) {
|
|
32
|
+
throw new TypeError("Cannot call a class as a function");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function _defineProperties(target, props) {
|
|
36
|
+
for(var i = 0; i < props.length; i++){
|
|
37
|
+
var descriptor = props[i];
|
|
38
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
39
|
+
descriptor.configurable = true;
|
|
40
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
41
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
45
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
46
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
47
|
+
return Constructor;
|
|
48
|
+
}
|
|
49
|
+
function _defineProperty(obj, key, value) {
|
|
50
|
+
if (key in obj) {
|
|
51
|
+
Object.defineProperty(obj, key, {
|
|
52
|
+
value: value,
|
|
53
|
+
enumerable: true,
|
|
54
|
+
configurable: true,
|
|
55
|
+
writable: true
|
|
56
|
+
});
|
|
57
|
+
} else {
|
|
58
|
+
obj[key] = value;
|
|
59
|
+
}
|
|
60
|
+
return obj;
|
|
61
|
+
}
|
|
62
|
+
var __generator = this && this.__generator || function(thisArg, body) {
|
|
63
|
+
var f, y, t, g, _ = {
|
|
64
|
+
label: 0,
|
|
65
|
+
sent: function() {
|
|
66
|
+
if (t[0] & 1) throw t[1];
|
|
67
|
+
return t[1];
|
|
68
|
+
},
|
|
69
|
+
trys: [],
|
|
70
|
+
ops: []
|
|
71
|
+
};
|
|
72
|
+
return(g = {
|
|
73
|
+
next: verb(0),
|
|
74
|
+
"throw": verb(1),
|
|
75
|
+
"return": verb(2)
|
|
76
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
77
|
+
return this;
|
|
78
|
+
}), g);
|
|
79
|
+
function verb(n) {
|
|
80
|
+
return function(v) {
|
|
81
|
+
return step([
|
|
82
|
+
n,
|
|
83
|
+
v
|
|
84
|
+
]);
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function step(op) {
|
|
88
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
89
|
+
while(_)try {
|
|
90
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
91
|
+
if (y = 0, t) op = [
|
|
92
|
+
op[0] & 2,
|
|
93
|
+
t.value
|
|
94
|
+
];
|
|
95
|
+
switch(op[0]){
|
|
96
|
+
case 0:
|
|
97
|
+
case 1:
|
|
98
|
+
t = op;
|
|
99
|
+
break;
|
|
100
|
+
case 4:
|
|
101
|
+
_.label++;
|
|
102
|
+
return {
|
|
103
|
+
value: op[1],
|
|
104
|
+
done: false
|
|
105
|
+
};
|
|
106
|
+
case 5:
|
|
107
|
+
_.label++;
|
|
108
|
+
y = op[1];
|
|
109
|
+
op = [
|
|
110
|
+
0
|
|
111
|
+
];
|
|
112
|
+
continue;
|
|
113
|
+
case 7:
|
|
114
|
+
op = _.ops.pop();
|
|
115
|
+
_.trys.pop();
|
|
116
|
+
continue;
|
|
117
|
+
default:
|
|
118
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
119
|
+
_ = 0;
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
123
|
+
_.label = op[1];
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
127
|
+
_.label = t[1];
|
|
128
|
+
t = op;
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
if (t && _.label < t[2]) {
|
|
132
|
+
_.label = t[2];
|
|
133
|
+
_.ops.push(op);
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
if (t[2]) _.ops.pop();
|
|
137
|
+
_.trys.pop();
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
op = body.call(thisArg, _);
|
|
141
|
+
} catch (e) {
|
|
142
|
+
op = [
|
|
143
|
+
6,
|
|
144
|
+
e
|
|
145
|
+
];
|
|
146
|
+
y = 0;
|
|
147
|
+
} finally{
|
|
148
|
+
f = t = 0;
|
|
149
|
+
}
|
|
150
|
+
if (op[0] & 5) throw op[1];
|
|
151
|
+
return {
|
|
152
|
+
value: op[0] ? op[1] : void 0,
|
|
153
|
+
done: true
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
import { fs } from "@modern-js/utils";
|
|
158
|
+
import LRU from "lru-cache";
|
|
9
159
|
var Byte = 1;
|
|
10
160
|
var KB = 1024 * Byte;
|
|
11
161
|
var MB = 1024 * KB;
|
|
12
|
-
var getContentLength = function
|
|
13
|
-
|
|
162
|
+
var getContentLength = function(cache) {
|
|
163
|
+
return cache.content.length;
|
|
14
164
|
};
|
|
15
|
-
var createCacheItem =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}));
|
|
37
|
-
return function createCacheItem(_x, _x2) {
|
|
38
|
-
return _ref.apply(this, arguments);
|
|
39
|
-
};
|
|
40
|
-
}();
|
|
41
|
-
export var LruReader = /*#__PURE__*/function () {
|
|
42
|
-
// private timer?: NodeJS.Timeout;
|
|
43
|
-
|
|
44
|
-
function LruReader() {
|
|
45
|
-
_classCallCheck(this, LruReader);
|
|
46
|
-
_defineProperty(this, "cache", void 0);
|
|
47
|
-
this.cache = new LRU({
|
|
48
|
-
max: 256 * MB,
|
|
49
|
-
length: getContentLength,
|
|
50
|
-
maxAge: 5 * 60 * 5000 // 60s
|
|
165
|
+
var createCacheItem = function() {
|
|
166
|
+
var _ref = _asyncToGenerator(function(filepath, mtime) {
|
|
167
|
+
var content;
|
|
168
|
+
return __generator(this, function(_state) {
|
|
169
|
+
switch(_state.label){
|
|
170
|
+
case 0:
|
|
171
|
+
return [
|
|
172
|
+
4,
|
|
173
|
+
fs.readFile(filepath)
|
|
174
|
+
];
|
|
175
|
+
case 1:
|
|
176
|
+
content = _state.sent();
|
|
177
|
+
return [
|
|
178
|
+
2,
|
|
179
|
+
{
|
|
180
|
+
content: content,
|
|
181
|
+
mtime: mtime
|
|
182
|
+
}
|
|
183
|
+
];
|
|
184
|
+
}
|
|
185
|
+
});
|
|
51
186
|
});
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
187
|
+
return function createCacheItem(filepath, mtime) {
|
|
188
|
+
return _ref.apply(this, arguments);
|
|
189
|
+
};
|
|
190
|
+
}();
|
|
191
|
+
var LruReader = /*#__PURE__*/ function() {
|
|
192
|
+
"use strict";
|
|
193
|
+
function LruReader() {
|
|
194
|
+
_classCallCheck(this, LruReader);
|
|
195
|
+
_defineProperty(this, "cache", void 0);
|
|
196
|
+
this.cache = new LRU({
|
|
197
|
+
max: 256 * MB,
|
|
198
|
+
length: getContentLength,
|
|
199
|
+
maxAge: 5 * 60 * 5e3
|
|
200
|
+
});
|
|
64
201
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
202
|
+
_createClass(LruReader, [
|
|
203
|
+
{
|
|
204
|
+
key: "init",
|
|
205
|
+
value: function init() {}
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
key: "close",
|
|
209
|
+
value: function close() {}
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
key: "read",
|
|
213
|
+
value: function read(filepath) {
|
|
214
|
+
var _this = this;
|
|
215
|
+
return _asyncToGenerator(function() {
|
|
216
|
+
var content, stat, item;
|
|
217
|
+
return __generator(this, function(_state) {
|
|
218
|
+
switch(_state.label){
|
|
219
|
+
case 0:
|
|
220
|
+
if (_this.cache.has(filepath)) {
|
|
221
|
+
content = _this.cache.get(filepath).content;
|
|
222
|
+
return [
|
|
223
|
+
2,
|
|
224
|
+
{
|
|
225
|
+
content: content
|
|
226
|
+
}
|
|
227
|
+
];
|
|
228
|
+
}
|
|
229
|
+
if (!fs.existsSync(filepath)) {
|
|
230
|
+
return [
|
|
231
|
+
2,
|
|
232
|
+
null
|
|
233
|
+
];
|
|
234
|
+
}
|
|
235
|
+
stat = fs.statSync(filepath);
|
|
236
|
+
if (stat.isDirectory()) {
|
|
237
|
+
return [
|
|
238
|
+
2,
|
|
239
|
+
null
|
|
240
|
+
];
|
|
241
|
+
}
|
|
242
|
+
if (stat.size > 20 * MB) {
|
|
243
|
+
return [
|
|
244
|
+
2,
|
|
245
|
+
null
|
|
246
|
+
];
|
|
247
|
+
}
|
|
248
|
+
return [
|
|
249
|
+
4,
|
|
250
|
+
createCacheItem(filepath, stat.mtime)
|
|
251
|
+
];
|
|
252
|
+
case 1:
|
|
253
|
+
item = _state.sent();
|
|
254
|
+
_this.cache.set(filepath, item);
|
|
255
|
+
return [
|
|
256
|
+
2,
|
|
257
|
+
item
|
|
258
|
+
];
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
})();
|
|
111
262
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
key: "update",
|
|
266
|
+
value: function update() {
|
|
267
|
+
var cache = this.cache;
|
|
268
|
+
var files = cache.keys();
|
|
269
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
270
|
+
try {
|
|
271
|
+
for(var _iterator = files[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
272
|
+
var filepath = _step.value;
|
|
273
|
+
if (!fs.existsSync(filepath)) {
|
|
274
|
+
cache.del(filepath);
|
|
275
|
+
}
|
|
276
|
+
try {
|
|
277
|
+
var item = cache.get(filepath);
|
|
278
|
+
var stat = fs.statSync(filepath);
|
|
279
|
+
var mtime = stat.mtime;
|
|
280
|
+
if (item.mtime < mtime) {
|
|
281
|
+
cache.del(filepath);
|
|
282
|
+
}
|
|
283
|
+
} catch (e) {
|
|
284
|
+
cache.del(filepath);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
} catch (err) {
|
|
288
|
+
_didIteratorError = true;
|
|
289
|
+
_iteratorError = err;
|
|
290
|
+
} finally{
|
|
291
|
+
try {
|
|
292
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
293
|
+
_iterator.return();
|
|
294
|
+
}
|
|
295
|
+
} finally{
|
|
296
|
+
if (_didIteratorError) {
|
|
297
|
+
throw _iteratorError;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
140
301
|
}
|
|
141
|
-
} catch (e) {
|
|
142
|
-
// for safe
|
|
143
|
-
cache.del(filepath);
|
|
144
|
-
}
|
|
145
302
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
} finally {
|
|
149
|
-
_iterator.f();
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// private timeTask() {
|
|
154
|
-
// this.timer = setInterval(() => this.update, 5 * 60 * 1000).unref();
|
|
155
|
-
// }
|
|
156
|
-
}]);
|
|
157
|
-
return LruReader;
|
|
303
|
+
]);
|
|
304
|
+
return LruReader;
|
|
158
305
|
}();
|
|
159
306
|
var reader = new LruReader();
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
307
|
+
var readFile = function() {
|
|
308
|
+
var _ref = _asyncToGenerator(function(filepath) {
|
|
309
|
+
var file;
|
|
310
|
+
return __generator(this, function(_state) {
|
|
311
|
+
switch(_state.label){
|
|
312
|
+
case 0:
|
|
313
|
+
return [
|
|
314
|
+
4,
|
|
315
|
+
reader.read(filepath)
|
|
316
|
+
];
|
|
317
|
+
case 1:
|
|
318
|
+
file = _state.sent();
|
|
319
|
+
return [
|
|
320
|
+
2,
|
|
321
|
+
file === null || file === void 0 ? void 0 : file.content
|
|
322
|
+
];
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
return function readFile(filepath) {
|
|
327
|
+
return _ref.apply(this, arguments);
|
|
328
|
+
};
|
|
182
329
|
}();
|
|
183
|
-
|
|
184
|
-
|
|
330
|
+
var updateFile = function() {
|
|
331
|
+
reader.update();
|
|
332
|
+
};
|
|
333
|
+
var init = function() {
|
|
334
|
+
reader.init();
|
|
185
335
|
};
|
|
186
|
-
|
|
187
|
-
|
|
336
|
+
var close = function() {
|
|
337
|
+
reader.close();
|
|
188
338
|
};
|
|
189
|
-
export
|
|
190
|
-
reader.close();
|
|
191
|
-
};
|
|
339
|
+
export { LruReader, close, init, readFile, updateFile };
|