@sveltejs/kit 1.15.4 → 1.15.6
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 +1 -1
- package/src/core/sync/create_manifest_data/index.js +46 -4
- package/src/exports/node/index.js +18 -11
- package/src/exports/vite/build/build_server.js +1 -2
- package/src/exports/vite/dev/index.js +1 -2
- package/src/runtime/client/client.js +7 -5
- package/src/runtime/client/utils.js +16 -11
- package/src/runtime/server/page/actions.js +12 -5
- package/src/runtime/server/page/render.js +4 -15
- package/src/runtime/server/respond.js +8 -1
- package/src/runtime/server/utils.js +4 -6
- package/types/ambient.d.ts +3 -1
- package/types/internal.d.ts +0 -2
package/package.json
CHANGED
|
@@ -227,6 +227,18 @@ function create_routes_and_nodes(cwd, config, fallback) {
|
|
|
227
227
|
config.kit.moduleExtensions
|
|
228
228
|
);
|
|
229
229
|
|
|
230
|
+
/**
|
|
231
|
+
* @param {string} type
|
|
232
|
+
* @param {string} existing_file
|
|
233
|
+
*/
|
|
234
|
+
function duplicate_files_error(type, existing_file) {
|
|
235
|
+
return new Error(
|
|
236
|
+
`Multiple ${type} files found in ${routes_base}${route.id} : ${path.basename(
|
|
237
|
+
existing_file
|
|
238
|
+
)} and ${file.name}`
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
|
|
230
242
|
if (item.kind === 'component') {
|
|
231
243
|
if (item.is_error) {
|
|
232
244
|
route.error = {
|
|
@@ -234,21 +246,51 @@ function create_routes_and_nodes(cwd, config, fallback) {
|
|
|
234
246
|
component: project_relative
|
|
235
247
|
};
|
|
236
248
|
} else if (item.is_layout) {
|
|
237
|
-
if (!route.layout)
|
|
249
|
+
if (!route.layout) {
|
|
250
|
+
route.layout = { depth, child_pages: [] };
|
|
251
|
+
} else if (route.layout.component) {
|
|
252
|
+
throw duplicate_files_error('layout component', route.layout.component);
|
|
253
|
+
}
|
|
254
|
+
|
|
238
255
|
route.layout.component = project_relative;
|
|
239
256
|
if (item.uses_layout !== undefined) route.layout.parent_id = item.uses_layout;
|
|
240
257
|
} else {
|
|
241
|
-
if (!route.leaf)
|
|
258
|
+
if (!route.leaf) {
|
|
259
|
+
route.leaf = { depth };
|
|
260
|
+
} else if (route.leaf.component) {
|
|
261
|
+
throw duplicate_files_error('page component', route.leaf.component);
|
|
262
|
+
}
|
|
263
|
+
|
|
242
264
|
route.leaf.component = project_relative;
|
|
243
265
|
if (item.uses_layout !== undefined) route.leaf.parent_id = item.uses_layout;
|
|
244
266
|
}
|
|
245
267
|
} else if (item.is_layout) {
|
|
246
|
-
if (!route.layout)
|
|
268
|
+
if (!route.layout) {
|
|
269
|
+
route.layout = { depth, child_pages: [] };
|
|
270
|
+
} else if (route.layout[item.kind]) {
|
|
271
|
+
throw duplicate_files_error(
|
|
272
|
+
item.kind + ' layout module',
|
|
273
|
+
/** @type {string} */ (route.layout[item.kind])
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
|
|
247
277
|
route.layout[item.kind] = project_relative;
|
|
248
278
|
} else if (item.is_page) {
|
|
249
|
-
if (!route.leaf)
|
|
279
|
+
if (!route.leaf) {
|
|
280
|
+
route.leaf = { depth };
|
|
281
|
+
} else if (route.leaf[item.kind]) {
|
|
282
|
+
throw duplicate_files_error(
|
|
283
|
+
item.kind + ' page module',
|
|
284
|
+
/** @type {string} */ (route.leaf[item.kind])
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
|
|
250
288
|
route.leaf[item.kind] = project_relative;
|
|
251
289
|
} else {
|
|
290
|
+
if (route.endpoint) {
|
|
291
|
+
throw duplicate_files_error('endpoint', route.endpoint.file);
|
|
292
|
+
}
|
|
293
|
+
|
|
252
294
|
route.endpoint = {
|
|
253
295
|
file: project_relative
|
|
254
296
|
};
|
|
@@ -105,17 +105,25 @@ export async function getRequest({ request, base, bodySizeLimit }) {
|
|
|
105
105
|
|
|
106
106
|
/** @type {import('@sveltejs/kit/node').setResponse} */
|
|
107
107
|
export async function setResponse(res, response) {
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
108
|
+
for (const [key, value] of response.headers) {
|
|
109
|
+
try {
|
|
110
|
+
res.setHeader(
|
|
111
|
+
key,
|
|
112
|
+
key === 'set-cookie'
|
|
113
|
+
? set_cookie_parser.splitCookiesString(
|
|
114
|
+
// This is absurd but necessary, TODO: investigate why
|
|
115
|
+
/** @type {string}*/ (response.headers.get(key))
|
|
116
|
+
)
|
|
117
|
+
: value
|
|
118
|
+
);
|
|
119
|
+
} catch (error) {
|
|
120
|
+
res.getHeaderNames().forEach((name) => res.removeHeader(name));
|
|
121
|
+
res.writeHead(500).end(String(error));
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
116
124
|
}
|
|
117
125
|
|
|
118
|
-
res.writeHead(response.status
|
|
126
|
+
res.writeHead(response.status);
|
|
119
127
|
|
|
120
128
|
if (!response.body) {
|
|
121
129
|
res.end();
|
|
@@ -123,11 +131,10 @@ export async function setResponse(res, response) {
|
|
|
123
131
|
}
|
|
124
132
|
|
|
125
133
|
if (response.body.locked) {
|
|
126
|
-
res.
|
|
134
|
+
res.end(
|
|
127
135
|
'Fatal error: Response body is locked. ' +
|
|
128
136
|
`This can happen when the response was already read (for example through 'response.json()' or 'response.text()').`
|
|
129
137
|
);
|
|
130
|
-
res.end();
|
|
131
138
|
return;
|
|
132
139
|
}
|
|
133
140
|
|
|
@@ -57,8 +57,7 @@ export function build_server_nodes(out, kit, manifest_data, server_manifest, cli
|
|
|
57
57
|
exports.push(
|
|
58
58
|
`export const component = async () => (await import('../${
|
|
59
59
|
resolve_symlinks(server_manifest, node.component).chunk.file
|
|
60
|
-
}')).default
|
|
61
|
-
`export const file = '${entry.file}';` // TODO what is this?
|
|
60
|
+
}')).default;`
|
|
62
61
|
);
|
|
63
62
|
}
|
|
64
63
|
|
|
@@ -145,12 +145,11 @@ export async function dev(vite, vite_config, svelte_config) {
|
|
|
145
145
|
|
|
146
146
|
if (node.component) {
|
|
147
147
|
result.component = async () => {
|
|
148
|
-
const { module_node, module
|
|
148
|
+
const { module_node, module } = await resolve(
|
|
149
149
|
/** @type {string} */ (node.component)
|
|
150
150
|
);
|
|
151
151
|
|
|
152
152
|
module_nodes.push(module_node);
|
|
153
|
-
result.file = url.endsWith('.svelte') ? url : url + '?import'; // TODO what is this for?
|
|
154
153
|
|
|
155
154
|
return module.default;
|
|
156
155
|
};
|
|
@@ -1266,8 +1266,8 @@ export function create_client(app, target) {
|
|
|
1266
1266
|
const a = find_anchor(element, container);
|
|
1267
1267
|
if (!a) return;
|
|
1268
1268
|
|
|
1269
|
-
const { url, external } = get_link_info(a, base);
|
|
1270
|
-
if (external) return;
|
|
1269
|
+
const { url, external, download } = get_link_info(a, base);
|
|
1270
|
+
if (external || download) return;
|
|
1271
1271
|
|
|
1272
1272
|
const options = get_router_options(a);
|
|
1273
1273
|
|
|
@@ -1300,8 +1300,8 @@ export function create_client(app, target) {
|
|
|
1300
1300
|
observer.disconnect();
|
|
1301
1301
|
|
|
1302
1302
|
for (const a of container.querySelectorAll('a')) {
|
|
1303
|
-
const { url, external } = get_link_info(a, base);
|
|
1304
|
-
if (external) continue;
|
|
1303
|
+
const { url, external, download } = get_link_info(a, base);
|
|
1304
|
+
if (external || download) continue;
|
|
1305
1305
|
|
|
1306
1306
|
const options = get_router_options(a);
|
|
1307
1307
|
if (options.reload) continue;
|
|
@@ -1517,7 +1517,7 @@ export function create_client(app, target) {
|
|
|
1517
1517
|
const a = find_anchor(/** @type {Element} */ (event.composedPath()[0]), container);
|
|
1518
1518
|
if (!a) return;
|
|
1519
1519
|
|
|
1520
|
-
const { url, external, target } = get_link_info(a, base);
|
|
1520
|
+
const { url, external, target, download } = get_link_info(a, base);
|
|
1521
1521
|
if (!url) return;
|
|
1522
1522
|
|
|
1523
1523
|
// bail out before `beforeNavigate` if link opens in a different tab
|
|
@@ -1545,6 +1545,8 @@ export function create_client(app, target) {
|
|
|
1545
1545
|
)
|
|
1546
1546
|
return;
|
|
1547
1547
|
|
|
1548
|
+
if (download) return;
|
|
1549
|
+
|
|
1548
1550
|
// Ignore the following but fire beforeNavigate
|
|
1549
1551
|
if (external || options.reload) {
|
|
1550
1552
|
if (before_navigate({ url, type: 'link' })) {
|
|
@@ -133,10 +133,11 @@ export function get_link_info(a, base) {
|
|
|
133
133
|
!url ||
|
|
134
134
|
!!target ||
|
|
135
135
|
is_external_url(url, base) ||
|
|
136
|
-
(a.getAttribute('rel') || '').split(/\s+/).includes('external')
|
|
137
|
-
a.hasAttribute('download');
|
|
136
|
+
(a.getAttribute('rel') || '').split(/\s+/).includes('external');
|
|
138
137
|
|
|
139
|
-
|
|
138
|
+
const download = url?.origin === location.origin && a.hasAttribute('download');
|
|
139
|
+
|
|
140
|
+
return { url, external, target, download };
|
|
140
141
|
}
|
|
141
142
|
|
|
142
143
|
/**
|
|
@@ -231,14 +232,18 @@ export function create_updated_store() {
|
|
|
231
232
|
|
|
232
233
|
if (interval) timeout = setTimeout(check, interval);
|
|
233
234
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
235
|
+
try {
|
|
236
|
+
const res = await fetch(`${assets}/${__SVELTEKIT_APP_VERSION_FILE__}`, {
|
|
237
|
+
headers: {
|
|
238
|
+
pragma: 'no-cache',
|
|
239
|
+
'cache-control': 'no-cache'
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
if (!res.ok) {
|
|
244
|
+
return false;
|
|
238
245
|
}
|
|
239
|
-
});
|
|
240
246
|
|
|
241
|
-
if (res.ok) {
|
|
242
247
|
const data = await res.json();
|
|
243
248
|
const updated = data.version !== version;
|
|
244
249
|
|
|
@@ -248,8 +253,8 @@ export function create_updated_store() {
|
|
|
248
253
|
}
|
|
249
254
|
|
|
250
255
|
return updated;
|
|
251
|
-
}
|
|
252
|
-
|
|
256
|
+
} catch {
|
|
257
|
+
return false;
|
|
253
258
|
}
|
|
254
259
|
}
|
|
255
260
|
|
|
@@ -72,11 +72,7 @@ export async function handle_action_json_request(event, options, server) {
|
|
|
72
72
|
const err = normalize_error(e);
|
|
73
73
|
|
|
74
74
|
if (err instanceof Redirect) {
|
|
75
|
-
return
|
|
76
|
-
type: 'redirect',
|
|
77
|
-
status: err.status,
|
|
78
|
-
location: err.location
|
|
79
|
-
});
|
|
75
|
+
return action_json_redirect(err);
|
|
80
76
|
}
|
|
81
77
|
|
|
82
78
|
return action_json(
|
|
@@ -100,6 +96,17 @@ function check_incorrect_fail_use(error) {
|
|
|
100
96
|
: error;
|
|
101
97
|
}
|
|
102
98
|
|
|
99
|
+
/**
|
|
100
|
+
* @param {import('types').Redirect} redirect
|
|
101
|
+
*/
|
|
102
|
+
export function action_json_redirect(redirect) {
|
|
103
|
+
return action_json({
|
|
104
|
+
type: 'redirect',
|
|
105
|
+
status: redirect.status,
|
|
106
|
+
location: redirect.location
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
103
110
|
/**
|
|
104
111
|
* @param {import('types').ActionResult} data
|
|
105
112
|
* @param {ResponseInit} [init]
|
|
@@ -95,23 +95,12 @@ export async function render_response({
|
|
|
95
95
|
|
|
96
96
|
// if appropriate, use relative paths for greater portability
|
|
97
97
|
if (paths.relative !== false && !state.prerendering?.fallback) {
|
|
98
|
-
const segments = event.url.pathname.slice(paths.base.length).split('/');
|
|
98
|
+
const segments = event.url.pathname.slice(paths.base.length).split('/').slice(2);
|
|
99
99
|
|
|
100
|
-
|
|
101
|
-
// if we're on `/my-base-path`, relative links need to start `./my-base-path` rather than `.`
|
|
102
|
-
base = `./${paths.base.split('/').at(-1)}`;
|
|
100
|
+
base = segments.map(() => '..').join('/') || '.';
|
|
103
101
|
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
base =
|
|
107
|
-
segments
|
|
108
|
-
.slice(2)
|
|
109
|
-
.map(() => '..')
|
|
110
|
-
.join('/') || '.';
|
|
111
|
-
|
|
112
|
-
// resolve e.g. '../..' against current location, then remove trailing slash
|
|
113
|
-
base_expression = `new URL(${s(base)}, location).pathname.slice(0, -1)`;
|
|
114
|
-
}
|
|
102
|
+
// resolve e.g. '../..' against current location, then remove trailing slash
|
|
103
|
+
base_expression = `new URL(${s(base)}, location).pathname.slice(0, -1)`;
|
|
115
104
|
|
|
116
105
|
if (!paths.assets || (paths.assets[0] === '/' && paths.assets !== SVELTE_KIT_ASSETS)) {
|
|
117
106
|
assets = base;
|
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
} from '../../utils/exports.js';
|
|
27
27
|
import { get_option } from '../../utils/options.js';
|
|
28
28
|
import { error, json, text } from '../../exports/index.js';
|
|
29
|
+
import { action_json_redirect, is_action_json_request } from './page/actions.js';
|
|
29
30
|
|
|
30
31
|
/* global __SVELTEKIT_ADAPTER_NAME__ */
|
|
31
32
|
|
|
@@ -175,7 +176,11 @@ export async function respond(request, options, manifest, state) {
|
|
|
175
176
|
try {
|
|
176
177
|
// determine whether we need to redirect to add/remove a trailing slash
|
|
177
178
|
if (route && !is_data_request) {
|
|
178
|
-
if
|
|
179
|
+
// if `paths.base === '/a/b/c`, then the root route is `/a/b/c/`,
|
|
180
|
+
// regardless of the `trailingSlash` route option
|
|
181
|
+
if (url.pathname === base || url.pathname === base + '/') {
|
|
182
|
+
trailing_slash = 'always';
|
|
183
|
+
} else if (route.page) {
|
|
179
184
|
const nodes = await Promise.all([
|
|
180
185
|
// we use == here rather than === because [undefined] serializes as "[null]"
|
|
181
186
|
...route.page.layouts.map((n) => (n == undefined ? n : manifest._.nodes[n]())),
|
|
@@ -309,6 +314,8 @@ export async function respond(request, options, manifest, state) {
|
|
|
309
314
|
if (e instanceof Redirect) {
|
|
310
315
|
const response = is_data_request
|
|
311
316
|
? redirect_json_response(e)
|
|
317
|
+
: route?.page && is_action_json_request(event)
|
|
318
|
+
? action_json_redirect(e)
|
|
312
319
|
: redirect_response(e.status, e.location);
|
|
313
320
|
add_cookies_to_headers(response.headers, Object.values(cookies_to_add));
|
|
314
321
|
return response;
|
|
@@ -34,13 +34,11 @@ export function method_not_allowed(mod, method) {
|
|
|
34
34
|
|
|
35
35
|
/** @param {Partial<Record<import('types').HttpMethod, any>>} mod */
|
|
36
36
|
export function allowed_methods(mod) {
|
|
37
|
-
const allowed = []
|
|
37
|
+
const allowed = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'].filter(
|
|
38
|
+
(method) => method in mod
|
|
39
|
+
);
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
if (method in mod) allowed.push(method);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (mod.GET || mod.HEAD) allowed.push('HEAD');
|
|
41
|
+
if ('GET' in mod || 'HEAD' in mod) allowed.push('HEAD');
|
|
44
42
|
|
|
45
43
|
return allowed;
|
|
46
44
|
}
|
package/types/ambient.d.ts
CHANGED
|
@@ -281,11 +281,13 @@ declare module '$app/paths' {
|
|
|
281
281
|
}
|
|
282
282
|
|
|
283
283
|
/**
|
|
284
|
-
*
|
|
284
|
+
* These stores are _contextual_ on the server — they are added to the [context](https://svelte.dev/tutorial/context-api) of your root component. This means that `page` is unique to each request, rather than shared between multiple requests handled by the same server simultaneously.
|
|
285
285
|
*
|
|
286
286
|
* Because of that, you must subscribe to the stores during component initialization (which happens automatically if you reference the store value, e.g. as `$page`, in a component) before you can use them.
|
|
287
287
|
*
|
|
288
288
|
* In the browser, we don't need to worry about this, and stores can be accessed from anywhere. Code that will only ever run on the browser can refer to (or subscribe to) any of these stores at any time.
|
|
289
|
+
*
|
|
290
|
+
* You can read more about client/server differences in the [state management](https://kit.svelte.dev/docs/state-management#using-stores-with-context) documentation.
|
|
289
291
|
*/
|
|
290
292
|
declare module '$app/stores' {
|
|
291
293
|
import { Readable } from 'svelte/store';
|
package/types/internal.d.ts
CHANGED
|
@@ -290,8 +290,6 @@ export interface SSRNode {
|
|
|
290
290
|
component: SSRComponentLoader;
|
|
291
291
|
/** index into the `components` array in client/manifest.js */
|
|
292
292
|
index: number;
|
|
293
|
-
/** client-side module URL for this component */
|
|
294
|
-
file: string;
|
|
295
293
|
/** external JS files */
|
|
296
294
|
imports: string[];
|
|
297
295
|
/** external CSS files */
|