@sveltejs/kit 1.0.0-next.384 → 1.0.0-next.385
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 +23 -1
- package/assets/server/index.js +22 -22
- package/dist/chunks/error.js +18 -0
- package/dist/cli.js +1 -1
- package/dist/node/polyfills.js +1 -0
- package/dist/vite.js +77 -14
- 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
|
}
|
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() {
|
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';
|
|
@@ -1112,28 +1112,39 @@ function escape_html_attr(str) {
|
|
|
1112
1112
|
|
|
1113
1113
|
/**
|
|
1114
1114
|
* @typedef {import('types').PrerenderErrorHandler} PrerenderErrorHandler
|
|
1115
|
-
* @typedef {import('types').PrerenderOnErrorValue} OnError
|
|
1116
1115
|
* @typedef {import('types').Logger} Logger
|
|
1117
1116
|
*/
|
|
1118
1117
|
|
|
1119
|
-
/**
|
|
1120
|
-
|
|
1121
|
-
|
|
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})` : ''}`;
|
|
1122
1129
|
}
|
|
1123
1130
|
|
|
1124
|
-
/**
|
|
1125
|
-
|
|
1126
|
-
|
|
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) {
|
|
1127
1138
|
case 'continue':
|
|
1128
1139
|
return (details) => {
|
|
1129
|
-
log.error(format_error(details));
|
|
1140
|
+
log.error(format_error(details, config));
|
|
1130
1141
|
};
|
|
1131
1142
|
case 'fail':
|
|
1132
1143
|
return (details) => {
|
|
1133
|
-
throw new Error(format_error(details));
|
|
1144
|
+
throw new Error(format_error(details, config));
|
|
1134
1145
|
};
|
|
1135
1146
|
default:
|
|
1136
|
-
return onError;
|
|
1147
|
+
return config.prerender.onError;
|
|
1137
1148
|
}
|
|
1138
1149
|
}
|
|
1139
1150
|
|
|
@@ -1162,6 +1173,58 @@ async function prerender({ config, entries, files, log }) {
|
|
|
1162
1173
|
}
|
|
1163
1174
|
|
|
1164
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
|
+
};
|
|
1165
1228
|
|
|
1166
1229
|
const server_root = join(config.outDir, 'output');
|
|
1167
1230
|
|
|
@@ -1177,7 +1240,7 @@ async function prerender({ config, entries, files, log }) {
|
|
|
1177
1240
|
|
|
1178
1241
|
const server = new Server(manifest);
|
|
1179
1242
|
|
|
1180
|
-
const error = normalise_error_handler(log, config
|
|
1243
|
+
const error = normalise_error_handler(log, config);
|
|
1181
1244
|
|
|
1182
1245
|
const q = queue(config.prerender.concurrency);
|
|
1183
1246
|
|
|
@@ -1231,7 +1294,7 @@ async function prerender({ config, entries, files, log }) {
|
|
|
1231
1294
|
/** @type {Map<string, import('types').PrerenderDependency>} */
|
|
1232
1295
|
const dependencies = new Map();
|
|
1233
1296
|
|
|
1234
|
-
const response = await server.respond(new Request(
|
|
1297
|
+
const response = await server.respond(new Request(config.prerender.origin + encoded), {
|
|
1235
1298
|
getClientAddress,
|
|
1236
1299
|
prerendering: {
|
|
1237
1300
|
dependencies
|
|
@@ -1367,7 +1430,7 @@ async function prerender({ config, entries, files, log }) {
|
|
|
1367
1430
|
await q.done();
|
|
1368
1431
|
}
|
|
1369
1432
|
|
|
1370
|
-
const rendered = await server.respond(new Request('
|
|
1433
|
+
const rendered = await server.respond(new Request(config.prerender.origin + '/[fallback]'), {
|
|
1371
1434
|
getClientAddress,
|
|
1372
1435
|
prerendering: {
|
|
1373
1436
|
fallback: true,
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED