Skip to content

Commit

Permalink
Merge branch 'add-live-reload-option' of https://github.com/EslamHiko…
Browse files Browse the repository at this point in the history
…/webpack-dev-server into add-live-reload-option
  • Loading branch information
EslamHiko committed May 14, 2019
2 parents 2d8c08d + 7df6693 commit 9a86d02
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 54 deletions.
14 changes: 13 additions & 1 deletion bin/webpack-dev-server.js
Expand Up @@ -192,7 +192,19 @@ function startDevServer(config, options) {
}
});

runServer();
server.listen(options.socket, options.host, (err) => {
if (err) {
throw err;
}
// chmod 666 (rw rw rw)
const READ_WRITE = 438;

fs.chmod(options.socket, READ_WRITE, (err) => {
if (err) {
throw err;
}
});
});
} else if (options.port) {
runServer();
} else {
Expand Down
46 changes: 16 additions & 30 deletions lib/Server.js
Expand Up @@ -741,6 +741,21 @@ class Server {
return false;
}

showStatus() {
const suffix =
this.options.inline !== false || this.options.lazy === true
? '/'
: '/webpack-dev-server/';
const uri = `${createDomain(this.options, this.listeningApp)}${suffix}`;

status(
uri,
this.options,
this.log,
this.options.stats && this.options.stats.colors
);
}

// delegate listen call and init sockjs
listen(port, hostname, fn) {
this.hostname = hostname;
Expand Down Expand Up @@ -820,36 +835,7 @@ class Server {
runBonjour(this.options);
}

const showStatus = () => {
const suffix =
this.options.inline !== false || this.options.lazy === true
? '/'
: '/webpack-dev-server/';

const uri = `${createDomain(this.options, this.listeningApp)}${suffix}`;

status(
uri,
this.options,
this.log,
this.options.stats && this.options.stats.colors
);
};

if (this.options.socket) {
// chmod 666 (rw rw rw)
const READ_WRITE = 438;

fs.chmod(this.options.socket, READ_WRITE, (err) => {
if (err) {
throw err;
}

showStatus();
});
} else {
showStatus();
}
this.showStatus();

if (fn) {
fn.call(this.listeningApp, err);
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -87,7 +87,7 @@
"marked": "0.6.2",
"memfs": "2.15.2",
"nyc": "14.1.1",
"prettier": "1.17.0",
"prettier": "1.17.1",
"puppeteer": "1.15.0",
"rimraf": "2.6.3",
"standard-version": "6.0.1",
Expand Down
56 changes: 37 additions & 19 deletions test/cli.test.js
Expand Up @@ -3,25 +3,23 @@
/* eslint-disable
array-bracket-spacing,
*/
const path = require('path');
const { unlink } = require('fs');
const { join, resolve } = require('path');
const execa = require('execa');
const runDevServer = require('./helpers/run-webpack-dev-server');

const httpsCertificateDirectory = path.join(
__dirname,
'fixtures/https-certificate'
);
const caPath = path.join(httpsCertificateDirectory, 'ca.pem');
const pfxPath = path.join(httpsCertificateDirectory, 'server.pfx');
const keyPath = path.join(httpsCertificateDirectory, 'server.key');
const certPath = path.join(httpsCertificateDirectory, 'server.crt');
const httpsCertificateDirectory = join(__dirname, 'fixtures/https-certificate');
const caPath = join(httpsCertificateDirectory, 'ca.pem');
const pfxPath = join(httpsCertificateDirectory, 'server.pfx');
const keyPath = join(httpsCertificateDirectory, 'server.key');
const certPath = join(httpsCertificateDirectory, 'server.crt');

describe('CLI', () => {
it('--progress', (done) => {
runDevServer('--progress')
.then((output) => {
expect(output.code).toEqual(0);
expect(output.stderr.indexOf('0% compiling') >= 0).toBe(true);
expect(output.stderr.includes('0% compiling')).toBe(true);
done();
})
.catch(done);
Expand All @@ -31,7 +29,7 @@ describe('CLI', () => {
runDevServer('--bonjour')
.then((output) => {
expect(output.code).toEqual(0);
expect(output.stdout.indexOf('Bonjour') >= 0).toBe(true);
expect(output.stdout.includes('Bonjour')).toBe(true);
done();
})
.catch(done);
Expand All @@ -41,7 +39,7 @@ describe('CLI', () => {
runDevServer('--https')
.then((output) => {
expect(output.code).toEqual(0);
expect(output.stdout.indexOf('Project is running at') >= 0).toBe(true);
expect(output.stdout.includes('Project is running at')).toBe(true);
done();
})
.catch(done);
Expand All @@ -53,7 +51,7 @@ describe('CLI', () => {
)
.then((output) => {
expect(output.code).toEqual(0);
expect(output.stdout.indexOf('Project is running at') >= 0).toBe(true);
expect(output.stdout.includes('Project is running at')).toBe(true);
done();
})
.catch(done);
Expand Down Expand Up @@ -82,9 +80,29 @@ describe('CLI', () => {
.catch(done);
});

// The Unix socket to listen to (instead of a host).
it('--socket', (done) => {
const socketPath = join('.', 'webpack.sock');

runDevServer(`--socket ${socketPath}`)
.then((output) => {
expect(output.code).toEqual(0);

if (process.platform === 'win32') {
done();
} else {
expect(output.stdout.includes(socketPath)).toBe(true);
unlink(socketPath, () => {
done();
});
}
})
.catch(done);
});

it('should exit the process when SIGINT is detected', (done) => {
const cliPath = path.resolve(__dirname, '../bin/webpack-dev-server.js');
const examplePath = path.resolve(__dirname, '../examples/cli/public');
const cliPath = resolve(__dirname, '../bin/webpack-dev-server.js');
const examplePath = resolve(__dirname, '../examples/cli/public');
const cp = execa('node', [cliPath], { cwd: examplePath });

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

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

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

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

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

0 comments on commit 9a86d02

Please sign in to comment.