diff --git a/.github/renovate.json5 b/.github/renovate.json5 index 7fb2dd9..61cde5e 100644 --- a/.github/renovate.json5 +++ b/.github/renovate.json5 @@ -1,4 +1,4 @@ { - "$schema": "https://docs.renovatebot.com/renovate-schema.json", - "extends": ["github>rstackjs/renovate"] + $schema: 'https://docs.renovatebot.com/renovate-schema.json', + extends: ['github>rstackjs/renovate'], } diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 08b22a6..bf7e4b8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,7 +5,7 @@ on: # Run `npm run bump` to bump the version and create a git tag. push: tags: - - "v*" + - 'v*' workflow_dispatch: @@ -46,4 +46,4 @@ jobs: - name: Create GitHub Release uses: ncipollo/release-action@339a81892b84b4eeb0f6e744e4574d79d0d9b8dd # v1 with: - generateReleaseNotes: "true" + generateReleaseNotes: 'true' diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 58944cf..ca395b5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,7 +30,7 @@ jobs: uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6 with: node-version: 24.15.0 - cache: "pnpm" + cache: 'pnpm' - name: Install Dependencies run: pnpm install && npx playwright install diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..79e4884 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,3 @@ +# Ignore artifacts: +dist +pnpm-lock.yaml diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..544138b --- /dev/null +++ b/.prettierrc @@ -0,0 +1,3 @@ +{ + "singleQuote": true +} diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 699ed73..f172f18 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,3 +1,3 @@ { - "recommendations": ["biomejs.biome"] + "recommendations": ["rstack.rslint", "esbenp.prettier-vscode"] } diff --git a/.vscode/settings.json b/.vscode/settings.json index 8008c76..d360af2 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,15 +1,4 @@ { "search.useIgnoreFiles": true, - "[json]": { - "editor.defaultFormatter": "biomejs.biome" - }, - "[typescript]": { - "editor.defaultFormatter": "biomejs.biome" - }, - "[javascript]": { - "editor.defaultFormatter": "biomejs.biome" - }, - "[javascriptreact]": { - "editor.defaultFormatter": "biomejs.biome" - } + "cSpell.words": ["rslint"] } diff --git a/README.md b/README.md index dc481e1..2be1d6f 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Add plugin to your `rsbuild.config.ts`: ```ts // rsbuild.config.ts -import { pluginBasicSsl } from "@rsbuild/plugin-basic-ssl"; +import { pluginBasicSsl } from '@rsbuild/plugin-basic-ssl'; export default { plugins: [pluginBasicSsl()], @@ -44,7 +44,7 @@ Filename of the generated certificate. ```ts pluginBasicSsl({ - filename: "foo.pem", + filename: 'foo.pem', }); ``` @@ -57,10 +57,10 @@ Output path of the generated certificate. - **Example:** ```ts -import path from "node:path"; +import path from 'node:path'; pluginBasicSsl({ - outputPath: path.join(__dirname, "node_modules/.cache/cert"), + outputPath: path.join(__dirname, 'node_modules/.cache/cert'), }); ``` @@ -72,14 +72,14 @@ Attributes passing to `selfsigned`, see [selfsigned](https://github.com/jfromani - **Default:** ```ts -const defaultAttrs = [{ name: "commonName", value: "localhost" }]; +const defaultAttrs = [{ name: 'commonName', value: 'localhost' }]; ``` - **Example:** ```ts pluginBasicSsl({ - selfsignedAttrs: [{ name: "commonName", value: "example.com" }], + selfsignedAttrs: [{ name: 'commonName', value: 'example.com' }], }); ``` diff --git a/biome.json b/biome.json deleted file mode 100644 index c569af9..0000000 --- a/biome.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "$schema": "https://biomejs.dev/schemas/1.8.3/schema.json", - "organizeImports": { - "enabled": true - }, - "vcs": { - "enabled": true, - "defaultBranch": "main", - "clientKind": "git", - "useIgnoreFile": true - }, - "javascript": { - "formatter": { - "quoteStyle": "single" - } - }, - "linter": { - "enabled": true, - "rules": { - "recommended": true - } - } -} diff --git a/package.json b/package.json index 9cd9a48..3313995 100644 --- a/package.json +++ b/package.json @@ -20,31 +20,26 @@ "scripts": { "build": "rslib", "dev": "rslib -w", - "lint": "biome check .", - "lint:write": "biome check . --write", - "prepare": "simple-git-hooks && npm run build", + "lint": "rslint && prettier -c .", + "lint:write": "rslint --fix && prettier -w .", + "prepare": "simple-git-hooks && pnpm run build", "test": "playwright test", - "bump": "npx bumpp" + "bump": "pnpx bumpp" }, "simple-git-hooks": { - "pre-commit": "npx nano-staged" - }, - "nano-staged": { - "*.{js,jsx,ts,tsx,mjs,cjs}": [ - "biome check --write --no-errors-on-unmatched" - ] + "pre-commit": "pnpm run lint:write" }, "dependencies": { "selfsigned": "^3.0.1" }, "devDependencies": { - "@biomejs/biome": "^1.9.4", "@playwright/test": "^1.59.1", "@rsbuild/core": "1.7.5", "@rslib/core": "^0.21.3", + "@rslint/core": "^0.5.0", "@types/node": "^24.12.2", - "nano-staged": "^1.0.2", "playwright": "^1.59.1", + "prettier": "^3.8.3", "simple-git-hooks": "^2.13.1", "typescript": "6.0.3" }, diff --git a/playground/package.json b/playground/package.json index 0697e8b..ac46698 100644 --- a/playground/package.json +++ b/playground/package.json @@ -1,9 +1,9 @@ { - "name": "playground", - "private": true, - "version": "0.0.0", - "scripts": { - "dev": "npx rsbuild", - "build": "npx rsbuild build" - } + "name": "playground", + "private": true, + "version": "0.0.0", + "scripts": { + "dev": "npx rsbuild", + "build": "npx rsbuild build" + } } diff --git a/playground/rsbuild.config.ts b/playground/rsbuild.config.ts index 2e08c5b..be92f6a 100644 --- a/playground/rsbuild.config.ts +++ b/playground/rsbuild.config.ts @@ -2,5 +2,5 @@ import { defineConfig } from '@rsbuild/core'; import { pluginBasicSsl } from '../src'; export default defineConfig({ - plugins: [pluginBasicSsl()], + plugins: [pluginBasicSsl()], }); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cc2d395..3a62d10 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,9 +12,6 @@ importers: specifier: ^3.0.1 version: 3.0.1 devDependencies: - '@biomejs/biome': - specifier: ^1.9.4 - version: 1.9.4 '@playwright/test': specifier: ^1.59.1 version: 1.59.1 @@ -24,15 +21,18 @@ importers: '@rslib/core': specifier: ^0.21.3 version: 0.21.3(core-js@3.47.0)(typescript@6.0.3) + '@rslint/core': + specifier: ^0.5.0 + version: 0.5.1(jiti@2.6.1) '@types/node': specifier: ^24.12.2 version: 24.12.2 - nano-staged: - specifier: ^1.0.2 - version: 1.0.2 playwright: specifier: ^1.59.1 version: 1.59.1 + prettier: + specifier: ^3.8.3 + version: 3.8.3 simple-git-hooks: specifier: ^2.13.1 version: 2.13.1 @@ -104,63 +104,6 @@ packages: resolution: {integrity: sha512-Hb4o6h1Pf6yRUAX07DR4JVY7dmQw+RVQMW5/m55GoiAT/VRoKCWBtIUPPOnqDVhbx1Cjfil9b6EDrgJsUAujEQ==} engines: {node: '>= 10'} - '@biomejs/biome@1.9.4': - resolution: {integrity: sha512-1rkd7G70+o9KkTn5KLmDYXihGoTaIGO9PIIN2ZB7UJxFrWw04CZHPYiMRjYsaDvVV7hP1dYNRLxSANLaBFGpog==} - engines: {node: '>=14.21.3'} - hasBin: true - - '@biomejs/cli-darwin-arm64@1.9.4': - resolution: {integrity: sha512-bFBsPWrNvkdKrNCYeAp+xo2HecOGPAy9WyNyB/jKnnedgzl4W4Hb9ZMzYNbf8dMCGmUdSavlYHiR01QaYR58cw==} - engines: {node: '>=14.21.3'} - cpu: [arm64] - os: [darwin] - - '@biomejs/cli-darwin-x64@1.9.4': - resolution: {integrity: sha512-ngYBh/+bEedqkSevPVhLP4QfVPCpb+4BBe2p7Xs32dBgs7rh9nY2AIYUL6BgLw1JVXV8GlpKmb/hNiuIxfPfZg==} - engines: {node: '>=14.21.3'} - cpu: [x64] - os: [darwin] - - '@biomejs/cli-linux-arm64-musl@1.9.4': - resolution: {integrity: sha512-v665Ct9WCRjGa8+kTr0CzApU0+XXtRgwmzIf1SeKSGAv+2scAlW6JR5PMFo6FzqqZ64Po79cKODKf3/AAmECqA==} - engines: {node: '>=14.21.3'} - cpu: [arm64] - os: [linux] - libc: [musl] - - '@biomejs/cli-linux-arm64@1.9.4': - resolution: {integrity: sha512-fJIW0+LYujdjUgJJuwesP4EjIBl/N/TcOX3IvIHJQNsAqvV2CHIogsmA94BPG6jZATS4Hi+xv4SkBBQSt1N4/g==} - engines: {node: '>=14.21.3'} - cpu: [arm64] - os: [linux] - libc: [glibc] - - '@biomejs/cli-linux-x64-musl@1.9.4': - resolution: {integrity: sha512-gEhi/jSBhZ2m6wjV530Yy8+fNqG8PAinM3oV7CyO+6c3CEh16Eizm21uHVsyVBEB6RIM8JHIl6AGYCv6Q6Q9Tg==} - engines: {node: '>=14.21.3'} - cpu: [x64] - os: [linux] - libc: [musl] - - '@biomejs/cli-linux-x64@1.9.4': - resolution: {integrity: sha512-lRCJv/Vi3Vlwmbd6K+oQ0KhLHMAysN8lXoCI7XeHlxaajk06u7G+UsFSO01NAs5iYuWKmVZjmiOzJ0OJmGsMwg==} - engines: {node: '>=14.21.3'} - cpu: [x64] - os: [linux] - libc: [glibc] - - '@biomejs/cli-win32-arm64@1.9.4': - resolution: {integrity: sha512-tlbhLk+WXZmgwoIKwHIHEBZUwxml7bRJgk0X2sPyNR3S93cdRq6XulAZRQJ17FYGGzWne0fgrXBKpl7l4M87Hg==} - engines: {node: '>=14.21.3'} - cpu: [arm64] - os: [win32] - - '@biomejs/cli-win32-x64@1.9.4': - resolution: {integrity: sha512-8Y5wMhVIPaWe6jw2H+KlEm4wP/f7EW3810ZLmDlrEEy5KvBsb9ECEfu/kMWD484ijfQ8+nIi0giMgu9g1UAuuA==} - engines: {node: '>=14.21.3'} - cpu: [x64] - os: [win32] - '@emnapi/core@1.10.0': resolution: {integrity: sha512-yq6OkJ4p82CAfPl0u9mQebQHKPJkY7WrIuk205cTYnYe+k2Z8YBh11FrbRG/H6ihirqcacOgl2BIO8oyMQLeXw==} @@ -239,6 +182,45 @@ packages: typescript: optional: true + '@rslint/core@0.5.1': + resolution: {integrity: sha512-UGcalhkpNvm4zN7E2DiQsuwM10LMi3CazOiANVevf5hn+NB7WKEMWYKn3bFySptg7Ll042IKMUlIXaFQjWs9lQ==} + hasBin: true + peerDependencies: + jiti: ^2.0.0 + peerDependenciesMeta: + jiti: + optional: true + + '@rslint/darwin-arm64@0.5.1': + resolution: {integrity: sha512-grbPKhrRv0BTKvdByIIlS5avc4ttF9vylaStJh/TTYS96cTkjCcTv7RAUv/ZI3VSaSZdRBcW4f6wW9pPWpt41w==} + cpu: [arm64] + os: [darwin] + + '@rslint/darwin-x64@0.5.1': + resolution: {integrity: sha512-v7P5AYWzm4Xrly5nl5yXSAyHn6j9pwZyFFUTD9UCOodZMEVmBxW3WxdL9iq8PfnG5n8GXHqTqBSYwWfG1WWD0g==} + cpu: [x64] + os: [darwin] + + '@rslint/linux-arm64@0.5.1': + resolution: {integrity: sha512-czDNVvgea0LpTlqaRvZHulJn8RmmDso2DufIWedxIA9yfK+nEK4H0tANNVQL4NBTHiv/6cqQw8NveP3KD5I93g==} + cpu: [arm64] + os: [linux] + + '@rslint/linux-x64@0.5.1': + resolution: {integrity: sha512-D0isbtok26OSjSQkWDDfTWPLQDqrufbTbiihMFxkDlIRKDGcU9HvnfTlEmgnwzkxt6Jm7CBZZiXdFtyhPgnWEg==} + cpu: [x64] + os: [linux] + + '@rslint/win32-arm64@0.5.1': + resolution: {integrity: sha512-XnU369fuTR9EqFhRMmbg+rHO3T/gwC+VV2AC1HAvZ62/pgNjFQmlK6IEsU293sgXHOUnRIQ6IsC9J0imyrCMXQ==} + cpu: [arm64] + os: [win32] + + '@rslint/win32-x64@0.5.1': + resolution: {integrity: sha512-7++ELodvfVPFDSYEMVWb7OA+BD2JeONXtwXP/vmbrcawBTff7E/6VREB8dGPYCNh/ypBuSQ2WYXUtYAxQxwSiQ==} + cpu: [x64] + os: [win32] + '@rspack/binding-darwin-arm64@1.7.10': resolution: {integrity: sha512-bsXi7I6TpH+a4L6okIUh1JDvwT+XcK/L7Yvhu5G2t5YYyd2fl5vMM5O9cePRpEb0RdqJZ3Z8i9WIWHap9aQ8Gw==} cpu: [arm64] @@ -387,6 +369,15 @@ packages: core-js@3.47.0: resolution: {integrity: sha512-c3Q2VVkGAUyupsjRnaNX6u8Dq2vAdzm9iuPj5FW0fRxzlxgq9Q39MDq10IvmQSpLgHQNyQzQmOo6bgGHmH3NNg==} + fdir@6.5.0: + resolution: {integrity: sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==} + engines: {node: '>=12.0.0'} + peerDependencies: + picomatch: ^3 || ^4 + peerDependenciesMeta: + picomatch: + optional: true + fsevents@2.3.2: resolution: {integrity: sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==} engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} @@ -396,15 +387,14 @@ packages: resolution: {integrity: sha512-ekilCSN1jwRvIbgeg/57YFh8qQDNbwDb9xT/qu2DAHbFFZUicIl4ygVaAvzveMhMVr3LnpSKTNnwt8PoOfmKhQ==} hasBin: true - nano-staged@1.0.2: - resolution: {integrity: sha512-Fytar3zHLY99nlMfqPPbraxZodqQAHPpdPRyYaplL+lB9DCR6pUrafxbG+Btz4+7fO5Rm/+DO4ZeDO/nLSUMhw==} - engines: {node: ^22 || >= 24} - hasBin: true - node-forge@1.3.1: resolution: {integrity: sha512-dPEtOeMvF9VMcYV/1Wb8CPoVAXtp6MKMlcbAt4ddqmGqUJ6fQZFXkNZNkNlfevtNkGtaSoXf/vNNNSvgrdXwtA==} engines: {node: '>= 6.13.0'} + picomatch@4.0.4: + resolution: {integrity: sha512-QP88BAKvMam/3NxH6vj2o21R6MjxZUAd6nlwAS/pnGvN9IVLocLHxGYIzFhg6fUQ+5th6P4dv4eW9jX3DSIj7A==} + engines: {node: '>=12'} + playwright-core@1.59.1: resolution: {integrity: sha512-HBV/RJg81z5BiiZ9yPzIiClYV/QMsDCKUyogwH9p3MCP6IYjUFu/MActgYAvK0oWyV9NlwM3GLBjADyWgydVyg==} engines: {node: '>=18'} @@ -415,6 +405,11 @@ packages: engines: {node: '>=18'} hasBin: true + prettier@3.8.3: + resolution: {integrity: sha512-7igPTM53cGHMW8xWuVTydi2KO233VFiTNyF5hLJqpilHfmn8C8gPf+PS7dUT64YcXFbiMGZxS9pCSxL/Dxm/Jw==} + engines: {node: '>=14'} + hasBin: true + rsbuild-plugin-dts@0.21.3: resolution: {integrity: sha512-8E3/npwRp99gc/Bl5bE1KKN5eIS2TQ3fuA7fBEk67R1RF7V4OtFKVI7mhk3X8zoH/9cclV9v909dguegZDgncw==} engines: {node: ^20.19.0 || >=22.12.0} @@ -439,6 +434,10 @@ packages: resolution: {integrity: sha512-WszCLXwT4h2k1ufIXAgsbiTOazqqevFCIncOuUBZJ91DdvWcC5+OFkluWRQPrcuSYd8fjq+o2y1QfWqYMoAToQ==} hasBin: true + tinyglobby@0.2.15: + resolution: {integrity: sha512-j2Zq4NyQYG5XMST4cbs02Ak8iJUdxRM0XI5QyxXuZOzKOINmWurp3smXu3y5wDcJrptwpSjgXHzIQxR0omXljQ==} + engines: {node: '>=12.0.0'} + tslib@2.8.1: resolution: {integrity: sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==} @@ -491,41 +490,6 @@ snapshots: '@ast-grep/napi-win32-ia32-msvc': 0.37.0 '@ast-grep/napi-win32-x64-msvc': 0.37.0 - '@biomejs/biome@1.9.4': - optionalDependencies: - '@biomejs/cli-darwin-arm64': 1.9.4 - '@biomejs/cli-darwin-x64': 1.9.4 - '@biomejs/cli-linux-arm64': 1.9.4 - '@biomejs/cli-linux-arm64-musl': 1.9.4 - '@biomejs/cli-linux-x64': 1.9.4 - '@biomejs/cli-linux-x64-musl': 1.9.4 - '@biomejs/cli-win32-arm64': 1.9.4 - '@biomejs/cli-win32-x64': 1.9.4 - - '@biomejs/cli-darwin-arm64@1.9.4': - optional: true - - '@biomejs/cli-darwin-x64@1.9.4': - optional: true - - '@biomejs/cli-linux-arm64-musl@1.9.4': - optional: true - - '@biomejs/cli-linux-arm64@1.9.4': - optional: true - - '@biomejs/cli-linux-x64-musl@1.9.4': - optional: true - - '@biomejs/cli-linux-x64@1.9.4': - optional: true - - '@biomejs/cli-win32-arm64@1.9.4': - optional: true - - '@biomejs/cli-win32-x64@1.9.4': - optional: true - '@emnapi/core@1.10.0': dependencies: '@emnapi/wasi-threads': 1.2.1 @@ -629,6 +593,37 @@ snapshots: - '@typescript/native-preview' - core-js + '@rslint/core@0.5.1(jiti@2.6.1)': + dependencies: + picomatch: 4.0.4 + tinyglobby: 0.2.15 + optionalDependencies: + '@rslint/darwin-arm64': 0.5.1 + '@rslint/darwin-x64': 0.5.1 + '@rslint/linux-arm64': 0.5.1 + '@rslint/linux-x64': 0.5.1 + '@rslint/win32-arm64': 0.5.1 + '@rslint/win32-x64': 0.5.1 + jiti: 2.6.1 + + '@rslint/darwin-arm64@0.5.1': + optional: true + + '@rslint/darwin-x64@0.5.1': + optional: true + + '@rslint/linux-arm64@0.5.1': + optional: true + + '@rslint/linux-x64@0.5.1': + optional: true + + '@rslint/win32-arm64@0.5.1': + optional: true + + '@rslint/win32-x64@0.5.1': + optional: true + '@rspack/binding-darwin-arm64@1.7.10': optional: true @@ -752,15 +747,19 @@ snapshots: core-js@3.47.0: {} + fdir@6.5.0(picomatch@4.0.4): + optionalDependencies: + picomatch: 4.0.4 + fsevents@2.3.2: optional: true jiti@2.6.1: {} - nano-staged@1.0.2: {} - node-forge@1.3.1: {} + picomatch@4.0.4: {} + playwright-core@1.59.1: {} playwright@1.59.1: @@ -769,6 +768,8 @@ snapshots: optionalDependencies: fsevents: 2.3.2 + prettier@3.8.3: {} + rsbuild-plugin-dts@0.21.3(@rsbuild/core@2.0.1(core-js@3.47.0))(typescript@6.0.3): dependencies: '@ast-grep/napi': 0.37.0 @@ -782,6 +783,11 @@ snapshots: simple-git-hooks@2.13.1: {} + tinyglobby@0.2.15: + dependencies: + fdir: 6.5.0(picomatch@4.0.4) + picomatch: 4.0.4 + tslib@2.8.1: {} typescript@6.0.3: {} diff --git a/rslib.config.ts b/rslib.config.ts index e9a61d1..b366628 100644 --- a/rslib.config.ts +++ b/rslib.config.ts @@ -1,11 +1,11 @@ import { defineConfig } from '@rslib/core'; export default defineConfig({ - lib: [ - { syntax: 'es2021', dts: true }, - { format: 'cjs', syntax: 'es2021' }, - ], - output: { - target: 'node', - }, + lib: [ + { syntax: 'es2021', dts: true }, + { format: 'cjs', syntax: 'es2021' }, + ], + output: { + target: 'node', + }, }); diff --git a/rslint.config.ts b/rslint.config.ts new file mode 100644 index 0000000..5055b09 --- /dev/null +++ b/rslint.config.ts @@ -0,0 +1,3 @@ +import { defineConfig, ts } from '@rslint/core'; + +export default defineConfig([ts.configs.recommended]); diff --git a/src/index.ts b/src/index.ts index eb2d304..dc17f97 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,41 +5,41 @@ import { resolveHttpsConfig } from './util.js'; export const PLUGIN_BASIC_SSL_NAME = 'rsbuild:basic-ssl'; export type PluginBasicSslOptions = { - /** - * Filename of the generated certificate - * @default 'fake-cert.pem' - */ - filename?: string; - /** - * Output path of the generated certificate - * @default __dirname - */ - outputPath?: string; - /** - * Attributes passing to `selfsigned`. - */ - selfsignedAttrs?: Parameters[0]; - /** - * Options passing to `selfsigned`. - */ - selfsignedOptions?: SelfsignedOptions; + /** + * Filename of the generated certificate + * @default 'fake-cert.pem' + */ + filename?: string; + /** + * Output path of the generated certificate + * @default __dirname + */ + outputPath?: string; + /** + * Attributes passing to `selfsigned`. + */ + selfsignedAttrs?: Parameters[0]; + /** + * Options passing to `selfsigned`. + */ + selfsignedOptions?: SelfsignedOptions; }; export const pluginBasicSsl = ( - options: PluginBasicSslOptions = {}, + options: PluginBasicSslOptions = {}, ): RsbuildPlugin => ({ - name: PLUGIN_BASIC_SSL_NAME, - setup(api) { - api.modifyRsbuildConfig(async (config) => { - const httpsConfig = await resolveHttpsConfig( - config.server?.https, - options, - ); + name: PLUGIN_BASIC_SSL_NAME, + setup(api) { + api.modifyRsbuildConfig(async (config) => { + const httpsConfig = await resolveHttpsConfig( + config.server?.https, + options, + ); - config.server = { - ...config.server, - https: httpsConfig, - }; - }); - }, + config.server = { + ...config.server, + https: httpsConfig, + }; + }); + }, }); diff --git a/src/util.ts b/src/util.ts index 621a80c..4152ab7 100644 --- a/src/util.ts +++ b/src/util.ts @@ -10,70 +10,70 @@ type HttpsConfig = ServerConfig['https']; const __dirname = path.dirname(fileURLToPath(import.meta.url)); async function ensureDir(dir: string) { - try { - await fs.promises.access(dir); - } catch (error) { - await ensureDir(path.dirname(dir)); - await fs.promises.mkdir(dir); - } + try { + await fs.promises.access(dir); + } catch { + await ensureDir(path.dirname(dir)); + await fs.promises.mkdir(dir); + } } export const resolveHttpsConfig = async ( - config: HttpsConfig, - options: PluginBasicSslOptions, + config: HttpsConfig, + options: PluginBasicSslOptions, ): Promise<{ - key: NonNullable['key']; - cert: NonNullable['cert']; + key: NonNullable['key']; + cert: NonNullable['cert']; }> => { - const { key, cert } = config ?? {}; + const { key, cert } = config ?? {}; - if (key && cert) { - return { key, cert }; - } + if (key && cert) { + return { key, cert }; + } - const certPath = path.join( - options.outputPath ?? __dirname, - options.filename ?? 'fake-cert.pem', - ); + const certPath = path.join( + options.outputPath ?? __dirname, + options.filename ?? 'fake-cert.pem', + ); - const selfsignedOptions = { - days: 30, - keySize: 2048, - ...options.selfsignedOptions, - }; + const selfsignedOptions = { + days: 30, + keySize: 2048, + ...options.selfsignedOptions, + }; - if (fs.existsSync(certPath)) { - const stats = await fs.promises.stat(certPath); - const timeDiff = Date.now() - stats.mtimeMs; - const daysDiff = timeDiff / (1000 * 60 * 60 * 24); + if (fs.existsSync(certPath)) { + const stats = await fs.promises.stat(certPath); + const timeDiff = Date.now() - stats.mtimeMs; + const daysDiff = timeDiff / (1000 * 60 * 60 * 24); - // Default validity period is 30 days - if (daysDiff < selfsignedOptions.days) { - const content = await fs.promises.readFile(certPath, { - encoding: 'utf-8', - }); - return { - key: content, - cert: content, - }; - } - } + // Default validity period is 30 days + if (daysDiff < selfsignedOptions.days) { + const content = await fs.promises.readFile(certPath, { + encoding: 'utf-8', + }); + return { + key: content, + cert: content, + }; + } + } - const pem = selfsigned.generate( - options.selfsignedAttrs ?? [{ name: 'commonName', value: 'localhost' }], - selfsignedOptions, - ); + const pem = selfsigned.generate( + options.selfsignedAttrs ?? [{ name: 'commonName', value: 'localhost' }], + selfsignedOptions, + ); - const content = pem.private + pem.cert; + const content = pem.private + pem.cert; - if (options.outputPath) { - await ensureDir(options.outputPath); - } + if (options.outputPath) { + await ensureDir(options.outputPath); + } - await fs.promises.writeFile(certPath, content, { encoding: 'utf-8' }); + await fs.promises.writeFile(certPath, content, { encoding: 'utf-8' }); - return { - key: content, - cert: content, - }; + return { + key: content, + cert: content, + }; }; diff --git a/test/basic/index.test.ts b/test/basic/index.test.ts index 676f913..0742b6f 100644 --- a/test/basic/index.test.ts +++ b/test/basic/index.test.ts @@ -7,20 +7,20 @@ import { pluginBasicSsl } from '../../dist'; const __dirname = dirname(fileURLToPath(import.meta.url)); test('should print HTTPS server URLs', async () => { - const rsbuild = await createRsbuild({ - cwd: __dirname, - rsbuildConfig: { - plugins: [pluginBasicSsl()], - }, - }); + const rsbuild = await createRsbuild({ + cwd: __dirname, + rsbuildConfig: { + plugins: [pluginBasicSsl()], + }, + }); - const { server, urls } = await rsbuild.startDevServer(); + const { server, urls } = await rsbuild.startDevServer(); - await new Promise((resolve) => { - rsbuild.onDevCompileDone(resolve); - }); + await new Promise((resolve) => { + rsbuild.onDevCompileDone(resolve); + }); - expect(urls.every((url) => url.startsWith('https'))).toBeTruthy(); + expect(urls.every((url) => url.startsWith('https'))).toBeTruthy(); - await server.close(); + await server.close(); }); diff --git a/test/basic/rsbuild.config.ts b/test/basic/rsbuild.config.ts index ef4a0cf..96b65cd 100644 --- a/test/basic/rsbuild.config.ts +++ b/test/basic/rsbuild.config.ts @@ -1,5 +1,5 @@ import { pluginBasicSsl } from '@rsbuild/plugin-basic-ssl'; export default { - plugins: [pluginBasicSsl()], + plugins: [pluginBasicSsl()], }; diff --git a/test/filename/index.test.ts b/test/filename/index.test.ts index cf82432..f959e71 100644 --- a/test/filename/index.test.ts +++ b/test/filename/index.test.ts @@ -7,27 +7,27 @@ import { pluginBasicSsl } from '../../dist'; const __dirname = dirname(fileURLToPath(import.meta.url)); test('should print HTTPS server URLs when custom filename', async () => { - const rsbuild = await createRsbuild({ - cwd: __dirname, - rsbuildConfig: { - plugins: [ - pluginBasicSsl({ - filename: 'foo.pem', - }), - ], - server: { - port: 3100, - }, - }, - }); + const rsbuild = await createRsbuild({ + cwd: __dirname, + rsbuildConfig: { + plugins: [ + pluginBasicSsl({ + filename: 'foo.pem', + }), + ], + server: { + port: 3100, + }, + }, + }); - const { server, urls } = await rsbuild.startDevServer(); + const { server, urls } = await rsbuild.startDevServer(); - await new Promise((resolve) => { - rsbuild.onDevCompileDone(resolve); - }); + await new Promise((resolve) => { + rsbuild.onDevCompileDone(resolve); + }); - expect(urls.every((url) => url.startsWith('https'))).toBeTruthy(); + expect(urls.every((url) => url.startsWith('https'))).toBeTruthy(); - await server.close(); + await server.close(); }); diff --git a/test/filename/rsbuild.config.ts b/test/filename/rsbuild.config.ts index ef4a0cf..96b65cd 100644 --- a/test/filename/rsbuild.config.ts +++ b/test/filename/rsbuild.config.ts @@ -1,5 +1,5 @@ import { pluginBasicSsl } from '@rsbuild/plugin-basic-ssl'; export default { - plugins: [pluginBasicSsl()], + plugins: [pluginBasicSsl()], }; diff --git a/test/output-path/index.test.ts b/test/output-path/index.test.ts index 12f8fd4..3893245 100644 --- a/test/output-path/index.test.ts +++ b/test/output-path/index.test.ts @@ -7,27 +7,27 @@ import { pluginBasicSsl } from '../../dist'; const __dirname = dirname(fileURLToPath(import.meta.url)); test('should print HTTPS server URLs when custom output path', async () => { - const rsbuild = await createRsbuild({ - cwd: __dirname, - rsbuildConfig: { - plugins: [ - pluginBasicSsl({ - outputPath: join(__dirname, 'dist'), - }), - ], - server: { - port: 3200, - }, - }, - }); + const rsbuild = await createRsbuild({ + cwd: __dirname, + rsbuildConfig: { + plugins: [ + pluginBasicSsl({ + outputPath: join(__dirname, 'dist'), + }), + ], + server: { + port: 3200, + }, + }, + }); - const { server, urls } = await rsbuild.startDevServer(); + const { server, urls } = await rsbuild.startDevServer(); - await new Promise((resolve) => { - rsbuild.onDevCompileDone(resolve); - }); + await new Promise((resolve) => { + rsbuild.onDevCompileDone(resolve); + }); - expect(urls.every((url) => url.startsWith('https'))).toBeTruthy(); + expect(urls.every((url) => url.startsWith('https'))).toBeTruthy(); - await server.close(); + await server.close(); }); diff --git a/test/output-path/rsbuild.config.ts b/test/output-path/rsbuild.config.ts index ef4a0cf..96b65cd 100644 --- a/test/output-path/rsbuild.config.ts +++ b/test/output-path/rsbuild.config.ts @@ -1,5 +1,5 @@ import { pluginBasicSsl } from '@rsbuild/plugin-basic-ssl'; export default { - plugins: [pluginBasicSsl()], + plugins: [pluginBasicSsl()], }; diff --git a/test/selfsigned-options/index.test.ts b/test/selfsigned-options/index.test.ts index 5f14234..9970dae 100644 --- a/test/selfsigned-options/index.test.ts +++ b/test/selfsigned-options/index.test.ts @@ -7,29 +7,29 @@ import { pluginBasicSsl } from '../../dist'; const __dirname = dirname(fileURLToPath(import.meta.url)); test('should print HTTPS server URLs when custom selfsigned options', async () => { - const rsbuild = await createRsbuild({ - cwd: __dirname, - rsbuildConfig: { - plugins: [ - pluginBasicSsl({ - selfsignedOptions: { - days: 1, - }, - }), - ], - server: { - port: 3300, - }, - }, - }); + const rsbuild = await createRsbuild({ + cwd: __dirname, + rsbuildConfig: { + plugins: [ + pluginBasicSsl({ + selfsignedOptions: { + days: 1, + }, + }), + ], + server: { + port: 3300, + }, + }, + }); - const { server, urls } = await rsbuild.startDevServer(); + const { server, urls } = await rsbuild.startDevServer(); - await new Promise((resolve) => { - rsbuild.onDevCompileDone(resolve); - }); + await new Promise((resolve) => { + rsbuild.onDevCompileDone(resolve); + }); - expect(urls.every((url) => url.startsWith('https'))).toBeTruthy(); + expect(urls.every((url) => url.startsWith('https'))).toBeTruthy(); - await server.close(); + await server.close(); }); diff --git a/test/selfsigned-options/rsbuild.config.ts b/test/selfsigned-options/rsbuild.config.ts index ef4a0cf..96b65cd 100644 --- a/test/selfsigned-options/rsbuild.config.ts +++ b/test/selfsigned-options/rsbuild.config.ts @@ -1,5 +1,5 @@ import { pluginBasicSsl } from '@rsbuild/plugin-basic-ssl'; export default { - plugins: [pluginBasicSsl()], + plugins: [pluginBasicSsl()], };