Skip to content

Commit e1daeff

Browse files
committed
chore: rebase
1 parent d9a5622 commit e1daeff

File tree

147 files changed

+14576
-9065
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+14576
-9065
lines changed

.github/workflows/nodejs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
run: npm run lint
4747

4848
- name: Security audit
49-
run: npm audit
49+
run: npm audit --production
5050

5151
- name: Check commit message
5252
uses: wagoid/commitlint-github-action@v1

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ coverage
1010
node_modules
1111
.vscode
1212
yarn.lock
13+
yarn-error.log
1314

1415
.eslintcache
1516

README.md

Lines changed: 108 additions & 99 deletions
Large diffs are not rendered by default.

bin/cli-flags.js

Lines changed: 129 additions & 93 deletions
Large diffs are not rendered by default.

client-src/clients/BaseClient.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

client-src/clients/SockJSClient.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22

33
const SockJS = require('../modules/sockjs-client');
44
const { log } = require('../utils/log');
5-
const BaseClient = require('./BaseClient');
65

7-
module.exports = class SockJSClient extends BaseClient {
6+
module.exports = class SockJSClient {
87
constructor(url) {
9-
super();
10-
118
// SockJS requires `http` and `https` protocols
129
this.sock = new SockJS(
1310
url.replace(/^ws:/i, 'http:').replace(/^wss:/i, 'https:')
@@ -17,11 +14,6 @@ module.exports = class SockJSClient extends BaseClient {
1714
};
1815
}
1916

20-
// eslint-disable-next-line no-unused-vars
21-
static getClientPath(options) {
22-
return require.resolve('./SockJSClient');
23-
}
24-
2517
onOpen(f) {
2618
this.sock.onopen = f;
2719
}

client-src/clients/WebsocketClient.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
11
'use strict';
22

33
const { log } = require('../utils/log');
4-
const BaseClient = require('./BaseClient');
54

6-
module.exports = class WebsocketClient extends BaseClient {
5+
module.exports = class WebsocketClient {
76
constructor(url) {
8-
super();
9-
107
this.client = new WebSocket(url);
118
this.client.onerror = (error) => {
129
log.error(error);
1310
};
1411
}
1512

16-
// eslint-disable-next-line no-unused-vars
17-
static getClientPath(options) {
18-
return require.resolve('./WebsocketClient');
19-
}
20-
2113
onOpen(f) {
2214
this.client.onopen = f;
2315
}

client-src/index.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ const socketURL = createSocketURL(parsedResourceQuery);
5151

5252
function setAllLogLevel(level) {
5353
// This is needed because the HMR logger operate separately from dev server logger
54-
webpackHotLog.setLogLevel(level);
54+
webpackHotLog.setLogLevel(
55+
level === 'verbose' || level === 'log' ? 'info' : level
56+
);
5557
setLogLevel(level);
5658
}
5759

@@ -85,7 +87,7 @@ const onSocketMessage = {
8587

8688
// Fixes #1042. overlay doesn't clear if errors are fixed but warnings remain.
8789
if (options.overlay) {
88-
overlay.clear();
90+
overlay.hide();
8991
}
9092

9193
sendMessage('Invalid');
@@ -119,7 +121,7 @@ const onSocketMessage = {
119121
log.info('Nothing changed.');
120122

121123
if (options.overlay) {
122-
overlay.clear();
124+
overlay.hide();
123125
}
124126

125127
sendMessage('StillOk');
@@ -128,7 +130,7 @@ const onSocketMessage = {
128130
sendMessage('Ok');
129131

130132
if (options.overlay) {
131-
overlay.clear();
133+
overlay.hide();
132134
}
133135

134136
if (options.initial) {
@@ -175,7 +177,7 @@ const onSocketMessage = {
175177
: options.overlay && options.overlay.warnings;
176178

177179
if (needShowOverlay) {
178-
overlay.showMessage(warnings);
180+
overlay.show(warnings, 'warnings');
179181
}
180182

181183
if (options.initial) {
@@ -203,7 +205,7 @@ const onSocketMessage = {
203205
: options.overlay && options.overlay.errors;
204206

205207
if (needShowOverlay) {
206-
overlay.showMessage(errors);
208+
overlay.show(errors, 'errors');
207209
}
208210

209211
options.initial = false;

client-src/overlay.js

Lines changed: 109 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -19,113 +19,139 @@ const colors = {
1919
darkgrey: '6D7891',
2020
};
2121

22-
let overlayIframe = null;
23-
let overlayDiv = null;
24-
let lastOnOverlayDivReady = null;
22+
let iframeContainerElement;
23+
let containerElement;
24+
let onLoadQueue = [];
2525

2626
ansiHTML.setColors(colors);
2727

28-
function createOverlayIframe(onIframeLoad) {
29-
const iframe = document.createElement('iframe');
30-
31-
iframe.id = 'webpack-dev-server-client-overlay';
32-
iframe.src = 'about:blank';
33-
iframe.style.position = 'fixed';
34-
iframe.style.left = 0;
35-
iframe.style.top = 0;
36-
iframe.style.right = 0;
37-
iframe.style.bottom = 0;
38-
iframe.style.width = '100vw';
39-
iframe.style.height = '100vh';
40-
iframe.style.border = 'none';
41-
iframe.style.zIndex = 9999999999;
42-
iframe.onload = onIframeLoad;
43-
44-
return iframe;
28+
function createContainer() {
29+
iframeContainerElement = document.createElement('iframe');
30+
iframeContainerElement.id = 'webpack-dev-server-client-overlay';
31+
iframeContainerElement.src = 'about:blank';
32+
iframeContainerElement.style.position = 'fixed';
33+
iframeContainerElement.style.left = 0;
34+
iframeContainerElement.style.top = 0;
35+
iframeContainerElement.style.right = 0;
36+
iframeContainerElement.style.bottom = 0;
37+
iframeContainerElement.style.width = '100vw';
38+
iframeContainerElement.style.height = '100vh';
39+
iframeContainerElement.style.border = 'none';
40+
iframeContainerElement.style.zIndex = 9999999999;
41+
iframeContainerElement.onload = () => {
42+
containerElement =
43+
iframeContainerElement.contentDocument.createElement('div');
44+
containerElement.id = 'webpack-dev-server-client-overlay-div';
45+
containerElement.style.position = 'fixed';
46+
containerElement.style.boxSizing = 'border-box';
47+
containerElement.style.left = 0;
48+
containerElement.style.top = 0;
49+
containerElement.style.right = 0;
50+
containerElement.style.bottom = 0;
51+
containerElement.style.width = '100vw';
52+
containerElement.style.height = '100vh';
53+
containerElement.style.backgroundColor = 'rgba(0, 0, 0, 0.85)';
54+
containerElement.style.color = '#E8E8E8';
55+
containerElement.style.fontFamily = 'Menlo, Consolas, monospace';
56+
containerElement.style.fontSize = 'large';
57+
containerElement.style.padding = '2rem';
58+
containerElement.style.lineHeight = '1.2';
59+
containerElement.style.whiteSpace = 'pre-wrap';
60+
containerElement.style.overflow = 'auto';
61+
62+
const headerElement = document.createElement('span');
63+
64+
headerElement.innerText = 'Compiled with problems:';
65+
66+
const closeButtonElement = document.createElement('button');
67+
68+
closeButtonElement.innerText = 'X';
69+
closeButtonElement.style.background = 'transparent';
70+
closeButtonElement.style.border = 'none';
71+
closeButtonElement.style.fontSize = '20px';
72+
closeButtonElement.style.fontWeight = 'bold';
73+
closeButtonElement.style.color = 'white';
74+
closeButtonElement.style.cursor = 'pointer';
75+
closeButtonElement.style.cssFloat = 'right';
76+
closeButtonElement.style.styleFloat = 'right';
77+
closeButtonElement.addEventListener('click', () => {
78+
hide();
79+
});
80+
81+
containerElement.appendChild(headerElement);
82+
containerElement.appendChild(closeButtonElement);
83+
containerElement.appendChild(document.createElement('br'));
84+
containerElement.appendChild(document.createElement('br'));
85+
86+
iframeContainerElement.contentDocument.body.appendChild(containerElement);
87+
88+
onLoadQueue.forEach((onLoad) => {
89+
onLoad(containerElement);
90+
});
91+
onLoadQueue = [];
92+
93+
iframeContainerElement.onload = null;
94+
};
95+
96+
document.body.appendChild(iframeContainerElement);
4597
}
4698

47-
function addOverlayDivTo(iframe) {
48-
const div = iframe.contentDocument.createElement('div');
49-
50-
div.id = 'webpack-dev-server-client-overlay-div';
51-
div.style.position = 'fixed';
52-
div.style.boxSizing = 'border-box';
53-
div.style.left = 0;
54-
div.style.top = 0;
55-
div.style.right = 0;
56-
div.style.bottom = 0;
57-
div.style.width = '100vw';
58-
div.style.height = '100vh';
59-
div.style.backgroundColor = 'rgba(0, 0, 0, 0.85)';
60-
div.style.color = '#E8E8E8';
61-
div.style.fontFamily = 'Menlo, Consolas, monospace';
62-
div.style.fontSize = 'large';
63-
div.style.padding = '2rem';
64-
div.style.lineHeight = '1.2';
65-
div.style.whiteSpace = 'pre-wrap';
66-
div.style.overflow = 'auto';
67-
68-
iframe.contentDocument.body.appendChild(div);
69-
70-
return div;
71-
}
72-
73-
function ensureOverlayDivExists(onOverlayDivReady) {
74-
if (overlayDiv) {
99+
function ensureOverlayExists(callback) {
100+
if (containerElement) {
75101
// Everything is ready, call the callback right away.
76-
onOverlayDivReady(overlayDiv);
102+
callback(containerElement);
103+
77104
return;
78105
}
79106

80-
// Creating an iframe may be asynchronous so we'll schedule the callback.
81-
// In case of multiple calls, last callback wins.
82-
lastOnOverlayDivReady = onOverlayDivReady;
107+
onLoadQueue.push(callback);
83108

84-
if (overlayIframe) {
85-
// We've already created it.
109+
if (iframeContainerElement) {
86110
return;
87111
}
88112

89-
// Create iframe and, when it is ready, a div inside it.
90-
overlayIframe = createOverlayIframe(() => {
91-
overlayDiv = addOverlayDivTo(overlayIframe);
92-
// Now we can talk!
93-
lastOnOverlayDivReady(overlayDiv);
94-
});
95-
96-
// Zalgo alert: onIframeLoad() will be called either synchronously
97-
// or asynchronously depending on the browser.
98-
// We delay adding it so `overlayIframe` is set when `onIframeLoad` fires.
99-
document.body.appendChild(overlayIframe);
113+
createContainer();
100114
}
101115

102116
// Successful compilation.
103-
function clear() {
104-
if (!overlayDiv) {
105-
// It is not there in the first place.
117+
function hide() {
118+
if (!iframeContainerElement) {
106119
return;
107120
}
108121

109122
// Clean up and reset internal state.
110-
document.body.removeChild(overlayIframe);
123+
document.body.removeChild(iframeContainerElement);
111124

112-
overlayDiv = null;
113-
overlayIframe = null;
114-
lastOnOverlayDivReady = null;
125+
iframeContainerElement = null;
126+
containerElement = null;
115127
}
116128

117129
// Compilation with errors (e.g. syntax error or missing modules).
118-
function showMessage(messages) {
119-
ensureOverlayDivExists((div) => {
120-
// Make it look similar to our terminal.
121-
const errorMessage = messages[0].message || messages[0];
122-
const text = ansiHTML(encode(errorMessage));
123-
124-
div.innerHTML = `<span style="color: #${colors.red}">Failed to compile.</span><br><br>${text}`;
130+
function show(messages, type) {
131+
ensureOverlayExists(() => {
132+
messages.forEach((message) => {
133+
const entryElement = document.createElement('div');
134+
const typeElement = document.createElement('span');
135+
136+
typeElement.innerText = type === 'warnings' ? 'Warning:' : 'Error:';
137+
typeElement.style.color = `#${colors.red}`;
138+
139+
// Make it look similar to our terminal.
140+
const errorMessage = message.message || messages[0];
141+
const text = ansiHTML(encode(errorMessage));
142+
const messageTextNode = document.createTextNode(text);
143+
144+
entryElement.appendChild(typeElement);
145+
entryElement.appendChild(document.createElement('br'));
146+
entryElement.appendChild(document.createElement('br'));
147+
entryElement.appendChild(messageTextNode);
148+
entryElement.appendChild(document.createElement('br'));
149+
entryElement.appendChild(document.createElement('br'));
150+
entryElement.appendChild(document.createElement('br'));
151+
152+
containerElement.appendChild(entryElement);
153+
});
125154
});
126155
}
127156

128-
module.exports = {
129-
clear,
130-
showMessage,
131-
};
157+
module.exports = { show, hide };

examples/cli/web-socket-url-cli/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# CLI: Web Socket URL
22

33
```console
4-
npx webpack serve --open-target --host 0.0.0.0 --web-socket-url <insert-host>:8080
4+
npx webpack serve --open-target --host 0.0.0.0 --client-web-socket-url ws://<insert-host>:8080
55
```
66

7-
_NOTE: replace `<insert local ip>` with your local IP Address._
7+
_NOTE: replace `<insert-host>` with your local IP Address._
88

99
In order to make the server publicly accessible the client needs to know with
1010
what host to connect to the server. If `--host 0.0.0.0` is given, the client
11-
would try to connect to `0.0.0.0`. With the `--web-socket-url` options it is possible to
11+
would try to connect to `0.0.0.0`. With the `--client-web-socket-url` options it is possible to
1212
override this.
1313

1414
## What Should Happen

examples/cli/web-socket-url/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
npx webpack serve
55
```
66

7-
_NOTE: replace `<insert local ip>` with your local IP Address._
8-
97
You're now able to explicitly define the protocol used with the `client.webSocketURL` option
10-
(have a look to the config provided in `webpack.config.js`).
8+
(have a look at the config provided in `webpack.config.js`).
119

1210
## What Should Happen
1311

globalSetupTest.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ async function validatePorts() {
1717

1818
arr.forEach((port) => {
1919
const check = tcpPortUsed.check(port, 'localhost').then((inUse) => {
20-
if (inUse) throw new Error(`${port} has already used. [${key}]`);
20+
if (inUse) {
21+
throw new Error(`${port} has already used. [${key}]`);
22+
}
2123
});
2224

2325
samples.push(check);

0 commit comments

Comments
 (0)