@modern-js/server 2.20.0 → 2.21.1

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 CHANGED
@@ -1,5 +1,49 @@
1
1
  # @modern-js/server
2
2
 
3
+ ## 2.21.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [78e3ac8]
8
+ - Updated dependencies [2728724]
9
+ - @modern-js/prod-server@2.21.1
10
+ - @modern-js/server-utils@2.21.1
11
+ - @modern-js/types@2.21.1
12
+ - @modern-js/utils@2.21.1
13
+
14
+ ## 2.21.0
15
+
16
+ ### Patch Changes
17
+
18
+ - 26dcf3a: chore: bump typescript to v5 in devDependencies
19
+
20
+ chore: 升级 devDependencies 中的 typescript 版本到 v5
21
+
22
+ - 1ef03dc: feat(dev-server): enable gzip compression, add devServer.compress config
23
+
24
+ feat(dev-server): 默认启用 gzip 压缩,新增 devServer.compress 配置项
25
+
26
+ - 8fa8566: fix(dev-server): adjust hmr connection log level
27
+
28
+ fix(dev-server): 调整 hmr 连接的日志级别
29
+
30
+ - ad78387: chore(deps): bump babel-related dependencies to latest version
31
+
32
+ chore(deps): 升级 babel 相关依赖到最新版本
33
+
34
+ - Updated dependencies [cfc5bda]
35
+ - Updated dependencies [e81eeaf]
36
+ - Updated dependencies [26dcf3a]
37
+ - Updated dependencies [1ef03dc]
38
+ - Updated dependencies [056627f]
39
+ - Updated dependencies [0fc15ca]
40
+ - Updated dependencies [43b4e83]
41
+ - Updated dependencies [ad78387]
42
+ - @modern-js/prod-server@2.21.0
43
+ - @modern-js/utils@2.21.0
44
+ - @modern-js/server-utils@2.21.0
45
+ - @modern-js/types@2.21.0
46
+
3
47
  ## 2.20.0
4
48
 
5
49
  ### Patch Changes
@@ -24,6 +24,7 @@ const getDefaultDevOptions = () => {
24
24
  },
25
25
  watch: true,
26
26
  hot: true,
27
+ compress: true,
27
28
  liveReload: true
28
29
  };
29
30
  };
@@ -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.debug === "function") {
14
- console.debug("[HMR] connected.");
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.debug("[HMR] disconnected. Refresh the page if necessary.");
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")) {
@@ -16,6 +16,7 @@ export var getDefaultDevOptions = function() {
16
16
  },
17
17
  watch: true,
18
18
  hot: true,
19
+ compress: true,
19
20
  liveReload: true
20
21
  };
21
22
  };
@@ -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.debug === "function") {
9
- console.debug("[HMR] connected.");
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.debug("[HMR] disconnected. Refresh the page if necessary.");
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, _ref, connectHistoryApiFallback, historyApiFallbackMiddleware;
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
- 2
271
+ 4
253
272
  ];
254
273
  return [
255
274
  4,
256
275
  import("connect-history-api-fallback")
257
276
  ];
258
- case 1:
259
- _ref = _state.sent(), connectHistoryApiFallback = _ref.default;
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 = 2;
265
- case 2:
283
+ _state.label = 4;
284
+ case 4:
266
285
  return [
267
286
  2
268
287
  ];
@@ -16,6 +16,7 @@ export const getDefaultDevOptions = () => {
16
16
  },
17
17
  watch: true,
18
18
  hot: true,
19
+ compress: true,
19
20
  liveReload: true
20
21
  };
21
22
  };
@@ -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.debug === "function") {
9
- console.debug("[HMR] connected.");
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.debug("[HMR] disconnected. Refresh the page if necessary.");
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
  }
@@ -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;
@@ -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.20.0",
18
+ "version": "2.21.1",
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.18.0",
43
- "@babel/register": "^7.17.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
- "@swc/helpers": "0.5.1",
49
- "@modern-js/prod-server": "2.20.0",
50
- "@modern-js/server-utils": "2.20.0",
51
- "@modern-js/types": "2.20.0",
52
- "@modern-js/utils": "2.20.0"
50
+ "@modern-js/prod-server": "2.21.1",
51
+ "@modern-js/server-utils": "2.21.1",
52
+ "@modern-js/types": "2.21.1",
53
+ "@modern-js/utils": "2.21.1"
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.0",
63
+ "ts-node": "^10.9.1",
63
64
  "tsconfig-paths": "4.1.1",
64
- "typescript": "^4",
65
+ "typescript": "^5",
65
66
  "webpack": "^5.82.1",
66
67
  "websocket": "^1",
67
- "@modern-js/server-core": "2.20.0",
68
- "@scripts/build": "2.20.0",
69
- "@scripts/jest-config": "2.20.0"
68
+ "@modern-js/server-core": "2.21.1",
69
+ "@scripts/jest-config": "2.21.1",
70
+ "@scripts/build": "2.21.1"
70
71
  },
71
72
  "peerDependencies": {
72
73
  "devcert": "^1.0.0",