@modern-js/server 2.15.1-alpha.0 → 2.17.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.
- package/CHANGELOG.md +25 -0
- package/dist/cjs/constants.js +12 -28
- package/dist/cjs/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +14 -32
- package/dist/cjs/dev-tools/dev-middleware/hmr-client/index.js +24 -42
- package/dist/cjs/dev-tools/dev-middleware/index.js +45 -50
- package/dist/cjs/dev-tools/dev-middleware/socketServer.js +48 -46
- package/dist/cjs/dev-tools/https/index.js +21 -38
- package/dist/cjs/dev-tools/mock/getMockData.js +33 -33
- package/dist/cjs/dev-tools/mock/index.js +67 -47
- package/dist/cjs/dev-tools/register/index.js +59 -70
- package/dist/cjs/dev-tools/watcher/dependencyTree.js +52 -55
- package/dist/cjs/dev-tools/watcher/index.js +52 -53
- package/dist/cjs/dev-tools/watcher/statsCache.js +37 -47
- package/dist/cjs/index.js +16 -28
- package/dist/cjs/server/devServer.js +163 -109
- package/dist/cjs/server/index.js +11 -29
- package/dist/cjs/types.js +4 -15
- package/dist/esm/constants.js +19 -20
- package/dist/esm/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +43 -44
- package/dist/esm/dev-tools/dev-middleware/hmr-client/index.js +148 -157
- package/dist/esm/dev-tools/dev-middleware/index.js +307 -291
- package/dist/esm/dev-tools/dev-middleware/socketServer.js +216 -202
- package/dist/esm/dev-tools/https/index.js +189 -182
- package/dist/esm/dev-tools/mock/getMockData.js +297 -278
- package/dist/esm/dev-tools/mock/index.js +198 -192
- package/dist/esm/dev-tools/register/index.js +141 -141
- package/dist/esm/dev-tools/watcher/dependencyTree.js +153 -138
- package/dist/esm/dev-tools/watcher/index.js +187 -175
- package/dist/esm/dev-tools/watcher/statsCache.js +118 -116
- package/dist/esm/index.js +9 -8
- package/dist/esm/server/devServer.js +803 -766
- package/dist/esm/server/index.js +80 -76
- package/dist/esm/types.js +1 -1
- package/dist/esm-node/constants.js +4 -5
- package/dist/esm-node/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +2 -11
- package/dist/esm-node/dev-tools/dev-middleware/hmr-client/index.js +125 -139
- package/dist/esm-node/dev-tools/dev-middleware/index.js +31 -17
- package/dist/esm-node/dev-tools/dev-middleware/socketServer.js +33 -12
- package/dist/esm-node/dev-tools/https/index.js +13 -15
- package/dist/esm-node/dev-tools/mock/getMockData.js +20 -12
- package/dist/esm-node/dev-tools/mock/index.js +7 -7
- package/dist/esm-node/dev-tools/register/index.js +38 -29
- package/dist/esm-node/dev-tools/watcher/dependencyTree.js +32 -21
- package/dist/esm-node/dev-tools/watcher/index.js +31 -18
- package/dist/esm-node/dev-tools/watcher/statsCache.js +18 -8
- package/dist/esm-node/index.js +2 -5
- package/dist/esm-node/server/devServer.js +87 -62
- package/dist/esm-node/server/index.js +1 -4
- package/dist/esm-node/types.js +1 -0
- package/package.json +13 -9
- package/dist/js/modern/constants.js +0 -19
- package/dist/js/modern/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +0 -41
- package/dist/js/modern/dev-tools/dev-middleware/hmr-client/index.js +0 -143
- package/dist/js/modern/dev-tools/dev-middleware/index.js +0 -94
- package/dist/js/modern/dev-tools/dev-middleware/socket-server.js +0 -132
- package/dist/js/modern/dev-tools/https/index.js +0 -49
- package/dist/js/modern/dev-tools/mock/getMockData.js +0 -114
- package/dist/js/modern/dev-tools/mock/index.js +0 -54
- package/dist/js/modern/dev-tools/register/index.js +0 -111
- package/dist/js/modern/dev-tools/watcher/dependency-tree.js +0 -59
- package/dist/js/modern/dev-tools/watcher/index.js +0 -106
- package/dist/js/modern/dev-tools/watcher/stats-cache.js +0 -58
- package/dist/js/modern/index.js +0 -12
- package/dist/js/modern/server/dev-server.js +0 -293
- package/dist/js/modern/server/index.js +0 -16
- package/dist/js/modern/types.js +0 -0
- package/dist/js/node/constants.js +0 -42
- package/dist/js/node/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +0 -65
- package/dist/js/node/dev-tools/dev-middleware/hmr-client/index.js +0 -152
- package/dist/js/node/dev-tools/dev-middleware/index.js +0 -119
- package/dist/js/node/dev-tools/dev-middleware/socket-server.js +0 -159
- package/dist/js/node/dev-tools/https/index.js +0 -72
- package/dist/js/node/dev-tools/mock/getMockData.js +0 -135
- package/dist/js/node/dev-tools/mock/index.js +0 -83
- package/dist/js/node/dev-tools/register/index.js +0 -138
- package/dist/js/node/dev-tools/watcher/dependency-tree.js +0 -89
- package/dist/js/node/dev-tools/watcher/index.js +0 -135
- package/dist/js/node/dev-tools/watcher/stats-cache.js +0 -87
- package/dist/js/node/index.js +0 -35
- package/dist/js/node/server/dev-server.js +0 -310
- package/dist/js/node/server/index.js +0 -39
- package/dist/js/node/types.js +0 -15
- package/dist/js/treeshaking/constants.js +0 -21
- package/dist/js/treeshaking/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +0 -51
- package/dist/js/treeshaking/dev-tools/dev-middleware/hmr-client/index.js +0 -157
- package/dist/js/treeshaking/dev-tools/dev-middleware/index.js +0 -322
- package/dist/js/treeshaking/dev-tools/dev-middleware/socket-server.js +0 -209
- package/dist/js/treeshaking/dev-tools/https/index.js +0 -193
- package/dist/js/treeshaking/dev-tools/mock/getMockData.js +0 -327
- package/dist/js/treeshaking/dev-tools/mock/index.js +0 -191
- package/dist/js/treeshaking/dev-tools/register/index.js +0 -153
- package/dist/js/treeshaking/dev-tools/watcher/dependency-tree.js +0 -150
- package/dist/js/treeshaking/dev-tools/watcher/index.js +0 -200
- package/dist/js/treeshaking/dev-tools/watcher/stats-cache.js +0 -128
- package/dist/js/treeshaking/index.js +0 -9
- package/dist/js/treeshaking/server/dev-server.js +0 -799
- package/dist/js/treeshaking/server/index.js +0 -92
- package/dist/js/treeshaking/types.js +0 -1
|
@@ -1,201 +1,213 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
|
7
|
-
|
|
8
|
+
function _array_without_holes(arr) {
|
|
9
|
+
if (Array.isArray(arr))
|
|
10
|
+
return _array_like_to_array(arr);
|
|
8
11
|
}
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
|
42
|
-
|
|
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
|
|
45
|
-
|
|
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
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
63
|
+
ownKeys.forEach(function(key) {
|
|
64
|
+
_define_property(target, key, source[key]);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return target;
|
|
61
68
|
}
|
|
62
|
-
function
|
|
63
|
-
|
|
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
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
89
|
+
export var defaultWatchOptions = {
|
|
90
|
+
// 初始化的时候不触发 add、addDir 事件
|
|
91
|
+
ignoreInitial: true,
|
|
92
|
+
ignored: /api\/typings\/.*/
|
|
81
93
|
};
|
|
82
|
-
var getWatchedFiles = function(watcher) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
|
|
101
|
+
});
|
|
102
|
+
return files;
|
|
91
103
|
};
|
|
92
|
-
var mergeWatchOptions = function(options) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
106
|
-
|
|
116
|
+
}
|
|
117
|
+
var finalWatchOptions = _object_spread({}, defaultWatchOptions, watchOptions);
|
|
118
|
+
return finalWatchOptions;
|
|
107
119
|
};
|
|
108
|
-
var Watcher =
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
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
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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
|
-
|
|
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
|
|
213
|
+
export { Watcher as default };
|
|
@@ -1,128 +1,130 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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 =
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
+
;
|