Skip to content

Commit 9b216c5

Browse files
committed
feat: overhaul project using Bun
1 parent 045a349 commit 9b216c5

38 files changed

Lines changed: 311 additions & 4468 deletions

.eslintignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.eslintrc.js

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

.github/renovate.json

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

.github/workflows/main.yml

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,15 @@ jobs:
1212

1313
steps:
1414
- name: Checkout
15-
uses: actions/checkout@v3
15+
uses: actions/checkout@v4
1616

17-
- name: Use Node 12
18-
uses: actions/setup-node@v3
17+
- name: Setup Bun
18+
uses: oven-sh/setup-bun@v1
1919
with:
20-
node-version: 12.x
21-
22-
- name: Use cached node_modules
23-
uses: actions/cache@v2
24-
with:
25-
path: node_modules
26-
key: nodeModules-${{ hashFiles('**/yarn.lock') }}
27-
restore-keys: |
28-
nodeModules-
20+
bun-version: latest
2921

3022
- name: Install dependencies
31-
run: yarn install --frozen-lockfile
23+
run: bun install --frozen-lockfile
3224

33-
- name: Lint and Tests
34-
run: yarn lint & yarn test --ci --coverage --maxWorkers=2
25+
- name: Run tests
26+
run: bun test

.husky/pre-commit

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
#!/bin/sh
2-
. "$(dirname "$0")/_/husky.sh"
3-
4-
yarn lint-staged
2+
bunx lint-staged

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v22.21.0

.vscode/settings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"typescript.tsdk": "node_modules/typescript/lib"
3-
}
2+
"typescript.experimental.useTsgo": true
3+
}

CLAUDE.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
Default to using Bun instead of Node.js.
2+
3+
- Use `bun <file>` instead of `node <file>` or `ts-node <file>`
4+
- Use `bun test` instead of `jest` or `vitest`
5+
- Use `bun build <file.html|file.ts|file.css>` instead of `webpack` or `esbuild`
6+
- Use `bun install` instead of `npm install` or `yarn install` or `pnpm install`
7+
- Use `bun run <script>` instead of `npm run <script>` or `yarn run <script>` or `pnpm run <script>`
8+
- Bun automatically loads .env, so don't use dotenv.
9+
10+
## APIs
11+
12+
- `Bun.serve()` supports WebSockets, HTTPS, and routes. Don't use `express`.
13+
- `bun:sqlite` for SQLite. Don't use `better-sqlite3`.
14+
- `Bun.redis` for Redis. Don't use `ioredis`.
15+
- `Bun.sql` for Postgres. Don't use `pg` or `postgres.js`.
16+
- `WebSocket` is built-in. Don't use `ws`.
17+
- Prefer `Bun.file` over `node:fs`'s readFile/writeFile
18+
- Bun.$`ls` instead of execa.
19+
20+
## Testing
21+
22+
Use `bun test` to run tests.
23+
24+
```ts#index.test.ts
25+
import { test, expect } from "bun:test";
26+
27+
test("hello world", () => {
28+
expect(1).toBe(1);
29+
});
30+
```
31+
32+
## Frontend
33+
34+
Use HTML imports with `Bun.serve()`. Don't use `vite`. HTML imports fully support React, CSS, Tailwind.
35+
36+
Server:
37+
38+
```ts#index.ts
39+
import index from "./index.html"
40+
41+
Bun.serve({
42+
routes: {
43+
"/": index,
44+
"/api/users/:id": {
45+
GET: (req) => {
46+
return new Response(JSON.stringify({ id: req.params.id }));
47+
},
48+
},
49+
},
50+
// optional websocket support
51+
websocket: {
52+
open: (ws) => {
53+
ws.send("Hello, world!");
54+
},
55+
message: (ws, message) => {
56+
ws.send(message);
57+
},
58+
close: (ws) => {
59+
// handle close
60+
}
61+
},
62+
development: {
63+
hmr: true,
64+
console: true,
65+
}
66+
})
67+
```
68+
69+
HTML files can import .tsx, .jsx or .js files directly and Bun's bundler will transpile & bundle automatically. `<link>` tags can point to stylesheets and Bun's CSS bundler will bundle.
70+
71+
```html#index.html
72+
<html>
73+
<body>
74+
<h1>Hello, world!</h1>
75+
<script type="module" src="./frontend.tsx"></script>
76+
</body>
77+
</html>
78+
```
79+
80+
With the following `frontend.tsx`:
81+
82+
```tsx#frontend.tsx
83+
import React from "react";
84+
85+
// import .css files directly and it works
86+
import './index.css';
87+
88+
import { createRoot } from "react-dom/client";
89+
90+
const root = createRoot(document.body);
91+
92+
export default function Frontend() {
93+
return <h1>Hello, world!</h1>;
94+
}
95+
96+
root.render(<Frontend />);
97+
```
98+
99+
Then, run index.ts
100+
101+
```sh
102+
bun --hot ./index.ts
103+
```
104+
105+
For more information, read the Bun API docs in `node_modules/bun-types/docs/**.md`.

bun.lock

Lines changed: 106 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@
22
"name": "ts-algorithms",
33
"version": "1.0.2",
44
"description": "A list of data structures and algorithms in TypeScript",
5-
"main": "index.js",
65
"scripts": {
7-
"clean": "rimraf dist",
8-
"build": "npm run clean && tsc",
9-
"start": "tsnd --respawn --transpileOnly --no-notify ./src",
10-
"lint": "eslint 'src/**/*.ts'",
11-
"test": "jest",
12-
"test:w": "jest --watch"
6+
"test": "bun test",
7+
"test:w": "bun test --watch",
8+
"prepare": "husky"
139
},
1410
"keywords": [
1511
"algorithms",
@@ -19,49 +15,24 @@
1915
"author": "Ryan Dsouza",
2016
"license": "ISC",
2117
"dependencies": {
22-
"typescript": "^4.0.0"
18+
"typescript": "^5.9.3"
2319
},
2420
"devDependencies": {
25-
"@types/jest": "27.4.1",
26-
"@types/node": "16.11.26",
27-
"@types/prettier": "2.4.4",
28-
"@types/rimraf": "3.0.2",
29-
"@typescript-eslint/eslint-plugin": "5.15.0",
30-
"@typescript-eslint/parser": "5.15.0",
31-
"eslint": "8.11.0",
32-
"eslint-config-prettier": "8.5.0",
33-
"husky": "7.0.4",
34-
"jest": "27.5.1",
35-
"lint-staged": "12.3.7",
36-
"prettier": "2.6.0",
37-
"rimraf": "3.0.2",
38-
"ts-jest": "27.1.3",
39-
"ts-node-dev": "1.1.8",
40-
"typesync": "0.8.0"
41-
},
42-
"jest": {
43-
"roots": [
44-
"<rootDir>/src"
45-
],
46-
"transform": {
47-
"^.+\\.tsx?$": "ts-jest"
48-
},
49-
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
50-
"moduleFileExtensions": [
51-
"ts",
52-
"js",
53-
"json"
54-
]
21+
"@types/bun": "latest",
22+
"husky": "9.1.7",
23+
"lint-staged": "16.2.7",
24+
"prettier": "3.7.2"
5525
},
5626
"prettier": {
5727
"semi": false,
5828
"singleQuote": true
5929
},
30+
"private": true,
31+
"peerDependencies": {
32+
"typescript": "^5.9.3"
33+
},
6034
"lint-staged": {
61-
"*.{js,ts}": [
62-
"npm run lint"
63-
],
64-
"*.{js,ts,json,md}": [
35+
"*.{ts,tsx,json,md}": [
6536
"prettier --write"
6637
]
6738
}

0 commit comments

Comments
 (0)