@modern-js/server 2.6.1-alpha.0 → 2.8.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 +45 -0
- package/README.md +2 -2
- package/dist/cjs/server/devServer.js +1 -1
- package/dist/esm/server/devServer.js +1 -1
- package/dist/esm-node/server/devServer.js +1 -1
- package/package.json +12 -12
- 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 -146
- 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 -105
- package/dist/js/modern/dev-tools/mock/index.js +0 -70
- package/dist/js/modern/dev-tools/register/index.js +0 -112
- 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 -294
- 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 -155
- 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 -126
- package/dist/js/node/dev-tools/mock/index.js +0 -99
- package/dist/js/node/dev-tools/register/index.js +0 -139
- 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 -311
- 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 -162
- 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 -318
- package/dist/js/treeshaking/dev-tools/mock/index.js +0 -207
- package/dist/js/treeshaking/dev-tools/register/index.js +0 -154
- 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 -800
- package/dist/js/treeshaking/server/index.js +0 -92
- package/dist/js/treeshaking/types.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,50 @@
|
|
|
1
1
|
# @modern-js/server
|
|
2
2
|
|
|
3
|
+
## 2.8.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ea7bb41e30: feat: add custom web server docs
|
|
8
|
+
feat: 添加自定义 Web Server 文档
|
|
9
|
+
- Updated dependencies [1104a9f18b]
|
|
10
|
+
- Updated dependencies [70d82e1408]
|
|
11
|
+
- Updated dependencies [2c1151271d]
|
|
12
|
+
- Updated dependencies [1f6ca2c7fb]
|
|
13
|
+
- @modern-js/prod-server@2.8.0
|
|
14
|
+
- @modern-js/utils@2.8.0
|
|
15
|
+
- @modern-js/types@2.8.0
|
|
16
|
+
- @modern-js/server-utils@2.8.0
|
|
17
|
+
|
|
18
|
+
## 2.7.0
|
|
19
|
+
|
|
20
|
+
### Minor Changes
|
|
21
|
+
|
|
22
|
+
- 84bfb439b8: feat: support custom apiDir, lambdaDir and style of writing for bff
|
|
23
|
+
feat: 支持定制 api 目录,lambda 目录,bff 的写法
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- 6378e26bf9: fix: modern server not serve static file in developmenet env, dev-server-middleware serve it
|
|
28
|
+
fix: modern server 在开发环境不再托管静态文件,dev-server-middleware 托管他们
|
|
29
|
+
- 7fff9020e1: chore: make file naming consistent
|
|
30
|
+
|
|
31
|
+
chore: 统一文件命名为小驼峰格式
|
|
32
|
+
|
|
33
|
+
- 1eea234fdd: chore: make test files naming consistent
|
|
34
|
+
|
|
35
|
+
chore: 统一测试文件命名为小驼峰格式
|
|
36
|
+
|
|
37
|
+
- Updated dependencies [0f15fc597c]
|
|
38
|
+
- Updated dependencies [dcad887024]
|
|
39
|
+
- Updated dependencies [a4672f7c16]
|
|
40
|
+
- Updated dependencies [7fff9020e1]
|
|
41
|
+
- Updated dependencies [1eea234fdd]
|
|
42
|
+
- Updated dependencies [84bfb439b8]
|
|
43
|
+
- @modern-js/utils@2.7.0
|
|
44
|
+
- @modern-js/types@2.7.0
|
|
45
|
+
- @modern-js/prod-server@2.7.0
|
|
46
|
+
- @modern-js/server-utils@2.7.0
|
|
47
|
+
|
|
3
48
|
## 2.6.0
|
|
4
49
|
|
|
5
50
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -19,8 +19,8 @@ Please follow [Quick Start](https://modernjs.dev/en/guides/get-started/quick-sta
|
|
|
19
19
|
|
|
20
20
|
## Contributing
|
|
21
21
|
|
|
22
|
-
Please read the [Contributing Guide](https://github.com/
|
|
22
|
+
Please read the [Contributing Guide](https://github.com/web-infra-dev/modern.js/blob/main/CONTRIBUTING.md).
|
|
23
23
|
|
|
24
24
|
## License
|
|
25
25
|
|
|
26
|
-
Modern.js is [MIT licensed](https://github.com/
|
|
26
|
+
Modern.js is [MIT licensed](https://github.com/web-infra-dev/modern.js/blob/main/LICENSE).
|
|
@@ -142,7 +142,7 @@ class ModernDevServer extends import_prod_server.ModernServer {
|
|
|
142
142
|
}
|
|
143
143
|
devMiddleware.init(app);
|
|
144
144
|
devMiddleware.on("change", (stats) => {
|
|
145
|
-
if (stats.toJson({ all: false }).name
|
|
145
|
+
if (stats.toJson({ all: false }).name !== "server") {
|
|
146
146
|
this.onRepack({ routes: this.getRoutes() });
|
|
147
147
|
}
|
|
148
148
|
});
|
|
@@ -562,7 +562,7 @@ var ModernDevServer = /*#__PURE__*/ function(ModernServer) {
|
|
|
562
562
|
devMiddleware.on("change", function(stats) {
|
|
563
563
|
if (stats.toJson({
|
|
564
564
|
all: false
|
|
565
|
-
}).name
|
|
565
|
+
}).name !== "server") {
|
|
566
566
|
_this.onRepack({
|
|
567
567
|
routes: _this.getRoutes()
|
|
568
568
|
});
|
|
@@ -119,7 +119,7 @@ class ModernDevServer extends ModernServer {
|
|
|
119
119
|
}
|
|
120
120
|
devMiddleware.init(app);
|
|
121
121
|
devMiddleware.on("change", (stats) => {
|
|
122
|
-
if (stats.toJson({ all: false }).name
|
|
122
|
+
if (stats.toJson({ all: false }).name !== "server") {
|
|
123
123
|
this.onRepack({ routes: this.getRoutes() });
|
|
124
124
|
}
|
|
125
125
|
});
|
package/package.json
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
"name": "@modern-js/server",
|
|
3
3
|
"description": "A Progressive React Framework for modern web development.",
|
|
4
4
|
"homepage": "https://modernjs.dev",
|
|
5
|
-
"bugs": "https://github.com/
|
|
6
|
-
"repository": "
|
|
5
|
+
"bugs": "https://github.com/web-infra-dev/modern.js/issues",
|
|
6
|
+
"repository": "web-infra-dev/modern.js",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"keywords": [
|
|
9
9
|
"react",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "2.
|
|
14
|
+
"version": "2.8.0",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/cjs/index.js",
|
|
@@ -29,19 +29,16 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@babel/core": "^7.18.0",
|
|
31
31
|
"@babel/register": "^7.17.7",
|
|
32
|
-
"@modern-js/prod-server": "2.6.0",
|
|
33
|
-
"@modern-js/server-utils": "2.6.0",
|
|
34
|
-
"@modern-js/types": "2.6.0",
|
|
35
|
-
"@modern-js/utils": "2.6.0",
|
|
36
32
|
"connect-history-api-fallback": "^2.0.0",
|
|
37
33
|
"minimatch": "^3.0.4",
|
|
38
34
|
"path-to-regexp": "^6.2.0",
|
|
39
|
-
"ws": "^8.2.0"
|
|
35
|
+
"ws": "^8.2.0",
|
|
36
|
+
"@modern-js/prod-server": "2.8.0",
|
|
37
|
+
"@modern-js/server-utils": "2.8.0",
|
|
38
|
+
"@modern-js/types": "2.8.0",
|
|
39
|
+
"@modern-js/utils": "2.8.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@modern-js/server-core": "2.6.0",
|
|
43
|
-
"@scripts/build": "2.6.0",
|
|
44
|
-
"@scripts/jest-config": "2.6.0",
|
|
45
42
|
"@types/connect-history-api-fallback": "^1.3.5",
|
|
46
43
|
"@types/jest": "^27",
|
|
47
44
|
"@types/minimatch": "^3.0.5",
|
|
@@ -53,7 +50,10 @@
|
|
|
53
50
|
"tsconfig-paths": "4.1.1",
|
|
54
51
|
"typescript": "^4",
|
|
55
52
|
"webpack": "^5.75.0",
|
|
56
|
-
"websocket": "^1"
|
|
53
|
+
"websocket": "^1",
|
|
54
|
+
"@modern-js/server-core": "2.8.0",
|
|
55
|
+
"@scripts/build": "2.8.0",
|
|
56
|
+
"@scripts/jest-config": "2.8.0"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"devcert": "^1.0.0",
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { getIpv4Interfaces, HMR_SOCK_PATH } from "@modern-js/utils";
|
|
2
|
-
const getDefaultDevOptions = () => {
|
|
3
|
-
const network = getIpv4Interfaces().find((item) => !item.internal);
|
|
4
|
-
return {
|
|
5
|
-
client: {
|
|
6
|
-
port: "8080",
|
|
7
|
-
path: HMR_SOCK_PATH,
|
|
8
|
-
host: (network == null ? void 0 : network.address) || "localhost"
|
|
9
|
-
},
|
|
10
|
-
https: false,
|
|
11
|
-
devMiddleware: { writeToDisk: true },
|
|
12
|
-
watch: true,
|
|
13
|
-
hot: true,
|
|
14
|
-
liveReload: true
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
export {
|
|
18
|
-
getDefaultDevOptions
|
|
19
|
-
};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { HMR_SOCK_PATH } from "@modern-js/utils/constants";
|
|
2
|
-
function createSocketUrl(resourceQuery) {
|
|
3
|
-
const searchParams = resourceQuery.substr(1).split("&");
|
|
4
|
-
const options = {};
|
|
5
|
-
for (const pair of searchParams) {
|
|
6
|
-
const ary = pair.split("=");
|
|
7
|
-
options[ary[0]] = decodeURIComponent(ary[1]);
|
|
8
|
-
}
|
|
9
|
-
const currentLocation = self.location;
|
|
10
|
-
return getSocketUrl(options, currentLocation);
|
|
11
|
-
}
|
|
12
|
-
function formatURL({
|
|
13
|
-
port,
|
|
14
|
-
protocol,
|
|
15
|
-
hostname,
|
|
16
|
-
pathname
|
|
17
|
-
}) {
|
|
18
|
-
if (window.URL) {
|
|
19
|
-
const url = new URL("http://localhost");
|
|
20
|
-
url.port = port;
|
|
21
|
-
url.hostname = hostname;
|
|
22
|
-
url.protocol = protocol;
|
|
23
|
-
url.pathname = pathname;
|
|
24
|
-
return url.toString();
|
|
25
|
-
}
|
|
26
|
-
const colon = protocol.indexOf(":") === -1 ? ":" : "";
|
|
27
|
-
return `${protocol}${colon}//${hostname}:${port}${pathname}`;
|
|
28
|
-
}
|
|
29
|
-
function getSocketUrl(urlParts, location) {
|
|
30
|
-
const { host, port, path, protocol } = urlParts;
|
|
31
|
-
return formatURL({
|
|
32
|
-
protocol: protocol || (location.protocol === "https:" ? "wss" : "ws"),
|
|
33
|
-
hostname: host || location.hostname,
|
|
34
|
-
port: port || location.port,
|
|
35
|
-
pathname: path || HMR_SOCK_PATH
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
export {
|
|
39
|
-
createSocketUrl,
|
|
40
|
-
formatURL
|
|
41
|
-
};
|
|
@@ -1,146 +0,0 @@
|
|
|
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
|
-
import stripAnsi from "@modern-js/utils/strip-ansi";
|
|
6
|
-
import { formatWebpackMessages } from "@modern-js/utils/format";
|
|
7
|
-
import { createSocketUrl } from "./createSocketUrl";
|
|
8
|
-
var require_hmr_client = __commonJS({
|
|
9
|
-
"src/dev-tools/dev-middleware/hmr-client/index.ts"(exports, module) {
|
|
10
|
-
const hadRuntimeError = false;
|
|
11
|
-
const socketUrl = createSocketUrl(__resourceQuery);
|
|
12
|
-
const connection = new WebSocket(socketUrl);
|
|
13
|
-
connection.onopen = function() {
|
|
14
|
-
if (typeof console !== "undefined" && typeof console.debug === "function") {
|
|
15
|
-
console.debug("[HMR] connected.");
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
connection.onclose = function() {
|
|
19
|
-
if (typeof console !== "undefined" && typeof console.info === "function") {
|
|
20
|
-
console.debug("[HMR] disconnected. Refresh the page if necessary.");
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
let isFirstCompilation = true;
|
|
24
|
-
let mostRecentCompilationHash = null;
|
|
25
|
-
let hasCompileErrors = false;
|
|
26
|
-
function clearOutdatedErrors() {
|
|
27
|
-
if (typeof console !== "undefined" && typeof console.clear === "function") {
|
|
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
|
-
}
|
|
68
|
-
}
|
|
69
|
-
function handleErrors(errors) {
|
|
70
|
-
clearOutdatedErrors();
|
|
71
|
-
isFirstCompilation = false;
|
|
72
|
-
hasCompileErrors = true;
|
|
73
|
-
const formatted = formatWebpackMessages({
|
|
74
|
-
errors,
|
|
75
|
-
warnings: []
|
|
76
|
-
});
|
|
77
|
-
if (typeof console !== "undefined" && typeof console.error === "function") {
|
|
78
|
-
for (const error of formatted.errors) {
|
|
79
|
-
console.error(stripAnsi(error));
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
function handleAvailableHash(hash) {
|
|
84
|
-
mostRecentCompilationHash = hash;
|
|
85
|
-
}
|
|
86
|
-
connection.onmessage = function(e) {
|
|
87
|
-
const message = JSON.parse(e.data);
|
|
88
|
-
switch (message.type) {
|
|
89
|
-
case "hash":
|
|
90
|
-
handleAvailableHash(message.data);
|
|
91
|
-
break;
|
|
92
|
-
case "still-ok":
|
|
93
|
-
case "ok":
|
|
94
|
-
handleSuccess();
|
|
95
|
-
break;
|
|
96
|
-
case "content-changed":
|
|
97
|
-
window.location.reload();
|
|
98
|
-
break;
|
|
99
|
-
case "warnings":
|
|
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__;
|
|
110
|
-
}
|
|
111
|
-
function canApplyUpdates() {
|
|
112
|
-
return module.hot.status() === "idle";
|
|
113
|
-
}
|
|
114
|
-
function tryApplyUpdates() {
|
|
115
|
-
if (!module.hot) {
|
|
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(true, handleApplyUpdates);
|
|
133
|
-
if (result == null ? void 0 : result.then) {
|
|
134
|
-
result.then(
|
|
135
|
-
(updatedModules) => {
|
|
136
|
-
handleApplyUpdates(null, updatedModules);
|
|
137
|
-
},
|
|
138
|
-
(err) => {
|
|
139
|
-
handleApplyUpdates(err, null);
|
|
140
|
-
}
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
export default require_hmr_client();
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
-
var __spreadValues = (a, b) => {
|
|
7
|
-
for (var prop in b || (b = {}))
|
|
8
|
-
if (__hasOwnProp.call(b, prop))
|
|
9
|
-
__defNormalProp(a, prop, b[prop]);
|
|
10
|
-
if (__getOwnPropSymbols)
|
|
11
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
-
if (__propIsEnum.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
}
|
|
15
|
-
return a;
|
|
16
|
-
};
|
|
17
|
-
var __async = (__this, __arguments, generator) => {
|
|
18
|
-
return new Promise((resolve, reject) => {
|
|
19
|
-
var fulfilled = (value) => {
|
|
20
|
-
try {
|
|
21
|
-
step(generator.next(value));
|
|
22
|
-
} catch (e) {
|
|
23
|
-
reject(e);
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
var rejected = (value) => {
|
|
27
|
-
try {
|
|
28
|
-
step(generator.throw(value));
|
|
29
|
-
} catch (e) {
|
|
30
|
-
reject(e);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
34
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
import { EventEmitter } from "events";
|
|
38
|
-
import SocketServer from "./socket-server";
|
|
39
|
-
const noop = () => {
|
|
40
|
-
};
|
|
41
|
-
function getHMRClientPath(client) {
|
|
42
|
-
const protocol = (client == null ? void 0 : client.protocol) ? `&protocol=${client.protocol}` : "";
|
|
43
|
-
const host = (client == null ? void 0 : client.host) ? `&host=${client.host}` : "";
|
|
44
|
-
const path = (client == null ? void 0 : client.path) ? `&path=${client.path}` : "";
|
|
45
|
-
const port = (client == null ? void 0 : client.port) ? `&port=${client.port}` : "";
|
|
46
|
-
const clientEntry = `${require.resolve("./hmr-client")}?${host}${path}${port}${protocol}`;
|
|
47
|
-
return clientEntry;
|
|
48
|
-
}
|
|
49
|
-
class DevMiddleware extends EventEmitter {
|
|
50
|
-
constructor({ dev, devMiddleware }) {
|
|
51
|
-
super();
|
|
52
|
-
this.devOptions = dev;
|
|
53
|
-
this.socketServer = new SocketServer(dev);
|
|
54
|
-
if (devMiddleware) {
|
|
55
|
-
this.middleware = this.setupDevMiddleware(devMiddleware);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
init(app) {
|
|
59
|
-
app.on("listening", () => {
|
|
60
|
-
this.socketServer.prepare(app);
|
|
61
|
-
});
|
|
62
|
-
app.on("close", () => __async(this, null, function* () {
|
|
63
|
-
var _a;
|
|
64
|
-
(_a = this.middleware) == null ? void 0 : _a.close(noop);
|
|
65
|
-
this.socketServer.close();
|
|
66
|
-
}));
|
|
67
|
-
}
|
|
68
|
-
sockWrite(type, data) {
|
|
69
|
-
this.socketServer.sockWrite(type, data);
|
|
70
|
-
}
|
|
71
|
-
setupDevMiddleware(devMiddleware) {
|
|
72
|
-
const { devOptions } = this;
|
|
73
|
-
const callbacks = {
|
|
74
|
-
onInvalid: () => {
|
|
75
|
-
this.socketServer.sockWrite("invalid");
|
|
76
|
-
},
|
|
77
|
-
onDone: (stats) => {
|
|
78
|
-
this.socketServer.updateStats(stats);
|
|
79
|
-
this.emit("change", stats);
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
const enableHMR = this.devOptions.hot || this.devOptions.liveReload;
|
|
83
|
-
const middleware = devMiddleware(__spreadValues({
|
|
84
|
-
headers: devOptions.headers,
|
|
85
|
-
stats: false,
|
|
86
|
-
callbacks,
|
|
87
|
-
hmrClientPath: enableHMR ? getHMRClientPath(devOptions.client) : void 0
|
|
88
|
-
}, devOptions.devMiddleware));
|
|
89
|
-
return middleware;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
export {
|
|
93
|
-
DevMiddleware as default
|
|
94
|
-
};
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import ws from "ws";
|
|
2
|
-
import { logger } from "@modern-js/utils";
|
|
3
|
-
class SocketServer {
|
|
4
|
-
constructor(options) {
|
|
5
|
-
this.sockets = [];
|
|
6
|
-
this.timer = null;
|
|
7
|
-
this.options = options;
|
|
8
|
-
}
|
|
9
|
-
prepare(app) {
|
|
10
|
-
var _a;
|
|
11
|
-
this.app = app;
|
|
12
|
-
this.wsServer = new ws.Server({
|
|
13
|
-
noServer: true,
|
|
14
|
-
path: (_a = this.options.client) == null ? void 0 : _a.path
|
|
15
|
-
});
|
|
16
|
-
this.app.on("upgrade", (req, sock, head) => {
|
|
17
|
-
if (!this.wsServer.shouldHandle(req)) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
this.wsServer.handleUpgrade(req, sock, head, (connection) => {
|
|
21
|
-
this.wsServer.emit("connection", connection, req);
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
this.wsServer.on("error", (err) => {
|
|
25
|
-
logger.error(err);
|
|
26
|
-
});
|
|
27
|
-
this.timer = setInterval(() => {
|
|
28
|
-
this.wsServer.clients.forEach((socket) => {
|
|
29
|
-
const extWs = socket;
|
|
30
|
-
if (!extWs.isAlive) {
|
|
31
|
-
extWs.terminate();
|
|
32
|
-
} else {
|
|
33
|
-
extWs.isAlive = false;
|
|
34
|
-
extWs.ping(() => {
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}, 3e4);
|
|
39
|
-
this.wsServer.on("connection", (socket) => {
|
|
40
|
-
this.onConnect(socket);
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
updateStats(stats) {
|
|
44
|
-
this.stats = stats;
|
|
45
|
-
this.sendStats();
|
|
46
|
-
}
|
|
47
|
-
sockWrite(type, data) {
|
|
48
|
-
this.sockets.forEach((socket) => {
|
|
49
|
-
this.send(socket, JSON.stringify({ type, data }));
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
singleWrite(socket, type, data) {
|
|
53
|
-
this.send(socket, JSON.stringify({ type, data }));
|
|
54
|
-
}
|
|
55
|
-
close() {
|
|
56
|
-
this.sockets.forEach((socket) => {
|
|
57
|
-
socket.close();
|
|
58
|
-
});
|
|
59
|
-
if (this.timer) {
|
|
60
|
-
clearInterval(this.timer);
|
|
61
|
-
this.timer = null;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
onConnect(socket) {
|
|
65
|
-
const connection = socket;
|
|
66
|
-
connection.isAlive = true;
|
|
67
|
-
connection.on("pong", () => {
|
|
68
|
-
connection.isAlive = true;
|
|
69
|
-
});
|
|
70
|
-
if (!connection) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
this.sockets.push(connection);
|
|
74
|
-
connection.on("close", () => {
|
|
75
|
-
const idx = this.sockets.indexOf(connection);
|
|
76
|
-
if (idx >= 0) {
|
|
77
|
-
this.sockets.splice(idx, 1);
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
if (this.options.hot || this.options.hot === "only") {
|
|
81
|
-
this.singleWrite(connection, "hot");
|
|
82
|
-
}
|
|
83
|
-
if (this.options.liveReload) {
|
|
84
|
-
this.singleWrite(connection, "liveReload");
|
|
85
|
-
}
|
|
86
|
-
if (this.stats) {
|
|
87
|
-
this.sendStats(true);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
getStats() {
|
|
91
|
-
const curStats = this.stats;
|
|
92
|
-
if (!curStats) {
|
|
93
|
-
return null;
|
|
94
|
-
}
|
|
95
|
-
const defaultStats = {
|
|
96
|
-
all: false,
|
|
97
|
-
hash: true,
|
|
98
|
-
assets: true,
|
|
99
|
-
warnings: true,
|
|
100
|
-
errors: true,
|
|
101
|
-
errorDetails: false
|
|
102
|
-
};
|
|
103
|
-
return curStats.toJson(defaultStats);
|
|
104
|
-
}
|
|
105
|
-
sendStats(force = false) {
|
|
106
|
-
const stats = this.getStats();
|
|
107
|
-
if (!stats) {
|
|
108
|
-
return null;
|
|
109
|
-
}
|
|
110
|
-
const shouldEmit = !force && stats && (!stats.errors || stats.errors.length === 0) && stats.assets && stats.assets.every((asset) => !asset.emitted);
|
|
111
|
-
if (shouldEmit) {
|
|
112
|
-
return this.sockWrite("still-ok");
|
|
113
|
-
}
|
|
114
|
-
this.sockWrite("hash", stats.hash);
|
|
115
|
-
if (stats.errors && stats.errors.length > 0) {
|
|
116
|
-
return this.sockWrite("errors", stats.errors);
|
|
117
|
-
} else if (stats.warnings && stats.warnings.length > 0) {
|
|
118
|
-
return this.sockWrite("warnings", stats.warnings);
|
|
119
|
-
} else {
|
|
120
|
-
return this.sockWrite("ok");
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
send(connection, message) {
|
|
124
|
-
if (connection.readyState !== 1) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
connection.send(message);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
export {
|
|
131
|
-
SocketServer as default
|
|
132
|
-
};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
var __async = (__this, __arguments, generator) => {
|
|
2
|
-
return new Promise((resolve, reject) => {
|
|
3
|
-
var fulfilled = (value) => {
|
|
4
|
-
try {
|
|
5
|
-
step(generator.next(value));
|
|
6
|
-
} catch (e) {
|
|
7
|
-
reject(e);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var rejected = (value) => {
|
|
11
|
-
try {
|
|
12
|
-
step(generator.throw(value));
|
|
13
|
-
} catch (e) {
|
|
14
|
-
reject(e);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
import { chalk, getPackageManager, logger } from "@modern-js/utils";
|
|
22
|
-
const genHttpsOptions = (userOptions, pwd) => __async(void 0, null, function* () {
|
|
23
|
-
const httpsOptions = typeof userOptions === "boolean" ? {} : userOptions;
|
|
24
|
-
if (!httpsOptions.key || !httpsOptions.cert) {
|
|
25
|
-
let devcertPath;
|
|
26
|
-
try {
|
|
27
|
-
devcertPath = require.resolve("devcert", { paths: [pwd, __dirname] });
|
|
28
|
-
} catch (err) {
|
|
29
|
-
const packageManager = yield getPackageManager(pwd);
|
|
30
|
-
const command = chalk.yellow.bold(
|
|
31
|
-
`${packageManager} install devcert@1.2.2 -D`
|
|
32
|
-
);
|
|
33
|
-
logger.error(
|
|
34
|
-
`You have enabled "dev.https" option, but the "devcert" package is not installed.`
|
|
35
|
-
);
|
|
36
|
-
logger.error(
|
|
37
|
-
`Please run ${command} to install manually, otherwise the https can not work.`
|
|
38
|
-
);
|
|
39
|
-
throw new Error('[https] "devcert" is not found.');
|
|
40
|
-
}
|
|
41
|
-
const devcert = require(devcertPath);
|
|
42
|
-
const selfsign = yield devcert.certificateFor(["localhost"]);
|
|
43
|
-
return selfsign;
|
|
44
|
-
}
|
|
45
|
-
return httpsOptions;
|
|
46
|
-
});
|
|
47
|
-
export {
|
|
48
|
-
genHttpsOptions
|
|
49
|
-
};
|