@sveltejs/kit 1.0.0-next.255 → 1.0.0-next.259

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.
@@ -1033,8 +1033,8 @@ const updated = {
1033
1033
  /**
1034
1034
  * @param {{
1035
1035
  * branch: Array<import('./types').Loaded>;
1036
- * options: import('types/internal').SSRRenderOptions;
1037
- * state: import('types/internal').SSRRenderState;
1036
+ * options: import('types/internal').SSROptions;
1037
+ * state: import('types/internal').SSRState;
1038
1038
  * $session: any;
1039
1039
  * page_config: { hydrate: boolean, router: boolean };
1040
1040
  * status: number;
@@ -1168,11 +1168,13 @@ async function render_response({
1168
1168
  needs_nonce: options.template_contains_nonce
1169
1169
  });
1170
1170
 
1171
+ const target = hash(body);
1172
+
1171
1173
  // prettier-ignore
1172
1174
  const init_app = `
1173
1175
  import { start } from ${s(options.prefix + options.manifest._.entry.file)};
1174
1176
  start({
1175
- target: ${options.target ? `document.querySelector(${s(options.target)})` : 'document.body'},
1177
+ target: document.querySelector('[data-hydrate="${target}"]').parentNode,
1176
1178
  paths: ${s(options.paths)},
1177
1179
  session: ${try_serialize($session, (error) => {
1178
1180
  throw new Error(`Failed to serialize session data: ${error.message}`);
@@ -1250,7 +1252,7 @@ async function render_response({
1250
1252
  .map((dep) => `\n\t<link rel="modulepreload" href="${options.prefix + dep}">`)
1251
1253
  .join('');
1252
1254
 
1253
- const attributes = ['type="module"'];
1255
+ const attributes = ['type="module"', `data-hydrate="${target}"`];
1254
1256
 
1255
1257
  csp.add_script(init_app);
1256
1258
 
@@ -1258,7 +1260,7 @@ async function render_response({
1258
1260
  attributes.push(`nonce="${csp.nonce}"`);
1259
1261
  }
1260
1262
 
1261
- head += `<script ${attributes.join(' ')}>${init_app}</script>`;
1263
+ body += `\n\t\t<script ${attributes.join(' ')}>${init_app}</script>`;
1262
1264
 
1263
1265
  // prettier-ignore
1264
1266
  body += serialized_data
@@ -1268,7 +1270,7 @@ async function render_response({
1268
1270
 
1269
1271
  return `<script ${attributes}>${json}</script>`;
1270
1272
  })
1271
- .join('\n\n\t');
1273
+ .join('\n\t');
1272
1274
  }
1273
1275
 
1274
1276
  if (options.service_worker) {
@@ -1465,8 +1467,8 @@ function is_root_relative(path) {
1465
1467
  /**
1466
1468
  * @param {{
1467
1469
  * event: import('types/hooks').RequestEvent;
1468
- * options: import('types/internal').SSRRenderOptions;
1469
- * state: import('types/internal').SSRRenderState;
1470
+ * options: import('types/internal').SSROptions;
1471
+ * state: import('types/internal').SSRState;
1470
1472
  * route: import('types/internal').SSRPage | null;
1471
1473
  * url: URL;
1472
1474
  * params: Record<string, string>;
@@ -1553,9 +1555,15 @@ async function load_node({
1553
1555
 
1554
1556
  // merge headers from request
1555
1557
  for (const [key, value] of event.request.headers) {
1556
- if (opts.headers.has(key)) continue;
1557
- if (key === 'cookie' || key === 'authorization' || key === 'if-none-match') continue;
1558
- opts.headers.set(key, value);
1558
+ if (
1559
+ key !== 'authorization' &&
1560
+ key !== 'cookie' &&
1561
+ key !== 'host' &&
1562
+ key !== 'if-none-match' &&
1563
+ !opts.headers.has(key)
1564
+ ) {
1565
+ opts.headers.set(key, value);
1566
+ }
1559
1567
  }
1560
1568
 
1561
1569
  opts.headers.set('referer', event.url.href);
@@ -1763,15 +1771,15 @@ async function load_node({
1763
1771
 
1764
1772
  /**
1765
1773
  * @typedef {import('./types.js').Loaded} Loaded
1766
- * @typedef {import('types/internal').SSRRenderOptions} SSRRenderOptions
1767
- * @typedef {import('types/internal').SSRRenderState} SSRRenderState
1774
+ * @typedef {import('types/internal').SSROptions} SSROptions
1775
+ * @typedef {import('types/internal').SSRState} SSRState
1768
1776
  */
1769
1777
 
1770
1778
  /**
1771
1779
  * @param {{
1772
1780
  * event: import('types/hooks').RequestEvent;
1773
- * options: SSRRenderOptions;
1774
- * state: SSRRenderState;
1781
+ * options: SSROptions;
1782
+ * state: SSRState;
1775
1783
  * $session: any;
1776
1784
  * status: number;
1777
1785
  * error: Error;
@@ -1848,15 +1856,15 @@ async function respond_with_error({ event, options, state, $session, status, err
1848
1856
  /**
1849
1857
  * @typedef {import('./types.js').Loaded} Loaded
1850
1858
  * @typedef {import('types/internal').SSRNode} SSRNode
1851
- * @typedef {import('types/internal').SSRRenderOptions} SSRRenderOptions
1852
- * @typedef {import('types/internal').SSRRenderState} SSRRenderState
1859
+ * @typedef {import('types/internal').SSROptions} SSROptions
1860
+ * @typedef {import('types/internal').SSRState} SSRState
1853
1861
  */
1854
1862
 
1855
1863
  /**
1856
1864
  * @param {{
1857
1865
  * event: import('types/hooks').RequestEvent;
1858
- * options: SSRRenderOptions;
1859
- * state: SSRRenderState;
1866
+ * options: SSROptions;
1867
+ * state: SSRState;
1860
1868
  * $session: any;
1861
1869
  * route: import('types/internal').SSRPage;
1862
1870
  * params: Record<string, string>;
@@ -2081,7 +2089,7 @@ async function respond$1(opts) {
2081
2089
 
2082
2090
  /**
2083
2091
  * @param {import('types/internal').SSRComponent} leaf
2084
- * @param {SSRRenderOptions} options
2092
+ * @param {SSROptions} options
2085
2093
  */
2086
2094
  function get_page_config(leaf, options) {
2087
2095
  // TODO remove for 1.0
@@ -2114,8 +2122,8 @@ function with_cookies(response, set_cookie_headers) {
2114
2122
  * @param {import('types/hooks').RequestEvent} event
2115
2123
  * @param {import('types/internal').SSRPage} route
2116
2124
  * @param {RegExpExecArray} match
2117
- * @param {import('types/internal').SSRRenderOptions} options
2118
- * @param {import('types/internal').SSRRenderState} state
2125
+ * @param {import('types/internal').SSROptions} options
2126
+ * @param {import('types/internal').SSRState} state
2119
2127
  * @param {boolean} ssr
2120
2128
  * @returns {Promise<Response | undefined>}
2121
2129
  */
@@ -2212,6 +2220,7 @@ async function respond(request, options, state = {}) {
2212
2220
  request,
2213
2221
  url,
2214
2222
  params: {},
2223
+ // @ts-expect-error this picks up types that belong to the tests
2215
2224
  locals: {},
2216
2225
  platform: state.platform
2217
2226
  };
@@ -185,6 +185,7 @@ async function create_plugin(config, cwd) {
185
185
 
186
186
  /** @type {import('types/internal').Hooks} */
187
187
  const hooks = {
188
+ // @ts-expect-error this picks up types that belong to the tests
188
189
  getSession: user_hooks.getSession || (() => ({})),
189
190
  handle: amp ? sequence(amp, handle) : handle,
190
191
  handleError:
@@ -271,7 +272,6 @@ async function create_plugin(config, cwd) {
271
272
  read: (file) => fs__default.readFileSync(path__default.join(config.kit.files.assets, file)),
272
273
  root,
273
274
  router: config.kit.browser.router,
274
- target: config.kit.target,
275
275
  template: ({ head, body, assets, nonce }) => {
276
276
  return (
277
277
  template
@@ -328,7 +328,6 @@ export class App {
328
328
  root,
329
329
  service_worker: ${has_service_worker ? "base + '/service-worker.js'" : 'null'},
330
330
  router: ${s(config.kit.browser.router)},
331
- target: ${s(config.kit.target)},
332
331
  template,
333
332
  template_contains_nonce: ${template.includes('%svelte.nonce%')},
334
333
  trailing_slash: ${s(config.kit.trailingSlash)}
@@ -161,7 +161,7 @@ function crawl(html) {
161
161
  if (html[i + 1] === '!') {
162
162
  i += 2;
163
163
 
164
- if (html.substring(i, DOCTYPE.length).toUpperCase() === DOCTYPE) {
164
+ if (html.substr(i, DOCTYPE.length).toUpperCase() === DOCTYPE) {
165
165
  i += DOCTYPE.length;
166
166
  while (i < html.length) {
167
167
  if (html[i++] === '>') {
@@ -171,10 +171,10 @@ function crawl(html) {
171
171
  }
172
172
 
173
173
  // skip cdata
174
- if (html.substring(i, CDATA_OPEN.length) === CDATA_OPEN) {
174
+ if (html.substr(i, CDATA_OPEN.length) === CDATA_OPEN) {
175
175
  i += CDATA_OPEN.length;
176
176
  while (i < html.length) {
177
- if (html.substring(i, CDATA_CLOSE.length) === CDATA_CLOSE) {
177
+ if (html.substr(i, CDATA_CLOSE.length) === CDATA_CLOSE) {
178
178
  i += CDATA_CLOSE.length;
179
179
  continue main;
180
180
  }
@@ -184,10 +184,10 @@ function crawl(html) {
184
184
  }
185
185
 
186
186
  // skip comments
187
- if (html.substring(i, COMMENT_OPEN.length) === COMMENT_OPEN) {
187
+ if (html.substr(i, COMMENT_OPEN.length) === COMMENT_OPEN) {
188
188
  i += COMMENT_OPEN.length;
189
189
  while (i < html.length) {
190
- if (html.substring(i, COMMENT_CLOSE.length) === COMMENT_CLOSE) {
190
+ if (html.substr(i, COMMENT_CLOSE.length) === COMMENT_CLOSE) {
191
191
  i += COMMENT_CLOSE.length;
192
192
  continue main;
193
193
  }
@@ -215,7 +215,7 @@ function crawl(html) {
215
215
  if (
216
216
  html[i] === '<' &&
217
217
  html[i + 1] === '/' &&
218
- html.substring(i + 2, tag.length).toUpperCase() === tag
218
+ html.substr(i + 2, tag.length).toUpperCase() === tag
219
219
  ) {
220
220
  continue main;
221
221
  }
package/dist/cli.js CHANGED
@@ -684,7 +684,8 @@ const options = object(
684
684
  `${keypath} has been removed — use the handle hook instead: https://kit.svelte.dev/docs#hooks-handle'`
685
685
  ),
686
686
 
687
- target: string(null),
687
+ // TODO remove this for 1.0
688
+ target: error((keypath) => `${keypath} is no longer required, and should be removed`),
688
689
 
689
690
  trailingSlash: list(['never', 'always', 'ignore']),
690
691
 
@@ -994,7 +995,7 @@ async function launch(port, https) {
994
995
  exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}`);
995
996
  }
996
997
 
997
- const prog = sade('svelte-kit').version('1.0.0-next.255');
998
+ const prog = sade('svelte-kit').version('1.0.0-next.259');
998
999
 
999
1000
  prog
1000
1001
  .command('dev')
@@ -1152,7 +1153,7 @@ async function check_port(port) {
1152
1153
  function welcome({ port, host, https, open, loose, allow, cwd }) {
1153
1154
  if (open) launch(port, https);
1154
1155
 
1155
- console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.255'}\n`));
1156
+ console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.259'}\n`));
1156
1157
 
1157
1158
  const protocol = https ? 'https:' : 'http:';
1158
1159
  const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.255",
3
+ "version": "1.0.0-next.259",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -1,5 +1,12 @@
1
1
  /* eslint-disable import/no-duplicates */
2
2
 
3
+ declare namespace App {
4
+ interface Locals {}
5
+ interface Platform {}
6
+ interface Session {}
7
+ interface Stuff {}
8
+ }
9
+
3
10
  declare module '$app/env' {
4
11
  /**
5
12
  * Whether or not app is in AMP mode.
@@ -106,10 +113,10 @@ declare module '$app/stores' {
106
113
  * A convenience function around `getContext` that returns `{ navigating, page, session }`.
107
114
  * Most of the time, you won't need to use it.
108
115
  */
109
- export function getStores<Session = any>(): {
116
+ export function getStores(): {
110
117
  navigating: typeof navigating;
111
118
  page: typeof page;
112
- session: Writable<Session>;
119
+ session: Writable<App.Session>;
113
120
  updated: typeof updated;
114
121
  };
115
122
  /**
@@ -118,7 +125,7 @@ declare module '$app/stores' {
118
125
  export const page: Readable<{
119
126
  url: URL;
120
127
  params: Record<string, string>;
121
- stuff: Record<string, any>;
128
+ stuff: App.Stuff;
122
129
  status: number;
123
130
  error: Error | null;
124
131
  }>;
@@ -132,7 +139,7 @@ declare module '$app/stores' {
132
139
  * A writable store whose initial value is whatever was returned from `getSession`.
133
140
  * It can be written to, but this will not cause changes to persist on the server — this is something you must implement yourself.
134
141
  */
135
- export const session: Writable<any>;
142
+ export const session: Writable<App.Session>;
136
143
  /**
137
144
  * A writable store indicating if the site was updated since the store was created.
138
145
  * It can be written to when custom logic is required to detect updates.
package/types/config.d.ts CHANGED
@@ -163,7 +163,6 @@ export interface Config {
163
163
  register?: boolean;
164
164
  files?: (filepath: string) => boolean;
165
165
  };
166
- target?: string;
167
166
  trailingSlash?: TrailingSlash;
168
167
  version?: {
169
168
  name?: string;
@@ -1,7 +1,7 @@
1
1
  import { RequestEvent } from './hooks';
2
- import { Either, JSONString, MaybePromise, ResponseHeaders } from './helper';
2
+ import { Either, JSONValue, MaybePromise, ResponseHeaders } from './helper';
3
3
 
4
- type Body = JSONString | Uint8Array | ReadableStream | import('stream').Readable;
4
+ type Body = JSONValue | Uint8Array | ReadableStream | import('stream').Readable;
5
5
 
6
6
  export interface EndpointOutput<Output extends Body = Body> {
7
7
  status?: number;
@@ -13,12 +13,6 @@ export interface Fallthrough {
13
13
  fallthrough: true;
14
14
  }
15
15
 
16
- export interface RequestHandler<
17
- Locals = Record<string, any>,
18
- Platform = Record<string, any>,
19
- Output extends Body = Body
20
- > {
21
- (event: RequestEvent<Locals, Platform>): MaybePromise<
22
- Either<Response | EndpointOutput<Output>, Fallthrough>
23
- >;
16
+ export interface RequestHandler<Output extends Body = Body> {
17
+ (event: RequestEvent): MaybePromise<Either<Response | EndpointOutput<Output>, Fallthrough>>;
24
18
  }
package/types/helper.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- type ToJSON = { toJSON(...args: any[]): JSONValue };
2
- type JSONValue = Exclude<JSONString, ToJSON>;
3
- export type JSONString =
1
+ type ToJSON = { toJSON(...args: any[]): Exclude<JSONValue, ToJSON> };
2
+
3
+ export type JSONValue =
4
4
  | string
5
5
  | number
6
6
  | boolean
7
7
  | null
8
8
  | ToJSON
9
- | JSONString[]
10
- | { [key: string]: JSONString };
9
+ | JSONValue[]
10
+ | { [key: string]: JSONValue };
11
11
 
12
12
  /** `string[]` is only for set-cookie, everything else must be type of `string` */
13
13
  export type ResponseHeaders = Record<string, string | string[]>;
@@ -16,9 +16,6 @@ export type ResponseHeaders = Record<string, string | string[]>;
16
16
  type Only<T, U> = { [P in keyof T]: T[P] } & { [P in Exclude<keyof U, keyof T>]?: never };
17
17
 
18
18
  export type Either<T, U> = Only<T, U> | Only<U, T>;
19
- export type InferValue<T, Key extends keyof T, Default> = T extends Record<Key, infer Val>
20
- ? Val
21
- : Default;
22
19
  export type MaybePromise<T> = T | Promise<T>;
23
20
  export type RecursiveRequired<T> = {
24
21
  // Recursive implementation of TypeScript's Required utility type.
package/types/hooks.d.ts CHANGED
@@ -2,35 +2,31 @@ import { MaybePromise } from './helper';
2
2
 
3
3
  export type StrictBody = string | Uint8Array;
4
4
 
5
- export interface RequestEvent<Locals = Record<string, any>, Platform = Record<string, any>> {
5
+ export interface RequestEvent {
6
6
  request: Request;
7
7
  url: URL;
8
8
  params: Record<string, string>;
9
- locals: Locals;
10
- platform: Readonly<Platform>;
9
+ locals: App.Locals;
10
+ platform: Readonly<App.Platform>;
11
11
  }
12
12
 
13
- export interface GetSession<
14
- Locals = Record<string, any>,
15
- Platform = Record<string, any>,
16
- Session = any
17
- > {
18
- (event: RequestEvent<Locals, Platform>): MaybePromise<Session>;
13
+ export interface GetSession {
14
+ (event: RequestEvent): MaybePromise<App.Session>;
19
15
  }
20
16
 
21
17
  export interface ResolveOpts {
22
18
  ssr?: boolean;
23
19
  }
24
20
 
25
- export interface Handle<Locals = Record<string, any>, Platform = Record<string, any>> {
21
+ export interface Handle {
26
22
  (input: {
27
- event: RequestEvent<Locals, Platform>;
28
- resolve(event: RequestEvent<Locals, Platform>, opts?: ResolveOpts): MaybePromise<Response>;
23
+ event: RequestEvent;
24
+ resolve(event: RequestEvent, opts?: ResolveOpts): MaybePromise<Response>;
29
25
  }): MaybePromise<Response>;
30
26
  }
31
27
 
32
- export interface HandleError<Locals = Record<string, any>> {
33
- (input: { error: Error & { frame?: string }; event: RequestEvent<Locals> }): void;
28
+ export interface HandleError {
29
+ (input: { error: Error & { frame?: string }; event: RequestEvent }): void;
34
30
  }
35
31
 
36
32
  export interface ExternalFetch {
@@ -119,7 +119,7 @@ export interface SSRNode {
119
119
  styles?: Record<string, string>;
120
120
  }
121
121
 
122
- export interface SSRRenderOptions {
122
+ export interface SSROptions {
123
123
  amp: boolean;
124
124
  csp: ValidatedConfig['kit']['csp'];
125
125
  dev: boolean;
@@ -140,7 +140,6 @@ export interface SSRRenderOptions {
140
140
  root: SSRComponent['default'];
141
141
  router: boolean;
142
142
  service_worker?: string;
143
- target: string;
144
143
  template({
145
144
  head,
146
145
  body,
@@ -156,7 +155,7 @@ export interface SSRRenderOptions {
156
155
  trailing_slash: TrailingSlash;
157
156
  }
158
157
 
159
- export interface SSRRenderState {
158
+ export interface SSRState {
160
159
  fetched?: string;
161
160
  initiator?: SSRPage | null;
162
161
  platform?: any;
@@ -248,5 +247,5 @@ export interface MethodOverride {
248
247
  }
249
248
 
250
249
  export interface Respond {
251
- (request: Request, options: SSRRenderOptions, state?: SSRRenderState): Promise<Response>;
250
+ (request: Request, options: SSROptions, state?: SSRState): Promise<Response>;
252
251
  }
package/types/page.d.ts CHANGED
@@ -1,85 +1,32 @@
1
1
  import { Fallthrough } from './endpoint';
2
- import { Either, InferValue, MaybePromise } from './helper';
2
+ import { Either, MaybePromise } from './helper';
3
3
 
4
- export interface LoadInput<
5
- PageParams extends Record<string, string> = Record<string, string>,
6
- Stuff extends Record<string, any> = Record<string, any>,
7
- Session = any
8
- > {
4
+ export interface LoadInput<Params = Record<string, string>> {
9
5
  url: URL;
10
- params: PageParams;
6
+ params: Params;
11
7
  fetch(info: RequestInfo, init?: RequestInit): Promise<Response>;
12
- session: Session;
13
- stuff: Stuff;
8
+ session: App.Session;
9
+ stuff: Partial<App.Stuff>;
14
10
  }
15
11
 
16
- export interface ErrorLoadInput<
17
- PageParams extends Record<string, string> = Record<string, string>,
18
- Stuff extends Record<string, any> = Record<string, any>,
19
- Session = any
20
- > extends LoadInput<PageParams, Stuff, Session> {
12
+ export interface ErrorLoadInput<Params = Record<string, string>> extends LoadInput<Params> {
21
13
  status?: number;
22
14
  error?: Error;
23
15
  }
24
16
 
25
- export interface LoadOutput<
26
- Props extends Record<string, any> = Record<string, any>,
27
- Stuff extends Record<string, any> = Record<string, any>
28
- > {
17
+ export interface LoadOutput<Props = Record<string, any>> {
29
18
  status?: number;
30
19
  error?: string | Error;
31
20
  redirect?: string;
32
21
  props?: Props;
33
- stuff?: Stuff;
22
+ stuff?: Partial<App.Stuff>;
34
23
  maxage?: number;
35
24
  }
36
25
 
37
- interface LoadInputExtends {
38
- stuff?: Record<string, any>;
39
- pageParams?: Record<string, string>;
40
- session?: any;
26
+ export interface Load<Params = Record<string, string>, Props = Record<string, any>> {
27
+ (input: LoadInput<Params>): MaybePromise<Either<Fallthrough, LoadOutput<Props>>>;
41
28
  }
42
29
 
43
- interface LoadOutputExtends {
44
- stuff?: Record<string, any>;
45
- props?: Record<string, any>;
46
- }
47
-
48
- export interface Load<
49
- Input extends LoadInputExtends = Required<LoadInputExtends>,
50
- Output extends LoadOutputExtends = Required<LoadOutputExtends>
51
- > {
52
- (
53
- input: LoadInput<
54
- InferValue<Input, 'pageParams', Record<string, string>>,
55
- InferValue<Input, 'stuff', Record<string, any>>,
56
- InferValue<Input, 'session', any>
57
- >
58
- ): MaybePromise<
59
- Either<
60
- Fallthrough,
61
- LoadOutput<
62
- InferValue<Output, 'props', Record<string, any>>,
63
- InferValue<Output, 'stuff', Record<string, any>>
64
- >
65
- >
66
- >;
67
- }
68
-
69
- export interface ErrorLoad<
70
- Input extends LoadInputExtends = Required<LoadInputExtends>,
71
- Output extends LoadOutputExtends = Required<LoadOutputExtends>
72
- > {
73
- (
74
- input: ErrorLoadInput<
75
- InferValue<Input, 'pageParams', Record<string, string>>,
76
- InferValue<Input, 'stuff', Record<string, any>>,
77
- InferValue<Input, 'session', any>
78
- >
79
- ): MaybePromise<
80
- LoadOutput<
81
- InferValue<Output, 'props', Record<string, any>>,
82
- InferValue<Output, 'stuff', Record<string, any>>
83
- >
84
- >;
30
+ export interface ErrorLoad<Params = Record<string, string>, Props = Record<string, any>> {
31
+ (input: ErrorLoadInput<Params>): MaybePromise<LoadOutput<Props>>;
85
32
  }