@sveltejs/kit 1.0.0-next.402 → 1.0.0-next.406

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.
Files changed (99) hide show
  1. package/package.json +24 -25
  2. package/{dist → src}/cli.js +19 -18
  3. package/{dist/chunks/index3.js → src/core/adapt/builder.js} +52 -63
  4. package/src/core/adapt/index.js +19 -0
  5. package/src/core/config/index.js +86 -0
  6. package/{dist/chunks/index.js → src/core/config/options.js} +7 -194
  7. package/src/core/config/types.d.ts +1 -0
  8. package/src/core/constants.js +3 -0
  9. package/src/core/generate_manifest/index.js +99 -0
  10. package/src/core/prerender/crawl.js +194 -0
  11. package/src/core/prerender/prerender.js +378 -0
  12. package/src/core/prerender/queue.js +80 -0
  13. package/src/core/sync/create_manifest_data/index.js +492 -0
  14. package/src/core/sync/create_manifest_data/types.d.ts +40 -0
  15. package/src/core/sync/sync.js +59 -0
  16. package/src/core/sync/utils.js +97 -0
  17. package/src/core/sync/write_ambient.js +87 -0
  18. package/src/core/sync/write_client_manifest.js +82 -0
  19. package/src/core/sync/write_matchers.js +25 -0
  20. package/src/core/sync/write_root.js +88 -0
  21. package/{dist/chunks → src/core/sync}/write_tsconfig.js +24 -108
  22. package/src/core/sync/write_types.js +738 -0
  23. package/src/core/utils.js +58 -0
  24. package/{dist → src}/hooks.js +1 -3
  25. package/src/index/index.js +45 -0
  26. package/src/index/private.js +31 -0
  27. package/src/node/index.js +145 -0
  28. package/src/node/polyfills.js +40 -0
  29. package/src/packaging/index.js +218 -0
  30. package/src/packaging/types.d.ts +8 -0
  31. package/src/packaging/typescript.js +150 -0
  32. package/src/packaging/utils.js +138 -0
  33. package/{assets → src/runtime}/app/env.js +3 -5
  34. package/src/runtime/app/navigation.js +22 -0
  35. package/src/runtime/app/paths.js +1 -0
  36. package/{assets → src/runtime}/app/stores.js +6 -9
  37. package/src/runtime/client/ambient.d.ts +17 -0
  38. package/{assets/client/start.js → src/runtime/client/client.js} +302 -878
  39. package/src/runtime/client/fetcher.js +60 -0
  40. package/src/runtime/client/parse.js +36 -0
  41. package/{assets → src/runtime}/client/singletons.js +2 -4
  42. package/src/runtime/client/start.js +48 -0
  43. package/src/runtime/client/types.d.ts +106 -0
  44. package/src/runtime/client/utils.js +113 -0
  45. package/src/runtime/components/error.svelte +16 -0
  46. package/{assets → src/runtime}/components/layout.svelte +0 -0
  47. package/{assets → src/runtime}/env/dynamic/private.js +0 -0
  48. package/{assets → src/runtime}/env/dynamic/public.js +0 -0
  49. package/{assets → src/runtime}/env-private.js +2 -4
  50. package/{assets → src/runtime}/env-public.js +2 -4
  51. package/src/runtime/env.js +6 -0
  52. package/src/runtime/hash.js +16 -0
  53. package/{assets → src/runtime}/paths.js +3 -5
  54. package/src/runtime/server/endpoint.js +42 -0
  55. package/src/runtime/server/index.js +434 -0
  56. package/src/runtime/server/page/cookie.js +25 -0
  57. package/src/runtime/server/page/crypto.js +239 -0
  58. package/src/runtime/server/page/csp.js +249 -0
  59. package/src/runtime/server/page/fetch.js +265 -0
  60. package/src/runtime/server/page/index.js +423 -0
  61. package/src/runtime/server/page/load_data.js +94 -0
  62. package/src/runtime/server/page/render.js +357 -0
  63. package/src/runtime/server/page/respond_with_error.js +105 -0
  64. package/src/runtime/server/page/types.d.ts +44 -0
  65. package/src/runtime/server/utils.js +116 -0
  66. package/src/utils/error.js +22 -0
  67. package/src/utils/escape.js +104 -0
  68. package/{dist/chunks → src/utils}/filesystem.js +22 -24
  69. package/src/utils/http.js +55 -0
  70. package/src/utils/misc.js +1 -0
  71. package/src/utils/routing.js +107 -0
  72. package/src/utils/url.js +97 -0
  73. package/src/vite/build/build_server.js +333 -0
  74. package/src/vite/build/build_service_worker.js +90 -0
  75. package/src/vite/build/utils.js +152 -0
  76. package/src/vite/dev/index.js +565 -0
  77. package/src/vite/index.js +536 -0
  78. package/src/vite/preview/index.js +186 -0
  79. package/src/vite/types.d.ts +3 -0
  80. package/src/vite/utils.js +335 -0
  81. package/svelte-kit.js +1 -10
  82. package/types/ambient.d.ts +5 -12
  83. package/types/index.d.ts +91 -44
  84. package/types/internal.d.ts +50 -72
  85. package/types/private.d.ts +2 -1
  86. package/assets/app/navigation.js +0 -24
  87. package/assets/app/paths.js +0 -1
  88. package/assets/components/error.svelte +0 -29
  89. package/assets/env.js +0 -8
  90. package/assets/server/index.js +0 -3579
  91. package/dist/chunks/error.js +0 -12
  92. package/dist/chunks/index2.js +0 -15745
  93. package/dist/chunks/multipart-parser.js +0 -458
  94. package/dist/chunks/sync.js +0 -1366
  95. package/dist/chunks/utils.js +0 -66
  96. package/dist/node/polyfills.js +0 -17778
  97. package/dist/node.js +0 -348
  98. package/dist/prerender.js +0 -788
  99. package/dist/vite.js +0 -2520
@@ -1,7 +1,10 @@
1
1
  import { OutputAsset, OutputChunk } from 'rollup';
2
+ import { SvelteComponent } from 'svelte/internal';
2
3
  import {
4
+ Action,
3
5
  Config,
4
6
  ExternalFetch,
7
+ ServerLoad,
5
8
  GetSession,
6
9
  Handle,
7
10
  HandleError,
@@ -14,14 +17,7 @@ import {
14
17
  ServerInitOptions,
15
18
  SSRManifest
16
19
  } from './index.js';
17
- import {
18
- HttpMethod,
19
- JSONObject,
20
- MaybePromise,
21
- RequestOptions,
22
- ResponseHeaders,
23
- TrailingSlash
24
- } from './private.js';
20
+ import { HttpMethod, MaybePromise, RequestOptions, TrailingSlash } from './private.js';
25
21
 
26
22
  export interface ServerModule {
27
23
  Server: typeof InternalServer;
@@ -64,16 +60,25 @@ export interface BuildData {
64
60
  };
65
61
  }
66
62
 
67
- export type CSRComponent = any; // TODO
63
+ export interface CSRPageNode {
64
+ component: typeof SvelteComponent;
65
+ shared: {
66
+ load: Load;
67
+ hydrate: boolean;
68
+ router: boolean;
69
+ };
70
+ server: boolean;
71
+ }
68
72
 
69
- export type CSRComponentLoader = () => Promise<CSRComponent>;
73
+ export type CSRPageNodeLoader = () => Promise<CSRPageNode>;
70
74
 
71
75
  export type CSRRoute = {
72
76
  id: string;
73
77
  exec: (path: string) => undefined | Record<string, string>;
74
- a: CSRComponentLoader[];
75
- b: CSRComponentLoader[];
76
- has_shadow: boolean;
78
+ errors: CSRPageNodeLoader[];
79
+ layouts: CSRPageNodeLoader[];
80
+ leaf: CSRPageNodeLoader;
81
+ uses_server_data: boolean;
77
82
  };
78
83
 
79
84
  export interface EndpointData {
@@ -109,7 +114,7 @@ export class InternalServer extends Server {
109
114
 
110
115
  export interface ManifestData {
111
116
  assets: Asset[];
112
- components: string[];
117
+ nodes: PageNode[];
113
118
  routes: RouteData[];
114
119
  matchers: Record<string, string>;
115
120
  }
@@ -119,34 +124,24 @@ export interface MethodOverride {
119
124
  allowed: string[];
120
125
  }
121
126
 
122
- export type NormalizedLoadOutput = {
123
- status?: number;
124
- error?: Error;
125
- redirect?: string;
126
- props?: Record<string, any> | Promise<Record<string, any>>;
127
- stuff?: Record<string, any>;
128
- cache?: NormalizedLoadOutputCache;
129
- dependencies?: string[];
130
- };
131
-
132
- export interface NormalizedLoadOutputCache {
133
- maxage: number;
134
- private?: boolean;
127
+ export interface PageNode {
128
+ component?: string; // TODO supply default component if it's missing (bit of an edge case)
129
+ shared?: string;
130
+ server?: string;
135
131
  }
136
132
 
137
133
  export interface PageData {
138
134
  type: 'page';
139
135
  id: string;
140
- shadow: string | null;
141
136
  pattern: RegExp;
142
- path: string;
143
- a: Array<string | undefined>;
144
- b: Array<string | undefined>;
137
+ errors: Array<PageNode | undefined>;
138
+ layouts: Array<PageNode | undefined>;
139
+ leaf: PageNode;
145
140
  }
146
141
 
147
142
  export type PayloadScriptAttributes =
148
143
  | { type: 'data'; url: string; body?: string }
149
- | { type: 'props' };
144
+ | { type: 'server_data' };
150
145
 
151
146
  export interface PrerenderDependency {
152
147
  response: Response;
@@ -154,6 +149,7 @@ export interface PrerenderDependency {
154
149
  }
155
150
 
156
151
  export interface PrerenderOptions {
152
+ cache?: string; // including this here is a bit of a hack, but it makes it easy to add <meta http-equiv>
157
153
  fallback?: boolean;
158
154
  dependencies: Map<string, PrerenderDependency>;
159
155
  }
@@ -174,29 +170,7 @@ export interface Respond {
174
170
 
175
171
  export type RouteData = PageData | EndpointData;
176
172
 
177
- export interface ShadowEndpointOutput<Output extends JSONObject = JSONObject> {
178
- status?: number;
179
- headers?: Partial<ResponseHeaders>;
180
- body?: Output;
181
- }
182
-
183
- export interface ShadowRequestHandler<Output extends JSONObject = JSONObject> {
184
- (event: RequestEvent): MaybePromise<ShadowEndpointOutput<Output>>;
185
- }
186
-
187
- export interface ShadowData {
188
- status?: number;
189
- error?: Error;
190
- redirect?: string;
191
- cookies?: string[];
192
- body?: JSONObject;
193
- }
194
-
195
173
  export interface SSRComponent {
196
- router?: boolean;
197
- hydrate?: boolean;
198
- prerender?: boolean;
199
- load: Load;
200
174
  default: {
201
175
  render(props: Record<string, any>): {
202
176
  html: string;
@@ -217,13 +191,11 @@ export interface SSREndpoint {
217
191
  pattern: RegExp;
218
192
  names: string[];
219
193
  types: string[];
220
- load(): Promise<{
221
- [method: string]: RequestHandler;
222
- }>;
194
+ load(): Promise<Partial<Record<HttpMethod, RequestHandler>>>;
223
195
  }
224
196
 
225
197
  export interface SSRNode {
226
- module: SSRComponent;
198
+ component: SSRComponent;
227
199
  /** index into the `components` array in client-manifest.js */
228
200
  index: number;
229
201
  /** client-side module URL for this component */
@@ -234,6 +206,23 @@ export interface SSRNode {
234
206
  stylesheets: string[];
235
207
  /** inlined styles */
236
208
  inline_styles?: () => MaybePromise<Record<string, string>>;
209
+
210
+ shared: {
211
+ load?: Load;
212
+ hydrate?: boolean;
213
+ prerender?: boolean;
214
+ router?: boolean;
215
+ ssr?: boolean;
216
+ };
217
+
218
+ server: {
219
+ load?: ServerLoad;
220
+ HEAD?: ServerLoad;
221
+ POST?: Action;
222
+ PATCH?: Action;
223
+ PUT?: Action;
224
+ DELETE?: Action;
225
+ };
237
226
  }
238
227
 
239
228
  export type SSRNodeLoader = () => Promise<SSRNode>;
@@ -282,20 +271,9 @@ export interface SSRPage {
282
271
  pattern: RegExp;
283
272
  names: string[];
284
273
  types: string[];
285
- shadow:
286
- | null
287
- | (() => Promise<{
288
- [method: string]: ShadowRequestHandler;
289
- }>);
290
- /**
291
- * plan a is to render 1 or more layout components followed by a leaf component.
292
- */
293
- a: Array<number | undefined>;
294
- /**
295
- * plan b — if one of them components fails in `load` we backtrack until we find
296
- * the nearest error component.
297
- */
298
- b: Array<number | undefined>;
274
+ errors: Array<number | undefined>;
275
+ layouts: Array<number | undefined>;
276
+ leaf: number;
299
277
  }
300
278
 
301
279
  export interface SSRErrorPage {
@@ -26,6 +26,7 @@ export interface AdapterEntry {
26
26
  }) => MaybePromise<void>;
27
27
  }
28
28
 
29
+ // TODO is this still used?
29
30
  export type BodyValidator<T> = {
30
31
  [P in keyof T]: T[P] extends { [k: string]: unknown }
31
32
  ? BodyValidator<T[P]> // recurse when T[P] is an object
@@ -212,7 +213,7 @@ export interface RequestOptions {
212
213
  }
213
214
 
214
215
  /** `string[]` is only for set-cookie, everything else must be type of `string` */
215
- export type ResponseHeaders = Record<string, string | number | string[]>;
216
+ export type ResponseHeaders = Record<string, string | number | string[] | null>;
216
217
 
217
218
  export interface RouteDefinition {
218
219
  id: string;
@@ -1,24 +0,0 @@
1
- import { client } from '../client/singletons.js';
2
-
3
- /**
4
- * @param {string} name
5
- */
6
- function guard(name) {
7
- return () => {
8
- throw new Error(`Cannot call ${name}(...) on the server`);
9
- };
10
- }
11
-
12
- const ssr = import.meta.env.SSR;
13
-
14
- const disableScrollHandling = ssr
15
- ? guard('disableScrollHandling')
16
- : client.disable_scroll_handling;
17
- const goto = ssr ? guard('goto') : client.goto;
18
- const invalidate = ssr ? guard('invalidate') : client.invalidate;
19
- const prefetch = ssr ? guard('prefetch') : client.prefetch;
20
- const prefetchRoutes = ssr ? guard('prefetchRoutes') : client.prefetch_routes;
21
- const beforeNavigate = ssr ? () => {} : client.before_navigate;
22
- const afterNavigate = ssr ? () => {} : client.after_navigate;
23
-
24
- export { afterNavigate, beforeNavigate, disableScrollHandling, goto, invalidate, prefetch, prefetchRoutes };
@@ -1 +0,0 @@
1
- export { assets, base } from '../paths.js';
@@ -1,29 +0,0 @@
1
- <script context="module">
2
- /** @type {import('@sveltejs/kit').Load} */
3
- export function load({ error, status }) {
4
- return {
5
- props: { error, status }
6
- };
7
- }
8
- </script>
9
-
10
- <script>
11
- /** @type {number} */
12
- export let status;
13
-
14
- /** @type {Error & {frame?: string} & {loc?: object}} */
15
- export let error;
16
- </script>
17
-
18
- <h1>{status}</h1>
19
-
20
- <pre>{error.message}</pre>
21
-
22
- <!-- TODO figure out what to do with frames/stacktraces in prod -->
23
- <!-- frame is populated by Svelte in its CompileError and is a Rollup/Vite convention -->
24
- {#if error.frame}
25
- <pre>{error.frame}</pre>
26
- {/if}
27
- {#if error.stack}
28
- <pre>{error.stack}</pre>
29
- {/if}
package/assets/env.js DELETED
@@ -1,8 +0,0 @@
1
- let prerendering = false;
2
-
3
- /** @param {boolean} value */
4
- function set_prerendering(value) {
5
- prerendering = value;
6
- }
7
-
8
- export { prerendering, set_prerendering };