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>
This commit is contained in:
Eamon Heffernan
2023-09-19 05:04:44 +10:00
committed by GitHub
parent c037eafafd
commit f7585e3597
45 changed files with 726 additions and 105 deletions

8
@types/bun.d.ts vendored Normal file
View File

@@ -0,0 +1,8 @@
declare const Bun: {
fileURLToPath: (url: string) => string;
env: any;
file: (path: string) => {
text: () => Promise<string>;
stream: () => Promise<ReadableStream<Uint8Array>>;
};
};

View File

@@ -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",

View File

@@ -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"

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="256px" height="225px" viewBox="0 0 256 225" version="1.1" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid">
<title>bun</title>
<g>
<path d="M228.747342,65.5878481 C228.228861,65.036962 227.677975,64.4860759 227.127089,63.9675949 C226.576203,63.4491139 226.057722,62.8658228 225.506835,62.3473418 C224.955949,61.8288608 224.437468,61.2455696 223.886582,60.7270886 C223.335696,60.2086076 222.817215,59.6253165 222.266329,59.1068354 C221.715443,58.5883544 221.196962,58.0050633 220.646076,57.4865823 C220.09519,56.9681013 219.576709,56.3848101 219.025823,55.8663291 C218.474937,55.3478481 217.956456,54.764557 217.40557,54.2460759 C233.479011,70.0426328 242.687167,91.5322114 243.037975,114.065823 C243.037975,167.761013 188.532658,211.443038 121.518987,211.443038 C83.9939241,211.443038 50.4222785,197.735696 28.0951899,176.251139 L29.715443,177.871392 L31.3356962,179.491646 L32.9559494,181.111899 L34.5762025,182.732152 L36.1964557,184.352405 L37.8167089,185.972658 L39.436962,187.592911 C61.7316456,209.98481 96.0486076,224.405063 134.481013,224.405063 C201.494684,224.405063 256,180.723038 256,127.189873 C256,104.311899 246.148861,82.6329114 228.747342,65.5878481 Z" fill="#000000"></path>
<g>
<path d="M234.936709,114.065823 C234.936709,163.353924 184.157975,203.309367 121.518987,203.309367 C58.88,203.309367 8.10126582,163.353924 8.10126582,114.065823 C8.10126582,83.5078481 27.5443038,56.5144304 57.4217722,40.5063291 C87.2992405,24.4982278 105.899747,8.10126582 121.518987,8.10126582 C137.138228,8.10126582 150.489114,21.484557 185.616203,40.5063291 C215.493671,56.5144304 234.936709,83.5078481 234.936709,114.065823 Z" fill="#FBF0DF"></path>
<path d="M234.936709,114.065823 C234.92095,107.734124 234.048911,101.433644 232.344304,95.3356962 C223.497722,203.244557 91.8683544,208.429367 40.1174684,176.153924 C63.3811561,194.185313 92.088984,203.762208 121.518987,203.309367 C184.060759,203.309367 234.936709,163.289114 234.936709,114.065823 Z" fill="#F6DECE"></path>
<path d="M77.8693671,34.5762025 C92.3544304,25.8916456 111.603038,9.59189873 130.527595,9.55949367 C127.616276,8.61845016 124.578512,8.12672565 121.518987,8.10126582 C113.676962,8.10126582 105.316456,12.1518987 94.7848101,18.2440506 C91.123038,20.3827848 87.3316456,22.7483544 83.3134177,25.2111392 C75.763038,29.8774684 67.1108861,35.1594937 57.3893671,40.441519 C26.5397468,57.1301266 8.10126582,84.6420253 8.10126582,114.065823 C8.10126582,115.362025 8.10126582,116.658228 8.10126582,117.922025 C27.7387342,48.5427848 63.4167089,43.2607595 77.8693671,34.5762025 Z" fill="#FFFEFC"></path>
<path d="M112.186329,16.2997468 C112.278053,31.7831799 105.616661,46.5376311 93.9422785,56.7088608 C93.0349367,57.5189873 93.7478481,59.0744304 94.9144304,58.6207595 C105.834937,54.3756962 120.579241,41.6729114 114.357468,16.0405063 C114.098228,14.5822785 112.186329,14.9711392 112.186329,16.2997468 Z M119.542278,16.2997468 C127.566115,29.3917041 129.471751,45.3351299 124.759494,59.9493671 C124.370633,61.0835443 125.764051,62.0556962 126.541772,61.1159494 C133.638481,52.0425316 139.827848,34.0253165 121.292152,14.5822785 C120.352405,13.7397468 118.894177,15.0359494 119.542278,16.1701266 L119.542278,16.2997468 Z M128.486076,15.7488608 C141.049027,24.6429777 149.144791,38.5416906 150.683544,53.8572152 C150.615391,54.4238071 151.00415,54.9440779 151.566825,55.0392999 C152.129501,55.134522 152.667801,54.771138 152.789873,54.2136709 C155.771139,42.9043038 154.086076,23.6232911 129.555443,13.6101266 C128.259241,13.0916456 127.416709,14.841519 128.486076,15.6192405 L128.486076,15.7488608 Z M68.6663291,49.4501266 C83.6039833,44.9874805 95.9395495,34.383842 102.59443,20.2855696 C103.177722,19.1189873 105.02481,19.5726582 104.733165,20.8688608 C99.1270886,46.7929114 80.364557,52.204557 68.6987342,51.4916456 C67.4673418,51.5240506 67.4997468,49.8065823 68.6663291,49.4501266 Z" fill="#CCBEA7"></path>
<path d="M121.518987,211.443038 C54.5053165,211.443038 0,167.761013 0,114.065823 C0,81.6607595 20.0263291,51.4268354 53.5655696,33.3124051 C63.2870886,28.1275949 71.6151899,22.9103797 79.0359494,18.3412658 C83.1189873,15.8136709 86.9751899,13.4481013 90.7017722,11.244557 C102.075949,4.5043038 111.797468,0 121.518987,0 C131.240506,0 139.730633,3.88860759 150.359494,10.1751899 C153.6,12.0222785 156.840506,14.0313924 160.307848,16.2349367 C168.376709,21.2253165 177.482532,26.8637975 189.472405,33.3124051 C223.011646,51.4268354 243.037975,81.6283544 243.037975,114.065823 C243.037975,167.761013 188.532658,211.443038 121.518987,211.443038 Z M121.518987,8.10126582 C113.676962,8.10126582 105.316456,12.1518987 94.7848101,18.2440506 C91.123038,20.3827848 87.3316456,22.7483544 83.3134177,25.2111392 C75.763038,29.8774684 67.1108861,35.1594937 57.3893671,40.441519 C26.5397468,57.1301266 8.10126582,84.6420253 8.10126582,114.065823 C8.10126582,163.289114 58.9772152,203.341772 121.518987,203.341772 C184.060759,203.341772 234.936709,163.289114 234.936709,114.065823 C234.936709,84.6420253 216.498228,57.1301266 185.616203,40.5063291 C173.367089,34.0253165 163.807595,27.9331646 156.062785,23.1372152 C152.530633,20.9660759 149.290127,18.956962 146.341266,17.1746835 C136.522532,11.3417722 129.361013,8.10126582 121.518987,8.10126582 Z" fill="#000000"></path>
</g>
<g transform="translate(97.241876, 133.279793)">
<path d="M47.1226807,4.44172636 C45.6669472,10.4040245 42.3532397,15.74908 37.6604022,19.7045112 C34.1371951,23.1198314 29.5761979,25.2635001 24.6983769,25.7966631 C19.6740185,25.3480005 14.9529852,23.1989587 11.3150858,19.7045112 C6.6701778,15.7303732 3.40311412,10.3873628 1.98242754,4.44172636 C1.88701487,3.7264017 2.12798715,3.00718467 2.63509843,2.49373449 C3.14220972,1.98028432 3.85837793,1.73039661 4.5748326,1.81691623 L44.5626807,1.81691623 C45.2738527,1.74125781 45.9804395,1.99594814 46.4797913,2.50794181 C46.9791432,3.01993549 47.216092,3.73266774 47.1226807,4.44172636 L47.1226807,4.44172636 Z" fill="#B71422"></path>
<path d="M11.3150858,19.9637517 C14.9455746,23.4602176 19.6495528,25.6295279 24.6659718,26.1207137 C29.6709647,25.6224581 34.3624545,23.4536428 37.9844529,19.9637517 C39.1430506,18.8838441 40.2257884,17.7253146 41.2249592,16.4964099 C37.1902398,11.9191589 31.444861,9.21062322 25.3464782,9.01084028 C18.7926833,9.16604522 12.7343824,12.5344605 9.14394652,18.0194479 C9.88926298,18.6999542 10.5373642,19.3480555 11.3150858,19.9637517 Z" fill="#FF6164"></path>
<path d="M11.8335668,17.4037517 C15.0885475,13.1963755 20.09203,10.7125464 25.4112883,10.6634985 C30.2641696,10.8066282 34.8879216,12.7601635 38.3733136,16.1399542 C39.1186301,15.3298276 39.8315415,14.487296 40.5120478,13.6447643 C36.3895233,9.71862809 30.941417,7.48617688 25.249263,7.39058712 C19.089802,7.44370473 13.2769769,10.2490764 9.40318703,15.0381821 C10.1693703,15.8706288 10.9807201,16.6603426 11.8335668,17.4037517 L11.8335668,17.4037517 Z" fill="#000000"></path>
<path d="M24.5687566,27.7409669 C19.1688852,27.2678257 14.0873074,24.9839705 10.1485035,21.2599542 C5.13238447,17.0173554 1.6016649,11.2841934 0.0705288015,4.89539724 C-0.151852826,3.74343711 0.157751438,2.55265148 0.913060447,1.65489092 C1.81299919,0.568161768 3.1645387,-0.0418250921 4.5748326,0.00223268757 L44.5626807,0.00223268757 C45.9700686,-0.0274082757 47.3156254,0.579878411 48.2244529,1.65489092 C48.9725774,2.55599028 49.2706426,3.74825096 49.0345794,4.89539724 L49.0345794,4.89539724 C47.5034433,11.2841934 43.9727238,17.0173554 38.9566048,21.2599542 C35.026306,24.9773527 29.9572316,27.2607195 24.5687566,27.7409669 L24.5687566,27.7409669 Z M4.5748326,3.76122003 C4.05635159,3.76122003 3.92673133,3.98805547 3.89432627,4.0528656 C5.26412049,9.5930665 8.36270541,14.5530724 12.7409085,18.2138783 C15.9424073,21.3680086 20.1048328,23.363692 24.5687566,23.8847643 C29.0211539,23.3695838 33.1789271,21.3989132 36.3966048,18.2786884 C40.7611007,14.611682 43.8476364,9.65279947 45.210782,4.11767573 C45.0667036,3.90641264 44.8163516,3.79375422 44.5626807,3.82603016 L4.5748326,3.76122003 Z" fill="#000000"></path>
</g>
<g transform="translate(53.792405, 88.400517)">
<ellipse fill="#FEBBD0" cx="117.047089" cy="40.1827746" rx="18.956962" ry="11.1473418"></ellipse>
<ellipse fill="#FEBBD0" cx="18.956962" cy="40.1827746" rx="18.956962" ry="11.1473418"></ellipse>
<path d="M27.8683544,35.7109055 C35.093039,35.7239878 41.6136279,31.3820336 44.3874852,24.711055 C47.1613425,18.0400764 45.6417372,10.3549319 40.5377474,5.24166207 C35.4337576,0.12839229 27.7513862,-1.4051707 21.0753798,1.35656396 C14.3993734,4.11829861 10.0455696,10.6309895 10.0455696,17.855686 C10.0455696,27.7041939 18.0198627,35.693002 27.8683544,35.7109055 L27.8683544,35.7109055 Z M108.135696,35.7108759 C115.36901,35.7633877 121.919337,31.4465623 124.723868,24.7788644 C127.528399,18.1111666 126.032946,10.4101683 120.936753,5.27670874 C115.84056,0.143249186 108.150662,-1.40827319 101.462707,1.34760374 C94.7747529,4.10348068 90.410096,10.6221813 90.410096,17.855686 C90.3921296,27.6737362 98.3177754,35.6573393 108.135696,35.7108759 L108.135696,35.7108759 Z" fill="#000000"></path>
<path d="M22.3594937,18.989942 C25.0754753,19.002984 27.531328,17.3770145 28.5797934,14.8715307 C29.6282588,12.3660469 29.06239,9.47558299 27.1465343,7.55042702 C25.2306786,5.62527104 22.3429888,5.04541162 19.8324572,6.08173168 C17.3219255,7.11805175 15.6840506,9.56600172 15.6840506,12.2820151 C15.6840506,15.9740391 18.6675127,18.9720273 22.3594937,18.989942 Z M102.626835,18.989942 C105.342817,19.002984 107.79867,17.3770145 108.847135,14.8715307 C109.895601,12.3660469 109.329732,9.47558299 107.413876,7.55042702 C105.49802,5.62527104 102.610331,5.04541162 100.099799,6.08173168 C97.5892672,7.11805175 95.9513924,9.56600172 95.9513924,12.2820151 C95.9510073,15.9490221 98.8954034,18.9367182 102.562025,18.989942 L102.626835,18.989942 Z" fill="#FFFFFF"></path>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 9.9 KiB

View File

@@ -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/",

View File

@@ -0,0 +1,5 @@
{
"id": "qwik-city-vite-bun-server",
"package": "@builder.io/qwik-city/vite/bun-server",
"members": []
}

View File

@@ -0,0 +1,5 @@
---
title: \@builder.io/qwik-city/vite/bun-server API Reference
---
# [API](/api) &rsaquo; @builder.io/qwik-city/vite/bun-server

View File

@@ -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"
},

View File

@@ -645,6 +645,7 @@ export type SymbolMapperFn = (
export type SystemEnvironment =
| "node"
| "deno"
| "bun"
| "webworker"
| "browsermain"
| "unknown";

View File

@@ -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

View File

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

View File

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

View File

@@ -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)
```

View File

@@ -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"
}
}

View File

@@ -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 };

View File

@@ -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"
}
}

View File

@@ -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)
```

View File

@@ -0,0 +1,167 @@
import type {
ServerRenderOptions,
ServerRequestEvent,
ClientConn,
} from '@builder.io/qwik-city/middleware/request-handler';
import {
mergeHeadersCookies,
requestHandler,
} from '@builder.io/qwik-city/middleware/request-handler';
import { getNotFound } from '@qwik-city-not-found-paths';
import { isStaticPath } from '@qwik-city-static-paths';
import { _deserializeData, _serializeData, _verifySerializable } from '@builder.io/qwik';
import { setServerPlatform } from '@builder.io/qwik/server';
import { MIME_TYPES } from '../request-handler/mime-types';
import { join, extname } from 'node:path';
// @builder.io/qwik-city/middleware/bun
/**
* @public
*/
export function createQwikCity(opts: QwikCityBunOptions) {
const qwikSerializer = {
_deserializeData,
_serializeData,
_verifySerializable,
};
if (opts.manifest) {
setServerPlatform(opts.manifest);
}
const staticFolder =
opts.static?.root ?? join(Bun.fileURLToPath(import.meta.url), '..', '..', 'dist');
async function router(request: Request) {
try {
const url = new URL(request.url);
const serverRequestEv: ServerRequestEvent<Response> = {
mode: 'server',
locale: undefined,
url,
env: Bun.env,
request,
getWritableStream: (status, headers, cookies, resolve) => {
const { readable, writable } = new TransformStream<Uint8Array>();
const response = new Response(readable, {
status,
headers: mergeHeadersCookies(headers, cookies),
});
resolve(response);
return writable;
},
platform: {
ssr: true,
},
getClientConn: () => {
return opts.getClientConn ? opts.getClientConn(request) : {};
},
};
// send request to qwik city request handler
const handledResponse = await requestHandler(serverRequestEv, opts, qwikSerializer);
if (handledResponse) {
handledResponse.completion.then((v) => {
if (v) {
console.error(v);
}
});
const response = await handledResponse.response;
if (response) {
return response;
}
}
// qwik city did not have a route for this request
return null;
} catch (e: any) {
console.error(e);
return new Response(String(e || 'Error'), {
status: 500,
headers: { 'Content-Type': 'text/plain; charset=utf-8', 'X-Error': 'bun-server' },
});
}
}
const notFound = async (request: Request) => {
try {
const url = new URL(request.url);
const notFoundHtml = getNotFound(url.pathname);
return new Response(notFoundHtml, {
status: 404,
headers: { 'Content-Type': 'text/html; charset=utf-8', 'X-Not-Found': url.pathname },
});
} catch (e) {
console.error(e);
return new Response(String(e || 'Error'), {
status: 500,
headers: { 'Content-Type': 'text/plain; charset=utf-8', 'X-Error': 'bun-server' },
});
}
};
const openStaticFile = async (url: URL) => {
const pathname = url.pathname;
const fileName = pathname.slice(url.pathname.lastIndexOf('/'));
let filePath: string;
if (fileName.includes('.')) {
filePath = join(staticFolder, pathname);
} else if (opts.qwikCityPlan.trailingSlash) {
filePath = join(staticFolder, pathname + 'index.html');
} else {
filePath = join(staticFolder, pathname, 'index.html');
}
return {
filePath,
content: Bun.file(filePath),
};
};
const staticFile = async (request: Request) => {
try {
const url = new URL(request.url);
if (isStaticPath(request.method || 'GET', url)) {
const { filePath, content } = await openStaticFile(url);
const ext = extname(filePath).replace(/^\./, '');
return new Response(await content.stream(), {
status: 200,
headers: {
'content-type': MIME_TYPES[ext] || 'text/plain; charset=utf-8',
'Cache-Control': opts.static?.cacheControl || 'max-age=3600',
},
});
}
return null;
} catch (e) {
console.error(e);
return new Response(String(e || 'Error'), {
status: 500,
headers: { 'Content-Type': 'text/plain; charset=utf-8', 'X-Error': 'bun-server' },
});
}
};
return {
router,
notFound,
staticFile,
};
}
/**
* @public
*/
export interface QwikCityBunOptions extends ServerRenderOptions {
/** Options for serving static files */
static?: {
/** The root folder for statics files. Defaults to /dist */
root?: string;
/** Set the Cache-Control header for all static files */
cacheControl?: string;
};
getClientConn?: (request: Request) => ClientConn;
}

View File

@@ -63,6 +63,10 @@
"import": "./lib/adapters/cloud-run/vite/index.mjs",
"require": "./lib/adapters/cloud-run/vite/index.cjs"
},
"./adapters/bun-server/vite": {
"import": "./lib/adapters/bun-server/vite/index.mjs",
"require": "./lib/adapters/bun-server/vite/index.cjs"
},
"./adapters/deno-server/vite": {
"import": "./lib/adapters/deno-server/vite/index.mjs",
"require": "./lib/adapters/deno-server/vite/index.cjs"
@@ -96,6 +100,9 @@
"./middleware/deno": {
"import": "./lib/middleware/deno/index.mjs"
},
"./middleware/bun": {
"import": "./lib/middleware/bun/index.mjs"
},
"./middleware/netlify-edge": {
"import": "./lib/middleware/netlify-edge/index.mjs"
},

View File

@@ -23,7 +23,7 @@ function getEntryModulePath() {
if (isDeno()) {
return './deno.mjs';
}
if (isNode()) {
if (isNode() || isBun()) {
if (isCjs()) {
return './node.cjs';
}
@@ -44,8 +44,12 @@ function isDeno() {
return typeof Deno !== 'undefined';
}
function isBun() {
return typeof Bun !== 'undefined';
}
function isNode() {
return !isDeno() && typeof process !== 'undefined' && !!process.versions?.node;
return !isBun() && !isDeno() && typeof process !== 'undefined' && !!process.versions?.node;
}
function isCjs() {
@@ -54,3 +58,4 @@ function isCjs() {
}
declare const Deno: any;
declare const Bun: any;

View File

@@ -1,14 +1,15 @@
import type { IntegrationData, UpdateAppResult } from '../types';
import { bgBlue, bgMagenta, blue, bold, cyan, magenta } from 'kleur/colors';
import { bye, getPackageManager, note, panic, printHeader } from '../utils/utils';
import { intro, isCancel, log, outro, select, spinner } from '@clack/prompts';
import { loadIntegrations, sortIntegrationsAndReturnAsClackOptions } from '../utils/integrations';
/* eslint-disable no-console */
import type { AppCommand } from '../utils/app-command';
import { loadIntegrations, sortIntegrationsAndReturnAsClackOptions } from '../utils/integrations';
import { bgBlue, bold, magenta, cyan, bgMagenta, green } from 'kleur/colors';
import { bye, getPackageManager, panic, printHeader, note } from '../utils/utils';
import { updateApp } from './update-app';
import type { IntegrationData, UpdateAppResult } from '../types';
import { relative } from 'node:path';
import { logNextStep } from '../utils/log';
import { relative } from 'node:path';
import { runInPkg } from '../utils/install-deps';
import { intro, isCancel, select, log, spinner, outro } from '@clack/prompts';
import { updateApp } from './update-app';
export async function runAddInteractive(app: AppCommand, id: string | undefined) {
const pkgManager = getPackageManager();
@@ -167,9 +168,9 @@ async function logUpdateAppResult(pkgManager: string, result: UpdateAppResult) {
function logUpdateAppCommitResult(result: UpdateAppResult, pkgManager: string) {
if (result.updates.installedScripts.length > 0) {
const prefix = pkgManager === 'npm' ? 'npm run' : pkgManager;
const prefix = pkgManager === 'npm' || pkgManager === 'bun' ? `${pkgManager} run` : pkgManager;
const message = result.updates.installedScripts
.map((script) => ` - ${prefix} ${green(script)}`)
.map((script) => `- ${prefix} ${blue(script)}`)
.join('\n');
note(message, 'New scripts added');
}

View File

@@ -1,5 +1,5 @@
import { cyan } from 'kleur/colors';
import type { NextSteps } from '../types';
import { cyan } from 'kleur/colors';
export function logSuccessFooter(docs: string[]) {
const outString = [];
@@ -26,7 +26,7 @@ export function logNextStep(nextSteps: NextSteps | undefined, packageManager: st
const outString: string[] = [];
if (nextSteps) {
nextSteps.lines.forEach((step) =>
outString.push(` ${step.replace(/\bpnpm\b/g, packageManager)}`)
outString.push(`${step.replace(/\bpnpm\b/g, packageManager)}`)
);
}
return outString.join('\n');

View File

@@ -1,11 +1,12 @@
import { blue, gray, green, magenta, red, reset, white } from 'kleur/colors';
import { log, outro } from '@clack/prompts';
import type { ChildProcess } from 'node:child_process';
import type { IntegrationPackageJson } from '../types';
import detectPackageManager from 'which-pm-runs';
import fs from 'node:fs';
import { join } from 'node:path';
import { red, blue, magenta, white, gray, reset, green } from 'kleur/colors';
import { log, outro } from '@clack/prompts';
import spawn from 'cross-spawn';
import type { ChildProcess } from 'node:child_process';
import detectPackageManager from 'which-pm-runs';
import type { IntegrationPackageJson } from '../types';
export function runCommand(cmd: string, args: string[], cwd: string) {
let child: ChildProcess;
@@ -182,7 +183,35 @@ export async function getFilesDeep(root: string) {
return files;
}
// Used from https://github.com/sindresorhus/is-unicode-supported/blob/main/index.js
export default function isUnicodeSupported() {
if (process.platform !== 'win32') {
return process.env.TERM !== 'linux'; // Linux console (kernel)
}
return (
Boolean(process.env.CI) ||
Boolean(process.env.WT_SESSION) || // Windows Terminal
Boolean(process.env.TERMINUS_SUBLIME) || // Terminus (<0.2.27)
process.env.ConEmuTask === '{cmd::Cmder}' || // ConEmu and cmder
process.env.TERM_PROGRAM === 'Terminus-Sublime' ||
process.env.TERM_PROGRAM === 'vscode' ||
process.env.TERM === 'xterm-256color' ||
process.env.TERM === 'alacritty' ||
process.env.TERMINAL_EMULATOR === 'JetBrains-JediTerm'
);
}
// Used from https://github.com/natemoo-re/clack/blob/main/packages/prompts/src/index.ts
const unicode = isUnicodeSupported();
const s = (c: string, fallback: string) => (unicode ? c : fallback);
const S_BAR = s('│', '|');
const S_BAR_H = s('─', '-');
const S_CORNER_TOP_RIGHT = s('╮', '+');
const S_CONNECT_LEFT = s('├', '+');
const S_CORNER_BOTTOM_RIGHT = s('╯', '+');
const S_STEP_SUBMIT = s('◇', 'o');
function ansiRegex() {
const pattern = [
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
@@ -192,23 +221,25 @@ function ansiRegex() {
return new RegExp(pattern, 'g');
}
const bar = '│';
const strip = (str: string) => str.replace(ansiRegex(), '');
export const note = (message = '', title = '') => {
const lines = `\n${message}\n`.split('\n');
const titleLen = strip(title).length;
const len =
lines.reduce((sum, ln) => {
ln = strip(ln);
return ln.length > sum ? ln.length : sum;
}, 0) + 2;
Math.max(
lines.reduce((sum, ln) => {
ln = strip(ln);
return ln.length > sum ? ln.length : sum;
}, 0),
titleLen
) + 2;
const msg = lines
.map((ln) => `${gray(bar)} ${white(ln)}${' '.repeat(len - strip(ln).length)}${gray(bar)}`)
.map((ln) => `${gray(S_BAR)} ${white(ln)}${' '.repeat(len - strip(ln).length)}${gray(S_BAR)}`)
.join('\n');
process.stdout.write(
`${gray(bar)}\n${green('○')} ${reset(title)} ${gray(
'─'.repeat(len - title.length - 1) + '╮'
)}\n${msg}\n${gray('├' + '─'.repeat(len + 2) + '╯')}\n`
`${gray(S_BAR)}\n${green(S_STEP_SUBMIT)} ${reset(title)} ${gray(
S_BAR_H.repeat(Math.max(len - titleLen - 1, 1)) + S_CORNER_TOP_RIGHT
)}\n${msg}\n${gray(S_CONNECT_LEFT + S_BAR_H.repeat(len + 2) + S_CORNER_BOTTOM_RIGHT)}\n`
);
};
// End of used code from clack

View File

@@ -369,7 +369,7 @@ export type SymbolMapper = Record<string, readonly [symbol: string, chunk: strin
export type SymbolMapperFn = (symbolName: string, mapper: SymbolMapper | undefined) => readonly [symbol: string, chunk: string] | undefined;
// @public (undocumented)
export type SystemEnvironment = 'node' | 'deno' | 'webworker' | 'browsermain' | 'unknown';
export type SystemEnvironment = 'node' | 'deno' | 'bun' | 'webworker' | 'browsermain' | 'unknown';
// @public (undocumented)
export interface TransformFsOptions extends TransformOptions {

View File

@@ -265,6 +265,10 @@ const getEnv = (): SystemEnvironment => {
return 'deno';
}
if (typeof Bun !== 'undefined') {
return 'bun';
}
if (
typeof process !== 'undefined' &&
typeof global !== 'undefined' &&
@@ -310,3 +314,4 @@ const extensions: { [ext: string]: boolean } = {
declare const globalThis: { IS_CJS: boolean; IS_ESM: boolean; [key: string]: any };
declare const WorkerGlobalScope: any;
declare const Deno: any;
declare const Bun: any;

View File

@@ -53,7 +53,7 @@ export interface OptimizerSystem {
/**
* @public
*/
export type SystemEnvironment = 'node' | 'deno' | 'webworker' | 'browsermain' | 'unknown';
export type SystemEnvironment = 'node' | 'deno' | 'bun' | 'webworker' | 'browsermain' | 'unknown';
// OPTIONS ***************

78
pnpm-lock.yaml generated
View File

@@ -19,8 +19,8 @@ importers:
specifier: ^0.8.0
version: 0.8.0
'@clack/prompts':
specifier: ^0.6.3
version: 0.6.3
specifier: ^0.7.0
version: 0.7.0
'@microsoft/api-documenter':
specifier: ^7.22.30
version: 7.22.30(@types/node@20.4.5)
@@ -196,8 +196,8 @@ importers:
packages/create-qwik:
devDependencies:
'@clack/prompts':
specifier: ^0.6.3
version: 0.6.3
specifier: ^0.7.0
version: 0.7.0
'@types/yargs':
specifier: 17.0.24
version: 17.0.24
@@ -221,19 +221,19 @@ importers:
version: 0.8.0
'@builder.io/qwik':
specifier: github:BuilderIo/qwik-build#main
version: github.com/BuilderIo/qwik-build/4d4509af4baf2ef88a99c4280ba24dd22d2a7110(undici@5.22.1)
version: github.com/BuilderIo/qwik-build/48c1524f9b8dc7a356b1694e5468d389aee7daca(undici@5.22.1)
'@builder.io/qwik-city':
specifier: github:BuilderIo/qwik-city-build#main
version: github.com/BuilderIo/qwik-city-build/da90f34fa48e1ed2f846120997f86310480c4c22(rollup@3.26.3)
version: github.com/BuilderIo/qwik-city-build/80b973155c27bf23f16aaf6430aa6bc3170ce414(rollup@3.26.3)
'@builder.io/qwik-labs':
specifier: github:BuilderIo/qwik-labs-build#a487845dd5039e3e178f69755f603cbc2edef2c2
version: github.com/BuilderIo/qwik-labs-build/a487845dd5039e3e178f69755f603cbc2edef2c2
'@builder.io/qwik-react':
specifier: 0.5.0
version: 0.5.0(@builder.io/qwik@1.2.10)(@types/react-dom@18.2.7)(@types/react@18.2.17)(react-dom@18.2.0)(react@18.2.0)
version: 0.5.0(@builder.io/qwik@1.2.11)(@types/react-dom@18.2.7)(@types/react@18.2.17)(react-dom@18.2.0)(react@18.2.0)
'@builder.io/sdk-qwik':
specifier: ^0.4.5
version: 0.4.5(@builder.io/qwik@1.2.10)
version: 0.4.5(@builder.io/qwik@1.2.11)
'@docsearch/css':
specifier: 3.3.4
version: 3.3.4
@@ -245,7 +245,7 @@ importers:
version: 11.11.0(@emotion/react@11.11.1)(@types/react@18.2.17)(react@18.2.0)
'@modular-forms/qwik':
specifier: ^0.12.0
version: 0.12.0(@builder.io/qwik-city@1.2.10-dev20230911173253)(@builder.io/qwik@1.2.10)
version: 0.12.0(@builder.io/qwik-city@1.2.11-dev20230915194738)(@builder.io/qwik@1.2.11)
'@mui/material':
specifier: ^5.13.0
version: 5.13.0(@emotion/react@11.11.1)(@emotion/styled@11.11.0)(@types/react@18.2.17)(react-dom@18.2.0)(react@18.2.0)
@@ -269,7 +269,7 @@ importers:
version: 0.0.28
'@unpic/qwik':
specifier: ^0.0.24
version: 0.0.24(@builder.io/qwik@1.2.10)
version: 0.0.24(@builder.io/qwik@1.2.11)
algoliasearch:
specifier: 4.16.0
version: 4.16.0
@@ -372,13 +372,13 @@ importers:
version: 0.7.1
'@builder.io/qwik-auth':
specifier: 0.1.0
version: 0.1.0(@auth/core@0.7.1)(@builder.io/qwik-city@1.2.10-dev20230911173253)(@builder.io/qwik@1.2.10)
version: 0.1.0(@auth/core@0.7.1)(@builder.io/qwik-city@1.2.11-dev20230915194738)(@builder.io/qwik@1.2.11)
'@libsql/client':
specifier: ^0.3.1
version: 0.3.1
'@modular-forms/qwik':
specifier: ^0.12.0
version: 0.12.0(@builder.io/qwik-city@1.2.10-dev20230911173253)(@builder.io/qwik@1.2.10)
version: 0.12.0(@builder.io/qwik-city@1.2.11-dev20230915194738)(@builder.io/qwik@1.2.11)
'@typescript/analyze-trace':
specifier: ^0.10.0
version: 0.10.0
@@ -400,10 +400,10 @@ importers:
devDependencies:
'@builder.io/qwik':
specifier: github:BuilderIo/qwik-build#main
version: github.com/BuilderIo/qwik-build/4d4509af4baf2ef88a99c4280ba24dd22d2a7110(undici@5.22.1)
version: github.com/BuilderIo/qwik-build/48c1524f9b8dc7a356b1694e5468d389aee7daca(undici@5.22.1)
'@builder.io/qwik-city':
specifier: github:BuilderIo/qwik-city-build#main
version: github.com/BuilderIo/qwik-city-build/da90f34fa48e1ed2f846120997f86310480c4c22(rollup@3.26.3)
version: github.com/BuilderIo/qwik-city-build/80b973155c27bf23f16aaf6430aa6bc3170ce414(rollup@3.26.3)
'@builder.io/qwik-labs':
specifier: workspace:*
version: link:../qwik-labs
@@ -1317,7 +1317,7 @@ packages:
hasBin: true
dev: true
/@builder.io/qwik-auth@0.1.0(@auth/core@0.7.1)(@builder.io/qwik-city@1.2.10-dev20230911173253)(@builder.io/qwik@1.2.10):
/@builder.io/qwik-auth@0.1.0(@auth/core@0.7.1)(@builder.io/qwik-city@1.2.11-dev20230915194738)(@builder.io/qwik@1.2.11):
resolution: {integrity: sha512-uwwVbam6yQs9evtmof/+SpRT7DzoxD+2DSwsndGcm9JBU4Sh1xMyzll6F9QbivKVboglx+4X05OzJG7QTttWMQ==}
engines: {node: '>=16.8.0 <18.0.0 || >=18.11'}
peerDependencies:
@@ -1326,8 +1326,8 @@ packages:
'@builder.io/qwik-city': '>=0.6.0'
dependencies:
'@auth/core': 0.7.1
'@builder.io/qwik': github.com/BuilderIo/qwik-build/4d4509af4baf2ef88a99c4280ba24dd22d2a7110(undici@5.22.1)
'@builder.io/qwik-city': github.com/BuilderIo/qwik-city-build/da90f34fa48e1ed2f846120997f86310480c4c22(rollup@3.26.3)
'@builder.io/qwik': github.com/BuilderIo/qwik-build/48c1524f9b8dc7a356b1694e5468d389aee7daca(undici@5.22.1)
'@builder.io/qwik-city': github.com/BuilderIo/qwik-city-build/80b973155c27bf23f16aaf6430aa6bc3170ce414(rollup@3.26.3)
dev: false
/@builder.io/qwik-city@1.2.10(rollup@3.26.3):
@@ -1346,7 +1346,7 @@ packages:
- supports-color
dev: true
/@builder.io/qwik-react@0.5.0(@builder.io/qwik@1.2.10)(@types/react-dom@18.2.7)(@types/react@18.2.17)(react-dom@18.2.0)(react@18.2.0):
/@builder.io/qwik-react@0.5.0(@builder.io/qwik@1.2.11)(@types/react-dom@18.2.7)(@types/react@18.2.17)(react-dom@18.2.0)(react@18.2.0):
resolution: {integrity: sha512-JdJWQWOJGv7ddQqEZwzR8wPh0IoCQZwD9qo75+reiQaLp6eH+Pjsm/kn1LaMQt6u72pCCNjnj5kEn/bnbfnIjQ==}
engines: {node: '>=16'}
peerDependencies:
@@ -1356,7 +1356,7 @@ packages:
react: '>=18.0.0'
react-dom: '>=18.0.0'
dependencies:
'@builder.io/qwik': github.com/BuilderIo/qwik-build/4d4509af4baf2ef88a99c4280ba24dd22d2a7110(undici@5.22.1)
'@builder.io/qwik': github.com/BuilderIo/qwik-build/48c1524f9b8dc7a356b1694e5468d389aee7daca(undici@5.22.1)
'@types/react': 18.2.17
'@types/react-dom': 18.2.7
react: 18.2.0
@@ -1385,12 +1385,12 @@ packages:
undici: 5.22.1
dev: true
/@builder.io/sdk-qwik@0.4.5(@builder.io/qwik@1.2.10):
/@builder.io/sdk-qwik@0.4.5(@builder.io/qwik@1.2.11):
resolution: {integrity: sha512-JBHOowt0D2344zSq4kIcz2qnz0LxIZMy5KkYHhWVc9wgM5DMoO5N9YgzUqkQo209NPO58oyLv2BBWHLr+v//QQ==}
peerDependencies:
'@builder.io/qwik': '>=1.0.0'
dependencies:
'@builder.io/qwik': github.com/BuilderIo/qwik-build/4d4509af4baf2ef88a99c4280ba24dd22d2a7110(undici@5.22.1)
'@builder.io/qwik': github.com/BuilderIo/qwik-build/48c1524f9b8dc7a356b1694e5468d389aee7daca(undici@5.22.1)
dev: true
/@builder.io/vite-plugin-macro@0.0.7(@types/node@20.4.5)(rollup@3.26.3)(terser@5.19.2):
@@ -1412,17 +1412,17 @@ packages:
- terser
dev: true
/@clack/core@0.3.2:
resolution: {integrity: sha512-FZnsNynwGDIDktx6PEZK1EuCkFpY4ldEX6VYvfl0dqeoLPb9Jpw1xoUXaVcGR8ExmYNm1w2vdGdJkEUYD/2pqg==}
/@clack/core@0.3.3:
resolution: {integrity: sha512-5ZGyb75BUBjlll6eOa1m/IZBxwk91dooBWhPSL67sWcLS0zt9SnswRL0l26TVdBhb0wnWORRxUn//uH6n4z7+A==}
dependencies:
picocolors: 1.0.0
sisteransi: 1.0.5
dev: true
/@clack/prompts@0.6.3:
resolution: {integrity: sha512-AM+kFmAHawpUQv2q9+mcB6jLKxXGjgu/r2EQjEwujgpCdzrST6BJqYw00GRn56/L/Izw5U7ImoLmy00X/r80Pw==}
/@clack/prompts@0.7.0:
resolution: {integrity: sha512-0MhX9/B4iL6Re04jPrttDm+BsP8y6mS7byuv0BvXgdXhbV5PdlsHt55dvNsuBCPZ7xq1oTAOOuotR9NFbQyMSA==}
dependencies:
'@clack/core': 0.3.2
'@clack/core': 0.3.3
picocolors: 1.0.0
sisteransi: 1.0.5
dev: true
@@ -2739,14 +2739,14 @@ packages:
resolution: {integrity: sha512-9b8mPpKrfeGRuhFH5iO1iwCLeIIsV6+H1sRfxbkoGXIyQE2BTsPd9zqSqQJ+pv5sJ/hT5M1zvOFL02MnEezFug==}
dev: true
/@modular-forms/qwik@0.12.0(@builder.io/qwik-city@1.2.10-dev20230911173253)(@builder.io/qwik@1.2.10):
/@modular-forms/qwik@0.12.0(@builder.io/qwik-city@1.2.11-dev20230915194738)(@builder.io/qwik@1.2.11):
resolution: {integrity: sha512-IJi5Uvm1Z1tJZLOpYM8jWza40Viac6tblnMre0pdrslVv7tW3MnXFgQgO539YksooOsn1Jn1KjVUVmhiMuXXuA==}
peerDependencies:
'@builder.io/qwik': ^1.0.0
'@builder.io/qwik-city': ^1.0.0
dependencies:
'@builder.io/qwik': github.com/BuilderIo/qwik-build/4d4509af4baf2ef88a99c4280ba24dd22d2a7110(undici@5.22.1)
'@builder.io/qwik-city': github.com/BuilderIo/qwik-city-build/da90f34fa48e1ed2f846120997f86310480c4c22(rollup@3.26.3)
'@builder.io/qwik': github.com/BuilderIo/qwik-build/48c1524f9b8dc7a356b1694e5468d389aee7daca(undici@5.22.1)
'@builder.io/qwik-city': github.com/BuilderIo/qwik-city-build/80b973155c27bf23f16aaf6430aa6bc3170ce414(rollup@3.26.3)
/@mui/base@5.0.0-beta.0(@types/react@18.2.17)(react-dom@18.2.0)(react@18.2.0):
resolution: {integrity: sha512-ap+juKvt8R8n3cBqd/pGtZydQ4v2I/hgJKnvJRGjpSh3RvsvnDHO4rXov8MHQlH6VqpOekwgilFLGxMZjNTucA==}
@@ -5547,13 +5547,13 @@ packages:
unpic: 3.9.0
dev: true
/@unpic/qwik@0.0.24(@builder.io/qwik@1.2.10):
/@unpic/qwik@0.0.24(@builder.io/qwik@1.2.11):
resolution: {integrity: sha512-i8BWq6Tj325bH8a5HlNW4CKTt+kN09y3d6uJztrJWha5SLdrDESrFBPNqosWcuF8p8GjL2L0Em7Lnvr6f1+/9w==}
engines: {node: '>=15.0.0'}
peerDependencies:
'@builder.io/qwik': '*'
dependencies:
'@builder.io/qwik': github.com/BuilderIo/qwik-build/4d4509af4baf2ef88a99c4280ba24dd22d2a7110(undici@5.22.1)
'@builder.io/qwik': github.com/BuilderIo/qwik-build/48c1524f9b8dc7a356b1694e5468d389aee7daca(undici@5.22.1)
dev: true
/@vercel/nft@0.22.6(supports-color@9.4.0):
@@ -19011,11 +19011,11 @@ packages:
/zwitch@2.0.4:
resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==}
github.com/BuilderIo/qwik-build/4d4509af4baf2ef88a99c4280ba24dd22d2a7110(undici@5.22.1):
resolution: {tarball: https://codeload.github.com/BuilderIo/qwik-build/tar.gz/4d4509af4baf2ef88a99c4280ba24dd22d2a7110}
id: github.com/BuilderIo/qwik-build/4d4509af4baf2ef88a99c4280ba24dd22d2a7110
github.com/BuilderIo/qwik-build/48c1524f9b8dc7a356b1694e5468d389aee7daca(undici@5.22.1):
resolution: {tarball: https://codeload.github.com/BuilderIo/qwik-build/tar.gz/48c1524f9b8dc7a356b1694e5468d389aee7daca}
id: github.com/BuilderIo/qwik-build/48c1524f9b8dc7a356b1694e5468d389aee7daca
name: '@builder.io/qwik'
version: 1.2.10
version: 1.2.11
engines: {node: '>=16.8.0 <18.0.0 || >=18.11'}
hasBin: true
peerDependencies:
@@ -19024,11 +19024,11 @@ packages:
csstype: 3.1.2
undici: 5.22.1
github.com/BuilderIo/qwik-city-build/da90f34fa48e1ed2f846120997f86310480c4c22(rollup@3.26.3):
resolution: {tarball: https://codeload.github.com/BuilderIo/qwik-city-build/tar.gz/da90f34fa48e1ed2f846120997f86310480c4c22}
id: github.com/BuilderIo/qwik-city-build/da90f34fa48e1ed2f846120997f86310480c4c22
github.com/BuilderIo/qwik-city-build/80b973155c27bf23f16aaf6430aa6bc3170ce414(rollup@3.26.3):
resolution: {tarball: https://codeload.github.com/BuilderIo/qwik-city-build/tar.gz/80b973155c27bf23f16aaf6430aa6bc3170ce414}
id: github.com/BuilderIo/qwik-city-build/80b973155c27bf23f16aaf6430aa6bc3170ce414
name: '@builder.io/qwik-city'
version: 1.2.10-dev20230911173253
version: 1.2.11-dev20230915194738
engines: {node: '>=16.8.0 <18.0.0 || >=18.11'}
dependencies:
'@mdx-js/mdx': 2.3.0

View File

@@ -96,6 +96,11 @@ export async function apiExtractor(config: BuildConfig) {
join(config.packagesDir, 'qwik-city', 'adapters', 'deno-server', 'vite'),
join(config.packagesDir, 'qwik-city', 'lib', 'adapters', 'deno-server', 'vite', 'index.d.ts')
);
createTypesApi(
config,
join(config.packagesDir, 'qwik-city', 'adapters', 'bun-server', 'vite'),
join(config.packagesDir, 'qwik-city', 'lib', 'adapters', 'bun-server', 'vite', 'index.d.ts')
);
createTypesApi(
config,
join(config.packagesDir, 'qwik-city', 'adapters', 'node-server', 'vite'),
@@ -131,6 +136,11 @@ export async function apiExtractor(config: BuildConfig) {
join(config.packagesDir, 'qwik-city', 'middleware', 'cloudflare-pages'),
join(config.packagesDir, 'qwik-city', 'lib', 'middleware', 'cloudflare-pages', 'index.d.ts')
);
createTypesApi(
config,
join(config.packagesDir, 'qwik-city', 'middleware', 'bun'),
join(config.packagesDir, 'qwik-city', 'lib', 'middleware', 'bun', 'index.d.ts')
);
createTypesApi(
config,
join(config.packagesDir, 'qwik-city', 'middleware', 'deno'),

View File

@@ -25,6 +25,7 @@ export async function buildQwikCity(config: BuildConfig) {
buildAdapterCloudflarePagesVite(config),
buildAdapterCloudRunVite(config),
buildAdapterDenoVite(config),
buildAdapterBunVite(config),
buildAdapterNodeServerVite(config),
buildAdapterNetlifyEdgeVite(config),
buildAdapterSharedVite(config),
@@ -34,6 +35,7 @@ export async function buildQwikCity(config: BuildConfig) {
buildMiddlewareNetlifyEdge(config),
buildMiddlewareAzureSwa(config),
buildMiddlewareDeno(config),
buildMiddlewareBun(config),
buildMiddlewareNode(config),
buildMiddlewareRequestHandler(config),
buildMiddlewareVercelEdge(config),
@@ -75,6 +77,11 @@ export async function buildQwikCity(config: BuildConfig) {
import: './adapters/cloud-run/vite/index.mjs',
require: './adapters/cloud-run/vite/index.cjs',
},
'./adapters/bun-server/vite': {
types: './adapters/bun-server/vite/index.d.ts',
import: './adapters/bun-server/vite/index.mjs',
require: './adapters/bun-server/vite/index.cjs',
},
'./adapters/deno-server/vite': {
types: './adapters/deno-server/vite/index.d.ts',
import: './adapters/deno-server/vite/index.mjs',
@@ -121,6 +128,10 @@ export async function buildQwikCity(config: BuildConfig) {
types: './middleware/deno/index.d.ts',
import: './middleware/deno/index.mjs',
},
'./middleware/bun': {
types: './middleware/bun/index.d.ts',
import: './middleware/bun/index.mjs',
},
'./middleware/netlify-edge': {
types: './middleware/netlify-edge/index.d.ts',
import: './middleware/netlify-edge/index.mjs',
@@ -386,6 +397,35 @@ async function buildAdapterCloudRunVite(config: BuildConfig) {
});
}
async function buildAdapterBunVite(config: BuildConfig) {
const entryPoints = [join(config.srcQwikCityDir, 'adapters', 'bun-server', 'vite', 'index.ts')];
await build({
entryPoints,
outfile: join(config.distQwikCityPkgDir, 'adapters', 'bun-server', 'vite', 'index.mjs'),
bundle: true,
platform: 'node',
target: nodeTarget,
format: 'esm',
external: ADAPTER_EXTERNALS,
plugins: [resolveAdapterShared('../../shared/vite/index.mjs')],
});
await build({
entryPoints,
outfile: join(config.distQwikCityPkgDir, 'adapters', 'bun-server', 'vite', 'index.cjs'),
bundle: true,
platform: 'node',
target: nodeTarget,
format: 'cjs',
external: ADAPTER_EXTERNALS,
plugins: [
resolveAdapterShared('../../shared/vite/index.cjs'),
resolveRequestHandler('../../../middleware/request-handler/index.cjs'),
],
});
}
async function buildAdapterDenoVite(config: BuildConfig) {
const entryPoints = [join(config.srcQwikCityDir, 'adapters', 'deno-server', 'vite', 'index.ts')];
@@ -584,6 +624,21 @@ async function buildMiddlewareCloudflarePages(config: BuildConfig) {
});
}
async function buildMiddlewareBun(config: BuildConfig) {
const entryPoints = [join(config.srcQwikCityDir, 'middleware', 'bun', 'index.ts')];
await build({
entryPoints,
outfile: join(config.distQwikCityPkgDir, 'middleware', 'bun', 'index.mjs'),
bundle: true,
platform: 'node',
target: nodeTarget,
format: 'esm',
external: MIDDLEWARE_EXTERNALS,
plugins: [resolveRequestHandler('../request-handler/index.mjs')],
});
}
async function buildMiddlewareDeno(config: BuildConfig) {
const entryPoints = [join(config.srcQwikCityDir, 'middleware', 'deno', 'index.ts')];

View File

@@ -18,10 +18,10 @@
"nextSteps": {
"title": "Next Steps",
"lines": [
" Now you can build and deploy to Azure with:",
"Now you can build and deploy to Azure with:",
"",
" - pnpm run build: production build for Azure SWA",
" - pnpm run deploy: it will use the SWA CLI to deploy your site"
"- pnpm run build: production build for Azure SWA",
"- pnpm run deploy: it will use the SWA CLI to deploy your site"
]
}
}

View File

@@ -0,0 +1,9 @@
## Bun Server
This app has a minimal [Bun server](https://bun.sh/docs/api/http) implementation. After running a full build, you can preview the build using the command:
```
bun run serve
```
Then visit [http://localhost:3000/](http://localhost:3000/)

View File

@@ -0,0 +1,23 @@
import { bunServerAdapter } from "@builder.io/qwik-city/adapters/bun-server/vite";
import { extendConfig } from "@builder.io/qwik-city/vite";
import baseConfig from "../../vite.config";
export default extendConfig(baseConfig, () => {
return {
build: {
ssr: true,
rollupOptions: {
input: ["src/entry.bun.ts", "@qwik-city-plan"],
},
minify: false,
},
plugins: [
bunServerAdapter({
ssg: {
include: ["/*"],
origin: "https://yoursite.dev",
},
}),
],
};
});

View File

@@ -0,0 +1,24 @@
{
"description": "Bun server",
"scripts": {
"build.server": "vite build -c adapters/bun/vite.config.ts",
"serve": "bun server/entry.bun.js"
},
"__qwik__": {
"priority": 20,
"displayName": "Adapter: Bun Server",
"docs": [
"https://qwik.builder.io/deployments/bun/",
"https://bun.sh/docs/api/http"
],
"nextSteps": {
"title": "Next Steps",
"lines": [
"Now you can build a production-ready Bun app:",
"",
"- bun run build: production build",
"- bun run serve: runs the production server locally"
]
}
}
}

View File

@@ -0,0 +1,48 @@
/*
* WHAT IS THIS FILE?
*
* It's the entry point for the Bun HTTP server when building for production.
*
* Learn more about the Bun integration here:
* - https://qwik.builder.io/docs/deployments/bun/
* - https://bun.sh/docs/api/http
*
*/
import { createQwikCity } from "@builder.io/qwik-city/middleware/bun";
import qwikCityPlan from "@qwik-city-plan";
import { manifest } from "@qwik-client-manifest";
import render from "./entry.ssr";
// Create the Qwik City Bun middleware
const { router, notFound, staticFile } = createQwikCity({
render,
qwikCityPlan,
manifest,
});
// Allow for dynamic port
const port = Number(Bun.env.PORT ?? 3000);
/* eslint-disable */
console.log(`Server started: http://localhost:${port}/`);
Bun.serve({
async fetch(request: Request) {
const staticResponse = await staticFile(request);
if (staticResponse) {
return staticResponse;
}
// Server-side render this request with Qwik City
const qwikCityResponse = await router(request);
if (qwikCityResponse) {
return qwikCityResponse;
}
// Path not found
return notFound(request);
},
port,
});
declare const Bun: any;

View File

@@ -14,10 +14,10 @@
"nextSteps": {
"title": "Next Steps",
"lines": [
" Now you can build and deploy to Google Cloud Run with:",
"Now you can build and deploy to Google Cloud Run with:",
"",
" - pnpm run build: production build for Cloud Run",
" - pnpm run deploy: it will use the gcloud CLI to deploy your site"
"- pnpm run build: production build for Cloud Run",
"- pnpm run deploy: it will use the gcloud CLI to deploy your site"
]
}
}

View File

@@ -18,10 +18,10 @@
"nextSteps": {
"title": "Next Steps",
"lines": [
" Now you can build and deploy to Cloudflare Pages with:",
"Now you can build and deploy to Cloudflare Pages with:",
"",
" - pnpm run build: production build for Cloudflare",
" - pnpm run deploy: it will use the Cloudflare CLI to deploy your site"
"- pnpm run build: production build for Cloudflare",
"- pnpm run deploy: it will use the Cloudflare CLI to deploy your site"
]
}
}

View File

@@ -14,10 +14,10 @@
"nextSteps": {
"title": "Next Steps",
"lines": [
" Now you can build a production-ready Deno app:",
"Now you can build a production-ready Deno app:",
"",
" - pnpm run build: production build",
" - pnpm run serve: runs the production server locally"
"- pnpm run build: production build",
"- pnpm run serve: runs the production server locally"
]
}
}

View File

@@ -20,10 +20,10 @@
"nextSteps": {
"title": "Next Steps",
"lines": [
" Now you can build a production-ready Express app:",
"Now you can build a production-ready Express app:",
"",
" - pnpm run build: production build",
" - pnpm run serve: runs the production server locally"
"- pnpm run build: production build",
"- pnpm run serve: runs the production server locally"
]
}
}

View File

@@ -20,10 +20,10 @@
"nextSteps": {
"title": "Next Steps",
"lines": [
" Now you can build a production-ready Fastify app:",
"Now you can build a production-ready Fastify app:",
"",
" - pnpm run build: production build for Fastify",
" - pnpm run serve: runs the production server locally"
"- pnpm run build: production build for Fastify",
"- pnpm run serve: runs the production server locally"
]
}
}

View File

@@ -17,8 +17,7 @@
"nextSteps": {
"title": "Next Steps",
"lines": [
"",
" - cd functions && pnpm i"
"- cd functions && pnpm i"
]
}
}

View File

@@ -19,10 +19,10 @@
"nextSteps": {
"title": "Next Steps",
"lines": [
" Now you can build and deploy to Netlify with:",
"Now you can build and deploy to Netlify with:",
"",
" - pnpm run build: production build for Netlify",
" - pnpm run deploy: it will use the netlify CLI to deploy your site"
"- pnpm run build: production build for Netlify",
"- pnpm run deploy: it will use the netlify CLI to deploy your site"
]
}
}

View File

@@ -13,10 +13,10 @@
"nextSteps": {
"title": "Next Steps",
"lines": [
" Now you can build a production-ready node app:",
"Now you can build a production-ready node app:",
"",
" - pnpm run build: production build",
" - pnpm run serve: runs the production server locally"
"- pnpm run build: production build",
"- pnpm run serve: runs the production server locally"
]
}
}

View File

@@ -11,8 +11,8 @@
],
"nextSteps": {
"lines": [
" You must change the 'origin' url under staticAdapter",
" inside 'vite.config.ts'"
"You must change the 'origin' url under staticAdapter",
"inside 'vite.config.ts'"
]
}
}

View File

@@ -18,10 +18,10 @@
"nextSteps": {
"title": "Next Steps",
"lines": [
" Now you can build and deploy to Vercel with:",
"Now you can build and deploy to Vercel with:",
"",
" - pnpm run build: production build for Vercel",
" - pnpm run deploy: it will use the Vercel CLI to deploy your site"
"- pnpm run build: production build for Vercel",
"- pnpm run deploy: it will use the Vercel CLI to deploy your site"
]
}
}

View File

@@ -97,7 +97,8 @@
"starters/apps/qwikcity-test/**/*",
"starters/dev-server.ts",
"packages/qwik-react/vite",
"@types/deno.d.ts"
"@types/deno.d.ts",
"@types/bun.d.ts"
],
"exclude": [
"packages/create-qwik/dist",