Skip to content

Commit d6b5674

Browse files
committed
fix(Server): return socket processing to bin
1 parent 8a326ff commit d6b5674

File tree

3 files changed

+37
-34
lines changed

3 files changed

+37
-34
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: 8 additions & 3 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');
@@ -83,11 +84,15 @@ describe('CLI', () => {
8384
});
8485

8586
it('--socket', (done) => {
86-
runDevServer('--socket ./webpack.sock')
87+
const socketPath = './webpack.sock';
88+
89+
runDevServer(`--socket ${socketPath}`)
8790
.then((output) => {
8891
expect(output.code).toEqual(0);
89-
expect(output.stdout.includes('./webpack.sock')).toBe(true);
90-
done();
92+
expect(output.stdout.includes(socketPath)).toBe(true);
93+
unlink(socketPath, () => {
94+
done();
95+
});
9196
})
9297
.catch(done);
9398
});

0 commit comments

Comments
 (0)