@rspack/dev-server 2.0.0-beta.1 → 2.0.0-beta.2

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 (42) hide show
  1. package/README.md +4 -3
  2. package/client/clients/WebSocketClient.d.ts +17 -0
  3. package/client/clients/WebSocketClient.js +28 -28
  4. package/client/index.d.ts +17 -0
  5. package/client/index.js +224 -363
  6. package/client/modules/logger/Logger.d.ts +40 -0
  7. package/client/modules/logger/Logger.js +123 -0
  8. package/client/modules/logger/createConsoleLogger.d.ts +12 -0
  9. package/client/modules/logger/createConsoleLogger.js +119 -0
  10. package/client/modules/logger/index.d.ts +18 -0
  11. package/client/modules/logger/index.js +20 -712
  12. package/client/modules/types.d.ts +45 -0
  13. package/client/modules/types.js +17 -0
  14. package/client/overlay.d.ts +44 -0
  15. package/client/overlay.js +241 -290
  16. package/client/progress.d.ts +11 -0
  17. package/client/progress.js +178 -111
  18. package/client/socket.d.ts +15 -0
  19. package/client/socket.js +19 -46
  20. package/client/utils/ansiHTML.d.ts +30 -0
  21. package/client/utils/ansiHTML.js +106 -153
  22. package/client/utils/log.d.ts +13 -0
  23. package/client/utils/log.js +7 -17
  24. package/client/utils/sendMessage.d.ts +11 -0
  25. package/client/utils/sendMessage.js +6 -15
  26. package/dist/0~launch-editor.js +618 -0
  27. package/dist/0~open.js +547 -0
  28. package/dist/0~p-retry.js +158 -0
  29. package/dist/131.js +1398 -0
  30. package/dist/getPort.d.ts +4 -1
  31. package/dist/index.js +1 -5
  32. package/dist/rslib-runtime.js +66 -0
  33. package/dist/server.d.ts +7 -7
  34. package/dist/servers/WebsocketServer.d.ts +8 -1
  35. package/dist/types.d.ts +7 -5
  36. package/package.json +55 -58
  37. package/dist/config.js +0 -2
  38. package/dist/getPort.js +0 -141
  39. package/dist/server.js +0 -1971
  40. package/dist/servers/BaseServer.js +0 -20
  41. package/dist/servers/WebsocketServer.js +0 -72
  42. package/dist/types.js +0 -5
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The following code is modified based on
3
+ * https://github.com/webpack/webpack-dev-server
4
+ *
5
+ * MIT Licensed
6
+ * Author Tobias Koppers @sokra
7
+ * Copyright (c) JS Foundation and other contributors
8
+ * https://github.com/webpack/webpack-dev-server/blob/main/LICENSE
9
+ */
10
+ export declare function isProgressSupported(): boolean;
11
+ export declare function defineProgressElement(): void;
@@ -1,130 +1,197 @@
1
- /**
2
- * The following code is modified based on
3
- * https://github.com/webpack/webpack-dev-server
4
- *
5
- * MIT Licensed
6
- * Author Tobias Koppers @sokra
7
- * Copyright (c) JS Foundation and other contributors
8
- * https://github.com/webpack/webpack-dev-server/blob/main/LICENSE
9
- */
10
- var __extends = (this && this.__extends) || (function () {
11
- var extendStatics = function (d, b) {
12
- extendStatics = Object.setPrototypeOf ||
13
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
14
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
15
- return extendStatics(d, b);
16
- };
17
- return function (d, b) {
18
- if (typeof b !== "function" && b !== null)
19
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
20
- extendStatics(d, b);
21
- function __() { this.constructor = d; }
22
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
23
- };
24
- })();
25
- export function isProgressSupported() {
26
- return ('customElements' in self && Boolean(HTMLElement.prototype.attachShadow));
1
+ function _define_property(obj, key, value) {
2
+ if (key in obj) Object.defineProperty(obj, key, {
3
+ value: value,
4
+ enumerable: true,
5
+ configurable: true,
6
+ writable: true
7
+ });
8
+ else obj[key] = value;
9
+ return obj;
27
10
  }
28
- export function defineProgressElement() {
29
- if (customElements.get('wds-progress')) {
30
- return;
31
- }
32
- var WebpackDevServerProgress = /** @class */ (function (_super) {
33
- __extends(WebpackDevServerProgress, _super);
34
- function WebpackDevServerProgress() {
35
- var _this = _super.call(this) || this;
36
- _this.attachShadow({ mode: 'open' });
37
- _this.maxDashOffset = -219.99078369140625;
38
- _this.animationTimer = undefined;
39
- _this.type = 'circular';
40
- _this.initialProgress = 0;
41
- return _this;
42
- }
43
- WebpackDevServerProgress.prototype.reset = function () {
44
- var _a;
11
+ function isProgressSupported() {
12
+ return 'customElements' in self && Boolean(HTMLElement.prototype.attachShadow);
13
+ }
14
+ function defineProgressElement() {
15
+ if (customElements.get('wds-progress')) return;
16
+ class WebpackDevServerProgress extends HTMLElement {
17
+ reset() {
18
+ var _this_getAttribute;
45
19
  clearTimeout(this.animationTimer);
46
- this.animationTimer = undefined;
47
- var typeAttr = (_a = this.getAttribute('type')) === null || _a === void 0 ? void 0 : _a.toLowerCase();
48
- this.type = typeAttr === 'circular' ? 'circular' : 'linear';
49
- var innerHTML = this.type === 'circular'
50
- ? WebpackDevServerProgress.circularTemplate()
51
- : WebpackDevServerProgress.linearTemplate();
20
+ this.animationTimer = void 0;
21
+ const typeAttr = null == (_this_getAttribute = this.getAttribute('type')) ? void 0 : _this_getAttribute.toLowerCase();
22
+ this.type = 'circular' === typeAttr ? 'circular' : 'linear';
23
+ const innerHTML = 'circular' === this.type ? WebpackDevServerProgress.circularTemplate() : WebpackDevServerProgress.linearTemplate();
52
24
  this.shadowRoot.innerHTML = innerHTML;
53
- var progressValue = this.getAttribute('progress');
25
+ const progressValue = this.getAttribute('progress');
54
26
  this.initialProgress = progressValue ? Number(progressValue) : 0;
55
27
  this.update(this.initialProgress);
56
- };
57
- WebpackDevServerProgress.circularTemplate = function () {
58
- return "\n <style>\n :host {\n width: 200px;\n height: 200px;\n position: fixed;\n right: 5%;\n top: 5%;\n pointer-events: none;\n transition: opacity .25s ease-in-out;\n z-index: 2147483645;\n }\n\n circle {\n fill: #282d35;\n }\n\n path {\n fill: rgba(0, 0, 0, 0);\n stroke: rgb(186, 223, 172);\n stroke-dasharray: 219.99078369140625;\n stroke-dashoffset: -219.99078369140625;\n stroke-width: 10;\n transform: rotate(90deg) translate(0px, -80px);\n }\n\n text {\n font-family: 'Open Sans', sans-serif;\n font-size: 18px;\n fill: #ffffff;\n dominant-baseline: middle;\n text-anchor: middle;\n }\n\n tspan#percent-super {\n fill: #bdc3c7;\n font-size: 0.45em;\n baseline-shift: 10%;\n }\n\n @keyframes fade {\n 0% { opacity: 1; transform: scale(1); }\n 100% { opacity: 0; transform: scale(0); }\n }\n\n .disappear {\n animation: fade 0.3s;\n animation-fill-mode: forwards;\n animation-delay: 0.5s;\n }\n\n .hidden {\n display: none;\n }\n </style>\n <svg id=\"progress\" class=\"hidden noselect\" viewBox=\"0 0 80 80\">\n <circle cx=\"50%\" cy=\"50%\" r=\"35\"></circle>\n <path d=\"M5,40a35,35 0 1,0 70,0a35,35 0 1,0 -70,0\"></path>\n <text x=\"50%\" y=\"51%\">\n <tspan id=\"percent-value\">0</tspan>\n <tspan id=\"percent-super\">%</tspan>\n </text>\n </svg>\n ";
59
- };
60
- WebpackDevServerProgress.linearTemplate = function () {
61
- return "\n <style>\n :host {\n position: fixed;\n top: 0;\n left: 0;\n pointer-events: none;\n height: 4px;\n width: 100vw;\n z-index: 2147483645;\n }\n\n #bar {\n width: 0%;\n height: 4px;\n background-color: rgb(186, 223, 172);\n }\n\n @keyframes fade {\n 0% { opacity: 1; }\n 100% { opacity: 0; }\n }\n\n .disappear {\n animation: fade 0.3s;\n animation-fill-mode: forwards;\n animation-delay: 0.5s;\n }\n\n .hidden {\n display: none;\n }\n </style>\n <div id=\"progress\"></div>\n ";
62
- };
63
- WebpackDevServerProgress.prototype.connectedCallback = function () {
28
+ }
29
+ static circularTemplate() {
30
+ return `
31
+ <style>
32
+ :host {
33
+ width: 200px;
34
+ height: 200px;
35
+ position: fixed;
36
+ right: 5%;
37
+ top: 5%;
38
+ pointer-events: none;
39
+ transition: opacity .25s ease-in-out;
40
+ z-index: 2147483645;
41
+ }
42
+
43
+ circle {
44
+ fill: #282d35;
45
+ }
46
+
47
+ path {
48
+ fill: rgba(0, 0, 0, 0);
49
+ stroke: rgb(186, 223, 172);
50
+ stroke-dasharray: 219.99078369140625;
51
+ stroke-dashoffset: -219.99078369140625;
52
+ stroke-width: 10;
53
+ transform: rotate(90deg) translate(0px, -80px);
54
+ }
55
+
56
+ text {
57
+ font-family: 'Open Sans', sans-serif;
58
+ font-size: 18px;
59
+ fill: #ffffff;
60
+ dominant-baseline: middle;
61
+ text-anchor: middle;
62
+ }
63
+
64
+ tspan#percent-super {
65
+ fill: #bdc3c7;
66
+ font-size: 0.45em;
67
+ baseline-shift: 10%;
68
+ }
69
+
70
+ @keyframes fade {
71
+ 0% { opacity: 1; transform: scale(1); }
72
+ 100% { opacity: 0; transform: scale(0); }
73
+ }
74
+
75
+ .disappear {
76
+ animation: fade 0.3s;
77
+ animation-fill-mode: forwards;
78
+ animation-delay: 0.5s;
79
+ }
80
+
81
+ .hidden {
82
+ display: none;
83
+ }
84
+ </style>
85
+ <svg id="progress" class="hidden noselect" viewBox="0 0 80 80">
86
+ <circle cx="50%" cy="50%" r="35"></circle>
87
+ <path d="M5,40a35,35 0 1,0 70,0a35,35 0 1,0 -70,0"></path>
88
+ <text x="50%" y="51%">
89
+ <tspan id="percent-value">0</tspan>
90
+ <tspan id="percent-super">%</tspan>
91
+ </text>
92
+ </svg>
93
+ `;
94
+ }
95
+ static linearTemplate() {
96
+ return `
97
+ <style>
98
+ :host {
99
+ position: fixed;
100
+ top: 0;
101
+ left: 0;
102
+ pointer-events: none;
103
+ height: 4px;
104
+ width: 100vw;
105
+ z-index: 2147483645;
106
+ }
107
+
108
+ #bar {
109
+ width: 0%;
110
+ height: 4px;
111
+ background-color: rgb(186, 223, 172);
112
+ }
113
+
114
+ @keyframes fade {
115
+ 0% { opacity: 1; }
116
+ 100% { opacity: 0; }
117
+ }
118
+
119
+ .disappear {
120
+ animation: fade 0.3s;
121
+ animation-fill-mode: forwards;
122
+ animation-delay: 0.5s;
123
+ }
124
+
125
+ .hidden {
126
+ display: none;
127
+ }
128
+ </style>
129
+ <div id="progress"></div>
130
+ `;
131
+ }
132
+ connectedCallback() {
64
133
  this.reset();
65
- };
66
- Object.defineProperty(WebpackDevServerProgress, "observedAttributes", {
67
- get: function () {
68
- return ['progress', 'type'];
69
- },
70
- enumerable: false,
71
- configurable: true
72
- });
73
- WebpackDevServerProgress.prototype.attributeChangedCallback = function (name, oldValue, newValue) {
74
- if (name === 'progress') {
75
- this.update(Number(newValue));
76
- }
77
- else if (name === 'type') {
78
- this.reset();
79
- }
80
- };
81
- WebpackDevServerProgress.prototype.update = function (percent) {
82
- var shadowRoot = this.shadowRoot;
83
- var element = shadowRoot.querySelector('#progress');
84
- if (this.type === 'circular') {
85
- var path = shadowRoot.querySelector('path');
86
- var value = shadowRoot.querySelector('#percent-value');
87
- var offset = ((100 - percent) / 100) * this.maxDashOffset;
134
+ }
135
+ static get observedAttributes() {
136
+ return [
137
+ 'progress',
138
+ 'type'
139
+ ];
140
+ }
141
+ attributeChangedCallback(name, oldValue, newValue) {
142
+ if ('progress' === name) this.update(Number(newValue));
143
+ else if ('type' === name) this.reset();
144
+ }
145
+ update(percent) {
146
+ const shadowRoot = this.shadowRoot;
147
+ const element = shadowRoot.querySelector('#progress');
148
+ if ('circular' === this.type) {
149
+ const path = shadowRoot.querySelector('path');
150
+ const value = shadowRoot.querySelector('#percent-value');
151
+ const offset = (100 - percent) / 100 * this.maxDashOffset;
88
152
  path.style.strokeDashoffset = String(offset);
89
153
  value.textContent = String(percent);
90
- }
91
- else {
92
- element.style.width = "".concat(percent, "%");
93
- }
94
- if (percent >= 100) {
95
- this.hide();
96
- }
97
- else if (percent > 0) {
98
- this.show();
99
- }
100
- };
101
- WebpackDevServerProgress.prototype.show = function () {
102
- var shadowRoot = this.shadowRoot;
103
- var element = shadowRoot.querySelector('#progress');
154
+ } else element.style.width = `${percent}%`;
155
+ if (percent >= 100) this.hide();
156
+ else if (percent > 0) this.show();
157
+ }
158
+ show() {
159
+ const shadowRoot = this.shadowRoot;
160
+ const element = shadowRoot.querySelector('#progress');
104
161
  element.classList.remove('hidden');
105
- };
106
- WebpackDevServerProgress.prototype.hide = function () {
107
- var _this = this;
108
- var shadowRoot = this.shadowRoot;
109
- var element = shadowRoot.querySelector('#progress');
110
- if (this.type === 'circular') {
162
+ }
163
+ hide() {
164
+ const shadowRoot = this.shadowRoot;
165
+ const element = shadowRoot.querySelector('#progress');
166
+ if ('circular' === this.type) {
111
167
  element.classList.add('disappear');
112
- element.addEventListener('animationend', function () {
168
+ element.addEventListener('animationend', ()=>{
113
169
  element.classList.add('hidden');
114
- _this.update(0);
115
- }, { once: true });
116
- }
117
- else if (this.type === 'linear') {
170
+ this.update(0);
171
+ }, {
172
+ once: true
173
+ });
174
+ } else if ('linear' === this.type) {
118
175
  element.classList.add('disappear');
119
- this.animationTimer = setTimeout(function () {
176
+ this.animationTimer = setTimeout(()=>{
120
177
  element.classList.remove('disappear');
121
178
  element.classList.add('hidden');
122
179
  element.style.width = '0%';
123
- _this.animationTimer = undefined;
180
+ this.animationTimer = void 0;
124
181
  }, 800);
125
182
  }
126
- };
127
- return WebpackDevServerProgress;
128
- }(HTMLElement));
183
+ }
184
+ constructor(){
185
+ super(), _define_property(this, "maxDashOffset", void 0), _define_property(this, "animationTimer", void 0), _define_property(this, "type", void 0), _define_property(this, "initialProgress", void 0);
186
+ this.attachShadow({
187
+ mode: 'open'
188
+ });
189
+ this.maxDashOffset = -219.99078369140625;
190
+ this.animationTimer = void 0;
191
+ this.type = 'circular';
192
+ this.initialProgress = 0;
193
+ }
194
+ }
129
195
  customElements.define('wds-progress', WebpackDevServerProgress);
130
196
  }
197
+ export { defineProgressElement, isProgressSupported };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The following code is modified based on
3
+ * https://github.com/webpack/webpack-dev-server
4
+ *
5
+ * MIT Licensed
6
+ * Author Tobias Koppers @sokra
7
+ * Copyright (c) JS Foundation and other contributors
8
+ * https://github.com/webpack/webpack-dev-server/blob/main/LICENSE
9
+ */
10
+ import type { CommunicationClient, EXPECTED_ANY } from './type.js';
11
+ export declare let client: CommunicationClient | null;
12
+ declare function socket(url: string, handlers: {
13
+ [handler: string]: (data?: EXPECTED_ANY, params?: EXPECTED_ANY) => EXPECTED_ANY;
14
+ }, reconnect?: number): void;
15
+ export default socket;
package/client/socket.js CHANGED
@@ -1,60 +1,33 @@
1
- /**
2
- * The following code is modified based on
3
- * https://github.com/webpack/webpack-dev-server
4
- *
5
- * MIT Licensed
6
- * Author Tobias Koppers @sokra
7
- * Copyright (c) JS Foundation and other contributors
8
- * https://github.com/webpack/webpack-dev-server/blob/main/LICENSE
9
- */
10
- import WebSocketClient from './clients/WebSocketClient.js';
11
- import { log } from './utils/log.js';
12
- // this WebsocketClient is here as a default fallback, in case the client is not injected
13
- var Client = typeof __webpack_dev_server_client__ !== 'undefined'
14
- ? typeof __webpack_dev_server_client__.default !== 'undefined'
15
- ? __webpack_dev_server_client__.default
16
- : __webpack_dev_server_client__
17
- : WebSocketClient;
18
- var retries = 0;
19
- var maxRetries = 10;
20
- // Initialized client is exported so external consumers can utilize the same instance
21
- // It is mutable to enforce singleton
22
- export var client = null;
23
- var timeout;
1
+ import WebSocketClient from "./clients/WebSocketClient.js";
2
+ import { log } from "./utils/log.js";
3
+ const Client = "u" > typeof __rspack_dev_server_client__ ? void 0 !== __rspack_dev_server_client__.default ? __rspack_dev_server_client__.default : __rspack_dev_server_client__ : WebSocketClient;
4
+ let retries = 0;
5
+ let maxRetries = 10;
6
+ let client = null;
7
+ let timeout;
24
8
  function socket(url, handlers, reconnect) {
25
9
  client = new Client(url);
26
- client.onOpen(function () {
10
+ client.onOpen(()=>{
27
11
  retries = 0;
28
- if (timeout) {
29
- clearTimeout(timeout);
30
- }
31
- if (typeof reconnect !== 'undefined') {
32
- maxRetries = reconnect;
33
- }
12
+ if (timeout) clearTimeout(timeout);
13
+ if (void 0 !== reconnect) maxRetries = reconnect;
34
14
  });
35
- client.onClose(function () {
36
- if (retries === 0) {
37
- handlers.close();
38
- }
39
- // Try to reconnect.
15
+ client.onClose(()=>{
16
+ if (0 === retries) handlers.close();
40
17
  client = null;
41
- // After 10 retries stop trying, to prevent logspam.
42
18
  if (retries < maxRetries) {
43
- // Exponentially increase timeout to reconnect.
44
- // Respectfully copied from the package `got`.
45
- var retryInMs = 1000 * Math.pow(2, retries) + Math.random() * 100;
19
+ const retryInMs = 1000 * Math.pow(2, retries) + 100 * Math.random();
46
20
  retries += 1;
47
21
  log.info('Trying to reconnect...');
48
- timeout = setTimeout(function () {
22
+ timeout = setTimeout(()=>{
49
23
  socket(url, handlers, reconnect);
50
24
  }, retryInMs);
51
25
  }
52
26
  });
53
- client.onMessage(function (data) {
54
- var message = JSON.parse(data);
55
- if (handlers[message.type]) {
56
- handlers[message.type](message.data, message.params);
57
- }
27
+ client.onMessage((data)=>{
28
+ const message = JSON.parse(data);
29
+ if (handlers[message.type]) handlers[message.type](message.data, message.params);
58
30
  });
59
31
  }
60
- export default socket;
32
+ const client_src_socket = socket;
33
+ export { client, client_src_socket as default };
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The following code is modified based on
3
+ * https://github.com/webpack/webpack-dev-server
4
+ *
5
+ * MIT Licensed
6
+ * Author Tobias Koppers @sokra
7
+ * Copyright (c) JS Foundation and other contributors
8
+ * https://github.com/webpack/webpack-dev-server/blob/main/LICENSE
9
+ */
10
+ interface AnsiHtmlTags {
11
+ open: typeof _openTags;
12
+ close: typeof _closeTags;
13
+ }
14
+ type Option<T> = T | null | undefined;
15
+ type Match = {
16
+ advance: (n: number) => void;
17
+ } & Array<string>;
18
+ declare const _defColors: Record<string, string | Array<string>>;
19
+ declare const _openTags: Record<string, string | ((m: Match) => Option<string>)>;
20
+ declare const _closeTags: Record<string, string | ((ansiCodes: Option<Array<string>>) => string)>;
21
+ /**
22
+ * Converts text with ANSI color codes to HTML markup.
23
+ */
24
+ declare function ansiHTML(text: string): string;
25
+ declare namespace ansiHTML {
26
+ var setColors: (colors: typeof _defColors) => void;
27
+ var reset: () => void;
28
+ var tags: AnsiHtmlTags;
29
+ }
30
+ export default ansiHTML;