From 1dd0e3c691c38c9223dee325615867582e4975d9 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" Date: Mon, 13 May 2019 16:26:25 +0100 Subject: [PATCH 1/2] chore(deps): update dependency prettier to v1.17.1 (#1868) --- package-lock.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 91ade8d6c9..d5dbcf49ab 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9181,9 +9181,9 @@ "dev": true }, "prettier": { - "version": "1.17.0", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.17.0.tgz", - "integrity": "sha512-sXe5lSt2WQlCbydGETgfm1YBShgOX4HxQkFPvbxkcwgDvGDeqVau8h+12+lmSVlP3rHPz0oavfddSZg/q+Szjw==", + "version": "1.17.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.17.1.tgz", + "integrity": "sha512-TzGRNvuUSmPgwivDqkZ9tM/qTGW9hqDKWOE9YHiyQdixlKbv7kvEqsmDPrcHJTKwthU774TQwZXVtaQ/mMsvjg==", "dev": true }, "prettier-linter-helpers": { diff --git a/package.json b/package.json index aecbd43e13..4cc8a9905b 100644 --- a/package.json +++ b/package.json @@ -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", From 0538e6116b4e43a8d620bb49b633fdd8027eeb23 Mon Sep 17 00:00:00 2001 From: Yuta Hiroto Date: Tue, 14 May 2019 10:51:42 +0100 Subject: [PATCH 2/2] refactor: put socket processing back to /bin (#1869) --- bin/webpack-dev-server.js | 14 +++++++++- lib/Server.js | 46 +++++++++++--------------------- test/cli.test.js | 56 ++++++++++++++++++++++++++------------- 3 files changed, 66 insertions(+), 50 deletions(-) diff --git a/bin/webpack-dev-server.js b/bin/webpack-dev-server.js index 8001c4f57f..898190df52 100755 --- a/bin/webpack-dev-server.js +++ b/bin/webpack-dev-server.js @@ -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 { diff --git a/lib/Server.js b/lib/Server.js index 2c5ef5f402..ef4bd2a5f4 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -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; @@ -816,36 +831,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); diff --git a/test/cli.test.js b/test/cli.test.js index 69b2128169..5f65afaac4 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -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); @@ -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); @@ -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); @@ -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); @@ -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) => { @@ -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; @@ -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 });