@modern-js/server 2.15.0 → 2.16.0

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.
Files changed (51) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/constants.js +12 -28
  3. package/dist/cjs/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +14 -32
  4. package/dist/cjs/dev-tools/dev-middleware/hmr-client/index.js +24 -42
  5. package/dist/cjs/dev-tools/dev-middleware/index.js +45 -50
  6. package/dist/cjs/dev-tools/dev-middleware/socketServer.js +48 -46
  7. package/dist/cjs/dev-tools/https/index.js +21 -38
  8. package/dist/cjs/dev-tools/mock/getMockData.js +33 -33
  9. package/dist/cjs/dev-tools/mock/index.js +67 -47
  10. package/dist/cjs/dev-tools/register/index.js +59 -70
  11. package/dist/cjs/dev-tools/watcher/dependencyTree.js +52 -55
  12. package/dist/cjs/dev-tools/watcher/index.js +52 -53
  13. package/dist/cjs/dev-tools/watcher/statsCache.js +37 -47
  14. package/dist/cjs/index.js +16 -28
  15. package/dist/cjs/server/devServer.js +163 -109
  16. package/dist/cjs/server/index.js +11 -29
  17. package/dist/cjs/types.js +4 -15
  18. package/dist/esm/constants.js +19 -20
  19. package/dist/esm/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +43 -44
  20. package/dist/esm/dev-tools/dev-middleware/hmr-client/index.js +148 -157
  21. package/dist/esm/dev-tools/dev-middleware/index.js +307 -291
  22. package/dist/esm/dev-tools/dev-middleware/socketServer.js +216 -202
  23. package/dist/esm/dev-tools/https/index.js +189 -182
  24. package/dist/esm/dev-tools/mock/getMockData.js +297 -278
  25. package/dist/esm/dev-tools/mock/index.js +198 -192
  26. package/dist/esm/dev-tools/register/index.js +141 -141
  27. package/dist/esm/dev-tools/watcher/dependencyTree.js +153 -138
  28. package/dist/esm/dev-tools/watcher/index.js +187 -175
  29. package/dist/esm/dev-tools/watcher/statsCache.js +118 -116
  30. package/dist/esm/index.js +9 -8
  31. package/dist/esm/server/devServer.js +803 -722
  32. package/dist/esm/server/index.js +80 -76
  33. package/dist/esm/types.js +1 -1
  34. package/dist/esm-node/constants.js +4 -5
  35. package/dist/esm-node/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +2 -11
  36. package/dist/esm-node/dev-tools/dev-middleware/hmr-client/index.js +125 -139
  37. package/dist/esm-node/dev-tools/dev-middleware/index.js +31 -17
  38. package/dist/esm-node/dev-tools/dev-middleware/socketServer.js +33 -12
  39. package/dist/esm-node/dev-tools/https/index.js +13 -15
  40. package/dist/esm-node/dev-tools/mock/getMockData.js +20 -12
  41. package/dist/esm-node/dev-tools/mock/index.js +7 -7
  42. package/dist/esm-node/dev-tools/register/index.js +38 -29
  43. package/dist/esm-node/dev-tools/watcher/dependencyTree.js +32 -21
  44. package/dist/esm-node/dev-tools/watcher/index.js +31 -18
  45. package/dist/esm-node/dev-tools/watcher/statsCache.js +18 -8
  46. package/dist/esm-node/index.js +2 -5
  47. package/dist/esm-node/server/devServer.js +87 -62
  48. package/dist/esm-node/server/index.js +1 -4
  49. package/dist/esm-node/types.js +1 -0
  50. package/dist/types/server/devServer.d.ts +1 -1
  51. package/package.json +13 -9
@@ -1,201 +1,213 @@
1
- function _arrayLikeToArray(arr, len) {
2
- if (len == null || len > arr.length) len = arr.length;
3
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
- return arr2;
1
+ function _array_like_to_array(arr, len) {
2
+ if (len == null || len > arr.length)
3
+ len = arr.length;
4
+ for (var i = 0, arr2 = new Array(len); i < len; i++)
5
+ arr2[i] = arr[i];
6
+ return arr2;
5
7
  }
6
- function _arrayWithoutHoles(arr) {
7
- if (Array.isArray(arr)) return _arrayLikeToArray(arr);
8
+ function _array_without_holes(arr) {
9
+ if (Array.isArray(arr))
10
+ return _array_like_to_array(arr);
8
11
  }
9
- function _classCallCheck(instance, Constructor) {
10
- if (!(instance instanceof Constructor)) {
11
- throw new TypeError("Cannot call a class as a function");
12
- }
12
+ function _class_call_check(instance, Constructor) {
13
+ if (!(instance instanceof Constructor)) {
14
+ throw new TypeError("Cannot call a class as a function");
15
+ }
13
16
  }
14
17
  function _defineProperties(target, props) {
15
- for(var i = 0; i < props.length; i++){
16
- var descriptor = props[i];
17
- descriptor.enumerable = descriptor.enumerable || false;
18
- descriptor.configurable = true;
19
- if ("value" in descriptor) descriptor.writable = true;
20
- Object.defineProperty(target, descriptor.key, descriptor);
21
- }
18
+ for (var i = 0; i < props.length; i++) {
19
+ var descriptor = props[i];
20
+ descriptor.enumerable = descriptor.enumerable || false;
21
+ descriptor.configurable = true;
22
+ if ("value" in descriptor)
23
+ descriptor.writable = true;
24
+ Object.defineProperty(target, descriptor.key, descriptor);
25
+ }
22
26
  }
23
- function _createClass(Constructor, protoProps, staticProps) {
24
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
25
- if (staticProps) _defineProperties(Constructor, staticProps);
26
- return Constructor;
27
+ function _create_class(Constructor, protoProps, staticProps) {
28
+ if (protoProps)
29
+ _defineProperties(Constructor.prototype, protoProps);
30
+ if (staticProps)
31
+ _defineProperties(Constructor, staticProps);
32
+ return Constructor;
27
33
  }
28
- function _defineProperty(obj, key, value) {
29
- if (key in obj) {
30
- Object.defineProperty(obj, key, {
31
- value: value,
32
- enumerable: true,
33
- configurable: true,
34
- writable: true
35
- });
36
- } else {
37
- obj[key] = value;
38
- }
39
- return obj;
34
+ function _define_property(obj, key, value) {
35
+ if (key in obj) {
36
+ Object.defineProperty(obj, key, {
37
+ value,
38
+ enumerable: true,
39
+ configurable: true,
40
+ writable: true
41
+ });
42
+ } else {
43
+ obj[key] = value;
44
+ }
45
+ return obj;
40
46
  }
41
- function _iterableToArray(iter) {
42
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
47
+ function _iterable_to_array(iter) {
48
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null)
49
+ return Array.from(iter);
43
50
  }
44
- function _nonIterableSpread() {
45
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
51
+ function _non_iterable_spread() {
52
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
46
53
  }
47
- function _objectSpread(target) {
48
- for(var i = 1; i < arguments.length; i++){
49
- var source = arguments[i] != null ? arguments[i] : {};
50
- var ownKeys = Object.keys(source);
51
- if (typeof Object.getOwnPropertySymbols === "function") {
52
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
53
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
54
- }));
55
- }
56
- ownKeys.forEach(function(key) {
57
- _defineProperty(target, key, source[key]);
58
- });
54
+ function _object_spread(target) {
55
+ for (var i = 1; i < arguments.length; i++) {
56
+ var source = arguments[i] != null ? arguments[i] : {};
57
+ var ownKeys = Object.keys(source);
58
+ if (typeof Object.getOwnPropertySymbols === "function") {
59
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
60
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
61
+ }));
59
62
  }
60
- return target;
63
+ ownKeys.forEach(function(key) {
64
+ _define_property(target, key, source[key]);
65
+ });
66
+ }
67
+ return target;
61
68
  }
62
- function _toConsumableArray(arr) {
63
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
69
+ function _to_consumable_array(arr) {
70
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
64
71
  }
65
- function _unsupportedIterableToArray(o, minLen) {
66
- if (!o) return;
67
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
68
- var n = Object.prototype.toString.call(o).slice(8, -1);
69
- if (n === "Object" && o.constructor) n = o.constructor.name;
70
- if (n === "Map" || n === "Set") return Array.from(n);
71
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
72
+ function _unsupported_iterable_to_array(o, minLen) {
73
+ if (!o)
74
+ return;
75
+ if (typeof o === "string")
76
+ return _array_like_to_array(o, minLen);
77
+ var n = Object.prototype.toString.call(o).slice(8, -1);
78
+ if (n === "Object" && o.constructor)
79
+ n = o.constructor.name;
80
+ if (n === "Map" || n === "Set")
81
+ return Array.from(n);
82
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
83
+ return _array_like_to_array(o, minLen);
72
84
  }
73
85
  import path from "path";
74
86
  import { fs, chokidar } from "@modern-js/utils";
75
87
  import { DependencyTree } from "./dependencyTree";
76
88
  import { StatsCache } from "./statsCache";
77
- var defaultWatchOptions = {
78
- // 初始化的时候不触发 add、addDir 事件
79
- ignoreInitial: true,
80
- ignored: /api\/typings\/.*/
89
+ export var defaultWatchOptions = {
90
+ // 初始化的时候不触发 add、addDir 事件
91
+ ignoreInitial: true,
92
+ ignored: /api\/typings\/.*/
81
93
  };
82
- var getWatchedFiles = function(watcher) {
83
- var watched = watcher.getWatched();
84
- var files = [];
85
- Object.keys(watched).forEach(function(dir) {
86
- watched[dir].forEach(function(fileName) {
87
- files.push(path.join(dir, fileName));
88
- });
94
+ export var getWatchedFiles = function(watcher) {
95
+ var watched = watcher.getWatched();
96
+ var files = [];
97
+ Object.keys(watched).forEach(function(dir) {
98
+ watched[dir].forEach(function(fileName) {
99
+ files.push(path.join(dir, fileName));
89
100
  });
90
- return files;
101
+ });
102
+ return files;
91
103
  };
92
- var mergeWatchOptions = function(options) {
93
- var watchOptions = _objectSpread({}, options);
94
- if (watchOptions) {
95
- var ignored = watchOptions.ignored;
96
- var finalIgnored = ignored ? [
97
- defaultWatchOptions.ignored
98
- ].concat(_toConsumableArray(Array.isArray(ignored) ? ignored : [
99
- ignored
100
- ])) : ignored;
101
- if (finalIgnored) {
102
- watchOptions.ignored = finalIgnored;
103
- }
104
+ export var mergeWatchOptions = function(options) {
105
+ var watchOptions = _object_spread({}, options);
106
+ if (watchOptions) {
107
+ var ignored = watchOptions.ignored;
108
+ var finalIgnored = ignored ? [
109
+ defaultWatchOptions.ignored
110
+ ].concat(_to_consumable_array(Array.isArray(ignored) ? ignored : [
111
+ ignored
112
+ ])) : ignored;
113
+ if (finalIgnored) {
114
+ watchOptions.ignored = finalIgnored;
104
115
  }
105
- var finalWatchOptions = _objectSpread({}, defaultWatchOptions, watchOptions);
106
- return finalWatchOptions;
116
+ }
117
+ var finalWatchOptions = _object_spread({}, defaultWatchOptions, watchOptions);
118
+ return finalWatchOptions;
107
119
  };
108
- var Watcher = /*#__PURE__*/ function() {
109
- "use strict";
110
- function Watcher() {
111
- _classCallCheck(this, Watcher);
112
- _defineProperty(this, "dependencyTree", null);
113
- _defineProperty(this, "watcher", void 0);
114
- }
115
- _createClass(Watcher, [
116
- {
117
- key: "listen",
118
- value: function listen(files, options, callback) {
119
- var watched = files.filter(Boolean);
120
- var filenames = watched.map(function(filename) {
121
- return filename.replace(/\\/g, "/");
122
- });
123
- var cache = new StatsCache();
124
- var watcher = chokidar.watch(filenames, options);
125
- watcher.on("ready", function() {
126
- cache.add(getWatchedFiles(watcher));
127
- });
128
- watcher.on("change", function(changed) {
129
- if (!fs.existsSync(changed) || cache.isDiff(changed)) {
130
- cache.refresh(changed);
131
- callback(changed, "change");
132
- }
133
- });
134
- watcher.on("add", function(changed) {
135
- if (!cache.has(changed)) {
136
- cache.add([
137
- changed
138
- ]);
139
- callback(changed, "add");
140
- }
141
- });
142
- watcher.on("unlink", function(changed) {
143
- cache.del(changed);
144
- callback(changed, "unlink");
145
- });
146
- this.watcher = watcher;
147
- }
148
- },
149
- {
150
- key: "createDepTree",
151
- value: function createDepTree() {
152
- this.dependencyTree = new DependencyTree();
153
- }
154
- },
155
- {
156
- key: "updateDepTree",
157
- value: function updateDepTree() {
158
- var _this_dependencyTree;
159
- (_this_dependencyTree = this.dependencyTree) === null || _this_dependencyTree === void 0 ? void 0 : _this_dependencyTree.update(require.cache);
160
- }
161
- },
162
- {
163
- key: "cleanDepCache",
164
- value: function cleanDepCache(filepath) {
165
- var _this_dependencyTree;
166
- var node = (_this_dependencyTree = this.dependencyTree) === null || _this_dependencyTree === void 0 ? void 0 : _this_dependencyTree.getNode(filepath);
167
- if (node && require.cache[filepath]) {
168
- delete require.cache[filepath];
169
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
170
- try {
171
- for(var _iterator = node.parent.values()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
172
- var parentNode = _step.value;
173
- this.cleanDepCache(parentNode.module.filename);
174
- }
175
- } catch (err) {
176
- _didIteratorError = true;
177
- _iteratorError = err;
178
- } finally{
179
- try {
180
- if (!_iteratorNormalCompletion && _iterator.return != null) {
181
- _iterator.return();
182
- }
183
- } finally{
184
- if (_didIteratorError) {
185
- throw _iteratorError;
186
- }
187
- }
188
- }
189
- }
120
+ var Watcher = /* @__PURE__ */ function() {
121
+ "use strict";
122
+ function Watcher2() {
123
+ _class_call_check(this, Watcher2);
124
+ _define_property(this, "dependencyTree", null);
125
+ _define_property(this, "watcher", void 0);
126
+ }
127
+ _create_class(Watcher2, [
128
+ {
129
+ key: "listen",
130
+ value: function listen(files, options, callback) {
131
+ var watched = files.filter(Boolean);
132
+ var filenames = watched.map(function(filename) {
133
+ return filename.replace(/\\/g, "/");
134
+ });
135
+ var cache = new StatsCache();
136
+ var watcher = chokidar.watch(filenames, options);
137
+ watcher.on("ready", function() {
138
+ cache.add(getWatchedFiles(watcher));
139
+ });
140
+ watcher.on("change", function(changed) {
141
+ if (!fs.existsSync(changed) || cache.isDiff(changed)) {
142
+ cache.refresh(changed);
143
+ callback(changed, "change");
144
+ }
145
+ });
146
+ watcher.on("add", function(changed) {
147
+ if (!cache.has(changed)) {
148
+ cache.add([
149
+ changed
150
+ ]);
151
+ callback(changed, "add");
152
+ }
153
+ });
154
+ watcher.on("unlink", function(changed) {
155
+ cache.del(changed);
156
+ callback(changed, "unlink");
157
+ });
158
+ this.watcher = watcher;
159
+ }
160
+ },
161
+ {
162
+ key: "createDepTree",
163
+ value: function createDepTree() {
164
+ this.dependencyTree = new DependencyTree();
165
+ }
166
+ },
167
+ {
168
+ key: "updateDepTree",
169
+ value: function updateDepTree() {
170
+ var _this_dependencyTree;
171
+ (_this_dependencyTree = this.dependencyTree) === null || _this_dependencyTree === void 0 ? void 0 : _this_dependencyTree.update(require.cache);
172
+ }
173
+ },
174
+ {
175
+ key: "cleanDepCache",
176
+ value: function cleanDepCache(filepath) {
177
+ var _this_dependencyTree;
178
+ var node = (_this_dependencyTree = this.dependencyTree) === null || _this_dependencyTree === void 0 ? void 0 : _this_dependencyTree.getNode(filepath);
179
+ if (node && require.cache[filepath]) {
180
+ delete require.cache[filepath];
181
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
182
+ try {
183
+ for (var _iterator = node.parent.values()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
184
+ var parentNode = _step.value;
185
+ this.cleanDepCache(parentNode.module.filename);
190
186
  }
191
- },
192
- {
193
- key: "close",
194
- value: function close() {
195
- return this.watcher.close();
187
+ } catch (err) {
188
+ _didIteratorError = true;
189
+ _iteratorError = err;
190
+ } finally {
191
+ try {
192
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
193
+ _iterator.return();
194
+ }
195
+ } finally {
196
+ if (_didIteratorError) {
197
+ throw _iteratorError;
198
+ }
196
199
  }
200
+ }
197
201
  }
198
- ]);
199
- return Watcher;
202
+ }
203
+ },
204
+ {
205
+ key: "close",
206
+ value: function close() {
207
+ return this.watcher.close();
208
+ }
209
+ }
210
+ ]);
211
+ return Watcher2;
200
212
  }();
201
- export { Watcher as default, defaultWatchOptions, getWatchedFiles, mergeWatchOptions };
213
+ export { Watcher as default };
@@ -1,128 +1,130 @@
1
- function _classCallCheck(instance, Constructor) {
2
- if (!(instance instanceof Constructor)) {
3
- throw new TypeError("Cannot call a class as a function");
4
- }
1
+ function _class_call_check(instance, Constructor) {
2
+ if (!(instance instanceof Constructor)) {
3
+ throw new TypeError("Cannot call a class as a function");
4
+ }
5
5
  }
6
6
  function _defineProperties(target, props) {
7
- for(var i = 0; i < props.length; i++){
8
- var descriptor = props[i];
9
- descriptor.enumerable = descriptor.enumerable || false;
10
- descriptor.configurable = true;
11
- if ("value" in descriptor) descriptor.writable = true;
12
- Object.defineProperty(target, descriptor.key, descriptor);
13
- }
7
+ for (var i = 0; i < props.length; i++) {
8
+ var descriptor = props[i];
9
+ descriptor.enumerable = descriptor.enumerable || false;
10
+ descriptor.configurable = true;
11
+ if ("value" in descriptor)
12
+ descriptor.writable = true;
13
+ Object.defineProperty(target, descriptor.key, descriptor);
14
+ }
14
15
  }
15
- function _createClass(Constructor, protoProps, staticProps) {
16
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
17
- if (staticProps) _defineProperties(Constructor, staticProps);
18
- return Constructor;
16
+ function _create_class(Constructor, protoProps, staticProps) {
17
+ if (protoProps)
18
+ _defineProperties(Constructor.prototype, protoProps);
19
+ if (staticProps)
20
+ _defineProperties(Constructor, staticProps);
21
+ return Constructor;
19
22
  }
20
- function _defineProperty(obj, key, value) {
21
- if (key in obj) {
22
- Object.defineProperty(obj, key, {
23
- value: value,
24
- enumerable: true,
25
- configurable: true,
26
- writable: true
27
- });
28
- } else {
29
- obj[key] = value;
30
- }
31
- return obj;
23
+ function _define_property(obj, key, value) {
24
+ if (key in obj) {
25
+ Object.defineProperty(obj, key, {
26
+ value,
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true
30
+ });
31
+ } else {
32
+ obj[key] = value;
33
+ }
34
+ return obj;
32
35
  }
33
36
  import fs from "fs";
34
37
  import crypto from "crypto";
35
- var StatsCache = /*#__PURE__*/ function() {
36
- "use strict";
37
- function StatsCache() {
38
- _classCallCheck(this, StatsCache);
39
- _defineProperty(this, "cachedHash", {});
40
- _defineProperty(this, "cachedSize", {});
41
- }
42
- _createClass(StatsCache, [
43
- {
44
- key: "add",
45
- value: function add(files) {
46
- var _this = this, cachedHash = _this.cachedHash, cachedSize = _this.cachedSize;
47
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
48
- try {
49
- for(var _iterator = files[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
50
- var filename = _step.value;
51
- if (fs.existsSync(filename)) {
52
- var stats = fs.statSync(filename);
53
- if (stats.isFile() && !cachedHash[filename]) {
54
- cachedHash[filename] = this.hash(stats, filename);
55
- cachedSize[filename] = stats.size;
56
- }
57
- }
58
- }
59
- } catch (err) {
60
- _didIteratorError = true;
61
- _iteratorError = err;
62
- } finally{
63
- try {
64
- if (!_iteratorNormalCompletion && _iterator.return != null) {
65
- _iterator.return();
66
- }
67
- } finally{
68
- if (_didIteratorError) {
69
- throw _iteratorError;
70
- }
71
- }
72
- }
73
- }
74
- },
75
- {
76
- key: "refresh",
77
- value: function refresh(filename) {
78
- var _this = this, cachedHash = _this.cachedHash, cachedSize = _this.cachedSize;
79
- if (fs.existsSync(filename)) {
80
- var stats = fs.statSync(filename);
81
- if (stats.isFile()) {
82
- cachedHash[filename] = this.hash(stats, filename);
83
- cachedSize[filename] = stats.size;
84
- }
85
- }
86
- }
87
- },
88
- {
89
- key: "del",
90
- value: function del(filename) {
91
- if (this.cachedHash[filename]) {
92
- delete this.cachedHash[filename];
93
- delete this.cachedSize[filename];
94
- }
38
+ export var StatsCache = /* @__PURE__ */ function() {
39
+ "use strict";
40
+ function StatsCache2() {
41
+ _class_call_check(this, StatsCache2);
42
+ _define_property(this, "cachedHash", {});
43
+ _define_property(this, "cachedSize", {});
44
+ }
45
+ _create_class(StatsCache2, [
46
+ {
47
+ key: "add",
48
+ value: function add(files) {
49
+ var _this = this, cachedHash = _this.cachedHash, cachedSize = _this.cachedSize;
50
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
51
+ try {
52
+ for (var _iterator = files[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
53
+ var filename = _step.value;
54
+ if (fs.existsSync(filename)) {
55
+ var stats = fs.statSync(filename);
56
+ if (stats.isFile() && !cachedHash[filename]) {
57
+ cachedHash[filename] = this.hash(stats, filename);
58
+ cachedSize[filename] = stats.size;
59
+ }
95
60
  }
96
- },
97
- {
98
- key: "isDiff",
99
- value: function isDiff(filename) {
100
- var _this = this, cachedHash = _this.cachedHash, cachedSize = _this.cachedSize;
101
- var stats = fs.statSync(filename);
102
- var hash = cachedHash[filename];
103
- var size = cachedSize[filename];
104
- if (stats.size !== size) {
105
- return true;
106
- }
107
- if (this.hash(stats, filename) !== hash) {
108
- return true;
109
- }
110
- return false;
61
+ }
62
+ } catch (err) {
63
+ _didIteratorError = true;
64
+ _iteratorError = err;
65
+ } finally {
66
+ try {
67
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
68
+ _iterator.return();
111
69
  }
112
- },
113
- {
114
- key: "has",
115
- value: function has(filename) {
116
- return Boolean(this.cachedHash[filename]);
117
- }
118
- },
119
- {
120
- key: "hash",
121
- value: function hash(stats, filename) {
122
- return crypto.createHash("md5").update(fs.readFileSync(filename)).digest("hex");
70
+ } finally {
71
+ if (_didIteratorError) {
72
+ throw _iteratorError;
123
73
  }
74
+ }
75
+ }
76
+ }
77
+ },
78
+ {
79
+ key: "refresh",
80
+ value: function refresh(filename) {
81
+ var _this = this, cachedHash = _this.cachedHash, cachedSize = _this.cachedSize;
82
+ if (fs.existsSync(filename)) {
83
+ var stats = fs.statSync(filename);
84
+ if (stats.isFile()) {
85
+ cachedHash[filename] = this.hash(stats, filename);
86
+ cachedSize[filename] = stats.size;
87
+ }
88
+ }
89
+ }
90
+ },
91
+ {
92
+ key: "del",
93
+ value: function del(filename) {
94
+ if (this.cachedHash[filename]) {
95
+ delete this.cachedHash[filename];
96
+ delete this.cachedSize[filename];
124
97
  }
125
- ]);
126
- return StatsCache;
98
+ }
99
+ },
100
+ {
101
+ key: "isDiff",
102
+ value: function isDiff(filename) {
103
+ var _this = this, cachedHash = _this.cachedHash, cachedSize = _this.cachedSize;
104
+ var stats = fs.statSync(filename);
105
+ var hash = cachedHash[filename];
106
+ var size = cachedSize[filename];
107
+ if (stats.size !== size) {
108
+ return true;
109
+ }
110
+ if (this.hash(stats, filename) !== hash) {
111
+ return true;
112
+ }
113
+ return false;
114
+ }
115
+ },
116
+ {
117
+ key: "has",
118
+ value: function has(filename) {
119
+ return Boolean(this.cachedHash[filename]);
120
+ }
121
+ },
122
+ {
123
+ key: "hash",
124
+ value: function hash(stats, filename) {
125
+ return crypto.createHash("md5").update(fs.readFileSync(filename)).digest("hex");
126
+ }
127
+ }
128
+ ]);
129
+ return StatsCache2;
127
130
  }();
128
- export { StatsCache };
package/dist/esm/index.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import { DevServer as Server } from "./server";
2
- var src_default = function(options) {
3
- if (options == null) {
4
- throw new Error("can not start server without options");
5
- }
6
- var server = new Server(options);
7
- return server.init();
8
- };
9
- export { Server, src_default as default };
2
+ export { Server };
3
+ export default function(options) {
4
+ if (options == null) {
5
+ throw new Error("can not start server without options");
6
+ }
7
+ var server = new Server(options);
8
+ return server.init();
9
+ }
10
+ ;