@modern-js/server 2.20.0 → 2.21.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 +33 -0
- package/dist/cjs/constants.js +1 -0
- package/dist/cjs/dev-tools/dev-middleware/hmr-client/index.js +3 -3
- package/dist/cjs/server/devServer.js +9 -0
- package/dist/esm/constants.js +1 -0
- package/dist/esm/dev-tools/dev-middleware/hmr-client/index.js +3 -3
- package/dist/esm/server/devServer.js +25 -6
- package/dist/esm-node/constants.js +1 -0
- package/dist/esm-node/dev-tools/dev-middleware/hmr-client/index.js +3 -3
- package/dist/esm-node/server/devServer.js +9 -0
- package/dist/types/dev-tools/mock/getMockData.d.ts +0 -2
- package/dist/types/dev-tools/watcher/dependencyTree.d.ts +0 -2
- package/dist/types/index.d.ts +0 -2
- package/dist/types/types.d.ts +0 -3
- package/package.json +14 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# @modern-js/server
|
|
2
2
|
|
|
3
|
+
## 2.21.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 26dcf3a: chore: bump typescript to v5 in devDependencies
|
|
8
|
+
|
|
9
|
+
chore: 升级 devDependencies 中的 typescript 版本到 v5
|
|
10
|
+
|
|
11
|
+
- 1ef03dc: feat(dev-server): enable gzip compression, add devServer.compress config
|
|
12
|
+
|
|
13
|
+
feat(dev-server): 默认启用 gzip 压缩,新增 devServer.compress 配置项
|
|
14
|
+
|
|
15
|
+
- 8fa8566: fix(dev-server): adjust hmr connection log level
|
|
16
|
+
|
|
17
|
+
fix(dev-server): 调整 hmr 连接的日志级别
|
|
18
|
+
|
|
19
|
+
- ad78387: chore(deps): bump babel-related dependencies to latest version
|
|
20
|
+
|
|
21
|
+
chore(deps): 升级 babel 相关依赖到最新版本
|
|
22
|
+
|
|
23
|
+
- Updated dependencies [cfc5bda]
|
|
24
|
+
- Updated dependencies [e81eeaf]
|
|
25
|
+
- Updated dependencies [26dcf3a]
|
|
26
|
+
- Updated dependencies [1ef03dc]
|
|
27
|
+
- Updated dependencies [056627f]
|
|
28
|
+
- Updated dependencies [0fc15ca]
|
|
29
|
+
- Updated dependencies [43b4e83]
|
|
30
|
+
- Updated dependencies [ad78387]
|
|
31
|
+
- @modern-js/prod-server@2.21.0
|
|
32
|
+
- @modern-js/utils@2.21.0
|
|
33
|
+
- @modern-js/server-utils@2.21.0
|
|
34
|
+
- @modern-js/types@2.21.0
|
|
35
|
+
|
|
3
36
|
## 2.20.0
|
|
4
37
|
|
|
5
38
|
### Patch Changes
|
package/dist/cjs/constants.js
CHANGED
|
@@ -10,13 +10,13 @@ const hadRuntimeError = false;
|
|
|
10
10
|
const socketUrl = (0, _createSocketUrl.createSocketUrl)(__resourceQuery);
|
|
11
11
|
const connection = new WebSocket(socketUrl);
|
|
12
12
|
connection.onopen = function() {
|
|
13
|
-
if (typeof console !== "undefined" && typeof console.
|
|
14
|
-
console.
|
|
13
|
+
if (typeof console !== "undefined" && typeof console.info === "function") {
|
|
14
|
+
console.info("[HMR] connected.");
|
|
15
15
|
}
|
|
16
16
|
};
|
|
17
17
|
connection.onclose = function() {
|
|
18
18
|
if (typeof console !== "undefined" && typeof console.info === "function") {
|
|
19
|
-
console.
|
|
19
|
+
console.info("[HMR] disconnected. Refresh the page if necessary.");
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
22
|
let isFirstCompilation = true;
|
|
@@ -79,6 +79,15 @@ class ModernDevServer extends _prodserver.ModernServer {
|
|
|
79
79
|
}
|
|
80
80
|
async applyDefaultMiddlewares(app) {
|
|
81
81
|
const { pwd, dev, devMiddleware } = this;
|
|
82
|
+
if (dev.compress) {
|
|
83
|
+
const { default: compression } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("http-compression")));
|
|
84
|
+
this.addHandler((ctx, next) => {
|
|
85
|
+
compression({
|
|
86
|
+
gzip: true,
|
|
87
|
+
brotli: false
|
|
88
|
+
})(ctx.req, ctx.res, next);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
82
91
|
this.addHandler((ctx, next) => {
|
|
83
92
|
ctx.res.setHeader("Access-Control-Allow-Origin", "*");
|
|
84
93
|
if (ctx.path.includes("hot-update")) {
|
package/dist/esm/constants.js
CHANGED
|
@@ -5,13 +5,13 @@ var hadRuntimeError = false;
|
|
|
5
5
|
var socketUrl = createSocketUrl(__resourceQuery);
|
|
6
6
|
var connection = new WebSocket(socketUrl);
|
|
7
7
|
connection.onopen = function() {
|
|
8
|
-
if (typeof console !== "undefined" && typeof console.
|
|
9
|
-
console.
|
|
8
|
+
if (typeof console !== "undefined" && typeof console.info === "function") {
|
|
9
|
+
console.info("[HMR] connected.");
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
12
|
connection.onclose = function() {
|
|
13
13
|
if (typeof console !== "undefined" && typeof console.info === "function") {
|
|
14
|
-
console.
|
|
14
|
+
console.info("[HMR] disconnected. Refresh the page if necessary.");
|
|
15
15
|
}
|
|
16
16
|
};
|
|
17
17
|
var isFirstCompilation = true;
|
|
@@ -177,11 +177,30 @@ export var ModernDevServer = /* @__PURE__ */ function(ModernServer2) {
|
|
|
177
177
|
value: function applyDefaultMiddlewares(app) {
|
|
178
178
|
var _this = this;
|
|
179
179
|
return _async_to_generator(function() {
|
|
180
|
-
var pwd, dev, devMiddleware, proxyHandlers,
|
|
180
|
+
var pwd, dev, devMiddleware, _ref, compression, proxyHandlers, _ref1, connectHistoryApiFallback, historyApiFallbackMiddleware;
|
|
181
181
|
return _ts_generator(this, function(_state) {
|
|
182
182
|
switch (_state.label) {
|
|
183
183
|
case 0:
|
|
184
184
|
pwd = _this.pwd, dev = _this.dev, devMiddleware = _this.devMiddleware;
|
|
185
|
+
if (!dev.compress)
|
|
186
|
+
return [
|
|
187
|
+
3,
|
|
188
|
+
2
|
|
189
|
+
];
|
|
190
|
+
return [
|
|
191
|
+
4,
|
|
192
|
+
import("http-compression")
|
|
193
|
+
];
|
|
194
|
+
case 1:
|
|
195
|
+
_ref = _state.sent(), compression = _ref.default;
|
|
196
|
+
_this.addHandler(function(ctx, next) {
|
|
197
|
+
compression({
|
|
198
|
+
gzip: true,
|
|
199
|
+
brotli: false
|
|
200
|
+
})(ctx.req, ctx.res, next);
|
|
201
|
+
});
|
|
202
|
+
_state.label = 2;
|
|
203
|
+
case 2:
|
|
185
204
|
_this.addHandler(function(ctx, next) {
|
|
186
205
|
ctx.res.setHeader("Access-Control-Allow-Origin", "*");
|
|
187
206
|
if (ctx.path.includes("hot-update")) {
|
|
@@ -249,20 +268,20 @@ export var ModernDevServer = /* @__PURE__ */ function(ModernServer2) {
|
|
|
249
268
|
if (!dev.historyApiFallback)
|
|
250
269
|
return [
|
|
251
270
|
3,
|
|
252
|
-
|
|
271
|
+
4
|
|
253
272
|
];
|
|
254
273
|
return [
|
|
255
274
|
4,
|
|
256
275
|
import("connect-history-api-fallback")
|
|
257
276
|
];
|
|
258
|
-
case
|
|
259
|
-
|
|
277
|
+
case 3:
|
|
278
|
+
_ref1 = _state.sent(), connectHistoryApiFallback = _ref1.default;
|
|
260
279
|
historyApiFallbackMiddleware = connectHistoryApiFallback(typeof dev.historyApiFallback === "boolean" ? {} : dev.historyApiFallback);
|
|
261
280
|
_this.addHandler(function(ctx, next) {
|
|
262
281
|
return historyApiFallbackMiddleware(ctx.req, ctx.res, next);
|
|
263
282
|
});
|
|
264
|
-
_state.label =
|
|
265
|
-
case
|
|
283
|
+
_state.label = 4;
|
|
284
|
+
case 4:
|
|
266
285
|
return [
|
|
267
286
|
2
|
|
268
287
|
];
|
|
@@ -5,13 +5,13 @@ const hadRuntimeError = false;
|
|
|
5
5
|
const socketUrl = createSocketUrl(__resourceQuery);
|
|
6
6
|
const connection = new WebSocket(socketUrl);
|
|
7
7
|
connection.onopen = function() {
|
|
8
|
-
if (typeof console !== "undefined" && typeof console.
|
|
9
|
-
console.
|
|
8
|
+
if (typeof console !== "undefined" && typeof console.info === "function") {
|
|
9
|
+
console.info("[HMR] connected.");
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
12
|
connection.onclose = function() {
|
|
13
13
|
if (typeof console !== "undefined" && typeof console.info === "function") {
|
|
14
|
-
console.
|
|
14
|
+
console.info("[HMR] disconnected. Refresh the page if necessary.");
|
|
15
15
|
}
|
|
16
16
|
};
|
|
17
17
|
let isFirstCompilation = true;
|
|
@@ -69,6 +69,15 @@ export class ModernDevServer extends ModernServer {
|
|
|
69
69
|
}
|
|
70
70
|
async applyDefaultMiddlewares(app) {
|
|
71
71
|
const { pwd, dev, devMiddleware } = this;
|
|
72
|
+
if (dev.compress) {
|
|
73
|
+
const { default: compression } = await import("http-compression");
|
|
74
|
+
this.addHandler((ctx, next) => {
|
|
75
|
+
compression({
|
|
76
|
+
gzip: true,
|
|
77
|
+
brotli: false
|
|
78
|
+
})(ctx.req, ctx.res, next);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
72
81
|
this.addHandler((ctx, next) => {
|
|
73
82
|
ctx.res.setHeader("Access-Control-Allow-Origin", "*");
|
|
74
83
|
if (ctx.path.includes("hot-update")) {
|
|
@@ -11,8 +11,6 @@ export type MockApi = {
|
|
|
11
11
|
};
|
|
12
12
|
declare const createFunctionDataHandler: (method: string, handler: (req: IncomingMessage, res: ServerResponse, next: NextFunction) => void) => (context: ModernServerContext, next: NextFunction) => Promise<void>;
|
|
13
13
|
declare const createStaticDataHandler: (method: string, handler: Record<string, any>) => (context: ModernServerContext) => void;
|
|
14
|
-
|
|
15
14
|
declare const _default: (mockConfig: MockConfig) => MockApi[];
|
|
16
|
-
|
|
17
15
|
export default _default;
|
|
18
16
|
export declare const getMatched: (context: ModernServerContext, mockApiList: MockApi[]) => MockApi | undefined;
|
|
@@ -14,7 +14,6 @@ export interface TreeNode {
|
|
|
14
14
|
* `module.parent` is the module that first required. so we have to implement
|
|
15
15
|
* a new tree which revisit the cache tree to find all parent node
|
|
16
16
|
*/
|
|
17
|
-
|
|
18
17
|
export declare class DependencyTree {
|
|
19
18
|
private readonly tree;
|
|
20
19
|
private readonly ignore;
|
|
@@ -25,7 +24,6 @@ export declare class DependencyTree {
|
|
|
25
24
|
*
|
|
26
25
|
* @param cache
|
|
27
26
|
*/
|
|
28
|
-
|
|
29
27
|
update(cache: any): void;
|
|
30
28
|
private shouldIgnore;
|
|
31
29
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,7 +2,5 @@ import { DevServer as Server } from './server';
|
|
|
2
2
|
import type { ModernDevServerOptions } from './types';
|
|
3
3
|
export { Server };
|
|
4
4
|
export type { ModernDevServerOptions };
|
|
5
|
-
|
|
6
5
|
declare const _default: (options: ModernDevServerOptions) => Promise<Server>;
|
|
7
|
-
|
|
8
6
|
export default _default;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -15,12 +15,10 @@ export type DevMiddlewareOptions = {
|
|
|
15
15
|
/** To ensure HMR works, the devMiddleware need inject the hmr client path into page when HMR enable. */
|
|
16
16
|
hmrClientPath?: string;
|
|
17
17
|
/** The options need by compiler middleware (like webpackMiddleware) */
|
|
18
|
-
|
|
19
18
|
headers?: Record<string, string | string[]>;
|
|
20
19
|
writeToDisk?: boolean | ((filename: string) => boolean);
|
|
21
20
|
stats?: boolean;
|
|
22
21
|
/** should trigger when compiler hook called */
|
|
23
|
-
|
|
24
22
|
callbacks: MiddlewareCallbacks;
|
|
25
23
|
};
|
|
26
24
|
/**
|
|
@@ -29,7 +27,6 @@ export type DevMiddlewareOptions = {
|
|
|
29
27
|
* - Inject the hmr client path into page (the hmr client modern/server already provide).
|
|
30
28
|
* - Notify server when compiler hooks are triggered.
|
|
31
29
|
*/
|
|
32
|
-
|
|
33
30
|
export type DevMiddleware = (options: DevMiddlewareOptions) => DevMiddlewareAPI;
|
|
34
31
|
export type ExtraOptions = {
|
|
35
32
|
dev: boolean | Partial<DevServerOptions>;
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.
|
|
18
|
+
"version": "2.21.0",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/index.js",
|
|
@@ -39,17 +39,18 @@
|
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@babel/core": "^7.
|
|
43
|
-
"@babel/register": "^7.
|
|
42
|
+
"@babel/core": "^7.21.8",
|
|
43
|
+
"@babel/register": "^7.21.0",
|
|
44
|
+
"@swc/helpers": "0.5.1",
|
|
44
45
|
"connect-history-api-fallback": "^2.0.0",
|
|
46
|
+
"http-compression": "1.0.6",
|
|
45
47
|
"minimatch": "^3.0.4",
|
|
46
48
|
"path-to-regexp": "^6.2.0",
|
|
47
49
|
"ws": "^8.2.0",
|
|
48
|
-
"@
|
|
49
|
-
"@modern-js/
|
|
50
|
-
"@modern-js/
|
|
51
|
-
"@modern-js/
|
|
52
|
-
"@modern-js/utils": "2.20.0"
|
|
50
|
+
"@modern-js/prod-server": "2.21.0",
|
|
51
|
+
"@modern-js/server-utils": "2.21.0",
|
|
52
|
+
"@modern-js/types": "2.21.0",
|
|
53
|
+
"@modern-js/utils": "2.21.0"
|
|
53
54
|
},
|
|
54
55
|
"devDependencies": {
|
|
55
56
|
"@types/connect-history-api-fallback": "^1.3.5",
|
|
@@ -59,14 +60,14 @@
|
|
|
59
60
|
"@types/ws": "^7.4.7",
|
|
60
61
|
"jest": "^29",
|
|
61
62
|
"node-mocks-http": "^1.11.0",
|
|
62
|
-
"ts-node": "^10.1
|
|
63
|
+
"ts-node": "^10.9.1",
|
|
63
64
|
"tsconfig-paths": "4.1.1",
|
|
64
|
-
"typescript": "^
|
|
65
|
+
"typescript": "^5",
|
|
65
66
|
"webpack": "^5.82.1",
|
|
66
67
|
"websocket": "^1",
|
|
67
|
-
"@modern-js/server-core": "2.
|
|
68
|
-
"@scripts/
|
|
69
|
-
"@scripts/
|
|
68
|
+
"@modern-js/server-core": "2.21.0",
|
|
69
|
+
"@scripts/jest-config": "2.21.0",
|
|
70
|
+
"@scripts/build": "2.21.0"
|
|
70
71
|
},
|
|
71
72
|
"peerDependencies": {
|
|
72
73
|
"devcert": "^1.0.0",
|