sepal 0.2.0-alpha.0 → 0.3.0-alpha.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.
Files changed (65) hide show
  1. package/README.md +14 -5
  2. package/cli.js +127 -10
  3. package/package.json +48 -4
  4. package/src/abort.js +129 -0
  5. package/src/app.js +13 -0
  6. package/src/dom.js +173 -60
  7. package/src/fetch.js +347 -80
  8. package/src/form-data.js +141 -0
  9. package/src/host-call.js +57 -0
  10. package/src/index.js +9 -11
  11. package/src/lru.js +45 -0
  12. package/src/native.js +32 -0
  13. package/src/notifications.js +60 -0
  14. package/src/os.js +35 -0
  15. package/src/process.js +164 -0
  16. package/src/protocol.js +3 -4
  17. package/src/renderer.js +140 -10
  18. package/src/secrets.js +42 -0
  19. package/src/settings.js +52 -0
  20. package/src/shims.js +30 -8
  21. package/src/stem.js +125 -0
  22. package/src/updater.js +3 -2
  23. package/src/url.js +65 -20
  24. package/src/web.js +86 -0
  25. package/src/window.js +6 -2
  26. package/types/abort.d.ts +46 -0
  27. package/types/app.d.ts +7 -0
  28. package/types/fetch.d.ts +118 -28
  29. package/types/form-data.d.ts +19 -0
  30. package/types/host-call.d.ts +18 -0
  31. package/types/index.d.ts +5 -2
  32. package/types/lru.d.ts +18 -0
  33. package/types/native.d.ts +22 -0
  34. package/types/notifications.d.ts +53 -0
  35. package/types/os.d.ts +53 -0
  36. package/types/process.d.ts +90 -0
  37. package/types/protocol.d.ts +0 -2
  38. package/types/renderer.d.ts +16 -1
  39. package/types/secrets.d.ts +22 -0
  40. package/types/settings.d.ts +29 -0
  41. package/types/shims.d.ts +1 -0
  42. package/types/stem.d.ts +21 -0
  43. package/types/updater.d.ts +6 -4
  44. package/types/url.d.ts +1 -1
  45. package/types/vite/adapter.d.ts +22 -0
  46. package/types/vite/add.d.ts +77 -0
  47. package/types/vite/app.d.ts +52 -1
  48. package/types/vite/licenses.d.ts +11 -0
  49. package/types/vite/native.d.ts +135 -0
  50. package/types/vite/page.d.ts +20 -0
  51. package/types/vite/permissions.d.ts +56 -0
  52. package/types/vite/sveltekit.d.ts +5 -42
  53. package/types/vite/vite.d.ts +86 -29
  54. package/types/web.d.ts +17 -0
  55. package/types/window.d.ts +5 -1
  56. package/vite/adapter.js +118 -0
  57. package/vite/add.js +254 -0
  58. package/vite/app.js +195 -27
  59. package/vite/head.js +2 -2
  60. package/vite/licenses.js +115 -0
  61. package/vite/native.js +535 -0
  62. package/vite/page.js +95 -0
  63. package/vite/permissions.d.ts +56 -0
  64. package/vite/sveltekit.js +11 -263
  65. package/vite/vite.js +378 -109
package/vite/page.js ADDED
@@ -0,0 +1,95 @@
1
+ // What a build may put in an app's page: the checks both presets run on
2
+ // index.html and the stylesheets it loads.
3
+ //
4
+ // The host takes what Vite and SvelteKit write: a head with a title, meta,
5
+ // stylesheets (<link> and <style>) and modulepreload; markup in the body;
6
+ // inline classic scripts and module scripts. Scripts, stylesheets,
7
+ // modulepreload targets and fonts come from the app folder only, never from
8
+ // the network, and the host refuses them too. Anything else a browser would
9
+ // do with a page is left out, which the build says.
10
+ //
11
+ // Runs in Node.
12
+
13
+ /** A URL that goes to the network: `http:`, `https:`, or `//host`. */
14
+ const REMOTE = /^\s*(?:https?:)?\/\//i;
15
+
16
+ /** @param {string} tag @returns {Record<string, string>} */
17
+ function attributes(tag) {
18
+ /** @type {Record<string, string>} */
19
+ const found = {};
20
+ for (const [, name, double, single, bare] of tag.matchAll(/\s([^\s"'=<>/]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g)) {
21
+ found[name.toLowerCase()] = double ?? single ?? bare ?? '';
22
+ }
23
+ return found;
24
+ }
25
+
26
+ const FONTS = 'Fonts load only from the app folder: self-host them, for example with Fontsource (https://fontsource.org).';
27
+
28
+ /**
29
+ * What in a stylesheet would load from the network: `@import` of a remote
30
+ * stylesheet, and fonts in `@font-face`. Images are not checked: they are
31
+ * refused when they load, as today.
32
+ * @param {string} css
33
+ * @param {string} where the file, for the message
34
+ * @returns {string[]}
35
+ */
36
+ export function check_css(css, where) {
37
+ const errors = [];
38
+ const code = css.replace(/\/\*[\s\S]*?\*\//g, '');
39
+ for (const [, url] of code.matchAll(/@import\s+(?:url\(\s*)?["']?([^"')\s;]+)/gi)) {
40
+ if (REMOTE.test(url)) errors.push(`${where} imports the stylesheet ${url}. Stylesheets load only from the app folder: import it from a package, or put it in static/. ${FONTS}`);
41
+ }
42
+ for (const [block] of code.matchAll(/@font-face\s*\{[^}]*\}/gi)) {
43
+ for (const [, url] of block.matchAll(/url\(\s*["']?([^"')\s]+)/gi)) {
44
+ if (REMOTE.test(url)) errors.push(`${where} loads the font ${url}. ${FONTS}`);
45
+ }
46
+ }
47
+ return errors;
48
+ }
49
+
50
+ /**
51
+ * Check a page. `errors` stop the build: something would load from the
52
+ * network. `warnings` are what the host leaves out.
53
+ * @param {string} html
54
+ * @param {string} where the file, for the messages
55
+ * @returns {{ errors: string[], warnings: string[] }}
56
+ */
57
+ export function check_page(html, where = 'index.html') {
58
+ /** @type {string[]} */
59
+ const errors = [];
60
+ /** @type {Set<string>} */
61
+ const warnings = new Set();
62
+ const page = html.replace(/<!--[\s\S]*?-->/g, '');
63
+
64
+ for (const [tag, name] of page.matchAll(/<([a-z][a-z0-9-]*)\b[^>]*>/gi)) {
65
+ const attrs = attributes(tag.slice(name.length + 1, -1));
66
+ const element = name.toLowerCase();
67
+ if (Object.keys(attrs).some((attr) => /^on[a-z]/.test(attr))) warnings.add('event handler attributes (onclick and the like) do nothing: nothing runs them');
68
+ if (element === 'iframe') warnings.add('<iframe> is not supported: it stays empty');
69
+ if (element === 'script') {
70
+ const type = (attrs.type ?? '').trim().toLowerCase();
71
+ if (attrs.src !== undefined && REMOTE.test(attrs.src)) {
72
+ errors.push(`${where} loads the script ${attrs.src}. Scripts load only from the app folder: install the package and import it, or put the file in static/.`);
73
+ } else if (type === 'importmap') {
74
+ warnings.add('import maps are not supported: imports are resolved by the build');
75
+ } else if (attrs.src !== undefined && type !== 'module' && /^(|text\/javascript|application\/javascript)$/.test(type)) {
76
+ warnings.add('<script src> without type="module" is not run: load scripts as modules');
77
+ }
78
+ }
79
+ if (element === 'link' && attrs.href !== undefined && REMOTE.test(attrs.href)) {
80
+ const rel = (attrs.rel ?? '').toLowerCase().split(/\s+/);
81
+ if (rel.includes('stylesheet')) {
82
+ errors.push(`${where} loads the stylesheet ${attrs.href}. Stylesheets load only from the app folder: import it from a package, or put it in static/. ${FONTS}`);
83
+ } else if (rel.includes('modulepreload')) {
84
+ errors.push(`${where} preloads the module ${attrs.href}. Scripts load only from the app folder: install the package and import it.`);
85
+ } else if (rel.includes('preload') && (attrs.as ?? '').toLowerCase() === 'font') {
86
+ errors.push(`${where} preloads the font ${attrs.href}. ${FONTS}`);
87
+ }
88
+ }
89
+ }
90
+ for (const [, css] of page.matchAll(/<style\b[^>]*>([\s\S]*?)<\/style>/gi)) errors.push(...check_css(css, `a <style> in ${where}`));
91
+ for (const [, code] of page.matchAll(/<script\b[^>]*>([\s\S]*?)<\/script>/gi)) {
92
+ if (/\bdocument\.write(ln)?\s*\(/.test(code)) warnings.add('document.write() does nothing');
93
+ }
94
+ return { errors, warnings: [...warnings].map((warning) => `${where}: ${warning}`) };
95
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * What the app may do, beyond its own page: `permissions` in
3
+ * `sepal.config.ts`. Each key is default-deny.
4
+ *
5
+ * A plugin's package adds its own key, which its commands need:
6
+ *
7
+ * ```ts
8
+ * declare module 'sepal/permissions' {
9
+ * interface Permissions { watch?: boolean | string[] }
10
+ * }
11
+ * ```
12
+ *
13
+ * (`sepal/vite`'s `Permissions` is this one; augment it here, where it is
14
+ * declared.) A key no installed package declares is an error here, as the
15
+ * host's own check is at launch.
16
+ */
17
+ export interface Permissions {
18
+ /** Which URLs `fetch` may reach: origins, optionally with a path prefix, or a host with a wildcard. `true` allows any. */
19
+ http?: boolean | string[];
20
+ /** Which directories the file APIs may touch: `data`, `documents`, `downloads`, `desktop`, `home`, or absolute paths. `true` allows any. */
21
+ fs?: boolean | string[];
22
+ /** Open, save and message dialogs. */
23
+ dialog?: boolean;
24
+ /** Reading and writing the clipboard. */
25
+ clipboard?: boolean;
26
+ /** Opening web and mail links, and allowed files, in their default app. */
27
+ open?: boolean;
28
+ /** Changing the window: minimise, maximise, decorations, close, drag. */
29
+ window?: boolean;
30
+ /**
31
+ * The system's details (`info()` in `sepal/os`): platform, version, locale,
32
+ * host name, dark mode. Environment variables only by name, listed in
33
+ * `env`, which gives `info()` too.
34
+ */
35
+ os?: boolean | { env?: string[] };
36
+ /** The app's settings (`sepal/settings`), shared with the app's Rust. */
37
+ settings?: boolean;
38
+ /**
39
+ * The programs `sepal/process` may run: names (`'git'`, found in the
40
+ * app's `PATH` and the usual install folders) and absolute paths. `true`
41
+ * allows any. The list limits which programs start, not what they do:
42
+ * `git` runs hooks and aliases, and a shell or `node` runs anything.
43
+ */
44
+ process?: boolean | string[];
45
+ /**
46
+ * The OS's keychain (`sepal/secrets`): the login keychain on macOS, the
47
+ * Secret Service or the Secret portal on Linux. Kept under the app's id;
48
+ * on Linux other programs of the user's can read an unlocked keyring.
49
+ */
50
+ secrets?: boolean;
51
+ /**
52
+ * The system's notifications (`sepal/notifications`). On macOS the user
53
+ * is asked as well, the first time.
54
+ */
55
+ notifications?: boolean;
56
+ }
package/vite/sveltekit.js CHANGED
@@ -1,272 +1,20 @@
1
- // SvelteKit, with its own client router, on the Sepal renderer.
1
+ // `sepalKit()` is gone. A SvelteKit app uses SvelteKit's own plugin, with
2
+ // `withSepal()`, `sepal/adapter` and `sepal()`; this says how to move.
2
3
  //
3
- // // vite.config.ts
4
- // import { sepalKit } from 'sepal/sveltekit';
5
- // export default defineConfig({ plugins: [sepalKit()] });
6
- //
7
- // This takes the place of `sveltekit()`: it calls it, with what an app in a
8
- // window needs. The result of `vite build` is the same as for any other
9
- // Sepal app: `dist/app.js`, `dist/app.css`, `dist/app.json` and the
10
- // static files. Settings for the app come from `sepal.config.ts`, as always.
11
- //
12
- // An app has no server, so SvelteKit runs as a single-page app: no
13
- // `+page.server.ts`, no form actions, no `+server.ts`, nothing prerendered.
14
- //
15
- // Two things here reach into SvelteKit's own files as they are bundled (see
16
- // `patch`). A SvelteKit release can move them; the build then stops and says
17
- // so, rather than produce an app that does not start.
4
+ // ponytail: remove a release after 0.2.0-alpha.0.
18
5
  //
19
6
  // Runs in Node.
20
7
 
21
- import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs';
22
- import { dirname, join, posix, relative, resolve } from 'node:path';
23
- import { dev_window, load_config, manifest } from './app.js';
24
- import { element_bindings } from './bindings.js';
25
- import { head } from './head.js';
26
-
27
- /**
28
- * The edits to SvelteKit's client. Each names the file, what to find in it,
29
- * and what goes there instead.
30
- * @type {{ file: string, find: string, replace: string, prepend: string, why: string }[]}
31
- */
32
- const patch = [
33
- {
34
- // The entry of a single-bundle build. The DOM and the runtime (`__sb`,
35
- // the host's way in) have to exist before any of SvelteKit runs; and
36
- // SvelteKit starts without waiting, so a failure would go unnoticed.
37
- file: '/kit/src/runtime/client/bundle.js',
38
- find: 'void kit.start(app, element, options);',
39
- replace: "kit.start(app, element, options).catch((error) => console.error('SvelteKit did not start:', error));",
40
- prepend: "import 'sepal/dom';\nimport 'sepal';\n",
41
- why: 'how its single bundle starts'
42
- },
43
- {
44
- // SvelteKit mounts its root component itself, and does not say with
45
- // which renderer.
46
- file: '/kit/src/runtime/client/client.js',
47
- find: 'render(Root, {',
48
- replace: 'render(Root, {\n\t\trenderer: __sepal_renderer,',
49
- prepend: "import __sepal_renderer from 'sepal/renderer';\n",
50
- why: 'how it mounts its root component'
51
- }
52
- ];
53
-
54
- /** Every file under a directory, as paths relative to it. @param {string} directory @returns {string[]} */
55
- function files_in(directory) {
56
- return readdirSync(directory, { recursive: true, withFileTypes: true })
57
- .filter((entry) => entry.isFile())
58
- // With `/` on Windows too: these are compared with the paths in SvelteKit's page.
59
- .map((entry) => relative(directory, join(entry.parentPath, entry.name)).replaceAll('\\', '/'));
60
- }
61
-
62
- /**
63
- * The files under `src` that SvelteKit would run on a server, which an app
64
- * does not have: they would build, and then never run. Relative to `src`.
65
- *
66
- * ponytail: comes out when the backend thread lands; that is where they will run.
67
- * @param {string} src
68
- */
69
- export function server_files(src) {
70
- if (!existsSync(src)) return [];
71
- return files_in(src).filter((file) => /(^|\/)(\+(page|layout)\.server\.|\+server\.|hooks\.server\.)|\.remote\.[^/]+$/.test(file));
72
- }
8
+ import { KIT_SETUP } from './vite.js';
73
9
 
74
10
  /**
75
- * Turn what SvelteKit built (an HTML page that imports one module) into what
76
- * the host loads (a script, a stylesheet, and the other files as they are).
77
- * @param {string} from SvelteKit's client output, with its fallback page as `index.html`
78
- * @param {string} to
11
+ * @deprecated Use SvelteKit's `sveltekit(withSepal({ adapter: adapter() }))`,
12
+ * with `adapter` from `sepal/adapter`, and `sepal()` from `sepal/vite`.
13
+ * @param {Record<string, unknown>} [_options]
14
+ * @returns {never}
79
15
  */
80
- export function convert(from, to) {
81
- const html = readFileSync(join(from, 'index.html'), 'utf8');
82
- // `__sveltekit_abc123 = { base: "", version: "…" };`, which SvelteKit's client reads.
83
- const payload = /__sveltekit_\w+ = \{[^}]*\};/.exec(html)?.[0];
84
- if (!payload) throw new Error('sepal: SvelteKit changed its start script; there is no payload in the fallback page');
85
-
86
- // The page says which files are this build's. The directory may hold more:
87
- // in watch mode SvelteKit leaves the previous build's next to them.
88
- const files = files_in(from);
89
- const bundle = /import\("\/([^"]+)"\)/.exec(html)?.[1];
90
- if (!bundle || !files.includes(bundle)) {
91
- throw new Error('sepal: SvelteKit did not produce a single bundle (output.bundleStrategy must be "single")');
92
- }
93
- let code = readFileSync(join(from, bundle), 'utf8');
94
-
95
- // The module's one export statement: `export{a as app,b as start}`, or
96
- // `export { app, start }` when not minified.
97
- const exported = /export\s*\{([^}]*)\};?\s*$/.exec(code);
98
- const start = exported?.[1]
99
- .split(',')
100
- .map((pair) => pair.trim().split(/\s+as\s+/))
101
- .find(([local, as = local]) => as === 'start')?.[0];
102
- if (!exported || !start) throw new Error('sepal: SvelteKit changed its bundle; it does not end by exporting `start`');
103
- code = code.slice(0, exported.index);
104
-
105
- // A script has no `import.meta`. The module's address only matters for
106
- // resolving paths next to it.
107
- code = code.replaceAll('import.meta.resolve', '((path) => new URL(path, __module_url).href)').replaceAll('import.meta.url', '__module_url');
108
-
109
- mkdirSync(to, { recursive: true });
110
- writeFileSync(
111
- join(to, 'app.js'),
112
- `(() => {
113
- // The bundle was a module, and module code is strict. Run as a sloppy script,
114
- // the minified Tracker broke on V8 (a renderer method missing on Insights).
115
- 'use strict';
116
- const __module_url = ${JSON.stringify(`http://app.localhost/${bundle}`)};
117
- ${code}
118
- globalThis.${payload}
119
- // Where SvelteKit puts the app: the element its start script sat in.
120
- const __sepal_target = document.createElement('div');
121
- document.body.appendChild(__sepal_target);
122
- ${start}(__sepal_target);
123
- })();
124
- `
16
+ export function sepalKit(_options) {
17
+ throw new Error(
18
+ `sepal: sepalKit() is gone. A SvelteKit app uses SvelteKit's own plugin, given its options through withSepal(), with Sepal's adapter, and sepal(). In vite.config.ts:\n\n${KIT_SETUP}\n\nWhat went to sepalKit({ kit }) goes to withSepal({ … }) as it is, and \`out\` to adapter({ out }).`
125
19
  );
126
-
127
- const styles = [...html.matchAll(/<link href="\/([^"]+)" rel="stylesheet">/g)].map((link) => link[1]).filter((file) => files.includes(file));
128
- const css = styles.map((file) => rebase_css(readFileSync(join(from, file), 'utf8'), posix.dirname(file)));
129
- // SvelteKit's route announcer is a 1px `overflow: hidden` box at the top
130
- // left. Blitz hit-tests what overflows such a box, so after the first
131
- // navigation its invisible text took clicks meant for what is drawn there.
132
- // ponytail: until Blitz's hit testing clips to `overflow: hidden`; then this goes.
133
- css.push('#svelte-announcer { pointer-events: none }');
134
- writeFileSync(join(to, 'app.css'), css.join('\n'));
135
-
136
- // Everything else is for the app to load by its path: static files, and
137
- // what SvelteKit put in `_app/immutable/assets`.
138
- for (const file of files) {
139
- if (file === 'index.html' || file.startsWith('.vite/') || file.endsWith('/version.json') || /\.(js|css)$/.test(file) && file.startsWith('_app/')) continue;
140
- mkdirSync(dirname(join(to, file)), { recursive: true });
141
- cpSync(join(from, file), join(to, file));
142
- }
143
- }
144
-
145
- /**
146
- * A stylesheet moved from `dir` (relative to the build, `/`-separated) to
147
- * app.css at its root. Its relative `url()`s, such as a font next to it in
148
- * `_app/immutable/assets`, have to say where they now are from there.
149
- * @param {string} css
150
- * @param {string} dir
151
- */
152
- export function rebase_css(css, dir) {
153
- return css.replace(
154
- /url\(\s*(['"]?)(?![a-z][a-z0-9+.-]*:|\/|#)([^'")]+)\1\s*\)/gi,
155
- (_, quote, path) => `url(${quote}${posix.join(dir, path)}${quote})`
156
- );
157
- }
158
-
159
- /**
160
- * @typedef {import('./vite.js').Config & {
161
- * kit?: import('@sveltejs/kit/vite').Config,
162
- * out?: string
163
- * }} KitOptions
164
- * `app` and `permissions` override `sepal.config.ts`, key by key. `kit` is
165
- * passed on to SvelteKit. `out` is where the app is written (default `dist`).
166
- */
167
-
168
- /**
169
- * @param {KitOptions} [inline]
170
- * @returns {Promise<import('vite').PluginOption[]>}
171
- */
172
- export async function sepalKit(inline = {}) {
173
- const { sveltekit } = await import('@sveltejs/kit/vite').catch(() => {
174
- throw new Error('sepal: @sveltejs/kit is not installed. Add it to this project to use `sepalKit()`.');
175
- });
176
- const { kit = {}, out = 'dist', ...overrides } = inline;
177
-
178
- /** `sepal.config.ts` with `overrides` on top. Filled in by the `config` hook. @type {import('./vite.js').Config} */
179
- let options = overrides;
180
- let root = process.cwd();
181
- let watching = false;
182
- const show = dev_window(() => ({ root, out_dir: resolve(root, out), name: options.app?.name }));
183
- // Deprecated in SvelteKit 3's types, but still the only way to move `static/`:
184
- // the top-level `assets` is `paths.assets`, a URL.
185
- const static_dir = () => resolve(root, kit.files?.assets ?? 'static');
186
-
187
- /** @type {import('@sveltejs/kit').Adapter} */
188
- const adapter = {
189
- name: 'sepal',
190
- async adapt(builder) {
191
- const staging = builder.getBuildDirectory('sepal');
192
- const to = resolve(root, out);
193
- // `builder.rimraf` is deprecated in SvelteKit 3.
194
- rmSync(staging, { force: true, recursive: true });
195
- rmSync(to, { force: true, recursive: true });
196
- builder.writeClient(staging);
197
- // The page SvelteKit serves for a route it did not prerender: nothing
198
- // in it but the script that starts the app.
199
- await builder.generateFallback(join(staging, 'index.html'));
200
- convert(staging, to);
201
-
202
- const written = manifest(options, root, existsSync(static_dir()) ? static_dir() : '');
203
- if (written) writeFileSync(join(to, 'app.json'), written.json);
204
- if (written?.icon) cpSync(written.icon, join(to, 'icon.png'));
205
- builder.log.minor(`Wrote the app to ${out}`);
206
- if (watching) show();
207
- }
208
- };
209
-
210
- /** @type {import('vite').Plugin} */
211
- const plugin = {
212
- name: 'sepal:sveltekit',
213
- enforce: 'pre',
214
- async config(user, env) {
215
- const project = resolve(user.root ?? '.');
216
- options = { ...(await load_config(project, env)).config, ...overrides };
217
- return {
218
- resolve: {
219
- // Selects Svelte's client build with custom renderer support, and
220
- // tells libraries that there is a DOM (the layer loaded in `patch`).
221
- conditions: ['svelte-custom-renderer', 'browser', 'svelte', 'module', 'import', 'default']
222
- }
223
- };
224
- },
225
- configResolved(config) {
226
- root = config.root;
227
- watching = config.build.watch != null;
228
- },
229
- buildStart() {
230
- // On every build, so that a file added in watch mode is caught too.
231
- const src = resolve(root, kit.files?.src ?? 'src');
232
- const found = server_files(src);
233
- if (found.length > 0) {
234
- const names = found.map((file) => posix.join(relative(root, src).replaceAll('\\', '/'), file)).join(', ');
235
- this.error(
236
- `sepal: ${names} ${found.length === 1 ? 'is' : 'are'} server code. It would run in the app's backend thread, which Sepal does not have yet, so it would never run. Use +page.ts/+layout.ts (\`load\` runs in the app) until then.`
237
- );
238
- }
239
- },
240
- transform(code, id) {
241
- const edit = patch.find(({ file }) => id.endsWith(file));
242
- if (edit === undefined) return;
243
- if (!code.includes(edit.find)) {
244
- this.error(`sepal: this version of SvelteKit changed ${edit.why}, which Sepal has to adjust. Use the SvelteKit version Sepal was tested with, or update Sepal.`);
245
- }
246
- return { code: edit.prepend + code.replace(edit.find, edit.replace), map: null };
247
- }
248
- };
249
-
250
- return [
251
- plugin,
252
- ...(await sveltekit({
253
- ...kit,
254
- adapter,
255
- // One module, not one per route: the host loads one script.
256
- output: { ...kit.output, bundleStrategy: 'single' },
257
- // Nothing is rendered ahead of time. There is no server to send it.
258
- prerender: { ...kit.prerender, entries: kit.prerender?.entries ?? [] },
259
- // SvelteKit 3 asks the server for a new version every hour by default:
260
- // a wake-up on a timer, and a request nothing answers. An app updates
261
- // through `sepal/updater` instead.
262
- version: { ...kit.version, pollInterval: kit.version?.pollInterval ?? 0 },
263
- // Ours first: they have to see `bind:` on elements and `<svelte:head>`
264
- // before Svelte refuses them.
265
- preprocess: [element_bindings(), head(), ...[kit.preprocess ?? []].flat()],
266
- compilerOptions: {
267
- ...kit.compilerOptions,
268
- experimental: { ...kit.compilerOptions?.experimental, customRenderer: 'sepal/renderer' }
269
- }
270
- }))
271
- ];
272
20
  }