@modern-js/server 2.15.1-alpha.0 → 2.17.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.
Files changed (98) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/cjs/constants.js +12 -28
  3. package/dist/cjs/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +14 -32
  4. package/dist/cjs/dev-tools/dev-middleware/hmr-client/index.js +24 -42
  5. package/dist/cjs/dev-tools/dev-middleware/index.js +45 -50
  6. package/dist/cjs/dev-tools/dev-middleware/socketServer.js +48 -46
  7. package/dist/cjs/dev-tools/https/index.js +21 -38
  8. package/dist/cjs/dev-tools/mock/getMockData.js +33 -33
  9. package/dist/cjs/dev-tools/mock/index.js +67 -47
  10. package/dist/cjs/dev-tools/register/index.js +59 -70
  11. package/dist/cjs/dev-tools/watcher/dependencyTree.js +52 -55
  12. package/dist/cjs/dev-tools/watcher/index.js +52 -53
  13. package/dist/cjs/dev-tools/watcher/statsCache.js +37 -47
  14. package/dist/cjs/index.js +16 -28
  15. package/dist/cjs/server/devServer.js +163 -109
  16. package/dist/cjs/server/index.js +11 -29
  17. package/dist/cjs/types.js +4 -15
  18. package/dist/esm/constants.js +19 -20
  19. package/dist/esm/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +43 -44
  20. package/dist/esm/dev-tools/dev-middleware/hmr-client/index.js +148 -157
  21. package/dist/esm/dev-tools/dev-middleware/index.js +307 -291
  22. package/dist/esm/dev-tools/dev-middleware/socketServer.js +216 -202
  23. package/dist/esm/dev-tools/https/index.js +189 -182
  24. package/dist/esm/dev-tools/mock/getMockData.js +297 -278
  25. package/dist/esm/dev-tools/mock/index.js +198 -192
  26. package/dist/esm/dev-tools/register/index.js +141 -141
  27. package/dist/esm/dev-tools/watcher/dependencyTree.js +153 -138
  28. package/dist/esm/dev-tools/watcher/index.js +187 -175
  29. package/dist/esm/dev-tools/watcher/statsCache.js +118 -116
  30. package/dist/esm/index.js +9 -8
  31. package/dist/esm/server/devServer.js +803 -766
  32. package/dist/esm/server/index.js +80 -76
  33. package/dist/esm/types.js +1 -1
  34. package/dist/esm-node/constants.js +4 -5
  35. package/dist/esm-node/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +2 -11
  36. package/dist/esm-node/dev-tools/dev-middleware/hmr-client/index.js +125 -139
  37. package/dist/esm-node/dev-tools/dev-middleware/index.js +31 -17
  38. package/dist/esm-node/dev-tools/dev-middleware/socketServer.js +33 -12
  39. package/dist/esm-node/dev-tools/https/index.js +13 -15
  40. package/dist/esm-node/dev-tools/mock/getMockData.js +20 -12
  41. package/dist/esm-node/dev-tools/mock/index.js +7 -7
  42. package/dist/esm-node/dev-tools/register/index.js +38 -29
  43. package/dist/esm-node/dev-tools/watcher/dependencyTree.js +32 -21
  44. package/dist/esm-node/dev-tools/watcher/index.js +31 -18
  45. package/dist/esm-node/dev-tools/watcher/statsCache.js +18 -8
  46. package/dist/esm-node/index.js +2 -5
  47. package/dist/esm-node/server/devServer.js +87 -62
  48. package/dist/esm-node/server/index.js +1 -4
  49. package/dist/esm-node/types.js +1 -0
  50. package/package.json +13 -9
  51. package/dist/js/modern/constants.js +0 -19
  52. package/dist/js/modern/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +0 -41
  53. package/dist/js/modern/dev-tools/dev-middleware/hmr-client/index.js +0 -143
  54. package/dist/js/modern/dev-tools/dev-middleware/index.js +0 -94
  55. package/dist/js/modern/dev-tools/dev-middleware/socket-server.js +0 -132
  56. package/dist/js/modern/dev-tools/https/index.js +0 -49
  57. package/dist/js/modern/dev-tools/mock/getMockData.js +0 -114
  58. package/dist/js/modern/dev-tools/mock/index.js +0 -54
  59. package/dist/js/modern/dev-tools/register/index.js +0 -111
  60. package/dist/js/modern/dev-tools/watcher/dependency-tree.js +0 -59
  61. package/dist/js/modern/dev-tools/watcher/index.js +0 -106
  62. package/dist/js/modern/dev-tools/watcher/stats-cache.js +0 -58
  63. package/dist/js/modern/index.js +0 -12
  64. package/dist/js/modern/server/dev-server.js +0 -293
  65. package/dist/js/modern/server/index.js +0 -16
  66. package/dist/js/modern/types.js +0 -0
  67. package/dist/js/node/constants.js +0 -42
  68. package/dist/js/node/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +0 -65
  69. package/dist/js/node/dev-tools/dev-middleware/hmr-client/index.js +0 -152
  70. package/dist/js/node/dev-tools/dev-middleware/index.js +0 -119
  71. package/dist/js/node/dev-tools/dev-middleware/socket-server.js +0 -159
  72. package/dist/js/node/dev-tools/https/index.js +0 -72
  73. package/dist/js/node/dev-tools/mock/getMockData.js +0 -135
  74. package/dist/js/node/dev-tools/mock/index.js +0 -83
  75. package/dist/js/node/dev-tools/register/index.js +0 -138
  76. package/dist/js/node/dev-tools/watcher/dependency-tree.js +0 -89
  77. package/dist/js/node/dev-tools/watcher/index.js +0 -135
  78. package/dist/js/node/dev-tools/watcher/stats-cache.js +0 -87
  79. package/dist/js/node/index.js +0 -35
  80. package/dist/js/node/server/dev-server.js +0 -310
  81. package/dist/js/node/server/index.js +0 -39
  82. package/dist/js/node/types.js +0 -15
  83. package/dist/js/treeshaking/constants.js +0 -21
  84. package/dist/js/treeshaking/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +0 -51
  85. package/dist/js/treeshaking/dev-tools/dev-middleware/hmr-client/index.js +0 -157
  86. package/dist/js/treeshaking/dev-tools/dev-middleware/index.js +0 -322
  87. package/dist/js/treeshaking/dev-tools/dev-middleware/socket-server.js +0 -209
  88. package/dist/js/treeshaking/dev-tools/https/index.js +0 -193
  89. package/dist/js/treeshaking/dev-tools/mock/getMockData.js +0 -327
  90. package/dist/js/treeshaking/dev-tools/mock/index.js +0 -191
  91. package/dist/js/treeshaking/dev-tools/register/index.js +0 -153
  92. package/dist/js/treeshaking/dev-tools/watcher/dependency-tree.js +0 -150
  93. package/dist/js/treeshaking/dev-tools/watcher/index.js +0 -200
  94. package/dist/js/treeshaking/dev-tools/watcher/stats-cache.js +0 -128
  95. package/dist/js/treeshaking/index.js +0 -9
  96. package/dist/js/treeshaking/server/dev-server.js +0 -799
  97. package/dist/js/treeshaking/server/index.js +0 -92
  98. package/dist/js/treeshaking/types.js +0 -1
@@ -1,92 +1,96 @@
1
- function _assertThisInitialized(self) {
2
- if (self === void 0) {
3
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
4
- }
5
- return self;
1
+ function _assert_this_initialized(self) {
2
+ if (self === void 0) {
3
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
4
+ }
5
+ return self;
6
6
  }
7
- function _classCallCheck(instance, Constructor) {
8
- if (!(instance instanceof Constructor)) {
9
- throw new TypeError("Cannot call a class as a function");
10
- }
7
+ function _class_call_check(instance, Constructor) {
8
+ if (!(instance instanceof Constructor)) {
9
+ throw new TypeError("Cannot call a class as a function");
10
+ }
11
11
  }
12
- function _getPrototypeOf(o) {
13
- _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
14
- return o.__proto__ || Object.getPrototypeOf(o);
15
- };
16
- return _getPrototypeOf(o);
12
+ function _get_prototype_of(o) {
13
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o2) {
14
+ return o2.__proto__ || Object.getPrototypeOf(o2);
15
+ };
16
+ return _get_prototype_of(o);
17
17
  }
18
18
  function _inherits(subClass, superClass) {
19
- if (typeof superClass !== "function" && superClass !== null) {
20
- throw new TypeError("Super expression must either be null or a function");
19
+ if (typeof superClass !== "function" && superClass !== null) {
20
+ throw new TypeError("Super expression must either be null or a function");
21
+ }
22
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
23
+ constructor: {
24
+ value: subClass,
25
+ writable: true,
26
+ configurable: true
21
27
  }
22
- subClass.prototype = Object.create(superClass && superClass.prototype, {
23
- constructor: {
24
- value: subClass,
25
- writable: true,
26
- configurable: true
27
- }
28
- });
29
- if (superClass) _setPrototypeOf(subClass, superClass);
28
+ });
29
+ if (superClass)
30
+ _set_prototype_of(subClass, superClass);
30
31
  }
31
- function _possibleConstructorReturn(self, call) {
32
- if (call && (_typeof(call) === "object" || typeof call === "function")) {
33
- return call;
34
- }
35
- return _assertThisInitialized(self);
32
+ function _possible_constructor_return(self, call) {
33
+ if (call && (_type_of(call) === "object" || typeof call === "function")) {
34
+ return call;
35
+ }
36
+ return _assert_this_initialized(self);
36
37
  }
37
- function _setPrototypeOf(o, p) {
38
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
39
- o.__proto__ = p;
40
- return o;
41
- };
42
- return _setPrototypeOf(o, p);
38
+ function _set_prototype_of(o, p) {
39
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o2, p2) {
40
+ o2.__proto__ = p2;
41
+ return o2;
42
+ };
43
+ return _set_prototype_of(o, p);
43
44
  }
44
- var _typeof = function(obj) {
45
- "@swc/helpers - typeof";
46
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
47
- };
48
- function _isNativeReflectConstruct() {
49
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
50
- if (Reflect.construct.sham) return false;
51
- if (typeof Proxy === "function") return true;
52
- try {
53
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
54
- return true;
55
- } catch (e) {
56
- return false;
57
- }
45
+ function _type_of(obj) {
46
+ "@swc/helpers - typeof";
47
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
48
+ }
49
+ function _is_native_reflect_construct() {
50
+ if (typeof Reflect === "undefined" || !Reflect.construct)
51
+ return false;
52
+ if (Reflect.construct.sham)
53
+ return false;
54
+ if (typeof Proxy === "function")
55
+ return true;
56
+ try {
57
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {
58
+ }));
59
+ return true;
60
+ } catch (e) {
61
+ return false;
62
+ }
58
63
  }
59
- function _createSuper(Derived) {
60
- var hasNativeReflectConstruct = _isNativeReflectConstruct();
61
- return function _createSuperInternal() {
62
- var Super = _getPrototypeOf(Derived), result;
63
- if (hasNativeReflectConstruct) {
64
- var NewTarget = _getPrototypeOf(this).constructor;
65
- result = Reflect.construct(Super, arguments, NewTarget);
66
- } else {
67
- result = Super.apply(this, arguments);
68
- }
69
- return _possibleConstructorReturn(this, result);
70
- };
64
+ function _create_super(Derived) {
65
+ var hasNativeReflectConstruct = _is_native_reflect_construct();
66
+ return function _createSuperInternal() {
67
+ var Super = _get_prototype_of(Derived), result;
68
+ if (hasNativeReflectConstruct) {
69
+ var NewTarget = _get_prototype_of(this).constructor;
70
+ result = Reflect.construct(Super, arguments, NewTarget);
71
+ } else {
72
+ result = Super.apply(this, arguments);
73
+ }
74
+ return _possible_constructor_return(this, result);
75
+ };
71
76
  }
72
77
  import { Server } from "@modern-js/prod-server";
73
78
  import { ModernDevServer } from "./devServer";
74
79
  var createDevServer = function(options) {
75
- return new ModernDevServer(options);
80
+ return new ModernDevServer(options);
76
81
  };
77
- var DevServer = /*#__PURE__*/ function(Server) {
78
- "use strict";
79
- _inherits(DevServer, Server);
80
- var _super = _createSuper(DevServer);
81
- function DevServer(options) {
82
- _classCallCheck(this, DevServer);
83
- var _this;
84
- _this = _super.call(this, options);
85
- if (options.dev) {
86
- _this.serverImpl = createDevServer;
87
- }
88
- return _this;
82
+ export var DevServer = /* @__PURE__ */ function(Server2) {
83
+ "use strict";
84
+ _inherits(DevServer2, Server2);
85
+ var _super = _create_super(DevServer2);
86
+ function DevServer2(options) {
87
+ _class_call_check(this, DevServer2);
88
+ var _this;
89
+ _this = _super.call(this, options);
90
+ if (options.dev) {
91
+ _this.serverImpl = createDevServer;
89
92
  }
90
- return DevServer;
93
+ return _this;
94
+ }
95
+ return DevServer2;
91
96
  }(Server);
92
- export { DevServer };
package/dist/esm/types.js CHANGED
@@ -1 +1 @@
1
- "use strict";
1
+ export {};
@@ -1,5 +1,5 @@
1
1
  import { HMR_SOCK_PATH } from "@modern-js/utils/universal/constants";
2
- const getDefaultDevOptions = () => {
2
+ export const getDefaultDevOptions = () => {
3
3
  return {
4
4
  client: {
5
5
  path: HMR_SOCK_PATH,
@@ -11,12 +11,11 @@ const getDefaultDevOptions = () => {
11
11
  protocol: ""
12
12
  },
13
13
  https: false,
14
- devMiddleware: { writeToDisk: true },
14
+ devMiddleware: {
15
+ writeToDisk: true
16
+ },
15
17
  watch: true,
16
18
  hot: true,
17
19
  liveReload: true
18
20
  };
19
21
  };
20
- export {
21
- getDefaultDevOptions
22
- };
@@ -1,5 +1,5 @@
1
1
  import { HMR_SOCK_PATH } from "@modern-js/utils/universal/constants";
2
- function createSocketUrl(resourceQuery) {
2
+ export function createSocketUrl(resourceQuery) {
3
3
  const searchParams = resourceQuery.substr(1).split("&");
4
4
  const options = {};
5
5
  for (const pair of searchParams) {
@@ -9,12 +9,7 @@ function createSocketUrl(resourceQuery) {
9
9
  const currentLocation = self.location;
10
10
  return getSocketUrl(options, currentLocation);
11
11
  }
12
- function formatURL({
13
- port,
14
- protocol,
15
- hostname,
16
- pathname
17
- }) {
12
+ export function formatURL({ port, protocol, hostname, pathname }) {
18
13
  if (window.URL) {
19
14
  const url = new URL("http://localhost");
20
15
  url.port = port;
@@ -35,7 +30,3 @@ function getSocketUrl(urlParts, location) {
35
30
  pathname: path || HMR_SOCK_PATH
36
31
  });
37
32
  }
38
- export {
39
- createSocketUrl,
40
- formatURL
41
- };
@@ -1,150 +1,136 @@
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
1
  import stripAnsi from "@modern-js/utils/strip-ansi";
6
2
  import { formatWebpackMessages } from "@modern-js/utils/universal/format-webpack";
7
3
  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.onopen = function() {
14
- if (typeof console !== "undefined" && typeof console.debug === "function") {
15
- console.debug("[HMR] connected.");
16
- }
17
- };
18
- connection.onclose = function() {
19
- if (typeof console !== "undefined" && typeof console.info === "function") {
20
- console.debug("[HMR] disconnected. Refresh the page if necessary.");
21
- }
22
- };
23
- let isFirstCompilation = true;
24
- let mostRecentCompilationHash = null;
25
- let hasCompileErrors = false;
26
- function clearOutdatedErrors() {
27
- if (typeof console !== "undefined" && typeof console.clear === "function") {
28
- if (hasCompileErrors) {
29
- console.clear();
30
- }
31
- }
32
- }
33
- function handleSuccess() {
34
- clearOutdatedErrors();
35
- const isHotUpdate = !isFirstCompilation;
36
- isFirstCompilation = false;
37
- hasCompileErrors = false;
38
- if (isHotUpdate) {
39
- tryApplyUpdates();
40
- }
41
- }
42
- function handleWarnings(warnings) {
43
- clearOutdatedErrors();
44
- const isHotUpdate = !isFirstCompilation;
45
- isFirstCompilation = false;
46
- hasCompileErrors = false;
47
- function printWarnings() {
48
- const formatted = formatWebpackMessages({
49
- warnings,
50
- errors: []
51
- });
52
- if (typeof console !== "undefined" && typeof console.warn === "function") {
53
- for (let i = 0; i < formatted.warnings.length; i++) {
54
- if (i === 5) {
55
- console.warn(
56
- "There were more warnings in other files.\nYou can find a complete log in the terminal."
57
- );
58
- break;
59
- }
60
- console.warn(stripAnsi(formatted.warnings[i]));
61
- }
62
- }
63
- }
64
- printWarnings();
65
- if (isHotUpdate) {
66
- tryApplyUpdates();
67
- }
4
+ const hadRuntimeError = false;
5
+ const socketUrl = createSocketUrl(__resourceQuery);
6
+ const connection = new WebSocket(socketUrl);
7
+ connection.onopen = function() {
8
+ if (typeof console !== "undefined" && typeof console.debug === "function") {
9
+ console.debug("[HMR] connected.");
10
+ }
11
+ };
12
+ connection.onclose = function() {
13
+ if (typeof console !== "undefined" && typeof console.info === "function") {
14
+ console.debug("[HMR] disconnected. Refresh the page if necessary.");
15
+ }
16
+ };
17
+ let isFirstCompilation = true;
18
+ let mostRecentCompilationHash = null;
19
+ let hasCompileErrors = false;
20
+ function clearOutdatedErrors() {
21
+ if (typeof console !== "undefined" && typeof console.clear === "function") {
22
+ if (hasCompileErrors) {
23
+ console.clear();
68
24
  }
69
- function handleErrors(errors) {
70
- clearOutdatedErrors();
71
- isFirstCompilation = false;
72
- hasCompileErrors = true;
73
- const formatted = formatWebpackMessages({
74
- errors,
75
- warnings: []
76
- });
77
- if (typeof console !== "undefined" && typeof console.error === "function") {
78
- for (const error of formatted.errors) {
79
- console.error(stripAnsi(error));
25
+ }
26
+ }
27
+ function handleSuccess() {
28
+ clearOutdatedErrors();
29
+ const isHotUpdate = !isFirstCompilation;
30
+ isFirstCompilation = false;
31
+ hasCompileErrors = false;
32
+ if (isHotUpdate) {
33
+ tryApplyUpdates();
34
+ }
35
+ }
36
+ function handleWarnings(warnings) {
37
+ clearOutdatedErrors();
38
+ const isHotUpdate = !isFirstCompilation;
39
+ isFirstCompilation = false;
40
+ hasCompileErrors = false;
41
+ function printWarnings() {
42
+ const formatted = formatWebpackMessages({
43
+ warnings,
44
+ errors: []
45
+ });
46
+ if (typeof console !== "undefined" && typeof console.warn === "function") {
47
+ for (let i = 0; i < formatted.warnings.length; i++) {
48
+ if (i === 5) {
49
+ console.warn("There were more warnings in other files.\nYou can find a complete log in the terminal.");
50
+ break;
80
51
  }
52
+ console.warn(stripAnsi(formatted.warnings[i]));
81
53
  }
82
54
  }
83
- function handleAvailableHash(hash) {
84
- mostRecentCompilationHash = hash;
85
- }
86
- connection.onmessage = function(e) {
87
- const message = JSON.parse(e.data);
88
- switch (message.type) {
89
- case "hash":
90
- handleAvailableHash(message.data);
91
- break;
92
- case "still-ok":
93
- case "ok":
94
- handleSuccess();
95
- break;
96
- case "content-changed":
97
- window.location.reload();
98
- break;
99
- case "warnings":
100
- handleWarnings(message.data);
101
- break;
102
- case "errors":
103
- handleErrors(message.data);
104
- break;
105
- default:
106
- }
107
- };
108
- function isUpdateAvailable() {
109
- return mostRecentCompilationHash !== __webpack_hash__;
55
+ }
56
+ printWarnings();
57
+ if (isHotUpdate) {
58
+ tryApplyUpdates();
59
+ }
60
+ }
61
+ function handleErrors(errors) {
62
+ clearOutdatedErrors();
63
+ isFirstCompilation = false;
64
+ hasCompileErrors = true;
65
+ const formatted = formatWebpackMessages({
66
+ errors,
67
+ warnings: []
68
+ });
69
+ if (typeof console !== "undefined" && typeof console.error === "function") {
70
+ for (const error of formatted.errors) {
71
+ console.error(stripAnsi(error));
110
72
  }
111
- function canApplyUpdates() {
112
- return module.hot.status() === "idle";
73
+ }
74
+ }
75
+ function handleAvailableHash(hash) {
76
+ mostRecentCompilationHash = hash;
77
+ }
78
+ connection.onmessage = function(e) {
79
+ const message = JSON.parse(e.data);
80
+ switch (message.type) {
81
+ case "hash":
82
+ handleAvailableHash(message.data);
83
+ break;
84
+ case "still-ok":
85
+ case "ok":
86
+ handleSuccess();
87
+ break;
88
+ case "content-changed":
89
+ window.location.reload();
90
+ break;
91
+ case "warnings":
92
+ handleWarnings(message.data);
93
+ break;
94
+ case "errors":
95
+ handleErrors(message.data);
96
+ break;
97
+ default:
98
+ }
99
+ };
100
+ function isUpdateAvailable() {
101
+ return mostRecentCompilationHash !== __webpack_hash__;
102
+ }
103
+ function canApplyUpdates() {
104
+ return module.hot.status() === "idle";
105
+ }
106
+ function tryApplyUpdates() {
107
+ if (!module.hot) {
108
+ window.location.reload();
109
+ return;
110
+ }
111
+ if (!isUpdateAvailable() || !canApplyUpdates()) {
112
+ return;
113
+ }
114
+ function handleApplyUpdates(err, updatedModules) {
115
+ const wantsForcedReload = err || !updatedModules || hadRuntimeError;
116
+ if (wantsForcedReload) {
117
+ window.location.reload();
118
+ return;
113
119
  }
114
- function tryApplyUpdates() {
115
- if (!module.hot) {
116
- window.location.reload();
117
- return;
118
- }
119
- if (!isUpdateAvailable() || !canApplyUpdates()) {
120
- return;
121
- }
122
- function handleApplyUpdates(err, updatedModules) {
123
- const wantsForcedReload = err || !updatedModules || hadRuntimeError;
124
- if (wantsForcedReload) {
125
- window.location.reload();
126
- return;
127
- }
128
- if (isUpdateAvailable()) {
129
- tryApplyUpdates();
130
- }
131
- }
132
- const result = module.hot.check(
133
- /* autoApply */
134
- true,
135
- handleApplyUpdates
136
- );
137
- if (result == null ? void 0 : result.then) {
138
- result.then(
139
- (updatedModules) => {
140
- handleApplyUpdates(null, updatedModules);
141
- },
142
- (err) => {
143
- handleApplyUpdates(err, null);
144
- }
145
- );
146
- }
120
+ if (isUpdateAvailable()) {
121
+ tryApplyUpdates();
147
122
  }
148
123
  }
149
- });
150
- export default require_hmr_client();
124
+ const result = module.hot.check(
125
+ /* autoApply */
126
+ true,
127
+ handleApplyUpdates
128
+ );
129
+ if (result === null || result === void 0 ? void 0 : result.then) {
130
+ result.then((updatedModules) => {
131
+ handleApplyUpdates(null, updatedModules);
132
+ }, (err) => {
133
+ handleApplyUpdates(err, null);
134
+ });
135
+ }
136
+ }
@@ -1,31 +1,36 @@
1
+ function _define_property(obj, key, value) {
2
+ if (key in obj) {
3
+ Object.defineProperty(obj, key, {
4
+ value,
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true
8
+ });
9
+ } else {
10
+ obj[key] = value;
11
+ }
12
+ return obj;
13
+ }
1
14
  import { EventEmitter } from "events";
2
15
  import SocketServer from "./socketServer";
3
16
  const noop = () => {
4
17
  };
5
18
  function getHMRClientPath(client) {
6
- const protocol = (client == null ? void 0 : client.protocol) ? `&protocol=${client.protocol}` : "";
7
- const host = (client == null ? void 0 : client.host) ? `&host=${client.host}` : "";
8
- const path = (client == null ? void 0 : client.path) ? `&path=${client.path}` : "";
9
- const port = (client == null ? void 0 : client.port) ? `&port=${client.port}` : "";
19
+ const protocol = (client === null || client === void 0 ? void 0 : client.protocol) ? `&protocol=${client.protocol}` : "";
20
+ const host = (client === null || client === void 0 ? void 0 : client.host) ? `&host=${client.host}` : "";
21
+ const path = (client === null || client === void 0 ? void 0 : client.path) ? `&path=${client.path}` : "";
22
+ const port = (client === null || client === void 0 ? void 0 : client.port) ? `&port=${client.port}` : "";
10
23
  const clientEntry = `${require.resolve("@modern-js/server/hmr-client")}?${host}${path}${port}${protocol}`;
11
24
  return clientEntry;
12
25
  }
13
26
  class DevMiddleware extends EventEmitter {
14
- constructor({ dev, devMiddleware }) {
15
- super();
16
- this.devOptions = dev;
17
- this.socketServer = new SocketServer(dev);
18
- if (devMiddleware) {
19
- this.middleware = this.setupDevMiddleware(devMiddleware);
20
- }
21
- }
22
27
  init(app) {
23
28
  app.on("listening", () => {
24
29
  this.socketServer.prepare(app);
25
30
  });
26
31
  app.on("close", async () => {
27
- var _a;
28
- (_a = this.middleware) == null ? void 0 : _a.close(noop);
32
+ var _this_middleware;
33
+ (_this_middleware = this.middleware) === null || _this_middleware === void 0 ? void 0 : _this_middleware.close(noop);
29
34
  this.socketServer.close();
30
35
  });
31
36
  }
@@ -53,7 +58,16 @@ class DevMiddleware extends EventEmitter {
53
58
  });
54
59
  return middleware;
55
60
  }
61
+ constructor({ dev, devMiddleware }) {
62
+ super();
63
+ _define_property(this, "middleware", void 0);
64
+ _define_property(this, "devOptions", void 0);
65
+ _define_property(this, "socketServer", void 0);
66
+ this.devOptions = dev;
67
+ this.socketServer = new SocketServer(dev);
68
+ if (devMiddleware) {
69
+ this.middleware = this.setupDevMiddleware(devMiddleware);
70
+ }
71
+ }
56
72
  }
57
- export {
58
- DevMiddleware as default
59
- };
73
+ export { DevMiddleware as default };
@@ -1,18 +1,26 @@
1
+ function _define_property(obj, key, value) {
2
+ if (key in obj) {
3
+ Object.defineProperty(obj, key, {
4
+ value,
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true
8
+ });
9
+ } else {
10
+ obj[key] = value;
11
+ }
12
+ return obj;
13
+ }
1
14
  import ws from "ws";
2
15
  import { logger } from "@modern-js/utils";
3
16
  class SocketServer {
4
- constructor(options) {
5
- this.sockets = [];
6
- this.timer = null;
7
- this.options = options;
8
- }
9
17
  // create socket, install socket handler, bind socket event
10
18
  prepare(app) {
11
- var _a;
19
+ var _this_options_client;
12
20
  this.app = app;
13
21
  this.wsServer = new ws.Server({
14
22
  noServer: true,
15
- path: (_a = this.options.client) == null ? void 0 : _a.path
23
+ path: (_this_options_client = this.options.client) === null || _this_options_client === void 0 ? void 0 : _this_options_client.path
16
24
  });
17
25
  this.app.on("upgrade", (req, sock, head) => {
18
26
  if (!this.wsServer.shouldHandle(req)) {
@@ -48,11 +56,17 @@ class SocketServer {
48
56
  // write message to each socket
49
57
  sockWrite(type, data) {
50
58
  this.sockets.forEach((socket) => {
51
- this.send(socket, JSON.stringify({ type, data }));
59
+ this.send(socket, JSON.stringify({
60
+ type,
61
+ data
62
+ }));
52
63
  });
53
64
  }
54
65
  singleWrite(socket, type, data) {
55
- this.send(socket, JSON.stringify({ type, data }));
66
+ this.send(socket, JSON.stringify({
67
+ type,
68
+ data
69
+ }));
56
70
  }
57
71
  close() {
58
72
  this.sockets.forEach((socket) => {
@@ -131,7 +145,14 @@ class SocketServer {
131
145
  }
132
146
  connection.send(message);
133
147
  }
148
+ constructor(options) {
149
+ _define_property(this, "wsServer", void 0);
150
+ _define_property(this, "sockets", []);
151
+ _define_property(this, "options", void 0);
152
+ _define_property(this, "app", void 0);
153
+ _define_property(this, "stats", void 0);
154
+ _define_property(this, "timer", null);
155
+ this.options = options;
156
+ }
134
157
  }
135
- export {
136
- SocketServer as default
137
- };
158
+ export { SocketServer as default };