@sveltejs/kit 1.0.0-next.270 → 1.0.0-next.271
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/assets/server/index.js +50 -25
- package/dist/cli.js +2 -2
- package/package.json +1 -1
- package/types/hooks.d.ts +6 -3
- package/types/index.d.ts +8 -1
package/assets/server/index.js
CHANGED
|
@@ -1057,7 +1057,7 @@ const updated = {
|
|
|
1057
1057
|
* error?: Error;
|
|
1058
1058
|
* url: URL;
|
|
1059
1059
|
* params: Record<string, string>;
|
|
1060
|
-
*
|
|
1060
|
+
* resolve_opts: import('types/hooks').RequiredResolveOptions;
|
|
1061
1061
|
* stuff: Record<string, any>;
|
|
1062
1062
|
* }} opts
|
|
1063
1063
|
*/
|
|
@@ -1071,7 +1071,7 @@ async function render_response({
|
|
|
1071
1071
|
error,
|
|
1072
1072
|
url,
|
|
1073
1073
|
params,
|
|
1074
|
-
|
|
1074
|
+
resolve_opts,
|
|
1075
1075
|
stuff
|
|
1076
1076
|
}) {
|
|
1077
1077
|
if (state.prerender) {
|
|
@@ -1103,7 +1103,7 @@ async function render_response({
|
|
|
1103
1103
|
error.stack = options.get_stack(error);
|
|
1104
1104
|
}
|
|
1105
1105
|
|
|
1106
|
-
if (ssr) {
|
|
1106
|
+
if (resolve_opts.ssr) {
|
|
1107
1107
|
branch.forEach(({ node, props, loaded, fetched, uses_credentials }) => {
|
|
1108
1108
|
if (node.css) node.css.forEach((url) => stylesheets.add(url));
|
|
1109
1109
|
if (node.js) node.js.forEach((url) => modulepreloads.add(url));
|
|
@@ -1199,9 +1199,9 @@ async function render_response({
|
|
|
1199
1199
|
throw new Error(`Failed to serialize session data: ${error.message}`);
|
|
1200
1200
|
})},
|
|
1201
1201
|
route: ${!!page_config.router},
|
|
1202
|
-
spa: ${!ssr},
|
|
1202
|
+
spa: ${!resolve_opts.ssr},
|
|
1203
1203
|
trailing_slash: ${s(options.trailing_slash)},
|
|
1204
|
-
hydrate: ${ssr && page_config.hydrate ? `{
|
|
1204
|
+
hydrate: ${resolve_opts.ssr && page_config.hydrate ? `{
|
|
1205
1205
|
status: ${status},
|
|
1206
1206
|
error: ${serialize_error(error)},
|
|
1207
1207
|
nodes: [
|
|
@@ -1327,7 +1327,9 @@ async function render_response({
|
|
|
1327
1327
|
const assets =
|
|
1328
1328
|
options.paths.assets || (segments.length > 0 ? segments.map(() => '..').join('/') : '.');
|
|
1329
1329
|
|
|
1330
|
-
const html =
|
|
1330
|
+
const html = resolve_opts.transformPage({
|
|
1331
|
+
html: options.template({ head, body, assets, nonce: /** @type {string} */ (csp.nonce) })
|
|
1332
|
+
});
|
|
1331
1333
|
|
|
1332
1334
|
const headers = new Headers({
|
|
1333
1335
|
'content-type': 'text/html',
|
|
@@ -2014,10 +2016,18 @@ function validate_shadow_output(result) {
|
|
|
2014
2016
|
* $session: any;
|
|
2015
2017
|
* status: number;
|
|
2016
2018
|
* error: Error;
|
|
2017
|
-
*
|
|
2019
|
+
* resolve_opts: import('types/hooks').RequiredResolveOptions;
|
|
2018
2020
|
* }} opts
|
|
2019
2021
|
*/
|
|
2020
|
-
async function respond_with_error({
|
|
2022
|
+
async function respond_with_error({
|
|
2023
|
+
event,
|
|
2024
|
+
options,
|
|
2025
|
+
state,
|
|
2026
|
+
$session,
|
|
2027
|
+
status,
|
|
2028
|
+
error,
|
|
2029
|
+
resolve_opts
|
|
2030
|
+
}) {
|
|
2021
2031
|
try {
|
|
2022
2032
|
const default_layout = await options.manifest._.nodes[0](); // 0 is always the root layout
|
|
2023
2033
|
const default_error = await options.manifest._.nodes[1](); // 1 is always the root error
|
|
@@ -2073,7 +2083,7 @@ async function respond_with_error({ event, options, state, $session, status, err
|
|
|
2073
2083
|
branch: [layout_loaded, error_loaded],
|
|
2074
2084
|
url: event.url,
|
|
2075
2085
|
params,
|
|
2076
|
-
|
|
2086
|
+
resolve_opts
|
|
2077
2087
|
});
|
|
2078
2088
|
} catch (err) {
|
|
2079
2089
|
const error = coalesce_to_error(err);
|
|
@@ -2099,19 +2109,19 @@ async function respond_with_error({ event, options, state, $session, status, err
|
|
|
2099
2109
|
* options: SSROptions;
|
|
2100
2110
|
* state: SSRState;
|
|
2101
2111
|
* $session: any;
|
|
2112
|
+
* resolve_opts: import('types/hooks').RequiredResolveOptions;
|
|
2102
2113
|
* route: import('types/internal').SSRPage;
|
|
2103
2114
|
* params: Record<string, string>;
|
|
2104
|
-
* ssr: boolean;
|
|
2105
2115
|
* }} opts
|
|
2106
2116
|
* @returns {Promise<Response | undefined>}
|
|
2107
2117
|
*/
|
|
2108
2118
|
async function respond$1(opts) {
|
|
2109
|
-
const { event, options, state, $session, route,
|
|
2119
|
+
const { event, options, state, $session, route, resolve_opts } = opts;
|
|
2110
2120
|
|
|
2111
2121
|
/** @type {Array<SSRNode | undefined>} */
|
|
2112
2122
|
let nodes;
|
|
2113
2123
|
|
|
2114
|
-
if (!ssr) {
|
|
2124
|
+
if (!resolve_opts.ssr) {
|
|
2115
2125
|
return await render_response({
|
|
2116
2126
|
...opts,
|
|
2117
2127
|
branch: [],
|
|
@@ -2141,7 +2151,7 @@ async function respond$1(opts) {
|
|
|
2141
2151
|
$session,
|
|
2142
2152
|
status: 500,
|
|
2143
2153
|
error,
|
|
2144
|
-
|
|
2154
|
+
resolve_opts
|
|
2145
2155
|
});
|
|
2146
2156
|
}
|
|
2147
2157
|
|
|
@@ -2172,7 +2182,7 @@ async function respond$1(opts) {
|
|
|
2172
2182
|
|
|
2173
2183
|
let stuff = {};
|
|
2174
2184
|
|
|
2175
|
-
ssr: if (ssr) {
|
|
2185
|
+
ssr: if (resolve_opts.ssr) {
|
|
2176
2186
|
for (let i = 0; i < nodes.length; i += 1) {
|
|
2177
2187
|
const node = nodes[i];
|
|
2178
2188
|
|
|
@@ -2277,7 +2287,7 @@ async function respond$1(opts) {
|
|
|
2277
2287
|
$session,
|
|
2278
2288
|
status,
|
|
2279
2289
|
error,
|
|
2280
|
-
|
|
2290
|
+
resolve_opts
|
|
2281
2291
|
}),
|
|
2282
2292
|
set_cookie_headers
|
|
2283
2293
|
);
|
|
@@ -2358,10 +2368,10 @@ function with_cookies(response, set_cookie_headers) {
|
|
|
2358
2368
|
* @param {import('types/internal').SSRPage} route
|
|
2359
2369
|
* @param {import('types/internal').SSROptions} options
|
|
2360
2370
|
* @param {import('types/internal').SSRState} state
|
|
2361
|
-
* @param {
|
|
2371
|
+
* @param {import('types/hooks').RequiredResolveOptions} resolve_opts
|
|
2362
2372
|
* @returns {Promise<Response | undefined>}
|
|
2363
2373
|
*/
|
|
2364
|
-
async function render_page(event, route, options, state,
|
|
2374
|
+
async function render_page(event, route, options, state, resolve_opts) {
|
|
2365
2375
|
if (state.initiator === route) {
|
|
2366
2376
|
// infinite request cycle detected
|
|
2367
2377
|
return new Response(`Not found: ${event.url.pathname}`, {
|
|
@@ -2387,9 +2397,9 @@ async function render_page(event, route, options, state, ssr) {
|
|
|
2387
2397
|
options,
|
|
2388
2398
|
state,
|
|
2389
2399
|
$session,
|
|
2400
|
+
resolve_opts,
|
|
2390
2401
|
route,
|
|
2391
|
-
params: event.params
|
|
2392
|
-
ssr
|
|
2402
|
+
params: event.params // TODO this is redundant
|
|
2393
2403
|
});
|
|
2394
2404
|
|
|
2395
2405
|
if (response) {
|
|
@@ -2461,6 +2471,9 @@ function negotiate(accept, types) {
|
|
|
2461
2471
|
|
|
2462
2472
|
const DATA_SUFFIX = '/__data.json';
|
|
2463
2473
|
|
|
2474
|
+
/** @param {{ html: string }} opts */
|
|
2475
|
+
const default_transform = ({ html }) => html;
|
|
2476
|
+
|
|
2464
2477
|
/** @type {import('types/internal').Respond} */
|
|
2465
2478
|
async function respond(request, options, state = {}) {
|
|
2466
2479
|
const url = new URL(request.url);
|
|
@@ -2544,13 +2557,22 @@ async function respond(request, options, state = {}) {
|
|
|
2544
2557
|
rawBody: body_getter
|
|
2545
2558
|
});
|
|
2546
2559
|
|
|
2547
|
-
|
|
2560
|
+
/** @type {import('types/hooks').RequiredResolveOptions} */
|
|
2561
|
+
let resolve_opts = {
|
|
2562
|
+
ssr: true,
|
|
2563
|
+
transformPage: default_transform
|
|
2564
|
+
};
|
|
2548
2565
|
|
|
2549
2566
|
try {
|
|
2550
2567
|
const response = await options.hooks.handle({
|
|
2551
2568
|
event,
|
|
2552
2569
|
resolve: async (event, opts) => {
|
|
2553
|
-
if (opts
|
|
2570
|
+
if (opts) {
|
|
2571
|
+
resolve_opts = {
|
|
2572
|
+
ssr: opts.ssr !== false,
|
|
2573
|
+
transformPage: opts.transformPage || default_transform
|
|
2574
|
+
};
|
|
2575
|
+
}
|
|
2554
2576
|
|
|
2555
2577
|
if (state.prerender && state.prerender.fallback) {
|
|
2556
2578
|
return await render_response({
|
|
@@ -2563,7 +2585,10 @@ async function respond(request, options, state = {}) {
|
|
|
2563
2585
|
stuff: {},
|
|
2564
2586
|
status: 200,
|
|
2565
2587
|
branch: [],
|
|
2566
|
-
|
|
2588
|
+
resolve_opts: {
|
|
2589
|
+
...resolve_opts,
|
|
2590
|
+
ssr: false
|
|
2591
|
+
}
|
|
2567
2592
|
});
|
|
2568
2593
|
}
|
|
2569
2594
|
|
|
@@ -2622,7 +2647,7 @@ async function respond(request, options, state = {}) {
|
|
|
2622
2647
|
response =
|
|
2623
2648
|
route.type === 'endpoint'
|
|
2624
2649
|
? await render_endpoint(event, await route.load())
|
|
2625
|
-
: await render_page(event, route, options, state,
|
|
2650
|
+
: await render_page(event, route, options, state, resolve_opts);
|
|
2626
2651
|
}
|
|
2627
2652
|
|
|
2628
2653
|
if (response) {
|
|
@@ -2674,7 +2699,7 @@ async function respond(request, options, state = {}) {
|
|
|
2674
2699
|
$session,
|
|
2675
2700
|
status: 404,
|
|
2676
2701
|
error: new Error(`Not found: ${event.url.pathname}`),
|
|
2677
|
-
|
|
2702
|
+
resolve_opts
|
|
2678
2703
|
});
|
|
2679
2704
|
}
|
|
2680
2705
|
|
|
@@ -2710,7 +2735,7 @@ async function respond(request, options, state = {}) {
|
|
|
2710
2735
|
$session,
|
|
2711
2736
|
status: 500,
|
|
2712
2737
|
error,
|
|
2713
|
-
|
|
2738
|
+
resolve_opts
|
|
2714
2739
|
});
|
|
2715
2740
|
} catch (/** @type {unknown} */ e) {
|
|
2716
2741
|
const error = coalesce_to_error(e);
|
package/dist/cli.js
CHANGED
|
@@ -998,7 +998,7 @@ async function launch(port, https) {
|
|
|
998
998
|
exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}`);
|
|
999
999
|
}
|
|
1000
1000
|
|
|
1001
|
-
const prog = sade('svelte-kit').version('1.0.0-next.
|
|
1001
|
+
const prog = sade('svelte-kit').version('1.0.0-next.271');
|
|
1002
1002
|
|
|
1003
1003
|
prog
|
|
1004
1004
|
.command('dev')
|
|
@@ -1156,7 +1156,7 @@ async function check_port(port) {
|
|
|
1156
1156
|
function welcome({ port, host, https, open, loose, allow, cwd }) {
|
|
1157
1157
|
if (open) launch(port, https);
|
|
1158
1158
|
|
|
1159
|
-
console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.
|
|
1159
|
+
console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.271'}\n`));
|
|
1160
1160
|
|
|
1161
1161
|
const protocol = https ? 'https:' : 'http:';
|
|
1162
1162
|
const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
|
package/package.json
CHANGED
package/types/hooks.d.ts
CHANGED
|
@@ -14,14 +14,17 @@ export interface GetSession {
|
|
|
14
14
|
(event: RequestEvent): MaybePromise<App.Session>;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export interface
|
|
18
|
-
ssr
|
|
17
|
+
export interface RequiredResolveOptions {
|
|
18
|
+
ssr: boolean;
|
|
19
|
+
transformPage: ({ html }: { html: string }) => string;
|
|
19
20
|
}
|
|
20
21
|
|
|
22
|
+
export type ResolveOptions = Partial<RequiredResolveOptions>;
|
|
23
|
+
|
|
21
24
|
export interface Handle {
|
|
22
25
|
(input: {
|
|
23
26
|
event: RequestEvent;
|
|
24
|
-
resolve(event: RequestEvent, opts?:
|
|
27
|
+
resolve(event: RequestEvent, opts?: ResolveOptions): MaybePromise<Response>;
|
|
25
28
|
}): MaybePromise<Response>;
|
|
26
29
|
}
|
|
27
30
|
|
package/types/index.d.ts
CHANGED
|
@@ -14,4 +14,11 @@ export {
|
|
|
14
14
|
} from './config';
|
|
15
15
|
export { EndpointOutput, RequestHandler } from './endpoint';
|
|
16
16
|
export { ErrorLoad, ErrorLoadInput, Load, LoadInput, LoadOutput } from './page';
|
|
17
|
-
export {
|
|
17
|
+
export {
|
|
18
|
+
ExternalFetch,
|
|
19
|
+
GetSession,
|
|
20
|
+
Handle,
|
|
21
|
+
HandleError,
|
|
22
|
+
RequestEvent,
|
|
23
|
+
ResolveOptions
|
|
24
|
+
} from './hooks';
|