@modern-js/server 2.15.1-alpha.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 -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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @modern-js/server
|
|
2
2
|
|
|
3
|
+
## 2.16.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 4e876ab: chore: package.json include the monorepo-relative directory
|
|
8
|
+
|
|
9
|
+
chore: 在 package.json 中声明 monorepo 的子路径
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [5954330]
|
|
12
|
+
- Updated dependencies [7596520]
|
|
13
|
+
- Updated dependencies [4e876ab]
|
|
14
|
+
- @modern-js/utils@2.16.0
|
|
15
|
+
- @modern-js/prod-server@2.16.0
|
|
16
|
+
- @modern-js/types@2.16.0
|
|
17
|
+
- @modern-js/server-utils@2.16.0
|
|
18
|
+
|
|
3
19
|
## 2.15.0
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/cjs/constants.js
CHANGED
|
@@ -1,30 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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 constants_exports = {};
|
|
19
|
-
__export(constants_exports, {
|
|
20
|
-
getDefaultDevOptions: () => getDefaultDevOptions
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "getDefaultDevOptions", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => getDefaultDevOptions
|
|
21
8
|
});
|
|
22
|
-
|
|
23
|
-
var import_constants = require("@modern-js/utils/universal/constants");
|
|
9
|
+
const _constants = require("@modern-js/utils/universal/constants");
|
|
24
10
|
const getDefaultDevOptions = () => {
|
|
25
11
|
return {
|
|
26
12
|
client: {
|
|
27
|
-
path:
|
|
13
|
+
path: _constants.HMR_SOCK_PATH,
|
|
28
14
|
// By default it is set to the port number of the dev server
|
|
29
15
|
port: "",
|
|
30
16
|
// By default it is set to "location.hostname"
|
|
@@ -33,13 +19,11 @@ const getDefaultDevOptions = () => {
|
|
|
33
19
|
protocol: ""
|
|
34
20
|
},
|
|
35
21
|
https: false,
|
|
36
|
-
devMiddleware: {
|
|
22
|
+
devMiddleware: {
|
|
23
|
+
writeToDisk: true
|
|
24
|
+
},
|
|
37
25
|
watch: true,
|
|
38
26
|
hot: true,
|
|
39
27
|
liveReload: true
|
|
40
28
|
};
|
|
41
29
|
};
|
|
42
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
43
|
-
0 && (module.exports = {
|
|
44
|
-
getDefaultDevOptions
|
|
45
|
-
});
|
|
@@ -1,27 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
6
|
for (var name in all)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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 createSocketUrl_exports = {};
|
|
19
|
-
__export(createSocketUrl_exports, {
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
20
13
|
createSocketUrl: () => createSocketUrl,
|
|
21
14
|
formatURL: () => formatURL
|
|
22
15
|
});
|
|
23
|
-
|
|
24
|
-
var import_constants = require("@modern-js/utils/universal/constants");
|
|
16
|
+
const _constants = require("@modern-js/utils/universal/constants");
|
|
25
17
|
function createSocketUrl(resourceQuery) {
|
|
26
18
|
const searchParams = resourceQuery.substr(1).split("&");
|
|
27
19
|
const options = {};
|
|
@@ -32,12 +24,7 @@ function createSocketUrl(resourceQuery) {
|
|
|
32
24
|
const currentLocation = self.location;
|
|
33
25
|
return getSocketUrl(options, currentLocation);
|
|
34
26
|
}
|
|
35
|
-
function formatURL({
|
|
36
|
-
port,
|
|
37
|
-
protocol,
|
|
38
|
-
hostname,
|
|
39
|
-
pathname
|
|
40
|
-
}) {
|
|
27
|
+
function formatURL({ port, protocol, hostname, pathname }) {
|
|
41
28
|
if (window.URL) {
|
|
42
29
|
const url = new URL("http://localhost");
|
|
43
30
|
url.port = port;
|
|
@@ -55,11 +42,6 @@ function getSocketUrl(urlParts, location) {
|
|
|
55
42
|
protocol: protocol || (location.protocol === "https:" ? "wss" : "ws"),
|
|
56
43
|
hostname: host || location.hostname,
|
|
57
44
|
port: port || location.port,
|
|
58
|
-
pathname: path ||
|
|
45
|
+
pathname: path || _constants.HMR_SOCK_PATH
|
|
59
46
|
});
|
|
60
47
|
}
|
|
61
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
62
|
-
0 && (module.exports = {
|
|
63
|
-
createSocketUrl,
|
|
64
|
-
formatURL
|
|
65
|
-
});
|
|
@@ -1,30 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return to;
|
|
14
|
-
};
|
|
15
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
-
mod
|
|
22
|
-
));
|
|
23
|
-
var import_strip_ansi = __toESM(require("@modern-js/utils/strip-ansi"));
|
|
24
|
-
var import_format_webpack = require("@modern-js/utils/universal/format-webpack");
|
|
25
|
-
var import_createSocketUrl = require("./createSocketUrl");
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
const _stripansi = /* @__PURE__ */ _interop_require_default(require("@modern-js/utils/strip-ansi"));
|
|
6
|
+
const _formatwebpack = require("@modern-js/utils/universal/format-webpack");
|
|
7
|
+
const _createSocketUrl = require("./createSocketUrl");
|
|
8
|
+
function _interop_require_default(obj) {
|
|
9
|
+
return obj && obj.__esModule ? obj : {
|
|
10
|
+
default: obj
|
|
11
|
+
};
|
|
12
|
+
}
|
|
26
13
|
const hadRuntimeError = false;
|
|
27
|
-
const socketUrl = (0,
|
|
14
|
+
const socketUrl = (0, _createSocketUrl.createSocketUrl)(__resourceQuery);
|
|
28
15
|
const connection = new WebSocket(socketUrl);
|
|
29
16
|
connection.onopen = function() {
|
|
30
17
|
if (typeof console !== "undefined" && typeof console.debug === "function") {
|
|
@@ -61,19 +48,17 @@ function handleWarnings(warnings) {
|
|
|
61
48
|
isFirstCompilation = false;
|
|
62
49
|
hasCompileErrors = false;
|
|
63
50
|
function printWarnings() {
|
|
64
|
-
const formatted = (0,
|
|
51
|
+
const formatted = (0, _formatwebpack.formatWebpackMessages)({
|
|
65
52
|
warnings,
|
|
66
53
|
errors: []
|
|
67
54
|
});
|
|
68
55
|
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
69
56
|
for (let i = 0; i < formatted.warnings.length; i++) {
|
|
70
57
|
if (i === 5) {
|
|
71
|
-
console.warn(
|
|
72
|
-
"There were more warnings in other files.\nYou can find a complete log in the terminal."
|
|
73
|
-
);
|
|
58
|
+
console.warn("There were more warnings in other files.\nYou can find a complete log in the terminal.");
|
|
74
59
|
break;
|
|
75
60
|
}
|
|
76
|
-
console.warn((0,
|
|
61
|
+
console.warn((0, _stripansi.default)(formatted.warnings[i]));
|
|
77
62
|
}
|
|
78
63
|
}
|
|
79
64
|
}
|
|
@@ -86,13 +71,13 @@ function handleErrors(errors) {
|
|
|
86
71
|
clearOutdatedErrors();
|
|
87
72
|
isFirstCompilation = false;
|
|
88
73
|
hasCompileErrors = true;
|
|
89
|
-
const formatted = (0,
|
|
74
|
+
const formatted = (0, _formatwebpack.formatWebpackMessages)({
|
|
90
75
|
errors,
|
|
91
76
|
warnings: []
|
|
92
77
|
});
|
|
93
78
|
if (typeof console !== "undefined" && typeof console.error === "function") {
|
|
94
79
|
for (const error of formatted.errors) {
|
|
95
|
-
console.error((0,
|
|
80
|
+
console.error((0, _stripansi.default)(error));
|
|
96
81
|
}
|
|
97
82
|
}
|
|
98
83
|
}
|
|
@@ -150,14 +135,11 @@ function tryApplyUpdates() {
|
|
|
150
135
|
true,
|
|
151
136
|
handleApplyUpdates
|
|
152
137
|
);
|
|
153
|
-
if (result
|
|
154
|
-
result.then(
|
|
155
|
-
(updatedModules)
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
handleApplyUpdates(err, null);
|
|
160
|
-
}
|
|
161
|
-
);
|
|
138
|
+
if (result === null || result === void 0 ? void 0 : result.then) {
|
|
139
|
+
result.then((updatedModules) => {
|
|
140
|
+
handleApplyUpdates(null, updatedModules);
|
|
141
|
+
}, (err) => {
|
|
142
|
+
handleApplyUpdates(err, null);
|
|
143
|
+
});
|
|
162
144
|
}
|
|
163
145
|
}
|
|
@@ -1,63 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var dev_middleware_exports = {};
|
|
29
|
-
__export(dev_middleware_exports, {
|
|
30
|
-
default: () => DevMiddleware
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
31
4
|
});
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => DevMiddleware
|
|
8
|
+
});
|
|
9
|
+
const _events = require("events");
|
|
10
|
+
const _socketServer = /* @__PURE__ */ _interop_require_default(require("./socketServer"));
|
|
11
|
+
function _define_property(obj, key, value) {
|
|
12
|
+
if (key in obj) {
|
|
13
|
+
Object.defineProperty(obj, key, {
|
|
14
|
+
value,
|
|
15
|
+
enumerable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true
|
|
18
|
+
});
|
|
19
|
+
} else {
|
|
20
|
+
obj[key] = value;
|
|
21
|
+
}
|
|
22
|
+
return obj;
|
|
23
|
+
}
|
|
24
|
+
function _interop_require_default(obj) {
|
|
25
|
+
return obj && obj.__esModule ? obj : {
|
|
26
|
+
default: obj
|
|
27
|
+
};
|
|
28
|
+
}
|
|
35
29
|
const noop = () => {
|
|
36
30
|
};
|
|
37
31
|
function getHMRClientPath(client) {
|
|
38
|
-
const protocol = (client
|
|
39
|
-
const host = (client
|
|
40
|
-
const path = (client
|
|
41
|
-
const port = (client
|
|
32
|
+
const protocol = (client === null || client === void 0 ? void 0 : client.protocol) ? `&protocol=${client.protocol}` : "";
|
|
33
|
+
const host = (client === null || client === void 0 ? void 0 : client.host) ? `&host=${client.host}` : "";
|
|
34
|
+
const path = (client === null || client === void 0 ? void 0 : client.path) ? `&path=${client.path}` : "";
|
|
35
|
+
const port = (client === null || client === void 0 ? void 0 : client.port) ? `&port=${client.port}` : "";
|
|
42
36
|
const clientEntry = `${require.resolve("@modern-js/server/hmr-client")}?${host}${path}${port}${protocol}`;
|
|
43
37
|
return clientEntry;
|
|
44
38
|
}
|
|
45
|
-
class DevMiddleware extends
|
|
46
|
-
constructor({ dev, devMiddleware }) {
|
|
47
|
-
super();
|
|
48
|
-
this.devOptions = dev;
|
|
49
|
-
this.socketServer = new import_socketServer.default(dev);
|
|
50
|
-
if (devMiddleware) {
|
|
51
|
-
this.middleware = this.setupDevMiddleware(devMiddleware);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
39
|
+
class DevMiddleware extends _events.EventEmitter {
|
|
54
40
|
init(app) {
|
|
55
41
|
app.on("listening", () => {
|
|
56
42
|
this.socketServer.prepare(app);
|
|
57
43
|
});
|
|
58
44
|
app.on("close", async () => {
|
|
59
|
-
var
|
|
60
|
-
(
|
|
45
|
+
var _this_middleware;
|
|
46
|
+
(_this_middleware = this.middleware) === null || _this_middleware === void 0 ? void 0 : _this_middleware.close(noop);
|
|
61
47
|
this.socketServer.close();
|
|
62
48
|
});
|
|
63
49
|
}
|
|
@@ -85,6 +71,15 @@ class DevMiddleware extends import_events.EventEmitter {
|
|
|
85
71
|
});
|
|
86
72
|
return middleware;
|
|
87
73
|
}
|
|
74
|
+
constructor({ dev, devMiddleware }) {
|
|
75
|
+
super();
|
|
76
|
+
_define_property(this, "middleware", void 0);
|
|
77
|
+
_define_property(this, "devOptions", void 0);
|
|
78
|
+
_define_property(this, "socketServer", void 0);
|
|
79
|
+
this.devOptions = dev;
|
|
80
|
+
this.socketServer = new _socketServer.default(dev);
|
|
81
|
+
if (devMiddleware) {
|
|
82
|
+
this.middleware = this.setupDevMiddleware(devMiddleware);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
88
85
|
}
|
|
89
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
90
|
-
0 && (module.exports = {});
|
|
@@ -1,50 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var socketServer_exports = {};
|
|
29
|
-
__export(socketServer_exports, {
|
|
30
|
-
default: () => SocketServer
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
31
4
|
});
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => SocketServer
|
|
8
|
+
});
|
|
9
|
+
const _ws = /* @__PURE__ */ _interop_require_default(require("ws"));
|
|
10
|
+
const _utils = require("@modern-js/utils");
|
|
11
|
+
function _define_property(obj, key, value) {
|
|
12
|
+
if (key in obj) {
|
|
13
|
+
Object.defineProperty(obj, key, {
|
|
14
|
+
value,
|
|
15
|
+
enumerable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true
|
|
18
|
+
});
|
|
19
|
+
} else {
|
|
20
|
+
obj[key] = value;
|
|
40
21
|
}
|
|
22
|
+
return obj;
|
|
23
|
+
}
|
|
24
|
+
function _interop_require_default(obj) {
|
|
25
|
+
return obj && obj.__esModule ? obj : {
|
|
26
|
+
default: obj
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
class SocketServer {
|
|
41
30
|
// create socket, install socket handler, bind socket event
|
|
42
31
|
prepare(app) {
|
|
43
|
-
var
|
|
32
|
+
var _this_options_client;
|
|
44
33
|
this.app = app;
|
|
45
|
-
this.wsServer = new
|
|
34
|
+
this.wsServer = new _ws.default.Server({
|
|
46
35
|
noServer: true,
|
|
47
|
-
path: (
|
|
36
|
+
path: (_this_options_client = this.options.client) === null || _this_options_client === void 0 ? void 0 : _this_options_client.path
|
|
48
37
|
});
|
|
49
38
|
this.app.on("upgrade", (req, sock, head) => {
|
|
50
39
|
if (!this.wsServer.shouldHandle(req)) {
|
|
@@ -55,7 +44,7 @@ class SocketServer {
|
|
|
55
44
|
});
|
|
56
45
|
});
|
|
57
46
|
this.wsServer.on("error", (err) => {
|
|
58
|
-
|
|
47
|
+
_utils.logger.error(err);
|
|
59
48
|
});
|
|
60
49
|
this.timer = setInterval(() => {
|
|
61
50
|
this.wsServer.clients.forEach((socket) => {
|
|
@@ -80,11 +69,17 @@ class SocketServer {
|
|
|
80
69
|
// write message to each socket
|
|
81
70
|
sockWrite(type, data) {
|
|
82
71
|
this.sockets.forEach((socket) => {
|
|
83
|
-
this.send(socket, JSON.stringify({
|
|
72
|
+
this.send(socket, JSON.stringify({
|
|
73
|
+
type,
|
|
74
|
+
data
|
|
75
|
+
}));
|
|
84
76
|
});
|
|
85
77
|
}
|
|
86
78
|
singleWrite(socket, type, data) {
|
|
87
|
-
this.send(socket, JSON.stringify({
|
|
79
|
+
this.send(socket, JSON.stringify({
|
|
80
|
+
type,
|
|
81
|
+
data
|
|
82
|
+
}));
|
|
88
83
|
}
|
|
89
84
|
close() {
|
|
90
85
|
this.sockets.forEach((socket) => {
|
|
@@ -163,6 +158,13 @@ class SocketServer {
|
|
|
163
158
|
}
|
|
164
159
|
connection.send(message);
|
|
165
160
|
}
|
|
161
|
+
constructor(options) {
|
|
162
|
+
_define_property(this, "wsServer", void 0);
|
|
163
|
+
_define_property(this, "sockets", []);
|
|
164
|
+
_define_property(this, "options", void 0);
|
|
165
|
+
_define_property(this, "app", void 0);
|
|
166
|
+
_define_property(this, "stats", void 0);
|
|
167
|
+
_define_property(this, "timer", null);
|
|
168
|
+
this.options = options;
|
|
169
|
+
}
|
|
166
170
|
}
|
|
167
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
168
|
-
0 && (module.exports = {});
|
|
@@ -1,52 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 https_exports = {};
|
|
19
|
-
__export(https_exports, {
|
|
20
|
-
genHttpsOptions: () => genHttpsOptions
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
21
4
|
});
|
|
22
|
-
|
|
23
|
-
|
|
5
|
+
Object.defineProperty(exports, "genHttpsOptions", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => genHttpsOptions
|
|
8
|
+
});
|
|
9
|
+
const _utils = require("@modern-js/utils");
|
|
24
10
|
const genHttpsOptions = async (userOptions, pwd) => {
|
|
25
11
|
const httpsOptions = typeof userOptions === "boolean" ? {} : userOptions;
|
|
26
12
|
if (!httpsOptions.key || !httpsOptions.cert) {
|
|
27
13
|
let devcertPath;
|
|
28
14
|
try {
|
|
29
|
-
devcertPath = require.resolve("devcert", {
|
|
15
|
+
devcertPath = require.resolve("devcert", {
|
|
16
|
+
paths: [
|
|
17
|
+
pwd,
|
|
18
|
+
__dirname
|
|
19
|
+
]
|
|
20
|
+
});
|
|
30
21
|
} catch (err) {
|
|
31
|
-
const packageManager = await (0,
|
|
32
|
-
const command =
|
|
33
|
-
|
|
34
|
-
);
|
|
35
|
-
import_utils.logger.error(
|
|
36
|
-
`You have enabled "dev.https" option, but the "devcert" package is not installed.`
|
|
37
|
-
);
|
|
38
|
-
import_utils.logger.error(
|
|
39
|
-
`Please run ${command} to install manually, otherwise the https can not work.`
|
|
40
|
-
);
|
|
22
|
+
const packageManager = await (0, _utils.getPackageManager)(pwd);
|
|
23
|
+
const command = _utils.chalk.yellow.bold(`${packageManager} install devcert@1.2.2 -D`);
|
|
24
|
+
_utils.logger.error(`You have enabled "dev.https" option, but the "devcert" package is not installed.`);
|
|
25
|
+
_utils.logger.error(`Please run ${command} to install manually, otherwise the https can not work.`);
|
|
41
26
|
throw new Error('[https] "devcert" is not found.');
|
|
42
27
|
}
|
|
43
28
|
const devcert = require(devcertPath);
|
|
44
|
-
const selfsign = await devcert.certificateFor([
|
|
29
|
+
const selfsign = await devcert.certificateFor([
|
|
30
|
+
"localhost"
|
|
31
|
+
]);
|
|
45
32
|
return selfsign;
|
|
46
33
|
}
|
|
47
34
|
return httpsOptions;
|
|
48
35
|
};
|
|
49
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
-
0 && (module.exports = {
|
|
51
|
-
genHttpsOptions
|
|
52
|
-
});
|
|
@@ -1,29 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
6
|
for (var name in all)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var getMockData_exports = {};
|
|
19
|
-
__export(getMockData_exports, {
|
|
20
|
-
default: () => getMockData_default,
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
13
|
+
default: () => _default,
|
|
21
14
|
getMatched: () => getMatched
|
|
22
15
|
});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
16
|
+
const _pathtoregexp = require("path-to-regexp");
|
|
17
|
+
const VALID_METHODS = [
|
|
18
|
+
"get",
|
|
19
|
+
"post",
|
|
20
|
+
"put",
|
|
21
|
+
"delete",
|
|
22
|
+
"patch"
|
|
23
|
+
];
|
|
24
|
+
const BODY_PARSED_METHODS = [
|
|
25
|
+
"post",
|
|
26
|
+
"put",
|
|
27
|
+
"delete",
|
|
28
|
+
"patch"
|
|
29
|
+
];
|
|
27
30
|
const createFunctionDataHandler = (method, handler) => async (context, next) => {
|
|
28
31
|
const { req, res } = context;
|
|
29
32
|
return handler(req, res, next);
|
|
@@ -33,14 +36,15 @@ const createStaticDataHandler = (method, handler) => (context) => {
|
|
|
33
36
|
res.setHeader("Content-Type", "application/json");
|
|
34
37
|
res.end(JSON.stringify(handler));
|
|
35
38
|
};
|
|
36
|
-
const allowTypes = [
|
|
37
|
-
|
|
39
|
+
const allowTypes = [
|
|
40
|
+
"object",
|
|
41
|
+
"function"
|
|
42
|
+
];
|
|
43
|
+
const _default = (mockConfig) => Object.keys(mockConfig).reduce((acc, key) => {
|
|
38
44
|
const handler = mockConfig[key];
|
|
39
45
|
const type = typeof handler;
|
|
40
46
|
if (!allowTypes.includes(type)) {
|
|
41
|
-
throw new Error(
|
|
42
|
-
`mock value of ${key} should be object or function, but got ${type}`
|
|
43
|
-
);
|
|
47
|
+
throw new Error(`mock value of ${key} should be object or function, but got ${type}`);
|
|
44
48
|
}
|
|
45
49
|
const meta = parseKey(key);
|
|
46
50
|
if (type === "object") {
|
|
@@ -76,7 +80,7 @@ const getMatched = (context, mockApiList) => {
|
|
|
76
80
|
const matched = mockApiList.find((mockApi) => {
|
|
77
81
|
const { method, path: pathname } = mockApi;
|
|
78
82
|
if (method.toLowerCase() === targetMethod.toLowerCase()) {
|
|
79
|
-
return (0,
|
|
83
|
+
return (0, _pathtoregexp.match)(pathname, {
|
|
80
84
|
encode: encodeURI,
|
|
81
85
|
decode: decodeURIComponent
|
|
82
86
|
})(targetPathname);
|
|
@@ -85,7 +89,3 @@ const getMatched = (context, mockApiList) => {
|
|
|
85
89
|
});
|
|
86
90
|
return matched;
|
|
87
91
|
};
|
|
88
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
89
|
-
0 && (module.exports = {
|
|
90
|
-
getMatched
|
|
91
|
-
});
|