@modern-js/server 2.4.1-beta.0 → 2.5.1-alpha.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 +23 -4
- package/dist/cjs/constants.js +42 -0
- package/dist/cjs/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +65 -0
- package/dist/cjs/dev-tools/dev-middleware/hmr-client/index.js +155 -0
- package/dist/cjs/dev-tools/dev-middleware/index.js +86 -0
- package/dist/cjs/dev-tools/dev-middleware/socket-server.js +159 -0
- package/dist/cjs/dev-tools/https/index.js +52 -0
- package/dist/cjs/dev-tools/mock/getMockData.js +91 -0
- package/dist/cjs/dev-tools/mock/index.js +79 -0
- package/dist/cjs/dev-tools/register/index.js +125 -0
- package/dist/cjs/dev-tools/watcher/dependency-tree.js +89 -0
- package/dist/cjs/dev-tools/watcher/index.js +126 -0
- package/dist/cjs/dev-tools/watcher/stats-cache.js +87 -0
- package/dist/cjs/index.js +35 -0
- package/dist/cjs/server/dev-server.js +267 -0
- package/dist/cjs/server/index.js +39 -0
- package/dist/cjs/types.js +15 -0
- package/dist/esm/constants.js +21 -0
- package/dist/esm/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +51 -0
- package/dist/esm/dev-tools/dev-middleware/hmr-client/index.js +162 -0
- package/dist/esm/dev-tools/dev-middleware/index.js +322 -0
- package/dist/esm/dev-tools/dev-middleware/socket-server.js +209 -0
- package/dist/esm/dev-tools/https/index.js +193 -0
- package/dist/esm/dev-tools/mock/getMockData.js +318 -0
- package/dist/esm/dev-tools/mock/index.js +207 -0
- package/dist/esm/dev-tools/register/index.js +154 -0
- package/dist/esm/dev-tools/watcher/dependency-tree.js +150 -0
- package/dist/esm/dev-tools/watcher/index.js +200 -0
- package/dist/esm/dev-tools/watcher/stats-cache.js +128 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/server/dev-server.js +800 -0
- package/dist/esm/server/index.js +92 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm-node/constants.js +19 -0
- package/dist/esm-node/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +41 -0
- package/dist/esm-node/dev-tools/dev-middleware/hmr-client/index.js +146 -0
- package/dist/esm-node/dev-tools/dev-middleware/index.js +59 -0
- package/dist/esm-node/dev-tools/dev-middleware/socket-server.js +132 -0
- package/dist/esm-node/dev-tools/https/index.js +29 -0
- package/dist/esm-node/dev-tools/mock/getMockData.js +68 -0
- package/dist/esm-node/dev-tools/mock/index.js +50 -0
- package/dist/esm-node/dev-tools/register/index.js +96 -0
- package/dist/esm-node/dev-tools/watcher/dependency-tree.js +59 -0
- package/dist/esm-node/dev-tools/watcher/index.js +95 -0
- package/dist/esm-node/dev-tools/watcher/stats-cache.js +58 -0
- package/dist/esm-node/index.js +12 -0
- package/dist/esm-node/server/dev-server.js +247 -0
- package/dist/esm-node/server/index.js +16 -0
- package/dist/esm-node/types.js +0 -0
- package/dist/js/modern/dev-tools/dev-middleware/hmr-client/index.js +3 -6
- package/dist/js/node/dev-tools/dev-middleware/hmr-client/index.js +3 -6
- package/dist/js/treeshaking/dev-tools/dev-middleware/hmr-client/index.js +1 -6
- package/dist/js/treeshaking/dev-tools/dev-middleware/index.js +2 -2
- package/dist/js/treeshaking/dev-tools/dev-middleware/socket-server.js +2 -2
- package/dist/js/treeshaking/dev-tools/register/index.js +6 -6
- package/dist/js/treeshaking/dev-tools/watcher/index.js +4 -4
- package/dist/js/treeshaking/dev-tools/watcher/stats-cache.js +3 -3
- package/dist/js/treeshaking/server/dev-server.js +10 -10
- package/dist/types/dev-tools/mock/getMockData.d.ts +1 -1
- package/package.json +15 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,13 +1,32 @@
|
|
|
1
1
|
# @modern-js/server
|
|
2
2
|
|
|
3
|
-
## 2.
|
|
3
|
+
## 2.5.0
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
+
- 89ca6cc: refactor: merge build-config into scripts/build
|
|
8
|
+
|
|
9
|
+
refactor: 把 build-config 合并进 scripts/build
|
|
10
|
+
|
|
11
|
+
- bb4e712: feat: support export config filed in mock file
|
|
12
|
+
feat: 支持从 mock 文件中导出 config
|
|
13
|
+
- 6fca567: feat: support bff handle complete server, include page render
|
|
14
|
+
feat: 支持 bff 处理整个服务,包括页面渲染
|
|
15
|
+
- 30614fa: chore: modify package.json entry fields and build config
|
|
16
|
+
chore: 更改 package.json entry 字段以及构建配置
|
|
17
|
+
- f0b3d8c: fix: ts-node should compile scopeDir only
|
|
18
|
+
fix: ts-node 应该只编译 scopeDir 的文件
|
|
19
|
+
- Updated dependencies [89ca6cc]
|
|
20
|
+
- Updated dependencies [7cb8bb4]
|
|
21
|
+
- Updated dependencies [6fca567]
|
|
22
|
+
- Updated dependencies [30614fa]
|
|
23
|
+
- Updated dependencies [1b0ce87]
|
|
7
24
|
- Updated dependencies [11c053b]
|
|
8
|
-
|
|
9
|
-
- @modern-js/
|
|
10
|
-
- @modern-js/server-utils@2.
|
|
25
|
+
- Updated dependencies [169c58b]
|
|
26
|
+
- @modern-js/prod-server@2.5.0
|
|
27
|
+
- @modern-js/server-utils@2.5.0
|
|
28
|
+
- @modern-js/types@2.5.0
|
|
29
|
+
- @modern-js/utils@2.5.0
|
|
11
30
|
|
|
12
31
|
## 2.4.0
|
|
13
32
|
|
|
@@ -0,0 +1,42 @@
|
|
|
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 constants_exports = {};
|
|
19
|
+
__export(constants_exports, {
|
|
20
|
+
getDefaultDevOptions: () => getDefaultDevOptions
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(constants_exports);
|
|
23
|
+
var import_utils = require("@modern-js/utils");
|
|
24
|
+
const getDefaultDevOptions = () => {
|
|
25
|
+
const network = (0, import_utils.getIpv4Interfaces)().find((item) => !item.internal);
|
|
26
|
+
return {
|
|
27
|
+
client: {
|
|
28
|
+
port: "8080",
|
|
29
|
+
path: import_utils.HMR_SOCK_PATH,
|
|
30
|
+
host: (network == null ? void 0 : network.address) || "localhost"
|
|
31
|
+
},
|
|
32
|
+
https: false,
|
|
33
|
+
devMiddleware: { writeToDisk: true },
|
|
34
|
+
watch: true,
|
|
35
|
+
hot: true,
|
|
36
|
+
liveReload: true
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
getDefaultDevOptions
|
|
42
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
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 createSocketUrl_exports = {};
|
|
19
|
+
__export(createSocketUrl_exports, {
|
|
20
|
+
createSocketUrl: () => createSocketUrl,
|
|
21
|
+
formatURL: () => formatURL
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(createSocketUrl_exports);
|
|
24
|
+
var import_constants = require("@modern-js/utils/constants");
|
|
25
|
+
function createSocketUrl(resourceQuery) {
|
|
26
|
+
const searchParams = resourceQuery.substr(1).split("&");
|
|
27
|
+
const options = {};
|
|
28
|
+
for (const pair of searchParams) {
|
|
29
|
+
const ary = pair.split("=");
|
|
30
|
+
options[ary[0]] = decodeURIComponent(ary[1]);
|
|
31
|
+
}
|
|
32
|
+
const currentLocation = self.location;
|
|
33
|
+
return getSocketUrl(options, currentLocation);
|
|
34
|
+
}
|
|
35
|
+
function formatURL({
|
|
36
|
+
port,
|
|
37
|
+
protocol,
|
|
38
|
+
hostname,
|
|
39
|
+
pathname
|
|
40
|
+
}) {
|
|
41
|
+
if (window.URL) {
|
|
42
|
+
const url = new URL("http://localhost");
|
|
43
|
+
url.port = port;
|
|
44
|
+
url.hostname = hostname;
|
|
45
|
+
url.protocol = protocol;
|
|
46
|
+
url.pathname = pathname;
|
|
47
|
+
return url.toString();
|
|
48
|
+
}
|
|
49
|
+
const colon = protocol.indexOf(":") === -1 ? ":" : "";
|
|
50
|
+
return `${protocol}${colon}//${hostname}:${port}${pathname}`;
|
|
51
|
+
}
|
|
52
|
+
function getSocketUrl(urlParts, location) {
|
|
53
|
+
const { host, port, path, protocol } = urlParts;
|
|
54
|
+
return formatURL({
|
|
55
|
+
protocol: protocol || (location.protocol === "https:" ? "wss" : "ws"),
|
|
56
|
+
hostname: host || location.hostname,
|
|
57
|
+
port: port || location.port,
|
|
58
|
+
pathname: path || import_constants.HMR_SOCK_PATH
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
62
|
+
0 && (module.exports = {
|
|
63
|
+
createSocketUrl,
|
|
64
|
+
formatURL
|
|
65
|
+
});
|
|
@@ -0,0 +1,155 @@
|
|
|
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");
|
|
22
|
+
const hadRuntimeError = false;
|
|
23
|
+
const socketUrl = (0, import_createSocketUrl.createSocketUrl)(__resourceQuery);
|
|
24
|
+
const connection = new WebSocket(socketUrl);
|
|
25
|
+
connection.onopen = function() {
|
|
26
|
+
if (typeof console !== "undefined" && typeof console.debug === "function") {
|
|
27
|
+
console.debug("[HMR] connected.");
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
connection.onclose = function() {
|
|
31
|
+
if (typeof console !== "undefined" && typeof console.info === "function") {
|
|
32
|
+
console.debug("[HMR] disconnected. Refresh the page if necessary.");
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
let isFirstCompilation = true;
|
|
36
|
+
let mostRecentCompilationHash = null;
|
|
37
|
+
let hasCompileErrors = false;
|
|
38
|
+
function clearOutdatedErrors() {
|
|
39
|
+
if (typeof console !== "undefined" && typeof console.clear === "function") {
|
|
40
|
+
if (hasCompileErrors) {
|
|
41
|
+
console.clear();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function handleSuccess() {
|
|
46
|
+
clearOutdatedErrors();
|
|
47
|
+
const isHotUpdate = !isFirstCompilation;
|
|
48
|
+
isFirstCompilation = false;
|
|
49
|
+
hasCompileErrors = false;
|
|
50
|
+
if (isHotUpdate) {
|
|
51
|
+
tryApplyUpdates();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function handleWarnings(warnings) {
|
|
55
|
+
clearOutdatedErrors();
|
|
56
|
+
const isHotUpdate = !isFirstCompilation;
|
|
57
|
+
isFirstCompilation = false;
|
|
58
|
+
hasCompileErrors = false;
|
|
59
|
+
function printWarnings() {
|
|
60
|
+
const formatted = (0, import_format.formatWebpackMessages)({
|
|
61
|
+
warnings,
|
|
62
|
+
errors: []
|
|
63
|
+
});
|
|
64
|
+
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
65
|
+
for (let i = 0; i < formatted.warnings.length; i++) {
|
|
66
|
+
if (i === 5) {
|
|
67
|
+
console.warn(
|
|
68
|
+
"There were more warnings in other files.\nYou can find a complete log in the terminal."
|
|
69
|
+
);
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
console.warn((0, import_strip_ansi.default)(formatted.warnings[i]));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
printWarnings();
|
|
77
|
+
if (isHotUpdate) {
|
|
78
|
+
tryApplyUpdates();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function handleErrors(errors) {
|
|
82
|
+
clearOutdatedErrors();
|
|
83
|
+
isFirstCompilation = false;
|
|
84
|
+
hasCompileErrors = true;
|
|
85
|
+
const formatted = (0, import_format.formatWebpackMessages)({
|
|
86
|
+
errors,
|
|
87
|
+
warnings: []
|
|
88
|
+
});
|
|
89
|
+
if (typeof console !== "undefined" && typeof console.error === "function") {
|
|
90
|
+
for (const error of formatted.errors) {
|
|
91
|
+
console.error((0, import_strip_ansi.default)(error));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function handleAvailableHash(hash) {
|
|
96
|
+
mostRecentCompilationHash = hash;
|
|
97
|
+
}
|
|
98
|
+
connection.onmessage = function(e) {
|
|
99
|
+
const message = JSON.parse(e.data);
|
|
100
|
+
switch (message.type) {
|
|
101
|
+
case "hash":
|
|
102
|
+
handleAvailableHash(message.data);
|
|
103
|
+
break;
|
|
104
|
+
case "still-ok":
|
|
105
|
+
case "ok":
|
|
106
|
+
handleSuccess();
|
|
107
|
+
break;
|
|
108
|
+
case "content-changed":
|
|
109
|
+
window.location.reload();
|
|
110
|
+
break;
|
|
111
|
+
case "warnings":
|
|
112
|
+
handleWarnings(message.data);
|
|
113
|
+
break;
|
|
114
|
+
case "errors":
|
|
115
|
+
handleErrors(message.data);
|
|
116
|
+
break;
|
|
117
|
+
default:
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
function isUpdateAvailable() {
|
|
121
|
+
return mostRecentCompilationHash !== __webpack_hash__;
|
|
122
|
+
}
|
|
123
|
+
function canApplyUpdates() {
|
|
124
|
+
return module.hot.status() === "idle";
|
|
125
|
+
}
|
|
126
|
+
function tryApplyUpdates() {
|
|
127
|
+
if (!module.hot) {
|
|
128
|
+
window.location.reload();
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (!isUpdateAvailable() || !canApplyUpdates()) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
function handleApplyUpdates(err, updatedModules) {
|
|
135
|
+
const wantsForcedReload = err || !updatedModules || hadRuntimeError;
|
|
136
|
+
if (wantsForcedReload) {
|
|
137
|
+
window.location.reload();
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (isUpdateAvailable()) {
|
|
141
|
+
tryApplyUpdates();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const result = module.hot.check(true, handleApplyUpdates);
|
|
145
|
+
if (result == null ? void 0 : result.then) {
|
|
146
|
+
result.then(
|
|
147
|
+
(updatedModules) => {
|
|
148
|
+
handleApplyUpdates(null, updatedModules);
|
|
149
|
+
},
|
|
150
|
+
(err) => {
|
|
151
|
+
handleApplyUpdates(err, null);
|
|
152
|
+
}
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
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 dev_middleware_exports = {};
|
|
25
|
+
__export(dev_middleware_exports, {
|
|
26
|
+
default: () => DevMiddleware
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(dev_middleware_exports);
|
|
29
|
+
var import_events = require("events");
|
|
30
|
+
var import_socket_server = __toESM(require("./socket-server"));
|
|
31
|
+
const noop = () => {
|
|
32
|
+
};
|
|
33
|
+
function getHMRClientPath(client) {
|
|
34
|
+
const protocol = (client == null ? void 0 : client.protocol) ? `&protocol=${client.protocol}` : "";
|
|
35
|
+
const host = (client == null ? void 0 : client.host) ? `&host=${client.host}` : "";
|
|
36
|
+
const path = (client == null ? void 0 : client.path) ? `&path=${client.path}` : "";
|
|
37
|
+
const port = (client == null ? void 0 : client.port) ? `&port=${client.port}` : "";
|
|
38
|
+
const clientEntry = `${require.resolve("./hmr-client")}?${host}${path}${port}${protocol}`;
|
|
39
|
+
return clientEntry;
|
|
40
|
+
}
|
|
41
|
+
class DevMiddleware extends import_events.EventEmitter {
|
|
42
|
+
constructor({ dev, devMiddleware }) {
|
|
43
|
+
super();
|
|
44
|
+
this.devOptions = dev;
|
|
45
|
+
this.socketServer = new import_socket_server.default(dev);
|
|
46
|
+
if (devMiddleware) {
|
|
47
|
+
this.middleware = this.setupDevMiddleware(devMiddleware);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
init(app) {
|
|
51
|
+
app.on("listening", () => {
|
|
52
|
+
this.socketServer.prepare(app);
|
|
53
|
+
});
|
|
54
|
+
app.on("close", async () => {
|
|
55
|
+
var _a;
|
|
56
|
+
(_a = this.middleware) == null ? void 0 : _a.close(noop);
|
|
57
|
+
this.socketServer.close();
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
sockWrite(type, data) {
|
|
61
|
+
this.socketServer.sockWrite(type, data);
|
|
62
|
+
}
|
|
63
|
+
setupDevMiddleware(devMiddleware) {
|
|
64
|
+
const { devOptions } = this;
|
|
65
|
+
const callbacks = {
|
|
66
|
+
onInvalid: () => {
|
|
67
|
+
this.socketServer.sockWrite("invalid");
|
|
68
|
+
},
|
|
69
|
+
onDone: (stats) => {
|
|
70
|
+
this.socketServer.updateStats(stats);
|
|
71
|
+
this.emit("change", stats);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const enableHMR = this.devOptions.hot || this.devOptions.liveReload;
|
|
75
|
+
const middleware = devMiddleware({
|
|
76
|
+
headers: devOptions.headers,
|
|
77
|
+
stats: false,
|
|
78
|
+
callbacks,
|
|
79
|
+
hmrClientPath: enableHMR ? getHMRClientPath(devOptions.client) : void 0,
|
|
80
|
+
...devOptions.devMiddleware
|
|
81
|
+
});
|
|
82
|
+
return middleware;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
86
|
+
0 && (module.exports = {});
|
|
@@ -0,0 +1,159 @@
|
|
|
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 socket_server_exports = {};
|
|
25
|
+
__export(socket_server_exports, {
|
|
26
|
+
default: () => SocketServer
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(socket_server_exports);
|
|
29
|
+
var import_ws = __toESM(require("ws"));
|
|
30
|
+
var import_utils = require("@modern-js/utils");
|
|
31
|
+
class SocketServer {
|
|
32
|
+
constructor(options) {
|
|
33
|
+
this.sockets = [];
|
|
34
|
+
this.timer = null;
|
|
35
|
+
this.options = options;
|
|
36
|
+
}
|
|
37
|
+
prepare(app) {
|
|
38
|
+
var _a;
|
|
39
|
+
this.app = app;
|
|
40
|
+
this.wsServer = new import_ws.default.Server({
|
|
41
|
+
noServer: true,
|
|
42
|
+
path: (_a = this.options.client) == null ? void 0 : _a.path
|
|
43
|
+
});
|
|
44
|
+
this.app.on("upgrade", (req, sock, head) => {
|
|
45
|
+
if (!this.wsServer.shouldHandle(req)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
this.wsServer.handleUpgrade(req, sock, head, (connection) => {
|
|
49
|
+
this.wsServer.emit("connection", connection, req);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
this.wsServer.on("error", (err) => {
|
|
53
|
+
import_utils.logger.error(err);
|
|
54
|
+
});
|
|
55
|
+
this.timer = setInterval(() => {
|
|
56
|
+
this.wsServer.clients.forEach((socket) => {
|
|
57
|
+
const extWs = socket;
|
|
58
|
+
if (!extWs.isAlive) {
|
|
59
|
+
extWs.terminate();
|
|
60
|
+
} else {
|
|
61
|
+
extWs.isAlive = false;
|
|
62
|
+
extWs.ping(() => {
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}, 3e4);
|
|
67
|
+
this.wsServer.on("connection", (socket) => {
|
|
68
|
+
this.onConnect(socket);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
updateStats(stats) {
|
|
72
|
+
this.stats = stats;
|
|
73
|
+
this.sendStats();
|
|
74
|
+
}
|
|
75
|
+
sockWrite(type, data) {
|
|
76
|
+
this.sockets.forEach((socket) => {
|
|
77
|
+
this.send(socket, JSON.stringify({ type, data }));
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
singleWrite(socket, type, data) {
|
|
81
|
+
this.send(socket, JSON.stringify({ type, data }));
|
|
82
|
+
}
|
|
83
|
+
close() {
|
|
84
|
+
this.sockets.forEach((socket) => {
|
|
85
|
+
socket.close();
|
|
86
|
+
});
|
|
87
|
+
if (this.timer) {
|
|
88
|
+
clearInterval(this.timer);
|
|
89
|
+
this.timer = null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
onConnect(socket) {
|
|
93
|
+
const connection = socket;
|
|
94
|
+
connection.isAlive = true;
|
|
95
|
+
connection.on("pong", () => {
|
|
96
|
+
connection.isAlive = true;
|
|
97
|
+
});
|
|
98
|
+
if (!connection) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
this.sockets.push(connection);
|
|
102
|
+
connection.on("close", () => {
|
|
103
|
+
const idx = this.sockets.indexOf(connection);
|
|
104
|
+
if (idx >= 0) {
|
|
105
|
+
this.sockets.splice(idx, 1);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
if (this.options.hot || this.options.hot === "only") {
|
|
109
|
+
this.singleWrite(connection, "hot");
|
|
110
|
+
}
|
|
111
|
+
if (this.options.liveReload) {
|
|
112
|
+
this.singleWrite(connection, "liveReload");
|
|
113
|
+
}
|
|
114
|
+
if (this.stats) {
|
|
115
|
+
this.sendStats(true);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
getStats() {
|
|
119
|
+
const curStats = this.stats;
|
|
120
|
+
if (!curStats) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
const defaultStats = {
|
|
124
|
+
all: false,
|
|
125
|
+
hash: true,
|
|
126
|
+
assets: true,
|
|
127
|
+
warnings: true,
|
|
128
|
+
errors: true,
|
|
129
|
+
errorDetails: false
|
|
130
|
+
};
|
|
131
|
+
return curStats.toJson(defaultStats);
|
|
132
|
+
}
|
|
133
|
+
sendStats(force = false) {
|
|
134
|
+
const stats = this.getStats();
|
|
135
|
+
if (!stats) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
const shouldEmit = !force && stats && (!stats.errors || stats.errors.length === 0) && stats.assets && stats.assets.every((asset) => !asset.emitted);
|
|
139
|
+
if (shouldEmit) {
|
|
140
|
+
return this.sockWrite("still-ok");
|
|
141
|
+
}
|
|
142
|
+
this.sockWrite("hash", stats.hash);
|
|
143
|
+
if (stats.errors && stats.errors.length > 0) {
|
|
144
|
+
return this.sockWrite("errors", stats.errors);
|
|
145
|
+
} else if (stats.warnings && stats.warnings.length > 0) {
|
|
146
|
+
return this.sockWrite("warnings", stats.warnings);
|
|
147
|
+
} else {
|
|
148
|
+
return this.sockWrite("ok");
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
send(connection, message) {
|
|
152
|
+
if (connection.readyState !== 1) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
connection.send(message);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
159
|
+
0 && (module.exports = {});
|
|
@@ -0,0 +1,52 @@
|
|
|
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 https_exports = {};
|
|
19
|
+
__export(https_exports, {
|
|
20
|
+
genHttpsOptions: () => genHttpsOptions
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(https_exports);
|
|
23
|
+
var import_utils = require("@modern-js/utils");
|
|
24
|
+
const genHttpsOptions = async (userOptions, pwd) => {
|
|
25
|
+
const httpsOptions = typeof userOptions === "boolean" ? {} : userOptions;
|
|
26
|
+
if (!httpsOptions.key || !httpsOptions.cert) {
|
|
27
|
+
let devcertPath;
|
|
28
|
+
try {
|
|
29
|
+
devcertPath = require.resolve("devcert", { paths: [pwd, __dirname] });
|
|
30
|
+
} catch (err) {
|
|
31
|
+
const packageManager = await (0, import_utils.getPackageManager)(pwd);
|
|
32
|
+
const command = import_utils.chalk.yellow.bold(
|
|
33
|
+
`${packageManager} install devcert@1.2.2 -D`
|
|
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
|
+
);
|
|
41
|
+
throw new Error('[https] "devcert" is not found.');
|
|
42
|
+
}
|
|
43
|
+
const devcert = require(devcertPath);
|
|
44
|
+
const selfsign = await devcert.certificateFor(["localhost"]);
|
|
45
|
+
return selfsign;
|
|
46
|
+
}
|
|
47
|
+
return httpsOptions;
|
|
48
|
+
};
|
|
49
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
+
0 && (module.exports = {
|
|
51
|
+
genHttpsOptions
|
|
52
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
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 getMockData_exports = {};
|
|
19
|
+
__export(getMockData_exports, {
|
|
20
|
+
default: () => getMockData_default,
|
|
21
|
+
getMatched: () => getMatched
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(getMockData_exports);
|
|
24
|
+
var import_path_to_regexp = require("path-to-regexp");
|
|
25
|
+
const VALID_METHODS = ["get", "post", "put", "delete", "patch"];
|
|
26
|
+
const BODY_PARSED_METHODS = ["post", "put", "delete", "patch"];
|
|
27
|
+
const createFunctionDataHandler = (method, handler) => async (context, next) => {
|
|
28
|
+
const { req, res } = context;
|
|
29
|
+
return handler(req, res, next);
|
|
30
|
+
};
|
|
31
|
+
const createStaticDataHandler = (method, handler) => (context) => {
|
|
32
|
+
const { res } = context;
|
|
33
|
+
res.setHeader("Content-Type", "application/json");
|
|
34
|
+
res.end(JSON.stringify(handler));
|
|
35
|
+
};
|
|
36
|
+
const allowTypes = ["object", "function"];
|
|
37
|
+
var getMockData_default = (mockConfig) => Object.keys(mockConfig).reduce((acc, key) => {
|
|
38
|
+
const handler = mockConfig[key];
|
|
39
|
+
const type = typeof handler;
|
|
40
|
+
if (!allowTypes.includes(type)) {
|
|
41
|
+
throw new Error(
|
|
42
|
+
`mock value of ${key} should be object or function, but got ${type}`
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
const meta = parseKey(key);
|
|
46
|
+
if (type === "object") {
|
|
47
|
+
acc.push({
|
|
48
|
+
...meta,
|
|
49
|
+
handler: createStaticDataHandler(meta.method, handler)
|
|
50
|
+
});
|
|
51
|
+
} else {
|
|
52
|
+
acc.push({
|
|
53
|
+
...meta,
|
|
54
|
+
handler: createFunctionDataHandler(meta.method, handler)
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return acc;
|
|
58
|
+
}, []);
|
|
59
|
+
const _blank = " ";
|
|
60
|
+
const parseKey = (key) => {
|
|
61
|
+
const splitted = key.split(_blank).filter(Boolean);
|
|
62
|
+
if (splitted.length > 1) {
|
|
63
|
+
const [method, pathname] = splitted;
|
|
64
|
+
return {
|
|
65
|
+
method: method.toLowerCase(),
|
|
66
|
+
path: pathname
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
method: "get",
|
|
71
|
+
path: key
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
const getMatched = (context, mockApiList) => {
|
|
75
|
+
const { path: targetPathname, method: targetMethod } = context;
|
|
76
|
+
const matched = mockApiList.find((mockApi) => {
|
|
77
|
+
const { method, path: pathname } = mockApi;
|
|
78
|
+
if (method.toLowerCase() === targetMethod.toLowerCase()) {
|
|
79
|
+
return (0, import_path_to_regexp.match)(pathname, {
|
|
80
|
+
encode: encodeURI,
|
|
81
|
+
decode: decodeURIComponent
|
|
82
|
+
})(targetPathname);
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
85
|
+
});
|
|
86
|
+
return matched;
|
|
87
|
+
};
|
|
88
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
89
|
+
0 && (module.exports = {
|
|
90
|
+
getMatched
|
|
91
|
+
});
|