@sveltejs/kit 1.0.0-next.235 → 1.0.0-next.239

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.
@@ -686,6 +686,12 @@ async function render_response({
686
686
 
687
687
  const inlined_style = Array.from(styles.values()).join('\n');
688
688
 
689
+ if (state.prerender) {
690
+ if (maxage) {
691
+ head += `<meta http-equiv="cache-control" content="max-age=${maxage}">`;
692
+ }
693
+ }
694
+
689
695
  if (options.amp) {
690
696
  head += `
691
697
  <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style>
@@ -1410,7 +1416,7 @@ async function respond$1(opts) {
1410
1416
  new Response(undefined, {
1411
1417
  status: loaded.loaded.status,
1412
1418
  headers: {
1413
- location: encodeURI(loaded.loaded.redirect)
1419
+ location: loaded.loaded.redirect
1414
1420
  }
1415
1421
  }),
1416
1422
  set_cookie_headers
@@ -6,8 +6,8 @@ import { c as coalesce_to_error, S as SVELTE_KIT_ASSETS, r as resolve_entry, $,
6
6
  import fs__default from 'fs';
7
7
  import { URL as URL$1 } from 'url';
8
8
  import { t as to_headers, s as sirv } from './http.js';
9
+ import { e as escape_html_attr, r as resolve, i as is_root_relative, a as escape_json_string_in_html } from './url.js';
9
10
  import { s } from './misc.js';
10
- import { r as resolve, i as is_root_relative } from './url.js';
11
11
  import { __fetch_polyfill } from '../install-fetch.js';
12
12
  import { getRawBody, setResponse } from '../node.js';
13
13
  import 'sade';
@@ -463,85 +463,6 @@ function writable(value, start = noop) {
463
463
  return { set, update, subscribe };
464
464
  }
465
465
 
466
- /** @type {Record<string, string>} */
467
- const escape_json_string_in_html_dict = {
468
- '"': '\\"',
469
- '<': '\\u003C',
470
- '>': '\\u003E',
471
- '/': '\\u002F',
472
- '\\': '\\\\',
473
- '\b': '\\b',
474
- '\f': '\\f',
475
- '\n': '\\n',
476
- '\r': '\\r',
477
- '\t': '\\t',
478
- '\0': '\\0',
479
- '\u2028': '\\u2028',
480
- '\u2029': '\\u2029'
481
- };
482
-
483
- /** @param {string} str */
484
- function escape_json_string_in_html(str) {
485
- return escape(
486
- str,
487
- escape_json_string_in_html_dict,
488
- (code) => `\\u${code.toString(16).toUpperCase()}`
489
- );
490
- }
491
-
492
- /** @type {Record<string, string>} */
493
- const escape_html_attr_dict = {
494
- '<': '&lt;',
495
- '>': '&gt;',
496
- '"': '&quot;'
497
- };
498
-
499
- /**
500
- * use for escaping string values to be used html attributes on the page
501
- * e.g.
502
- * <script data-url="here">
503
- *
504
- * @param {string} str
505
- * @returns string escaped string
506
- */
507
- function escape_html_attr(str) {
508
- return '"' + escape(str, escape_html_attr_dict, (code) => `&#${code};`) + '"';
509
- }
510
-
511
- /**
512
- *
513
- * @param str {string} string to escape
514
- * @param dict {Record<string, string>} dictionary of character replacements
515
- * @param unicode_encoder {function(number): string} encoder to use for high unicode characters
516
- * @returns {string}
517
- */
518
- function escape(str, dict, unicode_encoder) {
519
- let result = '';
520
-
521
- for (let i = 0; i < str.length; i += 1) {
522
- const char = str.charAt(i);
523
- const code = char.charCodeAt(0);
524
-
525
- if (char in dict) {
526
- result += dict[char];
527
- } else if (code >= 0xd800 && code <= 0xdfff) {
528
- const next = str.charCodeAt(i + 1);
529
-
530
- // If this is the beginning of a [high, low] surrogate pair,
531
- // add the next two characters, otherwise escape
532
- if (code <= 0xdbff && next >= 0xdc00 && next <= 0xdfff) {
533
- result += char + str[++i];
534
- } else {
535
- result += unicode_encoder(code);
536
- }
537
- } else {
538
- result += char;
539
- }
540
- }
541
-
542
- return result;
543
- }
544
-
545
466
  /** @param {URL} url */
546
467
  function create_prerendering_url_proxy(url) {
547
468
  return new Proxy(url, {
@@ -676,6 +597,12 @@ async function render_response({
676
597
 
677
598
  const inlined_style = Array.from(styles.values()).join('\n');
678
599
 
600
+ if (state.prerender) {
601
+ if (maxage) {
602
+ head += `<meta http-equiv="cache-control" content="max-age=${maxage}">`;
603
+ }
604
+ }
605
+
679
606
  if (options.amp) {
680
607
  head += `
681
608
  <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style>
@@ -1361,7 +1288,7 @@ async function respond$1(opts) {
1361
1288
  new Response(undefined, {
1362
1289
  status: loaded.loaded.status,
1363
1290
  headers: {
1364
- location: encodeURI(loaded.loaded.redirect)
1291
+ location: loaded.loaded.redirect
1365
1292
  }
1366
1293
  }),
1367
1294
  set_cookie_headers
@@ -3,7 +3,7 @@ import { readFileSync, writeFileSync } from 'fs';
3
3
  import { resolve, join, dirname } from 'path';
4
4
  import { pathToFileURL, URL } from 'url';
5
5
  import { __fetch_polyfill } from '../install-fetch.js';
6
- import { r as resolve$1, i as is_root_relative } from './url.js';
6
+ import { e as escape_html_attr, r as resolve$1, i as is_root_relative } from './url.js';
7
7
  import { g as generate_manifest } from './index4.js';
8
8
  import 'sade';
9
9
  import 'child_process';
@@ -441,7 +441,11 @@ async function prerender({ cwd, out, log, config, build_data, fallback, all }) {
441
441
  mkdirp(dirname(file));
442
442
 
443
443
  log.warn(`${rendered.status} ${decoded_path} -> ${location}`);
444
- writeFileSync(file, `<meta http-equiv="refresh" content="0;url=${encodeURI(location)}">`);
444
+
445
+ writeFileSync(
446
+ file,
447
+ `<meta http-equiv="refresh" content=${escape_html_attr(`0;url=${location}`)}>`
448
+ );
445
449
 
446
450
  const resolved = resolve$1(path, location);
447
451
  if (is_root_relative(resolved)) {
@@ -1,3 +1,82 @@
1
+ /** @type {Record<string, string>} */
2
+ const escape_json_string_in_html_dict = {
3
+ '"': '\\"',
4
+ '<': '\\u003C',
5
+ '>': '\\u003E',
6
+ '/': '\\u002F',
7
+ '\\': '\\\\',
8
+ '\b': '\\b',
9
+ '\f': '\\f',
10
+ '\n': '\\n',
11
+ '\r': '\\r',
12
+ '\t': '\\t',
13
+ '\0': '\\0',
14
+ '\u2028': '\\u2028',
15
+ '\u2029': '\\u2029'
16
+ };
17
+
18
+ /** @param {string} str */
19
+ function escape_json_string_in_html(str) {
20
+ return escape(
21
+ str,
22
+ escape_json_string_in_html_dict,
23
+ (code) => `\\u${code.toString(16).toUpperCase()}`
24
+ );
25
+ }
26
+
27
+ /** @type {Record<string, string>} */
28
+ const escape_html_attr_dict = {
29
+ '<': '&lt;',
30
+ '>': '&gt;',
31
+ '"': '&quot;'
32
+ };
33
+
34
+ /**
35
+ * use for escaping string values to be used html attributes on the page
36
+ * e.g.
37
+ * <script data-url="here">
38
+ *
39
+ * @param {string} str
40
+ * @returns string escaped string
41
+ */
42
+ function escape_html_attr(str) {
43
+ return '"' + escape(str, escape_html_attr_dict, (code) => `&#${code};`) + '"';
44
+ }
45
+
46
+ /**
47
+ *
48
+ * @param str {string} string to escape
49
+ * @param dict {Record<string, string>} dictionary of character replacements
50
+ * @param unicode_encoder {function(number): string} encoder to use for high unicode characters
51
+ * @returns {string}
52
+ */
53
+ function escape(str, dict, unicode_encoder) {
54
+ let result = '';
55
+
56
+ for (let i = 0; i < str.length; i += 1) {
57
+ const char = str.charAt(i);
58
+ const code = char.charCodeAt(0);
59
+
60
+ if (char in dict) {
61
+ result += dict[char];
62
+ } else if (code >= 0xd800 && code <= 0xdfff) {
63
+ const next = str.charCodeAt(i + 1);
64
+
65
+ // If this is the beginning of a [high, low] surrogate pair,
66
+ // add the next two characters, otherwise escape
67
+ if (code <= 0xdbff && next >= 0xdc00 && next <= 0xdfff) {
68
+ result += char + str[++i];
69
+ } else {
70
+ result += unicode_encoder(code);
71
+ }
72
+ } else {
73
+ result += char;
74
+ }
75
+ }
76
+
77
+ return result;
78
+ }
79
+
1
80
  const absolute = /^([a-z]+:)?\/?\//;
2
81
  const scheme = /^[a-z]+:/;
3
82
 
@@ -37,4 +116,4 @@ function is_root_relative(path) {
37
116
  return path[0] === '/' && path[1] !== '/';
38
117
  }
39
118
 
40
- export { is_root_relative as i, resolve as r };
119
+ export { escape_json_string_in_html as a, escape_html_attr as e, is_root_relative as i, resolve as r };
package/dist/cli.js CHANGED
@@ -933,7 +933,7 @@ async function launch(port, https) {
933
933
  exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}`);
934
934
  }
935
935
 
936
- const prog = sade('svelte-kit').version('1.0.0-next.235');
936
+ const prog = sade('svelte-kit').version('1.0.0-next.239');
937
937
 
938
938
  prog
939
939
  .command('dev')
@@ -1085,7 +1085,7 @@ async function check_port(port) {
1085
1085
  function welcome({ port, host, https, open, loose, allow, cwd }) {
1086
1086
  if (open) launch(port, https);
1087
1087
 
1088
- console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.235'}\n`));
1088
+ console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.239'}\n`));
1089
1089
 
1090
1090
  const protocol = https ? 'https:' : 'http:';
1091
1091
  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.235",
3
+ "version": "1.0.0-next.239",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -79,11 +79,13 @@
79
79
  "build": "rollup -c && node scripts/cp.js src/runtime/components assets/components",
80
80
  "dev": "rollup -cw",
81
81
  "lint": "eslint --ignore-path .gitignore --ignore-pattern \"src/packaging/test/**\" \"{src,test}/**/*.{ts,mjs,js,svelte}\" && npm run check-format",
82
- "check": "tsc && svelte-check --ignore \"src/packaging/test\"",
82
+ "check": "tsc && svelte-check --ignore test/prerendering,src/packaging/test",
83
83
  "format": "npm run check-format -- --write",
84
84
  "check-format": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore",
85
- "test": "npm run test:unit && npm run test:packaging && npm run test:integration",
85
+ "test": "npm run test:unit && npm run test:packaging && npm run test:prerendering && npm run test:integration",
86
86
  "test:unit": "uvu src \"(spec\\.js|test[\\\\/]index\\.js)\" -i packaging",
87
+ "test:prerendering": "pnpm test:prerendering:basics",
88
+ "test:prerendering:basics": "cd test/prerendering/basics && pnpm test",
87
89
  "test:packaging": "uvu src/packaging \"(spec\\.js|test[\\\\/]index\\.js)\"",
88
90
  "test:integration": "pnpm test:integration:amp && pnpm test:integration:basics && pnpm test:integration:options && pnpm test:integration:options-2",
89
91
  "test:integration:amp": "cd test/apps/amp && pnpm test",
@@ -195,5 +195,7 @@ declare module '@sveltejs/kit/node' {
195
195
  declare module '@sveltejs/kit/install-fetch' {
196
196
  import fetch, { Headers, Request, Response } from 'node-fetch';
197
197
 
198
+ export function __fetch_polyfill(): void;
199
+
198
200
  export { fetch, Headers, Request, Response };
199
201
  }
package/types/config.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { CompileOptions } from 'svelte/types/compiler/interfaces';
1
2
  import { UserConfig as ViteConfig } from 'vite';
2
3
  import { RecursiveRequired } from './helper';
3
4
  import { HttpMethod, Logger, RouteSegment, TrailingSlash } from './internal';
@@ -110,7 +111,7 @@ export interface PrerenderErrorHandler {
110
111
  export type PrerenderOnErrorValue = 'fail' | 'continue' | PrerenderErrorHandler;
111
112
 
112
113
  export interface Config {
113
- compilerOptions?: any;
114
+ compilerOptions?: CompileOptions;
114
115
  extensions?: string[];
115
116
  kit?: {
116
117
  adapter?: Adapter;
@@ -1,19 +1,18 @@
1
1
  import { RequestEvent } from './hooks';
2
- import { JSONString, MaybePromise, ResponseHeaders, Either, Fallthrough } from './helper';
2
+ import { Either, JSONString, MaybePromise, ResponseHeaders } from './helper';
3
3
 
4
- type DefaultBody = JSONString | Uint8Array;
4
+ type Body = JSONString | Uint8Array | ReadableStream | import('stream').Readable;
5
5
 
6
- export interface EndpointOutput<Body extends DefaultBody = DefaultBody> {
6
+ export interface EndpointOutput {
7
7
  status?: number;
8
8
  headers?: Headers | Partial<ResponseHeaders>;
9
9
  body?: Body;
10
10
  }
11
11
 
12
- export interface RequestHandler<
13
- Locals = Record<string, any>,
14
- Output extends DefaultBody = DefaultBody
15
- > {
16
- (request: RequestEvent<Locals>): MaybePromise<
17
- Either<Response | EndpointOutput<Output>, Fallthrough>
18
- >;
12
+ export interface Fallthrough {
13
+ fallthrough: true;
14
+ }
15
+
16
+ export interface RequestHandler<Locals = Record<string, any>> {
17
+ (event: RequestEvent<Locals>): MaybePromise<Either<Response | EndpointOutput, Fallthrough>>;
19
18
  }
package/types/helper.d.ts CHANGED
@@ -1,13 +1,3 @@
1
- interface ReadOnlyFormData {
2
- get(key: string): string | null;
3
- getAll(key: string): string[];
4
- has(key: string): boolean;
5
- entries(): Generator<[string, string], void>;
6
- keys(): Generator<string, void>;
7
- values(): Generator<string, void>;
8
- [Symbol.iterator](): Generator<[string, string], void>;
9
- }
10
-
11
1
  type ToJSON = { toJSON(...args: any[]): JSONValue };
12
2
  type JSONValue = Exclude<JSONString, ToJSON>;
13
3
  export type JSONString =
@@ -22,12 +12,14 @@ export type JSONString =
22
12
  /** `string[]` is only for set-cookie, everything else must be type of `string` */
23
13
  export type ResponseHeaders = Record<string, string | string[]>;
24
14
 
25
- // Utility Types
15
+ // <-- Utility Types -->
16
+ type Only<T, U> = { [P in keyof T]: T[P] } & { [P in keyof U]?: never };
17
+
18
+ export type Either<T, U> = Only<T, U> | Only<U, T>;
26
19
  export type InferValue<T, Key extends keyof T, Default> = T extends Record<Key, infer Val>
27
20
  ? Val
28
21
  : Default;
29
22
  export type MaybePromise<T> = T | Promise<T>;
30
- export type Rec<T = any> = Record<string, T>;
31
23
  export type RecursiveRequired<T> = {
32
24
  // Recursive implementation of TypeScript's Required utility type.
33
25
  // Will recursively continue until it reaches primitive or union
@@ -38,15 +30,3 @@ export type RecursiveRequired<T> = {
38
30
  ? Extract<T[K], Function> // only take the Function type.
39
31
  : T[K]; // Use the exact type for everything else
40
32
  };
41
-
42
- type Only<T, U> = {
43
- [P in keyof T]: T[P];
44
- } & {
45
- [P in keyof U]?: never;
46
- };
47
-
48
- export type Either<T, U> = Only<T, U> | Only<U, T>;
49
-
50
- export interface Fallthrough {
51
- fallthrough: true;
52
- }
@@ -1,11 +1,9 @@
1
1
  import { OutputAsset, OutputChunk } from 'rollup';
2
- import { RequestHandler } from './endpoint';
3
2
  import { InternalApp, SSRManifest } from './app';
3
+ import { Fallthrough, RequestHandler } from './endpoint';
4
+ import { Either } from './helper';
4
5
  import { ExternalFetch, GetSession, HandleError, InternalHandle, RequestEvent } from './hooks';
5
6
  import { Load } from './page';
6
- import { Either, Fallthrough } from './helper';
7
-
8
- type PageId = string;
9
7
 
10
8
  export interface PrerenderOptions {
11
9
  fallback?: string;
package/types/page.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- import { InferValue, MaybePromise, Rec, Either, Fallthrough } from './helper';
1
+ import { Fallthrough } from './endpoint';
2
+ import { Either, InferValue, MaybePromise } from './helper';
2
3
 
3
4
  export interface LoadInput<
4
- PageParams extends Rec<string> = Rec<string>,
5
- Stuff extends Rec = Rec,
5
+ PageParams extends Record<string, string> = Record<string, string>,
6
+ Stuff extends Record<string, any> = Record<string, any>,
6
7
  Session = any
7
8
  > {
8
9
  url: URL;
@@ -13,15 +14,18 @@ export interface LoadInput<
13
14
  }
14
15
 
15
16
  export interface ErrorLoadInput<
16
- PageParams extends Rec<string> = Rec<string>,
17
- Stuff extends Rec = Rec,
17
+ PageParams extends Record<string, string> = Record<string, string>,
18
+ Stuff extends Record<string, any> = Record<string, any>,
18
19
  Session = any
19
20
  > extends LoadInput<PageParams, Stuff, Session> {
20
21
  status?: number;
21
22
  error?: Error;
22
23
  }
23
24
 
24
- export interface LoadOutput<Props extends Rec = Rec, Stuff extends Rec = Rec> {
25
+ export interface LoadOutput<
26
+ Props extends Record<string, any> = Record<string, any>,
27
+ Stuff extends Record<string, any> = Record<string, any>
28
+ > {
25
29
  status?: number;
26
30
  error?: string | Error;
27
31
  redirect?: string;
@@ -31,14 +35,14 @@ export interface LoadOutput<Props extends Rec = Rec, Stuff extends Rec = Rec> {
31
35
  }
32
36
 
33
37
  interface LoadInputExtends {
34
- stuff?: Rec;
35
- pageParams?: Rec<string>;
38
+ stuff?: Record<string, any>;
39
+ pageParams?: Record<string, string>;
36
40
  session?: any;
37
41
  }
38
42
 
39
43
  interface LoadOutputExtends {
40
- stuff?: Rec;
41
- props?: Rec;
44
+ stuff?: Record<string, any>;
45
+ props?: Record<string, any>;
42
46
  }
43
47
 
44
48
  export interface Load<
@@ -47,14 +51,17 @@ export interface Load<
47
51
  > {
48
52
  (
49
53
  input: LoadInput<
50
- InferValue<Input, 'pageParams', Rec<string>>,
51
- InferValue<Input, 'stuff', Rec>,
54
+ InferValue<Input, 'pageParams', Record<string, string>>,
55
+ InferValue<Input, 'stuff', Record<string, any>>,
52
56
  InferValue<Input, 'session', any>
53
57
  >
54
58
  ): MaybePromise<
55
59
  Either<
56
- LoadOutput<InferValue<Output, 'props', Rec>, InferValue<Output, 'stuff', Rec>>,
57
- Fallthrough
60
+ Fallthrough,
61
+ LoadOutput<
62
+ InferValue<Output, 'props', Record<string, any>>,
63
+ InferValue<Output, 'stuff', Record<string, any>>
64
+ >
58
65
  >
59
66
  >;
60
67
  }
@@ -65,9 +72,14 @@ export interface ErrorLoad<
65
72
  > {
66
73
  (
67
74
  input: ErrorLoadInput<
68
- InferValue<Input, 'pageParams', Rec<string>>,
69
- InferValue<Input, 'stuff', Rec>,
75
+ InferValue<Input, 'pageParams', Record<string, string>>,
76
+ InferValue<Input, 'stuff', Record<string, any>>,
70
77
  InferValue<Input, 'session', any>
71
78
  >
72
- ): MaybePromise<LoadOutput<InferValue<Output, 'props', Rec>, InferValue<Output, 'stuff', Rec>>>;
79
+ ): MaybePromise<
80
+ LoadOutput<
81
+ InferValue<Output, 'props', Record<string, any>>,
82
+ InferValue<Output, 'stuff', Record<string, any>>
83
+ >
84
+ >;
73
85
  }