Skip to content

BREAKING CHANGE: remove socket option #2669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions bin/cli-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,6 @@ module.exports = {
describe: 'Will not check the host',
group: CONNECTION_GROUP,
},
{
name: 'socket',
type: String,
describe: 'Socket to listen',
group: CONNECTION_GROUP,
},
{
name: 'public',
type: String,
Expand Down
5 changes: 0 additions & 5 deletions bin/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,6 @@ const options = {
describe: 'Will not check the host',
group: CONNECTION_GROUP,
},
socket: {
type: 'String',
describe: 'Socket to listen',
group: CONNECTION_GROUP,
},
public: {
type: 'string',
describe: 'The public hostname/ip address of the server',
Expand Down
52 changes: 5 additions & 47 deletions bin/webpack-dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

/* eslint-disable no-shadow, no-console */

const fs = require('fs');
const net = require('net');
const debug = require('debug')('webpack-dev-server');
const importLocal = require('import-local');
const yargs = require('yargs');
Expand Down Expand Up @@ -116,51 +114,11 @@ function startDevServer(config, options) {
throw err;
}

if (options.socket) {
server.listeningApp.on('error', (e) => {
if (e.code === 'EADDRINUSE') {
const clientSocket = new net.Socket();

clientSocket.on('error', (err) => {
if (err.code === 'ECONNREFUSED') {
// No other server listening on this socket so it can be safely removed
fs.unlinkSync(options.socket);

server.listen(options.socket, options.host, (error) => {
if (error) {
throw error;
}
});
}
});

clientSocket.connect({ path: options.socket }, () => {
throw new Error('This socket is already used');
});
}
});

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 {
server.listen(options.port, options.host, (err) => {
if (err) {
throw err;
}
});
}
server.listen(options.port, options.host, (err) => {
if (err) {
throw err;
}
});
}

processOptions(config, argv, (config, options) => {
Expand Down
4 changes: 0 additions & 4 deletions lib/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,6 @@
"serveIndex": {
"type": "boolean"
},
"socket": {
"type": "string"
},
"staticOptions": {
"type": "object"
},
Expand Down Expand Up @@ -376,7 +373,6 @@
"requestCert": "should be {Boolean}",
"contentBasePublicPath": "should be {String|Array} (https://webpack.js.org/configuration/dev-server/#devservercontentbasepublicpath)",
"serveIndex": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverserveindex)",
"socket": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserversocket)",
"staticOptions": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devserverstaticoptions)",
"transportMode": "should be {String|Object} (https://webpack.js.org/configuration/dev-server/#devservertransportmode)",
"useLocalIp": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserveruselocalip)",
Expand Down
4 changes: 0 additions & 4 deletions lib/utils/createConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ function createConfig(config, argv, { port }) {
options.public = argv.public;
}

if (argv.socket) {
options.socket = argv.socket;
}

if (argv.liveReload === false) {
options.liveReload = false;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/createDomain.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function createDomain(options, server) {
: options.host || 'localhost';

// eslint-disable-next-line no-nested-ternary
const port = options.socket ? 0 : server ? server.address().port : 0;
const port = server ? server.address().port : 0;
// use explicitly defined public url
// (prefix with protocol if not explicitly given)
if (options.public) {
Expand Down
26 changes: 11 additions & 15 deletions lib/utils/processOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,17 @@ function processOptions(config, argv, callback) {
// we should use portfinder.
const options = createConfig(config, argv, { port: defaultPort });

if (options.socket) {
callback(config, options);
} else {
findPort(options.port)
.then((port) => {
options.port = port;
callback(config, options);
})
.catch((err) => {
// eslint-disable-next-line no-console
console.error(err.stack || err);
// eslint-disable-next-line no-process-exit
process.exit(1);
});
}
findPort(options.port)
.then((port) => {
options.port = port;
callback(config, options);
})
.catch((err) => {
// eslint-disable-next-line no-console
console.error(err.stack || err);
// eslint-disable-next-line no-process-exit
process.exit(1);
});
}

module.exports = processOptions;
2 changes: 1 addition & 1 deletion test/__snapshots__/Validation.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ exports[`Validation validation should fail validation for invalid \`overlay\` co
exports[`Validation validation should fail validation for no additional properties 1`] = `
"Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration has an unknown property 'additional'. These properties are valid:
object { allowedHosts?, bonjour?, client?, compress?, contentBasePublicPath?, contentBase?, dev?, disableHostCheck?, headers?, historyApiFallback?, host?, hot?, http2?, https?, injectClient?, injectHot?, liveReload?, onAfterSetupMiddleware?, onBeforeSetupMiddleware?, onListening?, open?, openPage?, overlay?, port?, profile?, progress?, proxy?, public?, requestCert?, serveIndex?, socket?, staticOptions?, transportMode?, useLocalIp?, watchContentBase?, watchOptions? }"
object { allowedHosts?, bonjour?, client?, compress?, contentBasePublicPath?, contentBase?, dev?, disableHostCheck?, headers?, historyApiFallback?, host?, hot?, http2?, https?, injectClient?, injectHot?, liveReload?, onAfterSetupMiddleware?, onBeforeSetupMiddleware?, onListening?, open?, openPage?, overlay?, port?, profile?, progress?, proxy?, public?, requestCert?, serveIndex?, staticOptions?, transportMode?, useLocalIp?, watchContentBase?, watchOptions? }"
`;
24 changes: 1 addition & 23 deletions test/cli/cli.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const { unlink } = require('fs');
const { join, resolve } = require('path');
const { resolve } = require('path');
const execa = require('execa');
const testBin = require('../helpers/test-bin');

Expand Down Expand Up @@ -90,27 +89,6 @@ describe('CLI', () => {
.catch(done);
});

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

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

if (process.platform === 'win32') {
done();
} else {
expect(output.stderr).toContain(socketPath);

unlink(socketPath, () => {
done();
});
}
})
.catch(done);
});

it('should accept the promise function of webpack.config.js', (done) => {
testBin(
false,
Expand Down
1 change: 0 additions & 1 deletion test/fixtures/schema/webpack.config.no-dev-stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module.exports = {
devServer: {
host: '_foo',
public: '_public',
socket: '_socket',
progress: '_progress',
publicPath: '_publicPath',
hot: '_hot',
Expand Down
4 changes: 0 additions & 4 deletions test/options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,6 @@ describe('options', () => {
success: [true],
failure: [''],
},
socket: {
success: [''],
failure: [false],
},
staticOptions: {
success: [{}],
failure: [false],
Expand Down
22 changes: 0 additions & 22 deletions test/server/utils/__snapshots__/createConfig.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -755,28 +755,6 @@ Object {
}
`;

exports[`createConfig socket option (devServer config) 1`] = `
Object {
"dev": Object {
"publicPath": "/",
},
"hot": true,
"port": 8080,
"socket": "socket",
}
`;

exports[`createConfig socket option 1`] = `
Object {
"dev": Object {
"publicPath": "/",
},
"hot": true,
"port": 8080,
"socket": "socket",
}
`;

exports[`createConfig useLocalIp option (in devServer config) 1`] = `
Object {
"dev": Object {
Expand Down
24 changes: 0 additions & 24 deletions test/server/utils/createConfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,30 +159,6 @@ describe('createConfig', () => {
expect(config).toMatchSnapshot();
});

it('socket option', () => {
const config = createConfig(
webpackConfig,
Object.assign({}, argv, {
socket: 'socket',
}),
{ port: 8080 }
);

expect(config).toMatchSnapshot();
});

it('socket option (devServer config)', () => {
const config = createConfig(
Object.assign({}, webpackConfig, {
devServer: { socket: 'socket' },
}),
argv,
{ port: 8080 }
);

expect(config).toMatchSnapshot();
});

it('progress option', () => {
const config = createConfig(
webpackConfig,
Expand Down