Skip to content

Commit 1a69983

Browse files
Merge branch 'master' into contentBasePrependPublic
2 parents 58e800d + 5dfa367 commit 1a69983

File tree

9 files changed

+1655
-683
lines changed

9 files changed

+1655
-683
lines changed

client-src/default/utils/createSocketUrl.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,11 @@ function createSocketUrl(resourceQuery) {
1111

1212
if (typeof resourceQuery === 'string' && resourceQuery !== '') {
1313
// If this bundle is inlined, use the resource query to get the correct url.
14+
// strip leading `?` from query string
1415
urlParts = url.parse(resourceQuery.substr(1));
1516
} else {
1617
// Else, get the url from the <script> this file was called with.
17-
let scriptHost = getCurrentScriptSource();
18-
19-
if (scriptHost) {
20-
// eslint-disable-next-line no-useless-escape
21-
scriptHost = scriptHost.replace(/\/[^\/]+$/, '');
22-
}
18+
const scriptHost = getCurrentScriptSource();
2319
urlParts = url.parse(scriptHost || '/', false, true);
2420
}
2521

@@ -50,6 +46,7 @@ function createSocketUrl(resourceQuery) {
5046
// because the browser doesn't accept non-secure websockets.
5147
if (
5248
hostname &&
49+
hostname !== '127.0.0.1' &&
5350
(self.location.protocol === 'https:' || urlParts.hostname === '0.0.0.0')
5451
) {
5552
protocol = self.location.protocol;

lib/servers/WebsocketServer.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,20 @@ module.exports = class WebsocketServer extends BaseServer {
1010
constructor(server) {
1111
super(server);
1212
this.wsServer = new ws.Server({
13-
server: this.server.listeningApp,
13+
noServer: true,
1414
path: this.server.sockPath,
1515
});
1616

17+
this.server.listeningApp.on('upgrade', (req, sock, head) => {
18+
if (!this.wsServer.shouldHandle(req)) {
19+
return;
20+
}
21+
22+
this.wsServer.handleUpgrade(req, sock, head, (connection) => {
23+
this.wsServer.emit('connection', connection, req);
24+
});
25+
});
26+
1727
this.wsServer.on('error', (err) => {
1828
this.server.log.error(err.message);
1929
});

package-lock.json

Lines changed: 1532 additions & 563 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"ip": "^1.1.5",
5252
"is-absolute-url": "^3.0.3",
5353
"killable": "^1.0.1",
54-
"loglevel": "^1.6.4",
54+
"loglevel": "^1.6.6",
5555
"opn": "^5.5.0",
5656
"p-retry": "^3.0.1",
5757
"portfinder": "^1.0.25",
@@ -71,44 +71,44 @@
7171
"yargs": "12.0.5"
7272
},
7373
"devDependencies": {
74-
"@babel/cli": "^7.6.4",
75-
"@babel/core": "^7.6.4",
76-
"@babel/plugin-transform-runtime": "^7.6.2",
77-
"@babel/preset-env": "^7.6.3",
78-
"@babel/runtime": "^7.6.3",
74+
"@babel/cli": "^7.7.0",
75+
"@babel/core": "^7.7.2",
76+
"@babel/plugin-transform-runtime": "^7.7.4",
77+
"@babel/preset-env": "^7.7.1",
78+
"@babel/runtime": "^7.7.2",
7979
"@commitlint/cli": "^8.2.0",
8080
"@commitlint/config-conventional": "^8.2.0",
8181
"babel-loader": "^8.0.6",
8282
"body-parser": "^1.19.0",
8383
"commitlint-azure-pipelines-cli": "^1.0.2",
84-
"copy-webpack-plugin": "^5.0.4",
84+
"copy-webpack-plugin": "^5.0.5",
8585
"css-loader": "^2.1.1",
86-
"eslint": "^6.5.1",
87-
"eslint-config-prettier": "^6.4.0",
86+
"eslint": "^6.7.1",
87+
"eslint-config-prettier": "^6.7.0",
8888
"eslint-config-webpack": "^1.2.5",
8989
"eslint-plugin-import": "^2.18.2",
9090
"execa": "^1.0.0",
9191
"file-loader": "^3.0.1",
9292
"html-loader": "^0.5.5",
9393
"html-webpack-plugin": "^3.2.0",
94-
"husky": "^3.0.9",
94+
"husky": "^3.1.0",
9595
"jest": "^24.9.0",
96-
"jest-junit": "^8.0.0",
96+
"jest-junit": "^9.0.0",
9797
"jquery": "^3.4.1",
9898
"less": "^3.10.3",
9999
"less-loader": "^5.0.0",
100-
"lint-staged": "^9.4.2",
100+
"lint-staged": "^9.5.0",
101101
"marked": "^0.7.0",
102-
"memfs": "^2.15.5",
102+
"memfs": "^3.0.1",
103103
"npm-run-all": "^4.1.5",
104-
"prettier": "^1.18.2",
104+
"prettier": "^1.19.1",
105105
"puppeteer": "^1.20.0",
106106
"rimraf": "^3.0.0",
107-
"standard-version": "^7.0.0",
107+
"standard-version": "^7.0.1",
108108
"style-loader": "^1.0.0",
109109
"supertest": "^4.0.2",
110110
"tcp-port-used": "^1.0.1",
111-
"typescript": "^3.6.4",
111+
"typescript": "^3.7.2",
112112
"url-loader": "^1.1.2",
113113
"webpack": "^4.41.2",
114114
"webpack-cli": "^3.3.10"

test/cli/cli.test.js

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,25 @@ describe('CLI', () => {
2020
testBin('--progress')
2121
.then((output) => {
2222
expect(output.code).toEqual(0);
23-
expect(output.stderr.includes('0% compiling')).toBe(true);
23+
expect(output.stderr).toContain('0% compiling');
2424
// should not profile
25-
expect(
26-
output.stderr.includes('ms after chunk modules optimization')
27-
).toBe(false);
25+
expect(output.stderr).not.toContain(
26+
'ms after chunk modules optimization'
27+
);
2828
done();
2929
})
3030
.catch(done);
3131
});
3232

3333
it('--quiet', async (done) => {
34-
const output = await testBin(`--quiet --port ${port1}`);
34+
const output = await testBin(`--quiet --colors=false --port ${port1}`);
3535
expect(output.code).toEqual(0);
3636
expect(output.stdout.split('\n').length === 3).toBe(true);
37-
expect(
38-
output.stdout.includes(`Project is running at http://localhost:${port1}/`)
39-
).toBe(true);
40-
expect(output.stdout.includes('webpack output is served from /')).toBe(
41-
true
37+
expect(output.stdout).toContain(
38+
`Project is running at http://localhost:${port1}/`
4239
);
43-
expect(
44-
output.stdout.includes('Content not from webpack is served from')
45-
).toBe(true);
40+
expect(output.stdout).toContain('webpack output is served from /');
41+
expect(output.stdout).toContain('Content not from webpack is served from');
4642
done();
4743
});
4844

@@ -51,9 +47,7 @@ describe('CLI', () => {
5147
.then((output) => {
5248
expect(output.code).toEqual(0);
5349
// should profile
54-
expect(output.stderr.includes('after chunk modules optimization')).toBe(
55-
true
56-
);
50+
expect(output.stderr).toContain('after chunk modules optimization');
5751
done();
5852
})
5953
.catch(done);
@@ -63,7 +57,7 @@ describe('CLI', () => {
6357
testBin('--bonjour')
6458
.then((output) => {
6559
expect(output.code).toEqual(0);
66-
expect(output.stdout.includes('Bonjour')).toBe(true);
60+
expect(output.stdout).toContain('Bonjour');
6761
done();
6862
})
6963
.catch(done);
@@ -73,7 +67,7 @@ describe('CLI', () => {
7367
testBin('--https')
7468
.then((output) => {
7569
expect(output.code).toEqual(0);
76-
expect(output.stdout.includes('Project is running at')).toBe(true);
70+
expect(output.stdout).toContain('Project is running at');
7771
done();
7872
})
7973
.catch(done);
@@ -85,7 +79,7 @@ describe('CLI', () => {
8579
)
8680
.then((output) => {
8781
expect(output.code).toEqual(0);
88-
expect(output.stdout.includes('Project is running at')).toBe(true);
82+
expect(output.stdout).toContain('Project is running at');
8983
done();
9084
})
9185
.catch(done);
@@ -115,9 +109,9 @@ describe('CLI', () => {
115109
testBin('--color')
116110
.then((output) => {
117111
// https://github.com/webpack/webpack-dev-server/blob/master/lib/utils/colors.js
118-
expect(
119-
output.stdout.includes('\u001b[39m \u001b[90m「wds」\u001b[39m:')
120-
).toEqual(true);
112+
expect(output.stdout).toContain(
113+
'\u001b[39m \u001b[90m「wds」\u001b[39m:'
114+
);
121115
done();
122116
})
123117
.catch(done);
@@ -134,7 +128,7 @@ describe('CLI', () => {
134128
if (process.platform === 'win32') {
135129
done();
136130
} else {
137-
expect(output.stdout.includes(socketPath)).toBe(true);
131+
expect(output.stdout).toContain(socketPath);
138132

139133
unlink(socketPath, () => {
140134
done();
@@ -155,7 +149,7 @@ describe('CLI', () => {
155149
})
156150
.catch((err) => {
157151
// for windows
158-
expect(err.stdout.includes('Compiled successfully.')).toEqual(true);
152+
expect(err.stdout).toContain('Compiled successfully.');
159153
done();
160154
});
161155
});

test/client/utils/__snapshots__/createSocketUrl.test.js.snap

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,38 @@ exports[`createSocketUrl should return the url when __resourceQuery is ?test 1`]
44

55
exports[`createSocketUrl should return the url when __resourceQuery is http://0.0.0.0 1`] = `"http://localhost/sockjs-node"`;
66

7-
exports[`createSocketUrl should return the url when __resourceQuery is http://user:pass@[::]:8080 1`] = `"ttp:user:pass@localhost:8080/sockjs-node"`;
7+
exports[`createSocketUrl should return the url when __resourceQuery is http://127.0.0.1 1`] = `"http://127.0.0.1/sockjs-node"`;
88

9-
exports[`createSocketUrl should return the url when __resourceQuery is http://user:password@localhost/ 1`] = `"ttp:user:password@localhost/sockjs-node"`;
9+
exports[`createSocketUrl should return the url when __resourceQuery is http://user:pass@[::]:8080 1`] = `"http://user:pass@localhost:8080/sockjs-node"`;
1010

11-
exports[`createSocketUrl should return the url when __resourceQuery is https://example.com 1`] = `"ttps:example.com/sockjs-node"`;
11+
exports[`createSocketUrl should return the url when __resourceQuery is http://user:password@localhost/ 1`] = `"http://user:password@localhost/sockjs-node"`;
1212

13-
exports[`createSocketUrl should return the url when __resourceQuery is https://example.com/path 1`] = `"ttps:example.com/sockjs-node"`;
13+
exports[`createSocketUrl should return the url when __resourceQuery is https://example.com 1`] = `"https://example.com/sockjs-node"`;
1414

15-
exports[`createSocketUrl should return the url when __resourceQuery is https://example.com/path/foo.js 1`] = `"ttps:example.com/sockjs-node"`;
15+
exports[`createSocketUrl should return the url when __resourceQuery is https://example.com/path 1`] = `"https://example.com/sockjs-node"`;
1616

17-
exports[`createSocketUrl should return the url when __resourceQuery is https://localhost:123 1`] = `"ttps:localhost:123/sockjs-node"`;
17+
exports[`createSocketUrl should return the url when __resourceQuery is https://example.com/path/foo.js 1`] = `"https://example.com/sockjs-node"`;
18+
19+
exports[`createSocketUrl should return the url when __resourceQuery is https://localhost:123 1`] = `"https://localhost:123/sockjs-node"`;
1820

1921
exports[`createSocketUrl should return the url when __resourceQuery is undefined 1`] = `"/sockjs-node"`;
2022

2123
exports[`createSocketUrl should return the url when the current script source is ?test 1`] = `"/sockjs-node"`;
2224

23-
exports[`createSocketUrl should return the url when the current script source is http://0.0.0.0 1`] = `"http:/sockjs-node"`;
25+
exports[`createSocketUrl should return the url when the current script source is http://0.0.0.0 1`] = `"http://localhost/sockjs-node"`;
26+
27+
exports[`createSocketUrl should return the url when the current script source is http://127.0.0.1 1`] = `"http://127.0.0.1/sockjs-node"`;
2428

25-
exports[`createSocketUrl should return the url when the current script source is http://user:pass@[::]:8080 1`] = `"http:/sockjs-node"`;
29+
exports[`createSocketUrl should return the url when the current script source is http://user:pass@[::]:8080 1`] = `"http://user:pass@localhost:8080/sockjs-node"`;
2630

2731
exports[`createSocketUrl should return the url when the current script source is http://user:password@localhost/ 1`] = `"http://user:password@localhost/sockjs-node"`;
2832

29-
exports[`createSocketUrl should return the url when the current script source is https://example.com 1`] = `"https:/sockjs-node"`;
33+
exports[`createSocketUrl should return the url when the current script source is https://example.com 1`] = `"https://example.com/sockjs-node"`;
3034

3135
exports[`createSocketUrl should return the url when the current script source is https://example.com/path 1`] = `"https://example.com/sockjs-node"`;
3236

3337
exports[`createSocketUrl should return the url when the current script source is https://example.com/path/foo.js 1`] = `"https://example.com/sockjs-node"`;
3438

35-
exports[`createSocketUrl should return the url when the current script source is https://localhost:123 1`] = `"https:/sockjs-node"`;
39+
exports[`createSocketUrl should return the url when the current script source is https://localhost:123 1`] = `"https://localhost:123/sockjs-node"`;
3640

3741
exports[`createSocketUrl should return the url when the current script source is undefined 1`] = `"/sockjs-node"`;

test/client/utils/createSocketUrl.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ describe('createSocketUrl', () => {
1010
'http://0.0.0.0',
1111
'https://localhost:123',
1212
'http://user:pass@[::]:8080',
13+
'http://127.0.0.1',
1314
// TODO: comment out after the major release
1415
// https://github.com/webpack/webpack-dev-server/pull/1954#issuecomment-498043376
1516
// 'file://filename',
@@ -26,7 +27,8 @@ describe('createSocketUrl', () => {
2627
const createSocketUrl = require('../../../client-src/default/utils/createSocketUrl');
2728

2829
test(`should return the url when __resourceQuery is ${url}`, () => {
29-
expect(createSocketUrl(url)).toMatchSnapshot();
30+
const query = url ? url.querystring : url;
31+
expect(createSocketUrl(query)).toMatchSnapshot();
3032
});
3133

3234
test(`should return the url when the current script source is ${url}`, () => {

test/e2e/ClientOptions.test.js

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,9 @@ describe('Client code', () => {
7272
.then((requestObj) => {
7373
page.waitFor(beforeBrowserCloseDelay).then(() => {
7474
browser.close().then(() => {
75-
expect(
76-
requestObj
77-
.url()
78-
.includes(`http://localhost:${port1}/sockjs-node`)
79-
).toBeTruthy();
75+
expect(requestObj.url()).toContain(
76+
`http://localhost:${port1}/sockjs-node`
77+
);
8078
done();
8179
});
8280
});
@@ -115,11 +113,9 @@ describe('Client complex inline script path', () => {
115113
.then((requestObj) => {
116114
page.waitFor(beforeBrowserCloseDelay).then(() => {
117115
browser.close().then(() => {
118-
expect(
119-
requestObj
120-
.url()
121-
.includes(`http://myhost.test:${port2}/foo/test/bar/`)
122-
).toBeTruthy();
116+
expect(requestObj.url()).toContain(
117+
`http://myhost.test:${port2}/foo/test/bar/`
118+
);
123119
done();
124120
});
125121
});
@@ -158,11 +154,9 @@ describe('Client complex inline script path with sockPort', () => {
158154
.then((requestObj) => {
159155
page.waitFor(beforeBrowserCloseDelay).then(() => {
160156
browser.close().then(() => {
161-
expect(
162-
requestObj
163-
.url()
164-
.includes(`http://localhost:${port3}/foo/test/bar`)
165-
).toBeTruthy();
157+
expect(requestObj.url()).toContain(
158+
`http://localhost:${port3}/foo/test/bar`
159+
);
166160
done();
167161
});
168162
});
@@ -202,11 +196,9 @@ describe('Client complex inline script path with sockPort, no sockPath', () => {
202196
.then((requestObj) => {
203197
page.waitFor(beforeBrowserCloseDelay).then(() => {
204198
browser.close().then(() => {
205-
expect(
206-
requestObj
207-
.url()
208-
.includes(`http://localhost:${port3}/sockjs-node`)
209-
).toBeTruthy();
199+
expect(requestObj.url()).toContain(
200+
`http://localhost:${port3}/sockjs-node`
201+
);
210202
done();
211203
});
212204
});
@@ -242,11 +234,9 @@ describe('Client complex inline script path with sockHost', () => {
242234
.then((requestObj) => {
243235
page.waitFor(beforeBrowserCloseDelay).then(() => {
244236
browser.close().then(() => {
245-
expect(
246-
requestObj
247-
.url()
248-
.includes(`http://myhost.test:${port2}/sockjs-node`)
249-
).toBeTruthy();
237+
expect(requestObj.url()).toContain(
238+
`http://myhost.test:${port2}/sockjs-node`
239+
);
250240
done();
251241
});
252242
});

0 commit comments

Comments
 (0)