Skip to content

Commit 9a86d02

Browse files
committed
Merge branch 'add-live-reload-option' of https://github.com/EslamHiko/webpack-dev-server into add-live-reload-option
2 parents 2d8c08d + 7df6693 commit 9a86d02

File tree

5 files changed

+70
-54
lines changed

5 files changed

+70
-54
lines changed

bin/webpack-dev-server.js

+13-1
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

+16-30
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;
@@ -820,36 +835,7 @@ class Server {
820835
runBonjour(this.options);
821836
}
822837

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

854840
if (fn) {
855841
fn.call(this.listeningApp, err);

package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"marked": "0.6.2",
8888
"memfs": "2.15.2",
8989
"nyc": "14.1.1",
90-
"prettier": "1.17.0",
90+
"prettier": "1.17.1",
9191
"puppeteer": "1.15.0",
9292
"rimraf": "2.6.3",
9393
"standard-version": "6.0.1",

test/cli.test.js

+37-19
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,23 @@
33
/* eslint-disable
44
array-bracket-spacing,
55
*/
6-
const path = require('path');
6+
const { unlink } = require('fs');
7+
const { join, resolve } = require('path');
78
const execa = require('execa');
89
const runDevServer = require('./helpers/run-webpack-dev-server');
910

10-
const httpsCertificateDirectory = path.join(
11-
__dirname,
12-
'fixtures/https-certificate'
13-
);
14-
const caPath = path.join(httpsCertificateDirectory, 'ca.pem');
15-
const pfxPath = path.join(httpsCertificateDirectory, 'server.pfx');
16-
const keyPath = path.join(httpsCertificateDirectory, 'server.key');
17-
const certPath = path.join(httpsCertificateDirectory, 'server.crt');
11+
const httpsCertificateDirectory = join(__dirname, 'fixtures/https-certificate');
12+
const caPath = join(httpsCertificateDirectory, 'ca.pem');
13+
const pfxPath = join(httpsCertificateDirectory, 'server.pfx');
14+
const keyPath = join(httpsCertificateDirectory, 'server.key');
15+
const certPath = join(httpsCertificateDirectory, 'server.crt');
1816

1917
describe('CLI', () => {
2018
it('--progress', (done) => {
2119
runDevServer('--progress')
2220
.then((output) => {
2321
expect(output.code).toEqual(0);
24-
expect(output.stderr.indexOf('0% compiling') >= 0).toBe(true);
22+
expect(output.stderr.includes('0% compiling')).toBe(true);
2523
done();
2624
})
2725
.catch(done);
@@ -31,7 +29,7 @@ describe('CLI', () => {
3129
runDevServer('--bonjour')
3230
.then((output) => {
3331
expect(output.code).toEqual(0);
34-
expect(output.stdout.indexOf('Bonjour') >= 0).toBe(true);
32+
expect(output.stdout.includes('Bonjour')).toBe(true);
3533
done();
3634
})
3735
.catch(done);
@@ -41,7 +39,7 @@ describe('CLI', () => {
4139
runDevServer('--https')
4240
.then((output) => {
4341
expect(output.code).toEqual(0);
44-
expect(output.stdout.indexOf('Project is running at') >= 0).toBe(true);
42+
expect(output.stdout.includes('Project is running at')).toBe(true);
4543
done();
4644
})
4745
.catch(done);
@@ -53,7 +51,7 @@ describe('CLI', () => {
5351
)
5452
.then((output) => {
5553
expect(output.code).toEqual(0);
56-
expect(output.stdout.indexOf('Project is running at') >= 0).toBe(true);
54+
expect(output.stdout.includes('Project is running at')).toBe(true);
5755
done();
5856
})
5957
.catch(done);
@@ -82,9 +80,29 @@ describe('CLI', () => {
8280
.catch(done);
8381
});
8482

83+
// The Unix socket to listen to (instead of a host).
84+
it('--socket', (done) => {
85+
const socketPath = join('.', 'webpack.sock');
86+
87+
runDevServer(`--socket ${socketPath}`)
88+
.then((output) => {
89+
expect(output.code).toEqual(0);
90+
91+
if (process.platform === 'win32') {
92+
done();
93+
} else {
94+
expect(output.stdout.includes(socketPath)).toBe(true);
95+
unlink(socketPath, () => {
96+
done();
97+
});
98+
}
99+
})
100+
.catch(done);
101+
});
102+
85103
it('should exit the process when SIGINT is detected', (done) => {
86-
const cliPath = path.resolve(__dirname, '../bin/webpack-dev-server.js');
87-
const examplePath = path.resolve(__dirname, '../examples/cli/public');
104+
const cliPath = resolve(__dirname, '../bin/webpack-dev-server.js');
105+
const examplePath = resolve(__dirname, '../examples/cli/public');
88106
const cp = execa('node', [cliPath], { cwd: examplePath });
89107

90108
cp.stdout.on('data', (data) => {
@@ -101,8 +119,8 @@ describe('CLI', () => {
101119
});
102120

103121
it('should exit the process when SIGINT is detected, even before the compilation is done', (done) => {
104-
const cliPath = path.resolve(__dirname, '../bin/webpack-dev-server.js');
105-
const examplePath = path.resolve(__dirname, '../examples/cli/public');
122+
const cliPath = resolve(__dirname, '../bin/webpack-dev-server.js');
123+
const examplePath = resolve(__dirname, '../examples/cli/public');
106124
const cp = execa('node', [cliPath], { cwd: examplePath });
107125
let killed = false;
108126

@@ -120,8 +138,8 @@ describe('CLI', () => {
120138
});
121139

122140
it('should use different random port when multiple instances are started on different processes', (done) => {
123-
const cliPath = path.resolve(__dirname, '../bin/webpack-dev-server.js');
124-
const examplePath = path.resolve(__dirname, '../examples/cli/public');
141+
const cliPath = resolve(__dirname, '../bin/webpack-dev-server.js');
142+
const examplePath = resolve(__dirname, '../examples/cli/public');
125143

126144
const cp = execa('node', [cliPath], { cwd: examplePath });
127145
const cp2 = execa('node', [cliPath], { cwd: examplePath });

0 commit comments

Comments
 (0)