Skip to content

Commit 2478bce

Browse files
committed
fix(Server): return socket processing to bin
1 parent 1dd0e3c commit 2478bce

File tree

3 files changed

+48
-35
lines changed

3 files changed

+48
-35
lines changed

bin/webpack-dev-server.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,19 @@ function startDevServer(config, options) {
192192
}
193193
});
194194

195-
runServer();
195+
server.listen(options.socket, options.host, (err) => {
196+
if (err) {
197+
throw err;
198+
}
199+
// chmod 666 (rw rw rw)
200+
const READ_WRITE = 438;
201+
202+
fs.chmod(options.socket, READ_WRITE, (err) => {
203+
if (err) {
204+
throw err;
205+
}
206+
});
207+
});
196208
} else if (options.port) {
197209
runServer();
198210
} else {

lib/Server.js

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,21 @@ class Server {
741741
return false;
742742
}
743743

744+
showStatus() {
745+
const suffix =
746+
this.options.inline !== false || this.options.lazy === true
747+
? '/'
748+
: '/webpack-dev-server/';
749+
const uri = `${createDomain(this.options, this.listeningApp)}${suffix}`;
750+
751+
status(
752+
uri,
753+
this.options,
754+
this.log,
755+
this.options.stats && this.options.stats.colors
756+
);
757+
}
758+
744759
// delegate listen call and init sockjs
745760
listen(port, hostname, fn) {
746761
this.hostname = hostname;
@@ -816,36 +831,7 @@ class Server {
816831
runBonjour(this.options);
817832
}
818833

819-
const showStatus = () => {
820-
const suffix =
821-
this.options.inline !== false || this.options.lazy === true
822-
? '/'
823-
: '/webpack-dev-server/';
824-
825-
const uri = `${createDomain(this.options, this.listeningApp)}${suffix}`;
826-
827-
status(
828-
uri,
829-
this.options,
830-
this.log,
831-
this.options.stats && this.options.stats.colors
832-
);
833-
};
834-
835-
if (this.options.socket) {
836-
// chmod 666 (rw rw rw)
837-
const READ_WRITE = 438;
838-
839-
fs.chmod(this.options.socket, READ_WRITE, (err) => {
840-
if (err) {
841-
throw err;
842-
}
843-
844-
showStatus();
845-
});
846-
} else {
847-
showStatus();
848-
}
834+
this.showStatus();
849835

850836
if (fn) {
851837
fn.call(this.listeningApp, err);

test/cli.test.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/* eslint-disable
44
array-bracket-spacing,
55
*/
6+
const { unlink } = require('fs');
67
const path = require('path');
78
const execa = require('execa');
89
const runDevServer = require('./helpers/run-webpack-dev-server');
@@ -21,7 +22,7 @@ describe('CLI', () => {
2122
runDevServer('--progress')
2223
.then((output) => {
2324
expect(output.code).toEqual(0);
24-
expect(output.stderr.indexOf('0% compiling') >= 0).toBe(true);
25+
expect(output.stderr.includes('0% compiling')).toBe(true);
2526
done();
2627
})
2728
.catch(done);
@@ -31,7 +32,7 @@ describe('CLI', () => {
3132
runDevServer('--bonjour')
3233
.then((output) => {
3334
expect(output.code).toEqual(0);
34-
expect(output.stdout.indexOf('Bonjour') >= 0).toBe(true);
35+
expect(output.stdout.includes('Bonjour')).toBe(true);
3536
done();
3637
})
3738
.catch(done);
@@ -41,7 +42,7 @@ describe('CLI', () => {
4142
runDevServer('--https')
4243
.then((output) => {
4344
expect(output.code).toEqual(0);
44-
expect(output.stdout.indexOf('Project is running at') >= 0).toBe(true);
45+
expect(output.stdout.includes('Project is running at')).toBe(true);
4546
done();
4647
})
4748
.catch(done);
@@ -53,7 +54,7 @@ describe('CLI', () => {
5354
)
5455
.then((output) => {
5556
expect(output.code).toEqual(0);
56-
expect(output.stdout.indexOf('Project is running at') >= 0).toBe(true);
57+
expect(output.stdout.includes('Project is running at')).toBe(true);
5758
done();
5859
})
5960
.catch(done);
@@ -82,6 +83,20 @@ describe('CLI', () => {
8283
.catch(done);
8384
});
8485

86+
it('--socket', (done) => {
87+
const socketPath = './webpack.sock';
88+
89+
runDevServer(`--socket ${socketPath}`)
90+
.then((output) => {
91+
expect(output.code).toEqual(0);
92+
expect(output.stdout.includes(socketPath)).toBe(true);
93+
unlink(socketPath, () => {
94+
done();
95+
});
96+
})
97+
.catch(done);
98+
});
99+
85100
it('should exit the process when SIGINT is detected', (done) => {
86101
const cliPath = path.resolve(__dirname, '../bin/webpack-dev-server.js');
87102
const examplePath = path.resolve(__dirname, '../examples/cli/public');

0 commit comments

Comments
 (0)