@sveltejs/kit 1.13.0 → 1.15.0
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/write_types/index.js +17 -10
- package/src/exports/vite/build/utils.js +3 -1
- package/src/exports/vite/dev/index.js +10 -1
- package/src/exports/vite/index.js +2 -1
- package/src/runtime/server/page/actions.js +1 -1
- package/src/runtime/server/utils.js +9 -1
- package/types/index.d.ts +6 -5
package/package.json
CHANGED
|
@@ -390,16 +390,23 @@ function process_node(node, outdir, is_page, proxies, all_pages_have_load = true
|
|
|
390
390
|
|
|
391
391
|
if (is_page) {
|
|
392
392
|
let type = 'unknown';
|
|
393
|
-
if (proxy) {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
type =
|
|
402
|
-
|
|
393
|
+
if (proxy && proxy.exports.includes('actions')) {
|
|
394
|
+
// If the file wasn't tweaked, we can use the return type of the original file.
|
|
395
|
+
// The advantage is that type updates are reflected without saving.
|
|
396
|
+
const from = proxy.modified
|
|
397
|
+
? `./proxy${replace_ext_with_js(basename)}`
|
|
398
|
+
: path_to_original(outdir, node.server);
|
|
399
|
+
|
|
400
|
+
exports.push(
|
|
401
|
+
`type ExcludeActionFailure<T> = T extends Kit.ActionFailure<any> ? never : T extends void ? never : T;`,
|
|
402
|
+
`type ActionsSuccess<T extends Record<string, (...args: any) => any>> = { [Key in keyof T]: ExcludeActionFailure<Awaited<ReturnType<T[Key]>>>; }[keyof T];`,
|
|
403
|
+
`type ExtractActionFailure<T> = T extends Kit.ActionFailure<infer X> ? X extends void ? never : X : never;`,
|
|
404
|
+
`type ActionsFailure<T extends Record<string, (...args: any) => any>> = { [Key in keyof T]: Exclude<ExtractActionFailure<Awaited<ReturnType<T[Key]>>>, void>; }[keyof T];`,
|
|
405
|
+
`type ActionsExport = typeof import('${from}').actions`,
|
|
406
|
+
`export type SubmitFunction = Kit.SubmitFunction<Expand<ActionsSuccess<ActionsExport>>, Expand<ActionsFailure<ActionsExport>>>`
|
|
407
|
+
);
|
|
408
|
+
|
|
409
|
+
type = `Expand<Kit.AwaitedActions<ActionsExport>> | null`;
|
|
403
410
|
}
|
|
404
411
|
exports.push(`export type ActionData = ${type};`);
|
|
405
412
|
}
|
|
@@ -72,7 +72,9 @@ export function find_deps(manifest, entry, add_dynamic_css) {
|
|
|
72
72
|
*/
|
|
73
73
|
export function resolve_symlinks(manifest, file) {
|
|
74
74
|
while (!manifest[file]) {
|
|
75
|
-
|
|
75
|
+
const next = path.relative('.', fs.realpathSync(file));
|
|
76
|
+
if (next === file) throw new Error(`Could not find file "${file}" in Vite manifest`);
|
|
77
|
+
file = next;
|
|
76
78
|
}
|
|
77
79
|
|
|
78
80
|
const chunk = manifest[file];
|
|
@@ -58,7 +58,16 @@ export async function dev(vite, vite_config, svelte_config) {
|
|
|
58
58
|
const msg = buildErrorMessage(err, [colors.red(`Internal server error: ${err.message}`)]);
|
|
59
59
|
|
|
60
60
|
vite.config.logger.error(msg, { error: err });
|
|
61
|
-
vite.ws.send({
|
|
61
|
+
vite.ws.send({
|
|
62
|
+
type: 'error',
|
|
63
|
+
err: {
|
|
64
|
+
...err,
|
|
65
|
+
// these properties are non-enumerable and will
|
|
66
|
+
// not be serialized unless we explicitly include them
|
|
67
|
+
message: err.message,
|
|
68
|
+
stack: err.stack
|
|
69
|
+
}
|
|
70
|
+
});
|
|
62
71
|
|
|
63
72
|
throw err;
|
|
64
73
|
}
|
|
@@ -564,11 +564,12 @@ function kit({ svelte_config }) {
|
|
|
564
564
|
preserveEntrySignatures: 'strict'
|
|
565
565
|
},
|
|
566
566
|
ssrEmitAssets: true,
|
|
567
|
+
copyPublicDir: !ssr,
|
|
567
568
|
target: ssr ? 'node16.14' : undefined,
|
|
568
569
|
// don't use the default name to avoid collisions with 'static/manifest.json'
|
|
569
570
|
manifest: 'vite-manifest.json'
|
|
570
571
|
},
|
|
571
|
-
publicDir:
|
|
572
|
+
publicDir: kit.files.assets,
|
|
572
573
|
worker: {
|
|
573
574
|
rollupOptions: {
|
|
574
575
|
output: {
|
|
@@ -214,7 +214,7 @@ async function call_action(event, actions) {
|
|
|
214
214
|
|
|
215
215
|
if (!is_form_content_type(event.request)) {
|
|
216
216
|
throw new Error(
|
|
217
|
-
`Actions expect form-encoded data (received ${event.request.headers.get('content-type')}`
|
|
217
|
+
`Actions expect form-encoded data (received ${event.request.headers.get('content-type')})`
|
|
218
218
|
);
|
|
219
219
|
}
|
|
220
220
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DEV } from 'esm-env';
|
|
1
2
|
import { json, text } from '../../exports/index.js';
|
|
2
3
|
import { coalesce_to_error } from '../../utils/error.js';
|
|
3
4
|
import { negotiate } from '../../utils/http.js';
|
|
@@ -52,7 +53,14 @@ export function allowed_methods(mod) {
|
|
|
52
53
|
* @param {string} message
|
|
53
54
|
*/
|
|
54
55
|
export function static_error_page(options, status, message) {
|
|
55
|
-
|
|
56
|
+
let page = options.templates.error({ status, message });
|
|
57
|
+
|
|
58
|
+
if (DEV) {
|
|
59
|
+
// inject Vite HMR client, for easier debugging
|
|
60
|
+
page = page.replace('</head>', '<script type="module" src="/@vite/client"></script></head>');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return text(page, {
|
|
56
64
|
headers: { 'content-type': 'text/html; charset=utf-8' },
|
|
57
65
|
status
|
|
58
66
|
});
|
package/types/index.d.ts
CHANGED
|
@@ -1167,10 +1167,10 @@ export type Actions<
|
|
|
1167
1167
|
*/
|
|
1168
1168
|
export type ActionResult<
|
|
1169
1169
|
Success extends Record<string, unknown> | undefined = Record<string, any>,
|
|
1170
|
-
|
|
1170
|
+
Failure extends Record<string, unknown> | undefined = Record<string, any>
|
|
1171
1171
|
> =
|
|
1172
1172
|
| { type: 'success'; status: number; data?: Success }
|
|
1173
|
-
| { type: 'failure'; status: number; data?:
|
|
1173
|
+
| { type: 'failure'; status: number; data?: Failure }
|
|
1174
1174
|
| { type: 'redirect'; status: number; location: string }
|
|
1175
1175
|
| { type: 'error'; status?: number; error: any };
|
|
1176
1176
|
|
|
@@ -1239,7 +1239,7 @@ export function text(body: string, init?: ResponseInit): Response;
|
|
|
1239
1239
|
* @param status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
|
|
1240
1240
|
* @param data Data associated with the failure (e.g. validation errors)
|
|
1241
1241
|
*/
|
|
1242
|
-
export function fail<T extends Record<string, unknown> | undefined>(
|
|
1242
|
+
export function fail<T extends Record<string, unknown> | undefined = undefined>(
|
|
1243
1243
|
status: number,
|
|
1244
1244
|
data?: T
|
|
1245
1245
|
): ActionFailure<T>;
|
|
@@ -1257,20 +1257,21 @@ export interface ActionFailure<T extends Record<string, unknown> | undefined = u
|
|
|
1257
1257
|
|
|
1258
1258
|
export interface SubmitFunction<
|
|
1259
1259
|
Success extends Record<string, unknown> | undefined = Record<string, any>,
|
|
1260
|
-
|
|
1260
|
+
Failure extends Record<string, unknown> | undefined = Record<string, any>
|
|
1261
1261
|
> {
|
|
1262
1262
|
(input: {
|
|
1263
1263
|
action: URL;
|
|
1264
1264
|
data: FormData;
|
|
1265
1265
|
form: HTMLFormElement;
|
|
1266
1266
|
controller: AbortController;
|
|
1267
|
+
submitter: HTMLElement | null;
|
|
1267
1268
|
cancel(): void;
|
|
1268
1269
|
}): MaybePromise<
|
|
1269
1270
|
| void
|
|
1270
1271
|
| ((opts: {
|
|
1271
1272
|
form: HTMLFormElement;
|
|
1272
1273
|
action: URL;
|
|
1273
|
-
result: ActionResult<Success,
|
|
1274
|
+
result: ActionResult<Success, Failure>;
|
|
1274
1275
|
/**
|
|
1275
1276
|
* Call this to get the default behavior of a form submission response.
|
|
1276
1277
|
* @param options Set `reset: false` if you don't want the `<form>` values to be reset after a successful submission.
|