@modern-js/server 2.5.1-alpha.2 → 2.6.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 +19 -0
- package/dist/cjs/dev-tools/dev-middleware/hmr-client/index.js +9 -1
- package/dist/cjs/dev-tools/dev-middleware/index.js +6 -2
- package/dist/cjs/dev-tools/dev-middleware/{socket-server.js → socketServer.js} +12 -3
- 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 → dependencyTree.js} +17 -4
- package/dist/cjs/dev-tools/watcher/index.js +9 -4
- package/dist/cjs/dev-tools/watcher/{stats-cache.js → statsCache.js} +7 -3
- package/dist/cjs/server/{dev-server.js → devServer.js} +13 -3
- package/dist/cjs/server/index.js +2 -2
- package/dist/esm/dev-tools/dev-middleware/hmr-client/index.js +1 -1
- package/dist/esm/dev-tools/dev-middleware/index.js +1 -1
- package/dist/esm/dev-tools/dev-middleware/{socket-server.js → socketServer.js} +5 -0
- package/dist/esm/dev-tools/register/index.js +1 -0
- package/dist/esm/dev-tools/watcher/{dependency-tree.js → dependencyTree.js} +8 -2
- package/dist/esm/dev-tools/watcher/index.js +3 -2
- package/dist/esm/server/{dev-server.js → devServer.js} +22 -3
- package/dist/esm/server/index.js +1 -1
- package/dist/esm-node/dev-tools/dev-middleware/hmr-client/index.js +5 -1
- package/dist/esm-node/dev-tools/dev-middleware/index.js +1 -1
- package/dist/esm-node/dev-tools/dev-middleware/{socket-server.js → socketServer.js} +5 -0
- package/dist/esm-node/dev-tools/register/index.js +1 -0
- package/dist/esm-node/dev-tools/watcher/{dependency-tree.js → dependencyTree.js} +10 -1
- package/dist/esm-node/dev-tools/watcher/index.js +3 -2
- package/dist/esm-node/server/{dev-server.js → devServer.js} +6 -0
- package/dist/esm-node/server/index.js +1 -1
- package/dist/types/server/{dev-server.d.ts → devServer.d.ts} +3 -1
- package/package.json +8 -8
- /package/dist/esm/dev-tools/watcher/{stats-cache.js → statsCache.js} +0 -0
- /package/dist/esm-node/dev-tools/watcher/{stats-cache.js → statsCache.js} +0 -0
- /package/dist/types/dev-tools/dev-middleware/{socket-server.d.ts → socketServer.d.ts} +0 -0
- /package/dist/types/dev-tools/watcher/{dependency-tree.d.ts → dependencyTree.d.ts} +0 -0
- /package/dist/types/dev-tools/watcher/{stats-cache.d.ts → statsCache.d.ts} +0 -0
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
|
));
|
|
@@ -27,7 +31,7 @@ __export(dev_middleware_exports, {
|
|
|
27
31
|
});
|
|
28
32
|
module.exports = __toCommonJS(dev_middleware_exports);
|
|
29
33
|
var import_events = require("events");
|
|
30
|
-
var
|
|
34
|
+
var import_socketServer = __toESM(require("./socketServer"));
|
|
31
35
|
const noop = () => {
|
|
32
36
|
};
|
|
33
37
|
function getHMRClientPath(client) {
|
|
@@ -42,7 +46,7 @@ class DevMiddleware extends import_events.EventEmitter {
|
|
|
42
46
|
constructor({ dev, devMiddleware }) {
|
|
43
47
|
super();
|
|
44
48
|
this.devOptions = dev;
|
|
45
|
-
this.socketServer = new
|
|
49
|
+
this.socketServer = new import_socketServer.default(dev);
|
|
46
50
|
if (devMiddleware) {
|
|
47
51
|
this.middleware = this.setupDevMiddleware(devMiddleware);
|
|
48
52
|
}
|
|
@@ -17,15 +17,19 @@ 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
|
));
|
|
23
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
-
var
|
|
25
|
-
__export(
|
|
28
|
+
var socketServer_exports = {};
|
|
29
|
+
__export(socketServer_exports, {
|
|
26
30
|
default: () => SocketServer
|
|
27
31
|
});
|
|
28
|
-
module.exports = __toCommonJS(
|
|
32
|
+
module.exports = __toCommonJS(socketServer_exports);
|
|
29
33
|
var import_ws = __toESM(require("ws"));
|
|
30
34
|
var import_utils = require("@modern-js/utils");
|
|
31
35
|
class SocketServer {
|
|
@@ -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,16 +17,20 @@ 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
|
));
|
|
23
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
-
var
|
|
25
|
-
__export(
|
|
28
|
+
var dependencyTree_exports = {};
|
|
29
|
+
__export(dependencyTree_exports, {
|
|
26
30
|
DependencyTree: () => DependencyTree,
|
|
27
31
|
defaultIgnores: () => defaultIgnores
|
|
28
32
|
});
|
|
29
|
-
module.exports = __toCommonJS(
|
|
33
|
+
module.exports = __toCommonJS(dependencyTree_exports);
|
|
30
34
|
var import_minimatch = __toESM(require("minimatch"));
|
|
31
35
|
const defaultIgnores = [
|
|
32
36
|
"**/bower_components/**",
|
|
@@ -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) => {
|
|
@@ -78,7 +87,11 @@ class DependencyTree {
|
|
|
78
87
|
}
|
|
79
88
|
shouldIgnore(path) {
|
|
80
89
|
return !path || Boolean(
|
|
81
|
-
this.ignore.find(
|
|
90
|
+
this.ignore.find(
|
|
91
|
+
(rule) => import_minimatch.default.match([path], rule, {
|
|
92
|
+
dot: true
|
|
93
|
+
}).length > 0
|
|
94
|
+
)
|
|
82
95
|
);
|
|
83
96
|
}
|
|
84
97
|
}
|
|
@@ -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
|
));
|
|
@@ -31,9 +35,10 @@ __export(watcher_exports, {
|
|
|
31
35
|
module.exports = __toCommonJS(watcher_exports);
|
|
32
36
|
var import_path = __toESM(require("path"));
|
|
33
37
|
var import_utils = require("@modern-js/utils");
|
|
34
|
-
var
|
|
35
|
-
var
|
|
38
|
+
var import_dependencyTree = require("./dependencyTree");
|
|
39
|
+
var import_statsCache = require("./statsCache");
|
|
36
40
|
const defaultWatchOptions = {
|
|
41
|
+
// 初始化的时候不触发 add、addDir 事件
|
|
37
42
|
ignoreInitial: true,
|
|
38
43
|
ignored: /api\/typings\/.*/
|
|
39
44
|
};
|
|
@@ -74,7 +79,7 @@ class Watcher {
|
|
|
74
79
|
listen(files, options, callback) {
|
|
75
80
|
const watched = files.filter(Boolean);
|
|
76
81
|
const filenames = watched.map((filename) => filename.replace(/\\/g, "/"));
|
|
77
|
-
const cache = new
|
|
82
|
+
const cache = new import_statsCache.StatsCache();
|
|
78
83
|
const watcher = import_utils.chokidar.watch(filenames, options);
|
|
79
84
|
watcher.on("ready", () => {
|
|
80
85
|
cache.add(getWatchedFiles(watcher));
|
|
@@ -98,7 +103,7 @@ class Watcher {
|
|
|
98
103
|
this.watcher = watcher;
|
|
99
104
|
}
|
|
100
105
|
createDepTree() {
|
|
101
|
-
this.dependencyTree = new
|
|
106
|
+
this.dependencyTree = new import_dependencyTree.DependencyTree();
|
|
102
107
|
}
|
|
103
108
|
updateDepTree() {
|
|
104
109
|
var _a;
|
|
@@ -17,15 +17,19 @@ 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
|
));
|
|
23
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
-
var
|
|
25
|
-
__export(
|
|
28
|
+
var statsCache_exports = {};
|
|
29
|
+
__export(statsCache_exports, {
|
|
26
30
|
StatsCache: () => StatsCache
|
|
27
31
|
});
|
|
28
|
-
module.exports = __toCommonJS(
|
|
32
|
+
module.exports = __toCommonJS(statsCache_exports);
|
|
29
33
|
var import_fs = __toESM(require("fs"));
|
|
30
34
|
var import_crypto = __toESM(require("crypto"));
|
|
31
35
|
class StatsCache {
|
|
@@ -17,15 +17,19 @@ 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
|
));
|
|
23
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
-
var
|
|
25
|
-
__export(
|
|
28
|
+
var devServer_exports = {};
|
|
29
|
+
__export(devServer_exports, {
|
|
26
30
|
ModernDevServer: () => ModernDevServer
|
|
27
31
|
});
|
|
28
|
-
module.exports = __toCommonJS(
|
|
32
|
+
module.exports = __toCommonJS(devServer_exports);
|
|
29
33
|
var import_http = require("http");
|
|
30
34
|
var import_path = __toESM(require("path"));
|
|
31
35
|
var import_https = require("https");
|
|
@@ -88,6 +92,7 @@ class ModernDevServer extends import_prod_server.ModernServer {
|
|
|
88
92
|
});
|
|
89
93
|
return { befores, afters };
|
|
90
94
|
}
|
|
95
|
+
// Complete the preparation of services
|
|
91
96
|
async onInit(runner, app) {
|
|
92
97
|
this.runner = runner;
|
|
93
98
|
const { dev } = this;
|
|
@@ -207,6 +212,11 @@ class ModernDevServer extends import_prod_server.ModernServer {
|
|
|
207
212
|
createContext(req, res) {
|
|
208
213
|
return super.createContext(req, res, { etag: true });
|
|
209
214
|
}
|
|
215
|
+
setupStaticMiddleware(_) {
|
|
216
|
+
return async (context, next) => {
|
|
217
|
+
return next();
|
|
218
|
+
};
|
|
219
|
+
}
|
|
210
220
|
async setupBeforeDevMiddleware() {
|
|
211
221
|
const { runner, conf, dev } = this;
|
|
212
222
|
const setupMids = dev.before || [];
|
package/dist/cjs/server/index.js
CHANGED
|
@@ -21,9 +21,9 @@ __export(server_exports, {
|
|
|
21
21
|
});
|
|
22
22
|
module.exports = __toCommonJS(server_exports);
|
|
23
23
|
var import_prod_server = require("@modern-js/prod-server");
|
|
24
|
-
var
|
|
24
|
+
var import_devServer = require("./devServer");
|
|
25
25
|
const createDevServer = (options) => {
|
|
26
|
-
return new
|
|
26
|
+
return new import_devServer.ModernDevServer(options);
|
|
27
27
|
};
|
|
28
28
|
class DevServer extends import_prod_server.Server {
|
|
29
29
|
constructor(options) {
|
|
@@ -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);
|
|
@@ -236,7 +236,7 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
236
236
|
}
|
|
237
237
|
};
|
|
238
238
|
import { EventEmitter } from "events";
|
|
239
|
-
import SocketServer from "./
|
|
239
|
+
import SocketServer from "./socketServer";
|
|
240
240
|
var noop = function() {};
|
|
241
241
|
function getHMRClientPath(client) {
|
|
242
242
|
var protocol = (client === null || client === void 0 ? void 0 : client.protocol) ? "&protocol=".concat(client.protocol) : "";
|
|
@@ -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) {
|
|
@@ -81,7 +81,11 @@ var DependencyTree = /*#__PURE__*/ function() {
|
|
|
81
81
|
}
|
|
82
82
|
},
|
|
83
83
|
{
|
|
84
|
-
|
|
84
|
+
/**
|
|
85
|
+
* update dependency tree
|
|
86
|
+
*
|
|
87
|
+
* @param cache
|
|
88
|
+
*/ key: "update",
|
|
85
89
|
value: function update(cache) {
|
|
86
90
|
var _this = this;
|
|
87
91
|
this.tree.clear();
|
|
@@ -140,7 +144,9 @@ var DependencyTree = /*#__PURE__*/ function() {
|
|
|
140
144
|
return !path || Boolean(this.ignore.find(function(rule) {
|
|
141
145
|
return minimatch.match([
|
|
142
146
|
path
|
|
143
|
-
], rule
|
|
147
|
+
], rule, {
|
|
148
|
+
dot: true
|
|
149
|
+
}).length > 0;
|
|
144
150
|
}));
|
|
145
151
|
}
|
|
146
152
|
}
|
|
@@ -72,9 +72,10 @@ function _unsupportedIterableToArray(o, minLen) {
|
|
|
72
72
|
}
|
|
73
73
|
import path from "path";
|
|
74
74
|
import { fs, chokidar } from "@modern-js/utils";
|
|
75
|
-
import { DependencyTree } from "./
|
|
76
|
-
import { StatsCache } from "./
|
|
75
|
+
import { DependencyTree } from "./dependencyTree";
|
|
76
|
+
import { StatsCache } from "./statsCache";
|
|
77
77
|
var defaultWatchOptions = {
|
|
78
|
+
// 初始化的时候不触发 add、addDir 事件
|
|
78
79
|
ignoreInitial: true,
|
|
79
80
|
ignored: /api\/typings\/.*/
|
|
80
81
|
};
|
|
@@ -255,13 +255,13 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
255
255
|
trys: [],
|
|
256
256
|
ops: []
|
|
257
257
|
};
|
|
258
|
-
return
|
|
258
|
+
return(g = {
|
|
259
259
|
next: verb(0),
|
|
260
260
|
"throw": verb(1),
|
|
261
261
|
"return": verb(2)
|
|
262
262
|
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
263
263
|
return this;
|
|
264
|
-
}), g;
|
|
264
|
+
}), g);
|
|
265
265
|
function verb(n) {
|
|
266
266
|
return function(v) {
|
|
267
267
|
return step([
|
|
@@ -434,7 +434,8 @@ var ModernDevServer = /*#__PURE__*/ function(ModernServer) {
|
|
|
434
434
|
},
|
|
435
435
|
{
|
|
436
436
|
key: "onInit",
|
|
437
|
-
value:
|
|
437
|
+
value: // Complete the preparation of services
|
|
438
|
+
function onInit(runner, app) {
|
|
438
439
|
var _this = this;
|
|
439
440
|
var _this1 = this, _superprop_get_onInit = function() {
|
|
440
441
|
return _get(_getPrototypeOf(ModernDevServer.prototype), "onInit", _this);
|
|
@@ -695,6 +696,24 @@ var ModernDevServer = /*#__PURE__*/ function(ModernServer) {
|
|
|
695
696
|
});
|
|
696
697
|
}
|
|
697
698
|
},
|
|
699
|
+
{
|
|
700
|
+
key: "setupStaticMiddleware",
|
|
701
|
+
value: function setupStaticMiddleware(_) {
|
|
702
|
+
return function() {
|
|
703
|
+
var _ref = _asyncToGenerator(function(context, next) {
|
|
704
|
+
return __generator(this, function(_state) {
|
|
705
|
+
return [
|
|
706
|
+
2,
|
|
707
|
+
next()
|
|
708
|
+
];
|
|
709
|
+
});
|
|
710
|
+
});
|
|
711
|
+
return function(context, next) {
|
|
712
|
+
return _ref.apply(this, arguments);
|
|
713
|
+
};
|
|
714
|
+
}();
|
|
715
|
+
}
|
|
716
|
+
},
|
|
698
717
|
{
|
|
699
718
|
key: "setupBeforeDevMiddleware",
|
|
700
719
|
value: function setupBeforeDevMiddleware() {
|
package/dist/esm/server/index.js
CHANGED
|
@@ -70,7 +70,7 @@ function _createSuper(Derived) {
|
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
72
|
import { Server } from "@modern-js/prod-server";
|
|
73
|
-
import { ModernDevServer } from "./
|
|
73
|
+
import { ModernDevServer } from "./devServer";
|
|
74
74
|
var createDevServer = function(options) {
|
|
75
75
|
return new ModernDevServer(options);
|
|
76
76
|
};
|
|
@@ -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}/`]
|
|
@@ -15,6 +15,11 @@ class DependencyTree {
|
|
|
15
15
|
getNode(path) {
|
|
16
16
|
return this.tree.get(path);
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* update dependency tree
|
|
20
|
+
*
|
|
21
|
+
* @param cache
|
|
22
|
+
*/
|
|
18
23
|
update(cache) {
|
|
19
24
|
this.tree.clear();
|
|
20
25
|
Object.keys(cache).forEach((path) => {
|
|
@@ -49,7 +54,11 @@ class DependencyTree {
|
|
|
49
54
|
}
|
|
50
55
|
shouldIgnore(path) {
|
|
51
56
|
return !path || Boolean(
|
|
52
|
-
this.ignore.find(
|
|
57
|
+
this.ignore.find(
|
|
58
|
+
(rule) => minimatch.match([path], rule, {
|
|
59
|
+
dot: true
|
|
60
|
+
}).length > 0
|
|
61
|
+
)
|
|
53
62
|
);
|
|
54
63
|
}
|
|
55
64
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { fs, chokidar } from "@modern-js/utils";
|
|
3
|
-
import { DependencyTree } from "./
|
|
4
|
-
import { StatsCache } from "./
|
|
3
|
+
import { DependencyTree } from "./dependencyTree";
|
|
4
|
+
import { StatsCache } from "./statsCache";
|
|
5
5
|
const defaultWatchOptions = {
|
|
6
|
+
// 初始化的时候不触发 add、addDir 事件
|
|
6
7
|
ignoreInitial: true,
|
|
7
8
|
ignored: /api\/typings\/.*/
|
|
8
9
|
};
|
|
@@ -69,6 +69,7 @@ class ModernDevServer extends ModernServer {
|
|
|
69
69
|
});
|
|
70
70
|
return { befores, afters };
|
|
71
71
|
}
|
|
72
|
+
// Complete the preparation of services
|
|
72
73
|
async onInit(runner, app) {
|
|
73
74
|
this.runner = runner;
|
|
74
75
|
const { dev } = this;
|
|
@@ -188,6 +189,11 @@ class ModernDevServer extends ModernServer {
|
|
|
188
189
|
createContext(req, res) {
|
|
189
190
|
return super.createContext(req, res, { etag: true });
|
|
190
191
|
}
|
|
192
|
+
setupStaticMiddleware(_) {
|
|
193
|
+
return async (context, next) => {
|
|
194
|
+
return next();
|
|
195
|
+
};
|
|
196
|
+
}
|
|
191
197
|
async setupBeforeDevMiddleware() {
|
|
192
198
|
const { runner, conf, dev } = this;
|
|
193
199
|
const setupMids = dev.before || [];
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import { IncomingMessage, Server, ServerResponse } from 'http';
|
|
4
|
-
import { ServerHookRunner, ModernServer, BuildOptions } from '@modern-js/prod-server';
|
|
4
|
+
import { NextFunction, ServerHookRunner, ModernServer, BuildOptions } from '@modern-js/prod-server';
|
|
5
|
+
import type { ModernServerContext } from '@modern-js/types';
|
|
5
6
|
import { WatchEvent } from '../dev-tools/watcher';
|
|
6
7
|
import type { ModernDevServerOptions } from '../types';
|
|
7
8
|
export declare class ModernDevServer extends ModernServer {
|
|
@@ -27,6 +28,7 @@ export declare class ModernDevServer extends ModernServer {
|
|
|
27
28
|
event: WatchEvent;
|
|
28
29
|
}): void;
|
|
29
30
|
protected createContext(req: IncomingMessage, res: ServerResponse): import("@modern-js/prod-server/src/libs/context").ModernServerContext;
|
|
31
|
+
protected setupStaticMiddleware(_: string): (context: ModernServerContext, next: NextFunction) => Promise<void>;
|
|
30
32
|
private setupBeforeDevMiddleware;
|
|
31
33
|
private setupAfterDevMiddleware;
|
|
32
34
|
private cleanSSRCache;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "2.
|
|
14
|
+
"version": "2.6.1-alpha.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,19 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@babel/core": "^7.18.0",
|
|
31
31
|
"@babel/register": "^7.17.7",
|
|
32
|
-
"@modern-js/prod-server": "2.
|
|
33
|
-
"@modern-js/server-utils": "2.
|
|
34
|
-
"@modern-js/types": "2.
|
|
35
|
-
"@modern-js/utils": "2.
|
|
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
36
|
"connect-history-api-fallback": "^2.0.0",
|
|
37
37
|
"minimatch": "^3.0.4",
|
|
38
38
|
"path-to-regexp": "^6.2.0",
|
|
39
39
|
"ws": "^8.2.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@modern-js/server-core": "2.
|
|
43
|
-
"@scripts/build": "2.
|
|
44
|
-
"@scripts/jest-config": "2.
|
|
42
|
+
"@modern-js/server-core": "2.6.0",
|
|
43
|
+
"@scripts/build": "2.6.0",
|
|
44
|
+
"@scripts/jest-config": "2.6.0",
|
|
45
45
|
"@types/connect-history-api-fallback": "^1.3.5",
|
|
46
46
|
"@types/jest": "^27",
|
|
47
47
|
"@types/minimatch": "^3.0.5",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|