Skip to content

Commit

Permalink
build(deps-dev): replace standard with neostandard (#112)
Browse files Browse the repository at this point in the history
* build(deps-dev): replace standard with neostandard

* chore: add eslint.config.js
  • Loading branch information
Fdawgs authored Dec 8, 2024
1 parent caae0cd commit 88d63bf
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![CI](https://github.com/fastify/fastify-routes/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fastify/fastify-routes/actions/workflows/ci.yml)
[![NPM version](https://img.shields.io/npm/v/@fastify/routes.svg?style=flat)](https://www.npmjs.com/package/@fastify/routes)
[![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)

This plugin decorates a Fastify instance with `routes`, which is a [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) of registered routes. Note that you have to await the registration of this plugin before registering any routes so that @fastify/routes can collect them.

Expand Down
6 changes: 6 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict'

module.exports = require('neostandard')({
ignores: require('neostandard').resolveIgnoresFromGitignore(),
ts: true
})
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"type": "commonjs",
"types": "types/index.d.ts",
"scripts": {
"lint": "standard | snazzy",
"lint": "eslint",
"lint:fix": "eslint --fix",
"test": "npm run test:unit && npm run test:typescript",
"test:unit": "c8 --100 node --test",
"test:typescript": "tsd"
Expand All @@ -33,8 +34,7 @@
"@types/node": "^22.0.0",
"c8": "^10.1.2",
"fastify": "^5.0.0",
"snazzy": "^9.0.0",
"standard": "^17.1.0",
"neostandard": "^0.11.9",
"tsd": "^0.31.1"
},
"dependencies": {
Expand Down
8 changes: 4 additions & 4 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/// <reference types="node" />

import { RouteOptions, FastifyPluginCallback } from "fastify";
import { RouteOptions, FastifyPluginCallback } from 'fastify'

declare module "fastify" {
declare module 'fastify' {
interface FastifyInstance {
routes: fastifyRoutes.FastifyRoutes;
}
}

declare namespace fastifyRoutes {
export type FastifyRoutes = Map<string, RouteOptions[]>;
export type FastifyRoutes = Map<string, RouteOptions[]>

export const fastifyRoutes: FastifyPluginCallback
export { fastifyRoutes as default }
}

declare function fastifyRoutes(...params: Parameters<FastifyPluginCallback>): ReturnType<FastifyPluginCallback>
declare function fastifyRoutes (...params: Parameters<FastifyPluginCallback>): ReturnType<FastifyPluginCallback>
export = fastifyRoutes
25 changes: 11 additions & 14 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,25 @@ import fastify, {
FastifyInstance,
FastifyPluginCallback,
RouteOptions,
} from "fastify";
import { expectAssignable, expectError, expectType } from "tsd";
} from 'fastify'
import { expectAssignable, expectError, expectType } from 'tsd'

import fastifyRoutes, { FastifyRoutes } from "..";
import fastifyRoutes, { FastifyRoutes } from '..'

const app: FastifyInstance = fastify()
app.register(fastifyRoutes)


const app: FastifyInstance = fastify();
app.register(fastifyRoutes);

expectType<FastifyPluginCallback>(fastifyRoutes);

expectType<FastifyPluginCallback>(fastifyRoutes)

expectError(
app.register(fastifyRoutes, {
unknownOption: "this should trigger a typescript error",
unknownOption: 'this should trigger a typescript error',
})
);
)

// Plugin property available
app.after(() => {
expectType<FastifyRoutes>(app.routes);
expectType<FastifyRoutes>(app.routes)

expectAssignable<RouteOptions[] | undefined>(app.routes.get("/rotue"));
});
expectAssignable<RouteOptions[] | undefined>(app.routes.get('/rotue'))
})

0 comments on commit 88d63bf

Please sign in to comment.