@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.
- package/CHANGELOG.md +16 -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 -722
- 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/dist/types/server/devServer.d.ts +1 -1
- package/package.json +13 -9
|
@@ -1,51 +1,50 @@
|
|
|
1
1
|
import { HMR_SOCK_PATH } from "@modern-js/utils/universal/constants";
|
|
2
|
-
function createSocketUrl(resourceQuery) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
export function createSocketUrl(resourceQuery) {
|
|
3
|
+
var searchParams = resourceQuery.substr(1).split("&");
|
|
4
|
+
var options = {};
|
|
5
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
6
|
+
try {
|
|
7
|
+
for (var _iterator = searchParams[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
8
|
+
var pair = _step.value;
|
|
9
|
+
var ary = pair.split("=");
|
|
10
|
+
options[ary[0]] = decodeURIComponent(ary[1]);
|
|
11
|
+
}
|
|
12
|
+
} catch (err) {
|
|
13
|
+
_didIteratorError = true;
|
|
14
|
+
_iteratorError = err;
|
|
15
|
+
} finally {
|
|
6
16
|
try {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
_iteratorError = err;
|
|
15
|
-
} finally{
|
|
16
|
-
try {
|
|
17
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
18
|
-
_iterator.return();
|
|
19
|
-
}
|
|
20
|
-
} finally{
|
|
21
|
-
if (_didIteratorError) {
|
|
22
|
-
throw _iteratorError;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
17
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
18
|
+
_iterator.return();
|
|
19
|
+
}
|
|
20
|
+
} finally {
|
|
21
|
+
if (_didIteratorError) {
|
|
22
|
+
throw _iteratorError;
|
|
23
|
+
}
|
|
25
24
|
}
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
}
|
|
26
|
+
var currentLocation = self.location;
|
|
27
|
+
return getSocketUrl(options, currentLocation);
|
|
28
28
|
}
|
|
29
|
-
function formatURL(param) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
29
|
+
export function formatURL(param) {
|
|
30
|
+
var port = param.port, protocol = param.protocol, hostname = param.hostname, pathname = param.pathname;
|
|
31
|
+
if (window.URL) {
|
|
32
|
+
var url = new URL("http://localhost");
|
|
33
|
+
url.port = port;
|
|
34
|
+
url.hostname = hostname;
|
|
35
|
+
url.protocol = protocol;
|
|
36
|
+
url.pathname = pathname;
|
|
37
|
+
return url.toString();
|
|
38
|
+
}
|
|
39
|
+
var colon = protocol.indexOf(":") === -1 ? ":" : "";
|
|
40
|
+
return "".concat(protocol).concat(colon, "//").concat(hostname, ":").concat(port).concat(pathname);
|
|
41
41
|
}
|
|
42
42
|
function getSocketUrl(urlParts, location) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
var host = urlParts.host, port = urlParts.port, path = urlParts.path, protocol = urlParts.protocol;
|
|
44
|
+
return formatURL({
|
|
45
|
+
protocol: protocol || (location.protocol === "https:" ? "wss" : "ws"),
|
|
46
|
+
hostname: host || location.hostname,
|
|
47
|
+
port: port || location.port,
|
|
48
|
+
pathname: path || HMR_SOCK_PATH
|
|
49
|
+
});
|
|
50
50
|
}
|
|
51
|
-
export { createSocketUrl, formatURL };
|
|
@@ -1,162 +1,153 @@
|
|
|
1
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
|
-
var __commonJS = function(cb, mod) {
|
|
3
|
-
return function __require() {
|
|
4
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = {
|
|
5
|
-
exports: {}
|
|
6
|
-
}).exports, mod), mod.exports;
|
|
7
|
-
};
|
|
8
|
-
};
|
|
9
1
|
import stripAnsi from "@modern-js/utils/strip-ansi";
|
|
10
2
|
import { formatWebpackMessages } from "@modern-js/utils/universal/format-webpack";
|
|
11
3
|
import { createSocketUrl } from "./createSocketUrl";
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
var hadRuntimeError = false;
|
|
96
|
-
var socketUrl = createSocketUrl(__resourceQuery);
|
|
97
|
-
var connection = new WebSocket(socketUrl);
|
|
98
|
-
connection.onopen = function() {
|
|
99
|
-
if (typeof console !== "undefined" && typeof console.debug === "function") {
|
|
100
|
-
console.debug("[HMR] connected.");
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
connection.onclose = function() {
|
|
104
|
-
if (typeof console !== "undefined" && typeof console.info === "function") {
|
|
105
|
-
console.debug("[HMR] disconnected. Refresh the page if necessary.");
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
var isFirstCompilation = true;
|
|
109
|
-
var mostRecentCompilationHash = null;
|
|
110
|
-
var hasCompileErrors = false;
|
|
111
|
-
connection.onmessage = function(e) {
|
|
112
|
-
var message = JSON.parse(e.data);
|
|
113
|
-
switch(message.type){
|
|
114
|
-
case "hash":
|
|
115
|
-
handleAvailableHash(message.data);
|
|
116
|
-
break;
|
|
117
|
-
case "still-ok":
|
|
118
|
-
case "ok":
|
|
119
|
-
handleSuccess();
|
|
120
|
-
break;
|
|
121
|
-
case "content-changed":
|
|
122
|
-
window.location.reload();
|
|
123
|
-
break;
|
|
124
|
-
case "warnings":
|
|
125
|
-
handleWarnings(message.data);
|
|
126
|
-
break;
|
|
127
|
-
case "errors":
|
|
128
|
-
handleErrors(message.data);
|
|
129
|
-
break;
|
|
130
|
-
default:
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
function tryApplyUpdates() {
|
|
134
|
-
if (!module.hot) {
|
|
135
|
-
window.location.reload();
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
if (!isUpdateAvailable() || !canApplyUpdates()) {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
function handleApplyUpdates(err, updatedModules) {
|
|
142
|
-
var wantsForcedReload = err || !updatedModules || hadRuntimeError;
|
|
143
|
-
if (wantsForcedReload) {
|
|
144
|
-
window.location.reload();
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
if (isUpdateAvailable()) {
|
|
148
|
-
tryApplyUpdates();
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
var result = module.hot.check(/* autoApply */ true, handleApplyUpdates);
|
|
152
|
-
if (result === null || result === void 0 ? void 0 : result.then) {
|
|
153
|
-
result.then(function(updatedModules) {
|
|
154
|
-
handleApplyUpdates(null, updatedModules);
|
|
155
|
-
}, function(err) {
|
|
156
|
-
handleApplyUpdates(err, null);
|
|
157
|
-
});
|
|
158
|
-
}
|
|
4
|
+
var hadRuntimeError = false;
|
|
5
|
+
var socketUrl = createSocketUrl(__resourceQuery);
|
|
6
|
+
var connection = new WebSocket(socketUrl);
|
|
7
|
+
connection.onopen = function() {
|
|
8
|
+
if (typeof console !== "undefined" && typeof console.debug === "function") {
|
|
9
|
+
console.debug("[HMR] connected.");
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
connection.onclose = function() {
|
|
13
|
+
if (typeof console !== "undefined" && typeof console.info === "function") {
|
|
14
|
+
console.debug("[HMR] disconnected. Refresh the page if necessary.");
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var isFirstCompilation = true;
|
|
18
|
+
var mostRecentCompilationHash = null;
|
|
19
|
+
var hasCompileErrors = false;
|
|
20
|
+
function clearOutdatedErrors() {
|
|
21
|
+
if (typeof console !== "undefined" && typeof console.clear === "function") {
|
|
22
|
+
if (hasCompileErrors) {
|
|
23
|
+
console.clear();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function handleSuccess() {
|
|
28
|
+
clearOutdatedErrors();
|
|
29
|
+
var isHotUpdate = !isFirstCompilation;
|
|
30
|
+
isFirstCompilation = false;
|
|
31
|
+
hasCompileErrors = false;
|
|
32
|
+
if (isHotUpdate) {
|
|
33
|
+
tryApplyUpdates();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function handleWarnings(warnings) {
|
|
37
|
+
var printWarnings = function printWarnings2() {
|
|
38
|
+
var formatted = formatWebpackMessages({
|
|
39
|
+
warnings,
|
|
40
|
+
errors: []
|
|
41
|
+
});
|
|
42
|
+
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
43
|
+
for (var i = 0; i < formatted.warnings.length; i++) {
|
|
44
|
+
if (i === 5) {
|
|
45
|
+
console.warn("There were more warnings in other files.\nYou can find a complete log in the terminal.");
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
console.warn(stripAnsi(formatted.warnings[i]));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
clearOutdatedErrors();
|
|
53
|
+
var isHotUpdate = !isFirstCompilation;
|
|
54
|
+
isFirstCompilation = false;
|
|
55
|
+
hasCompileErrors = false;
|
|
56
|
+
printWarnings();
|
|
57
|
+
if (isHotUpdate) {
|
|
58
|
+
tryApplyUpdates();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function handleErrors(errors) {
|
|
62
|
+
clearOutdatedErrors();
|
|
63
|
+
isFirstCompilation = false;
|
|
64
|
+
hasCompileErrors = true;
|
|
65
|
+
var formatted = formatWebpackMessages({
|
|
66
|
+
errors,
|
|
67
|
+
warnings: []
|
|
68
|
+
});
|
|
69
|
+
if (typeof console !== "undefined" && typeof console.error === "function") {
|
|
70
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
71
|
+
try {
|
|
72
|
+
for (var _iterator = formatted.errors[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
73
|
+
var error = _step.value;
|
|
74
|
+
console.error(stripAnsi(error));
|
|
75
|
+
}
|
|
76
|
+
} catch (err) {
|
|
77
|
+
_didIteratorError = true;
|
|
78
|
+
_iteratorError = err;
|
|
79
|
+
} finally {
|
|
80
|
+
try {
|
|
81
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
82
|
+
_iterator.return();
|
|
83
|
+
}
|
|
84
|
+
} finally {
|
|
85
|
+
if (_didIteratorError) {
|
|
86
|
+
throw _iteratorError;
|
|
159
87
|
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function handleAvailableHash(hash) {
|
|
93
|
+
mostRecentCompilationHash = hash;
|
|
94
|
+
}
|
|
95
|
+
connection.onmessage = function(e) {
|
|
96
|
+
var message = JSON.parse(e.data);
|
|
97
|
+
switch (message.type) {
|
|
98
|
+
case "hash":
|
|
99
|
+
handleAvailableHash(message.data);
|
|
100
|
+
break;
|
|
101
|
+
case "still-ok":
|
|
102
|
+
case "ok":
|
|
103
|
+
handleSuccess();
|
|
104
|
+
break;
|
|
105
|
+
case "content-changed":
|
|
106
|
+
window.location.reload();
|
|
107
|
+
break;
|
|
108
|
+
case "warnings":
|
|
109
|
+
handleWarnings(message.data);
|
|
110
|
+
break;
|
|
111
|
+
case "errors":
|
|
112
|
+
handleErrors(message.data);
|
|
113
|
+
break;
|
|
114
|
+
default:
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
function isUpdateAvailable() {
|
|
118
|
+
return mostRecentCompilationHash !== __webpack_hash__;
|
|
119
|
+
}
|
|
120
|
+
function canApplyUpdates() {
|
|
121
|
+
return module.hot.status() === "idle";
|
|
122
|
+
}
|
|
123
|
+
function tryApplyUpdates() {
|
|
124
|
+
var handleApplyUpdates = function handleApplyUpdates2(err, updatedModules) {
|
|
125
|
+
var wantsForcedReload = err || !updatedModules || hadRuntimeError;
|
|
126
|
+
if (wantsForcedReload) {
|
|
127
|
+
window.location.reload();
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (isUpdateAvailable()) {
|
|
131
|
+
tryApplyUpdates();
|
|
160
132
|
}
|
|
161
|
-
}
|
|
162
|
-
|
|
133
|
+
};
|
|
134
|
+
if (!module.hot) {
|
|
135
|
+
window.location.reload();
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (!isUpdateAvailable() || !canApplyUpdates()) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
var result = module.hot.check(
|
|
142
|
+
/* autoApply */
|
|
143
|
+
true,
|
|
144
|
+
handleApplyUpdates
|
|
145
|
+
);
|
|
146
|
+
if (result === null || result === void 0 ? void 0 : result.then) {
|
|
147
|
+
result.then(function(updatedModules) {
|
|
148
|
+
handleApplyUpdates(null, updatedModules);
|
|
149
|
+
}, function(err) {
|
|
150
|
+
handleApplyUpdates(err, null);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|