@modern-js/server 2.13.4 → 2.14.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 CHANGED
@@ -1,5 +1,30 @@
1
1
  # @modern-js/server
2
2
 
3
+ ## 2.14.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 4779152: fix(utils): the esm format files should be generate for the client
8
+
9
+ fix(utils): 应该为客户端使用,生成 esm 格式的文件
10
+
11
+ - 1f34dba: fix(devServer): using current host and port to create HMR connection
12
+
13
+ fix(devServer): 建立 HMR 连接时默认使用当前 host 和 port
14
+
15
+ - Updated dependencies [4779152]
16
+ - Updated dependencies [8a3c693]
17
+ - Updated dependencies [9321bef]
18
+ - Updated dependencies [9b45c58]
19
+ - Updated dependencies [52d0cb1]
20
+ - Updated dependencies [60a81d0]
21
+ - Updated dependencies [dacef96]
22
+ - Updated dependencies [16399fd]
23
+ - @modern-js/utils@2.14.0
24
+ - @modern-js/server-utils@2.14.0
25
+ - @modern-js/types@2.14.0
26
+ - @modern-js/prod-server@2.14.0
27
+
3
28
  ## 2.13.4
4
29
 
5
30
  ### Patch Changes
@@ -20,15 +20,17 @@ __export(constants_exports, {
20
20
  getDefaultDevOptions: () => getDefaultDevOptions
21
21
  });
22
22
  module.exports = __toCommonJS(constants_exports);
23
- var import_utils = require("@modern-js/utils");
24
23
  var import_constants = require("@modern-js/utils/universal/constants");
25
24
  const getDefaultDevOptions = () => {
26
- const network = (0, import_utils.getIpv4Interfaces)().find((item) => !item.internal);
27
25
  return {
28
26
  client: {
29
- port: "8080",
30
27
  path: import_constants.HMR_SOCK_PATH,
31
- host: (network == null ? void 0 : network.address) || "localhost"
28
+ // By default it is set to the port number of the dev server
29
+ port: "",
30
+ // By default it is set to "location.hostname"
31
+ host: "",
32
+ // By default it is set to "location.protocol === 'https:' ? 'wss' : 'ws'""
33
+ protocol: ""
32
34
  },
33
35
  https: false,
34
36
  devMiddleware: { writeToDisk: true },
@@ -39,7 +39,7 @@ function getHMRClientPath(client) {
39
39
  const host = (client == null ? void 0 : client.host) ? `&host=${client.host}` : "";
40
40
  const path = (client == null ? void 0 : client.path) ? `&path=${client.path}` : "";
41
41
  const port = (client == null ? void 0 : client.port) ? `&port=${client.port}` : "";
42
- const clientEntry = `${require.resolve("./hmr-client")}?${host}${path}${port}${protocol}`;
42
+ const clientEntry = `${require.resolve("@modern-js/server/hmr-client")}?${host}${path}${port}${protocol}`;
43
43
  return clientEntry;
44
44
  }
45
45
  class DevMiddleware extends import_events.EventEmitter {
@@ -36,6 +36,7 @@ var import_https = require("https");
36
36
  var import_utils = require("@modern-js/utils");
37
37
  var import_prod_server = require("@modern-js/prod-server");
38
38
  var import_constants = require("@modern-js/utils/constants");
39
+ var import_lodash = require("@modern-js/utils/lodash");
39
40
  var import_constants2 = require("../constants");
40
41
  var import_mock = require("../dev-tools/mock");
41
42
  var import_register = require("../dev-tools/register");
@@ -57,14 +58,7 @@ class ModernDevServer extends import_prod_server.ModernServer {
57
58
  getDevOptions(options) {
58
59
  const devOptions = typeof options.dev === "boolean" ? {} : options.dev;
59
60
  const defaultOptions = (0, import_constants2.getDefaultDevOptions)();
60
- return {
61
- ...defaultOptions,
62
- ...devOptions,
63
- client: {
64
- ...defaultOptions.client,
65
- ...devOptions == null ? void 0 : devOptions.client
66
- }
67
- };
61
+ return (0, import_lodash.merge)(defaultOptions, devOptions);
68
62
  }
69
63
  addMiddlewareHandler(handlers) {
70
64
  handlers.forEach((handler) => {
@@ -1,14 +1,14 @@
1
- import { getIpv4Interfaces } from "@modern-js/utils";
2
1
  import { HMR_SOCK_PATH } from "@modern-js/utils/universal/constants";
3
2
  var getDefaultDevOptions = function() {
4
- var network = getIpv4Interfaces().find(function(item) {
5
- return !item.internal;
6
- });
7
3
  return {
8
4
  client: {
9
- port: "8080",
10
5
  path: HMR_SOCK_PATH,
11
- host: (network === null || network === void 0 ? void 0 : network.address) || "localhost"
6
+ // By default it is set to the port number of the dev server
7
+ port: "",
8
+ // By default it is set to "location.hostname"
9
+ host: "",
10
+ // By default it is set to "location.protocol === 'https:' ? 'wss' : 'ws'""
11
+ protocol: ""
12
12
  },
13
13
  https: false,
14
14
  devMiddleware: {
@@ -243,7 +243,7 @@ function getHMRClientPath(client) {
243
243
  var host = (client === null || client === void 0 ? void 0 : client.host) ? "&host=".concat(client.host) : "";
244
244
  var path = (client === null || client === void 0 ? void 0 : client.path) ? "&path=".concat(client.path) : "";
245
245
  var port = (client === null || client === void 0 ? void 0 : client.port) ? "&port=".concat(client.port) : "";
246
- var clientEntry = "".concat(require.resolve("./hmr-client"), "?").concat(host).concat(path).concat(port).concat(protocol);
246
+ var clientEntry = "".concat(require.resolve("@modern-js/server/hmr-client"), "?").concat(host).concat(path).concat(port).concat(protocol);
247
247
  return clientEntry;
248
248
  }
249
249
  var DevMiddleware = /*#__PURE__*/ function(EventEmitter) {
@@ -144,45 +144,6 @@ function _nonIterableRest() {
144
144
  function _nonIterableSpread() {
145
145
  throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
146
146
  }
147
- function _objectSpread(target) {
148
- for(var i = 1; i < arguments.length; i++){
149
- var source = arguments[i] != null ? arguments[i] : {};
150
- var ownKeys = Object.keys(source);
151
- if (typeof Object.getOwnPropertySymbols === "function") {
152
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
153
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
154
- }));
155
- }
156
- ownKeys.forEach(function(key) {
157
- _defineProperty(target, key, source[key]);
158
- });
159
- }
160
- return target;
161
- }
162
- function ownKeys(object, enumerableOnly) {
163
- var keys = Object.keys(object);
164
- if (Object.getOwnPropertySymbols) {
165
- var symbols = Object.getOwnPropertySymbols(object);
166
- if (enumerableOnly) {
167
- symbols = symbols.filter(function(sym) {
168
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
169
- });
170
- }
171
- keys.push.apply(keys, symbols);
172
- }
173
- return keys;
174
- }
175
- function _objectSpreadProps(target, source) {
176
- source = source != null ? source : {};
177
- if (Object.getOwnPropertyDescriptors) {
178
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
179
- } else {
180
- ownKeys(Object(source)).forEach(function(key) {
181
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
182
- });
183
- }
184
- return target;
185
- }
186
147
  function _possibleConstructorReturn(self, call) {
187
148
  if (call && (_typeof(call) === "object" || typeof call === "function")) {
188
149
  return call;
@@ -346,6 +307,7 @@ import { createServer as createHttpsServer } from "https";
346
307
  import { API_DIR, SERVER_BUNDLE_DIRECTORY, SERVER_DIR, SHARED_DIR } from "@modern-js/utils";
347
308
  import { createProxyHandler, ModernServer, AGGRED_DIR } from "@modern-js/prod-server";
348
309
  import { LOADABLE_STATS_FILE } from "@modern-js/utils/constants";
310
+ import { merge as deepMerge } from "@modern-js/utils/lodash";
349
311
  import { getDefaultDevOptions } from "../constants";
350
312
  import { createMockHandler } from "../dev-tools/mock";
351
313
  import { enableRegister } from "../dev-tools/register";
@@ -380,9 +342,7 @@ var ModernDevServer = /*#__PURE__*/ function(ModernServer) {
380
342
  value: function getDevOptions(options) {
381
343
  var devOptions = typeof options.dev === "boolean" ? {} : options.dev;
382
344
  var defaultOptions = getDefaultDevOptions();
383
- return _objectSpreadProps(_objectSpread({}, defaultOptions, devOptions), {
384
- client: _objectSpread({}, defaultOptions.client, devOptions === null || devOptions === void 0 ? void 0 : devOptions.client)
385
- });
345
+ return deepMerge(defaultOptions, devOptions);
386
346
  }
387
347
  },
388
348
  {
@@ -1,12 +1,14 @@
1
- import { getIpv4Interfaces } from "@modern-js/utils";
2
1
  import { HMR_SOCK_PATH } from "@modern-js/utils/universal/constants";
3
2
  const getDefaultDevOptions = () => {
4
- const network = getIpv4Interfaces().find((item) => !item.internal);
5
3
  return {
6
4
  client: {
7
- port: "8080",
8
5
  path: HMR_SOCK_PATH,
9
- host: (network == null ? void 0 : network.address) || "localhost"
6
+ // By default it is set to the port number of the dev server
7
+ port: "",
8
+ // By default it is set to "location.hostname"
9
+ host: "",
10
+ // By default it is set to "location.protocol === 'https:' ? 'wss' : 'ws'""
11
+ protocol: ""
10
12
  },
11
13
  https: false,
12
14
  devMiddleware: { writeToDisk: true },
@@ -7,7 +7,7 @@ function getHMRClientPath(client) {
7
7
  const host = (client == null ? void 0 : client.host) ? `&host=${client.host}` : "";
8
8
  const path = (client == null ? void 0 : client.path) ? `&path=${client.path}` : "";
9
9
  const port = (client == null ? void 0 : client.port) ? `&port=${client.port}` : "";
10
- const clientEntry = `${require.resolve("./hmr-client")}?${host}${path}${port}${protocol}`;
10
+ const clientEntry = `${require.resolve("@modern-js/server/hmr-client")}?${host}${path}${port}${protocol}`;
11
11
  return clientEntry;
12
12
  }
13
13
  class DevMiddleware extends EventEmitter {
@@ -13,6 +13,7 @@ import {
13
13
  AGGRED_DIR
14
14
  } from "@modern-js/prod-server";
15
15
  import { LOADABLE_STATS_FILE } from "@modern-js/utils/constants";
16
+ import { merge as deepMerge } from "@modern-js/utils/lodash";
16
17
  import { getDefaultDevOptions } from "../constants";
17
18
  import { createMockHandler } from "../dev-tools/mock";
18
19
  import { enableRegister } from "../dev-tools/register";
@@ -34,14 +35,7 @@ class ModernDevServer extends ModernServer {
34
35
  getDevOptions(options) {
35
36
  const devOptions = typeof options.dev === "boolean" ? {} : options.dev;
36
37
  const defaultOptions = getDefaultDevOptions();
37
- return {
38
- ...defaultOptions,
39
- ...devOptions,
40
- client: {
41
- ...defaultOptions.client,
42
- ...devOptions == null ? void 0 : devOptions.client
43
- }
44
- };
38
+ return deepMerge(defaultOptions, devOptions);
45
39
  }
46
40
  addMiddlewareHandler(handlers) {
47
41
  handlers.forEach((handler) => {
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "2.13.4",
14
+ "version": "2.14.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/cjs/index.js",
@@ -24,6 +24,14 @@
24
24
  "require": "./dist/cjs/index.js"
25
25
  },
26
26
  "default": "./dist/esm/index.js"
27
+ },
28
+ "./hmr-client": {
29
+ "node": {
30
+ "jsnext:source": "./src/dev-tools/dev-middleware/hmr-client/index.ts",
31
+ "import": "./dist/esm/dev-tools/dev-middleware/hmr-client/index.js",
32
+ "require": "./dist/cjs/dev-tools/dev-middleware/hmr-client/index.js"
33
+ },
34
+ "default": "./dist/esm/dev-tools/dev-middleware/hmr-client/index.js"
27
35
  }
28
36
  },
29
37
  "dependencies": {
@@ -33,10 +41,10 @@
33
41
  "minimatch": "^3.0.4",
34
42
  "path-to-regexp": "^6.2.0",
35
43
  "ws": "^8.2.0",
36
- "@modern-js/prod-server": "2.13.4",
37
- "@modern-js/server-utils": "2.13.4",
38
- "@modern-js/types": "2.13.4",
39
- "@modern-js/utils": "2.13.4"
44
+ "@modern-js/prod-server": "2.14.0",
45
+ "@modern-js/server-utils": "2.14.0",
46
+ "@modern-js/types": "2.14.0",
47
+ "@modern-js/utils": "2.14.0"
40
48
  },
41
49
  "devDependencies": {
42
50
  "@types/connect-history-api-fallback": "^1.3.5",
@@ -51,9 +59,9 @@
51
59
  "typescript": "^4",
52
60
  "webpack": "^5.76.2",
53
61
  "websocket": "^1",
54
- "@modern-js/server-core": "2.13.4",
55
- "@scripts/build": "2.13.4",
56
- "@scripts/jest-config": "2.13.4"
62
+ "@modern-js/server-core": "2.14.0",
63
+ "@scripts/build": "2.14.0",
64
+ "@scripts/jest-config": "2.14.0"
57
65
  },
58
66
  "peerDependencies": {
59
67
  "devcert": "^1.0.0",