Skip to content

Commit 0e70e21

Browse files
committed
moving to biome
1 parent cd78c28 commit 0e70e21

File tree

13 files changed

+190
-198
lines changed

13 files changed

+190
-198
lines changed

.prettierrc.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,9 @@ There are a number of handy commands you can run to help with development.
5555
|`pnpm build`| Compile TypeScript to JavaScript |
5656
|`pnpm start`| Start JavaScript from 'build' directory |
5757
|`pnpm test`| Run unit tests (run `pnpm build` before) |
58-
|`pnpm test:watch`| Run backend tests in watch mode, running on changed test files |
59-
|`pnpm lint`| Run eslint |
60-
|`pnpm lint:fix`| Run eslint in fix mode |
58+
|`pnpm lint`| Run biome check |
6159

6260
## CI
6361

6462
Run tests on push/PR to 'main' branch
6563
Check `.github/workflows/CI.yml`
66-
67-
## Recommended Vscode Extensions
68-
69-
[Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode)
70-
[ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)

biome.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/2.3.2/schema.json",
3+
"vcs": {
4+
"enabled": true,
5+
"clientKind": "git",
6+
"useIgnoreFile": true
7+
},
8+
"files": {
9+
"ignoreUnknown": false
10+
},
11+
"formatter": {
12+
"enabled": true,
13+
"indentStyle": "tab",
14+
"indentWidth": 2,
15+
"lineEnding": "lf",
16+
"lineWidth": 100
17+
},
18+
"linter": {
19+
"enabled": true,
20+
"rules": {
21+
"recommended": true
22+
},
23+
"domains": {
24+
"test": "recommended"
25+
}
26+
},
27+
"javascript": {
28+
"formatter": {
29+
"jsxQuoteStyle": "single",
30+
"trailingCommas": "all",
31+
"semicolons": "always",
32+
"quoteStyle": "single"
33+
}
34+
},
35+
"assist": {
36+
"enabled": true,
37+
"actions": {
38+
"source": {
39+
"organizeImports": "on"
40+
}
41+
}
42+
}
43+
}

eslint.config.mjs

Lines changed: 0 additions & 36 deletions
This file was deleted.

package.json

Lines changed: 48 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,50 @@
11
{
2-
"name": "fastify-typescript-starter",
3-
"version": "1.5.0",
4-
"description": "Node.js boilerplate using fastify & TypeScript",
5-
"type": "module",
6-
"scripts": {
7-
"lint": "eslint .",
8-
"lint:fix": "eslint . --fix",
9-
"check:types": "tsc --noEmit",
10-
"build": "esbuild `find src \\( -name '*.ts' \\)` --platform=node --outdir=build --resolve-extensions=.js",
11-
"build:docker:prod": "docker build . -t my-fastify-app --build-arg APP_ENV=production",
12-
"start": "node build",
13-
"dev": "tsx watch src .env | pino-pretty --colorize",
14-
"pretest": "npm run build",
15-
"test": "vitest",
16-
"test:watch": "vitest -w"
17-
},
18-
"repository": {
19-
"type": "git",
20-
"url": "git+https://github.com/yonathan06/fastify-typescript-starter.git"
21-
},
22-
"engines": {
23-
"node": ">=22.0.0"
24-
},
25-
"keywords": [
26-
"nodejs",
27-
"fastify",
28-
"typescript"
29-
],
30-
"author": "Yonatan Bendahan",
31-
"license": "MIT",
32-
"bugs": {
33-
"url": "https://github.com/yonathan06/fastify-typescript-starter/issues"
34-
},
35-
"homepage": "https://github.com/yonathan06/fastify-typescript-starter#readme",
36-
"dependencies": {
37-
"@sinclair/typebox": "^0.34.9",
38-
"ajv": "^8.17.1",
39-
"dotenv": "^16.4.5",
40-
"env-schema": "^6.0.0",
41-
"fastify": "^5.1.0",
42-
"fastify-plugin": "^5.0.1"
43-
},
44-
"devDependencies": {
45-
"@types/node": "^22.10.1",
46-
"@typescript-eslint/eslint-plugin": "^8.16.0",
47-
"@typescript-eslint/parser": "^8.16.0",
48-
"esbuild": "^0.24.0",
49-
"eslint": "^9.16.0",
50-
"eslint-config-prettier": "^9.1.0",
51-
"eslint-plugin-prettier": "^5.2.1",
52-
"pino-pretty": "^13.0.0",
53-
"prettier": "^3.4.1",
54-
"tsx": "^4.19.2",
55-
"typescript": "^5.7.2",
56-
"vitest": "^2.1.6"
57-
}
2+
"name": "fastify-typescript-starter",
3+
"version": "1.5.0",
4+
"description": "Node.js boilerplate using fastify & TypeScript",
5+
"type": "module",
6+
"scripts": {
7+
"lint": "biome check",
8+
"check:types": "tsc --noEmit",
9+
"build": "esbuild `find src \\( -name '*.ts' \\)` --platform=node --outdir=build --resolve-extensions=.js",
10+
"build:docker:prod": "docker build . -t my-fastify-app --build-arg APP_ENV=production",
11+
"start": "node build",
12+
"dev": "tsx watch src .env | pino-pretty --colorize",
13+
"test": "vitest"
14+
},
15+
"repository": {
16+
"type": "git",
17+
"url": "git+https://github.com/yonathan06/fastify-typescript-starter.git"
18+
},
19+
"engines": {
20+
"node": ">=22.0.0"
21+
},
22+
"keywords": [
23+
"nodejs",
24+
"fastify",
25+
"typescript"
26+
],
27+
"author": "Yonatan Bendahan",
28+
"license": "MIT",
29+
"bugs": {
30+
"url": "https://github.com/yonathan06/fastify-typescript-starter/issues"
31+
},
32+
"homepage": "https://github.com/yonathan06/fastify-typescript-starter#readme",
33+
"dependencies": {
34+
"@sinclair/typebox": "^0.34.9",
35+
"ajv": "^8.17.1",
36+
"dotenv": "^16.4.5",
37+
"env-schema": "^6.0.0",
38+
"fastify": "^5.1.0",
39+
"fastify-plugin": "^5.0.1"
40+
},
41+
"devDependencies": {
42+
"@biomejs/biome": "2.3.2",
43+
"@types/node": "^22.10.1",
44+
"esbuild": "^0.24.0",
45+
"pino-pretty": "^13.0.0",
46+
"tsx": "^4.19.2",
47+
"typescript": "^5.7.2",
48+
"vitest": "^2.1.6"
49+
}
5850
}

src/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import server from './server.js';
22

33
process.on('unhandledRejection', (err) => {
4-
console.error(err);
5-
process.exit(1);
4+
console.error(err);
5+
process.exit(1);
66
});
77

88
const port = +server.config.API_PORT;
99
const host = server.config.API_HOST;
1010
await server.listen({ host, port });
1111

1212
for (const signal of ['SIGINT', 'SIGTERM']) {
13-
process.on(signal, () =>
14-
server.close().then((err) => {
15-
console.log(`close application on ${signal}`);
16-
process.exit(err ? 1 : 0);
17-
}),
18-
);
13+
process.on(signal, () =>
14+
server.close().then((err) => {
15+
console.log(`close application on ${signal}`);
16+
process.exit(err ? 1 : 0);
17+
}),
18+
);
1919
}

src/plugins/config.ts

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,45 @@
1-
import "dotenv/config";
2-
import fp from "fastify-plugin";
3-
import { FastifyPluginAsync } from "fastify";
4-
import { Static, Type } from "@sinclair/typebox";
5-
import Ajv from "ajv";
1+
import 'dotenv/config';
2+
import { type Static, Type } from '@sinclair/typebox';
3+
import Ajv from 'ajv';
4+
import type { FastifyPluginAsync } from 'fastify';
5+
import fp from 'fastify-plugin';
66

77
export enum NodeEnv {
8-
development = "development",
9-
test = "test",
10-
production = "production",
8+
development = 'development',
9+
test = 'test',
10+
production = 'production',
1111
}
1212

1313
const ConfigSchema = Type.Object({
14-
NODE_ENV: Type.Enum(NodeEnv),
15-
LOG_LEVEL: Type.String(),
16-
API_HOST: Type.String(),
17-
API_PORT: Type.String(),
14+
NODE_ENV: Type.Enum(NodeEnv),
15+
LOG_LEVEL: Type.String(),
16+
API_HOST: Type.String(),
17+
API_PORT: Type.String(),
1818
});
1919

2020
const ajv = new Ajv({
21-
allErrors: true,
22-
removeAdditional: true,
23-
useDefaults: true,
24-
coerceTypes: true,
25-
allowUnionTypes: true,
21+
allErrors: true,
22+
removeAdditional: true,
23+
useDefaults: true,
24+
coerceTypes: true,
25+
allowUnionTypes: true,
2626
});
2727

2828
export type Config = Static<typeof ConfigSchema>;
2929

3030
const configPlugin: FastifyPluginAsync = async (server) => {
31-
const validate = ajv.compile(ConfigSchema);
32-
const valid = validate(process.env);
33-
if (!valid) {
34-
throw new Error(
35-
".env file validation failed - " +
36-
JSON.stringify(validate.errors, null, 2)
37-
);
38-
}
39-
server.decorate("config", process.env as Config);
31+
const validate = ajv.compile(ConfigSchema);
32+
const valid = validate(process.env);
33+
if (!valid) {
34+
throw new Error(`.env file validation failed - ${JSON.stringify(validate.errors, null, 2)}`);
35+
}
36+
server.decorate('config', process.env as Config);
4037
};
4138

42-
declare module "fastify" {
43-
interface FastifyInstance {
44-
config: Config;
45-
}
39+
declare module 'fastify' {
40+
interface FastifyInstance {
41+
config: Config;
42+
}
4643
}
4744

4845
export default fp(configPlugin);

src/routes/index.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import { Type } from '@sinclair/typebox';
2-
import { FastifyPluginAsync } from 'fastify';
2+
import type { FastifyPluginAsync } from 'fastify';
33

44
const routes: FastifyPluginAsync = async (server) => {
5-
server.get('/', {
6-
schema: {
7-
response: {
8-
200: Type.Object({
9-
hello: Type.String(),
10-
}),
11-
},
12-
},
13-
}, async function () {
14-
return { hello: 'world' };
15-
});
16-
}
5+
server.get(
6+
'/',
7+
{
8+
schema: {
9+
response: {
10+
200: Type.Object({
11+
hello: Type.String(),
12+
}),
13+
},
14+
},
15+
},
16+
async () => ({ hello: 'world' }),
17+
);
18+
};
1719

1820
export default routes;

src/server.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import config from './plugins/config.js';
33
import routes from './routes/index.js';
44

55
const server = fastify({
6-
ajv: {
7-
customOptions: {
8-
removeAdditional: "all",
9-
coerceTypes: true,
10-
useDefaults: true,
11-
}
12-
},
13-
logger: {
14-
level: process.env.LOG_LEVEL,
15-
},
6+
ajv: {
7+
customOptions: {
8+
removeAdditional: 'all',
9+
coerceTypes: true,
10+
useDefaults: true,
11+
},
12+
},
13+
logger: {
14+
level: process.env.LOG_LEVEL,
15+
},
1616
});
1717

1818
await server.register(config);

0 commit comments

Comments
 (0)