@flightdev/adapter-bun 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-2026 Flight Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,115 @@
1
+ # @flight-framework/adapter-bun
2
+
3
+ Bun runtime deployment adapter for Flight Framework. Ultra-fast builds and runtime performance.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Installation](#installation)
8
+ - [Quick Start](#quick-start)
9
+ - [Configuration](#configuration)
10
+ - [Build Output](#build-output)
11
+ - [Running in Production](#running-in-production)
12
+ - [Docker](#docker)
13
+ - [License](#license)
14
+
15
+ ---
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ bun add @flight-framework/adapter-bun
21
+ ```
22
+
23
+ ---
24
+
25
+ ## Quick Start
26
+
27
+ ```typescript
28
+ // flight.config.ts
29
+ import { defineConfig } from '@flight-framework/core';
30
+ import bun from '@flight-framework/adapter-bun';
31
+
32
+ export default defineConfig({
33
+ adapter: bun(),
34
+ });
35
+ ```
36
+
37
+ Build and run:
38
+
39
+ ```bash
40
+ bun run build
41
+ bun .output/server/index.ts
42
+ ```
43
+
44
+ ---
45
+
46
+ ## Configuration
47
+
48
+ ```typescript
49
+ bun({
50
+ // Host to bind
51
+ host: '0.0.0.0',
52
+
53
+ // Port to listen on
54
+ port: 3000,
55
+
56
+ // Enable compression
57
+ compression: true,
58
+
59
+ // Development mode features
60
+ development: process.env.NODE_ENV !== 'production',
61
+ });
62
+ ```
63
+
64
+ ---
65
+
66
+ ## Build Output
67
+
68
+ ```
69
+ .output/
70
+ ├── server/
71
+ │ ├── index.ts # Server entry (Bun-native)
72
+ │ └── chunks/ # Code-split chunks
73
+ └── client/
74
+ └── assets/ # Static files
75
+ ```
76
+
77
+ ---
78
+
79
+ ## Running in Production
80
+
81
+ ```bash
82
+ # Build
83
+ bun run build
84
+
85
+ # Start
86
+ bun .output/server/index.ts
87
+
88
+ # With environment variables
89
+ PORT=8080 bun .output/server/index.ts
90
+ ```
91
+
92
+ ---
93
+
94
+ ## Docker
95
+
96
+ ```dockerfile
97
+ FROM oven/bun:1 AS builder
98
+ WORKDIR /app
99
+ COPY package.json bun.lockb ./
100
+ RUN bun install --frozen-lockfile
101
+ COPY . .
102
+ RUN bun run build
103
+
104
+ FROM oven/bun:1-slim
105
+ WORKDIR /app
106
+ COPY --from=builder /app/.output .output
107
+ EXPOSE 3000
108
+ CMD ["bun", ".output/server/index.ts"]
109
+ ```
110
+
111
+ ---
112
+
113
+ ## License
114
+
115
+ MIT
@@ -0,0 +1,59 @@
1
+ import { FlightAdapter } from '@flightdev/core/adapters';
2
+
3
+ /**
4
+ * Flight Adapter - Bun
5
+ *
6
+ * Ultra-fast deployment with Bun runtime.
7
+ * Native TypeScript, blazing fast starts, built-in bundler.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { defineConfig } from '@flightdev/core';
12
+ * import bun from '@flightdev/adapter-bun';
13
+ *
14
+ * export default defineConfig({
15
+ * adapter: bun({
16
+ * port: 3000,
17
+ * development: false,
18
+ * }),
19
+ * });
20
+ * ```
21
+ */
22
+
23
+ interface BunAdapterOptions {
24
+ /**
25
+ * Server port
26
+ * @default 3000
27
+ */
28
+ port?: number;
29
+ /**
30
+ * Hostname to bind
31
+ * @default '0.0.0.0'
32
+ */
33
+ hostname?: string;
34
+ /**
35
+ * Enable development mode with hot reload
36
+ * @default false
37
+ */
38
+ development?: boolean;
39
+ /**
40
+ * Enable HTTPS with TLS
41
+ */
42
+ tls?: {
43
+ cert: string;
44
+ key: string;
45
+ };
46
+ /**
47
+ * Enable compression (gzip/brotli)
48
+ * @default true
49
+ */
50
+ compression?: boolean;
51
+ /**
52
+ * Max request body size in bytes
53
+ * @default 128 * 1024 * 1024 (128MB)
54
+ */
55
+ maxBodySize?: number;
56
+ }
57
+ declare function bunAdapter(options?: BunAdapterOptions): FlightAdapter;
58
+
59
+ export { type BunAdapterOptions, bunAdapter, bunAdapter as default };
package/dist/index.js ADDED
@@ -0,0 +1,194 @@
1
+ // src/index.ts
2
+ import { createAdapter } from "@flightdev/core/adapters";
3
+ function bunAdapter(options = {}) {
4
+ const {
5
+ port = 3e3,
6
+ hostname: _hostname = "localhost",
7
+ development = false,
8
+ tls: _tls,
9
+ compression: _compression = true,
10
+ maxBodySize: _maxBodySize = 1024 * 1024 * 10
11
+ } = options;
12
+ return createAdapter({
13
+ name: "@flightdev/adapter-bun",
14
+ async adapt(builder) {
15
+ const { outDir, log } = builder;
16
+ log.info("Generating Bun server...");
17
+ const serverCode = generateBunServer(options);
18
+ await builder.writeFile("server.ts", serverCode);
19
+ log.info("Created server.ts");
20
+ await builder.copy(`${outDir}/client`, "public");
21
+ log.info("Copied static assets to public/");
22
+ const bunConfig = `# Flight + Bun Configuration
23
+ [install]
24
+ production = true
25
+
26
+ [run]
27
+ # Hot reload in development
28
+ watch = ${development}
29
+ `;
30
+ await builder.writeFile("bunfig.toml", bunConfig);
31
+ log.info("Created bunfig.toml");
32
+ const dockerfile = generateBunDockerfile();
33
+ await builder.writeFile("Dockerfile", dockerfile);
34
+ log.info("Created Dockerfile");
35
+ log.info(`
36
+ Bun adapter complete!
37
+
38
+ To run:
39
+ bun run server.ts
40
+
41
+ To run in production:
42
+ bun run --production server.ts
43
+
44
+ With Docker:
45
+ docker build -t my-flight-app .
46
+ docker run -p ${port}:${port} my-flight-app
47
+ `);
48
+ },
49
+ emulate: () => ({
50
+ env: {
51
+ BUN_ENV: development ? "development" : "production"
52
+ }
53
+ }),
54
+ supports: {
55
+ read: () => true,
56
+ streaming: () => true,
57
+ websockets: () => true,
58
+ node: () => true,
59
+ // Bun has Node.js compatibility
60
+ edge: () => false
61
+ }
62
+ });
63
+ }
64
+ function generateBunServer(options) {
65
+ const { port = 3e3, hostname = "0.0.0.0", compression = true } = options;
66
+ return `
67
+ // Flight + Bun Server
68
+ // Ultra-fast runtime with native TypeScript support
69
+
70
+ const PORT = parseInt(Bun.env.PORT || "${port}");
71
+ const HOST = Bun.env.HOST || "${hostname}";
72
+ const PUBLIC_DIR = "./public";
73
+
74
+ // MIME types
75
+ const MIME_TYPES: Record<string, string> = {
76
+ '.html': 'text/html',
77
+ '.js': 'text/javascript',
78
+ '.css': 'text/css',
79
+ '.json': 'application/json',
80
+ '.png': 'image/png',
81
+ '.jpg': 'image/jpeg',
82
+ '.svg': 'image/svg+xml',
83
+ '.ico': 'image/x-icon',
84
+ '.woff': 'font/woff',
85
+ '.woff2': 'font/woff2',
86
+ };
87
+
88
+ const server = Bun.serve({
89
+ port: PORT,
90
+ hostname: HOST,
91
+ ${compression ? "development: true, // Enable compression" : ""}
92
+
93
+ async fetch(request: Request): Promise<Response> {
94
+ const url = new URL(request.url);
95
+ const pathname = url.pathname;
96
+
97
+ // Try to serve static files
98
+ const staticResponse = await serveStatic(pathname);
99
+ if (staticResponse) return staticResponse;
100
+
101
+ // TODO: Integrate with Flight render engine for SSR
102
+
103
+ return new Response(\`
104
+ <!DOCTYPE html>
105
+ <html>
106
+ <head><title>Flight on Bun</title></head>
107
+ <body>
108
+ <h1>Flight \u2708\uFE0F + Bun</h1>
109
+ <p>Path: \${pathname}</p>
110
+ <p>Bun version: \${Bun.version}</p>
111
+ <p>Ultra-fast TypeScript runtime!</p>
112
+ </body>
113
+ </html>
114
+ \`, {
115
+ headers: { 'Content-Type': 'text/html' },
116
+ });
117
+ },
118
+
119
+ error(error: Error): Response {
120
+ console.error('Server error:', error);
121
+ return new Response('Internal Server Error', { status: 500 });
122
+ },
123
+ });
124
+
125
+ async function serveStatic(pathname: string): Promise<Response | null> {
126
+ try {
127
+ const filePath = PUBLIC_DIR + pathname;
128
+ const file = Bun.file(filePath);
129
+
130
+ if (await file.exists()) {
131
+ const ext = pathname.slice(pathname.lastIndexOf('.'));
132
+ const contentType = MIME_TYPES[ext] || 'application/octet-stream';
133
+
134
+ return new Response(file, {
135
+ headers: {
136
+ 'Content-Type': contentType,
137
+ 'Cache-Control': 'public, max-age=31536000, immutable',
138
+ },
139
+ });
140
+ }
141
+ } catch {
142
+ // File not found
143
+ }
144
+ return null;
145
+ }
146
+
147
+ console.log(\`
148
+ \u2708\uFE0F Flight + Bun server running!
149
+
150
+ \u279C Local: http://localhost:\${PORT}/
151
+ \u279C Network: http://\${HOST}:\${PORT}/
152
+
153
+ Bun v\${Bun.version} - Ultra-fast TypeScript runtime
154
+ \`);
155
+
156
+ export default server;
157
+ `;
158
+ }
159
+ function generateBunDockerfile() {
160
+ return `# Flight + Bun Dockerfile
161
+ # Ultra-fast container with Bun runtime
162
+
163
+ FROM oven/bun:1 AS base
164
+ WORKDIR /app
165
+
166
+ # Install dependencies
167
+ FROM base AS install
168
+ COPY package.json bun.lockb* ./
169
+ RUN bun install --frozen-lockfile --production
170
+
171
+ # Build stage
172
+ FROM base AS build
173
+ COPY --from=install /app/node_modules ./node_modules
174
+ COPY . .
175
+ # Build if needed
176
+ # RUN bun run build
177
+
178
+ # Production image
179
+ FROM base AS production
180
+ COPY --from=install /app/node_modules ./node_modules
181
+ COPY --from=build /app/server.ts .
182
+ COPY --from=build /app/public ./public
183
+
184
+ ENV NODE_ENV=production
185
+ ENV PORT=3000
186
+ EXPOSE 3000
187
+
188
+ CMD ["bun", "run", "server.ts"]
189
+ `;
190
+ }
191
+ export {
192
+ bunAdapter,
193
+ bunAdapter as default
194
+ };
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@flightdev/adapter-bun",
3
+ "version": "0.0.6",
4
+ "description": "Bun adapter for Flight Framework - ultra-fast Bun runtime",
5
+ "keywords": [
6
+ "flight",
7
+ "adapter",
8
+ "bun",
9
+ "fast",
10
+ "runtime"
11
+ ],
12
+ "license": "MIT",
13
+ "type": "module",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js"
18
+ }
19
+ },
20
+ "main": "./dist/index.js",
21
+ "types": "./dist/index.d.ts",
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "dependencies": {
26
+ "@flightdev/core": "0.6.7"
27
+ },
28
+ "devDependencies": {
29
+ "@types/node": "^22.0.0",
30
+ "rimraf": "^6.0.0",
31
+ "tsup": "^8.0.0",
32
+ "typescript": "^5.7.0"
33
+ },
34
+ "scripts": {
35
+ "build": "tsup",
36
+ "dev": "tsup --watch",
37
+ "clean": "rimraf dist",
38
+ "typecheck": "tsc --noEmit"
39
+ }
40
+ }