@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,51 +1,50 @@
1
1
  import { HMR_SOCK_PATH } from "@modern-js/utils/universal/constants";
2
- function createSocketUrl(resourceQuery) {
3
- var searchParams = resourceQuery.substr(1).split("&");
4
- var options = {};
5
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
2
+ export function createSocketUrl(resourceQuery) {
3
+ var searchParams = resourceQuery.substr(1).split("&");
4
+ var options = {};
5
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
6
+ try {
7
+ for (var _iterator = searchParams[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
8
+ var pair = _step.value;
9
+ var ary = pair.split("=");
10
+ options[ary[0]] = decodeURIComponent(ary[1]);
11
+ }
12
+ } catch (err) {
13
+ _didIteratorError = true;
14
+ _iteratorError = err;
15
+ } finally {
6
16
  try {
7
- for(var _iterator = searchParams[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
8
- var pair = _step.value;
9
- var ary = pair.split("=");
10
- options[ary[0]] = decodeURIComponent(ary[1]);
11
- }
12
- } catch (err) {
13
- _didIteratorError = true;
14
- _iteratorError = err;
15
- } finally{
16
- try {
17
- if (!_iteratorNormalCompletion && _iterator.return != null) {
18
- _iterator.return();
19
- }
20
- } finally{
21
- if (_didIteratorError) {
22
- throw _iteratorError;
23
- }
24
- }
17
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
18
+ _iterator.return();
19
+ }
20
+ } finally {
21
+ if (_didIteratorError) {
22
+ throw _iteratorError;
23
+ }
25
24
  }
26
- var currentLocation = self.location;
27
- return getSocketUrl(options, currentLocation);
25
+ }
26
+ var currentLocation = self.location;
27
+ return getSocketUrl(options, currentLocation);
28
28
  }
29
- function formatURL(param) {
30
- var port = param.port, protocol = param.protocol, hostname = param.hostname, pathname = param.pathname;
31
- if (window.URL) {
32
- var url = new URL("http://localhost");
33
- url.port = port;
34
- url.hostname = hostname;
35
- url.protocol = protocol;
36
- url.pathname = pathname;
37
- return url.toString();
38
- }
39
- var colon = protocol.indexOf(":") === -1 ? ":" : "";
40
- return "".concat(protocol).concat(colon, "//").concat(hostname, ":").concat(port).concat(pathname);
29
+ export function formatURL(param) {
30
+ var port = param.port, protocol = param.protocol, hostname = param.hostname, pathname = param.pathname;
31
+ if (window.URL) {
32
+ var url = new URL("http://localhost");
33
+ url.port = port;
34
+ url.hostname = hostname;
35
+ url.protocol = protocol;
36
+ url.pathname = pathname;
37
+ return url.toString();
38
+ }
39
+ var colon = protocol.indexOf(":") === -1 ? ":" : "";
40
+ return "".concat(protocol).concat(colon, "//").concat(hostname, ":").concat(port).concat(pathname);
41
41
  }
42
42
  function getSocketUrl(urlParts, location) {
43
- var host = urlParts.host, port = urlParts.port, path = urlParts.path, protocol = urlParts.protocol;
44
- return formatURL({
45
- protocol: protocol || (location.protocol === "https:" ? "wss" : "ws"),
46
- hostname: host || location.hostname,
47
- port: port || location.port,
48
- pathname: path || HMR_SOCK_PATH
49
- });
43
+ var host = urlParts.host, port = urlParts.port, path = urlParts.path, protocol = urlParts.protocol;
44
+ return formatURL({
45
+ protocol: protocol || (location.protocol === "https:" ? "wss" : "ws"),
46
+ hostname: host || location.hostname,
47
+ port: port || location.port,
48
+ pathname: path || HMR_SOCK_PATH
49
+ });
50
50
  }
51
- export { createSocketUrl, formatURL };
@@ -1,162 +1,153 @@
1
- var __getOwnPropNames = Object.getOwnPropertyNames;
2
- var __commonJS = function(cb, mod) {
3
- return function __require() {
4
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = {
5
- exports: {}
6
- }).exports, mod), mod.exports;
7
- };
8
- };
9
1
  import stripAnsi from "@modern-js/utils/strip-ansi";
10
2
  import { formatWebpackMessages } from "@modern-js/utils/universal/format-webpack";
11
3
  import { createSocketUrl } from "./createSocketUrl";
12
- var require_hmr_client = __commonJS({
13
- "src/dev-tools/dev-middleware/hmr-client/index.ts": function(exports, module) {
14
- var clearOutdatedErrors = function clearOutdatedErrors() {
15
- if (typeof console !== "undefined" && typeof console.clear === "function") {
16
- if (hasCompileErrors) {
17
- console.clear();
18
- }
19
- }
20
- };
21
- var handleSuccess = function handleSuccess() {
22
- clearOutdatedErrors();
23
- var isHotUpdate = !isFirstCompilation;
24
- isFirstCompilation = false;
25
- hasCompileErrors = false;
26
- if (isHotUpdate) {
27
- tryApplyUpdates();
28
- }
29
- };
30
- var handleWarnings = function handleWarnings(warnings) {
31
- clearOutdatedErrors();
32
- var isHotUpdate = !isFirstCompilation;
33
- isFirstCompilation = false;
34
- hasCompileErrors = false;
35
- function printWarnings() {
36
- var formatted = formatWebpackMessages({
37
- warnings: warnings,
38
- errors: []
39
- });
40
- if (typeof console !== "undefined" && typeof console.warn === "function") {
41
- for(var i = 0; i < formatted.warnings.length; i++){
42
- if (i === 5) {
43
- console.warn("There were more warnings in other files.\nYou can find a complete log in the terminal.");
44
- break;
45
- }
46
- console.warn(stripAnsi(formatted.warnings[i]));
47
- }
48
- }
49
- }
50
- printWarnings();
51
- if (isHotUpdate) {
52
- tryApplyUpdates();
53
- }
54
- };
55
- var handleErrors = function handleErrors(errors) {
56
- clearOutdatedErrors();
57
- isFirstCompilation = false;
58
- hasCompileErrors = true;
59
- var formatted = formatWebpackMessages({
60
- errors: errors,
61
- warnings: []
62
- });
63
- if (typeof console !== "undefined" && typeof console.error === "function") {
64
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
65
- try {
66
- for(var _iterator = formatted.errors[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
67
- var error = _step.value;
68
- console.error(stripAnsi(error));
69
- }
70
- } catch (err) {
71
- _didIteratorError = true;
72
- _iteratorError = err;
73
- } finally{
74
- try {
75
- if (!_iteratorNormalCompletion && _iterator.return != null) {
76
- _iterator.return();
77
- }
78
- } finally{
79
- if (_didIteratorError) {
80
- throw _iteratorError;
81
- }
82
- }
83
- }
84
- }
85
- };
86
- var handleAvailableHash = function handleAvailableHash(hash) {
87
- mostRecentCompilationHash = hash;
88
- };
89
- var isUpdateAvailable = function isUpdateAvailable() {
90
- return mostRecentCompilationHash !== __webpack_hash__;
91
- };
92
- var canApplyUpdates = function canApplyUpdates() {
93
- return module.hot.status() === "idle";
94
- };
95
- var hadRuntimeError = false;
96
- var socketUrl = createSocketUrl(__resourceQuery);
97
- var connection = new WebSocket(socketUrl);
98
- connection.onopen = function() {
99
- if (typeof console !== "undefined" && typeof console.debug === "function") {
100
- console.debug("[HMR] connected.");
101
- }
102
- };
103
- connection.onclose = function() {
104
- if (typeof console !== "undefined" && typeof console.info === "function") {
105
- console.debug("[HMR] disconnected. Refresh the page if necessary.");
106
- }
107
- };
108
- var isFirstCompilation = true;
109
- var mostRecentCompilationHash = null;
110
- var hasCompileErrors = false;
111
- connection.onmessage = function(e) {
112
- var message = JSON.parse(e.data);
113
- switch(message.type){
114
- case "hash":
115
- handleAvailableHash(message.data);
116
- break;
117
- case "still-ok":
118
- case "ok":
119
- handleSuccess();
120
- break;
121
- case "content-changed":
122
- window.location.reload();
123
- break;
124
- case "warnings":
125
- handleWarnings(message.data);
126
- break;
127
- case "errors":
128
- handleErrors(message.data);
129
- break;
130
- default:
131
- }
132
- };
133
- function tryApplyUpdates() {
134
- if (!module.hot) {
135
- window.location.reload();
136
- return;
137
- }
138
- if (!isUpdateAvailable() || !canApplyUpdates()) {
139
- return;
140
- }
141
- function handleApplyUpdates(err, updatedModules) {
142
- var wantsForcedReload = err || !updatedModules || hadRuntimeError;
143
- if (wantsForcedReload) {
144
- window.location.reload();
145
- return;
146
- }
147
- if (isUpdateAvailable()) {
148
- tryApplyUpdates();
149
- }
150
- }
151
- var result = module.hot.check(/* autoApply */ true, handleApplyUpdates);
152
- if (result === null || result === void 0 ? void 0 : result.then) {
153
- result.then(function(updatedModules) {
154
- handleApplyUpdates(null, updatedModules);
155
- }, function(err) {
156
- handleApplyUpdates(err, null);
157
- });
158
- }
4
+ var hadRuntimeError = false;
5
+ var socketUrl = createSocketUrl(__resourceQuery);
6
+ var 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
+ var isFirstCompilation = true;
18
+ var mostRecentCompilationHash = null;
19
+ var hasCompileErrors = false;
20
+ function clearOutdatedErrors() {
21
+ if (typeof console !== "undefined" && typeof console.clear === "function") {
22
+ if (hasCompileErrors) {
23
+ console.clear();
24
+ }
25
+ }
26
+ }
27
+ function handleSuccess() {
28
+ clearOutdatedErrors();
29
+ var isHotUpdate = !isFirstCompilation;
30
+ isFirstCompilation = false;
31
+ hasCompileErrors = false;
32
+ if (isHotUpdate) {
33
+ tryApplyUpdates();
34
+ }
35
+ }
36
+ function handleWarnings(warnings) {
37
+ var printWarnings = function printWarnings2() {
38
+ var formatted = formatWebpackMessages({
39
+ warnings,
40
+ errors: []
41
+ });
42
+ if (typeof console !== "undefined" && typeof console.warn === "function") {
43
+ for (var i = 0; i < formatted.warnings.length; i++) {
44
+ if (i === 5) {
45
+ console.warn("There were more warnings in other files.\nYou can find a complete log in the terminal.");
46
+ break;
47
+ }
48
+ console.warn(stripAnsi(formatted.warnings[i]));
49
+ }
50
+ }
51
+ };
52
+ clearOutdatedErrors();
53
+ var isHotUpdate = !isFirstCompilation;
54
+ isFirstCompilation = false;
55
+ hasCompileErrors = false;
56
+ printWarnings();
57
+ if (isHotUpdate) {
58
+ tryApplyUpdates();
59
+ }
60
+ }
61
+ function handleErrors(errors) {
62
+ clearOutdatedErrors();
63
+ isFirstCompilation = false;
64
+ hasCompileErrors = true;
65
+ var formatted = formatWebpackMessages({
66
+ errors,
67
+ warnings: []
68
+ });
69
+ if (typeof console !== "undefined" && typeof console.error === "function") {
70
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
71
+ try {
72
+ for (var _iterator = formatted.errors[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
73
+ var error = _step.value;
74
+ console.error(stripAnsi(error));
75
+ }
76
+ } catch (err) {
77
+ _didIteratorError = true;
78
+ _iteratorError = err;
79
+ } finally {
80
+ try {
81
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
82
+ _iterator.return();
83
+ }
84
+ } finally {
85
+ if (_didIteratorError) {
86
+ throw _iteratorError;
159
87
  }
88
+ }
89
+ }
90
+ }
91
+ }
92
+ function handleAvailableHash(hash) {
93
+ mostRecentCompilationHash = hash;
94
+ }
95
+ connection.onmessage = function(e) {
96
+ var message = JSON.parse(e.data);
97
+ switch (message.type) {
98
+ case "hash":
99
+ handleAvailableHash(message.data);
100
+ break;
101
+ case "still-ok":
102
+ case "ok":
103
+ handleSuccess();
104
+ break;
105
+ case "content-changed":
106
+ window.location.reload();
107
+ break;
108
+ case "warnings":
109
+ handleWarnings(message.data);
110
+ break;
111
+ case "errors":
112
+ handleErrors(message.data);
113
+ break;
114
+ default:
115
+ }
116
+ };
117
+ function isUpdateAvailable() {
118
+ return mostRecentCompilationHash !== __webpack_hash__;
119
+ }
120
+ function canApplyUpdates() {
121
+ return module.hot.status() === "idle";
122
+ }
123
+ function tryApplyUpdates() {
124
+ var handleApplyUpdates = function handleApplyUpdates2(err, updatedModules) {
125
+ var wantsForcedReload = err || !updatedModules || hadRuntimeError;
126
+ if (wantsForcedReload) {
127
+ window.location.reload();
128
+ return;
129
+ }
130
+ if (isUpdateAvailable()) {
131
+ tryApplyUpdates();
160
132
  }
161
- });
162
- export default require_hmr_client();
133
+ };
134
+ if (!module.hot) {
135
+ window.location.reload();
136
+ return;
137
+ }
138
+ if (!isUpdateAvailable() || !canApplyUpdates()) {
139
+ return;
140
+ }
141
+ var result = module.hot.check(
142
+ /* autoApply */
143
+ true,
144
+ handleApplyUpdates
145
+ );
146
+ if (result === null || result === void 0 ? void 0 : result.then) {
147
+ result.then(function(updatedModules) {
148
+ handleApplyUpdates(null, updatedModules);
149
+ }, function(err) {
150
+ handleApplyUpdates(err, null);
151
+ });
152
+ }
153
+ }