From 13de6e685160b63e17198a1d74a3cae5acea77bb Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sun, 8 Dec 2024 10:44:39 +0000 Subject: [PATCH 1/2] build(deps-dev): replace standard with neostandard --- README.md | 2 +- package.json | 9 +++------ types/index.d.ts | 12 ++++++------ types/index.test-d.ts | 42 +++++++++++++++++++++--------------------- 4 files changed, 31 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 2ff77da..19c1932 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![CI](https://github.com/fastify/fastify-http-proxy/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fastify/fastify-http-proxy/actions/workflows/ci.yml) [![NPM version](https://img.shields.io/npm/v/@fastify/http-proxy.svg?style=flat)](https://www.npmjs.com/package/@fastify/http-proxy) -[![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) Proxy your HTTP requests to another server, with hooks. This [`fastify`](https://fastify.dev) plugin forwards all requests diff --git a/package.json b/package.json index 3a9a62a..b644418 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,8 @@ "type": "commonjs", "types": "types/index.d.ts", "scripts": { - "lint": "standard | snazzy", - "lint:fix": "standard --fix | snazzy", + "lint": "eslint", + "lint:fix": "eslint --fix", "lint:typescript": "npm run lint:fix - --parser @typescript-eslint/parser --plugin typescript \"test/types/*.ts\"", "test": "npm run lint && tap \"test/*.js\" && npm run typescript", "typescript": "tsd" @@ -32,8 +32,6 @@ "@fastify/websocket": "^11.0.1", "@types/node": "^22.0.0", "@types/ws": "^8.5.10", - "@typescript-eslint/eslint-plugin": "^7.6.0", - "@typescript-eslint/parser": "^7.6.0", "express": "^4.19.2", "express-http-proxy": "^2.0.0", "fast-proxy": "^2.1.0", @@ -41,11 +39,10 @@ "got": "^11.8.6", "http-errors": "^2.0.0", "http-proxy": "^1.18.1", + "neostandard": "^0.11.9", "simple-get": "^4.0.1", - "snazzy": "^9.0.0", "socket.io": "^4.7.5", "socket.io-client": "^4.7.5", - "standard": "^17.1.0", "tap": "^18.7.2", "tsd": "^0.31.0", "typescript": "~5.7.2", diff --git a/types/index.d.ts b/types/index.d.ts index 3ffe4d4..6958556 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -7,14 +7,14 @@ import { preValidationHookHandler, RawServerBase, RequestGenericInterface, -} from 'fastify'; +} from 'fastify' import { FastifyReplyFromOptions, FastifyReplyFromHooks, -} from '@fastify/reply-from'; +} from '@fastify/reply-from' -import { ClientOptions, ServerOptions } from 'ws'; +import { ClientOptions, ServerOptions } from 'ws' interface FastifyHttpProxyWebsocketOptionsEnabled { websocket: true; @@ -28,14 +28,14 @@ interface FastifyHttpProxyWebsocketOptionsDisabled { type FastifyHttpProxy = FastifyPluginCallback< fastifyHttpProxy.FastifyHttpProxyOptions & (FastifyHttpProxyWebsocketOptionsEnabled | FastifyHttpProxyWebsocketOptionsDisabled) ->; +> declare namespace fastifyHttpProxy { type QueryStringFunction = ( search: string | undefined, reqUrl: string, request: FastifyRequest - ) => string; + ) => string export interface FastifyHttpProxyOptions extends FastifyReplyFromOptions { upstream: string; @@ -58,5 +58,5 @@ declare namespace fastifyHttpProxy { export { fastifyHttpProxy as default } } -declare function fastifyHttpProxy(...params: Parameters): ReturnType +declare function fastifyHttpProxy (...params: Parameters): ReturnType export = fastifyHttpProxy diff --git a/types/index.test-d.ts b/types/index.test-d.ts index f2f9ea9..38685da 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -4,15 +4,15 @@ import fastify, { type FastifyRequest, type RawServerBase, type RequestGenericInterface, -} from 'fastify'; -import { expectError, expectType } from 'tsd'; -import fastifyHttpProxy from '..'; +} from 'fastify' +import { expectError, expectType } from 'tsd' +import fastifyHttpProxy from '..' -const app = fastify(); +const app = fastify() app.register(fastifyHttpProxy, { upstream: 'http://origin.asd', -}); +}) app.register(fastifyHttpProxy, { upstream: 'http://origin.asd', @@ -23,16 +23,16 @@ app.register(fastifyHttpProxy, { replyOptions: { contentType: 'application/json' }, httpMethods: ['DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT', 'OPTIONS'], preHandler: (request, reply) => { - expectType(request.raw); - expectType(reply.raw); + expectType(request.raw) + expectType(reply.raw) }, beforeHandler: (request, reply) => { - expectType(request.raw); - expectType(reply.raw); + expectType(request.raw) + expectType(reply.raw) }, preValidation: (request, reply) => { - expectType(request.raw); - expectType(reply.raw); + expectType(request.raw) + expectType(reply.raw) }, base: 'whatever', cacheURLs: 10, @@ -56,28 +56,28 @@ app.register(fastifyHttpProxy, { websocket: true, wsUpstream: 'ws://origin.asd/connection', wsClientOptions: { - queryString(search, reqUrl, request) { - expectType(search); - expectType(reqUrl); - expectType>(request); - return ''; + queryString (search, reqUrl, request) { + expectType(search) + expectType(reqUrl) + expectType>(request) + return '' }, }, internalRewriteLocationHeader: true, -}); +}) expectError( app.register(fastifyHttpProxy, { thisOptionDoesNotExist: 'triggers a typescript error', }) -); +) expectError( app.register(fastifyHttpProxy, { upstream: 'http://origin.asd', wsUpstream: 'ws://origin.asd', }) -); +) expectError( app.register(fastifyHttpProxy, { @@ -85,7 +85,7 @@ expectError( websocket: false, wsUpstream: 'asdf', }) -); +) expectError( app.register(fastifyHttpProxy, { @@ -93,4 +93,4 @@ expectError( websocket: false, internalRewriteLocationHeader: 'NON_BOOLEAN_VALUE' }) -); +) From 463a55585cdc8efb923699b2023fb5016fcbf7e8 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sun, 8 Dec 2024 10:53:36 +0000 Subject: [PATCH 2/2] chore: add eslint.config.js --- eslint.config.js | 6 ++++++ 1 file changed, 6 insertions(+) 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 +})