Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Bun Adapter #5129

Merged
merged 10 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions @types/bun.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declare const Bun: {
fileURLToPath: (url: string) => string;
env: any;
file: (path: string) => {
text: () => Promise<string>;
stream: () => Promise<ReadableStream<Uint8Array>>;
};
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"devDependencies": {
"@builder.io/partytown": "^0.8.0",
"@clack/prompts": "^0.6.3",
"@clack/prompts": "^0.7.0",
"@microsoft/api-documenter": "^7.22.30",
"@microsoft/api-extractor": "7.36.3",
"@napi-rs/cli": "2.12.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-qwik/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"bin": "./create-qwik.cjs",
"bugs": "https://github.com/BuilderIO/qwik/issues",
"devDependencies": {
"@clack/prompts": "^0.6.3",
"@clack/prompts": "^0.7.0",
"@types/yargs": "17.0.24",
"kleur": "4.1.5",
"yargs": "17.7.2"
Expand Down
26 changes: 26 additions & 0 deletions packages/docs/public/ecosystem/bun.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions packages/docs/src/routes/(ecosystem)/ecosystem.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@
"href": "/docs/deployments/deno/",
"imgSrc": "/ecosystem/deno.svg"
},
{
"title": "Bun",
"href": "/docs/deployments/bun/",
"imgSrc": "/ecosystem/bun.svg"
},
{
"title": "Firebase",
"href": "/docs/deployments/firebase/",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "qwik-city-vite-bun-server",
"package": "@builder.io/qwik-city/vite/bun-server",
"members": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: \@builder.io/qwik-city/vite/bun-server API Reference
---

# [API](/api) &rsaquo; @builder.io/qwik-city/vite/bun-server
2 changes: 1 addition & 1 deletion packages/docs/src/routes/api/qwik-optimizer/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@
}
],
"kind": "TypeAlias",
"content": "```typescript\nexport type SystemEnvironment = 'node' | 'deno' | 'webworker' | 'browsermain' | 'unknown';\n```",
"content": "```typescript\nexport type SystemEnvironment = 'node' | 'deno' | 'bun' | 'webworker' | 'browsermain' | 'unknown';\n```",
"editUrl": "https://github.com/BuilderIO/qwik/tree/main/packages/qwik/src/optimizer/src/types.ts",
"mdFile": "qwik.systemenvironment.md"
},
Expand Down
1 change: 1 addition & 0 deletions packages/docs/src/routes/api/qwik-optimizer/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ export type SymbolMapperFn = (
export type SystemEnvironment =
| "node"
| "deno"
| "bun"
| "webworker"
| "browsermain"
| "unknown";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ export const onGet: RequestHandler = async ({

### `platform`

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

<CodeSandbox src="/src/routes/demo/qwikcity/middleware/platform/index.tsx">
```tsx
Expand Down
60 changes: 60 additions & 0 deletions packages/docs/src/routes/docs/deployments/bun/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
title: Bun Middleware | Deployments
contributors:
- EamonHeffernan
---

# Bun Middleware

Qwik City Bun middleware allows you to hook up Qwik City to a Bun server which uses the Bun Http API.

## Installation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we provide a link to the install guide of bun?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I've added much more detailed information about both the installation and the current issue with using bun install.


To install `bun` on Linux, OSX or WSL run the following command in your terminal

```shell
curl -fsSL https://bun.sh/install | bash
```

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).

There currently is an issue with using `bun` as the package manager.
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`.

```json
"trustedDependencies": [
"sharp"
]
```
This issue is currently being tracked [on the bun repository](https://github.com/oven-sh/bun/issues/3783).

To integrate the `bun` adapter, use the `add` command:

- For the [integrated HTTP server](https://bun.sh/docs/api/http):

```shell
bun run qwik add bun
```

## Production build

To build the application for production, use the `build` command, this command will automatically run `bun run build.server` and `bun run build.client`:

```shell
bun run build
```

## Serve

To start the Bun server after a build:

```shell
bun run serve
```

## Production deploy

Since you are choosing Bun, here you are in your own, after running `bun run build`:

- The `dist` folder will be created including all the static files.
- The `server` folder will be created including all bun server files.
1 change: 1 addition & 0 deletions packages/docs/src/routes/docs/menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
- [Google Cloud Run](deployments/gcp-cloud-run/index.mdx)
- [Cloudflare Pages](deployments/cloudflare-pages/index.mdx)
- [Deno](deployments/deno/index.mdx)
- [Bun](deployments/bun/index.mdx)
- [Netlify Edge](deployments/netlify-edge/index.mdx)
- [Node](deployments/node/index.mdx)
- [Vercel Edge](deployments/vercel-edge/index.mdx)
Expand Down
23 changes: 23 additions & 0 deletions packages/qwik-city/adapters/bun-server/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## API Report File for "@builder.io/qwik-city"

> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).

```ts

import { ServerAdapterOptions } from '../../shared/vite';
import type { StaticGenerateRenderOptions } from '@builder.io/qwik-city/static';

// @alpha (undocumented)
export function bunServerAdapter(opts?: bunServerAdapterOptions): any;

// @alpha (undocumented)
export interface bunServerAdapterOptions extends ServerAdapterOptions {
// (undocumented)
name?: string;
}

export { StaticGenerateRenderOptions }

// (No @packageDocumentation comment for this package)

```
19 changes: 19 additions & 0 deletions packages/qwik-city/adapters/bun-server/vite/api-extractor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"extends": "../../../api-extractor.json",
"mainEntryPointFilePath": "<projectFolder>/dist-dev/dts-out/packages/qwik-city/adapters/bun-server/vite/index.d.ts",
"apiReport": {
"enabled": true,
"reportFileName": "api.md",
"reportFolder": "<projectFolder>/packages/qwik-city/adapters/bun-server/",
"reportTempFolder": "<projectFolder>/dist-dev/api-extractor/qwik-city/adapters/bun-server"
},
"dtsRollup": {
"enabled": true,
"untrimmedFilePath": "<projectFolder>/packages/qwik-city/lib/adapters/bun-server/vite/index.d.ts"
},
"docModel": {
"enabled": true,
"apiJsonFilePath": "<projectFolder>/dist-dev/api/qwik-city/vite/bun-server/docs.api.json"
}
}
39 changes: 39 additions & 0 deletions packages/qwik-city/adapters/bun-server/vite/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import type { StaticGenerateRenderOptions } from '@builder.io/qwik-city/static';
import { viteAdapter, type ServerAdapterOptions } from '../../shared/vite';

/**
* @alpha
*/
export function bunServerAdapter(opts: bunServerAdapterOptions = {}): any {
const env = process?.env;
return viteAdapter({
name: opts.name || 'bun-server',
origin: env?.ORIGIN ?? env?.URL ?? 'https://yoursitename.qwik.builder.io',
ssg: opts.ssg,
cleanStaticGenerated: true,

config() {
return {
ssr: {
target: 'node',
},
build: {
ssr: true,
},
publicDir: false,
};
},
});
}

/**
* @alpha
*/
export interface bunServerAdapterOptions extends ServerAdapterOptions {
name?: string;
}

/**
* @alpha
*/
export type { StaticGenerateRenderOptions };
15 changes: 15 additions & 0 deletions packages/qwik-city/middleware/bun/api-extractor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"extends": "../../api-extractor.json",
"mainEntryPointFilePath": "<projectFolder>/dist-dev/dts-out/packages/qwik-city/middleware/bun/index.d.ts",
"apiReport": {
"enabled": true,
"reportFileName": "api.md",
"reportFolder": "<projectFolder>/packages/qwik-city/middleware/bun/",
"reportTempFolder": "<projectFolder>/dist-dev/api-extractor/qwik-city/middleware/bun"
},
"dtsRollup": {
"enabled": true,
"untrimmedFilePath": "<projectFolder>/packages/qwik-city/lib/middleware/bun/index.d.ts"
}
}
29 changes: 29 additions & 0 deletions packages/qwik-city/middleware/bun/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## API Report File for "@builder.io/qwik-city"

> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).

```ts

import type { ClientConn } from '@builder.io/qwik-city/middleware/request-handler';
import type { ServerRenderOptions } from '@builder.io/qwik-city/middleware/request-handler';

// @public (undocumented)
export function createQwikCity(opts: QwikCityBunOptions): {
router: (request: Request) => Promise<Response | null>;
notFound: (request: Request) => Promise<Response>;
staticFile: (request: Request) => Promise<Response | null>;
};

// @public (undocumented)
export interface QwikCityBunOptions extends ServerRenderOptions {
// (undocumented)
getClientConn?: (request: Request) => ClientConn;
static?: {
root?: string;
cacheControl?: string;
};
}

// (No @packageDocumentation comment for this package)

```
Loading