Skip to content

Commit 999da12

Browse files
authored
Merge pull request #188 from Cleboost/v2
Migrate to Bun, restructure project, remove packages
2 parents 8efc78e + f12b060 commit 999da12

File tree

141 files changed

+3226
-23025
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

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

.eslintrc.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"root": true,
3+
"env": {
4+
"es2021": true,
5+
"node": true
6+
},
7+
"parser": "@typescript-eslint/parser",
8+
"parserOptions": {
9+
"project": "./tsconfig.json",
10+
"sourceType": "module"
11+
},
12+
"plugins": ["@typescript-eslint"],
13+
"extends": [
14+
"eslint:recommended",
15+
"plugin:@typescript-eslint/recommended",
16+
"prettier"
17+
],
18+
"ignorePatterns": ["dist/", "node_modules/", "store/"],
19+
"rules": {
20+
"@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }]
21+
}
22+
}

.github/workflows/ci.yml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build
1+
name: CI
22

33
on:
44
pull_request:
@@ -9,29 +9,30 @@ on:
99
- master
1010

1111
jobs:
12-
autofix:
12+
ci:
1313
runs-on: ubuntu-latest
1414
concurrency:
15-
group: build-${{ github.ref_name }}
15+
group: ci-${{ github.ref_name }}
1616
cancel-in-progress: true
1717

1818
permissions:
1919
contents: read
2020

2121
steps:
22-
- name: Checkout repository
23-
uses: actions/checkout@v4
22+
- uses: actions/checkout@v4
23+
- uses: oven-sh/setup-bun@v2
2424

25-
- name: Setup Node.js
26-
uses: actions/setup-node@v4
27-
with:
28-
node-version: "22.x"
25+
- name: Install dependencies
26+
run: bun install
2927

30-
- name: Setup pnpm
31-
uses: pnpm/action-setup@v4
28+
- name: Check Types
29+
run: bun tsc
3230

33-
- name: Install dependencies for linting
34-
run: pnpm install --no-frozen-lockfile
31+
- name: Lint
32+
run: bun lint
3533

3634
- name: Run Build
37-
run: pnpm build
35+
run: bun run build
36+
37+
- name: Run Tests
38+
run: bun test

.github/workflows/lint.yml

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

.github/workflows/release.yml.old

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

.github/workflows/test.yml.old

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

.gitignore

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
# Project
2-
dist/
1+
# Node & Bun artifacts
32
node_modules/
4-
act.exe
5-
*.tgz
6-
.turbo
3+
dist/
4+
docs/
5+
.djs-core/
6+
7+
# Environment variables
8+
.env
79

8-
# IDE
9-
.vscode/
10-
.idea/
11-
DS_Store
10+
# Dev
11+
*.dev
12+
*.db
13+
djs-core-types.d.ts

.npmignore

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
src/
2+
examples/
3+
docs/
4+
tsconfig.json
5+
/index.ts
26
tests/
3-
playground/
7+
48
node_modules/
9+
.djs-generated/
10+
store/
511

612

7-
.vscode/
8-
.idea/
13+
.gitignore
914
.github/
10-
.DS_Store
11-
12-
header.txt
13-
tsconfig.json
14-
eslint.config.mjs
15+
.git/
16+
.cursor/
17+
.env
18+
eslint.config.js
19+
renovate.json
1520
.prettierrc
16-
.prettierignore
17-
jest.config.js
21+
.eslintrc.json

.prettierignore

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

0 commit comments

Comments
 (0)