@sveltejs/kit 1.0.0-next.543 → 1.0.0-next.545

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.543",
3
+ "version": "1.0.0-next.545",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -19,9 +19,11 @@ export function generate_manifest({ build_data, relative_path, routes, format =
19
19
  */
20
20
  const reindexed = new Map();
21
21
  /**
22
- * @type {Set<any>} All nodes actually used in the routes definition (prerendered routes are omitted)
22
+ * All nodes actually used in the routes definition (prerendered routes are omitted).
23
+ * Root layout/error is always included as they are needed for 404 and root errors.
24
+ * @type {Set<any>}
23
25
  */
24
- const used_nodes = new Set();
26
+ const used_nodes = new Set([0, 1]);
25
27
 
26
28
  for (const route of routes) {
27
29
  if (route.page) {
@@ -258,7 +258,12 @@ function create_routes_and_nodes(cwd, config, fallback) {
258
258
  // and smaller indexes take fewer bytes. also, this guarantees that
259
259
  // the default error/layout are 0/1
260
260
  for (const route of routes) {
261
- if (route.layout) nodes.push(route.layout);
261
+ if (route.layout) {
262
+ if (!route.layout?.component) {
263
+ route.layout.component = posixify(path.relative(cwd, `${fallback}/layout.svelte`));
264
+ }
265
+ nodes.push(route.layout);
266
+ }
262
267
  if (route.error) nodes.push(route.error);
263
268
  }
264
269
 
@@ -27,7 +27,7 @@ export function write(file, code) {
27
27
 
28
28
  /** @param {string} str */
29
29
  export function trim(str) {
30
- const indentation = /** @type {RegExpExecArray} */ (/\n?(\s*)/.exec(str))[1];
30
+ const indentation = /** @type {RegExpExecArray} */ (/\n?([ \t]*)/.exec(str))[1];
31
31
  const pattern = new RegExp(`^${indentation}`, 'gm');
32
32
  return str.replace(pattern, '').trim();
33
33
  }
@@ -13,7 +13,7 @@ export function error(status, message) {
13
13
 
14
14
  /** @type {import('@sveltejs/kit').redirect} */
15
15
  export function redirect(status, location) {
16
- if (isNaN(status) || status < 300 || status > 399) {
16
+ if (isNaN(status) || status < 300 || status > 308) {
17
17
  throw new Error('Invalid status code');
18
18
  }
19
19
 
@@ -5,7 +5,7 @@ import { pathToFileURL } from 'url';
5
5
  import { getRequest, setResponse } from '../../../exports/node/index.js';
6
6
  import { installPolyfills } from '../../../exports/node/polyfills.js';
7
7
  import { SVELTE_KIT_ASSETS } from '../../../constants.js';
8
- import { loadEnv } from 'vite';
8
+ import { loadEnv, normalizePath } from 'vite';
9
9
 
10
10
  /** @typedef {import('http').IncomingMessage} Req */
11
11
  /** @typedef {import('http').ServerResponse} Res */
@@ -100,7 +100,9 @@ export async function preview(vite, vite_config, svelte_config) {
100
100
 
101
101
  const { pathname } = new URL(/** @type {string} */ (req.url), 'http://dummy');
102
102
 
103
- let filename = join(svelte_config.kit.outDir, 'output/prerendered/pages' + pathname);
103
+ let filename = normalizePath(
104
+ join(svelte_config.kit.outDir, 'output/prerendered/pages' + pathname)
105
+ );
104
106
  let prerendered = is_file(filename);
105
107
 
106
108
  if (!prerendered) {
@@ -58,11 +58,11 @@ export function error(status, message) {
58
58
  /**
59
59
  * Creates a `Redirect` object. If thrown during request handling, SvelteKit will
60
60
  * return a redirect response.
61
- * @param {number} status
61
+ * @param {300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308} status
62
62
  * @param {string} location
63
63
  */
64
64
  export function redirect(status, location) {
65
- if (isNaN(status) || status < 300 || status > 399) {
65
+ if (isNaN(status) || status < 300 || status > 308) {
66
66
  throw new Error('Invalid status code');
67
67
  }
68
68
 
@@ -95,6 +95,8 @@ declare module '$app/environment' {
95
95
  declare module '$app/forms' {
96
96
  import type { ActionResult } from '@sveltejs/kit';
97
97
 
98
+ type MaybePromise<T> = T | Promise<T>;
99
+
98
100
  export type SubmitFunction<
99
101
  Success extends Record<string, unknown> | undefined = Record<string, any>,
100
102
  Invalid extends Record<string, unknown> | undefined = Record<string, any>
@@ -104,7 +106,7 @@ declare module '$app/forms' {
104
106
  form: HTMLFormElement;
105
107
  controller: AbortController;
106
108
  cancel(): void;
107
- }) =>
109
+ }) => MaybePromise<
108
110
  | void
109
111
  | ((opts: {
110
112
  form: HTMLFormElement;
@@ -115,7 +117,8 @@ declare module '$app/forms' {
115
117
  * @param options Set `reset: false` if you don't want the `<form>` values to be reset after a successful submission.
116
118
  */
117
119
  update(options?: { reset: boolean }): Promise<void>;
118
- }) => void);
120
+ }) => void)
121
+ >;
119
122
 
120
123
  /**
121
124
  * This action enhances a `<form>` element that otherwise would work without JavaScript.
package/types/index.d.ts CHANGED
@@ -731,7 +731,10 @@ export function error(
731
731
  * Creates a `Redirect` object. If thrown during request handling, SvelteKit will
732
732
  * return a redirect response.
733
733
  */
734
- export function redirect(status: number, location: string): Redirect;
734
+ export function redirect(
735
+ status: 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308,
736
+ location: string
737
+ ): Redirect;
735
738
 
736
739
  /**
737
740
  * Generates a JSON `Response` object from the supplied data.