@orochibraru/svelte-smol 1.8.0 → 1.8.2

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
@@ -12,7 +12,7 @@ bun add -d @orochibraru/svelte-smol
12
12
 
13
13
  ## Usage
14
14
 
15
- ```js
15
+ ```typescript
16
16
  // svelte.config.js
17
17
  import adapter from "@orochibraru/svelte-smol";
18
18
 
@@ -29,6 +29,29 @@ The compile step runs under the Bun runtime, so build with:
29
29
  bun run vite build
30
30
  ```
31
31
 
32
+ ## SvelteKit 3
33
+
34
+ SvelteKit 3 (prerelease) is supported by the same package: the adapter detects
35
+ which SvelteKit is building the app. Pass it to the Vite plugin instead of
36
+ `svelte.config.js`:
37
+
38
+ ```typescript
39
+ // vite.config.js
40
+ import { sveltekit } from "@sveltejs/kit/vite";
41
+ import { defineConfig } from "vite";
42
+ import adapter from "@orochibraru/svelte-smol";
43
+
44
+ export default defineConfig({
45
+ plugins: [sveltekit({ adapter: adapter() })],
46
+ });
47
+ ```
48
+
49
+ On SvelteKit 3 the assets are embedded in the executable and the options
50
+ change (`buildOptions`, `serverOptions`). Options meant for the other SvelteKit
51
+ version fail the build. See [SvelteKit 3](docs/sveltekit-3.md) for the options,
52
+ environment variables and the migration table. The rest of this README covers
53
+ SvelteKit 2.
54
+
32
55
  ## Output
33
56
 
34
57
  ```text
@@ -75,7 +98,7 @@ instrumentation — works the same.
75
98
 
76
99
  ## Options
77
100
 
78
- ```js
101
+ ```typescript
79
102
  adapter({
80
103
  out: "build", // output directory
81
104
  name: "server", // executable filename within `out`
@@ -101,23 +124,23 @@ runtime the first time you use a target.
101
124
 
102
125
  ## Runtime environment variables
103
126
 
104
- | Variable | Default | Purpose |
105
- | ------------------ | --------- | ----------------------------------------------------------------------------------------------- |
106
- | `HOST` | `0.0.0.0` | Listen address |
107
- | `PORT` | `3000` | Listen port |
108
- | `SOCKET_PATH` | — | Listen on a Unix socket instead of `HOST`/`PORT` |
109
- | `ASSETS_DIR` | — | Override where `client/` and `prerendered/` are looked up (absolute, or relative to the binary) |
110
- | `ORIGIN` | — | Absolute origin used for request URL resolution |
111
- | `PROTOCOL_HEADER` | — | Header carrying the forwarded protocol (e.g. `x-forwarded-proto`) |
112
- | `HOST_HEADER` | — | Header carrying the forwarded host |
113
- | `PORT_HEADER` | — | Header carrying the forwarded port |
114
- | `ADDRESS_HEADER` | — | Header carrying the client address (e.g. `x-forwarded-for`) |
115
- | `XFF_DEPTH` | `1` | Trusted-proxy depth when `ADDRESS_HEADER=x-forwarded-for` |
116
- | `BODY_SIZE_LIMIT` | `512K` | Max request body size (`K`/`M`/`G` suffixes allowed) |
117
- | `IDLE_TIMEOUT` | `10` | Bun socket idle timeout in seconds (SSE responses opt out) |
118
- | `SHUTDOWN_TIMEOUT` | `30` | Seconds to wait for in-flight requests on `SIGINT`/`SIGTERM` |
119
- | `HEALTHCHECK_PATH` | `/_health`| Endpoint the `healthcheck` binary probes (must match the `healthcheck` option) |
120
- | `HEALTHCHECK_TIMEOUT` | `2000` | `healthcheck` binary request timeout in ms |
127
+ | Variable | Default | Purpose |
128
+ | --------------------- | ---------- | ----------------------------------------------------------------------------------------------- |
129
+ | `HOST` | `0.0.0.0` | Listen address |
130
+ | `PORT` | `3000` | Listen port |
131
+ | `SOCKET_PATH` | — | Listen on a Unix socket instead of `HOST`/`PORT` |
132
+ | `ASSETS_DIR` | — | Override where `client/` and `prerendered/` are looked up (absolute, or relative to the binary) |
133
+ | `ORIGIN` | — | Absolute origin used for request URL resolution |
134
+ | `PROTOCOL_HEADER` | — | Header carrying the forwarded protocol (e.g. `x-forwarded-proto`) |
135
+ | `HOST_HEADER` | — | Header carrying the forwarded host |
136
+ | `PORT_HEADER` | — | Header carrying the forwarded port |
137
+ | `ADDRESS_HEADER` | — | Header carrying the client address (e.g. `x-forwarded-for`) |
138
+ | `XFF_DEPTH` | `1` | Trusted-proxy depth when `ADDRESS_HEADER=x-forwarded-for` |
139
+ | `BODY_SIZE_LIMIT` | `512K` | Max request body size (`K`/`M`/`G` suffixes allowed) |
140
+ | `IDLE_TIMEOUT` | `10` | Bun socket idle timeout in seconds (SSE responses opt out) |
141
+ | `SHUTDOWN_TIMEOUT` | `30` | Seconds to wait for in-flight requests on `SIGINT`/`SIGTERM` |
142
+ | `HEALTHCHECK_PATH` | `/_health` | Endpoint the `healthcheck` binary probes (must match the `healthcheck` option) |
143
+ | `HEALTHCHECK_TIMEOUT` | `2000` | `healthcheck` binary request timeout in ms |
121
144
 
122
145
  Set `envPrefix` to namespace these (`envPrefix: "MY_APP_"` → `MY_APP_PORT`).
123
146
 
@@ -147,11 +170,13 @@ wiring is needed.
147
170
 
148
171
  ## Releases
149
172
 
150
- Automated by [semantic-release](https://semantic-release.gitbook.io/) from
173
+ Automated by [releaser](https://github.com/orochibraru/releaser) from
151
174
  [Conventional Commits](https://www.conventionalcommits.org/):
152
175
 
153
- - `fix:` / `perf:` → **patch**, `feat:` → **minor**, `feat!:` or a
154
- `BREAKING CHANGE:` footer → **major**
155
- - `docs:` `refactor:` `test:` `chore:` `build:` `ci:` `style:` → **no release**
156
- - `feat:` / `fix:` scoped to `ci`, `build`, `deps`, `dev`, `repo`, `test`,
157
- `example`, `release` → **no release** (they don't touch the published package)
176
+ - `fix:` `perf:` `revert:` `feat:` `docs:` `refactor:`, and breaking changes
177
+ (`feat!:` or a `BREAKING CHANGE:` footer) → **patch**
178
+ - `test:` `chore:` `build:` `ci:` `style:` → **no release**
179
+ - Pushes that don't touch the published package (`index.ts`, `kit2/`, `kit3/`,
180
+ `package.json`, `tsconfig*.json`) don't run a release at all
181
+ - Every release is published from `main` to npm `latest`, for both SvelteKit
182
+ versions
package/dist/index.d.ts CHANGED
@@ -1,149 +1,19 @@
1
1
  import type { Adapter } from "@sveltejs/kit";
2
- export interface AdapterOptions {
3
- /**
4
- * Output directory. Holds the compiled executable plus the `client/` and
5
- * `prerendered/` folders it serves.
6
- * @default "build"
7
- */
8
- out?: string;
9
- /**
10
- * Filename of the compiled executable, written into `out`. Ignored when
11
- * {@link AdapterOptions.compile | `compile`} is `false` (the server bundle
12
- * is always `index.js` then).
13
- * @default "server"
14
- */
15
- name?: string;
16
- /**
17
- * Compile the server to a single standalone executable with
18
- * `bun build --compile`. Turn this off to emit a plain `build/index.js`
19
- * bundle instead, run with `bun run build/index.js`. Pure-JS dependencies
20
- * are still bundled in; a native (`.node`) addon can't be, so it resolves
21
- * from `node_modules` at runtime — which a `bun` process can do and a
22
- * compiled binary can't. This is the only way to ship `sharp`, `sqlite3`
23
- * and the like. The `healthcheck` binary is still compiled either way.
24
- * @default true
25
- */
26
- compile?: boolean;
27
- /**
28
- * Cross-compilation target for `bun build --compile`, e.g.
29
- * `"bun-linux-x64"`, `"bun-linux-arm64-musl"`, `"bun-darwin-arm64"`,
30
- * `"bun-windows-x64"` (optional `-modern` / `-baseline` SIMD suffix, and
31
- * `-musl` for Alpine). Bun downloads the matching runtime on first use.
32
- * @default the host platform
33
- */
34
- target?: Bun.Build.CompileTarget;
35
- /**
36
- * Emit a V8 bytecode cache into the executable for faster cold starts, at
37
- * the cost of a larger binary.
38
- * @default false
39
- */
40
- bytecode?: boolean;
41
- /**
42
- * Minify the bundled server code before embedding it.
43
- * @default false
44
- */
45
- minify?: boolean;
46
- /**
47
- * Embed a source map so server stack traces point at original code.
48
- * @default false
49
- */
50
- sourcemap?: boolean;
51
- /**
52
- * Pre-compress client assets and prerendered pages to `.gz` / `.br`
53
- * siblings. The handler serves them with the matching `Content-Encoding`
54
- * when the request's `Accept-Encoding` allows.
55
- * @default false
56
- */
57
- precompress?: boolean;
58
- /**
59
- * Compile a second tiny executable, `healthcheck`, alongside the server
60
- * and expose a matching `GET` endpoint. The binary probes that endpoint
61
- * over loopback (or the Unix socket) and exits `0` when healthy, `1`
62
- * otherwise — ready to drop into a Docker `HEALTHCHECK`. Pass an object
63
- * to change the endpoint path.
64
- * @default true
65
- */
66
- healthcheck?: boolean | {
67
- path?: string;
68
- };
69
- /**
70
- * Prefix for this adapter's own runtime env vars (`PORT`, `HOST`,
71
- * `ORIGIN`, ...).
72
- * @default ""
73
- */
74
- envPrefix?: string;
75
- /**
76
- * Serve the app's static assets and prerendered pages from the
77
- * executable. The `client/` and `prerendered/` folders must sit next to
78
- * the binary (or point `ASSETS_DIR` at their parent). Turn off when a
79
- * reverse proxy or CDN serves them instead.
80
- * @default true
81
- */
82
- serveAssets?: boolean;
83
- /**
84
- * Extra options merged into the `Bun.serve()` call (`tls`, `reusePort`,
85
- * `maxConnections`, a custom `error` handler, ...). Applied *before* this
86
- * adapter's own required fields (`idleTimeout`, `maxRequestBodySize`,
87
- * `fetch`, `hostname`/`port`/`unix`, `websocket`), so it can't be used to
88
- * override request handling, only to add to it. Use the existing env vars
89
- * (`IDLE_TIMEOUT`, `BODY_SIZE_LIMIT`, `HOST`/`PORT`, `SOCKET_PATH`,
90
- * `SHUTDOWN_TIMEOUT`) to change those instead.
91
- * @default {}
92
- */
93
- serveOptions?: Record<string, unknown>;
94
- }
2
+ import { type AdapterOptions as Kit2AdapterOptions } from "./kit2/index.js";
3
+ import { type AdapterOptions as Kit3AdapterOptions } from "./kit3/index.js";
4
+ export type { Kit2AdapterOptions, Kit3AdapterOptions };
5
+ export type AdapterOptions = Kit2AdapterOptions | Kit3AdapterOptions;
95
6
  /**
96
- * SvelteKit adapter that compiles the app into a single standalone executable
97
- * with `bun build --compile`.
98
- *
99
- * `adapt()` writes the SvelteKit server and this package's entrypoint templates
100
- * into a temp directory, then compiles them — `@sveltejs/kit` and every other
101
- * pure-JS dependency bundled in — into one binary. The build must run under the
102
- * Bun runtime (`bun --bun vite build`, or a `bunfig.toml` with `[run] bun =
103
- * true`); loading the config alone works under Node too.
104
- *
105
- * With {@link AdapterOptions.compile | `compile: false`} it emits a plain
106
- * `build/index.js` bundle instead (run with `bun`), the only way to ship a
107
- * native (`.node`) addon.
108
- *
109
- * Output, all written to {@link AdapterOptions.out | `out`}:
110
- *
111
- * ```text
112
- * build/
113
- * ├── server the executable (rename with `name`)
114
- * ├── client/ static assets, served by the executable
115
- * └── prerendered/ prerendered pages, served by the executable
116
- * ```
117
- *
118
- * The executable resolves `client/` and `prerendered/` from its own location
119
- * (`dirname(process.execPath)`, overridable with the `ASSETS_DIR` env var), so
120
- * it can run from any working directory. Deploy the whole `out` directory, or
121
- * just the binary when {@link AdapterOptions.serveAssets | `serveAssets`} is
122
- * off and a proxy/CDN serves the assets.
123
- *
124
- * Runtime configuration (`HOST`, `PORT`, `ORIGIN`, `BODY_SIZE_LIMIT`, …) is
125
- * read from environment variables, optionally namespaced by
126
- * {@link AdapterOptions.envPrefix | `envPrefix`}.
127
- *
128
- * @param options - see {@link AdapterOptions}
129
- * @returns the configured SvelteKit {@link Adapter}
7
+ * SvelteKit adapter that compiles the app into a standalone Bun executable.
8
+ * Runs the SvelteKit 2 or SvelteKit 3 implementation, whichever SvelteKit is
9
+ * building the app.
130
10
  *
131
11
  * @example
132
- * ```js
133
- * // svelte.config.js
12
+ * ```typescript
13
+ * // svelte.config.js (SvelteKit 2)
134
14
  * import adapter from "@orochibraru/svelte-smol";
135
15
  *
136
- * export default {
137
- * kit: {
138
- * adapter: adapter({
139
- * // cross-compile for an Alpine container from any host
140
- * target: "bun-linux-x64-musl",
141
- * bytecode: true,
142
- * }),
143
- * },
144
- * };
16
+ * export default { kit: { adapter: adapter() } };
145
17
  * ```
146
- *
147
- * @see {@link https://bun.com/docs/bundler/executables | Bun — Single-file executables}
148
18
  */
149
19
  export default function adapter(options?: AdapterOptions): Adapter;
package/dist/index.js CHANGED
@@ -1,181 +1,45 @@
1
- import { fileURLToPath } from "node:url";
2
- // `node:url`, not `Bun.fileURLToPath`: this module is loaded at config-parse
3
- // time by Node-based tooling too (svelte-check, the Svelte language server,
4
- // `svelte-kit sync`), where `Bun` is undefined. Everything that actually needs
5
- // the Bun runtime lives inside `adapt()`.
6
- const templates = fileURLToPath(new URL("./templates", import.meta.url));
1
+ import kit2 from "./kit2/index.js";
2
+ import kit3 from "./kit3/index.js";
3
+ const KIT2_ONLY = [
4
+ "name",
5
+ "compile",
6
+ "target",
7
+ "bytecode",
8
+ "minify",
9
+ "sourcemap",
10
+ "serveAssets",
11
+ "serveOptions",
12
+ ];
13
+ const KIT3_ONLY = ["buildOptions", "serverOptions"];
7
14
  /**
8
- * SvelteKit adapter that compiles the app into a single standalone executable
9
- * with `bun build --compile`.
10
- *
11
- * `adapt()` writes the SvelteKit server and this package's entrypoint templates
12
- * into a temp directory, then compiles them — `@sveltejs/kit` and every other
13
- * pure-JS dependency bundled in — into one binary. The build must run under the
14
- * Bun runtime (`bun --bun vite build`, or a `bunfig.toml` with `[run] bun =
15
- * true`); loading the config alone works under Node too.
16
- *
17
- * With {@link AdapterOptions.compile | `compile: false`} it emits a plain
18
- * `build/index.js` bundle instead (run with `bun`), the only way to ship a
19
- * native (`.node`) addon.
20
- *
21
- * Output, all written to {@link AdapterOptions.out | `out`}:
22
- *
23
- * ```text
24
- * build/
25
- * ├── server the executable (rename with `name`)
26
- * ├── client/ static assets, served by the executable
27
- * └── prerendered/ prerendered pages, served by the executable
28
- * ```
29
- *
30
- * The executable resolves `client/` and `prerendered/` from its own location
31
- * (`dirname(process.execPath)`, overridable with the `ASSETS_DIR` env var), so
32
- * it can run from any working directory. Deploy the whole `out` directory, or
33
- * just the binary when {@link AdapterOptions.serveAssets | `serveAssets`} is
34
- * off and a proxy/CDN serves the assets.
35
- *
36
- * Runtime configuration (`HOST`, `PORT`, `ORIGIN`, `BODY_SIZE_LIMIT`, …) is
37
- * read from environment variables, optionally namespaced by
38
- * {@link AdapterOptions.envPrefix | `envPrefix`}.
39
- *
40
- * @param options - see {@link AdapterOptions}
41
- * @returns the configured SvelteKit {@link Adapter}
15
+ * SvelteKit adapter that compiles the app into a standalone Bun executable.
16
+ * Runs the SvelteKit 2 or SvelteKit 3 implementation, whichever SvelteKit is
17
+ * building the app.
42
18
  *
43
19
  * @example
44
- * ```js
45
- * // svelte.config.js
20
+ * ```typescript
21
+ * // svelte.config.js (SvelteKit 2)
46
22
  * import adapter from "@orochibraru/svelte-smol";
47
23
  *
48
- * export default {
49
- * kit: {
50
- * adapter: adapter({
51
- * // cross-compile for an Alpine container from any host
52
- * target: "bun-linux-x64-musl",
53
- * bytecode: true,
54
- * }),
55
- * },
56
- * };
24
+ * export default { kit: { adapter: adapter() } };
57
25
  * ```
58
- *
59
- * @see {@link https://bun.com/docs/bundler/executables | Bun — Single-file executables}
60
26
  */
61
27
  export default function adapter(options = {}) {
62
- const { out = "build", name = "server", compile = true, target, bytecode = false, minify = false, sourcemap = false, precompress = false, healthcheck = true, envPrefix = "", serveAssets = true, serveOptions = {}, } = options;
63
- const healthcheckConfig = healthcheck === false
64
- ? false
65
- : {
66
- path: (healthcheck === true ? undefined : healthcheck.path) ?? "/_health",
67
- };
68
28
  return {
69
29
  name: "@orochibraru/svelte-smol",
70
30
  supports: {
71
31
  instrumentation: () => true,
72
32
  read: () => true,
73
33
  },
74
- async adapt(builder) {
75
- const { base } = builder.config.kit.paths;
76
- const tmp = builder.getBuildDirectory("adapter-bun");
77
- builder.rimraf(out);
78
- builder.rimraf(tmp);
79
- builder.mkdirp(`${out}/`);
80
- builder.mkdirp(tmp);
81
- builder.log.minor("Copying assets");
82
- builder.writeClient(`${out}/client${base}`);
83
- builder.writePrerendered(`${out}/prerendered${base}`);
84
- if (precompress) {
85
- builder.log.minor("Compressing assets");
86
- await Promise.all([
87
- builder.compress(`${out}/client`),
88
- builder.compress(`${out}/prerendered`),
89
- ]);
90
- }
91
- builder.log.minor("Building server");
92
- builder.writeServer(`${tmp}/server`);
93
- await Bun.write(`${tmp}/server/manifest.js`, [
94
- `export const manifest = ${builder.generateManifest({ relativePath: "./" })};`,
95
- `export const prerendered = new Set(${JSON.stringify(builder.prerendered.paths)});`,
96
- `export const base = ${JSON.stringify(base)};`,
97
- ].join("\n\n"));
98
- // Entry templates ship as raw `.ts` — `bun build --compile` runs them
99
- // straight through. The virtual specifiers (`ENV`, `MANIFEST`,
100
- // `SERVER`, `HANDLER`) and the `ENV_PREFIX` / `BUILD_OPTIONS` /
101
- // `SERVE_OPTIONS` tokens are resolved by this raw word-boundary token
102
- // swap over the copied source.
103
- builder.log.minor("Copying entrypoint");
104
- builder.copy(templates, tmp, {
105
- replace: {
106
- BUILD_OPTIONS: JSON.stringify({
107
- serveAssets,
108
- precompress,
109
- healthcheck: healthcheckConfig,
110
- compiled: compile,
111
- }),
112
- ENV: "./env.ts",
113
- ENV_PREFIX: JSON.stringify(envPrefix),
114
- HANDLER: "./handler.ts",
115
- MANIFEST: "./server/manifest.js",
116
- SERVE_OPTIONS: JSON.stringify(serveOptions),
117
- SERVER: "./server/index.js",
118
- },
119
- });
120
- const entry = `${tmp}/index.ts`;
121
- if (builder.hasServerInstrumentationFile?.()) {
122
- // Instrumentation (OpenTelemetry &c.) has to load before anything
123
- // else in the bundle. A compiled binary has no post-build
124
- // entrypoint to rewrite, so prepend the import to the compile
125
- // entrypoint instead.
126
- await Bun.write(entry, `import "./server/instrumentation.server.js";\n${await Bun.file(entry).text()}`);
127
- }
128
- const check = (result, label) => {
129
- if (!result.success) {
130
- for (const message of result.logs) {
131
- builder.log.error(String(message));
132
- }
133
- throw new Error(`\`bun build\` failed for ${label}`);
134
- }
135
- };
136
- const compileBinary = async (entrypoint, outName) => {
137
- builder.log.minor(target ? `Compiling ${outName} (${target})` : `Compiling ${outName}`);
138
- check(await Bun.build({
139
- entrypoints: [entrypoint],
140
- target: "bun",
141
- minify,
142
- bytecode,
143
- sourcemap: sourcemap ? "linked" : "none",
144
- compile: {
145
- outfile: `${out}/${outName}`,
146
- ...(target ? { target } : {}),
147
- },
148
- }), outName);
149
- builder.log.success(`Compiled ${out}/${outName}`);
150
- };
151
- const bundleServer = async (entrypoint) => {
152
- builder.log.minor("Bundling index.js");
153
- // Same bundle as the compiled binary, just emitted as a file. Every
154
- // pure-JS dependency is inlined; a native (`.node`) addon can't be,
155
- // so its `require` stays in the output and resolves from
156
- // `node_modules` at runtime — which is exactly what a plain `bun`
157
- // process (unlike a compiled binary) can do. Ship `node_modules`
158
- // for those; anything fully bundled needn't be installed.
159
- check(await Bun.build({
160
- entrypoints: [entrypoint],
161
- target: "bun",
162
- format: "esm",
163
- minify,
164
- sourcemap: sourcemap ? "linked" : "none",
165
- outdir: out,
166
- naming: "index.js",
167
- }), "index.js");
168
- builder.log.success(`Bundled ${out}/index.js`);
169
- };
170
- if (compile) {
171
- await compileBinary(entry, name);
172
- }
173
- else {
174
- await bundleServer(entry);
175
- }
176
- if (healthcheckConfig) {
177
- await compileBinary(`${tmp}/healthcheck.ts`, "healthcheck");
34
+ adapt(builder) {
35
+ const is_kit3 = "generateServerInstance" in builder;
36
+ const unsupported = Object.keys(options).filter((key) => (is_kit3 ? KIT2_ONLY : KIT3_ONLY).includes(key));
37
+ if (unsupported.length > 0) {
38
+ throw new Error(`svelte-smol: ${unsupported.join(", ")} not supported with SvelteKit ${is_kit3 ? 3 : 2}. See https://github.com/orochibraru/svelte-smol/blob/main/docs/sveltekit-3.md for the option mapping.`);
178
39
  }
40
+ return is_kit3
41
+ ? kit3(options).adapt(builder)
42
+ : kit2(options).adapt(builder);
179
43
  },
180
44
  };
181
45
  }
@@ -0,0 +1,149 @@
1
+ import type { Adapter } from "@sveltejs/kit";
2
+ export interface AdapterOptions {
3
+ /**
4
+ * Output directory. Holds the compiled executable plus the `client/` and
5
+ * `prerendered/` folders it serves.
6
+ * @default "build"
7
+ */
8
+ out?: string;
9
+ /**
10
+ * Filename of the compiled executable, written into `out`. Ignored when
11
+ * {@link AdapterOptions.compile | `compile`} is `false` (the server bundle
12
+ * is always `index.js` then).
13
+ * @default "server"
14
+ */
15
+ name?: string;
16
+ /**
17
+ * Compile the server to a single standalone executable with
18
+ * `bun build --compile`. Turn this off to emit a plain `build/index.js`
19
+ * bundle instead, run with `bun run build/index.js`. Pure-JS dependencies
20
+ * are still bundled in; a native (`.node`) addon can't be, so it resolves
21
+ * from `node_modules` at runtime — which a `bun` process can do and a
22
+ * compiled binary can't. This is the only way to ship `sharp`, `sqlite3`
23
+ * and the like. The `healthcheck` binary is still compiled either way.
24
+ * @default true
25
+ */
26
+ compile?: boolean;
27
+ /**
28
+ * Cross-compilation target for `bun build --compile`, e.g.
29
+ * `"bun-linux-x64"`, `"bun-linux-arm64-musl"`, `"bun-darwin-arm64"`,
30
+ * `"bun-windows-x64"` (optional `-modern` / `-baseline` SIMD suffix, and
31
+ * `-musl` for Alpine). Bun downloads the matching runtime on first use.
32
+ * @default the host platform
33
+ */
34
+ target?: Bun.Build.CompileTarget;
35
+ /**
36
+ * Emit a V8 bytecode cache into the executable for faster cold starts, at
37
+ * the cost of a larger binary.
38
+ * @default false
39
+ */
40
+ bytecode?: boolean;
41
+ /**
42
+ * Minify the bundled server code before embedding it.
43
+ * @default false
44
+ */
45
+ minify?: boolean;
46
+ /**
47
+ * Embed a source map so server stack traces point at original code.
48
+ * @default false
49
+ */
50
+ sourcemap?: boolean;
51
+ /**
52
+ * Pre-compress client assets and prerendered pages to `.gz` / `.br`
53
+ * siblings. The handler serves them with the matching `Content-Encoding`
54
+ * when the request's `Accept-Encoding` allows.
55
+ * @default false
56
+ */
57
+ precompress?: boolean;
58
+ /**
59
+ * Compile a second tiny executable, `healthcheck`, alongside the server
60
+ * and expose a matching `GET` endpoint. The binary probes that endpoint
61
+ * over loopback (or the Unix socket) and exits `0` when healthy, `1`
62
+ * otherwise — ready to drop into a Docker `HEALTHCHECK`. Pass an object
63
+ * to change the endpoint path.
64
+ * @default true
65
+ */
66
+ healthcheck?: boolean | {
67
+ path?: string;
68
+ };
69
+ /**
70
+ * Prefix for this adapter's own runtime env vars (`PORT`, `HOST`,
71
+ * `ORIGIN`, ...).
72
+ * @default ""
73
+ */
74
+ envPrefix?: string;
75
+ /**
76
+ * Serve the app's static assets and prerendered pages from the
77
+ * executable. The `client/` and `prerendered/` folders must sit next to
78
+ * the binary (or point `ASSETS_DIR` at their parent). Turn off when a
79
+ * reverse proxy or CDN serves them instead.
80
+ * @default true
81
+ */
82
+ serveAssets?: boolean;
83
+ /**
84
+ * Extra options merged into the `Bun.serve()` call (`tls`, `reusePort`,
85
+ * `maxConnections`, a custom `error` handler, ...). Applied *before* this
86
+ * adapter's own required fields (`idleTimeout`, `maxRequestBodySize`,
87
+ * `fetch`, `hostname`/`port`/`unix`, `websocket`), so it can't be used to
88
+ * override request handling, only to add to it. Use the existing env vars
89
+ * (`IDLE_TIMEOUT`, `BODY_SIZE_LIMIT`, `HOST`/`PORT`, `SOCKET_PATH`,
90
+ * `SHUTDOWN_TIMEOUT`) to change those instead.
91
+ * @default {}
92
+ */
93
+ serveOptions?: Record<string, unknown>;
94
+ }
95
+ /**
96
+ * SvelteKit adapter that compiles the app into a single standalone executable
97
+ * with `bun build --compile`.
98
+ *
99
+ * `adapt()` writes the SvelteKit server and this package's entrypoint templates
100
+ * into a temp directory, then compiles them — `@sveltejs/kit` and every other
101
+ * pure-JS dependency bundled in — into one binary. The build must run under the
102
+ * Bun runtime (`bun --bun vite build`, or a `bunfig.toml` with `[run] bun =
103
+ * true`); loading the config alone works under Node too.
104
+ *
105
+ * With {@link AdapterOptions.compile | `compile: false`} it emits a plain
106
+ * `build/index.js` bundle instead (run with `bun`), the only way to ship a
107
+ * native (`.node`) addon.
108
+ *
109
+ * Output, all written to {@link AdapterOptions.out | `out`}:
110
+ *
111
+ * ```text
112
+ * build/
113
+ * ├── server the executable (rename with `name`)
114
+ * ├── client/ static assets, served by the executable
115
+ * └── prerendered/ prerendered pages, served by the executable
116
+ * ```
117
+ *
118
+ * The executable resolves `client/` and `prerendered/` from its own location
119
+ * (`dirname(process.execPath)`, overridable with the `ASSETS_DIR` env var), so
120
+ * it can run from any working directory. Deploy the whole `out` directory, or
121
+ * just the binary when {@link AdapterOptions.serveAssets | `serveAssets`} is
122
+ * off and a proxy/CDN serves the assets.
123
+ *
124
+ * Runtime configuration (`HOST`, `PORT`, `ORIGIN`, `BODY_SIZE_LIMIT`, …) is
125
+ * read from environment variables, optionally namespaced by
126
+ * {@link AdapterOptions.envPrefix | `envPrefix`}.
127
+ *
128
+ * @param options - see {@link AdapterOptions}
129
+ * @returns the configured SvelteKit {@link Adapter}
130
+ *
131
+ * @example
132
+ * ```typescript
133
+ * // svelte.config.js
134
+ * import adapter from "@orochibraru/svelte-smol";
135
+ *
136
+ * export default {
137
+ * kit: {
138
+ * adapter: adapter({
139
+ * // cross-compile for an Alpine container from any host
140
+ * target: "bun-linux-x64-musl",
141
+ * bytecode: true,
142
+ * }),
143
+ * },
144
+ * };
145
+ * ```
146
+ *
147
+ * @see {@link https://bun.com/docs/bundler/executables | Bun — Single-file executables}
148
+ */
149
+ export default function adapter(options?: AdapterOptions): Adapter;