Skip to content

Commit 33815df

Browse files
authored
Bun Example and Template (#1913)
## Summary Add a quick bun example and template in response to #1759 ## How was it tested? Localhost, could add testscript in the future
1 parent 4df5a62 commit 33815df

File tree

10 files changed

+339
-0
lines changed

10 files changed

+339
-0
lines changed
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
2+
3+
# Logs
4+
5+
logs
6+
_.log
7+
npm-debug.log_
8+
yarn-debug.log*
9+
yarn-error.log*
10+
lerna-debug.log*
11+
.pnpm-debug.log*
12+
13+
# Caches
14+
15+
.cache
16+
17+
# Diagnostic reports (https://nodejs.org/api/report.html)
18+
19+
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
20+
21+
# Runtime data
22+
23+
pids
24+
_.pid
25+
_.seed
26+
*.pid.lock
27+
28+
# Directory for instrumented libs generated by jscoverage/JSCover
29+
30+
lib-cov
31+
32+
# Coverage directory used by tools like istanbul
33+
34+
coverage
35+
*.lcov
36+
37+
# nyc test coverage
38+
39+
.nyc_output
40+
41+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
42+
43+
.grunt
44+
45+
# Bower dependency directory (https://bower.io/)
46+
47+
bower_components
48+
49+
# node-waf configuration
50+
51+
.lock-wscript
52+
53+
# Compiled binary addons (https://nodejs.org/api/addons.html)
54+
55+
build/Release
56+
57+
# Dependency directories
58+
59+
node_modules/
60+
jspm_packages/
61+
62+
# Snowpack dependency directory (https://snowpack.dev/)
63+
64+
web_modules/
65+
66+
# TypeScript cache
67+
68+
*.tsbuildinfo
69+
70+
# Optional npm cache directory
71+
72+
.npm
73+
74+
# Optional eslint cache
75+
76+
.eslintcache
77+
78+
# Optional stylelint cache
79+
80+
.stylelintcache
81+
82+
# Microbundle cache
83+
84+
.rpt2_cache/
85+
.rts2_cache_cjs/
86+
.rts2_cache_es/
87+
.rts2_cache_umd/
88+
89+
# Optional REPL history
90+
91+
.node_repl_history
92+
93+
# Output of 'npm pack'
94+
95+
*.tgz
96+
97+
# Yarn Integrity file
98+
99+
.yarn-integrity
100+
101+
# dotenv environment variable files
102+
103+
.env
104+
.env.development.local
105+
.env.test.local
106+
.env.production.local
107+
.env.local
108+
109+
# parcel-bundler cache (https://parceljs.org/)
110+
111+
.parcel-cache
112+
113+
# Next.js build output
114+
115+
.next
116+
out
117+
118+
# Nuxt.js build / generate output
119+
120+
.nuxt
121+
dist
122+
123+
# Gatsby files
124+
125+
# Comment in the public line in if your project uses Gatsby and not Next.js
126+
127+
# https://nextjs.org/blog/next-9-1#public-directory-support
128+
129+
# public
130+
131+
# vuepress build output
132+
133+
.vuepress/dist
134+
135+
# vuepress v2.x temp and cache directory
136+
137+
.temp
138+
139+
# Docusaurus cache and generated files
140+
141+
.docusaurus
142+
143+
# Serverless directories
144+
145+
.serverless/
146+
147+
# FuseBox cache
148+
149+
.fusebox/
150+
151+
# DynamoDB Local files
152+
153+
.dynamodb/
154+
155+
# TernJS port file
156+
157+
.tern-port
158+
159+
# Stores VSCode versions used for testing VSCode extensions
160+
161+
.vscode-test
162+
163+
# yarn v2
164+
165+
.yarn/cache
166+
.yarn/unplugged
167+
.yarn/build-state.yml
168+
.yarn/install-state.gz
169+
.pnp.*
170+
171+
# IntelliJ based IDEs
172+
.idea
173+
174+
# Finder (MacOS) folder config
175+
.DS_Store

examples/development/bun/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Bun
2+
3+
Bun projects can be run in Devbox by adding the Bun runtime + package manager to your project.
4+
5+
[**Example Repo**](https://github.com/jetpack-io/devbox/tree/main/examples/development/bun)
6+
7+
[![Open In Devbox.sh](https://jetpack.io/img/devbox/open-in-devbox.svg)](https://devbox.sh/open/templates/bun)
8+
9+
## Add Bun to your Project
10+
11+
```bash
12+
devbox add bun@latest
13+
```
14+
15+
You can see which versions of `bun` are available using:
16+
17+
```bash
18+
devbox search bun
19+
```
20+
21+
To update bun to the latest version:
22+
23+
```bash
24+
devbox update bun
25+
```
26+
27+
## Scripts
28+
29+
To install dependencies:
30+
31+
```bash
32+
devbox run bun install
33+
```
34+
35+
To start + watch your project:
36+
37+
```bash
38+
devbox run dev
39+
```
40+
41+
This project was created using `bun init` in bun v1.0.33. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.

examples/development/bun/bun.lockb

3.4 KB
Binary file not shown.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/jetpack-io/devbox/0.10.1/.schema/devbox.schema.json",
3+
"packages": ["bun@latest"],
4+
"shell": {
5+
"init_hook": [],
6+
"scripts": {
7+
"build": "bun build ./index.ts",
8+
"test": "bun test",
9+
"dev": "bun --watch run index.ts"
10+
}
11+
}
12+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"lockfile_version": "1",
3+
"packages": {
4+
"bun@latest": {
5+
"last_modified": "2024-03-18T21:18:48Z",
6+
"resolved": "github:NixOS/nixpkgs/ca00bc5e9419b97c1a11210f08f9338e6ba7515c#bun",
7+
"source": "devbox-search",
8+
"version": "1.0.33",
9+
"systems": {
10+
"aarch64-darwin": {
11+
"outputs": [
12+
{
13+
"name": "out",
14+
"path": "/nix/store/zz5pszqh3dpagdxqjj2vhy8g3v908x6j-bun-1.0.33",
15+
"default": true
16+
}
17+
],
18+
"store_path": "/nix/store/zz5pszqh3dpagdxqjj2vhy8g3v908x6j-bun-1.0.33"
19+
},
20+
"aarch64-linux": {
21+
"outputs": [
22+
{
23+
"name": "out",
24+
"path": "/nix/store/n77y6pv1wfjkky7hk5wsx8f9vr8yl229-bun-1.0.33",
25+
"default": true
26+
}
27+
],
28+
"store_path": "/nix/store/n77y6pv1wfjkky7hk5wsx8f9vr8yl229-bun-1.0.33"
29+
},
30+
"x86_64-darwin": {
31+
"outputs": [
32+
{
33+
"name": "out",
34+
"path": "/nix/store/kgd534jkcbym2pwmjmv4kd2ms1kywhxq-bun-1.0.33",
35+
"default": true
36+
}
37+
],
38+
"store_path": "/nix/store/kgd534jkcbym2pwmjmv4kd2ms1kywhxq-bun-1.0.33"
39+
},
40+
"x86_64-linux": {
41+
"outputs": [
42+
{
43+
"name": "out",
44+
"path": "/nix/store/n02lmxaxkfcnbpvfc9r4n6pb3sqgqqf7-bun-1.0.33",
45+
"default": true
46+
}
47+
],
48+
"store_path": "/nix/store/n02lmxaxkfcnbpvfc9r4n6pb3sqgqqf7-bun-1.0.33"
49+
}
50+
}
51+
}
52+
}
53+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { expect, test } from "bun:test";
2+
3+
test("2 + 2", () => {
4+
expect(2 + 2).toBe(4);
5+
});

examples/development/bun/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import figlet from 'figlet';
2+
3+
const server = Bun.serve({
4+
port: 3000,
5+
fetch(req) {
6+
const body = figlet.textSync("Bun!");
7+
return new Response(body);
8+
},
9+
});
10+
11+
console.log(`Listening on http://localhost:${server.port} ...`);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "bun",
3+
"module": "index.tx",
4+
"type": "module",
5+
"devDependencies": {
6+
"@types/bun": "latest"
7+
},
8+
"peerDependencies": {
9+
"typescript": "^5.0.0"
10+
},
11+
"dependencies": {
12+
"figlet": "^1.7.0"
13+
}
14+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"compilerOptions": {
3+
// Enable latest features
4+
"lib": ["ESNext"],
5+
"target": "ESNext",
6+
"module": "ESNext",
7+
"moduleDetection": "force",
8+
"jsx": "react-jsx",
9+
"allowJs": true,
10+
11+
// Bundler mode
12+
"moduleResolution": "bundler",
13+
"allowImportingTsExtensions": true,
14+
"verbatimModuleSyntax": true,
15+
"noEmit": true,
16+
17+
// Best practices
18+
"strict": true,
19+
"skipLibCheck": true,
20+
"noFallthroughCasesInSwitch": true,
21+
22+
// Some stricter flags (disabled by default)
23+
"noUnusedLocals": false,
24+
"noUnusedParameters": false,
25+
"noPropertyAccessFromIndexSignature": false
26+
}
27+
}

internal/templates/templates.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var popularTemplates = []string{
1919
var templates = map[string]string{
2020
"apache": "examples/servers/apache/",
2121
"argo": "examples/cloud_development/argo-workflows/",
22+
"bun": "examples/development/bun/",
2223
"caddy": "examples/servers/caddy/",
2324
"django": "examples/stacks/django/",
2425
"dotnet": "examples/development/csharp/hello-world/",

0 commit comments

Comments
 (0)