@modern-js/server 2.5.1-alpha.1 → 2.6.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 +19 -0
- package/dist/cjs/dev-tools/dev-middleware/hmr-client/index.js +9 -1
- package/dist/cjs/dev-tools/dev-middleware/index.js +4 -0
- package/dist/cjs/dev-tools/dev-middleware/socket-server.js +9 -0
- package/dist/cjs/dev-tools/mock/index.js +4 -0
- package/dist/cjs/dev-tools/register/index.js +5 -0
- package/dist/cjs/dev-tools/watcher/dependency-tree.js +9 -0
- package/dist/cjs/dev-tools/watcher/index.js +5 -0
- package/dist/cjs/dev-tools/watcher/stats-cache.js +4 -0
- package/dist/cjs/server/dev-server.js +5 -0
- package/dist/esm/dev-tools/dev-middleware/hmr-client/index.js +1 -1
- package/dist/esm/dev-tools/dev-middleware/socket-server.js +5 -0
- package/dist/esm/dev-tools/register/index.js +1 -0
- package/dist/esm/dev-tools/watcher/dependency-tree.js +5 -1
- package/dist/esm/dev-tools/watcher/index.js +1 -0
- package/dist/esm/server/dev-server.js +2 -1
- package/dist/esm-node/dev-tools/dev-middleware/hmr-client/index.js +5 -1
- package/dist/esm-node/dev-tools/dev-middleware/socket-server.js +5 -0
- package/dist/esm-node/dev-tools/register/index.js +1 -0
- package/dist/esm-node/dev-tools/watcher/dependency-tree.js +5 -0
- package/dist/esm-node/dev-tools/watcher/index.js +1 -0
- package/dist/esm-node/server/dev-server.js +1 -0
- package/package.json +10 -10
- 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,24 @@
|
|
|
1
1
|
# @modern-js/server
|
|
2
2
|
|
|
3
|
+
## 2.6.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ba6db6e: fix: filter data when http method is get
|
|
8
|
+
fix: 过滤 get 请求的 data
|
|
9
|
+
- ba6db6e: fix: the dependency tree should be able to filter out node_modules files containing dot
|
|
10
|
+
fix: 依赖树应该能够过滤掉包含"."的 node_modules 文件
|
|
11
|
+
- Updated dependencies [36164a2]
|
|
12
|
+
- Updated dependencies [e1f799e]
|
|
13
|
+
- Updated dependencies [7915ab3]
|
|
14
|
+
- Updated dependencies [49fa0b1]
|
|
15
|
+
- Updated dependencies [0fe658a]
|
|
16
|
+
- Updated dependencies [62930b9]
|
|
17
|
+
- @modern-js/prod-server@2.6.0
|
|
18
|
+
- @modern-js/utils@2.6.0
|
|
19
|
+
- @modern-js/types@2.6.0
|
|
20
|
+
- @modern-js/server-utils@2.6.0
|
|
21
|
+
|
|
3
22
|
## 2.5.0
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
|
@@ -13,6 +13,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
13
13
|
return to;
|
|
14
14
|
};
|
|
15
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.
|
|
16
20
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
17
21
|
mod
|
|
18
22
|
));
|
|
@@ -141,7 +145,11 @@ function tryApplyUpdates() {
|
|
|
141
145
|
tryApplyUpdates();
|
|
142
146
|
}
|
|
143
147
|
}
|
|
144
|
-
const result = module.hot.check(
|
|
148
|
+
const result = module.hot.check(
|
|
149
|
+
/* autoApply */
|
|
150
|
+
true,
|
|
151
|
+
handleApplyUpdates
|
|
152
|
+
);
|
|
145
153
|
if (result == null ? void 0 : result.then) {
|
|
146
154
|
result.then(
|
|
147
155
|
(updatedModules) => {
|
|
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
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.
|
|
20
24
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
25
|
mod
|
|
22
26
|
));
|
|
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
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.
|
|
20
24
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
25
|
mod
|
|
22
26
|
));
|
|
@@ -34,6 +38,7 @@ class SocketServer {
|
|
|
34
38
|
this.timer = null;
|
|
35
39
|
this.options = options;
|
|
36
40
|
}
|
|
41
|
+
// create socket, install socket handler, bind socket event
|
|
37
42
|
prepare(app) {
|
|
38
43
|
var _a;
|
|
39
44
|
this.app = app;
|
|
@@ -72,6 +77,7 @@ class SocketServer {
|
|
|
72
77
|
this.stats = stats;
|
|
73
78
|
this.sendStats();
|
|
74
79
|
}
|
|
80
|
+
// write message to each socket
|
|
75
81
|
sockWrite(type, data) {
|
|
76
82
|
this.sockets.forEach((socket) => {
|
|
77
83
|
this.send(socket, JSON.stringify({ type, data }));
|
|
@@ -115,6 +121,7 @@ class SocketServer {
|
|
|
115
121
|
this.sendStats(true);
|
|
116
122
|
}
|
|
117
123
|
}
|
|
124
|
+
// get standard stats
|
|
118
125
|
getStats() {
|
|
119
126
|
const curStats = this.stats;
|
|
120
127
|
if (!curStats) {
|
|
@@ -130,6 +137,7 @@ class SocketServer {
|
|
|
130
137
|
};
|
|
131
138
|
return curStats.toJson(defaultStats);
|
|
132
139
|
}
|
|
140
|
+
// determine what message should send by stats
|
|
133
141
|
sendStats(force = false) {
|
|
134
142
|
const stats = this.getStats();
|
|
135
143
|
if (!stats) {
|
|
@@ -148,6 +156,7 @@ class SocketServer {
|
|
|
148
156
|
return this.sockWrite("ok");
|
|
149
157
|
}
|
|
150
158
|
}
|
|
159
|
+
// send message to connecting socket
|
|
151
160
|
send(connection, message) {
|
|
152
161
|
if (connection.readyState !== 1) {
|
|
153
162
|
return;
|
|
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
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.
|
|
20
24
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
25
|
mod
|
|
22
26
|
));
|
|
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
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.
|
|
20
24
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
25
|
mod
|
|
22
26
|
));
|
|
@@ -79,6 +83,7 @@ const enableRegister = (projectRoot, config) => {
|
|
|
79
83
|
tsNode.register({
|
|
80
84
|
project: tsconfigPath,
|
|
81
85
|
scope: true,
|
|
86
|
+
// for env.d.ts, https://www.npmjs.com/package/ts-node#missing-types
|
|
82
87
|
files: true,
|
|
83
88
|
transpileOnly: true,
|
|
84
89
|
ignore: ["(?:^|/)node_modules/", `(?:^|/)${distPath}/`]
|
|
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
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.
|
|
20
24
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
25
|
mod
|
|
22
26
|
));
|
|
@@ -44,6 +48,11 @@ class DependencyTree {
|
|
|
44
48
|
getNode(path) {
|
|
45
49
|
return this.tree.get(path);
|
|
46
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* update dependency tree
|
|
53
|
+
*
|
|
54
|
+
* @param cache
|
|
55
|
+
*/
|
|
47
56
|
update(cache) {
|
|
48
57
|
this.tree.clear();
|
|
49
58
|
Object.keys(cache).forEach((path) => {
|
|
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
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.
|
|
20
24
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
25
|
mod
|
|
22
26
|
));
|
|
@@ -34,6 +38,7 @@ var import_utils = require("@modern-js/utils");
|
|
|
34
38
|
var import_dependency_tree = require("./dependency-tree");
|
|
35
39
|
var import_stats_cache = require("./stats-cache");
|
|
36
40
|
const defaultWatchOptions = {
|
|
41
|
+
// 初始化的时候不触发 add、addDir 事件
|
|
37
42
|
ignoreInitial: true,
|
|
38
43
|
ignored: /api\/typings\/.*/
|
|
39
44
|
};
|
|
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
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.
|
|
20
24
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
25
|
mod
|
|
22
26
|
));
|
|
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
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.
|
|
20
24
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
25
|
mod
|
|
22
26
|
));
|
|
@@ -87,6 +91,7 @@ class ModernDevServer extends import_prod_server.ModernServer {
|
|
|
87
91
|
});
|
|
88
92
|
return { befores, afters };
|
|
89
93
|
}
|
|
94
|
+
// Complete the preparation of services
|
|
90
95
|
async onInit(runner, app) {
|
|
91
96
|
this.runner = runner;
|
|
92
97
|
const { dev } = this;
|
|
@@ -148,7 +148,7 @@ var require_hmr_client = __commonJS({
|
|
|
148
148
|
tryApplyUpdates();
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
|
-
var result = module.hot.check(true, handleApplyUpdates);
|
|
151
|
+
var result = module.hot.check(/* autoApply */ true, handleApplyUpdates);
|
|
152
152
|
if (result === null || result === void 0 ? void 0 : result.then) {
|
|
153
153
|
result.then(function(updatedModules) {
|
|
154
154
|
handleApplyUpdates(null, updatedModules);
|
|
@@ -46,6 +46,7 @@ var SocketServer = /*#__PURE__*/ function() {
|
|
|
46
46
|
}
|
|
47
47
|
_createClass(SocketServer, [
|
|
48
48
|
{
|
|
49
|
+
// create socket, install socket handler, bind socket event
|
|
49
50
|
key: "prepare",
|
|
50
51
|
value: function prepare(app) {
|
|
51
52
|
var _this = this;
|
|
@@ -90,6 +91,7 @@ var SocketServer = /*#__PURE__*/ function() {
|
|
|
90
91
|
}
|
|
91
92
|
},
|
|
92
93
|
{
|
|
94
|
+
// write message to each socket
|
|
93
95
|
key: "sockWrite",
|
|
94
96
|
value: function sockWrite(type, data) {
|
|
95
97
|
var _this = this;
|
|
@@ -153,6 +155,7 @@ var SocketServer = /*#__PURE__*/ function() {
|
|
|
153
155
|
}
|
|
154
156
|
},
|
|
155
157
|
{
|
|
158
|
+
// get standard stats
|
|
156
159
|
key: "getStats",
|
|
157
160
|
value: function getStats() {
|
|
158
161
|
var curStats = this.stats;
|
|
@@ -171,6 +174,7 @@ var SocketServer = /*#__PURE__*/ function() {
|
|
|
171
174
|
}
|
|
172
175
|
},
|
|
173
176
|
{
|
|
177
|
+
// determine what message should send by stats
|
|
174
178
|
key: "sendStats",
|
|
175
179
|
value: function sendStats() {
|
|
176
180
|
var force = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : false;
|
|
@@ -195,6 +199,7 @@ var SocketServer = /*#__PURE__*/ function() {
|
|
|
195
199
|
}
|
|
196
200
|
},
|
|
197
201
|
{
|
|
202
|
+
// send message to connecting socket
|
|
198
203
|
key: "send",
|
|
199
204
|
value: function send(connection, message) {
|
|
200
205
|
if (connection.readyState !== 1) {
|
|
@@ -75,6 +75,7 @@ import { fs, chokidar } from "@modern-js/utils";
|
|
|
75
75
|
import { DependencyTree } from "./dependency-tree";
|
|
76
76
|
import { StatsCache } from "./stats-cache";
|
|
77
77
|
var defaultWatchOptions = {
|
|
78
|
+
// 初始化的时候不触发 add、addDir 事件
|
|
78
79
|
ignoreInitial: true,
|
|
79
80
|
ignored: /api\/typings\/.*/
|
|
80
81
|
};
|
|
@@ -432,7 +432,8 @@ var ModernDevServer = /*#__PURE__*/ function(ModernServer) {
|
|
|
432
432
|
},
|
|
433
433
|
{
|
|
434
434
|
key: "onInit",
|
|
435
|
-
value:
|
|
435
|
+
value: // Complete the preparation of services
|
|
436
|
+
function onInit(runner, app) {
|
|
436
437
|
var _this = this;
|
|
437
438
|
var _this1 = this, _superprop_get_onInit = function() {
|
|
438
439
|
return _get(_getPrototypeOf(ModernDevServer.prototype), "onInit", _this);
|
|
@@ -129,7 +129,11 @@ var require_hmr_client = __commonJS({
|
|
|
129
129
|
tryApplyUpdates();
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
|
-
const result = module.hot.check(
|
|
132
|
+
const result = module.hot.check(
|
|
133
|
+
/* autoApply */
|
|
134
|
+
true,
|
|
135
|
+
handleApplyUpdates
|
|
136
|
+
);
|
|
133
137
|
if (result == null ? void 0 : result.then) {
|
|
134
138
|
result.then(
|
|
135
139
|
(updatedModules) => {
|
|
@@ -6,6 +6,7 @@ class SocketServer {
|
|
|
6
6
|
this.timer = null;
|
|
7
7
|
this.options = options;
|
|
8
8
|
}
|
|
9
|
+
// create socket, install socket handler, bind socket event
|
|
9
10
|
prepare(app) {
|
|
10
11
|
var _a;
|
|
11
12
|
this.app = app;
|
|
@@ -44,6 +45,7 @@ class SocketServer {
|
|
|
44
45
|
this.stats = stats;
|
|
45
46
|
this.sendStats();
|
|
46
47
|
}
|
|
48
|
+
// write message to each socket
|
|
47
49
|
sockWrite(type, data) {
|
|
48
50
|
this.sockets.forEach((socket) => {
|
|
49
51
|
this.send(socket, JSON.stringify({ type, data }));
|
|
@@ -87,6 +89,7 @@ class SocketServer {
|
|
|
87
89
|
this.sendStats(true);
|
|
88
90
|
}
|
|
89
91
|
}
|
|
92
|
+
// get standard stats
|
|
90
93
|
getStats() {
|
|
91
94
|
const curStats = this.stats;
|
|
92
95
|
if (!curStats) {
|
|
@@ -102,6 +105,7 @@ class SocketServer {
|
|
|
102
105
|
};
|
|
103
106
|
return curStats.toJson(defaultStats);
|
|
104
107
|
}
|
|
108
|
+
// determine what message should send by stats
|
|
105
109
|
sendStats(force = false) {
|
|
106
110
|
const stats = this.getStats();
|
|
107
111
|
if (!stats) {
|
|
@@ -120,6 +124,7 @@ class SocketServer {
|
|
|
120
124
|
return this.sockWrite("ok");
|
|
121
125
|
}
|
|
122
126
|
}
|
|
127
|
+
// send message to connecting socket
|
|
123
128
|
send(connection, message) {
|
|
124
129
|
if (connection.readyState !== 1) {
|
|
125
130
|
return;
|
|
@@ -51,6 +51,7 @@ const enableRegister = (projectRoot, config) => {
|
|
|
51
51
|
tsNode.register({
|
|
52
52
|
project: tsconfigPath,
|
|
53
53
|
scope: true,
|
|
54
|
+
// for env.d.ts, https://www.npmjs.com/package/ts-node#missing-types
|
|
54
55
|
files: true,
|
|
55
56
|
transpileOnly: true,
|
|
56
57
|
ignore: ["(?:^|/)node_modules/", `(?:^|/)${distPath}/`]
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "2.
|
|
14
|
+
"version": "2.6.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.5.0",
|
|
33
|
-
"@modern-js/server-utils": "2.5.0",
|
|
34
|
-
"@modern-js/types": "2.5.0",
|
|
35
|
-
"@modern-js/utils": "2.5.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.6.0",
|
|
37
|
+
"@modern-js/types": "2.6.0",
|
|
38
|
+
"@modern-js/server-utils": "2.6.0",
|
|
39
|
+
"@modern-js/utils": "2.6.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@modern-js/server-core": "2.5.0",
|
|
43
|
-
"@scripts/build": "2.5.0",
|
|
44
|
-
"@scripts/jest-config": "2.5.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.6.0",
|
|
55
|
+
"@scripts/jest-config": "2.6.0",
|
|
56
|
+
"@scripts/build": "2.6.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,143 +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.onclose = function() {
|
|
14
|
-
if (typeof console !== "undefined" && typeof console.info === "function") {
|
|
15
|
-
console.info(
|
|
16
|
-
"The development server has disconnected.\nRefresh the page if necessary."
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
let isFirstCompilation = true;
|
|
21
|
-
let mostRecentCompilationHash = null;
|
|
22
|
-
let hasCompileErrors = false;
|
|
23
|
-
function clearOutdatedErrors() {
|
|
24
|
-
if (typeof console !== "undefined" && typeof console.clear === "function") {
|
|
25
|
-
if (hasCompileErrors) {
|
|
26
|
-
console.clear();
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
function handleSuccess() {
|
|
31
|
-
clearOutdatedErrors();
|
|
32
|
-
const isHotUpdate = !isFirstCompilation;
|
|
33
|
-
isFirstCompilation = false;
|
|
34
|
-
hasCompileErrors = false;
|
|
35
|
-
if (isHotUpdate) {
|
|
36
|
-
tryApplyUpdates();
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
function handleWarnings(warnings) {
|
|
40
|
-
clearOutdatedErrors();
|
|
41
|
-
const isHotUpdate = !isFirstCompilation;
|
|
42
|
-
isFirstCompilation = false;
|
|
43
|
-
hasCompileErrors = false;
|
|
44
|
-
function printWarnings() {
|
|
45
|
-
const formatted = formatWebpackMessages({
|
|
46
|
-
warnings,
|
|
47
|
-
errors: []
|
|
48
|
-
});
|
|
49
|
-
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
50
|
-
for (let i = 0; i < formatted.warnings.length; i++) {
|
|
51
|
-
if (i === 5) {
|
|
52
|
-
console.warn(
|
|
53
|
-
"There were more warnings in other files.\nYou can find a complete log in the terminal."
|
|
54
|
-
);
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
console.warn(stripAnsi(formatted.warnings[i]));
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
printWarnings();
|
|
62
|
-
if (isHotUpdate) {
|
|
63
|
-
tryApplyUpdates();
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
function handleErrors(errors) {
|
|
67
|
-
clearOutdatedErrors();
|
|
68
|
-
isFirstCompilation = false;
|
|
69
|
-
hasCompileErrors = true;
|
|
70
|
-
const formatted = formatWebpackMessages({
|
|
71
|
-
errors,
|
|
72
|
-
warnings: []
|
|
73
|
-
});
|
|
74
|
-
if (typeof console !== "undefined" && typeof console.error === "function") {
|
|
75
|
-
for (const error of formatted.errors) {
|
|
76
|
-
console.error(stripAnsi(error));
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
function handleAvailableHash(hash) {
|
|
81
|
-
mostRecentCompilationHash = hash;
|
|
82
|
-
}
|
|
83
|
-
connection.onmessage = function(e) {
|
|
84
|
-
const message = JSON.parse(e.data);
|
|
85
|
-
switch (message.type) {
|
|
86
|
-
case "hash":
|
|
87
|
-
handleAvailableHash(message.data);
|
|
88
|
-
break;
|
|
89
|
-
case "still-ok":
|
|
90
|
-
case "ok":
|
|
91
|
-
handleSuccess();
|
|
92
|
-
break;
|
|
93
|
-
case "content-changed":
|
|
94
|
-
window.location.reload();
|
|
95
|
-
break;
|
|
96
|
-
case "warnings":
|
|
97
|
-
handleWarnings(message.data);
|
|
98
|
-
break;
|
|
99
|
-
case "errors":
|
|
100
|
-
handleErrors(message.data);
|
|
101
|
-
break;
|
|
102
|
-
default:
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
function isUpdateAvailable() {
|
|
106
|
-
return mostRecentCompilationHash !== __webpack_hash__;
|
|
107
|
-
}
|
|
108
|
-
function canApplyUpdates() {
|
|
109
|
-
return module.hot.status() === "idle";
|
|
110
|
-
}
|
|
111
|
-
function tryApplyUpdates() {
|
|
112
|
-
if (!module.hot) {
|
|
113
|
-
window.location.reload();
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
if (!isUpdateAvailable() || !canApplyUpdates()) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
function handleApplyUpdates(err, updatedModules) {
|
|
120
|
-
const wantsForcedReload = err || !updatedModules || hadRuntimeError;
|
|
121
|
-
if (wantsForcedReload) {
|
|
122
|
-
window.location.reload();
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
if (isUpdateAvailable()) {
|
|
126
|
-
tryApplyUpdates();
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
const result = module.hot.check(true, handleApplyUpdates);
|
|
130
|
-
if (result == null ? void 0 : result.then) {
|
|
131
|
-
result.then(
|
|
132
|
-
(updatedModules) => {
|
|
133
|
-
handleApplyUpdates(null, updatedModules);
|
|
134
|
-
},
|
|
135
|
-
(err) => {
|
|
136
|
-
handleApplyUpdates(err, null);
|
|
137
|
-
}
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
export default require_hmr_client();
|