@sveltejs/kit 3.0.0-next.1 → 3.0.0-next.11
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/package.json +33 -21
- package/src/constants.js +2 -0
- package/src/core/adapt/builder.js +32 -49
- package/src/core/adapt/index.js +1 -4
- package/src/core/config/index.js +137 -71
- package/src/core/config/options.js +236 -244
- package/src/core/config/types.d.ts +1 -1
- package/src/core/env.js +121 -5
- package/src/core/generate_manifest/index.js +12 -15
- package/src/core/postbuild/analyse.js +7 -19
- package/src/core/postbuild/crawl.js +22 -6
- package/src/core/postbuild/fallback.js +2 -1
- package/src/core/postbuild/prerender.js +114 -48
- package/src/core/postbuild/queue.js +2 -1
- package/src/core/sync/create_manifest_data/index.js +53 -50
- package/src/core/sync/sync.js +0 -2
- package/src/core/sync/write_client_manifest.js +8 -15
- package/src/core/sync/write_env.js +2 -1
- package/src/core/sync/write_non_ambient.js +12 -9
- package/src/core/sync/write_server.js +14 -15
- package/src/core/sync/write_tsconfig.js +16 -8
- package/src/core/sync/write_tsconfig_test/package.json +7 -0
- package/src/core/sync/write_types/index.js +28 -24
- package/src/core/utils.js +30 -5
- package/src/exports/env/index.js +77 -0
- package/src/exports/hooks/index.js +3 -9
- package/src/exports/hooks/sequence.js +3 -2
- package/src/exports/index.js +35 -13
- package/src/exports/internal/client.js +5 -0
- package/src/exports/internal/env.js +8 -5
- package/src/exports/internal/index.js +1 -90
- package/src/exports/internal/{event.js → server/event.js} +1 -2
- package/src/exports/internal/server/index.js +33 -0
- package/src/exports/internal/shared.js +89 -0
- package/src/exports/node/index.js +62 -15
- package/src/exports/params.js +68 -0
- package/src/exports/public.d.ts +363 -189
- package/src/exports/url.js +86 -0
- package/src/exports/vite/build/build_server.js +53 -59
- package/src/exports/vite/build/remote.js +18 -11
- package/src/exports/vite/build/utils.js +0 -8
- package/src/exports/vite/dev/index.js +92 -50
- package/src/exports/vite/index.js +903 -681
- package/src/exports/vite/module_ids.js +0 -2
- package/src/exports/vite/preview/index.js +32 -24
- package/src/exports/vite/static_analysis/index.js +2 -4
- package/src/exports/vite/static_analysis/types.d.ts +14 -0
- package/src/exports/vite/utils.js +40 -35
- package/src/runtime/app/env/internal.js +4 -4
- package/src/runtime/app/env/types.d.ts +1 -1
- package/src/runtime/app/environment/index.js +3 -3
- package/src/runtime/app/forms.js +24 -7
- package/src/runtime/app/paths/client.js +4 -10
- package/src/runtime/app/paths/internal/client.js +4 -2
- package/src/runtime/app/paths/internal/server.js +2 -23
- package/src/runtime/app/paths/public.d.ts +0 -28
- package/src/runtime/app/paths/server.js +10 -6
- package/src/runtime/app/server/index.js +1 -1
- package/src/runtime/app/server/remote/command.js +0 -3
- package/src/runtime/app/server/remote/form.js +27 -15
- package/src/runtime/app/server/remote/prerender.js +29 -36
- package/src/runtime/app/server/remote/query.js +101 -99
- package/src/runtime/app/server/remote/requested.js +22 -14
- package/src/runtime/app/server/remote/shared.js +30 -26
- package/src/runtime/app/state/client.js +1 -2
- package/src/runtime/app/stores.js +13 -76
- package/src/runtime/client/bundle.js +1 -1
- package/src/runtime/client/client-entry.js +3 -0
- package/src/runtime/client/client.js +411 -318
- package/src/runtime/client/entry.js +24 -3
- package/src/runtime/client/fetcher.js +3 -2
- package/src/runtime/client/ndjson.js +6 -33
- package/src/runtime/client/payload.js +17 -0
- package/src/runtime/client/remote-functions/cache.svelte.js +3 -1
- package/src/runtime/client/remote-functions/command.svelte.js +7 -32
- package/src/runtime/client/remote-functions/form.svelte.js +183 -112
- package/src/runtime/client/remote-functions/prerender.svelte.js +29 -8
- package/src/runtime/client/remote-functions/query/index.js +7 -14
- package/src/runtime/client/remote-functions/query/instance.svelte.js +63 -18
- package/src/runtime/client/remote-functions/query/proxy.js +3 -3
- package/src/runtime/client/remote-functions/query-batch.svelte.js +60 -68
- package/src/runtime/client/remote-functions/query-live/instance.svelte.js +60 -18
- package/src/runtime/client/remote-functions/query-live/iterator.js +36 -55
- package/src/runtime/client/remote-functions/shared.svelte.js +88 -62
- package/src/runtime/client/sse.js +32 -0
- package/src/runtime/client/state.svelte.js +65 -49
- package/src/runtime/client/stream.js +39 -0
- package/src/runtime/client/types.d.ts +11 -7
- package/src/runtime/client/utils.js +0 -96
- package/src/runtime/components/root.svelte +66 -0
- package/src/runtime/env/dynamic/private.js +7 -0
- package/src/runtime/env/dynamic/public.js +7 -0
- package/src/runtime/env/static/private.js +6 -0
- package/src/runtime/env/static/public.js +6 -0
- package/src/runtime/form-utils.js +100 -22
- package/src/runtime/server/cookie.js +69 -52
- package/src/runtime/server/csrf.js +65 -0
- package/src/runtime/server/data/index.js +15 -19
- package/src/runtime/server/env_module.js +0 -5
- package/src/runtime/server/errors.js +135 -0
- package/src/runtime/server/fetch.js +1 -1
- package/src/runtime/server/index.js +22 -12
- package/src/runtime/server/internal.js +25 -0
- package/src/runtime/server/page/actions.js +43 -27
- package/src/runtime/server/page/data_serializer.js +10 -10
- package/src/runtime/server/page/index.js +12 -17
- package/src/runtime/server/page/load_data.js +2 -2
- package/src/runtime/server/page/render.js +114 -193
- package/src/runtime/server/page/respond_with_error.js +11 -11
- package/src/runtime/server/page/server_routing.js +27 -18
- package/src/runtime/server/remote-functions.js +596 -0
- package/src/runtime/server/respond.js +100 -68
- package/src/runtime/server/sourcemaps.js +183 -0
- package/src/runtime/server/utils.js +2 -134
- package/src/runtime/shared.js +83 -13
- package/src/runtime/telemetry/otel.js +1 -1
- package/src/runtime/types.d.ts +8 -0
- package/src/types/ambient-private.d.ts +2 -0
- package/src/types/ambient.d.ts +10 -5
- package/src/types/global-private.d.ts +13 -25
- package/src/types/internal.d.ts +95 -80
- package/src/types/private.d.ts +41 -1
- package/src/utils/error.js +24 -4
- package/src/utils/escape.js +9 -25
- package/src/utils/features.js +1 -1
- package/src/utils/fork.js +7 -2
- package/src/utils/import.js +6 -1
- package/src/utils/imports.js +83 -0
- package/src/utils/mime.js +9 -0
- package/src/utils/page_nodes.js +3 -5
- package/src/utils/params.js +66 -0
- package/src/utils/routing.js +90 -44
- package/src/utils/shared-iterator.js +5 -0
- package/src/utils/streaming.js +14 -4
- package/src/utils/url.js +20 -2
- package/src/version.js +1 -1
- package/types/index.d.ts +537 -557
- package/types/index.d.ts.map +24 -39
- package/src/core/sync/write_root.js +0 -148
- package/src/exports/internal/server.js +0 -22
- package/src/runtime/server/remote.js +0 -457
- package/src/runtime/shared-server.js +0 -7
- package/src/types/synthetic/$lib.md +0 -5
- /package/src/exports/internal/{remote-functions.js → server/remote-functions.js} +0 -0
|
@@ -9,8 +9,6 @@ export const sveltekit_env_service_worker = '\0virtual:__sveltekit/env/service-w
|
|
|
9
9
|
|
|
10
10
|
export const service_worker = '\0virtual:service-worker';
|
|
11
11
|
|
|
12
|
-
export const sveltekit_server = '\0virtual:__sveltekit/server';
|
|
13
|
-
|
|
14
12
|
export const app_server = posixify(
|
|
15
13
|
fileURLToPath(new URL('../../runtime/app/server/index.js', import.meta.url))
|
|
16
14
|
);
|
|
@@ -1,24 +1,23 @@
|
|
|
1
|
+
/** @import { NextHandleFunction } from 'connect' */
|
|
2
|
+
/** @import { PreviewServer, ResolvedConfig } from 'vite' */
|
|
3
|
+
/** @import { ValidatedConfig, ServerInternalModule, ServerModule } from 'types' */
|
|
1
4
|
import fs from 'node:fs';
|
|
2
5
|
import { join } from 'node:path';
|
|
3
6
|
import { pathToFileURL } from 'node:url';
|
|
4
|
-
import { lookup } from '
|
|
7
|
+
import { lookup } from '../../../utils/mime.js';
|
|
5
8
|
import sirv from 'sirv';
|
|
6
9
|
import { loadEnv, normalizePath } from 'vite';
|
|
7
10
|
import { createReadableStream, getRequest, setResponse } from '../../../exports/node/index.js';
|
|
8
11
|
import { SVELTE_KIT_ASSETS } from '../../../constants.js';
|
|
9
12
|
import { is_chrome_devtools_request, not_found } from '../utils.js';
|
|
10
|
-
|
|
11
|
-
/** @typedef {import('http').IncomingMessage} Req */
|
|
12
|
-
/** @typedef {import('http').ServerResponse} Res */
|
|
13
|
-
/** @typedef {(req: Req, res: Res, next: () => void) => void} Handler */
|
|
13
|
+
import { stackless } from '../../../utils/error.js';
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* @param {
|
|
17
|
-
* @param {
|
|
18
|
-
* @param {
|
|
19
|
-
* @param {import('@sveltejs/kit').Adapter | undefined} adapter
|
|
16
|
+
* @param {PreviewServer} vite
|
|
17
|
+
* @param {ResolvedConfig} vite_config
|
|
18
|
+
* @param {ValidatedConfig} svelte_config
|
|
20
19
|
*/
|
|
21
|
-
export async function preview(vite, vite_config, svelte_config
|
|
20
|
+
export async function preview(vite, vite_config, svelte_config) {
|
|
22
21
|
const { paths } = svelte_config.kit;
|
|
23
22
|
const base = paths.base;
|
|
24
23
|
const assets = paths.assets ? SVELTE_KIT_ASSETS : paths.base;
|
|
@@ -29,8 +28,8 @@ export async function preview(vite, vite_config, svelte_config, adapter) {
|
|
|
29
28
|
|
|
30
29
|
const dir = join(svelte_config.kit.outDir, 'output/server');
|
|
31
30
|
|
|
32
|
-
if (!fs.existsSync(dir)) {
|
|
33
|
-
throw
|
|
31
|
+
if (!fs.existsSync(`${dir}/manifest.js`)) {
|
|
32
|
+
throw stackless(`Server files not found at ${dir}, did you run \`build\` first?`);
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
const instrumentation = join(dir, 'instrumentation.server.js');
|
|
@@ -38,10 +37,10 @@ export async function preview(vite, vite_config, svelte_config, adapter) {
|
|
|
38
37
|
await import(pathToFileURL(instrumentation).href);
|
|
39
38
|
}
|
|
40
39
|
|
|
41
|
-
/** @type {
|
|
40
|
+
/** @type {ServerInternalModule} */
|
|
42
41
|
const { set_assets } = await import(pathToFileURL(join(dir, 'internal.js')).href);
|
|
43
42
|
|
|
44
|
-
/** @type {
|
|
43
|
+
/** @type {ServerModule} */
|
|
45
44
|
const { Server } = await import(pathToFileURL(join(dir, 'index.js')).href);
|
|
46
45
|
|
|
47
46
|
const { manifest } = await import(pathToFileURL(join(dir, 'manifest.js')).href);
|
|
@@ -49,12 +48,21 @@ export async function preview(vite, vite_config, svelte_config, adapter) {
|
|
|
49
48
|
set_assets(assets);
|
|
50
49
|
|
|
51
50
|
const server = new Server(manifest);
|
|
52
|
-
await server.init({
|
|
53
|
-
env: loadEnv(vite_config.mode, svelte_config.kit.env.dir, ''),
|
|
54
|
-
read: (file) => createReadableStream(`${dir}/${file}`)
|
|
55
|
-
});
|
|
56
51
|
|
|
57
|
-
|
|
52
|
+
try {
|
|
53
|
+
await server.init({
|
|
54
|
+
env: loadEnv(vite_config.mode, svelte_config.kit.env.dir, ''),
|
|
55
|
+
read: (file) => createReadableStream(`${dir}/${file}`)
|
|
56
|
+
});
|
|
57
|
+
} catch (error) {
|
|
58
|
+
// Vite erases the error message when starting the preview server so we store
|
|
59
|
+
// it in the stack instead. This ensures errors thrown using `stackless`
|
|
60
|
+
// are still readable
|
|
61
|
+
if (error instanceof Error) error.stack = error.message;
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const emulator = await svelte_config.kit.adapter?.emulate?.();
|
|
58
66
|
|
|
59
67
|
return () => {
|
|
60
68
|
// Remove the base middleware. It screws with the URL.
|
|
@@ -196,12 +204,12 @@ export async function preview(vite, vite_config, svelte_config, adapter) {
|
|
|
196
204
|
vite.middlewares.use(async (req, res) => {
|
|
197
205
|
const host = req.headers[':authority'] || req.headers.host;
|
|
198
206
|
|
|
199
|
-
const request =
|
|
207
|
+
const request = getRequest({
|
|
200
208
|
base: `${protocol}://${host}`,
|
|
201
209
|
request: req
|
|
202
210
|
});
|
|
203
211
|
|
|
204
|
-
|
|
212
|
+
setResponse(
|
|
205
213
|
res,
|
|
206
214
|
await server.respond(request, {
|
|
207
215
|
getClientAddress: () => {
|
|
@@ -225,7 +233,7 @@ export async function preview(vite, vite_config, svelte_config, adapter) {
|
|
|
225
233
|
|
|
226
234
|
/**
|
|
227
235
|
* @param {string} dir
|
|
228
|
-
* @returns {
|
|
236
|
+
* @returns {NextHandleFunction}
|
|
229
237
|
*/
|
|
230
238
|
const mutable = (dir) =>
|
|
231
239
|
fs.existsSync(dir)
|
|
@@ -237,8 +245,8 @@ const mutable = (dir) =>
|
|
|
237
245
|
|
|
238
246
|
/**
|
|
239
247
|
* @param {string} scope
|
|
240
|
-
* @param {
|
|
241
|
-
* @returns {
|
|
248
|
+
* @param {NextHandleFunction} handler
|
|
249
|
+
* @returns {NextHandleFunction}
|
|
242
250
|
*/
|
|
243
251
|
function scoped(scope, handler) {
|
|
244
252
|
if (scope === '') return handler;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
/** @import { PageOptions } from './types.js' */
|
|
1
2
|
import path from 'node:path';
|
|
2
3
|
import { tsPlugin } from '@sveltejs/acorn-typescript';
|
|
3
4
|
import { Parser } from 'acorn';
|
|
4
5
|
import { read } from '../../../utils/filesystem.js';
|
|
5
6
|
|
|
6
|
-
const valid_page_options_array = /** @type {const} */ ([
|
|
7
|
+
export const valid_page_options_array = /** @type {const} */ ([
|
|
7
8
|
'ssr',
|
|
8
9
|
'prerender',
|
|
9
10
|
'csr',
|
|
@@ -16,9 +17,6 @@ const valid_page_options_array = /** @type {const} */ ([
|
|
|
16
17
|
/** @type {Set<string>} */
|
|
17
18
|
const valid_page_options = new Set(valid_page_options_array);
|
|
18
19
|
|
|
19
|
-
/** @typedef {typeof valid_page_options_array[number]} ValidPageOption */
|
|
20
|
-
/** @typedef {Partial<Record<ValidPageOption, any>>} PageOptions */
|
|
21
|
-
|
|
22
20
|
const skip_parsing_regex = new RegExp(
|
|
23
21
|
`${Array.from(valid_page_options).join('|')}|(?:export[\\s\\n]+\\*[\\s\\n]+from)`
|
|
24
22
|
);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PrerenderOption, TrailingSlash } from 'types';
|
|
2
|
+
import type { valid_page_options_array } from './index.js';
|
|
3
|
+
|
|
4
|
+
type ValidPageOption = (typeof valid_page_options_array)[number];
|
|
5
|
+
|
|
6
|
+
export type PageOptions = Partial<{
|
|
7
|
+
[K in ValidPageOption]: K extends 'ssr' | 'csr'
|
|
8
|
+
? boolean
|
|
9
|
+
: K extends 'prerender'
|
|
10
|
+
? PrerenderOption
|
|
11
|
+
: K extends 'trailingSlash'
|
|
12
|
+
? TrailingSlash
|
|
13
|
+
: any;
|
|
14
|
+
}>;
|
|
@@ -2,6 +2,7 @@ import path from 'node:path';
|
|
|
2
2
|
import { posixify } from '../../utils/os.js';
|
|
3
3
|
import { negotiate } from '../../utils/http.js';
|
|
4
4
|
import { escape_html } from '../../utils/escape.js';
|
|
5
|
+
import { stackless } from '../../utils/error.js';
|
|
5
6
|
import { dedent } from '../../core/sync/utils.js';
|
|
6
7
|
import {
|
|
7
8
|
app_server,
|
|
@@ -9,22 +10,19 @@ import {
|
|
|
9
10
|
service_worker,
|
|
10
11
|
sveltekit_env_private
|
|
11
12
|
} from './module_ids.js';
|
|
13
|
+
import { styleText } from 'node:util';
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
|
-
* Transforms
|
|
16
|
+
* Transforms alias to a valid vite.resolve.alias array.
|
|
15
17
|
*
|
|
16
18
|
* Related to tsconfig path alias creation.
|
|
17
19
|
*
|
|
18
20
|
* @param {import('types').ValidatedKitConfig} config
|
|
19
21
|
* @param {string} root
|
|
20
|
-
|
|
22
|
+
*/
|
|
21
23
|
export function get_config_aliases(config, root) {
|
|
22
24
|
/** @type {import('vite').Alias[]} */
|
|
23
|
-
const alias = [
|
|
24
|
-
// For now, we handle `$lib` specially here rather than make it a default value for
|
|
25
|
-
// `config.kit.alias` since it has special meaning for packaging, etc.
|
|
26
|
-
{ find: '$lib', replacement: config.files.lib }
|
|
27
|
-
];
|
|
25
|
+
const alias = [];
|
|
28
26
|
|
|
29
27
|
for (let [key, value] of Object.entries(config.alias)) {
|
|
30
28
|
value = posixify(value);
|
|
@@ -35,16 +33,16 @@ export function get_config_aliases(config, root) {
|
|
|
35
33
|
// Doing just `{ find: key.slice(0, -2) ,..}` would mean `import .. from "key"` would also be matched, which we don't want
|
|
36
34
|
alias.push({
|
|
37
35
|
find: new RegExp(`^${escape_for_regexp(key.slice(0, -2))}\\/(.+)$`),
|
|
38
|
-
replacement: `${path.resolve(root, value)}/$1`
|
|
36
|
+
replacement: `${posixify(path.resolve(root, value))}/$1`
|
|
39
37
|
});
|
|
40
38
|
} else if (key + '/*' in config.alias) {
|
|
41
39
|
// key and key/* both exist -> the replacement for key needs to happen _only_ on import .. from "key"
|
|
42
40
|
alias.push({
|
|
43
41
|
find: new RegExp(`^${escape_for_regexp(key)}$`),
|
|
44
|
-
replacement: path.resolve(root, value)
|
|
42
|
+
replacement: posixify(path.resolve(root, value))
|
|
45
43
|
});
|
|
46
44
|
} else {
|
|
47
|
-
alias.push({ find: key, replacement: path.resolve(root, value) });
|
|
45
|
+
alias.push({ find: key, replacement: posixify(path.resolve(root, value)) });
|
|
48
46
|
}
|
|
49
47
|
}
|
|
50
48
|
|
|
@@ -117,16 +115,20 @@ export function not_found(req, res, base) {
|
|
|
117
115
|
const query_pattern = /\?.*$/s;
|
|
118
116
|
|
|
119
117
|
/**
|
|
120
|
-
* Removes cwd
|
|
118
|
+
* Removes cwd path from the start of the id and replaces any `#`-prefixed
|
|
119
|
+
* import alias target paths with their alias names.
|
|
121
120
|
* @param {string} id
|
|
122
|
-
* @param {string}
|
|
121
|
+
* @param {Array<{ alias: string, path: string }>} aliases — sorted by path length descending
|
|
123
122
|
* @param {string} cwd
|
|
124
123
|
*/
|
|
125
|
-
export function normalize_id(id,
|
|
124
|
+
export function normalize_id(id, aliases, cwd) {
|
|
126
125
|
id = id.replace(query_pattern, '');
|
|
127
126
|
|
|
128
|
-
|
|
129
|
-
id
|
|
127
|
+
for (const { alias, path } of aliases) {
|
|
128
|
+
if (id === path || id.startsWith(path + '/')) {
|
|
129
|
+
id = id.replace(path, alias);
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
130
132
|
}
|
|
131
133
|
|
|
132
134
|
if (id.startsWith(cwd)) {
|
|
@@ -148,34 +150,22 @@ export function normalize_id(id, lib, cwd) {
|
|
|
148
150
|
return posixify(id);
|
|
149
151
|
}
|
|
150
152
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
* can't do anything useful with it)
|
|
155
|
-
* @param {string} message
|
|
156
|
-
*/
|
|
157
|
-
export function stackless(message) {
|
|
158
|
-
const error = new Error(message);
|
|
159
|
-
error.stack = '';
|
|
160
|
-
return error;
|
|
161
|
-
}
|
|
153
|
+
export const remote_module_pattern = /[/.]remote(\.[^/]+)+$/;
|
|
154
|
+
export const server_only_module_pattern = /[/.]server(\.[^/]+)+$/;
|
|
155
|
+
export const server_only_directory_pattern = /\/server\//;
|
|
162
156
|
|
|
163
157
|
export const strip_virtual_prefix = /** @param {string} id */ (id) => id.replace('\0virtual:', '');
|
|
164
158
|
|
|
165
159
|
/**
|
|
166
|
-
* For `error_for_missing_config('
|
|
160
|
+
* For `error_for_missing_config('remote functions', 'experimental.remoteFunctions', 'true')`,
|
|
167
161
|
* returns:
|
|
168
162
|
*
|
|
169
163
|
* ```
|
|
170
|
-
* To enable
|
|
164
|
+
* To enable remote functions, add the following to the SvelteKit plugin in your `vite.config.js`:
|
|
171
165
|
*
|
|
172
166
|
*\`\`\`js
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
* instrumentation:
|
|
176
|
-
* server: true
|
|
177
|
-
* }
|
|
178
|
-
* }
|
|
167
|
+
* experimental: {
|
|
168
|
+
* remoteFunctions: true
|
|
179
169
|
* }
|
|
180
170
|
*\`\`\`
|
|
181
171
|
*```
|
|
@@ -196,9 +186,24 @@ export function error_for_missing_config(feature_name, path, value) {
|
|
|
196
186
|
|
|
197
187
|
throw stackless(
|
|
198
188
|
dedent`\
|
|
199
|
-
To enable ${feature_name}, add the following to your \`
|
|
189
|
+
To enable ${feature_name}, add the following to your SvelteKit plugin in \`vite.config.js\`:
|
|
200
190
|
|
|
201
191
|
${result}
|
|
202
192
|
`
|
|
203
193
|
);
|
|
204
194
|
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* @param {number} status
|
|
198
|
+
* @param {Request} request
|
|
199
|
+
*/
|
|
200
|
+
export function log_response(status, request) {
|
|
201
|
+
const url = new URL(request.url);
|
|
202
|
+
const log = `[${status}] ${request.method} ${url.href.replace(url.origin, '')}`;
|
|
203
|
+
|
|
204
|
+
if (status < 400) {
|
|
205
|
+
console.log(log);
|
|
206
|
+
} else {
|
|
207
|
+
console.error(styleText(['bold', 'red'], log));
|
|
208
|
+
}
|
|
209
|
+
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { BROWSER } from 'esm-env';
|
|
2
|
+
import { payload } from '../../client/payload.js';
|
|
3
|
+
|
|
4
|
+
export const version = BROWSER ? payload.version : __SVELTEKIT_APP_VERSION__;
|
|
2
5
|
export let building = false;
|
|
3
6
|
export let prerendering = false;
|
|
4
7
|
|
|
@@ -9,6 +12,3 @@ export function set_building() {
|
|
|
9
12
|
export function set_prerendering() {
|
|
10
13
|
prerendering = true;
|
|
11
14
|
}
|
|
12
|
-
|
|
13
|
-
// force /@vite/client to be injected
|
|
14
|
-
import.meta.hot;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DEV } from 'esm-env';
|
|
2
2
|
export * from '../env/index.js';
|
|
3
3
|
|
|
4
|
-
if (
|
|
5
|
-
console.warn('`$app/environment` is
|
|
4
|
+
if (DEV) {
|
|
5
|
+
console.warn('`$app/environment` is deprecated, use `$app/env` instead');
|
|
6
6
|
}
|
package/src/runtime/app/forms.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as devalue from 'devalue';
|
|
2
2
|
import { BROWSER, DEV } from 'esm-env';
|
|
3
3
|
import { noop } from '../../utils/functions.js';
|
|
4
|
-
import {
|
|
5
|
-
import { app as client_app, applyAction } from '../client/client.js';
|
|
4
|
+
import { refreshAll } from './navigation.js';
|
|
5
|
+
import { app as client_app, applyAction, handle_error } from '../client/client.js';
|
|
6
6
|
import { app as server_app } from '../server/app.js';
|
|
7
7
|
|
|
8
8
|
export { applyAction };
|
|
@@ -30,11 +30,15 @@ export { applyAction };
|
|
|
30
30
|
* @returns {import('@sveltejs/kit').ActionResult<Success, Failure>}
|
|
31
31
|
*/
|
|
32
32
|
export function deserialize(result) {
|
|
33
|
+
if (result === '') {
|
|
34
|
+
return { type: 'success', status: 204, data: undefined };
|
|
35
|
+
}
|
|
36
|
+
|
|
33
37
|
const parsed = JSON.parse(result);
|
|
34
38
|
|
|
35
39
|
if (parsed.data) {
|
|
36
40
|
// the decoders should never be initialised at the top-level because `app`
|
|
37
|
-
// will not be initialised yet if `
|
|
41
|
+
// will not be initialised yet if `output.bundleStrategy` is 'single' or 'inline'
|
|
38
42
|
parsed.data = devalue.parse(parsed.data, BROWSER ? client_app.decoders : server_app.decoders);
|
|
39
43
|
}
|
|
40
44
|
|
|
@@ -102,7 +106,7 @@ export function enhance(form_element, submit = noop) {
|
|
|
102
106
|
HTMLFormElement.prototype.reset.call(form_element);
|
|
103
107
|
}
|
|
104
108
|
if (shouldInvalidateAll) {
|
|
105
|
-
await
|
|
109
|
+
await refreshAll();
|
|
106
110
|
}
|
|
107
111
|
}
|
|
108
112
|
|
|
@@ -197,11 +201,24 @@ export function enhance(form_element, submit = noop) {
|
|
|
197
201
|
signal: controller.signal
|
|
198
202
|
});
|
|
199
203
|
|
|
200
|
-
|
|
201
|
-
|
|
204
|
+
if (response.status === 204) {
|
|
205
|
+
result = { type: 'success', status: 204 };
|
|
206
|
+
} else {
|
|
207
|
+
result = deserialize(await response.text());
|
|
208
|
+
if (result.type === 'error' || result.type === 'failure') {
|
|
209
|
+
result.status = response.status;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
202
212
|
} catch (error) {
|
|
203
213
|
if (/** @type {any} */ (error)?.name === 'AbortError') return;
|
|
204
|
-
result = {
|
|
214
|
+
result = {
|
|
215
|
+
type: 'error',
|
|
216
|
+
error: await handle_error(error, {
|
|
217
|
+
params: {},
|
|
218
|
+
route: { id: null },
|
|
219
|
+
url: new URL(location.href)
|
|
220
|
+
})
|
|
221
|
+
};
|
|
205
222
|
}
|
|
206
223
|
|
|
207
224
|
await callback({
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
/** @import { Asset, RouteId, RouteIdWithSearchOrHash, Pathname, PathnameWithSearchOrHash, ResolvedPathname } from '$app/types' */
|
|
1
|
+
/** @import { Asset, RouteId, RouteIdWithSearchOrHash, Pathname, PathnameWithSearchOrHash, ResolvedPathname, RouteParams } from '$app/types' */
|
|
2
2
|
/** @import { ResolveArgs } from './types.js' */
|
|
3
3
|
import { base, assets, hash_routing } from './internal/client.js';
|
|
4
4
|
import { resolve_route } from '../../../utils/routing.js';
|
|
5
5
|
import { get_navigation_intent } from '../../client/client.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* Resolve the URL of an asset in your `static` directory, by prefixing it with [`config.
|
|
8
|
+
* Resolve the URL of an asset in your `static` directory, by prefixing it with [`config.paths.assets`](https://svelte.dev/docs/kit/configuration#paths) if configured, or otherwise by prefixing it with the base path.
|
|
9
9
|
*
|
|
10
10
|
* During server rendering, the base path is relative and depends on the page currently being rendered.
|
|
11
11
|
*
|
|
@@ -59,11 +59,7 @@ export function resolve(...args) {
|
|
|
59
59
|
);
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
// but we don't want to adjust the internal resolve_route function to accept `undefined`, hence the type cast.
|
|
64
|
-
return (
|
|
65
|
-
base + pathname_prefix + resolve_route(args[0], /** @type {Record<string, string>} */ (args[1]))
|
|
66
|
-
);
|
|
62
|
+
return base + pathname_prefix + resolve_route(args[0], args[1] ?? {});
|
|
67
63
|
}
|
|
68
64
|
|
|
69
65
|
/**
|
|
@@ -84,7 +80,7 @@ export function resolve(...args) {
|
|
|
84
80
|
* @since 2.52.0
|
|
85
81
|
*
|
|
86
82
|
* @param {Pathname | URL | (string & {})} url
|
|
87
|
-
* @returns {Promise<{ id:
|
|
83
|
+
* @returns {Promise<{ [K in RouteId]: { id: K; params: RouteParams<K>; } }[RouteId] | null>}
|
|
88
84
|
*/
|
|
89
85
|
export async function match(url) {
|
|
90
86
|
if (typeof url === 'string') {
|
|
@@ -102,5 +98,3 @@ export async function match(url) {
|
|
|
102
98
|
|
|
103
99
|
return null;
|
|
104
100
|
}
|
|
105
|
-
|
|
106
|
-
export { base, assets, resolve as resolveRoute };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { payload } from '../../../client/payload.js';
|
|
2
|
+
|
|
3
|
+
export const base = payload.base ?? __SVELTEKIT_PATHS_BASE__;
|
|
4
|
+
export const assets = payload.assets ?? base ?? __SVELTEKIT_PATHS_ASSETS__;
|
|
3
5
|
export const app_dir = __SVELTEKIT_APP_DIR__;
|
|
4
6
|
export const hash_routing = __SVELTEKIT_HASH_ROUTING__;
|
|
@@ -1,30 +1,9 @@
|
|
|
1
|
-
export
|
|
1
|
+
export const base = __SVELTEKIT_PATHS_BASE__;
|
|
2
2
|
export let assets = __SVELTEKIT_PATHS_ASSETS__ || base;
|
|
3
3
|
export const app_dir = __SVELTEKIT_APP_DIR__;
|
|
4
4
|
export const relative = __SVELTEKIT_PATHS_RELATIVE__;
|
|
5
5
|
|
|
6
|
-
const initial = { base, assets };
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* `base` could be overridden during rendering to be relative;
|
|
10
|
-
* this one's the original non-relative base path
|
|
11
|
-
*/
|
|
12
|
-
export const initial_base = initial.base;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @param {{ base: string, assets: string }} paths
|
|
16
|
-
*/
|
|
17
|
-
export function override(paths) {
|
|
18
|
-
base = paths.base;
|
|
19
|
-
assets = paths.assets;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function reset() {
|
|
23
|
-
base = initial.base;
|
|
24
|
-
assets = initial.assets;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
6
|
/** @param {string} path */
|
|
28
7
|
export function set_assets(path) {
|
|
29
|
-
assets =
|
|
8
|
+
assets = path;
|
|
30
9
|
}
|
|
@@ -1,29 +1 @@
|
|
|
1
|
-
import { RouteIdWithSearchOrHash, PathnameWithSearchOrHash, ResolvedPathname } from '$app/types';
|
|
2
|
-
import { ResolveArgs } from './types.js';
|
|
3
|
-
|
|
4
1
|
export { resolve, asset, match } from './client.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* A string that matches [`config.kit.paths.base`](https://svelte.dev/docs/kit/configuration#paths).
|
|
8
|
-
*
|
|
9
|
-
* Example usage: `<a href="{base}/your-page">Link</a>`
|
|
10
|
-
*
|
|
11
|
-
* @deprecated Use [`resolve(...)`](https://svelte.dev/docs/kit/$app-paths#resolve) instead
|
|
12
|
-
*/
|
|
13
|
-
export let base: '' | `/${string}`;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* An absolute path that matches [`config.kit.paths.assets`](https://svelte.dev/docs/kit/configuration#paths).
|
|
17
|
-
*
|
|
18
|
-
* > [!NOTE] If a value for `config.kit.paths.assets` is specified, it will be replaced with `'/_svelte_kit_assets'` during `vite dev` or `vite preview`, since the assets don't yet live at their eventual URL.
|
|
19
|
-
*
|
|
20
|
-
* @deprecated Use [`asset(...)`](https://svelte.dev/docs/kit/$app-paths#asset) instead
|
|
21
|
-
*/
|
|
22
|
-
export let assets: '' | `https://${string}` | `http://${string}` | '/_svelte_kit_assets';
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @deprecated Use [`resolve(...)`](https://svelte.dev/docs/kit/$app-paths#resolve) instead
|
|
26
|
-
*/
|
|
27
|
-
export function resolveRoute<T extends RouteIdWithSearchOrHash | PathnameWithSearchOrHash>(
|
|
28
|
-
...args: ResolveArgs<T>
|
|
29
|
-
): ResolvedPathname;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { base, assets, relative
|
|
1
|
+
import { base, assets, relative } from './internal/server.js';
|
|
2
2
|
import { resolve_route, find_route } from '../../../utils/routing.js';
|
|
3
3
|
import { decode_pathname } from '../../../utils/url.js';
|
|
4
|
+
import { add_data_suffix } from '../../pathname.js';
|
|
4
5
|
import { try_get_request_store } from '@sveltejs/kit/internal/server';
|
|
5
|
-
import { manifest } from '
|
|
6
|
+
import { manifest } from '../../server/internal.js';
|
|
6
7
|
import { get_hooks } from '__SERVER__/internal.js';
|
|
7
8
|
|
|
8
9
|
/** @type {import('./client.js').asset} */
|
|
@@ -20,13 +21,18 @@ export function resolve(id, params) {
|
|
|
20
21
|
);
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
const resolved = resolve_route(id,
|
|
24
|
+
const resolved = resolve_route(id, params ?? {});
|
|
24
25
|
|
|
25
26
|
if (relative) {
|
|
26
27
|
const store = try_get_request_store();
|
|
27
28
|
|
|
28
29
|
if (store && !store.state.prerendering?.fallback) {
|
|
29
|
-
|
|
30
|
+
// the relative path depth must reflect the URL the browser is actually at, which
|
|
31
|
+
// for a data request includes the `__data.json` suffix that was stripped during routing
|
|
32
|
+
const pathname = store.event.isDataRequest
|
|
33
|
+
? add_data_suffix(store.event.url.pathname)
|
|
34
|
+
: store.event.url.pathname;
|
|
35
|
+
const after_base = pathname.slice(base.length);
|
|
30
36
|
const segments = after_base.split('/').slice(2);
|
|
31
37
|
const prefix = segments.map(() => '..').join('/') || '.';
|
|
32
38
|
|
|
@@ -74,5 +80,3 @@ export async function match(url) {
|
|
|
74
80
|
|
|
75
81
|
return null;
|
|
76
82
|
}
|
|
77
|
-
|
|
78
|
-
export { base, assets, resolve as resolveRoute };
|
|
@@ -77,9 +77,6 @@ export function command(validate_or_fn, maybe_fn) {
|
|
|
77
77
|
);
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
state.remote.refreshes ??= new Map();
|
|
81
|
-
state.remote.reconnects ??= new Map();
|
|
82
|
-
|
|
83
80
|
const promise = Promise.resolve(
|
|
84
81
|
run_remote_function(event, state, true, () => validate(arg), fn)
|
|
85
82
|
);
|