@eslym/sveltekit-adapter-bun 1.0.14 → 2.0.0

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/README.md CHANGED
@@ -2,10 +2,162 @@
2
2
 
3
3
  Another sveltekit adapter for bun, an alternative to [svelte-adapter-bun](https://github.com/gornostay25/svelte-adapter-bun). This package support websocket in dev mode with few steps of setup.
4
4
 
5
+ The built bundle with version `2.0.0` will be ready to compile into single executable with bun.
6
+
5
7
  ## Installation
6
8
 
7
9
  ```shell
8
10
  bun add -d @eslym/sveltekit-adapter-bun
9
11
  ```
10
12
 
11
- TODO: add documentation
13
+ > [!IMPORTANT] > **Breaking Changes**
14
+ >
15
+ > Since version `2.0.0`, the custom hooks (`beforeServe`, `afterServe` and `setupCLI`) and CLI functionality is complemetely removed.
16
+
17
+ ## Setup dev server
18
+
19
+ > [!NOTE]
20
+ > You do not need to do this if you are not using websocket in dev mode.
21
+
22
+ 1. Create an entrypoint file for dev server, e.g. `./dev.ts`
23
+ 2. Add the following code to the entrypoint file
24
+
25
+ ```typescript
26
+ import { patchSvelteKit, startDevServer } from '@eslym/sveltekit-adapter-bun';
27
+
28
+ await patchSvelteKit();
29
+ await startDevServer();
30
+ ```
31
+
32
+ 3. run `bun dev.ts`
33
+
34
+ The `patchSvelteKit` function will patch the sveltekit using `bun patch` to let it get the original `Request` object from bun and pass it to the dev server, making `Bun.Server#upgrade` possible. The `startDevServer` function will start the dev server with websocket support.
35
+
36
+ The `patchSvelteKit` will not impact anything in production build, since the production build will not involve `@sveltejs/kit/node` unless you are using it in your code.
37
+
38
+ > [!IMPORTANT]
39
+ > This dev server uses bun's internal stuff, so it might break in the future bun version, but the
40
+ > production build will not be affected.
41
+
42
+ ## Use the websocket
43
+
44
+ ```typescript
45
+ // ./src/app.d.ts
46
+ // for the type checking
47
+
48
+ import type { AdapterPlatform } from '@eslym/sveltekit-adapter-bun';
49
+
50
+ // See https://kit.svelte.dev/docs/types#app
51
+ // for information about these interfaces
52
+ declare global {
53
+ namespace App {
54
+ // interface Error {}
55
+ // interface Locals {}
56
+ // interface PageData {}
57
+ // interface PageState {}
58
+ interface Platform extends AdapterPlatform {}
59
+ }
60
+ }
61
+ ```
62
+
63
+ ```typescript
64
+ // ./src/routes/echo/+server.ts
65
+
66
+ export async function GET({ platform }) {
67
+ // can mark any response for upgrade, if the upgrade failed, the response will be sent as is
68
+ return platform!.markForUpgrade(
69
+ new Response('Websocket Requried', {
70
+ status: 400
71
+ }),
72
+ {
73
+ message(ws, message) {
74
+ ws.send(message);
75
+ }
76
+ }
77
+ );
78
+ }
79
+ ```
80
+
81
+ ## Adapter Options
82
+
83
+ ```typescript
84
+ export type AdapterOptions = {
85
+ /**
86
+ * Output path
87
+ * @default './build'
88
+ */
89
+ out?: string;
90
+
91
+ /**
92
+ * The bundler for the final step build.
93
+ * @default 'rollup'
94
+ */
95
+ bundler?: 'rollup' | 'bun';
96
+
97
+ /**
98
+ * Enable pre-compress
99
+ * @default false
100
+ */
101
+ precompress?: boolean | PreCompressOptions;
102
+
103
+ /**
104
+ * Serve static assets, set if to false if you want to handle static assets yourself
105
+ * like using nginx or caddy. When it is true, an index of assets will build with
106
+ * bun's `import with { type: 'file' }` syntax, which make it ready to bundle into
107
+ * single executable file.
108
+ *
109
+ * @default true
110
+ */
111
+ serveStatic?: boolean;
112
+
113
+ /**
114
+ * File patterns to be ignored in the static assets, ex: `*.{br,gz}`
115
+ * @default ["**​/.*"]
116
+ */
117
+ staticIgnores?: string[];
118
+
119
+ /**
120
+ * Export prerendered entries as json
121
+ * @default false
122
+ */
123
+ exportPrerender?: boolean;
124
+
125
+ /**
126
+ * Include source maps
127
+ *
128
+ * @default true
129
+ */
130
+ sourceMap?: boolean | 'inline';
131
+
132
+ /**
133
+ * Minify the output when using bun build
134
+ *
135
+ * @default false
136
+ */
137
+ bunBuildMinify?:
138
+ | boolean
139
+ | {
140
+ whitespace?: boolean;
141
+ syntax?: boolean;
142
+ identifiers?: boolean;
143
+ };
144
+ };
145
+ ```
146
+
147
+ ## Runtime Environments
148
+
149
+ | Name | Description | Default |
150
+ | ---------------------- | ------------------------------------------------------------------------------------ | --------- |
151
+ | `HTTP_HOST` | The host for the server | `0.0.0.0` |
152
+ | `HTTP_PORT` | The port for the server | `3000` |
153
+ | `HTTP_SOCKET` | The path of the unix socket which the server will listen to (this will disable http) | - |
154
+ | `HTTP_PROTOCOL_HEADER` | The header name to get the protocol from the request | - |
155
+ | `HTTP_HOST_HEADER` | The header name to get the host from the request | - |
156
+ | `HTTP_IP_HEADER` | The header name to get the client ip from the request (usually `X-Forwarded-For`) | - |
157
+ | `HTTP_XFF_DEPTH` | The depth of the `X-Forwarded-For` header to get the client ip | `1` |
158
+ | `HTTP_OVERRIDE_ORIGIN` | Force the request origin when it is unable to retrieve from the request | - |
159
+ | `HTTP_IDLE_TIMEOUT` | The request timeout for the server(in seconds) | `30` |
160
+ | `HTTP_MAX_BODY` | The maximum body size for the request | `128mib` |
161
+ | `WS_IDLE_TIMEOUT` | The websocket idle timeout (in seconds) | `120` |
162
+ | `WS_MAX_PAYLOAD` | The maximum payload size for the websocket | `16mib` |
163
+ | `WS_NO_PING` | Disable automatic ping response | `false` |
@@ -0,0 +1,4 @@
1
+ import type { Glob } from 'bun';
2
+ export declare function build_assets_js(base_path: string, client_files: AsyncIterableIterator<string>, prerendered_pages: Map<string, {
3
+ file: string;
4
+ }>, immutable_prefix: string, ignores: Glob[]): Promise<string>;
package/dist/dev.d.ts CHANGED
@@ -1,5 +1,6 @@
1
+ import type { DevServeOptions } from './types';
1
2
  export declare function patchSveltekit(): Promise<void>;
2
- export declare function startDevServer({ port, host, config }?: {
3
+ export declare function startDevServer({ port, host, idleTimeout, config, websocket, ...serveOptions }?: DevServeOptions & {
3
4
  port?: number;
4
5
  host?: string;
5
6
  config?: string;