From a0936e3d1beb5247e73d0b6b9a5bbb981ac37985 Mon Sep 17 00:00:00 2001 From: neverland Date: Fri, 2 Oct 2026 22:48:31 +0800 Subject: [PATCH 1/4] feat!: remove legacy selfsigned days option --- README.md | 8 ++++---- src/index.ts | 9 +-------- src/util.ts | 5 ++--- test/selfsigned-options/index.test.ts | 21 ++++++++++++++++++--- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index daefa2f..fec8a14 100644 --- a/README.md +++ b/README.md @@ -87,14 +87,14 @@ pluginBasicSsl({ Options passing to `selfsigned`, see [selfsigned - Options](https://github.com/jfromaniello/selfsigned?tab=readme-ov-file#options) for details. -In addition, the plugin supports a `days` option to set the validity period of the certificate. It is converted to `notAfterDate` and ignored if `notAfterDate` is set. +Use `notAfterDate` to set the certificate's expiration date. The legacy `days` option is no longer supported. -- **Type:** `SelfsignedOptions & { days?: number }` +- **Type:** `SelfsignedOptions` - **Default:** ```ts const defaultOptions = { - days: 30, + notAfterDate: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000), keySize: 2048, }; ``` @@ -104,7 +104,7 @@ const defaultOptions = { ```ts pluginBasicSsl({ selfsignedOptions: { - days: 100, + notAfterDate: new Date(Date.now() + 100 * 24 * 60 * 60 * 1000), }, }); ``` diff --git a/src/index.ts b/src/index.ts index 32d3264..dc17f97 100644 --- a/src/index.ts +++ b/src/index.ts @@ -22,14 +22,7 @@ export type PluginBasicSslOptions = { /** * Options passing to `selfsigned`. */ - selfsignedOptions?: SelfsignedOptions & { - /** - * Validity period of the certificate in days. - * Ignored if `notAfterDate` is set. - * @default 30 - */ - days?: number; - }; + selfsignedOptions?: SelfsignedOptions; }; export const pluginBasicSsl = ( diff --git a/src/util.ts b/src/util.ts index 8ae7f5e..e294f01 100644 --- a/src/util.ts +++ b/src/util.ts @@ -46,11 +46,10 @@ export const resolveHttpsConfig = async ( options.filename ?? 'fake-cert.pem', ); - const { days = 30, ...restOptions } = options.selfsignedOptions ?? {}; const selfsignedOptions = { keySize: 2048, - notAfterDate: new Date(Date.now() + days * 24 * 60 * 60 * 1000), - ...restOptions, + notAfterDate: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000), + ...options.selfsignedOptions, }; if (fs.existsSync(certPath)) { diff --git a/test/selfsigned-options/index.test.ts b/test/selfsigned-options/index.test.ts index 84d2f21..6bd39f0 100644 --- a/test/selfsigned-options/index.test.ts +++ b/test/selfsigned-options/index.test.ts @@ -1,3 +1,6 @@ +import { X509Certificate } from 'node:crypto'; +import { mkdtemp, readFile, rm } from 'node:fs/promises'; +import { tmpdir } from 'node:os'; import { dirname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; import { expect, test } from '@rstest/playwright'; @@ -6,14 +9,23 @@ import { pluginBasicSsl } from '../../dist'; const __dirname = dirname(fileURLToPath(import.meta.url)); -test('should print HTTPS server URLs when custom selfsigned options', async () => { +test('should apply a custom certificate expiration date', async ({ + onTestFinished, +}) => { + const outputPath = await mkdtemp(join(tmpdir(), 'rsbuild-basic-ssl-')); + const notAfterDate = new Date(Date.now() + 24 * 60 * 60 * 1000); + // X.509 certificate timestamps have second precision. + notAfterDate.setMilliseconds(0); + onTestFinished(() => rm(outputPath, { recursive: true, force: true })); + const rsbuild = await createRsbuild({ cwd: __dirname, rsbuildConfig: { plugins: [ pluginBasicSsl({ + outputPath, selfsignedOptions: { - days: 1, + notAfterDate, }, }), ], @@ -24,6 +36,7 @@ test('should print HTTPS server URLs when custom selfsigned options', async () = }); const { server, urls } = await rsbuild.startDevServer(); + onTestFinished(() => server.close()); await new Promise((resolve) => { rsbuild.onDevCompileDone(resolve); @@ -31,5 +44,7 @@ test('should print HTTPS server URLs when custom selfsigned options', async () = expect(urls.every((url) => url.startsWith('https'))).toBeTruthy(); - await server.close(); + const content = await readFile(join(outputPath, 'fake-cert.pem'), 'utf-8'); + const certificate = new X509Certificate(content); + expect(new Date(certificate.validTo).getTime()).toBe(notAfterDate.getTime()); }); From e8f9eed87802fec455cebf1d4bcac241ed5f88e8 Mon Sep 17 00:00:00 2001 From: neverland Date: Fri, 2 Oct 2026 23:09:12 +0800 Subject: [PATCH 2/4] docs: focus certificate options on current usage --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fec8a14..bfb27bd 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ pluginBasicSsl({ Options passing to `selfsigned`, see [selfsigned - Options](https://github.com/jfromaniello/selfsigned?tab=readme-ov-file#options) for details. -Use `notAfterDate` to set the certificate's expiration date. The legacy `days` option is no longer supported. +Use `notAfterDate` to set the certificate's expiration date. - **Type:** `SelfsignedOptions` - **Default:** From ce42482aadfef056f19a6441367d791e1ad9d400 Mon Sep 17 00:00:00 2001 From: neverland Date: Sat, 3 Oct 2026 09:30:16 +0800 Subject: [PATCH 3/4] docs: remove redundant expiration guidance --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index bfb27bd..8edaada 100644 --- a/README.md +++ b/README.md @@ -87,8 +87,6 @@ pluginBasicSsl({ Options passing to `selfsigned`, see [selfsigned - Options](https://github.com/jfromaniello/selfsigned?tab=readme-ov-file#options) for details. -Use `notAfterDate` to set the certificate's expiration date. - - **Type:** `SelfsignedOptions` - **Default:** From 59a83835300908bce4b8b73ede0c8008289d5f88 Mon Sep 17 00:00:00 2001 From: neverland Date: Sat, 3 Oct 2026 09:31:32 +0800 Subject: [PATCH 4/4] test: simplify selfsigned option migration --- test/selfsigned-options/index.test.ts | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/test/selfsigned-options/index.test.ts b/test/selfsigned-options/index.test.ts index 6bd39f0..8e9ddcb 100644 --- a/test/selfsigned-options/index.test.ts +++ b/test/selfsigned-options/index.test.ts @@ -1,6 +1,3 @@ -import { X509Certificate } from 'node:crypto'; -import { mkdtemp, readFile, rm } from 'node:fs/promises'; -import { tmpdir } from 'node:os'; import { dirname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; import { expect, test } from '@rstest/playwright'; @@ -9,23 +6,14 @@ import { pluginBasicSsl } from '../../dist'; const __dirname = dirname(fileURLToPath(import.meta.url)); -test('should apply a custom certificate expiration date', async ({ - onTestFinished, -}) => { - const outputPath = await mkdtemp(join(tmpdir(), 'rsbuild-basic-ssl-')); - const notAfterDate = new Date(Date.now() + 24 * 60 * 60 * 1000); - // X.509 certificate timestamps have second precision. - notAfterDate.setMilliseconds(0); - onTestFinished(() => rm(outputPath, { recursive: true, force: true })); - +test('should print HTTPS server URLs when custom selfsigned options', async () => { const rsbuild = await createRsbuild({ cwd: __dirname, rsbuildConfig: { plugins: [ pluginBasicSsl({ - outputPath, selfsignedOptions: { - notAfterDate, + notAfterDate: new Date(Date.now() + 24 * 60 * 60 * 1000), }, }), ], @@ -36,7 +24,6 @@ test('should apply a custom certificate expiration date', async ({ }); const { server, urls } = await rsbuild.startDevServer(); - onTestFinished(() => server.close()); await new Promise((resolve) => { rsbuild.onDevCompileDone(resolve); @@ -44,7 +31,5 @@ test('should apply a custom certificate expiration date', async ({ expect(urls.every((url) => url.startsWith('https'))).toBeTruthy(); - const content = await readFile(join(outputPath, 'fake-cert.pem'), 'utf-8'); - const certificate = new X509Certificate(content); - expect(new Date(certificate.validTo).getTime()).toBe(notAfterDate.getTime()); + await server.close(); });