From b2ef165ac0662a159d34bdcbe62797df8c33a3d8 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Wed, 27 Nov 2024 12:03:19 +0000 Subject: [PATCH 1/2] build(deps-dev): replace standard with neostandard --- eslint.config.js | 6 ++++++ package.json | 8 +++----- types/index.d.ts | 26 +++++++++++++------------- types/index.test-d.ts | 14 +++++++------- 4 files changed, 29 insertions(+), 25 deletions(-) create mode 100644 eslint.config.js diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..89fd678 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,6 @@ +'use strict' + +module.exports = require('neostandard')({ + ignores: require('neostandard').resolveIgnoresFromGitignore(), + ts: true +}) diff --git a/package.json b/package.json index 0b298fb..9d87934 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,8 @@ "type": "commonjs", "types": "types/index.d.ts", "scripts": { - "lint": "standard", - "lint:fix": "standard --fix", + "lint": "eslint", + "lint:fix": "eslint --fix", "test": "npm run test:unit && npm run test:typescript", "test:typescript": "tsd", "test:unit": "c8 --100 node --test" @@ -32,12 +32,10 @@ "devDependencies": { "@fastify/pre-commit": "^2.1.0", "@types/node": "^22.0.0", - "@typescript-eslint/eslint-plugin": "^7.3.1", - "@typescript-eslint/parser": "^7.3.1", "c8": "^10.1.2", "cors": "^2.8.5", "fastify": "^5.0.0", - "standard": "^17.1.0", + "neostandard": "^0.11.9", "tsd": "^0.31.1", "typescript": "~5.7.2" }, diff --git a/types/index.d.ts b/types/index.d.ts index b369e5c..e5f2709 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,17 +1,17 @@ /// -import { FastifyInstance, FastifyPluginCallback, FastifyRequest } from 'fastify'; +import { FastifyInstance, FastifyPluginCallback, FastifyRequest } from 'fastify' -type OriginCallback = (err: Error | null, origin: ValueOrArray) => void; -type OriginType = string | boolean | RegExp; -type ValueOrArray = T | ArrayOfValueOrArray; +type OriginCallback = (err: Error | null, origin: ValueOrArray) => void +type OriginType = string | boolean | RegExp +type ValueOrArray = T | ArrayOfValueOrArray interface ArrayOfValueOrArray extends Array> { } type FastifyCorsPlugin = FastifyPluginCallback< NonNullable | fastifyCors.FastifyCorsOptionsDelegate ->; +> type FastifyCorsHook = | 'onRequest' @@ -22,8 +22,8 @@ type FastifyCorsHook = | 'onSend' declare namespace fastifyCors { - export type OriginFunction = (origin: string | undefined, callback: OriginCallback) => void; - export type AsyncOriginFunction = (origin: string | undefined) => Promise>; + export type OriginFunction = (origin: string | undefined, callback: OriginCallback) => void + export type AsyncOriginFunction = (origin: string | undefined) => Promise> export interface FastifyCorsOptions { /** @@ -102,16 +102,16 @@ declare namespace fastifyCors { } export interface FastifyCorsOptionsDelegateCallback { (req: FastifyRequest, cb: (error: Error | null, corsOptions?: FastifyCorsOptions) => void): void } - export interface FastifyCorsOptionsDelegatePromise { (req: FastifyRequest): Promise } + export interface FastifyCorsOptionsDelegatePromise { (req: FastifyRequest): Promise } export type FastifyCorsOptionsDelegate = FastifyCorsOptionsDelegateCallback | FastifyCorsOptionsDelegatePromise - export type FastifyPluginOptionsDelegate = (instance: FastifyInstance) => T; + export type FastifyPluginOptionsDelegate = (instance: FastifyInstance) => T export const fastifyCors: FastifyCorsPlugin - export { fastifyCors as default }; + export { fastifyCors as default } } -declare function fastifyCors( +declare function fastifyCors ( ...params: Parameters -): ReturnType; +): ReturnType -export = fastifyCors; +export = fastifyCors diff --git a/types/index.test-d.ts b/types/index.test-d.ts index 50d75dd..1ee85eb 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -120,9 +120,9 @@ app.register(fastifyCors, { const asyncCorsDelegate: OriginFunction = async (origin) => { if (origin === undefined || /localhost/.test(origin)) { - return true; + return true } - return false; + return false } app.register(fastifyCors, { @@ -371,15 +371,15 @@ appHttp2.register(fastifyCors, delegate) appHttp2.register(fastifyCors, { hook: 'preParsing', origin: function (origin, cb) { - expectType(origin) + expectType(origin) cb(null, false) }, }) -const asyncOriginFn: AsyncOriginFunction = async function (origin): Promise { - expectType(origin) - return false; -}; +const asyncOriginFn: AsyncOriginFunction = async function (origin): Promise { + expectType(origin) + return false +} appHttp2.register(fastifyCors, { hook: 'preParsing', From 3368f99c97333dc42cf0a6d5a18c6bad99b1f891 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Wed, 27 Nov 2024 12:06:59 +0000 Subject: [PATCH 2/2] docs(readme): update badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3672387..ee64cf7 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![CI](https://github.com/fastify/fastify-cors/workflows/CI/badge.svg) [![NPM version](https://img.shields.io/npm/v/@fastify/cors.svg?style=flat)](https://www.npmjs.com/package/@fastify/cors) -[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/) +[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard) `@fastify/cors` enables the use of [CORS](https://en.wikipedia.org/wiki/Cross-origin_resource_sharing) in a Fastify application.