@modern-js/server 2.0.0-beta.3 → 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 +79 -0
- package/dist/js/modern/constants.js +10 -9
- package/dist/js/modern/dev-tools/dev-middleware/dev-server-plugin.js +14 -20
- package/dist/js/modern/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +14 -19
- package/dist/js/modern/dev-tools/dev-middleware/hmr-client/index.js +134 -184
- package/dist/js/modern/dev-tools/dev-middleware/hmr-client/types.d.js +0 -0
- package/dist/js/modern/dev-tools/dev-middleware/index.js +65 -60
- package/dist/js/modern/dev-tools/dev-middleware/socket-server.js +33 -59
- package/dist/js/modern/dev-tools/https/global.d.js +0 -0
- package/dist/js/modern/dev-tools/https/index.js +28 -5
- package/dist/js/modern/dev-tools/mock/getMockData.js +71 -45
- package/dist/js/modern/dev-tools/mock/index.js +34 -15
- package/dist/js/modern/dev-tools/register/index.js +71 -54
- package/dist/js/modern/dev-tools/watcher/dependency-tree.js +25 -34
- package/dist/js/modern/dev-tools/watcher/index.js +51 -33
- package/dist/js/modern/dev-tools/watcher/stats-cache.js +13 -20
- package/dist/js/modern/index.js +7 -4
- package/dist/js/modern/server/dev-server.js +191 -215
- package/dist/js/modern/server/index.js +7 -4
- package/dist/js/node/constants.js +27 -14
- package/dist/js/node/dev-tools/dev-middleware/dev-server-plugin.js +36 -24
- package/dist/js/node/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +31 -24
- package/dist/js/node/dev-tools/dev-middleware/hmr-client/index.js +56 -98
- package/dist/js/node/dev-tools/dev-middleware/hmr-client/types.d.js +0 -0
- package/dist/js/node/dev-tools/dev-middleware/index.js +94 -72
- package/dist/js/node/dev-tools/dev-middleware/socket-server.js +57 -66
- package/dist/js/node/dev-tools/https/global.d.js +0 -0
- package/dist/js/node/dev-tools/https/index.js +52 -13
- package/dist/js/node/dev-tools/mock/getMockData.js +88 -51
- package/dist/js/node/dev-tools/mock/index.js +62 -28
- package/dist/js/node/dev-tools/register/index.js +98 -64
- package/dist/js/node/dev-tools/watcher/dependency-tree.js +50 -43
- package/dist/js/node/dev-tools/watcher/index.js +79 -47
- package/dist/js/node/dev-tools/watcher/stats-cache.js +40 -30
- package/dist/js/node/index.js +25 -15
- package/dist/js/node/server/dev-server.js +234 -237
- package/dist/js/node/server/index.js +26 -11
- package/dist/js/treeshaking/constants.js +21 -0
- package/dist/js/treeshaking/dev-tools/dev-middleware/dev-server-plugin.js +74 -0
- package/dist/js/treeshaking/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +51 -0
- package/dist/js/treeshaking/dev-tools/dev-middleware/hmr-client/index.js +157 -0
- package/dist/js/treeshaking/dev-tools/dev-middleware/hmr-client/types.d.js +1 -0
- package/dist/js/treeshaking/dev-tools/dev-middleware/index.js +363 -0
- package/dist/js/treeshaking/dev-tools/dev-middleware/socket-server.js +209 -0
- package/dist/js/treeshaking/dev-tools/https/global.d.js +1 -0
- package/dist/js/treeshaking/dev-tools/https/index.js +161 -0
- package/dist/js/treeshaking/dev-tools/mock/getMockData.js +327 -0
- package/dist/js/treeshaking/dev-tools/mock/index.js +191 -0
- package/dist/js/treeshaking/dev-tools/register/index.js +153 -0
- package/dist/js/treeshaking/dev-tools/watcher/dependency-tree.js +150 -0
- package/dist/js/treeshaking/dev-tools/watcher/index.js +200 -0
- package/dist/js/treeshaking/dev-tools/watcher/stats-cache.js +128 -0
- package/dist/js/treeshaking/index.js +9 -0
- package/dist/js/treeshaking/server/dev-server.js +800 -0
- package/dist/js/treeshaking/server/index.js +92 -0
- package/dist/js/treeshaking/types.js +1 -0
- package/dist/types/dev-tools/mock/getMockData.d.ts +2 -0
- package/dist/types/dev-tools/watcher/dependency-tree.d.ts +2 -0
- package/dist/types/dev-tools/watcher/index.d.ts +1 -1
- package/dist/types/index.d.ts +2 -0
- package/package.json +16 -13
- package/temp-fix-hmr.js +483 -0
|
@@ -1,17 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var stdin_exports = {};
|
|
19
|
+
__export(stdin_exports, {
|
|
20
|
+
createSocketUrl: () => createSocketUrl,
|
|
21
|
+
formatURL: () => formatURL
|
|
5
22
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
var _constants = require("@modern-js/utils/constants");
|
|
23
|
+
module.exports = __toCommonJS(stdin_exports);
|
|
24
|
+
var import_constants = require("@modern-js/utils/constants");
|
|
9
25
|
function createSocketUrl(resourceQuery) {
|
|
10
|
-
|
|
11
|
-
const searchParams = resourceQuery.substr(1).split('&');
|
|
26
|
+
const searchParams = resourceQuery.substr(1).split("&");
|
|
12
27
|
const options = {};
|
|
13
28
|
for (const pair of searchParams) {
|
|
14
|
-
const ary = pair.split(
|
|
29
|
+
const ary = pair.split("=");
|
|
15
30
|
options[ary[0]] = decodeURIComponent(ary[1]);
|
|
16
31
|
}
|
|
17
32
|
const currentLocation = self.location;
|
|
@@ -24,30 +39,22 @@ function formatURL({
|
|
|
24
39
|
pathname
|
|
25
40
|
}) {
|
|
26
41
|
if (window.URL) {
|
|
27
|
-
|
|
28
|
-
const url = new URL('http://localhost');
|
|
42
|
+
const url = new URL("http://localhost");
|
|
29
43
|
url.port = port;
|
|
30
44
|
url.hostname = hostname;
|
|
31
45
|
url.protocol = protocol;
|
|
32
46
|
url.pathname = pathname;
|
|
33
47
|
return url.toString();
|
|
34
48
|
}
|
|
35
|
-
|
|
36
|
-
// compatible with IE11
|
|
37
|
-
const colon = protocol.indexOf(':') === -1 ? ':' : '';
|
|
49
|
+
const colon = protocol.indexOf(":") === -1 ? ":" : "";
|
|
38
50
|
return `${protocol}${colon}//${hostname}:${port}${pathname}`;
|
|
39
51
|
}
|
|
40
52
|
function getSocketUrl(urlParts, location) {
|
|
41
|
-
const {
|
|
42
|
-
host,
|
|
43
|
-
port,
|
|
44
|
-
path,
|
|
45
|
-
protocol
|
|
46
|
-
} = urlParts;
|
|
53
|
+
const { host, port, path, protocol } = urlParts;
|
|
47
54
|
return formatURL({
|
|
48
|
-
protocol: protocol || location.protocol ===
|
|
55
|
+
protocol: protocol || location.protocol === "https:" ? "wss" : "ws",
|
|
49
56
|
hostname: host || location.hostname,
|
|
50
57
|
port: port || location.port,
|
|
51
|
-
pathname: path ||
|
|
58
|
+
pathname: path || import_constants.HMR_SOCK_PATH
|
|
52
59
|
});
|
|
53
|
-
}
|
|
60
|
+
}
|
|
@@ -1,167 +1,127 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
+
for (let key of __getOwnPropNames(from))
|
|
10
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
11
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
+
}
|
|
13
|
+
return to;
|
|
14
|
+
};
|
|
15
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
17
|
+
mod
|
|
18
|
+
));
|
|
19
|
+
var import_strip_ansi = __toESM(require("@modern-js/utils/strip-ansi"));
|
|
20
|
+
var import_format = require("@modern-js/utils/format");
|
|
21
|
+
var import_createSocketUrl = require("./createSocketUrl");
|
|
21
22
|
const hadRuntimeError = false;
|
|
22
|
-
|
|
23
|
-
// Connect to Dev Server
|
|
24
|
-
const socketUrl = (0, _createSocketUrl.createSocketUrl)(__resourceQuery);
|
|
23
|
+
const socketUrl = (0, import_createSocketUrl.createSocketUrl)(__resourceQuery);
|
|
25
24
|
const connection = new WebSocket(socketUrl);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (typeof console !== 'undefined' && typeof console.info === 'function') {
|
|
32
|
-
console.info('The development server has disconnected.\nRefresh the page if necessary.');
|
|
25
|
+
connection.onclose = function() {
|
|
26
|
+
if (typeof console !== "undefined" && typeof console.info === "function") {
|
|
27
|
+
console.info(
|
|
28
|
+
"The development server has disconnected. Refresh the page if necessary."
|
|
29
|
+
);
|
|
33
30
|
}
|
|
34
31
|
};
|
|
35
|
-
|
|
36
|
-
// Remember some state related to hot module replacement.
|
|
37
32
|
let isFirstCompilation = true;
|
|
38
33
|
let mostRecentCompilationHash = null;
|
|
39
34
|
let hasCompileErrors = false;
|
|
40
35
|
function clearOutdatedErrors() {
|
|
41
|
-
|
|
42
|
-
// eslint-disable-next-line node/no-unsupported-features/node-builtins, no-console
|
|
43
|
-
if (typeof console !== 'undefined' && typeof console.clear === 'function') {
|
|
36
|
+
if (typeof console !== "undefined" && typeof console.clear === "function") {
|
|
44
37
|
if (hasCompileErrors) {
|
|
45
|
-
// eslint-disable-next-line node/no-unsupported-features/node-builtins, no-console
|
|
46
38
|
console.clear();
|
|
47
39
|
}
|
|
48
40
|
}
|
|
49
41
|
}
|
|
50
|
-
|
|
51
|
-
// Successful compilation.
|
|
52
42
|
function handleSuccess() {
|
|
53
43
|
clearOutdatedErrors();
|
|
54
44
|
const isHotUpdate = !isFirstCompilation;
|
|
55
45
|
isFirstCompilation = false;
|
|
56
46
|
hasCompileErrors = false;
|
|
57
|
-
|
|
58
|
-
// Attempt to apply hot updates or reload.
|
|
59
47
|
if (isHotUpdate) {
|
|
60
48
|
tryApplyUpdates();
|
|
61
49
|
}
|
|
62
50
|
}
|
|
63
|
-
|
|
64
|
-
// Compilation with warnings (e.g. ESLint).
|
|
65
51
|
function handleWarnings(warnings) {
|
|
66
52
|
clearOutdatedErrors();
|
|
67
53
|
const isHotUpdate = !isFirstCompilation;
|
|
68
54
|
isFirstCompilation = false;
|
|
69
55
|
hasCompileErrors = false;
|
|
70
56
|
function printWarnings() {
|
|
71
|
-
|
|
72
|
-
const formatted = (0, _format.formatWebpackMessages)({
|
|
57
|
+
const formatted = (0, import_format.formatWebpackMessages)({
|
|
73
58
|
warnings,
|
|
74
59
|
errors: []
|
|
75
60
|
});
|
|
76
|
-
if (typeof console !==
|
|
61
|
+
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
77
62
|
for (let i = 0; i < formatted.warnings.length; i++) {
|
|
78
63
|
if (i === 5) {
|
|
79
|
-
console.warn(
|
|
64
|
+
console.warn(
|
|
65
|
+
"There were more warnings in other files. You can find a complete log in the terminal."
|
|
66
|
+
);
|
|
80
67
|
break;
|
|
81
68
|
}
|
|
82
|
-
console.warn((0,
|
|
69
|
+
console.warn((0, import_strip_ansi.default)(formatted.warnings[i]));
|
|
83
70
|
}
|
|
84
71
|
}
|
|
85
72
|
}
|
|
86
73
|
printWarnings();
|
|
87
|
-
|
|
88
|
-
// Attempt to apply hot updates or reload.
|
|
89
74
|
if (isHotUpdate) {
|
|
90
75
|
tryApplyUpdates();
|
|
91
76
|
}
|
|
92
77
|
}
|
|
93
|
-
|
|
94
|
-
// Compilation with errors (e.g. syntax error or missing modules).
|
|
95
78
|
function handleErrors(errors) {
|
|
96
79
|
clearOutdatedErrors();
|
|
97
80
|
isFirstCompilation = false;
|
|
98
81
|
hasCompileErrors = true;
|
|
99
|
-
|
|
100
|
-
// "Massage" webpack messages.
|
|
101
|
-
const formatted = (0, _format.formatWebpackMessages)({
|
|
82
|
+
const formatted = (0, import_format.formatWebpackMessages)({
|
|
102
83
|
errors,
|
|
103
84
|
warnings: []
|
|
104
85
|
});
|
|
105
|
-
|
|
106
|
-
// Also log them to the console.
|
|
107
|
-
if (typeof console !== 'undefined' && typeof console.error === 'function') {
|
|
86
|
+
if (typeof console !== "undefined" && typeof console.error === "function") {
|
|
108
87
|
for (const error of formatted.errors) {
|
|
109
|
-
console.error((0,
|
|
88
|
+
console.error((0, import_strip_ansi.default)(error));
|
|
110
89
|
}
|
|
111
90
|
}
|
|
112
|
-
|
|
113
|
-
// Do not attempt to reload now.
|
|
114
|
-
// We will reload on next success instead.
|
|
115
91
|
}
|
|
116
|
-
|
|
117
|
-
// There is a newer version of the code available.
|
|
118
92
|
function handleAvailableHash(hash) {
|
|
119
|
-
// Update last known compilation hash.
|
|
120
93
|
mostRecentCompilationHash = hash;
|
|
121
94
|
}
|
|
122
|
-
|
|
123
|
-
// Handle messages from the server.
|
|
124
|
-
connection.onmessage = function (e) {
|
|
95
|
+
connection.onmessage = function(e) {
|
|
125
96
|
const message = JSON.parse(e.data);
|
|
126
97
|
switch (message.type) {
|
|
127
|
-
case
|
|
98
|
+
case "hash":
|
|
128
99
|
handleAvailableHash(message.data);
|
|
129
100
|
break;
|
|
130
|
-
case
|
|
131
|
-
case
|
|
101
|
+
case "still-ok":
|
|
102
|
+
case "ok":
|
|
132
103
|
handleSuccess();
|
|
133
104
|
break;
|
|
134
|
-
case
|
|
135
|
-
// Triggered when a file from `contentBase` changed.
|
|
105
|
+
case "content-changed":
|
|
136
106
|
window.location.reload();
|
|
137
107
|
break;
|
|
138
|
-
case
|
|
108
|
+
case "warnings":
|
|
139
109
|
handleWarnings(message.data);
|
|
140
110
|
break;
|
|
141
|
-
case
|
|
111
|
+
case "errors":
|
|
142
112
|
handleErrors(message.data);
|
|
143
113
|
break;
|
|
144
114
|
default:
|
|
145
|
-
// Do nothing.
|
|
146
115
|
}
|
|
147
116
|
};
|
|
148
|
-
|
|
149
|
-
// Is there a newer version of this code available?
|
|
150
117
|
function isUpdateAvailable() {
|
|
151
|
-
// __webpack_hash__ is the hash of the current compilation.
|
|
152
|
-
// It's a global variable injected by webpack.
|
|
153
118
|
return mostRecentCompilationHash !== __webpack_hash__;
|
|
154
119
|
}
|
|
155
|
-
|
|
156
|
-
// webpack disallows updates in other states.
|
|
157
120
|
function canApplyUpdates() {
|
|
158
|
-
return module.hot.status() ===
|
|
121
|
+
return module.hot.status() === "idle";
|
|
159
122
|
}
|
|
160
|
-
|
|
161
|
-
// Attempt to update code on the fly, fall back to a hard reload.
|
|
162
123
|
function tryApplyUpdates() {
|
|
163
124
|
if (!module.hot) {
|
|
164
|
-
// HotModuleReplacementPlugin is not in webpack configuration.
|
|
165
125
|
window.location.reload();
|
|
166
126
|
return;
|
|
167
127
|
}
|
|
@@ -175,20 +135,18 @@ function tryApplyUpdates() {
|
|
|
175
135
|
return;
|
|
176
136
|
}
|
|
177
137
|
if (isUpdateAvailable()) {
|
|
178
|
-
// While we were updating, there was a new update! Do it again.
|
|
179
138
|
tryApplyUpdates();
|
|
180
139
|
}
|
|
181
140
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
});
|
|
141
|
+
const result = module.hot.check(true, handleApplyUpdates);
|
|
142
|
+
if (result == null ? void 0 : result.then) {
|
|
143
|
+
result.then(
|
|
144
|
+
(updatedModules) => {
|
|
145
|
+
handleApplyUpdates(null, updatedModules);
|
|
146
|
+
},
|
|
147
|
+
(err) => {
|
|
148
|
+
handleApplyUpdates(err, null);
|
|
149
|
+
}
|
|
150
|
+
);
|
|
193
151
|
}
|
|
194
|
-
}
|
|
152
|
+
}
|
|
File without changes
|
|
@@ -1,72 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var stdin_exports = {};
|
|
25
|
+
__export(stdin_exports, {
|
|
26
|
+
default: () => DevMiddleware
|
|
5
27
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
28
|
+
module.exports = __toCommonJS(stdin_exports);
|
|
29
|
+
var import_events = require("events");
|
|
30
|
+
var import_webpack_dev_middleware = __toESM(require("@modern-js/utils/webpack-dev-middleware"));
|
|
31
|
+
var import_dev_server_plugin = __toESM(require("./dev-server-plugin"));
|
|
32
|
+
var import_socket_server = __toESM(require("./socket-server"));
|
|
33
|
+
var __defProp2 = Object.defineProperty;
|
|
34
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
35
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
36
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
37
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
38
|
+
var __spreadValues = (a, b) => {
|
|
39
|
+
for (var prop in b || (b = {}))
|
|
40
|
+
if (__hasOwnProp2.call(b, prop))
|
|
41
|
+
__defNormalProp(a, prop, b[prop]);
|
|
42
|
+
if (__getOwnPropSymbols)
|
|
43
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
44
|
+
if (__propIsEnum.call(b, prop))
|
|
45
|
+
__defNormalProp(a, prop, b[prop]);
|
|
46
|
+
}
|
|
47
|
+
return a;
|
|
48
|
+
};
|
|
49
|
+
var __async = (__this, __arguments, generator) => {
|
|
50
|
+
return new Promise((resolve, reject) => {
|
|
51
|
+
var fulfilled = (value) => {
|
|
52
|
+
try {
|
|
53
|
+
step(generator.next(value));
|
|
54
|
+
} catch (e) {
|
|
55
|
+
reject(e);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
var rejected = (value) => {
|
|
59
|
+
try {
|
|
60
|
+
step(generator.throw(value));
|
|
61
|
+
} catch (e) {
|
|
62
|
+
reject(e);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
66
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
67
|
+
});
|
|
68
|
+
};
|
|
15
69
|
const noop = () => {
|
|
16
|
-
// noop
|
|
17
70
|
};
|
|
18
|
-
class DevMiddleware extends
|
|
19
|
-
constructor({
|
|
20
|
-
compiler,
|
|
21
|
-
dev,
|
|
22
|
-
devMiddleware
|
|
23
|
-
}) {
|
|
71
|
+
class DevMiddleware extends import_events.EventEmitter {
|
|
72
|
+
constructor({ compiler, dev, devMiddleware }) {
|
|
24
73
|
super();
|
|
25
|
-
_defineProperty(this, "middleware", void 0);
|
|
26
|
-
_defineProperty(this, "compiler", void 0);
|
|
27
|
-
_defineProperty(this, "devOptions", void 0);
|
|
28
|
-
_defineProperty(this, "socketServer", void 0);
|
|
29
74
|
this.compiler = compiler;
|
|
30
75
|
this.devOptions = dev;
|
|
31
|
-
|
|
32
|
-
// init socket server
|
|
33
|
-
this.socketServer = new _socketServer.default(dev);
|
|
34
|
-
|
|
35
|
-
// Todo: should remove after abstract dev middleware
|
|
76
|
+
this.socketServer = new import_socket_server.default(dev);
|
|
36
77
|
if (this.compiler) {
|
|
37
|
-
// setup compiler in server, also add dev-middleware to handler static file in memory
|
|
38
|
-
// set up plugin to each compiler
|
|
39
78
|
this.setupDevServerPlugin();
|
|
40
|
-
// register hooks for each compilation, update socket stats if recompiled
|
|
41
79
|
this.setupHooks();
|
|
42
|
-
// start dev middleware
|
|
43
80
|
this.middleware = this.setupDevMiddleware(devMiddleware);
|
|
44
81
|
}
|
|
45
82
|
}
|
|
46
83
|
init(app) {
|
|
47
|
-
app.on(
|
|
84
|
+
app.on("listening", () => {
|
|
48
85
|
this.socketServer.prepare(app);
|
|
49
86
|
});
|
|
50
|
-
app.on(
|
|
51
|
-
var
|
|
52
|
-
(
|
|
87
|
+
app.on("close", () => __async(this, null, function* () {
|
|
88
|
+
var _a;
|
|
89
|
+
(_a = this.middleware) == null ? void 0 : _a.close(noop);
|
|
53
90
|
this.socketServer.close();
|
|
54
|
-
});
|
|
91
|
+
}));
|
|
55
92
|
}
|
|
56
93
|
setupDevServerPlugin() {
|
|
57
|
-
const {
|
|
58
|
-
devOptions
|
|
59
|
-
} = this;
|
|
60
|
-
|
|
61
|
-
// apply dev server to client compiler, add hmr client to entry.
|
|
94
|
+
const { devOptions } = this;
|
|
62
95
|
if (this.compiler.compilers) {
|
|
63
|
-
this.compiler.compilers.forEach(target => {
|
|
96
|
+
this.compiler.compilers.forEach((target) => {
|
|
64
97
|
if (this.isClientCompiler(target)) {
|
|
65
|
-
new
|
|
98
|
+
new import_dev_server_plugin.default(devOptions).apply(target);
|
|
66
99
|
}
|
|
67
100
|
});
|
|
68
101
|
} else {
|
|
69
|
-
new
|
|
102
|
+
new import_dev_server_plugin.default(devOptions).apply(this.compiler);
|
|
70
103
|
}
|
|
71
104
|
}
|
|
72
105
|
sockWrite(type, data) {
|
|
@@ -74,22 +107,18 @@ class DevMiddleware extends _events.EventEmitter {
|
|
|
74
107
|
}
|
|
75
108
|
setupHooks() {
|
|
76
109
|
const invalidPlugin = () => {
|
|
77
|
-
this.socketServer.sockWrite(
|
|
110
|
+
this.socketServer.sockWrite("invalid");
|
|
78
111
|
};
|
|
79
|
-
const addHooks = compiler => {
|
|
80
|
-
if (compiler.name ===
|
|
112
|
+
const addHooks = (compiler) => {
|
|
113
|
+
if (compiler.name === "server") {
|
|
81
114
|
return;
|
|
82
115
|
}
|
|
83
|
-
const {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
} = compiler.hooks;
|
|
88
|
-
compile.tap('modern-dev-server', invalidPlugin);
|
|
89
|
-
invalid.tap('modern-dev-server', invalidPlugin);
|
|
90
|
-
done.tap('modern-dev-server', stats => {
|
|
116
|
+
const { compile, invalid, done } = compiler.hooks;
|
|
117
|
+
compile.tap("modern-dev-server", invalidPlugin);
|
|
118
|
+
invalid.tap("modern-dev-server", invalidPlugin);
|
|
119
|
+
done.tap("modern-dev-server", (stats) => {
|
|
91
120
|
this.socketServer.updateStats(stats);
|
|
92
|
-
this.emit(
|
|
121
|
+
this.emit("change", stats);
|
|
93
122
|
});
|
|
94
123
|
};
|
|
95
124
|
if (this.compiler.compilers) {
|
|
@@ -98,29 +127,22 @@ class DevMiddleware extends _events.EventEmitter {
|
|
|
98
127
|
addHooks(this.compiler);
|
|
99
128
|
}
|
|
100
129
|
}
|
|
101
|
-
setupDevMiddleware(devMiddleware =
|
|
102
|
-
const {
|
|
103
|
-
|
|
104
|
-
} = this;
|
|
105
|
-
const middleware = devMiddleware(this.compiler, _objectSpread({
|
|
130
|
+
setupDevMiddleware(devMiddleware = import_webpack_dev_middleware.default) {
|
|
131
|
+
const { devOptions } = this;
|
|
132
|
+
const middleware = devMiddleware(this.compiler, __spreadValues({
|
|
106
133
|
headers: devOptions.headers,
|
|
107
134
|
stats: false
|
|
108
135
|
}, devOptions.devMiddleware));
|
|
109
136
|
return middleware;
|
|
110
137
|
}
|
|
111
138
|
isClientCompiler(compiler) {
|
|
112
|
-
const {
|
|
113
|
-
target
|
|
114
|
-
} = compiler.options;
|
|
115
|
-
|
|
116
|
-
// if target not contains `node`, it's a client compiler
|
|
139
|
+
const { target } = compiler.options;
|
|
117
140
|
if (target) {
|
|
118
141
|
if (Array.isArray(target)) {
|
|
119
|
-
return !target.includes(
|
|
142
|
+
return !target.includes("node");
|
|
120
143
|
}
|
|
121
|
-
return target !==
|
|
144
|
+
return target !== "node";
|
|
122
145
|
}
|
|
123
|
-
return compiler.name ===
|
|
146
|
+
return compiler.name === "client";
|
|
124
147
|
}
|
|
125
148
|
}
|
|
126
|
-
exports.default = DevMiddleware;
|