Skip to content
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

feat: add port auto #3297

Merged
merged 3 commits into from
May 15, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
"type": "string"
},
{
"type": "null"
"enum": ["auto"]
}
],
"description": "Tells clients connected to devServer to use the provided port."
Expand Down Expand Up @@ -424,7 +424,7 @@
"type": "string"
},
{
"type": "null"
"enum": ["auto"]
}
],
"description": "Specify a port number to listen for requests on. https://webpack.js.org/configuration/dev-server/#devserverport"
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/findPort.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function runPortFinder() {
}

function findPort(port) {
if (port) {
if (port && port !== 'auto') {
return Promise.resolve(port);
}

Expand Down
19 changes: 15 additions & 4 deletions test/__snapshots__/validate-options.test.js.snap.webpack4
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ exports[`options validate should throw an error on the "client" option with '{"p
exports[`options validate should throw an error on the "client" option with '{"port":true}' value 1`] = `
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.client.port should be one of these:
number | string | null
number | string | \\"auto\\"
-> Tells clients connected to devServer to use the provided port.
Details:
* configuration.client.port should be a number.
* configuration.client.port should be a string.
* configuration.client.port should be a null."
* configuration.client.port should be \\"auto\\"."
`;

exports[`options validate should throw an error on the "client" option with '{"progress":""}' value 1`] = `
Expand Down Expand Up @@ -361,12 +361,23 @@ exports[`options validate should throw an error on the "open" option with '{"tar
exports[`options validate should throw an error on the "port" option with 'false' value 1`] = `
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.port should be one of these:
number | string | null
number | string | \\"auto\\"
-> Specify a port number to listen for requests on. https://webpack.js.org/configuration/dev-server/#devserverport
Details:
* configuration.port should be a number.
* configuration.port should be a string.
* configuration.port should be a null."
* configuration.port should be \\"auto\\"."
`;

exports[`options validate should throw an error on the "port" option with 'null' value 1`] = `
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.port should be one of these:
number | string | \\"auto\\"
-> Specify a port number to listen for requests on. https://webpack.js.org/configuration/dev-server/#devserverport
Details:
* configuration.port should be a number.
* configuration.port should be a string.
* configuration.port should be \\"auto\\"."
`;

exports[`options validate should throw an error on the "proxy" option with '[]' value 1`] = `
Expand Down
19 changes: 15 additions & 4 deletions test/__snapshots__/validate-options.test.js.snap.webpack5
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ exports[`options validate should throw an error on the "client" option with '{"p
exports[`options validate should throw an error on the "client" option with '{"port":true}' value 1`] = `
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.client.port should be one of these:
number | string | null
number | string | \\"auto\\"
-> Tells clients connected to devServer to use the provided port.
Details:
* configuration.client.port should be a number.
* configuration.client.port should be a string.
* configuration.client.port should be a null."
* configuration.client.port should be \\"auto\\"."
`;

exports[`options validate should throw an error on the "client" option with '{"progress":""}' value 1`] = `
Expand Down Expand Up @@ -361,12 +361,23 @@ exports[`options validate should throw an error on the "open" option with '{"tar
exports[`options validate should throw an error on the "port" option with 'false' value 1`] = `
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.port should be one of these:
number | string | null
number | string | \\"auto\\"
-> Specify a port number to listen for requests on. https://webpack.js.org/configuration/dev-server/#devserverport
Details:
* configuration.port should be a number.
* configuration.port should be a string.
* configuration.port should be a null."
* configuration.port should be \\"auto\\"."
`;

exports[`options validate should throw an error on the "port" option with 'null' value 1`] = `
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.port should be one of these:
number | string | \\"auto\\"
-> Specify a port number to listen for requests on. https://webpack.js.org/configuration/dev-server/#devserverport
Details:
* configuration.port should be a number.
* configuration.port should be a string.
* configuration.port should be \\"auto\\"."
`;

exports[`options validate should throw an error on the "proxy" option with '[]' value 1`] = `
Expand Down
4 changes: 2 additions & 2 deletions test/server/port-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('port', () => {
afterAll(testServer.close);
});

describe('is null', () => {
describe('is auto', () => {
beforeAll((done) => {
server = testServer.start(
config,
Expand All @@ -87,7 +87,7 @@ describe('port', () => {
directory: staticDirectory,
watch: false,
},
port: null,
port: 'auto',
},
done
);
Expand Down
6 changes: 3 additions & 3 deletions test/validate-options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const tests = {
{
host: '',
path: '',
port: null,
port: 'auto',
},
{
progress: false,
Expand Down Expand Up @@ -247,8 +247,8 @@ const tests = {
failure: ['', [], { foo: 'bar' }, { target: 90 }, { app: true }],
},
port: {
success: ['', 0, null],
failure: [false],
success: ['', 0, 'auto'],
failure: [false, null],
},
proxy: {
success: [
Expand Down