@sveltejs/kit 1.0.0-next.384 → 1.0.0-next.387
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/client/start.js +30 -1
- package/assets/server/index.js +25 -30
- package/dist/chunks/error.js +18 -0
- package/dist/chunks/index2.js +2 -5
- package/dist/cli.js +1 -1
- package/dist/node/polyfills.js +1 -0
- package/dist/node.js +23 -29
- package/dist/vite.js +136 -93
- package/package.json +1 -1
- package/types/index.d.ts +1 -0
package/assets/client/start.js
CHANGED
|
@@ -117,6 +117,28 @@ function normalize_path(path, trailing_slash) {
|
|
|
117
117
|
return path;
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
+
/** @param {Record<string, string>} params */
|
|
121
|
+
function decode_params(params) {
|
|
122
|
+
for (const key in params) {
|
|
123
|
+
// input has already been decoded by decodeURI
|
|
124
|
+
// now handle the rest that decodeURIComponent would do
|
|
125
|
+
params[key] = params[key]
|
|
126
|
+
.replace(/%23/g, '#')
|
|
127
|
+
.replace(/%3[Bb]/g, ';')
|
|
128
|
+
.replace(/%2[Cc]/g, ',')
|
|
129
|
+
.replace(/%2[Ff]/g, '/')
|
|
130
|
+
.replace(/%3[Ff]/g, '?')
|
|
131
|
+
.replace(/%3[Aa]/g, ':')
|
|
132
|
+
.replace(/%40/g, '@')
|
|
133
|
+
.replace(/%26/g, '&')
|
|
134
|
+
.replace(/%3[Dd]/g, '=')
|
|
135
|
+
.replace(/%2[Bb]/g, '+')
|
|
136
|
+
.replace(/%24/g, '$');
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return params;
|
|
140
|
+
}
|
|
141
|
+
|
|
120
142
|
class LoadURL extends URL {
|
|
121
143
|
/** @returns {string} */
|
|
122
144
|
get hash() {
|
|
@@ -1323,7 +1345,7 @@ function create_client({ target, session, base, trailing_slash }) {
|
|
|
1323
1345
|
if (params) {
|
|
1324
1346
|
const id = normalize_path(url.pathname, trailing_slash) + url.search;
|
|
1325
1347
|
/** @type {import('./types').NavigationIntent} */
|
|
1326
|
-
const intent = { id, route, params, url };
|
|
1348
|
+
const intent = { id, route, params: decode_params(params), url };
|
|
1327
1349
|
return intent;
|
|
1328
1350
|
}
|
|
1329
1351
|
}
|
|
@@ -1650,6 +1672,13 @@ function create_client({ target, session, base, trailing_slash }) {
|
|
|
1650
1672
|
}
|
|
1651
1673
|
});
|
|
1652
1674
|
|
|
1675
|
+
// fix link[rel=icon], because browsers will occasionally try to load relative
|
|
1676
|
+
// URLs after a pushState/replaceState, resulting in a 404 — see
|
|
1677
|
+
// https://github.com/sveltejs/kit/issues/3748#issuecomment-1125980897
|
|
1678
|
+
for (const link of document.querySelectorAll('link')) {
|
|
1679
|
+
if (link.rel === 'icon') link.href = link.href;
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1653
1682
|
addEventListener('pageshow', (event) => {
|
|
1654
1683
|
// If the user navigates to another site and then uses the back button and
|
|
1655
1684
|
// bfcache hits, we need to set navigating to null, the site doesn't know
|
package/assets/server/index.js
CHANGED
|
@@ -105,28 +105,6 @@ function lowercase_keys(obj) {
|
|
|
105
105
|
return clone;
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
/** @param {Record<string, string>} params */
|
|
109
|
-
function decode_params(params) {
|
|
110
|
-
for (const key in params) {
|
|
111
|
-
// input has already been decoded by decodeURI
|
|
112
|
-
// now handle the rest that decodeURIComponent would do
|
|
113
|
-
params[key] = params[key]
|
|
114
|
-
.replace(/%23/g, '#')
|
|
115
|
-
.replace(/%3[Bb]/g, ';')
|
|
116
|
-
.replace(/%2[Cc]/g, ',')
|
|
117
|
-
.replace(/%2[Ff]/g, '/')
|
|
118
|
-
.replace(/%3[Ff]/g, '?')
|
|
119
|
-
.replace(/%3[Aa]/g, ':')
|
|
120
|
-
.replace(/%40/g, '@')
|
|
121
|
-
.replace(/%26/g, '&')
|
|
122
|
-
.replace(/%3[Dd]/g, '=')
|
|
123
|
-
.replace(/%2[Bb]/g, '+')
|
|
124
|
-
.replace(/%24/g, '$');
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return params;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
108
|
/** @param {any} body */
|
|
131
109
|
function is_pojo(body) {
|
|
132
110
|
if (typeof body !== 'object') return false;
|
|
@@ -1290,6 +1268,28 @@ function normalize_path(path, trailing_slash) {
|
|
|
1290
1268
|
return path;
|
|
1291
1269
|
}
|
|
1292
1270
|
|
|
1271
|
+
/** @param {Record<string, string>} params */
|
|
1272
|
+
function decode_params(params) {
|
|
1273
|
+
for (const key in params) {
|
|
1274
|
+
// input has already been decoded by decodeURI
|
|
1275
|
+
// now handle the rest that decodeURIComponent would do
|
|
1276
|
+
params[key] = params[key]
|
|
1277
|
+
.replace(/%23/g, '#')
|
|
1278
|
+
.replace(/%3[Bb]/g, ';')
|
|
1279
|
+
.replace(/%2[Cc]/g, ',')
|
|
1280
|
+
.replace(/%2[Ff]/g, '/')
|
|
1281
|
+
.replace(/%3[Ff]/g, '?')
|
|
1282
|
+
.replace(/%3[Aa]/g, ':')
|
|
1283
|
+
.replace(/%40/g, '@')
|
|
1284
|
+
.replace(/%26/g, '&')
|
|
1285
|
+
.replace(/%3[Dd]/g, '=')
|
|
1286
|
+
.replace(/%2[Bb]/g, '+')
|
|
1287
|
+
.replace(/%24/g, '$');
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
return params;
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
1293
|
class LoadURL extends URL {
|
|
1294
1294
|
/** @returns {string} */
|
|
1295
1295
|
get hash() {
|
|
@@ -1410,20 +1410,15 @@ async function render_response({
|
|
|
1410
1410
|
}
|
|
1411
1411
|
|
|
1412
1412
|
const session = writable($session);
|
|
1413
|
+
// Even if $session isn't accessed, it still ends up serialized in the rendered HTML
|
|
1414
|
+
is_private = is_private || (cache?.private ?? (!!$session && Object.keys($session).length > 0));
|
|
1413
1415
|
|
|
1414
1416
|
/** @type {Record<string, any>} */
|
|
1415
1417
|
const props = {
|
|
1416
1418
|
stores: {
|
|
1417
1419
|
page: writable(null),
|
|
1418
1420
|
navigating: writable(null),
|
|
1419
|
-
|
|
1420
|
-
session: {
|
|
1421
|
-
...session,
|
|
1422
|
-
subscribe: (fn) => {
|
|
1423
|
-
is_private = cache?.private ?? true;
|
|
1424
|
-
return session.subscribe(fn);
|
|
1425
|
-
}
|
|
1426
|
-
},
|
|
1421
|
+
session,
|
|
1427
1422
|
updated
|
|
1428
1423
|
},
|
|
1429
1424
|
/** @type {import('types').Page} */
|
package/dist/chunks/error.js
CHANGED
|
@@ -365,6 +365,24 @@ const options = object(
|
|
|
365
365
|
);
|
|
366
366
|
}),
|
|
367
367
|
|
|
368
|
+
origin: validate('http://sveltekit-prerender', (input, keypath) => {
|
|
369
|
+
assert_string(input, keypath);
|
|
370
|
+
|
|
371
|
+
let origin;
|
|
372
|
+
|
|
373
|
+
try {
|
|
374
|
+
origin = new URL(input).origin;
|
|
375
|
+
} catch (e) {
|
|
376
|
+
throw new Error(`${keypath} must be a valid origin`);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
if (input !== origin) {
|
|
380
|
+
throw new Error(`${keypath} must be a valid origin (${origin} rather than ${input})`);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
return origin;
|
|
384
|
+
}),
|
|
385
|
+
|
|
368
386
|
// TODO: remove this for the 1.0 release
|
|
369
387
|
pages: error((keypath) => `${keypath} has been renamed to \`entries\`.`)
|
|
370
388
|
}),
|
package/dist/chunks/index2.js
CHANGED
|
@@ -54,7 +54,7 @@ function create_builder({ config, build_data, prerendered, log }) {
|
|
|
54
54
|
// TODO routes should come pre-filtered
|
|
55
55
|
function not_prerendered(route) {
|
|
56
56
|
if (route.type === 'page' && route.path) {
|
|
57
|
-
return !prerendered_paths.has(route.path);
|
|
57
|
+
return !prerendered_paths.has(route.path) && !prerendered_paths.has(route.path + '/');
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
return true;
|
|
@@ -157,10 +157,7 @@ function create_builder({ config, build_data, prerendered, log }) {
|
|
|
157
157
|
},
|
|
158
158
|
|
|
159
159
|
writeClient(dest) {
|
|
160
|
-
return [
|
|
161
|
-
...copy(`${config.kit.outDir}/output/client`, dest),
|
|
162
|
-
...copy(config.kit.files.assets, dest)
|
|
163
|
-
];
|
|
160
|
+
return [...copy(`${config.kit.outDir}/output/client`, dest)];
|
|
164
161
|
},
|
|
165
162
|
|
|
166
163
|
writePrerendered(dest, { fallback } = {}) {
|
package/dist/cli.js
CHANGED
package/dist/node/polyfills.js
CHANGED
|
@@ -17769,6 +17769,7 @@ function installPolyfills() {
|
|
|
17769
17769
|
Object.defineProperty(globalThis, name, {
|
|
17770
17770
|
enumerable: true,
|
|
17771
17771
|
configurable: true,
|
|
17772
|
+
writable: true,
|
|
17772
17773
|
value: globals[name]
|
|
17773
17774
|
});
|
|
17774
17775
|
}
|
package/dist/node.js
CHANGED
|
@@ -312,42 +312,36 @@ async function setResponse(res, response) {
|
|
|
312
312
|
return;
|
|
313
313
|
}
|
|
314
314
|
|
|
315
|
-
|
|
315
|
+
const cancel = (/** @type {Error|undefined} */ error) => {
|
|
316
|
+
res.off('close', cancel);
|
|
317
|
+
res.off('error', cancel);
|
|
316
318
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
});
|
|
319
|
+
// If the reader has already been interrupted with an error earlier,
|
|
320
|
+
// then it will appear here, it is useless, but it needs to be catch.
|
|
321
|
+
reader.cancel(error).catch(() => {});
|
|
322
|
+
if (error) res.destroy(error);
|
|
323
|
+
};
|
|
323
324
|
|
|
324
|
-
res.on('
|
|
325
|
-
|
|
326
|
-
cancelled = true;
|
|
327
|
-
reader.cancel(error);
|
|
328
|
-
res.emit('drain');
|
|
329
|
-
});
|
|
325
|
+
res.on('close', cancel);
|
|
326
|
+
res.on('error', cancel);
|
|
330
327
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
328
|
+
next();
|
|
329
|
+
async function next() {
|
|
330
|
+
try {
|
|
331
|
+
for (;;) {
|
|
332
|
+
const { done, value } = await reader.read();
|
|
334
333
|
|
|
335
|
-
|
|
334
|
+
if (done) break;
|
|
336
335
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
const ok = res.write(value);
|
|
343
|
-
|
|
344
|
-
if (!ok) {
|
|
345
|
-
await new Promise((fulfil) => res.once('drain', fulfil));
|
|
336
|
+
if (!res.write(value)) {
|
|
337
|
+
res.once('drain', next);
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
346
340
|
}
|
|
341
|
+
res.end();
|
|
342
|
+
} catch (error) {
|
|
343
|
+
cancel(error instanceof Error ? error : new Error(String(error)));
|
|
347
344
|
}
|
|
348
|
-
} catch (error) {
|
|
349
|
-
cancelled = true;
|
|
350
|
-
res.destroy(error instanceof Error ? error : undefined);
|
|
351
345
|
}
|
|
352
346
|
}
|
|
353
347
|
|
package/dist/vite.js
CHANGED
|
@@ -7,7 +7,7 @@ import * as vite from 'vite';
|
|
|
7
7
|
import { loadConfigFromFile } from 'vite';
|
|
8
8
|
import { p as posixify, m as mkdirp, r as rimraf } from './chunks/write_tsconfig.js';
|
|
9
9
|
import { g as get_runtime_directory, s, i as init, a as get_runtime_prefix, u as update, b as get_mime_lookup, p as parse_route_id, c as all, l as logger } from './chunks/sync.js';
|
|
10
|
-
import {
|
|
10
|
+
import { URL as URL$1, pathToFileURL } from 'url';
|
|
11
11
|
import { installPolyfills } from './node/polyfills.js';
|
|
12
12
|
import * as qs from 'querystring';
|
|
13
13
|
import { getRequest, setResponse } from './node.js';
|
|
@@ -284,9 +284,7 @@ const get_default_config = function ({ config, input, ssr, outDir }) {
|
|
|
284
284
|
__SVELTEKIT_APP_VERSION_POLL_INTERVAL__: JSON.stringify(config.kit.version.pollInterval),
|
|
285
285
|
__SVELTEKIT_DEV__: 'false'
|
|
286
286
|
},
|
|
287
|
-
|
|
288
|
-
// if it happens to be 'public' instead of 'static'
|
|
289
|
-
publicDir: false,
|
|
287
|
+
publicDir: ssr ? false : config.kit.files.assets,
|
|
290
288
|
resolve: {
|
|
291
289
|
alias: get_aliases(config.kit)
|
|
292
290
|
},
|
|
@@ -610,61 +608,6 @@ function get_methods(cwd, output, manifest_data) {
|
|
|
610
608
|
return methods;
|
|
611
609
|
}
|
|
612
610
|
|
|
613
|
-
const absolute = /^([a-z]+:)?\/?\//;
|
|
614
|
-
const scheme = /^[a-z]+:/;
|
|
615
|
-
|
|
616
|
-
/**
|
|
617
|
-
* @param {string} base
|
|
618
|
-
* @param {string} path
|
|
619
|
-
*/
|
|
620
|
-
function resolve(base, path) {
|
|
621
|
-
if (scheme.test(path)) return path;
|
|
622
|
-
|
|
623
|
-
const base_match = absolute.exec(base);
|
|
624
|
-
const path_match = absolute.exec(path);
|
|
625
|
-
|
|
626
|
-
if (!base_match) {
|
|
627
|
-
throw new Error(`bad base path: "${base}"`);
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
const baseparts = path_match ? [] : base.slice(base_match[0].length).split('/');
|
|
631
|
-
const pathparts = path_match ? path.slice(path_match[0].length).split('/') : path.split('/');
|
|
632
|
-
|
|
633
|
-
baseparts.pop();
|
|
634
|
-
|
|
635
|
-
for (let i = 0; i < pathparts.length; i += 1) {
|
|
636
|
-
const part = pathparts[i];
|
|
637
|
-
if (part === '.') continue;
|
|
638
|
-
else if (part === '..') baseparts.pop();
|
|
639
|
-
else baseparts.push(part);
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
const prefix = (path_match && path_match[0]) || (base_match && base_match[0]) || '';
|
|
643
|
-
|
|
644
|
-
return `${prefix}${baseparts.join('/')}`;
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
/** @param {string} path */
|
|
648
|
-
function is_root_relative(path) {
|
|
649
|
-
return path[0] === '/' && path[1] !== '/';
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
/**
|
|
653
|
-
* @param {string} path
|
|
654
|
-
* @param {import('types').TrailingSlash} trailing_slash
|
|
655
|
-
*/
|
|
656
|
-
function normalize_path(path, trailing_slash) {
|
|
657
|
-
if (path === '/' || trailing_slash === 'ignore') return path;
|
|
658
|
-
|
|
659
|
-
if (trailing_slash === 'never') {
|
|
660
|
-
return path.endsWith('/') ? path.slice(0, -1) : path;
|
|
661
|
-
} else if (trailing_slash === 'always' && !path.endsWith('/')) {
|
|
662
|
-
return path + '/';
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
return path;
|
|
666
|
-
}
|
|
667
|
-
|
|
668
611
|
/**
|
|
669
612
|
* @param {{
|
|
670
613
|
* config: import('types').ValidatedConfig;
|
|
@@ -715,9 +658,7 @@ async function build_service_worker(
|
|
|
715
658
|
];
|
|
716
659
|
|
|
717
660
|
export const prerendered = [
|
|
718
|
-
${prerendered.paths
|
|
719
|
-
.map((path) => s(normalize_path(path, config.kit.trailingSlash)))
|
|
720
|
-
.join(',\n\t\t\t\t')}
|
|
661
|
+
${prerendered.paths.map((path) => s(path)).join(',\n\t\t\t\t')}
|
|
721
662
|
];
|
|
722
663
|
|
|
723
664
|
export const version = ${s(config.kit.version.name)};
|
|
@@ -758,6 +699,45 @@ async function build_service_worker(
|
|
|
758
699
|
await vite.build(merged_config);
|
|
759
700
|
}
|
|
760
701
|
|
|
702
|
+
const absolute = /^([a-z]+:)?\/?\//;
|
|
703
|
+
const scheme = /^[a-z]+:/;
|
|
704
|
+
|
|
705
|
+
/**
|
|
706
|
+
* @param {string} base
|
|
707
|
+
* @param {string} path
|
|
708
|
+
*/
|
|
709
|
+
function resolve(base, path) {
|
|
710
|
+
if (scheme.test(path)) return path;
|
|
711
|
+
|
|
712
|
+
const base_match = absolute.exec(base);
|
|
713
|
+
const path_match = absolute.exec(path);
|
|
714
|
+
|
|
715
|
+
if (!base_match) {
|
|
716
|
+
throw new Error(`bad base path: "${base}"`);
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
const baseparts = path_match ? [] : base.slice(base_match[0].length).split('/');
|
|
720
|
+
const pathparts = path_match ? path.slice(path_match[0].length).split('/') : path.split('/');
|
|
721
|
+
|
|
722
|
+
baseparts.pop();
|
|
723
|
+
|
|
724
|
+
for (let i = 0; i < pathparts.length; i += 1) {
|
|
725
|
+
const part = pathparts[i];
|
|
726
|
+
if (part === '.') continue;
|
|
727
|
+
else if (part === '..') baseparts.pop();
|
|
728
|
+
else baseparts.push(part);
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
const prefix = (path_match && path_match[0]) || (base_match && base_match[0]) || '';
|
|
732
|
+
|
|
733
|
+
return `${prefix}${baseparts.join('/')}`;
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
/** @param {string} path */
|
|
737
|
+
function is_root_relative(path) {
|
|
738
|
+
return path[0] === '/' && path[1] !== '/';
|
|
739
|
+
}
|
|
740
|
+
|
|
761
741
|
/**
|
|
762
742
|
* @typedef {{
|
|
763
743
|
* fn: () => Promise<any>,
|
|
@@ -1112,28 +1092,39 @@ function escape_html_attr(str) {
|
|
|
1112
1092
|
|
|
1113
1093
|
/**
|
|
1114
1094
|
* @typedef {import('types').PrerenderErrorHandler} PrerenderErrorHandler
|
|
1115
|
-
* @typedef {import('types').PrerenderOnErrorValue} OnError
|
|
1116
1095
|
* @typedef {import('types').Logger} Logger
|
|
1117
1096
|
*/
|
|
1118
1097
|
|
|
1119
|
-
/**
|
|
1120
|
-
|
|
1121
|
-
|
|
1098
|
+
/**
|
|
1099
|
+
* @param {Parameters<PrerenderErrorHandler>[0]} details
|
|
1100
|
+
* @param {import('types').ValidatedKitConfig} config
|
|
1101
|
+
*/
|
|
1102
|
+
function format_error({ status, path, referrer, referenceType }, config) {
|
|
1103
|
+
const message =
|
|
1104
|
+
status === 404 && !path.startsWith(config.paths.base)
|
|
1105
|
+
? `${path} does not begin with \`base\`, which is configured in \`paths.base\` and can be imported from \`$app/paths\``
|
|
1106
|
+
: path;
|
|
1107
|
+
|
|
1108
|
+
return `${status} ${message}${referrer ? ` (${referenceType} from ${referrer})` : ''}`;
|
|
1122
1109
|
}
|
|
1123
1110
|
|
|
1124
|
-
/**
|
|
1125
|
-
|
|
1126
|
-
|
|
1111
|
+
/**
|
|
1112
|
+
* @param {Logger} log
|
|
1113
|
+
* @param {import('types').ValidatedKitConfig} config
|
|
1114
|
+
* @returns {PrerenderErrorHandler}
|
|
1115
|
+
*/
|
|
1116
|
+
function normalise_error_handler(log, config) {
|
|
1117
|
+
switch (config.prerender.onError) {
|
|
1127
1118
|
case 'continue':
|
|
1128
1119
|
return (details) => {
|
|
1129
|
-
log.error(format_error(details));
|
|
1120
|
+
log.error(format_error(details, config));
|
|
1130
1121
|
};
|
|
1131
1122
|
case 'fail':
|
|
1132
1123
|
return (details) => {
|
|
1133
|
-
throw new Error(format_error(details));
|
|
1124
|
+
throw new Error(format_error(details, config));
|
|
1134
1125
|
};
|
|
1135
1126
|
default:
|
|
1136
|
-
return onError;
|
|
1127
|
+
return config.prerender.onError;
|
|
1137
1128
|
}
|
|
1138
1129
|
}
|
|
1139
1130
|
|
|
@@ -1162,12 +1153,66 @@ async function prerender({ config, entries, files, log }) {
|
|
|
1162
1153
|
}
|
|
1163
1154
|
|
|
1164
1155
|
installPolyfills();
|
|
1156
|
+
const { fetch } = globalThis;
|
|
1157
|
+
globalThis.fetch = async (info, init) => {
|
|
1158
|
+
/** @type {string} */
|
|
1159
|
+
let url;
|
|
1160
|
+
|
|
1161
|
+
/** @type {RequestInit} */
|
|
1162
|
+
let opts = {};
|
|
1163
|
+
|
|
1164
|
+
if (info instanceof Request) {
|
|
1165
|
+
url = info.url;
|
|
1166
|
+
|
|
1167
|
+
opts = {
|
|
1168
|
+
method: info.method,
|
|
1169
|
+
headers: info.headers,
|
|
1170
|
+
body: info.body,
|
|
1171
|
+
mode: info.mode,
|
|
1172
|
+
credentials: info.credentials,
|
|
1173
|
+
cache: info.cache,
|
|
1174
|
+
redirect: info.redirect,
|
|
1175
|
+
referrer: info.referrer,
|
|
1176
|
+
integrity: info.integrity
|
|
1177
|
+
};
|
|
1178
|
+
} else {
|
|
1179
|
+
url = info.toString();
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
if (url.startsWith(config.prerender.origin + '/')) {
|
|
1183
|
+
const request = new Request(url, opts);
|
|
1184
|
+
const response = await server.respond(request, {
|
|
1185
|
+
getClientAddress,
|
|
1186
|
+
prerendering: {
|
|
1187
|
+
dependencies: new Map()
|
|
1188
|
+
}
|
|
1189
|
+
});
|
|
1190
|
+
|
|
1191
|
+
const decoded = new URL$1(url).pathname;
|
|
1192
|
+
|
|
1193
|
+
save(
|
|
1194
|
+
'dependencies',
|
|
1195
|
+
response,
|
|
1196
|
+
Buffer.from(await response.clone().arrayBuffer()),
|
|
1197
|
+
decoded,
|
|
1198
|
+
encodeURI(decoded),
|
|
1199
|
+
null,
|
|
1200
|
+
'fetched'
|
|
1201
|
+
);
|
|
1202
|
+
|
|
1203
|
+
return response;
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
return fetch(info, init);
|
|
1207
|
+
};
|
|
1165
1208
|
|
|
1166
1209
|
const server_root = join(config.outDir, 'output');
|
|
1167
1210
|
|
|
1168
1211
|
/** @type {import('types').ServerModule} */
|
|
1169
1212
|
const { Server, override } = await import(pathToFileURL(`${server_root}/server/index.js`).href);
|
|
1170
|
-
|
|
1213
|
+
|
|
1214
|
+
/** @type {import('types').SSRManifest} */
|
|
1215
|
+
const manifest = (await import(pathToFileURL(`${server_root}/server/manifest.js`).href)).manifest;
|
|
1171
1216
|
|
|
1172
1217
|
override({
|
|
1173
1218
|
paths: config.paths,
|
|
@@ -1177,7 +1222,7 @@ async function prerender({ config, entries, files, log }) {
|
|
|
1177
1222
|
|
|
1178
1223
|
const server = new Server(manifest);
|
|
1179
1224
|
|
|
1180
|
-
const error = normalise_error_handler(log, config
|
|
1225
|
+
const error = normalise_error_handler(log, config);
|
|
1181
1226
|
|
|
1182
1227
|
const q = queue(config.prerender.concurrency);
|
|
1183
1228
|
|
|
@@ -1186,11 +1231,7 @@ async function prerender({ config, entries, files, log }) {
|
|
|
1186
1231
|
* @param {boolean} is_html
|
|
1187
1232
|
*/
|
|
1188
1233
|
function output_filename(path, is_html) {
|
|
1189
|
-
const file = path.slice(config.paths.base.length + 1);
|
|
1190
|
-
|
|
1191
|
-
if (file === '') {
|
|
1192
|
-
return 'index.html';
|
|
1193
|
-
}
|
|
1234
|
+
const file = path.slice(config.paths.base.length + 1) || 'index.html';
|
|
1194
1235
|
|
|
1195
1236
|
if (is_html && !file.endsWith('.html')) {
|
|
1196
1237
|
return file + (file.endsWith('/') ? 'index.html' : '.html');
|
|
@@ -1231,7 +1272,7 @@ async function prerender({ config, entries, files, log }) {
|
|
|
1231
1272
|
/** @type {Map<string, import('types').PrerenderDependency>} */
|
|
1232
1273
|
const dependencies = new Map();
|
|
1233
1274
|
|
|
1234
|
-
const response = await server.respond(new Request(
|
|
1275
|
+
const response = await server.respond(new Request(config.prerender.origin + encoded), {
|
|
1235
1276
|
getClientAddress,
|
|
1236
1277
|
prerendering: {
|
|
1237
1278
|
dependencies
|
|
@@ -1320,7 +1361,7 @@ async function prerender({ config, entries, files, log }) {
|
|
|
1320
1361
|
location: resolved
|
|
1321
1362
|
});
|
|
1322
1363
|
|
|
1323
|
-
prerendered.paths.push(
|
|
1364
|
+
prerendered.paths.push(decoded);
|
|
1324
1365
|
}
|
|
1325
1366
|
}
|
|
1326
1367
|
} else {
|
|
@@ -1347,7 +1388,7 @@ async function prerender({ config, entries, files, log }) {
|
|
|
1347
1388
|
});
|
|
1348
1389
|
}
|
|
1349
1390
|
|
|
1350
|
-
prerendered.paths.push(
|
|
1391
|
+
prerendered.paths.push(decoded);
|
|
1351
1392
|
} else if (response_type !== OK) {
|
|
1352
1393
|
error({ status: response.status, path: decoded, referrer, referenceType });
|
|
1353
1394
|
}
|
|
@@ -1367,7 +1408,7 @@ async function prerender({ config, entries, files, log }) {
|
|
|
1367
1408
|
await q.done();
|
|
1368
1409
|
}
|
|
1369
1410
|
|
|
1370
|
-
const rendered = await server.respond(new Request('
|
|
1411
|
+
const rendered = await server.respond(new Request(config.prerender.origin + '/[fallback]'), {
|
|
1371
1412
|
getClientAddress,
|
|
1372
1413
|
prerendering: {
|
|
1373
1414
|
fallback: true,
|
|
@@ -2215,7 +2256,7 @@ async function dev(vite, vite_config, svelte_config) {
|
|
|
2215
2256
|
/** @type {function} */ (middleware.handle).name === 'viteServeStaticMiddleware'
|
|
2216
2257
|
);
|
|
2217
2258
|
|
|
2218
|
-
|
|
2259
|
+
remove_static_middlewares(vite.middlewares);
|
|
2219
2260
|
|
|
2220
2261
|
vite.middlewares.use(async (req, res) => {
|
|
2221
2262
|
try {
|
|
@@ -2421,11 +2462,15 @@ function not_found(res, message = 'Not found') {
|
|
|
2421
2462
|
/**
|
|
2422
2463
|
* @param {import('connect').Server} server
|
|
2423
2464
|
*/
|
|
2424
|
-
function
|
|
2425
|
-
|
|
2465
|
+
function remove_static_middlewares(server) {
|
|
2466
|
+
// We don't use viteServePublicMiddleware because of the following issues:
|
|
2467
|
+
// https://github.com/vitejs/vite/issues/9260
|
|
2468
|
+
// https://github.com/vitejs/vite/issues/9236
|
|
2469
|
+
// https://github.com/vitejs/vite/issues/9234
|
|
2470
|
+
const static_middlewares = ['viteServePublicMiddleware', 'viteServeStaticMiddleware'];
|
|
2426
2471
|
for (let i = server.stack.length - 1; i > 0; i--) {
|
|
2427
|
-
// @ts-expect-error using internals
|
|
2428
|
-
if (
|
|
2472
|
+
// @ts-expect-error using internals
|
|
2473
|
+
if (static_middlewares.includes(server.stack[i].handle.name)) {
|
|
2429
2474
|
server.stack.splice(i, 1);
|
|
2430
2475
|
}
|
|
2431
2476
|
}
|
|
@@ -2649,16 +2694,13 @@ async function preview(vite, config, protocol) {
|
|
|
2649
2694
|
const server = new Server(manifest);
|
|
2650
2695
|
|
|
2651
2696
|
return () => {
|
|
2652
|
-
//
|
|
2653
|
-
vite.middlewares.use(scoped(assets, mutable(config.kit.files.assets)));
|
|
2654
|
-
|
|
2655
|
-
// immutable generated client assets
|
|
2697
|
+
// generated client assets and the contents of `static`
|
|
2656
2698
|
vite.middlewares.use(
|
|
2657
2699
|
scoped(
|
|
2658
2700
|
assets,
|
|
2659
2701
|
sirv(join(config.kit.outDir, 'output/client'), {
|
|
2660
2702
|
setHeaders: (res, pathname) => {
|
|
2661
|
-
// only apply to
|
|
2703
|
+
// only apply to immutable directory, not e.g. version.json
|
|
2662
2704
|
if (pathname.startsWith(`/${config.kit.appDir}/immutable`)) {
|
|
2663
2705
|
res.setHeader('cache-control', 'public,max-age=31536000,immutable');
|
|
2664
2706
|
}
|
|
@@ -2980,6 +3022,7 @@ function kit() {
|
|
|
2980
3022
|
__SVELTEKIT_DEV__: 'true',
|
|
2981
3023
|
__SVELTEKIT_APP_VERSION_POLL_INTERVAL__: '0'
|
|
2982
3024
|
},
|
|
3025
|
+
publicDir: svelte_config.kit.files.assets,
|
|
2983
3026
|
resolve: {
|
|
2984
3027
|
alias: get_aliases(svelte_config.kit)
|
|
2985
3028
|
},
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED