@sveltejs/kit 1.0.0-next.383 → 1.0.0-next.386
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/app/env.js +2 -17
- package/assets/client/start.js +30 -1
- package/assets/server/index.js +25 -30
- package/dist/chunks/error.js +18 -0
- package/dist/cli.js +1 -1
- package/dist/node/polyfills.js +1 -0
- package/dist/vite.js +84 -19
- package/package.json +1 -1
- package/types/ambient.d.ts +2 -19
- package/types/index.d.ts +1 -0
- package/types/internal.d.ts +1 -0
package/assets/app/env.js
CHANGED
|
@@ -5,24 +5,9 @@ export { prerendering } from '../env.js';
|
|
|
5
5
|
*/
|
|
6
6
|
const browser = !import.meta.env.SSR;
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* @type {import('$app/env').server}
|
|
10
|
-
*/
|
|
11
|
-
const server = !!import.meta.env.SSR;
|
|
12
|
-
|
|
13
8
|
/**
|
|
14
9
|
* @type {import('$app/env').dev}
|
|
15
10
|
*/
|
|
16
|
-
const dev =
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @type {import('$app/env').prod}
|
|
20
|
-
*/
|
|
21
|
-
const prod = !import.meta.env.DEV;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* @type {import('$app/env').mode}
|
|
25
|
-
*/
|
|
26
|
-
const mode = import.meta.env.MODE;
|
|
11
|
+
const dev = __SVELTEKIT_DEV__;
|
|
27
12
|
|
|
28
|
-
export { browser, dev
|
|
13
|
+
export { browser, dev };
|
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/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/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';
|
|
@@ -46,7 +46,7 @@ async function get_vite_config(config_env) {
|
|
|
46
46
|
if (!config) {
|
|
47
47
|
throw new Error('Could not load Vite config');
|
|
48
48
|
}
|
|
49
|
-
return config;
|
|
49
|
+
return { ...config, mode: config_env.mode };
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
/**
|
|
@@ -281,7 +281,8 @@ const get_default_config = function ({ config, input, ssr, outDir }) {
|
|
|
281
281
|
__SVELTEKIT_ADAPTER_NAME__: JSON.stringify(config.kit.adapter?.name),
|
|
282
282
|
__SVELTEKIT_APP_VERSION__: JSON.stringify(config.kit.version.name),
|
|
283
283
|
__SVELTEKIT_APP_VERSION_FILE__: JSON.stringify(`${config.kit.appDir}/version.json`),
|
|
284
|
-
__SVELTEKIT_APP_VERSION_POLL_INTERVAL__: JSON.stringify(config.kit.version.pollInterval)
|
|
284
|
+
__SVELTEKIT_APP_VERSION_POLL_INTERVAL__: JSON.stringify(config.kit.version.pollInterval),
|
|
285
|
+
__SVELTEKIT_DEV__: 'false'
|
|
285
286
|
},
|
|
286
287
|
// prevent Vite copying the contents of `config.kit.files.assets`,
|
|
287
288
|
// if it happens to be 'public' instead of 'static'
|
|
@@ -434,9 +435,9 @@ export class Server {
|
|
|
434
435
|
/**
|
|
435
436
|
* @param {{
|
|
436
437
|
* cwd: string;
|
|
437
|
-
* config: import('types').ValidatedConfig
|
|
438
|
-
* vite_config_env: import('vite').ConfigEnv
|
|
439
|
-
* manifest_data: import('types').ManifestData
|
|
438
|
+
* config: import('types').ValidatedConfig;
|
|
439
|
+
* vite_config_env: import('vite').ConfigEnv;
|
|
440
|
+
* manifest_data: import('types').ManifestData;
|
|
440
441
|
* build_dir: string;
|
|
441
442
|
* output_dir: string;
|
|
442
443
|
* service_worker_entry_file: string | null;
|
|
@@ -1111,28 +1112,39 @@ function escape_html_attr(str) {
|
|
|
1111
1112
|
|
|
1112
1113
|
/**
|
|
1113
1114
|
* @typedef {import('types').PrerenderErrorHandler} PrerenderErrorHandler
|
|
1114
|
-
* @typedef {import('types').PrerenderOnErrorValue} OnError
|
|
1115
1115
|
* @typedef {import('types').Logger} Logger
|
|
1116
1116
|
*/
|
|
1117
1117
|
|
|
1118
|
-
/**
|
|
1119
|
-
|
|
1120
|
-
|
|
1118
|
+
/**
|
|
1119
|
+
* @param {Parameters<PrerenderErrorHandler>[0]} details
|
|
1120
|
+
* @param {import('types').ValidatedKitConfig} config
|
|
1121
|
+
*/
|
|
1122
|
+
function format_error({ status, path, referrer, referenceType }, config) {
|
|
1123
|
+
const message =
|
|
1124
|
+
status === 404 && !path.startsWith(config.paths.base)
|
|
1125
|
+
? `${path} does not begin with \`base\`, which is configured in \`paths.base\` and can be imported from \`$app/paths\``
|
|
1126
|
+
: path;
|
|
1127
|
+
|
|
1128
|
+
return `${status} ${message}${referrer ? ` (${referenceType} from ${referrer})` : ''}`;
|
|
1121
1129
|
}
|
|
1122
1130
|
|
|
1123
|
-
/**
|
|
1124
|
-
|
|
1125
|
-
|
|
1131
|
+
/**
|
|
1132
|
+
* @param {Logger} log
|
|
1133
|
+
* @param {import('types').ValidatedKitConfig} config
|
|
1134
|
+
* @returns {PrerenderErrorHandler}
|
|
1135
|
+
*/
|
|
1136
|
+
function normalise_error_handler(log, config) {
|
|
1137
|
+
switch (config.prerender.onError) {
|
|
1126
1138
|
case 'continue':
|
|
1127
1139
|
return (details) => {
|
|
1128
|
-
log.error(format_error(details));
|
|
1140
|
+
log.error(format_error(details, config));
|
|
1129
1141
|
};
|
|
1130
1142
|
case 'fail':
|
|
1131
1143
|
return (details) => {
|
|
1132
|
-
throw new Error(format_error(details));
|
|
1144
|
+
throw new Error(format_error(details, config));
|
|
1133
1145
|
};
|
|
1134
1146
|
default:
|
|
1135
|
-
return onError;
|
|
1147
|
+
return config.prerender.onError;
|
|
1136
1148
|
}
|
|
1137
1149
|
}
|
|
1138
1150
|
|
|
@@ -1161,6 +1173,58 @@ async function prerender({ config, entries, files, log }) {
|
|
|
1161
1173
|
}
|
|
1162
1174
|
|
|
1163
1175
|
installPolyfills();
|
|
1176
|
+
const { fetch } = globalThis;
|
|
1177
|
+
globalThis.fetch = async (info, init) => {
|
|
1178
|
+
/** @type {string} */
|
|
1179
|
+
let url;
|
|
1180
|
+
|
|
1181
|
+
/** @type {RequestInit} */
|
|
1182
|
+
let opts = {};
|
|
1183
|
+
|
|
1184
|
+
if (info instanceof Request) {
|
|
1185
|
+
url = info.url;
|
|
1186
|
+
|
|
1187
|
+
opts = {
|
|
1188
|
+
method: info.method,
|
|
1189
|
+
headers: info.headers,
|
|
1190
|
+
body: info.body,
|
|
1191
|
+
mode: info.mode,
|
|
1192
|
+
credentials: info.credentials,
|
|
1193
|
+
cache: info.cache,
|
|
1194
|
+
redirect: info.redirect,
|
|
1195
|
+
referrer: info.referrer,
|
|
1196
|
+
integrity: info.integrity
|
|
1197
|
+
};
|
|
1198
|
+
} else {
|
|
1199
|
+
url = info.toString();
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
if (url.startsWith(config.prerender.origin + '/')) {
|
|
1203
|
+
const request = new Request(url, opts);
|
|
1204
|
+
const response = await server.respond(request, {
|
|
1205
|
+
getClientAddress,
|
|
1206
|
+
prerendering: {
|
|
1207
|
+
dependencies: new Map()
|
|
1208
|
+
}
|
|
1209
|
+
});
|
|
1210
|
+
|
|
1211
|
+
const decoded = new URL$1(url).pathname;
|
|
1212
|
+
|
|
1213
|
+
save(
|
|
1214
|
+
'dependencies',
|
|
1215
|
+
response,
|
|
1216
|
+
Buffer.from(await response.clone().arrayBuffer()),
|
|
1217
|
+
decoded,
|
|
1218
|
+
encodeURI(decoded),
|
|
1219
|
+
null,
|
|
1220
|
+
'fetched'
|
|
1221
|
+
);
|
|
1222
|
+
|
|
1223
|
+
return response;
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
return fetch(info, init);
|
|
1227
|
+
};
|
|
1164
1228
|
|
|
1165
1229
|
const server_root = join(config.outDir, 'output');
|
|
1166
1230
|
|
|
@@ -1176,7 +1240,7 @@ async function prerender({ config, entries, files, log }) {
|
|
|
1176
1240
|
|
|
1177
1241
|
const server = new Server(manifest);
|
|
1178
1242
|
|
|
1179
|
-
const error = normalise_error_handler(log, config
|
|
1243
|
+
const error = normalise_error_handler(log, config);
|
|
1180
1244
|
|
|
1181
1245
|
const q = queue(config.prerender.concurrency);
|
|
1182
1246
|
|
|
@@ -1230,7 +1294,7 @@ async function prerender({ config, entries, files, log }) {
|
|
|
1230
1294
|
/** @type {Map<string, import('types').PrerenderDependency>} */
|
|
1231
1295
|
const dependencies = new Map();
|
|
1232
1296
|
|
|
1233
|
-
const response = await server.respond(new Request(
|
|
1297
|
+
const response = await server.respond(new Request(config.prerender.origin + encoded), {
|
|
1234
1298
|
getClientAddress,
|
|
1235
1299
|
prerendering: {
|
|
1236
1300
|
dependencies
|
|
@@ -1366,7 +1430,7 @@ async function prerender({ config, entries, files, log }) {
|
|
|
1366
1430
|
await q.done();
|
|
1367
1431
|
}
|
|
1368
1432
|
|
|
1369
|
-
const rendered = await server.respond(new Request('
|
|
1433
|
+
const rendered = await server.respond(new Request(config.prerender.origin + '/[fallback]'), {
|
|
1370
1434
|
getClientAddress,
|
|
1371
1435
|
prerendering: {
|
|
1372
1436
|
fallback: true,
|
|
@@ -2976,6 +3040,7 @@ function kit() {
|
|
|
2976
3040
|
}
|
|
2977
3041
|
},
|
|
2978
3042
|
define: {
|
|
3043
|
+
__SVELTEKIT_DEV__: 'true',
|
|
2979
3044
|
__SVELTEKIT_APP_VERSION_POLL_INTERVAL__: '0'
|
|
2980
3045
|
},
|
|
2981
3046
|
resolve: {
|
package/package.json
CHANGED
package/types/ambient.d.ts
CHANGED
|
@@ -65,7 +65,7 @@ declare namespace App {
|
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* ```ts
|
|
68
|
-
* import { browser, dev,
|
|
68
|
+
* import { browser, dev, prerendering } from '$app/env';
|
|
69
69
|
* ```
|
|
70
70
|
*/
|
|
71
71
|
declare module '$app/env' {
|
|
@@ -75,31 +75,14 @@ declare module '$app/env' {
|
|
|
75
75
|
export const browser: boolean;
|
|
76
76
|
|
|
77
77
|
/**
|
|
78
|
-
*
|
|
78
|
+
* Whether the dev server is running. This is not guaranteed to correspond to `NODE_ENV` or `MODE`.
|
|
79
79
|
*/
|
|
80
80
|
export const dev: boolean;
|
|
81
81
|
|
|
82
|
-
/**
|
|
83
|
-
* The Vite.js mode the app is running in. Configure in [`vite.config.js`](https://vitejs.dev/config/shared-options.html#mode).
|
|
84
|
-
* Vite.js loads the dotenv file associated with the provided mode, `.env.[mode]` or `.env.[mode].local`.
|
|
85
|
-
* By default, `vite dev` runs with `mode=development` and `vite build` runs with `mode=production`.
|
|
86
|
-
*/
|
|
87
|
-
export const mode: string;
|
|
88
|
-
|
|
89
82
|
/**
|
|
90
83
|
* `true` when prerendering, `false` otherwise.
|
|
91
84
|
*/
|
|
92
85
|
export const prerendering: boolean;
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* `true` in production mode, `false` in development.
|
|
96
|
-
*/
|
|
97
|
-
export const prod: boolean;
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* `true` if the app is running on the server.
|
|
101
|
-
*/
|
|
102
|
-
export const server: boolean;
|
|
103
86
|
}
|
|
104
87
|
|
|
105
88
|
/**
|
package/types/index.d.ts
CHANGED