Skip to content

Commit 437c8d3

Browse files
authored
feat: add port "auto" and remove port: null (#3297)
1 parent 670966f commit 437c8d3

File tree

6 files changed

+38
-16
lines changed

6 files changed

+38
-16
lines changed

lib/options.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@
174174
"type": "string"
175175
},
176176
{
177-
"type": "null"
177+
"enum": ["auto"]
178178
}
179179
],
180180
"description": "Tells clients connected to devServer to use the provided port."
@@ -424,7 +424,7 @@
424424
"type": "string"
425425
},
426426
{
427-
"type": "null"
427+
"enum": ["auto"]
428428
}
429429
],
430430
"description": "Specify a port number to listen for requests on. https://webpack.js.org/configuration/dev-server/#devserverport"

lib/utils/findPort.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function runPortFinder() {
1818
}
1919

2020
function findPort(port) {
21-
if (port) {
21+
if (port && port !== 'auto') {
2222
return Promise.resolve(port);
2323
}
2424

test/__snapshots__/validate-options.test.js.snap.webpack4

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ exports[`options validate should throw an error on the "client" option with '{"p
8282
exports[`options validate should throw an error on the "client" option with '{"port":true}' value 1`] = `
8383
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
8484
- configuration.client.port should be one of these:
85-
number | string | null
85+
number | string | \\"auto\\"
8686
-> Tells clients connected to devServer to use the provided port.
8787
Details:
8888
* configuration.client.port should be a number.
8989
* configuration.client.port should be a string.
90-
* configuration.client.port should be a null."
90+
* configuration.client.port should be \\"auto\\"."
9191
`;
9292

9393
exports[`options validate should throw an error on the "client" option with '{"progress":""}' value 1`] = `
@@ -361,12 +361,23 @@ exports[`options validate should throw an error on the "open" option with '{"tar
361361
exports[`options validate should throw an error on the "port" option with 'false' value 1`] = `
362362
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
363363
- configuration.port should be one of these:
364-
number | string | null
364+
number | string | \\"auto\\"
365365
-> Specify a port number to listen for requests on. https://webpack.js.org/configuration/dev-server/#devserverport
366366
Details:
367367
* configuration.port should be a number.
368368
* configuration.port should be a string.
369-
* configuration.port should be a null."
369+
* configuration.port should be \\"auto\\"."
370+
`;
371+
372+
exports[`options validate should throw an error on the "port" option with 'null' value 1`] = `
373+
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
374+
- configuration.port should be one of these:
375+
number | string | \\"auto\\"
376+
-> Specify a port number to listen for requests on. https://webpack.js.org/configuration/dev-server/#devserverport
377+
Details:
378+
* configuration.port should be a number.
379+
* configuration.port should be a string.
380+
* configuration.port should be \\"auto\\"."
370381
`;
371382

372383
exports[`options validate should throw an error on the "proxy" option with '[]' value 1`] = `

test/__snapshots__/validate-options.test.js.snap.webpack5

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ exports[`options validate should throw an error on the "client" option with '{"p
8282
exports[`options validate should throw an error on the "client" option with '{"port":true}' value 1`] = `
8383
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
8484
- configuration.client.port should be one of these:
85-
number | string | null
85+
number | string | \\"auto\\"
8686
-> Tells clients connected to devServer to use the provided port.
8787
Details:
8888
* configuration.client.port should be a number.
8989
* configuration.client.port should be a string.
90-
* configuration.client.port should be a null."
90+
* configuration.client.port should be \\"auto\\"."
9191
`;
9292

9393
exports[`options validate should throw an error on the "client" option with '{"progress":""}' value 1`] = `
@@ -361,12 +361,23 @@ exports[`options validate should throw an error on the "open" option with '{"tar
361361
exports[`options validate should throw an error on the "port" option with 'false' value 1`] = `
362362
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
363363
- configuration.port should be one of these:
364-
number | string | null
364+
number | string | \\"auto\\"
365365
-> Specify a port number to listen for requests on. https://webpack.js.org/configuration/dev-server/#devserverport
366366
Details:
367367
* configuration.port should be a number.
368368
* configuration.port should be a string.
369-
* configuration.port should be a null."
369+
* configuration.port should be \\"auto\\"."
370+
`;
371+
372+
exports[`options validate should throw an error on the "port" option with 'null' value 1`] = `
373+
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
374+
- configuration.port should be one of these:
375+
number | string | \\"auto\\"
376+
-> Specify a port number to listen for requests on. https://webpack.js.org/configuration/dev-server/#devserverport
377+
Details:
378+
* configuration.port should be a number.
379+
* configuration.port should be a string.
380+
* configuration.port should be \\"auto\\"."
370381
`;
371382

372383
exports[`options validate should throw an error on the "proxy" option with '[]' value 1`] = `

test/server/port-option.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ describe('port', () => {
7878
afterAll(testServer.close);
7979
});
8080

81-
describe('is null', () => {
81+
describe('is auto', () => {
8282
beforeAll((done) => {
8383
server = testServer.start(
8484
config,
@@ -87,7 +87,7 @@ describe('port', () => {
8787
directory: staticDirectory,
8888
watch: false,
8989
},
90-
port: null,
90+
port: 'auto',
9191
},
9292
done
9393
);

test/validate-options.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const tests = {
7070
{
7171
host: '',
7272
path: '',
73-
port: null,
73+
port: 'auto',
7474
},
7575
{
7676
progress: false,
@@ -247,8 +247,8 @@ const tests = {
247247
failure: ['', [], { foo: 'bar' }, { target: 90 }, { app: true }],
248248
},
249249
port: {
250-
success: ['', 0, null],
251-
failure: [false],
250+
success: ['', 0, 'auto'],
251+
failure: [false, null],
252252
},
253253
proxy: {
254254
success: [

0 commit comments

Comments
 (0)