@sveltejs/kit 1.0.11 → 1.0.13
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 +3 -3
- package/src/core/adapt/builder.js +1 -1
- package/src/core/{prerender → postbuild}/crawl.js +0 -0
- package/src/core/{prerender → postbuild}/entities.js +0 -0
- package/src/core/{prerender → postbuild}/fallback.js +10 -7
- package/src/core/postbuild/index.js +104 -0
- package/src/core/{prerender → postbuild}/prerender.js +32 -106
- package/src/core/{prerender → postbuild}/queue.js +0 -0
- package/src/core/sync/sync.js +10 -0
- package/src/core/sync/write_client_manifest.js +1 -1
- package/src/core/sync/write_server.js +89 -0
- package/src/core/utils.js +0 -9
- package/src/exports/vite/build/build_server.js +11 -163
- package/src/exports/vite/build/build_service_worker.js +3 -2
- package/src/exports/vite/build/utils.js +1 -0
- package/src/exports/vite/dev/index.js +72 -114
- package/src/exports/vite/index.js +26 -27
- package/src/exports/vite/preview/index.js +11 -12
- package/src/runtime/app/environment.js +1 -1
- package/src/runtime/app/paths.js +1 -1
- package/src/runtime/client/client.js +8 -2
- package/src/runtime/client/fetcher.js +12 -4
- package/src/runtime/client/start.js +1 -2
- package/src/runtime/client/types.d.ts +1 -1
- package/src/runtime/client/utils.js +1 -2
- package/src/runtime/control.js +23 -5
- package/src/runtime/server/ambient.d.ts +8 -0
- package/src/runtime/server/cookie.js +4 -5
- package/src/runtime/server/data/index.js +5 -2
- package/src/runtime/server/endpoint.js +5 -5
- package/src/runtime/server/fetch.js +11 -9
- package/src/runtime/server/index.js +54 -395
- package/src/runtime/server/page/csp.js +9 -11
- package/src/runtime/server/page/index.js +13 -8
- package/src/runtime/server/page/load_data.js +2 -3
- package/src/runtime/server/page/render.js +28 -25
- package/src/runtime/server/page/respond_with_error.js +20 -13
- package/src/runtime/server/page/types.d.ts +0 -1
- package/src/runtime/server/respond.js +419 -0
- package/src/runtime/server/utils.js +21 -4
- package/src/runtime/shared.js +28 -0
- package/types/index.d.ts +10 -5
- package/types/internal.d.ts +22 -39
- package/src/runtime/env.js +0 -12
- package/src/runtime/paths.js +0 -11
|
@@ -3,6 +3,7 @@ import { coalesce_to_error } from '../../utils/error.js';
|
|
|
3
3
|
import { negotiate } from '../../utils/http.js';
|
|
4
4
|
import { has_data_suffix } from '../../utils/url.js';
|
|
5
5
|
import { HttpError } from '../control.js';
|
|
6
|
+
import { fix_stack_trace } from '../shared.js';
|
|
6
7
|
|
|
7
8
|
/** @param {any} body */
|
|
8
9
|
export function is_pojo(body) {
|
|
@@ -74,7 +75,7 @@ export function get_option(nodes, option) {
|
|
|
74
75
|
* @param {string} message
|
|
75
76
|
*/
|
|
76
77
|
export function static_error_page(options, status, message) {
|
|
77
|
-
return new Response(options.
|
|
78
|
+
return new Response(options.templates.error({ status, message }), {
|
|
78
79
|
headers: { 'content-type': 'text/html; charset=utf-8' },
|
|
79
80
|
status
|
|
80
81
|
});
|
|
@@ -110,13 +111,29 @@ export async function handle_fatal_error(event, options, error) {
|
|
|
110
111
|
* @param {import('types').RequestEvent} event
|
|
111
112
|
* @param {import('types').SSROptions} options
|
|
112
113
|
* @param {any} error
|
|
113
|
-
* @returns {
|
|
114
|
+
* @returns {Promise<App.Error>}
|
|
114
115
|
*/
|
|
115
|
-
export function handle_error_and_jsonify(event, options, error) {
|
|
116
|
+
export async function handle_error_and_jsonify(event, options, error) {
|
|
116
117
|
if (error instanceof HttpError) {
|
|
117
118
|
return error.body;
|
|
118
119
|
} else {
|
|
119
|
-
|
|
120
|
+
if (__SVELTEKIT_DEV__) {
|
|
121
|
+
error = new Proxy(error, {
|
|
122
|
+
get: (target, property) => {
|
|
123
|
+
if (property === 'stack') {
|
|
124
|
+
return fix_stack_trace(target.stack);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return Reflect.get(target, property, target);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return (
|
|
133
|
+
(await options.hooks.handleError({ error, event })) ?? {
|
|
134
|
+
message: event.route.id != null ? 'Internal Error' : 'Not Found'
|
|
135
|
+
}
|
|
136
|
+
);
|
|
120
137
|
}
|
|
121
138
|
}
|
|
122
139
|
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export let assets = '';
|
|
2
|
+
export let base = '';
|
|
3
|
+
export let building = false;
|
|
4
|
+
export let version = '';
|
|
5
|
+
|
|
6
|
+
/** @param {string} stack */
|
|
7
|
+
export let fix_stack_trace = (stack) => stack;
|
|
8
|
+
|
|
9
|
+
/** @param {{ base: string, assets: string }} paths */
|
|
10
|
+
export function set_paths(paths) {
|
|
11
|
+
base = paths.base;
|
|
12
|
+
assets = paths.assets || base;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** @param {boolean} value */
|
|
16
|
+
export function set_building(value) {
|
|
17
|
+
building = value;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** @param {string} value */
|
|
21
|
+
export function set_version(value) {
|
|
22
|
+
version = value;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** @param {(stack: string) => string} value */
|
|
26
|
+
export function set_fix_stack_trace(value) {
|
|
27
|
+
fix_stack_trace = value;
|
|
28
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -1080,7 +1080,7 @@ export type ActionResult<
|
|
|
1080
1080
|
* Creates an `HttpError` object with an HTTP status code and an optional message.
|
|
1081
1081
|
* This object, if thrown during request handling, will cause SvelteKit to
|
|
1082
1082
|
* return an error response without invoking `handleError`
|
|
1083
|
-
* @param status The HTTP status code
|
|
1083
|
+
* @param status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
|
|
1084
1084
|
* @param body An object that conforms to the App.Error type. If a string is passed, it will be used as the message property.
|
|
1085
1085
|
*/
|
|
1086
1086
|
export function error(status: number, body: App.Error): HttpError;
|
|
@@ -1094,15 +1094,16 @@ export function error(
|
|
|
1094
1094
|
* The object returned by the [`error`](https://kit.svelte.dev/docs/modules#sveltejs-kit-error) function.
|
|
1095
1095
|
*/
|
|
1096
1096
|
export interface HttpError {
|
|
1097
|
-
/** The [HTTP status code](https://
|
|
1097
|
+
/** The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses), in the range 400-599. */
|
|
1098
1098
|
status: number;
|
|
1099
1099
|
/** The content of the error. */
|
|
1100
1100
|
body: App.Error;
|
|
1101
1101
|
}
|
|
1102
1102
|
|
|
1103
1103
|
/**
|
|
1104
|
-
* Create a `Redirect` object. If thrown during request handling, SvelteKit will
|
|
1105
|
-
*
|
|
1104
|
+
* Create a `Redirect` object. If thrown during request handling, SvelteKit will return a redirect response.
|
|
1105
|
+
* @param status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#redirection_messages). Must be in the range 300-308.
|
|
1106
|
+
* @param location The location to redirect to.
|
|
1106
1107
|
*/
|
|
1107
1108
|
export function redirect(
|
|
1108
1109
|
status: 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308,
|
|
@@ -1113,7 +1114,7 @@ export function redirect(
|
|
|
1113
1114
|
* The object returned by the [`redirect`](https://kit.svelte.dev/docs/modules#sveltejs-kit-redirect) function
|
|
1114
1115
|
*/
|
|
1115
1116
|
export interface Redirect {
|
|
1116
|
-
/** The [HTTP status code](https://
|
|
1117
|
+
/** The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#redirection_messages), in the range 300-308. */
|
|
1117
1118
|
status: 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308;
|
|
1118
1119
|
/** The location to redirect to. */
|
|
1119
1120
|
location: string;
|
|
@@ -1128,6 +1129,8 @@ export function json(data: any, init?: ResponseInit): Response;
|
|
|
1128
1129
|
|
|
1129
1130
|
/**
|
|
1130
1131
|
* Create an `ActionFailure` object.
|
|
1132
|
+
* @param status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
|
|
1133
|
+
* @param data Data associated with the failure (e.g. validation errors)
|
|
1131
1134
|
*/
|
|
1132
1135
|
export function fail<T extends Record<string, unknown> | undefined>(
|
|
1133
1136
|
status: number,
|
|
@@ -1139,7 +1142,9 @@ export function fail<T extends Record<string, unknown> | undefined>(
|
|
|
1139
1142
|
*/
|
|
1140
1143
|
export interface ActionFailure<T extends Record<string, unknown> | undefined = undefined>
|
|
1141
1144
|
extends UniqueInterface {
|
|
1145
|
+
/** The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses), in the range 400-599. */
|
|
1142
1146
|
status: number;
|
|
1147
|
+
/** Data associated with the failure (e.g. validation errors) */
|
|
1143
1148
|
data: T;
|
|
1144
1149
|
}
|
|
1145
1150
|
|
package/types/internal.d.ts
CHANGED
|
@@ -27,16 +27,13 @@ import {
|
|
|
27
27
|
|
|
28
28
|
export interface ServerModule {
|
|
29
29
|
Server: typeof InternalServer;
|
|
30
|
+
}
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
};
|
|
37
|
-
protocol?: 'http' | 'https';
|
|
38
|
-
read(file: string): Buffer;
|
|
39
|
-
}): void;
|
|
32
|
+
export interface ServerInternalModule {
|
|
33
|
+
set_building(building: boolean): void;
|
|
34
|
+
set_paths(paths: { base: string; assets: string }): void;
|
|
35
|
+
set_version(version: string): void;
|
|
36
|
+
set_fix_stack_trace(fix_stack_trace: (stack: string) => string): void;
|
|
40
37
|
}
|
|
41
38
|
|
|
42
39
|
export interface Asset {
|
|
@@ -74,7 +71,7 @@ export interface CSRPageNode {
|
|
|
74
71
|
load?: Load;
|
|
75
72
|
trailingSlash?: TrailingSlash;
|
|
76
73
|
};
|
|
77
|
-
|
|
74
|
+
has_server_load: boolean;
|
|
78
75
|
}
|
|
79
76
|
|
|
80
77
|
export type CSRPageNodeLoader = () => Promise<CSRPageNode>;
|
|
@@ -109,6 +106,7 @@ export class InternalServer extends Server {
|
|
|
109
106
|
request: Request,
|
|
110
107
|
options: RequestOptions & {
|
|
111
108
|
prerendering?: PrerenderOptions;
|
|
109
|
+
read: (file: string) => Buffer;
|
|
112
110
|
}
|
|
113
111
|
): Promise<Response>;
|
|
114
112
|
}
|
|
@@ -155,7 +153,12 @@ export type RecursiveRequired<T> = {
|
|
|
155
153
|
export type RequiredResolveOptions = Required<ResolveOptions>;
|
|
156
154
|
|
|
157
155
|
export interface Respond {
|
|
158
|
-
(
|
|
156
|
+
(
|
|
157
|
+
request: Request,
|
|
158
|
+
options: SSROptions,
|
|
159
|
+
manifest: SSRManifest,
|
|
160
|
+
state: SSRState
|
|
161
|
+
): Promise<Response>;
|
|
159
162
|
}
|
|
160
163
|
|
|
161
164
|
export interface RouteParam {
|
|
@@ -294,37 +297,18 @@ export interface SSRNode {
|
|
|
294
297
|
export type SSRNodeLoader = () => Promise<SSRNode>;
|
|
295
298
|
|
|
296
299
|
export interface SSROptions {
|
|
300
|
+
app_template_contains_nonce: boolean;
|
|
297
301
|
csp: ValidatedConfig['kit']['csp'];
|
|
298
|
-
|
|
299
|
-
check_origin: boolean;
|
|
300
|
-
};
|
|
301
|
-
dev: boolean;
|
|
302
|
+
csrf_check_origin: boolean;
|
|
302
303
|
embedded: boolean;
|
|
303
|
-
|
|
304
|
+
env_public_prefix: string;
|
|
304
305
|
hooks: ServerHooks;
|
|
305
|
-
manifest: SSRManifest;
|
|
306
|
-
paths: {
|
|
307
|
-
base: string;
|
|
308
|
-
assets: string;
|
|
309
|
-
};
|
|
310
|
-
public_env: Record<string, string>;
|
|
311
|
-
read(file: string): Buffer;
|
|
312
306
|
root: SSRComponent['default'];
|
|
313
307
|
service_worker: boolean;
|
|
314
|
-
|
|
315
|
-
head
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
nonce
|
|
319
|
-
}: {
|
|
320
|
-
head: string;
|
|
321
|
-
body: string;
|
|
322
|
-
assets: string;
|
|
323
|
-
nonce: string;
|
|
324
|
-
}): string;
|
|
325
|
-
app_template_contains_nonce: boolean;
|
|
326
|
-
error_template({ message, status }: { message: string; status: number }): string;
|
|
327
|
-
version: string;
|
|
308
|
+
templates: {
|
|
309
|
+
app(values: { head: string; body: string; assets: string; nonce: string }): string;
|
|
310
|
+
error(values: { message: string; status: number }): string;
|
|
311
|
+
};
|
|
328
312
|
}
|
|
329
313
|
|
|
330
314
|
export interface SSRErrorPage {
|
|
@@ -362,6 +346,7 @@ export interface SSRState {
|
|
|
362
346
|
* prerender option is inherited by the endpoint, unless overridden
|
|
363
347
|
*/
|
|
364
348
|
prerender_default?: PrerenderOption;
|
|
349
|
+
read?: (file: string) => Buffer;
|
|
365
350
|
}
|
|
366
351
|
|
|
367
352
|
export type StrictBody = string | ArrayBufferView;
|
|
@@ -383,10 +368,8 @@ export * from './private';
|
|
|
383
368
|
|
|
384
369
|
declare global {
|
|
385
370
|
const __SVELTEKIT_ADAPTER_NAME__: string;
|
|
386
|
-
const __SVELTEKIT_APP_VERSION__: string;
|
|
387
371
|
const __SVELTEKIT_APP_VERSION_FILE__: string;
|
|
388
372
|
const __SVELTEKIT_APP_VERSION_POLL_INTERVAL__: number;
|
|
389
|
-
const __SVELTEKIT_BROWSER__: boolean;
|
|
390
373
|
const __SVELTEKIT_DEV__: boolean;
|
|
391
374
|
const __SVELTEKIT_EMBEDDED__: boolean;
|
|
392
375
|
var Bun: object;
|
package/src/runtime/env.js
DELETED
package/src/runtime/paths.js
DELETED