Skip to content

Commit efbd6e9

Browse files
committed
refactor!: remove the deprecated option server.options.cacert (#4668)
1 parent 397f621 commit efbd6e9

File tree

10 files changed

+33
-301
lines changed

10 files changed

+33
-301
lines changed

lib/Server.js

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ class Server {
10461046

10471047
const httpsProperties =
10481048
/** @type {Array<keyof ServerOptions>} */
1049-
(["cacert", "ca", "cert", "crl", "key", "pfx"]);
1049+
(["ca", "cert", "crl", "key", "pfx"]);
10501050

10511051
for (const property of httpsProperties) {
10521052
if (
@@ -1058,16 +1058,6 @@ class Server {
10581058
continue;
10591059
}
10601060

1061-
// @ts-ignore
1062-
if (property === "cacert") {
1063-
// TODO remove the `cacert` option in favor `ca` in the next major release
1064-
util.deprecate(
1065-
() => {},
1066-
"The 'cacert' option is deprecated. Please use the 'ca' option.",
1067-
"DEP_WEBPACK_DEV_SERVER_CACERT"
1068-
)();
1069-
}
1070-
10711061
/** @type {any} */
10721062
const value =
10731063
/** @type {ServerOptions} */
@@ -1226,29 +1216,6 @@ class Server {
12261216
this.logger.info(`SSL certificate: ${certificatePath}`);
12271217
}
12281218

1229-
if (
1230-
/** @type {ServerOptions & { cacert?: ServerOptions["ca"] }} */ (
1231-
options.server.options
1232-
).cacert
1233-
) {
1234-
if (/** @type {ServerOptions} */ (options.server.options).ca) {
1235-
this.logger.warn(
1236-
"Do not specify 'ca' and 'cacert' options together, the 'ca' option will be used."
1237-
);
1238-
} else {
1239-
/** @type {ServerOptions} */
1240-
(options.server.options).ca =
1241-
/** @type {ServerOptions & { cacert?: ServerOptions["ca"] }} */
1242-
(options.server.options).cacert;
1243-
}
1244-
1245-
delete (
1246-
/** @type {ServerOptions & { cacert?: ServerOptions["ca"] }} */ (
1247-
options.server.options
1248-
).cacert
1249-
);
1250-
}
1251-
12521219
/** @type {ServerOptions} */
12531220
(options.server.options).key =
12541221
/** @type {ServerOptions} */

lib/options.json

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -618,30 +618,6 @@
618618
],
619619
"description": "Path to an SSL CA certificate or content of an SSL CA certificate."
620620
},
621-
"cacert": {
622-
"anyOf": [
623-
{
624-
"type": "array",
625-
"items": {
626-
"anyOf": [
627-
{
628-
"type": "string"
629-
},
630-
{
631-
"instanceof": "Buffer"
632-
}
633-
]
634-
}
635-
},
636-
{
637-
"type": "string"
638-
},
639-
{
640-
"instanceof": "Buffer"
641-
}
642-
],
643-
"description": "Path to an SSL CA certificate or content of an SSL CA certificate. Deprecated, use the `server.options.ca` option."
644-
},
645621
"cert": {
646622
"anyOf": [
647623
{

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -555,23 +555,6 @@ exports[`options validate should throw an error on the "server" option with '{"t
555555
* options.server.options.ca should be an instance of Buffer."
556556
`;
557557

558-
exports[`options validate should throw an error on the "server" option with '{"type":"https","options":{"cacert":true}}' value 1`] = `
559-
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
560-
- options.server should be one of these:
561-
\\"http\\" | \\"https\\" | \\"spdy\\" | non-empty string | object { type?, options? }
562-
-> Allows to set server and options (by default 'http').
563-
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverserver
564-
Details:
565-
* options.server.options.cacert should be one of these:
566-
[string | Buffer, ...] | string | Buffer
567-
-> Path to an SSL CA certificate or content of an SSL CA certificate. Deprecated, use the \`server.options.ca\` option.
568-
Details:
569-
* options.server.options.cacert should be an array:
570-
[string | Buffer, ...]
571-
* options.server.options.cacert should be a string.
572-
* options.server.options.cacert should be an instance of Buffer."
573-
`;
574-
575558
exports[`options validate should throw an error on the "server" option with '{"type":"https","options":{"cert":true}}' value 1`] = `
576559
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
577560
- options.server should be one of these:

test/cli/__snapshots__/basic.test.js.snap.webpack5

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ Options:
109109
--no-server-options-request-cert Does not request for an SSL certificate.
110110
--server-options-ca <value...> Path to an SSL CA certificate or content of an SSL CA certificate.
111111
--server-options-ca-reset Clear all items provided in 'server.options.ca' configuration. Path to an SSL CA certificate or content of an SSL CA certificate.
112-
--server-options-cacert <value...> Path to an SSL CA certificate or content of an SSL CA certificate. Deprecated, use the \`server.options.ca\` option.
113-
--server-options-cacert-reset Clear all items provided in 'server.options.cacert' configuration. Path to an SSL CA certificate or content of an SSL CA certificate. Deprecated, use the \`server.options.ca\` option.
114112
--server-options-cert <value...> Path to an SSL certificate or content of an SSL certificate.
115113
--server-options-cert-reset Clear all items provided in 'server.options.cert' configuration. Path to an SSL certificate or content of an SSL certificate.
116114
--server-options-crl <value...> Path to PEM formatted CRLs (Certificate Revocation Lists) or content of PEM formatted CRLs (Certificate Revocation Lists).

test/cli/__snapshots__/server-option.test.js.snap.webpack5

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`"server" CLI options should warn using "--server-options-cacert" and "--server-options-ca" together 1`] = `
4-
"<w> [webpack-dev-server] Do not specify 'ca' and 'cacert' options together, the 'ca' option will be used.
5-
<i> [webpack-dev-server] Project is running at:
6-
<i> Loopback: https://localhost:<port>/, https://<ip-v4>:<port>/, https://[<ip-v6>]:<port>/
7-
<i> [webpack-dev-server] On Your Network (IPv4): https://<ip-v4>:<port>/
8-
<i> [webpack-dev-server] On Your Network (IPv6): https://[<ip-v6>]:<port>/
9-
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
10-
`;
11-
123
exports[`"server" CLI options should work using "--no-server-options-request-cert" 1`] = `
134
"<i> [webpack-dev-server] Generating SSL certificate...
145
<i> [webpack-dev-server] SSL certificate: <cwd>/node_modules/.cache/webpack-dev-server/server.pem
@@ -27,15 +18,15 @@ exports[`"server" CLI options should work using "--server-options-key <path> --s
2718
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
2819
`;
2920

30-
exports[`"server" CLI options should work using "--server-options-key <path> --server-options-pfx <path> --server-options-passphrase webpack-dev-server --server-options-cert <path> --server-options-cacert <path>" 1`] = `
21+
exports[`"server" CLI options should work using "--server-options-key <path> --server-options-pfx <path> --server-options-passphrase webpack-dev-server --server-options-cert <path>" 1`] = `
3122
"<i> [webpack-dev-server] Project is running at:
3223
<i> Loopback: https://localhost:<port>/, https://<ip-v4>:<port>/, https://[<ip-v6>]:<port>/
3324
<i> [webpack-dev-server] On Your Network (IPv4): https://<ip-v4>:<port>/
3425
<i> [webpack-dev-server] On Your Network (IPv6): https://[<ip-v6>]:<port>/
3526
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
3627
`;
3728

38-
exports[`"server" CLI options should work using "--server-options-key <path> --server-options-pfx <path> --server-options-passphrase webpack-dev-server --server-options-cert <path>" 1`] = `
29+
exports[`"server" CLI options should work using "--server-options-key <path> --server-options-pfx <path> --server-options-passphrase webpack-dev-server --server-options-cert <path>" 2`] = `
3930
"<i> [webpack-dev-server] Project is running at:
4031
<i> Loopback: https://localhost:<port>/, https://<ip-v4>:<port>/, https://[<ip-v6>]:<port>/
4132
<i> [webpack-dev-server] On Your Network (IPv4): https://<ip-v4>:<port>/

test/cli/server-option.test.js

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,10 @@ describe('"server" CLI options', () => {
6262
).toMatchSnapshot();
6363
});
6464

65-
it('should work using "--server-options-key <path> --server-options-pfx <path> --server-options-passphrase webpack-dev-server --server-options-cert <path> --server-options-cacert <path>"', async () => {
65+
it('should work using "--server-options-key <path> --server-options-pfx <path> --server-options-passphrase webpack-dev-server --server-options-cert <path>"', async () => {
6666
const pfxFile = path.join(httpsCertificateDirectory, "server.pfx");
6767
const key = path.join(httpsCertificateDirectory, "server.key");
6868
const cert = path.join(httpsCertificateDirectory, "server.crt");
69-
const cacert = path.join(httpsCertificateDirectory, "ca.pem");
7069
const passphrase = "webpack-dev-server";
7170

7271
const { exitCode, stderr } = await testBin([
@@ -82,8 +81,6 @@ describe('"server" CLI options', () => {
8281
passphrase,
8382
"--server-options-cert",
8483
cert,
85-
"--server-options-cacert",
86-
cacert,
8784
]);
8885

8986
expect(exitCode).toEqual(0);
@@ -156,38 +153,6 @@ describe('"server" CLI options', () => {
156153
).toMatchSnapshot();
157154
});
158155

159-
it('should warn using "--server-options-cacert" and "--server-options-ca" together', async () => {
160-
const pfxFile = path.join(httpsCertificateDirectory, "server.pfx");
161-
const key = path.join(httpsCertificateDirectory, "server.key");
162-
const cert = path.join(httpsCertificateDirectory, "server.crt");
163-
const cacert = path.join(httpsCertificateDirectory, "ca.pem");
164-
const passphrase = "webpack-dev-server";
165-
166-
const { exitCode, stderr } = await testBin([
167-
"--port",
168-
port,
169-
"--server-type",
170-
"https",
171-
"--server-options-key",
172-
key,
173-
"--server-options-pfx",
174-
pfxFile,
175-
"--server-options-passphrase",
176-
passphrase,
177-
"--server-options-cert",
178-
cert,
179-
"--server-options-cacert",
180-
cacert,
181-
"--server-options-ca",
182-
cacert,
183-
]);
184-
185-
expect(exitCode).toEqual(0);
186-
expect(
187-
normalizeStderr(stderr, { ipv6: true, https: true })
188-
).toMatchSnapshot();
189-
});
190-
191156
// For https://github.com/webpack/webpack-dev-server/issues/3306
192157
it('should work using "--server-options-key <path> --server-options-pfx <path> --server-options-passphrase webpack-dev-server --server-options-cert <path>"', async () => {
193158
const pfxFile = path.join(httpsCertificateDirectory, "server.pfx");

test/e2e/__snapshots__/server.test.js.snap.webpack5

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ exports[`server option as object ca, pfx, key and cert are array of strings shou
191191

192192
exports[`server option as object ca, pfx, key and cert are buffer should handle GET request to index route (/): console messages 1`] = `Array []`;
193193

194+
exports[`server option as object ca, pfx, key and cert are buffer should handle GET request to index route (/): console messages 2`] = `Array []`;
195+
194196
exports[`server option as object ca, pfx, key and cert are buffer should handle GET request to index route (/): https options 1`] = `
195197
Object {
196198
"ca": "<Buffer>",
@@ -202,15 +204,35 @@ Object {
202204
}
203205
`;
204206

207+
exports[`server option as object ca, pfx, key and cert are buffer should handle GET request to index route (/): https options 2`] = `
208+
Object {
209+
"ca": "<Buffer>",
210+
"cert": "<Buffer>",
211+
"key": "<Buffer>",
212+
"passphrase": "webpack-dev-server",
213+
"pfx": "<Buffer>",
214+
"requestCert": false,
215+
}
216+
`;
217+
205218
exports[`server option as object ca, pfx, key and cert are buffer should handle GET request to index route (/): page errors 1`] = `Array []`;
206219

220+
exports[`server option as object ca, pfx, key and cert are buffer should handle GET request to index route (/): page errors 2`] = `Array []`;
221+
207222
exports[`server option as object ca, pfx, key and cert are buffer should handle GET request to index route (/): response status 1`] = `200`;
208223

224+
exports[`server option as object ca, pfx, key and cert are buffer should handle GET request to index route (/): response status 2`] = `200`;
225+
209226
exports[`server option as object ca, pfx, key and cert are buffer should handle GET request to index route (/): response text 1`] = `
210227
"Heyo.
211228
"
212229
`;
213230

231+
exports[`server option as object ca, pfx, key and cert are buffer should handle GET request to index route (/): response text 2`] = `
232+
"Heyo.
233+
"
234+
`;
235+
214236
exports[`server option as object ca, pfx, key and cert are buffer, key and pfx are objects should handle GET request to index route (/): console messages 1`] = `Array []`;
215237

216238
exports[`server option as object ca, pfx, key and cert are buffer, key and pfx are objects should handle GET request to index route (/): https options 1`] = `
@@ -467,50 +489,6 @@ exports[`server option as object ca, pfx, key and cert are strings, key and pfx
467489
"
468490
`;
469491

470-
exports[`server option as object cacert and ca, pfx, key and cert are buffer should handle GET request to index route (/): console messages 1`] = `Array []`;
471-
472-
exports[`server option as object cacert and ca, pfx, key and cert are buffer should handle GET request to index route (/): https options 1`] = `
473-
Object {
474-
"ca": "<Buffer>",
475-
"cert": "<Buffer>",
476-
"key": "<Buffer>",
477-
"passphrase": "webpack-dev-server",
478-
"pfx": "<Buffer>",
479-
"requestCert": false,
480-
}
481-
`;
482-
483-
exports[`server option as object cacert and ca, pfx, key and cert are buffer should handle GET request to index route (/): page errors 1`] = `Array []`;
484-
485-
exports[`server option as object cacert and ca, pfx, key and cert are buffer should handle GET request to index route (/): response status 1`] = `200`;
486-
487-
exports[`server option as object cacert and ca, pfx, key and cert are buffer should handle GET request to index route (/): response text 1`] = `
488-
"Heyo.
489-
"
490-
`;
491-
492-
exports[`server option as object cacert, pfx, key and cert are buffer should handle GET request to index route (/): console messages 1`] = `Array []`;
493-
494-
exports[`server option as object cacert, pfx, key and cert are buffer should handle GET request to index route (/): https options 1`] = `
495-
Object {
496-
"ca": "<Buffer>",
497-
"cert": "<Buffer>",
498-
"key": "<Buffer>",
499-
"passphrase": "webpack-dev-server",
500-
"pfx": "<Buffer>",
501-
"requestCert": false,
502-
}
503-
`;
504-
505-
exports[`server option as object cacert, pfx, key and cert are buffer should handle GET request to index route (/): page errors 1`] = `Array []`;
506-
507-
exports[`server option as object cacert, pfx, key and cert are buffer should handle GET request to index route (/): response status 1`] = `200`;
508-
509-
exports[`server option as object cacert, pfx, key and cert are buffer should handle GET request to index route (/): response text 1`] = `
510-
"Heyo.
511-
"
512-
`;
513-
514492
exports[`server option as object custom server with options should handle GET request to index route (/): console messages 1`] = `Array []`;
515493

516494
exports[`server option as object custom server with options should handle GET request to index route (/): http options 1`] = `

0 commit comments

Comments
 (0)