From de5d95f1a943a5872c0ed03e8d65118d81d5068b Mon Sep 17 00:00:00 2001 From: abearxiong Date: Sun, 9 Nov 2025 21:20:44 +0800 Subject: [PATCH] temp --- bun-server/bun.lock | 14 +++ bun-server/index.ts | 12 +++ bun-server/package.json | 17 ++++ bun-web/.gitignore | 34 +++++++ bun-web/CLAUDE.md | 106 +++++++++++++++++++++ bun-web/README.md | 21 +++++ bun-web/bun-env.d.ts | 17 ++++ bun-web/bun.lock | 38 ++++++++ bun-web/bunfig.toml | 2 + bun-web/package.json | 20 ++++ bun-web/src/APITester.tsx | 39 ++++++++ bun-web/src/App.tsx | 24 +++++ bun-web/src/frontend.tsx | 26 ++++++ bun-web/src/index.css | 187 ++++++++++++++++++++++++++++++++++++++ bun-web/src/index.html | 13 +++ bun-web/src/index.tsx | 41 +++++++++ bun-web/src/logo.svg | 1 + bun-web/src/react.svg | 8 ++ bun-web/tsconfig.json | 36 ++++++++ pnpm-workspace.yaml | 3 +- 20 files changed, 658 insertions(+), 1 deletion(-) create mode 100644 bun-server/bun.lock create mode 100644 bun-server/index.ts create mode 100644 bun-server/package.json create mode 100644 bun-web/.gitignore create mode 100644 bun-web/CLAUDE.md create mode 100644 bun-web/README.md create mode 100644 bun-web/bun-env.d.ts create mode 100644 bun-web/bun.lock create mode 100644 bun-web/bunfig.toml create mode 100644 bun-web/package.json create mode 100644 bun-web/src/APITester.tsx create mode 100644 bun-web/src/App.tsx create mode 100644 bun-web/src/frontend.tsx create mode 100644 bun-web/src/index.css create mode 100644 bun-web/src/index.html create mode 100644 bun-web/src/index.tsx create mode 100644 bun-web/src/logo.svg create mode 100644 bun-web/src/react.svg create mode 100644 bun-web/tsconfig.json diff --git a/bun-server/bun.lock b/bun-server/bun.lock new file mode 100644 index 0000000..7e2b89b --- /dev/null +++ b/bun-server/bun.lock @@ -0,0 +1,14 @@ +{ + "lockfileVersion": 1, + "workspaces": { + "": { + "name": "bun-server", + "dependencies": { + "es-toolkit": "^1.41.0", + }, + }, + }, + "packages": { + "es-toolkit": ["es-toolkit@1.41.0", "https://registry.npmmirror.com/es-toolkit/-/es-toolkit-1.41.0.tgz", {}, "sha512-bDd3oRmbVgqZCJS6WmeQieOrzpl3URcWBUVDXxOELlUW2FuW+0glPOz1n0KnRie+PdyvUZcXz2sOn00c6pPRIA=="], + } +} diff --git a/bun-server/index.ts b/bun-server/index.ts new file mode 100644 index 0000000..c782279 --- /dev/null +++ b/bun-server/index.ts @@ -0,0 +1,12 @@ +import { pick } from 'es-toolkit' + +const obj = { + a: { + b: { + c: 42 + } + } +} + +const c = pick(obj, ['a']) +console.log(c) // 42 \ No newline at end of file diff --git a/bun-server/package.json b/bun-server/package.json new file mode 100644 index 0000000..30a6a8a --- /dev/null +++ b/bun-server/package.json @@ -0,0 +1,17 @@ +{ + "name": "bun-server", + "version": "0.0.1", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "abearxiong (https://www.xiongxiao.me)", + "license": "MIT", + "packageManager": "pnpm@10.14.0", + "type": "module", + "dependencies": { + "es-toolkit": "^1.41.0" + } +} diff --git a/bun-web/.gitignore b/bun-web/.gitignore new file mode 100644 index 0000000..a14702c --- /dev/null +++ b/bun-web/.gitignore @@ -0,0 +1,34 @@ +# dependencies (bun install) +node_modules + +# output +out +dist +*.tgz + +# code coverage +coverage +*.lcov + +# logs +logs +_.log +report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json + +# dotenv environment variable files +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# caches +.eslintcache +.cache +*.tsbuildinfo + +# IntelliJ based IDEs +.idea + +# Finder (MacOS) folder config +.DS_Store diff --git a/bun-web/CLAUDE.md b/bun-web/CLAUDE.md new file mode 100644 index 0000000..1ee6890 --- /dev/null +++ b/bun-web/CLAUDE.md @@ -0,0 +1,106 @@ + +Default to using Bun instead of Node.js. + +- Use `bun ` instead of `node ` or `ts-node ` +- Use `bun test` instead of `jest` or `vitest` +- Use `bun build ` instead of `webpack` or `esbuild` +- Use `bun install` instead of `npm install` or `yarn install` or `pnpm install` +- Use `bun run + + +``` + +With the following `frontend.tsx`: + +```tsx#frontend.tsx +import React from "react"; + +// import .css files directly and it works +import './index.css'; + +import { createRoot } from "react-dom/client"; + +const root = createRoot(document.body); + +export default function Frontend() { + return

Hello, world!

; +} + +root.render(); +``` + +Then, run index.ts + +```sh +bun --hot ./index.ts +``` + +For more information, read the Bun API docs in `node_modules/bun-types/docs/**.md`. diff --git a/bun-web/README.md b/bun-web/README.md new file mode 100644 index 0000000..b3fefc1 --- /dev/null +++ b/bun-web/README.md @@ -0,0 +1,21 @@ +# bun-react-template + +To install dependencies: + +```bash +bun install +``` + +To start a development server: + +```bash +bun dev +``` + +To run for production: + +```bash +bun start +``` + +This project was created using `bun init` in bun v1.2.22. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime. diff --git a/bun-web/bun-env.d.ts b/bun-web/bun-env.d.ts new file mode 100644 index 0000000..72f1c26 --- /dev/null +++ b/bun-web/bun-env.d.ts @@ -0,0 +1,17 @@ +// Generated by `bun init` + +declare module "*.svg" { + /** + * A path to the SVG file + */ + const path: `${string}.svg`; + export = path; +} + +declare module "*.module.css" { + /** + * A record of class names to their corresponding CSS module classes + */ + const classes: { readonly [key: string]: string }; + export = classes; +} diff --git a/bun-web/bun.lock b/bun-web/bun.lock new file mode 100644 index 0000000..03aac14 --- /dev/null +++ b/bun-web/bun.lock @@ -0,0 +1,38 @@ +{ + "lockfileVersion": 1, + "workspaces": { + "": { + "name": "bun-react-template", + "dependencies": { + "react": "^19", + "react-dom": "^19", + }, + "devDependencies": { + "@types/bun": "latest", + "@types/react": "^19", + "@types/react-dom": "^19", + }, + }, + }, + "packages": { + "@types/bun": ["@types/bun@1.3.2", "https://registry.npmmirror.com/@types/bun/-/bun-1.3.2.tgz", { "dependencies": { "bun-types": "1.3.2" } }, "sha512-t15P7k5UIgHKkxwnMNkJbWlh/617rkDGEdSsDbu+qNHTaz9SKf7aC8fiIlUdD5RPpH6GEkP0cK7WlvmrEBRtWg=="], + + "@types/node": ["@types/node@24.10.0", "https://registry.npmmirror.com/@types/node/-/node-24.10.0.tgz", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-qzQZRBqkFsYyaSWXuEHc2WR9c0a0CXwiE5FWUvn7ZM+vdy1uZLfCunD38UzhuB7YN/J11ndbDBcTmOdxJo9Q7A=="], + + "@types/react": ["@types/react@19.2.2", "https://registry.npmmirror.com/@types/react/-/react-19.2.2.tgz", { "dependencies": { "csstype": "^3.0.2" } }, "sha512-6mDvHUFSjyT2B2yeNx2nUgMxh9LtOWvkhIU3uePn2I2oyNymUAX1NIsdgviM4CH+JSrp2D2hsMvJOkxY+0wNRA=="], + + "@types/react-dom": ["@types/react-dom@19.2.2", "https://registry.npmmirror.com/@types/react-dom/-/react-dom-19.2.2.tgz", { "peerDependencies": { "@types/react": "^19.2.0" } }, "sha512-9KQPoO6mZCi7jcIStSnlOWn2nEF3mNmyr3rIAsGnAbQKYbRLyqmeSc39EVgtxXVia+LMT8j3knZLAZAh+xLmrw=="], + + "bun-types": ["bun-types@1.3.2", "https://registry.npmmirror.com/bun-types/-/bun-types-1.3.2.tgz", { "dependencies": { "@types/node": "*" }, "peerDependencies": { "@types/react": "^19" } }, "sha512-i/Gln4tbzKNuxP70OWhJRZz1MRfvqExowP7U6JKoI8cntFrtxg7RJK3jvz7wQW54UuvNC8tbKHHri5fy74FVqg=="], + + "csstype": ["csstype@3.1.3", "https://registry.npmmirror.com/csstype/-/csstype-3.1.3.tgz", {}, "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw=="], + + "react": ["react@19.2.0", "https://registry.npmmirror.com/react/-/react-19.2.0.tgz", {}, "sha512-tmbWg6W31tQLeB5cdIBOicJDJRR2KzXsV7uSK9iNfLWQ5bIZfxuPEHp7M8wiHyHnn0DD1i7w3Zmin0FtkrwoCQ=="], + + "react-dom": ["react-dom@19.2.0", "https://registry.npmmirror.com/react-dom/-/react-dom-19.2.0.tgz", { "dependencies": { "scheduler": "^0.27.0" }, "peerDependencies": { "react": "^19.2.0" } }, "sha512-UlbRu4cAiGaIewkPyiRGJk0imDN2T3JjieT6spoL2UeSf5od4n5LB/mQ4ejmxhCFT1tYe8IvaFulzynWovsEFQ=="], + + "scheduler": ["scheduler@0.27.0", "https://registry.npmmirror.com/scheduler/-/scheduler-0.27.0.tgz", {}, "sha512-eNv+WrVbKu1f3vbYJT/xtiF5syA5HPIMtf9IgY/nKg0sWqzAUEvqY/xm7OcZc/qafLx/iO9FgOmeSAp4v5ti/Q=="], + + "undici-types": ["undici-types@7.16.0", "https://registry.npmmirror.com/undici-types/-/undici-types-7.16.0.tgz", {}, "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw=="], + } +} diff --git a/bun-web/bunfig.toml b/bun-web/bunfig.toml new file mode 100644 index 0000000..9819bf6 --- /dev/null +++ b/bun-web/bunfig.toml @@ -0,0 +1,2 @@ +[serve.static] +env = "BUN_PUBLIC_*" \ No newline at end of file diff --git a/bun-web/package.json b/bun-web/package.json new file mode 100644 index 0000000..3e7d68f --- /dev/null +++ b/bun-web/package.json @@ -0,0 +1,20 @@ +{ + "name": "bun-react-template", + "version": "0.1.0", + "private": true, + "type": "module", + "scripts": { + "dev": "bun --hot src/index.tsx", + "build": "bun build ./src/index.html --outdir=dist --sourcemap --target=browser --minify --define:process.env.NODE_ENV='\"production\"' --env='BUN_PUBLIC_*'", + "start": "NODE_ENV=production bun src/index.tsx" + }, + "dependencies": { + "react": "^19", + "react-dom": "^19" + }, + "devDependencies": { + "@types/react": "^19", + "@types/react-dom": "^19", + "@types/bun": "latest" + } +} diff --git a/bun-web/src/APITester.tsx b/bun-web/src/APITester.tsx new file mode 100644 index 0000000..fd2af48 --- /dev/null +++ b/bun-web/src/APITester.tsx @@ -0,0 +1,39 @@ +import { useRef, type FormEvent } from "react"; + +export function APITester() { + const responseInputRef = useRef(null); + + const testEndpoint = async (e: FormEvent) => { + e.preventDefault(); + + try { + const form = e.currentTarget; + const formData = new FormData(form); + const endpoint = formData.get("endpoint") as string; + const url = new URL(endpoint, location.href); + const method = formData.get("method") as string; + const res = await fetch(url, { method }); + + const data = await res.json(); + responseInputRef.current!.value = JSON.stringify(data, null, 2); + } catch (error) { + responseInputRef.current!.value = String(error); + } + }; + + return ( +
+
+ + + +
+