Skip to content

Commit f7585e3

Browse files
feat: Bun Adapter (#5129)
* Bun Adapter * Bun types * Update docs * Improved installation instructions for bun * cli cleanup * ✨ * Match the changes in the other pr * Update index.mdx * Update index.mdx --------- Co-authored-by: Roman Zanettin <roman.zanettin@gmail.com> Co-authored-by: roman zanettin <zanettin@users.noreply.github.com>
1 parent c037eaf commit f7585e3

File tree

45 files changed

+726
-105
lines changed

Some content is hidden

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

45 files changed

+726
-105
lines changed

@types/bun.d.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
declare const Bun: {
2+
fileURLToPath: (url: string) => string;
3+
env: any;
4+
file: (path: string) => {
5+
text: () => Promise<string>;
6+
stream: () => Promise<ReadableStream<Uint8Array>>;
7+
};
8+
};

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
},
2929
"devDependencies": {
3030
"@builder.io/partytown": "^0.8.0",
31-
"@clack/prompts": "^0.6.3",
31+
"@clack/prompts": "^0.7.0",
3232
"@microsoft/api-documenter": "^7.22.30",
3333
"@microsoft/api-extractor": "7.36.3",
3434
"@napi-rs/cli": "2.12.1",

packages/create-qwik/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"bin": "./create-qwik.cjs",
77
"bugs": "https://github.com/BuilderIO/qwik/issues",
88
"devDependencies": {
9-
"@clack/prompts": "^0.6.3",
9+
"@clack/prompts": "^0.7.0",
1010
"@types/yargs": "17.0.24",
1111
"kleur": "4.1.5",
1212
"yargs": "17.7.2"
+26
Loading

packages/docs/src/routes/(ecosystem)/ecosystem.json

+5
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@
9292
"href": "/docs/deployments/deno/",
9393
"imgSrc": "/ecosystem/deno.svg"
9494
},
95+
{
96+
"title": "Bun",
97+
"href": "/docs/deployments/bun/",
98+
"imgSrc": "/ecosystem/bun.svg"
99+
},
95100
{
96101
"title": "Firebase",
97102
"href": "/docs/deployments/firebase/",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"id": "qwik-city-vite-bun-server",
3+
"package": "@builder.io/qwik-city/vite/bun-server",
4+
"members": []
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: \@builder.io/qwik-city/vite/bun-server API Reference
3+
---
4+
5+
# [API](/api) &rsaquo; @builder.io/qwik-city/vite/bun-server

packages/docs/src/routes/api/qwik-optimizer/api.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@
644644
}
645645
],
646646
"kind": "TypeAlias",
647-
"content": "```typescript\nexport type SystemEnvironment = 'node' | 'deno' | 'webworker' | 'browsermain' | 'unknown';\n```",
647+
"content": "```typescript\nexport type SystemEnvironment = 'node' | 'deno' | 'bun' | 'webworker' | 'browsermain' | 'unknown';\n```",
648648
"editUrl": "https://github.com/BuilderIO/qwik/tree/main/packages/qwik/src/optimizer/src/types.ts",
649649
"mdFile": "qwik.systemenvironment.md"
650650
},

packages/docs/src/routes/api/qwik-optimizer/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,7 @@ export type SymbolMapperFn = (
645645
export type SystemEnvironment =
646646
| "node"
647647
| "deno"
648+
| "bun"
648649
| "webworker"
649650
| "browsermain"
650651
| "unknown";

packages/docs/src/routes/docs/(qwikcity)/middleware/index.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ export const onGet: RequestHandler = async ({
394394

395395
### `platform`
396396

397-
Deployment platform (Azure, Cloudflare, Deno, Google Cloud Run, Netlify, Node.js, Vercel, etc...) specific API.
397+
Deployment platform (Azure, Bun, Cloudflare, Deno, Google Cloud Run, Netlify, Node.js, Vercel, etc...) specific API.
398398

399399
<CodeSandbox src="/src/routes/demo/qwikcity/middleware/platform/index.tsx">
400400
```tsx
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
title: Bun Middleware | Deployments
3+
contributors:
4+
- EamonHeffernan
5+
---
6+
7+
# Bun Middleware
8+
9+
Qwik City Bun middleware allows you to hook up Qwik City to a Bun server which uses the Bun Http API.
10+
11+
## Installation
12+
13+
To install `bun` on Linux, OSX or WSL run the following command in your terminal
14+
15+
```shell
16+
curl -fsSL https://bun.sh/install | bash
17+
```
18+
19+
For other platforms or if you run into issues with installation, up to date `bun` installation instructions can be found [on the bun website](https://bun.sh/docs/installation).
20+
21+
There currently is an issue with using `bun` as the package manager.
22+
If you see the error `Something went wrong installing the "sharp" module` when using `bun` add the following code to your package.json, then remove the node_modules folder and any lockfiles such as bun.lockb or package-lock.json. You may then run `bun install`.
23+
24+
```json
25+
"trustedDependencies": [
26+
"sharp"
27+
]
28+
```
29+
This issue is currently being tracked [on the bun repository](https://github.com/oven-sh/bun/issues/3783).
30+
31+
To integrate the `bun` adapter, use the `add` command:
32+
33+
- For the [integrated HTTP server](https://bun.sh/docs/api/http):
34+
35+
```shell
36+
bun run qwik add bun
37+
```
38+
39+
## Production build
40+
41+
To build the application for production, use the `build` command, this command will automatically run `bun run build.server` and `bun run build.client`:
42+
43+
```shell
44+
bun run build
45+
```
46+
47+
## Serve
48+
49+
To start the Bun server after a build:
50+
51+
```shell
52+
bun run serve
53+
```
54+
55+
## Production deploy
56+
57+
Since you are choosing Bun, here you are in your own, after running `bun run build`:
58+
59+
- The `dist` folder will be created including all the static files.
60+
- The `server` folder will be created including all bun server files.

packages/docs/src/routes/docs/menu.md

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
- [Google Cloud Run](deployments/gcp-cloud-run/index.mdx)
7777
- [Cloudflare Pages](deployments/cloudflare-pages/index.mdx)
7878
- [Deno](deployments/deno/index.mdx)
79+
- [Bun](deployments/bun/index.mdx)
7980
- [Netlify Edge](deployments/netlify-edge/index.mdx)
8081
- [Node](deployments/node/index.mdx)
8182
- [Vercel Edge](deployments/vercel-edge/index.mdx)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## API Report File for "@builder.io/qwik-city"
2+
3+
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4+
5+
```ts
6+
7+
import { ServerAdapterOptions } from '../../shared/vite';
8+
import type { StaticGenerateRenderOptions } from '@builder.io/qwik-city/static';
9+
10+
// @alpha (undocumented)
11+
export function bunServerAdapter(opts?: bunServerAdapterOptions): any;
12+
13+
// @alpha (undocumented)
14+
export interface bunServerAdapterOptions extends ServerAdapterOptions {
15+
// (undocumented)
16+
name?: string;
17+
}
18+
19+
export { StaticGenerateRenderOptions }
20+
21+
// (No @packageDocumentation comment for this package)
22+
23+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3+
"extends": "../../../api-extractor.json",
4+
"mainEntryPointFilePath": "<projectFolder>/dist-dev/dts-out/packages/qwik-city/adapters/bun-server/vite/index.d.ts",
5+
"apiReport": {
6+
"enabled": true,
7+
"reportFileName": "api.md",
8+
"reportFolder": "<projectFolder>/packages/qwik-city/adapters/bun-server/",
9+
"reportTempFolder": "<projectFolder>/dist-dev/api-extractor/qwik-city/adapters/bun-server"
10+
},
11+
"dtsRollup": {
12+
"enabled": true,
13+
"untrimmedFilePath": "<projectFolder>/packages/qwik-city/lib/adapters/bun-server/vite/index.d.ts"
14+
},
15+
"docModel": {
16+
"enabled": true,
17+
"apiJsonFilePath": "<projectFolder>/dist-dev/api/qwik-city/vite/bun-server/docs.api.json"
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import type { StaticGenerateRenderOptions } from '@builder.io/qwik-city/static';
2+
import { viteAdapter, type ServerAdapterOptions } from '../../shared/vite';
3+
4+
/**
5+
* @alpha
6+
*/
7+
export function bunServerAdapter(opts: bunServerAdapterOptions = {}): any {
8+
const env = process?.env;
9+
return viteAdapter({
10+
name: opts.name || 'bun-server',
11+
origin: env?.ORIGIN ?? env?.URL ?? 'https://yoursitename.qwik.builder.io',
12+
ssg: opts.ssg,
13+
cleanStaticGenerated: true,
14+
15+
config() {
16+
return {
17+
ssr: {
18+
target: 'node',
19+
},
20+
build: {
21+
ssr: true,
22+
},
23+
publicDir: false,
24+
};
25+
},
26+
});
27+
}
28+
29+
/**
30+
* @alpha
31+
*/
32+
export interface bunServerAdapterOptions extends ServerAdapterOptions {
33+
name?: string;
34+
}
35+
36+
/**
37+
* @alpha
38+
*/
39+
export type { StaticGenerateRenderOptions };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3+
"extends": "../../api-extractor.json",
4+
"mainEntryPointFilePath": "<projectFolder>/dist-dev/dts-out/packages/qwik-city/middleware/bun/index.d.ts",
5+
"apiReport": {
6+
"enabled": true,
7+
"reportFileName": "api.md",
8+
"reportFolder": "<projectFolder>/packages/qwik-city/middleware/bun/",
9+
"reportTempFolder": "<projectFolder>/dist-dev/api-extractor/qwik-city/middleware/bun"
10+
},
11+
"dtsRollup": {
12+
"enabled": true,
13+
"untrimmedFilePath": "<projectFolder>/packages/qwik-city/lib/middleware/bun/index.d.ts"
14+
}
15+
}
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
## API Report File for "@builder.io/qwik-city"
2+
3+
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4+
5+
```ts
6+
7+
import type { ClientConn } from '@builder.io/qwik-city/middleware/request-handler';
8+
import type { ServerRenderOptions } from '@builder.io/qwik-city/middleware/request-handler';
9+
10+
// @public (undocumented)
11+
export function createQwikCity(opts: QwikCityBunOptions): {
12+
router: (request: Request) => Promise<Response | null>;
13+
notFound: (request: Request) => Promise<Response>;
14+
staticFile: (request: Request) => Promise<Response | null>;
15+
};
16+
17+
// @public (undocumented)
18+
export interface QwikCityBunOptions extends ServerRenderOptions {
19+
// (undocumented)
20+
getClientConn?: (request: Request) => ClientConn;
21+
static?: {
22+
root?: string;
23+
cacheControl?: string;
24+
};
25+
}
26+
27+
// (No @packageDocumentation comment for this package)
28+
29+
```

0 commit comments

Comments
 (0)