@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
package/dist/esm/server/index.js
CHANGED
|
@@ -1,92 +1,96 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
function _assert_this_initialized(self) {
|
|
2
|
+
if (self === void 0) {
|
|
3
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
4
|
+
}
|
|
5
|
+
return self;
|
|
6
6
|
}
|
|
7
|
-
function
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
function _class_call_check(instance, Constructor) {
|
|
8
|
+
if (!(instance instanceof Constructor)) {
|
|
9
|
+
throw new TypeError("Cannot call a class as a function");
|
|
10
|
+
}
|
|
11
11
|
}
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
function _get_prototype_of(o) {
|
|
13
|
+
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o2) {
|
|
14
|
+
return o2.__proto__ || Object.getPrototypeOf(o2);
|
|
15
|
+
};
|
|
16
|
+
return _get_prototype_of(o);
|
|
17
17
|
}
|
|
18
18
|
function _inherits(subClass, superClass) {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
20
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
21
|
+
}
|
|
22
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
23
|
+
constructor: {
|
|
24
|
+
value: subClass,
|
|
25
|
+
writable: true,
|
|
26
|
+
configurable: true
|
|
21
27
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
writable: true,
|
|
26
|
-
configurable: true
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
if (superClass) _setPrototypeOf(subClass, superClass);
|
|
28
|
+
});
|
|
29
|
+
if (superClass)
|
|
30
|
+
_set_prototype_of(subClass, superClass);
|
|
30
31
|
}
|
|
31
|
-
function
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
function _possible_constructor_return(self, call) {
|
|
33
|
+
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
34
|
+
return call;
|
|
35
|
+
}
|
|
36
|
+
return _assert_this_initialized(self);
|
|
36
37
|
}
|
|
37
|
-
function
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
function _set_prototype_of(o, p) {
|
|
39
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o2, p2) {
|
|
40
|
+
o2.__proto__ = p2;
|
|
41
|
+
return o2;
|
|
42
|
+
};
|
|
43
|
+
return _set_prototype_of(o, p);
|
|
43
44
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
function
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
45
|
+
function _type_of(obj) {
|
|
46
|
+
"@swc/helpers - typeof";
|
|
47
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
48
|
+
}
|
|
49
|
+
function _is_native_reflect_construct() {
|
|
50
|
+
if (typeof Reflect === "undefined" || !Reflect.construct)
|
|
51
|
+
return false;
|
|
52
|
+
if (Reflect.construct.sham)
|
|
53
|
+
return false;
|
|
54
|
+
if (typeof Proxy === "function")
|
|
55
|
+
return true;
|
|
56
|
+
try {
|
|
57
|
+
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {
|
|
58
|
+
}));
|
|
59
|
+
return true;
|
|
60
|
+
} catch (e) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
58
63
|
}
|
|
59
|
-
function
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
64
|
+
function _create_super(Derived) {
|
|
65
|
+
var hasNativeReflectConstruct = _is_native_reflect_construct();
|
|
66
|
+
return function _createSuperInternal() {
|
|
67
|
+
var Super = _get_prototype_of(Derived), result;
|
|
68
|
+
if (hasNativeReflectConstruct) {
|
|
69
|
+
var NewTarget = _get_prototype_of(this).constructor;
|
|
70
|
+
result = Reflect.construct(Super, arguments, NewTarget);
|
|
71
|
+
} else {
|
|
72
|
+
result = Super.apply(this, arguments);
|
|
73
|
+
}
|
|
74
|
+
return _possible_constructor_return(this, result);
|
|
75
|
+
};
|
|
71
76
|
}
|
|
72
77
|
import { Server } from "@modern-js/prod-server";
|
|
73
78
|
import { ModernDevServer } from "./devServer";
|
|
74
79
|
var createDevServer = function(options) {
|
|
75
|
-
|
|
80
|
+
return new ModernDevServer(options);
|
|
76
81
|
};
|
|
77
|
-
var DevServer =
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
return _this;
|
|
82
|
+
export var DevServer = /* @__PURE__ */ function(Server2) {
|
|
83
|
+
"use strict";
|
|
84
|
+
_inherits(DevServer2, Server2);
|
|
85
|
+
var _super = _create_super(DevServer2);
|
|
86
|
+
function DevServer2(options) {
|
|
87
|
+
_class_call_check(this, DevServer2);
|
|
88
|
+
var _this;
|
|
89
|
+
_this = _super.call(this, options);
|
|
90
|
+
if (options.dev) {
|
|
91
|
+
_this.serverImpl = createDevServer;
|
|
89
92
|
}
|
|
90
|
-
return
|
|
93
|
+
return _this;
|
|
94
|
+
}
|
|
95
|
+
return DevServer2;
|
|
91
96
|
}(Server);
|
|
92
|
-
export { DevServer };
|
package/dist/esm/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HMR_SOCK_PATH } from "@modern-js/utils/universal/constants";
|
|
2
|
-
const getDefaultDevOptions = () => {
|
|
2
|
+
export const getDefaultDevOptions = () => {
|
|
3
3
|
return {
|
|
4
4
|
client: {
|
|
5
5
|
path: HMR_SOCK_PATH,
|
|
@@ -11,12 +11,11 @@ const getDefaultDevOptions = () => {
|
|
|
11
11
|
protocol: ""
|
|
12
12
|
},
|
|
13
13
|
https: false,
|
|
14
|
-
devMiddleware: {
|
|
14
|
+
devMiddleware: {
|
|
15
|
+
writeToDisk: true
|
|
16
|
+
},
|
|
15
17
|
watch: true,
|
|
16
18
|
hot: true,
|
|
17
19
|
liveReload: true
|
|
18
20
|
};
|
|
19
21
|
};
|
|
20
|
-
export {
|
|
21
|
-
getDefaultDevOptions
|
|
22
|
-
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HMR_SOCK_PATH } from "@modern-js/utils/universal/constants";
|
|
2
|
-
function createSocketUrl(resourceQuery) {
|
|
2
|
+
export function createSocketUrl(resourceQuery) {
|
|
3
3
|
const searchParams = resourceQuery.substr(1).split("&");
|
|
4
4
|
const options = {};
|
|
5
5
|
for (const pair of searchParams) {
|
|
@@ -9,12 +9,7 @@ function createSocketUrl(resourceQuery) {
|
|
|
9
9
|
const currentLocation = self.location;
|
|
10
10
|
return getSocketUrl(options, currentLocation);
|
|
11
11
|
}
|
|
12
|
-
function formatURL({
|
|
13
|
-
port,
|
|
14
|
-
protocol,
|
|
15
|
-
hostname,
|
|
16
|
-
pathname
|
|
17
|
-
}) {
|
|
12
|
+
export function formatURL({ port, protocol, hostname, pathname }) {
|
|
18
13
|
if (window.URL) {
|
|
19
14
|
const url = new URL("http://localhost");
|
|
20
15
|
url.port = port;
|
|
@@ -35,7 +30,3 @@ function getSocketUrl(urlParts, location) {
|
|
|
35
30
|
pathname: path || HMR_SOCK_PATH
|
|
36
31
|
});
|
|
37
32
|
}
|
|
38
|
-
export {
|
|
39
|
-
createSocketUrl,
|
|
40
|
-
formatURL
|
|
41
|
-
};
|
|
@@ -1,150 +1,136 @@
|
|
|
1
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
3
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
4
|
-
};
|
|
5
1
|
import stripAnsi from "@modern-js/utils/strip-ansi";
|
|
6
2
|
import { formatWebpackMessages } from "@modern-js/utils/universal/format-webpack";
|
|
7
3
|
import { createSocketUrl } from "./createSocketUrl";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (hasCompileErrors) {
|
|
29
|
-
console.clear();
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
function handleSuccess() {
|
|
34
|
-
clearOutdatedErrors();
|
|
35
|
-
const isHotUpdate = !isFirstCompilation;
|
|
36
|
-
isFirstCompilation = false;
|
|
37
|
-
hasCompileErrors = false;
|
|
38
|
-
if (isHotUpdate) {
|
|
39
|
-
tryApplyUpdates();
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
function handleWarnings(warnings) {
|
|
43
|
-
clearOutdatedErrors();
|
|
44
|
-
const isHotUpdate = !isFirstCompilation;
|
|
45
|
-
isFirstCompilation = false;
|
|
46
|
-
hasCompileErrors = false;
|
|
47
|
-
function printWarnings() {
|
|
48
|
-
const formatted = formatWebpackMessages({
|
|
49
|
-
warnings,
|
|
50
|
-
errors: []
|
|
51
|
-
});
|
|
52
|
-
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
53
|
-
for (let i = 0; i < formatted.warnings.length; i++) {
|
|
54
|
-
if (i === 5) {
|
|
55
|
-
console.warn(
|
|
56
|
-
"There were more warnings in other files.\nYou can find a complete log in the terminal."
|
|
57
|
-
);
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
console.warn(stripAnsi(formatted.warnings[i]));
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
printWarnings();
|
|
65
|
-
if (isHotUpdate) {
|
|
66
|
-
tryApplyUpdates();
|
|
67
|
-
}
|
|
4
|
+
const hadRuntimeError = false;
|
|
5
|
+
const socketUrl = createSocketUrl(__resourceQuery);
|
|
6
|
+
const 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
|
+
let isFirstCompilation = true;
|
|
18
|
+
let mostRecentCompilationHash = null;
|
|
19
|
+
let hasCompileErrors = false;
|
|
20
|
+
function clearOutdatedErrors() {
|
|
21
|
+
if (typeof console !== "undefined" && typeof console.clear === "function") {
|
|
22
|
+
if (hasCompileErrors) {
|
|
23
|
+
console.clear();
|
|
68
24
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function handleSuccess() {
|
|
28
|
+
clearOutdatedErrors();
|
|
29
|
+
const isHotUpdate = !isFirstCompilation;
|
|
30
|
+
isFirstCompilation = false;
|
|
31
|
+
hasCompileErrors = false;
|
|
32
|
+
if (isHotUpdate) {
|
|
33
|
+
tryApplyUpdates();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function handleWarnings(warnings) {
|
|
37
|
+
clearOutdatedErrors();
|
|
38
|
+
const isHotUpdate = !isFirstCompilation;
|
|
39
|
+
isFirstCompilation = false;
|
|
40
|
+
hasCompileErrors = false;
|
|
41
|
+
function printWarnings() {
|
|
42
|
+
const formatted = formatWebpackMessages({
|
|
43
|
+
warnings,
|
|
44
|
+
errors: []
|
|
45
|
+
});
|
|
46
|
+
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
47
|
+
for (let i = 0; i < formatted.warnings.length; i++) {
|
|
48
|
+
if (i === 5) {
|
|
49
|
+
console.warn("There were more warnings in other files.\nYou can find a complete log in the terminal.");
|
|
50
|
+
break;
|
|
80
51
|
}
|
|
52
|
+
console.warn(stripAnsi(formatted.warnings[i]));
|
|
81
53
|
}
|
|
82
54
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
handleWarnings(message.data);
|
|
101
|
-
break;
|
|
102
|
-
case "errors":
|
|
103
|
-
handleErrors(message.data);
|
|
104
|
-
break;
|
|
105
|
-
default:
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
function isUpdateAvailable() {
|
|
109
|
-
return mostRecentCompilationHash !== __webpack_hash__;
|
|
55
|
+
}
|
|
56
|
+
printWarnings();
|
|
57
|
+
if (isHotUpdate) {
|
|
58
|
+
tryApplyUpdates();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function handleErrors(errors) {
|
|
62
|
+
clearOutdatedErrors();
|
|
63
|
+
isFirstCompilation = false;
|
|
64
|
+
hasCompileErrors = true;
|
|
65
|
+
const formatted = formatWebpackMessages({
|
|
66
|
+
errors,
|
|
67
|
+
warnings: []
|
|
68
|
+
});
|
|
69
|
+
if (typeof console !== "undefined" && typeof console.error === "function") {
|
|
70
|
+
for (const error of formatted.errors) {
|
|
71
|
+
console.error(stripAnsi(error));
|
|
110
72
|
}
|
|
111
|
-
|
|
112
|
-
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function handleAvailableHash(hash) {
|
|
76
|
+
mostRecentCompilationHash = hash;
|
|
77
|
+
}
|
|
78
|
+
connection.onmessage = function(e) {
|
|
79
|
+
const message = JSON.parse(e.data);
|
|
80
|
+
switch (message.type) {
|
|
81
|
+
case "hash":
|
|
82
|
+
handleAvailableHash(message.data);
|
|
83
|
+
break;
|
|
84
|
+
case "still-ok":
|
|
85
|
+
case "ok":
|
|
86
|
+
handleSuccess();
|
|
87
|
+
break;
|
|
88
|
+
case "content-changed":
|
|
89
|
+
window.location.reload();
|
|
90
|
+
break;
|
|
91
|
+
case "warnings":
|
|
92
|
+
handleWarnings(message.data);
|
|
93
|
+
break;
|
|
94
|
+
case "errors":
|
|
95
|
+
handleErrors(message.data);
|
|
96
|
+
break;
|
|
97
|
+
default:
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
function isUpdateAvailable() {
|
|
101
|
+
return mostRecentCompilationHash !== __webpack_hash__;
|
|
102
|
+
}
|
|
103
|
+
function canApplyUpdates() {
|
|
104
|
+
return module.hot.status() === "idle";
|
|
105
|
+
}
|
|
106
|
+
function tryApplyUpdates() {
|
|
107
|
+
if (!module.hot) {
|
|
108
|
+
window.location.reload();
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (!isUpdateAvailable() || !canApplyUpdates()) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
function handleApplyUpdates(err, updatedModules) {
|
|
115
|
+
const wantsForcedReload = err || !updatedModules || hadRuntimeError;
|
|
116
|
+
if (wantsForcedReload) {
|
|
117
|
+
window.location.reload();
|
|
118
|
+
return;
|
|
113
119
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
window.location.reload();
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
if (!isUpdateAvailable() || !canApplyUpdates()) {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
function handleApplyUpdates(err, updatedModules) {
|
|
123
|
-
const wantsForcedReload = err || !updatedModules || hadRuntimeError;
|
|
124
|
-
if (wantsForcedReload) {
|
|
125
|
-
window.location.reload();
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
if (isUpdateAvailable()) {
|
|
129
|
-
tryApplyUpdates();
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
const result = module.hot.check(
|
|
133
|
-
/* autoApply */
|
|
134
|
-
true,
|
|
135
|
-
handleApplyUpdates
|
|
136
|
-
);
|
|
137
|
-
if (result == null ? void 0 : result.then) {
|
|
138
|
-
result.then(
|
|
139
|
-
(updatedModules) => {
|
|
140
|
-
handleApplyUpdates(null, updatedModules);
|
|
141
|
-
},
|
|
142
|
-
(err) => {
|
|
143
|
-
handleApplyUpdates(err, null);
|
|
144
|
-
}
|
|
145
|
-
);
|
|
146
|
-
}
|
|
120
|
+
if (isUpdateAvailable()) {
|
|
121
|
+
tryApplyUpdates();
|
|
147
122
|
}
|
|
148
123
|
}
|
|
149
|
-
|
|
150
|
-
|
|
124
|
+
const result = module.hot.check(
|
|
125
|
+
/* autoApply */
|
|
126
|
+
true,
|
|
127
|
+
handleApplyUpdates
|
|
128
|
+
);
|
|
129
|
+
if (result === null || result === void 0 ? void 0 : result.then) {
|
|
130
|
+
result.then((updatedModules) => {
|
|
131
|
+
handleApplyUpdates(null, updatedModules);
|
|
132
|
+
}, (err) => {
|
|
133
|
+
handleApplyUpdates(err, null);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -1,31 +1,36 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
1
14
|
import { EventEmitter } from "events";
|
|
2
15
|
import SocketServer from "./socketServer";
|
|
3
16
|
const noop = () => {
|
|
4
17
|
};
|
|
5
18
|
function getHMRClientPath(client) {
|
|
6
|
-
const protocol = (client
|
|
7
|
-
const host = (client
|
|
8
|
-
const path = (client
|
|
9
|
-
const port = (client
|
|
19
|
+
const protocol = (client === null || client === void 0 ? void 0 : client.protocol) ? `&protocol=${client.protocol}` : "";
|
|
20
|
+
const host = (client === null || client === void 0 ? void 0 : client.host) ? `&host=${client.host}` : "";
|
|
21
|
+
const path = (client === null || client === void 0 ? void 0 : client.path) ? `&path=${client.path}` : "";
|
|
22
|
+
const port = (client === null || client === void 0 ? void 0 : client.port) ? `&port=${client.port}` : "";
|
|
10
23
|
const clientEntry = `${require.resolve("@modern-js/server/hmr-client")}?${host}${path}${port}${protocol}`;
|
|
11
24
|
return clientEntry;
|
|
12
25
|
}
|
|
13
26
|
class DevMiddleware extends EventEmitter {
|
|
14
|
-
constructor({ dev, devMiddleware }) {
|
|
15
|
-
super();
|
|
16
|
-
this.devOptions = dev;
|
|
17
|
-
this.socketServer = new SocketServer(dev);
|
|
18
|
-
if (devMiddleware) {
|
|
19
|
-
this.middleware = this.setupDevMiddleware(devMiddleware);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
27
|
init(app) {
|
|
23
28
|
app.on("listening", () => {
|
|
24
29
|
this.socketServer.prepare(app);
|
|
25
30
|
});
|
|
26
31
|
app.on("close", async () => {
|
|
27
|
-
var
|
|
28
|
-
(
|
|
32
|
+
var _this_middleware;
|
|
33
|
+
(_this_middleware = this.middleware) === null || _this_middleware === void 0 ? void 0 : _this_middleware.close(noop);
|
|
29
34
|
this.socketServer.close();
|
|
30
35
|
});
|
|
31
36
|
}
|
|
@@ -53,7 +58,16 @@ class DevMiddleware extends EventEmitter {
|
|
|
53
58
|
});
|
|
54
59
|
return middleware;
|
|
55
60
|
}
|
|
61
|
+
constructor({ dev, devMiddleware }) {
|
|
62
|
+
super();
|
|
63
|
+
_define_property(this, "middleware", void 0);
|
|
64
|
+
_define_property(this, "devOptions", void 0);
|
|
65
|
+
_define_property(this, "socketServer", void 0);
|
|
66
|
+
this.devOptions = dev;
|
|
67
|
+
this.socketServer = new SocketServer(dev);
|
|
68
|
+
if (devMiddleware) {
|
|
69
|
+
this.middleware = this.setupDevMiddleware(devMiddleware);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
56
72
|
}
|
|
57
|
-
export {
|
|
58
|
-
DevMiddleware as default
|
|
59
|
-
};
|
|
73
|
+
export { DevMiddleware as default };
|
|
@@ -1,18 +1,26 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
1
14
|
import ws from "ws";
|
|
2
15
|
import { logger } from "@modern-js/utils";
|
|
3
16
|
class SocketServer {
|
|
4
|
-
constructor(options) {
|
|
5
|
-
this.sockets = [];
|
|
6
|
-
this.timer = null;
|
|
7
|
-
this.options = options;
|
|
8
|
-
}
|
|
9
17
|
// create socket, install socket handler, bind socket event
|
|
10
18
|
prepare(app) {
|
|
11
|
-
var
|
|
19
|
+
var _this_options_client;
|
|
12
20
|
this.app = app;
|
|
13
21
|
this.wsServer = new ws.Server({
|
|
14
22
|
noServer: true,
|
|
15
|
-
path: (
|
|
23
|
+
path: (_this_options_client = this.options.client) === null || _this_options_client === void 0 ? void 0 : _this_options_client.path
|
|
16
24
|
});
|
|
17
25
|
this.app.on("upgrade", (req, sock, head) => {
|
|
18
26
|
if (!this.wsServer.shouldHandle(req)) {
|
|
@@ -48,11 +56,17 @@ class SocketServer {
|
|
|
48
56
|
// write message to each socket
|
|
49
57
|
sockWrite(type, data) {
|
|
50
58
|
this.sockets.forEach((socket) => {
|
|
51
|
-
this.send(socket, JSON.stringify({
|
|
59
|
+
this.send(socket, JSON.stringify({
|
|
60
|
+
type,
|
|
61
|
+
data
|
|
62
|
+
}));
|
|
52
63
|
});
|
|
53
64
|
}
|
|
54
65
|
singleWrite(socket, type, data) {
|
|
55
|
-
this.send(socket, JSON.stringify({
|
|
66
|
+
this.send(socket, JSON.stringify({
|
|
67
|
+
type,
|
|
68
|
+
data
|
|
69
|
+
}));
|
|
56
70
|
}
|
|
57
71
|
close() {
|
|
58
72
|
this.sockets.forEach((socket) => {
|
|
@@ -131,7 +145,14 @@ class SocketServer {
|
|
|
131
145
|
}
|
|
132
146
|
connection.send(message);
|
|
133
147
|
}
|
|
148
|
+
constructor(options) {
|
|
149
|
+
_define_property(this, "wsServer", void 0);
|
|
150
|
+
_define_property(this, "sockets", []);
|
|
151
|
+
_define_property(this, "options", void 0);
|
|
152
|
+
_define_property(this, "app", void 0);
|
|
153
|
+
_define_property(this, "stats", void 0);
|
|
154
|
+
_define_property(this, "timer", null);
|
|
155
|
+
this.options = options;
|
|
156
|
+
}
|
|
134
157
|
}
|
|
135
|
-
export {
|
|
136
|
-
SocketServer as default
|
|
137
|
-
};
|
|
158
|
+
export { SocketServer as default };
|