@orochibraru/svelte-smol 1.6.0 → 1.7.0-next.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 +14 -6
- package/dist/index.d.ts +13 -9
- package/dist/index.js +36 -20
- package/dist/templates/handler.ts +4 -4
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -10,17 +10,25 @@ no JS files to ship, just one binary plus its static assets.
|
|
|
10
10
|
bun add -d @orochibraru/svelte-smol
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
+
For SvelteKit 3 (prerelease), install from the `next` tag instead:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
bun add -d @orochibraru/svelte-smol@next @sveltejs/kit@next
|
|
17
|
+
```
|
|
18
|
+
|
|
13
19
|
## Usage
|
|
14
20
|
|
|
21
|
+
SvelteKit 3 reads its options from the `sveltekit()` Vite plugin:
|
|
22
|
+
|
|
15
23
|
```js
|
|
16
|
-
//
|
|
24
|
+
// vite.config.js
|
|
25
|
+
import { sveltekit } from "@sveltejs/kit/vite";
|
|
26
|
+
import { defineConfig } from "vite";
|
|
17
27
|
import adapter from "@orochibraru/svelte-smol";
|
|
18
28
|
|
|
19
|
-
export default {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
},
|
|
23
|
-
};
|
|
29
|
+
export default defineConfig({
|
|
30
|
+
plugins: [sveltekit({ adapter: adapter() })],
|
|
31
|
+
});
|
|
24
32
|
```
|
|
25
33
|
|
|
26
34
|
The compile step runs under the Bun runtime, so build with:
|
package/dist/index.d.ts
CHANGED
|
@@ -130,18 +130,22 @@ export interface AdapterOptions {
|
|
|
130
130
|
*
|
|
131
131
|
* @example
|
|
132
132
|
* ```js
|
|
133
|
-
* //
|
|
133
|
+
* // vite.config.js
|
|
134
|
+
* import { sveltekit } from "@sveltejs/kit/vite";
|
|
135
|
+
* import { defineConfig } from "vite";
|
|
134
136
|
* import adapter from "@orochibraru/svelte-smol";
|
|
135
137
|
*
|
|
136
|
-
* export default {
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
138
|
+
* export default defineConfig({
|
|
139
|
+
* plugins: [
|
|
140
|
+
* sveltekit({
|
|
141
|
+
* adapter: adapter({
|
|
142
|
+
* // cross-compile for an Alpine container from any host
|
|
143
|
+
* target: "bun-linux-x64-musl",
|
|
144
|
+
* bytecode: true,
|
|
145
|
+
* }),
|
|
142
146
|
* }),
|
|
143
|
-
*
|
|
144
|
-
* };
|
|
147
|
+
* ],
|
|
148
|
+
* });
|
|
145
149
|
* ```
|
|
146
150
|
*
|
|
147
151
|
* @see {@link https://bun.com/docs/bundler/executables | Bun — Single-file executables}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { mkdirSync, rmSync } from "node:fs";
|
|
1
2
|
import { fileURLToPath } from "node:url";
|
|
2
3
|
// `node:url`, not `Bun.fileURLToPath`: this module is loaded at config-parse
|
|
3
4
|
// time by Node-based tooling too (svelte-check, the Svelte language server,
|
|
@@ -42,18 +43,22 @@ const templates = fileURLToPath(new URL("./templates", import.meta.url));
|
|
|
42
43
|
*
|
|
43
44
|
* @example
|
|
44
45
|
* ```js
|
|
45
|
-
* //
|
|
46
|
+
* // vite.config.js
|
|
47
|
+
* import { sveltekit } from "@sveltejs/kit/vite";
|
|
48
|
+
* import { defineConfig } from "vite";
|
|
46
49
|
* import adapter from "@orochibraru/svelte-smol";
|
|
47
50
|
*
|
|
48
|
-
* export default {
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
51
|
+
* export default defineConfig({
|
|
52
|
+
* plugins: [
|
|
53
|
+
* sveltekit({
|
|
54
|
+
* adapter: adapter({
|
|
55
|
+
* // cross-compile for an Alpine container from any host
|
|
56
|
+
* target: "bun-linux-x64-musl",
|
|
57
|
+
* bytecode: true,
|
|
58
|
+
* }),
|
|
54
59
|
* }),
|
|
55
|
-
*
|
|
56
|
-
* };
|
|
60
|
+
* ],
|
|
61
|
+
* });
|
|
57
62
|
* ```
|
|
58
63
|
*
|
|
59
64
|
* @see {@link https://bun.com/docs/bundler/executables | Bun — Single-file executables}
|
|
@@ -72,12 +77,12 @@ export default function adapter(options = {}) {
|
|
|
72
77
|
read: () => true,
|
|
73
78
|
},
|
|
74
79
|
async adapt(builder) {
|
|
75
|
-
const { base } = builder.config.
|
|
80
|
+
const { base } = builder.config.paths;
|
|
76
81
|
const tmp = builder.getBuildDirectory("adapter-bun");
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
82
|
+
rmSync(out, { force: true, recursive: true });
|
|
83
|
+
rmSync(tmp, { force: true, recursive: true });
|
|
84
|
+
mkdirSync(out, { recursive: true });
|
|
85
|
+
mkdirSync(tmp, { recursive: true });
|
|
81
86
|
builder.log.minor("Copying assets");
|
|
82
87
|
builder.writeClient(`${out}/client${base}`);
|
|
83
88
|
builder.writePrerendered(`${out}/prerendered${base}`);
|
|
@@ -90,10 +95,15 @@ export default function adapter(options = {}) {
|
|
|
90
95
|
}
|
|
91
96
|
builder.log.minor("Building server");
|
|
92
97
|
builder.writeServer(`${tmp}/server`);
|
|
98
|
+
// SvelteKit 3 no longer hands out a serialised manifest; it writes a
|
|
99
|
+
// module exporting a ready-made `server` instance instead.
|
|
100
|
+
builder.generateServerInstance(`${tmp}/server/instance.js`, {
|
|
101
|
+
serverDirectory: `${tmp}/server`,
|
|
102
|
+
});
|
|
93
103
|
await Bun.write(`${tmp}/server/manifest.js`, [
|
|
94
|
-
`export const manifest = ${builder.generateManifest({ relativePath: "./" })};`,
|
|
95
104
|
`export const prerendered = new Set(${JSON.stringify(builder.prerendered.paths)});`,
|
|
96
105
|
`export const base = ${JSON.stringify(base)};`,
|
|
106
|
+
`export const app_path = ${JSON.stringify(builder.getAppPath())};`,
|
|
97
107
|
].join("\n\n"));
|
|
98
108
|
// Entry templates ship as raw `.ts` — `bun build --compile` runs them
|
|
99
109
|
// straight through. The virtual specifiers (`ENV`, `MANIFEST`,
|
|
@@ -114,16 +124,22 @@ export default function adapter(options = {}) {
|
|
|
114
124
|
HANDLER: "./handler.ts",
|
|
115
125
|
MANIFEST: "./server/manifest.js",
|
|
116
126
|
SERVE_OPTIONS: JSON.stringify(serveOptions),
|
|
117
|
-
SERVER: "./server/
|
|
127
|
+
SERVER: "./server/instance.js",
|
|
118
128
|
},
|
|
119
129
|
});
|
|
120
130
|
const entry = `${tmp}/index.ts`;
|
|
121
|
-
if (builder.hasServerInstrumentationFile
|
|
131
|
+
if (builder.hasServerInstrumentationFile()) {
|
|
122
132
|
// Instrumentation (OpenTelemetry &c.) has to load before anything
|
|
123
133
|
// else in the bundle. A compiled binary has no post-build
|
|
124
|
-
// entrypoint to rewrite, so prepend the
|
|
125
|
-
// entrypoint instead.
|
|
126
|
-
|
|
134
|
+
// entrypoint to rewrite, so prepend the imports to the compile
|
|
135
|
+
// entrypoint instead. The initializer populates
|
|
136
|
+
// `$env/dynamic/private` first, so instrumentation can read it.
|
|
137
|
+
const initializer = builder.createInstrumentationInitializer({
|
|
138
|
+
outputDirectory: tmp,
|
|
139
|
+
serverDirectory: `${tmp}/server`,
|
|
140
|
+
environment: "export default Bun.env;",
|
|
141
|
+
});
|
|
142
|
+
await Bun.write(entry, `import ${JSON.stringify(initializer)};\nimport "./server/instrumentation.server.js";\n${await Bun.file(entry).text()}`);
|
|
127
143
|
}
|
|
128
144
|
const check = (result, label) => {
|
|
129
145
|
if (!result.success) {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/* global ENV_PREFIX, BUILD_OPTIONS */
|
|
2
2
|
|
|
3
3
|
import { env } from "ENV";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { app_path, base, prerendered } from "MANIFEST";
|
|
5
|
+
import { server as kit_server } from "SERVER";
|
|
6
6
|
import { statSync } from "node:fs";
|
|
7
7
|
import { dirname, resolve } from "node:path";
|
|
8
8
|
import type { Server as SvelteKitServer } from "@sveltejs/kit";
|
|
9
9
|
|
|
10
|
-
const server =
|
|
10
|
+
const server = kit_server as SvelteKitServer & {
|
|
11
11
|
websocket?: () => Bun.WebSocketHandler<undefined> | undefined;
|
|
12
12
|
};
|
|
13
13
|
|
|
@@ -33,7 +33,7 @@ const self_dir = compiled ? dirname(process.execPath) : import.meta.dir;
|
|
|
33
33
|
const assets_root = resolve(self_dir, env("ASSETS_DIR", ""));
|
|
34
34
|
const client_dir = `${assets_root}/client${base}`;
|
|
35
35
|
const prerendered_dir = `${assets_root}/prerendered${base}`;
|
|
36
|
-
const immutable_prefix =
|
|
36
|
+
const immutable_prefix = `/${app_path}/immutable/`;
|
|
37
37
|
|
|
38
38
|
await server.init({
|
|
39
39
|
env: Bun.env as Record<string, string>,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orochibraru/svelte-smol",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0-next.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"keywords": [
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"@biomejs/biome": "^2.5.11",
|
|
49
49
|
"@semantic-release/github": "^12.0.9",
|
|
50
50
|
"@semantic-release/npm": "^13.1.5",
|
|
51
|
-
"@sveltejs/kit": "^
|
|
51
|
+
"@sveltejs/kit": "^3.0.0-next.27",
|
|
52
52
|
"@sveltejs/vite-plugin-svelte": "^7.3.0",
|
|
53
53
|
"@types/bun": "^1.4.0",
|
|
54
54
|
"conventional-changelog-conventionalcommits": "^8",
|
|
@@ -59,6 +59,6 @@
|
|
|
59
59
|
"vite": "^8.2.2"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
|
-
"@sveltejs/kit": "^
|
|
62
|
+
"@sveltejs/kit": "^3.0.0-next.0"
|
|
63
63
|
}
|
|
64
64
|
}
|