@sveltejs/kit 1.0.0-next.310 → 1.0.0-next.314

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/README.md CHANGED
@@ -5,7 +5,7 @@ This is the [SvelteKit](https://kit.svelte.dev) framework and CLI.
5
5
  The quickest way to get started is via the [create-svelte](https://github.com/sveltejs/kit/tree/master/packages/create-svelte) package:
6
6
 
7
7
  ```bash
8
- npm init svelte@next my-app
8
+ npm init svelte my-app
9
9
  cd my-app
10
10
  npm install
11
11
  npm run dev
@@ -27,10 +27,7 @@ function normalize(loaded) {
27
27
  const status = loaded.status;
28
28
 
29
29
  if (!loaded.error && has_error_status) {
30
- return {
31
- status: status || 500,
32
- error: new Error()
33
- };
30
+ return { status: status || 500, error: new Error() };
34
31
  }
35
32
 
36
33
  const error = typeof loaded.error === 'string' ? new Error(loaded.error) : loaded.error;
@@ -70,6 +67,18 @@ function normalize(loaded) {
70
67
  }
71
68
  }
72
69
 
70
+ if (loaded.dependencies) {
71
+ if (
72
+ !Array.isArray(loaded.dependencies) ||
73
+ loaded.dependencies.some((dep) => typeof dep !== 'string')
74
+ ) {
75
+ return {
76
+ status: 500,
77
+ error: new Error('"dependencies" property returned from load() must be of type string[]')
78
+ };
79
+ }
80
+ }
81
+
73
82
  // TODO remove before 1.0
74
83
  if (/** @type {any} */ (loaded).context) {
75
84
  throw new Error(
@@ -839,6 +848,12 @@ function create_client({ target, session, base, trailing_slash }) {
839
848
  stuff
840
849
  };
841
850
 
851
+ /** @param dep {string} */
852
+ function add_dependency(dep) {
853
+ const { href } = new URL(dep, url);
854
+ node.uses.dependencies.add(href);
855
+ }
856
+
842
857
  if (props) {
843
858
  // shadow endpoint props means we need to mark this URL as a dependency of itself
844
859
  node.uses.dependencies.add(url.href);
@@ -859,7 +874,7 @@ function create_client({ target, session, base, trailing_slash }) {
859
874
  const session = $session;
860
875
 
861
876
  if (module.load) {
862
- /** @type {import('types').LoadInput | import('types').ErrorLoadInput} */
877
+ /** @type {import('types').LoadInput} */
863
878
  const load_input = {
864
879
  routeId,
865
880
  params: uses_params,
@@ -878,11 +893,12 @@ function create_client({ target, session, base, trailing_slash }) {
878
893
  },
879
894
  fetch(resource, info) {
880
895
  const requested = typeof resource === 'string' ? resource : resource.url;
881
- const { href } = new URL(requested, url);
882
- node.uses.dependencies.add(href);
896
+ add_dependency(requested);
883
897
 
884
898
  return started ? fetch(resource, info) : initial_fetch(resource, info);
885
- }
899
+ },
900
+ status: status ?? null,
901
+ error: error ?? null
886
902
  };
887
903
 
888
904
  if (import.meta.env.DEV) {
@@ -894,11 +910,6 @@ function create_client({ target, session, base, trailing_slash }) {
894
910
  });
895
911
  }
896
912
 
897
- if (error) {
898
- /** @type {import('types').ErrorLoadInput} */ (load_input).status = status;
899
- /** @type {import('types').ErrorLoadInput} */ (load_input).error = error;
900
- }
901
-
902
913
  const loaded = await module.load.call(null, load_input);
903
914
 
904
915
  if (!loaded) {
@@ -907,6 +918,9 @@ function create_client({ target, session, base, trailing_slash }) {
907
918
 
908
919
  node.loaded = normalize(loaded);
909
920
  if (node.loaded.stuff) node.stuff = node.loaded.stuff;
921
+ if (node.loaded.dependencies) {
922
+ node.loaded.dependencies.forEach(add_dependency);
923
+ }
910
924
  } else if (props) {
911
925
  node.loaded = normalize({ props });
912
926
  }
@@ -1433,7 +1447,11 @@ function create_client({ target, session, base, trailing_slash }) {
1433
1447
  // 2. 'rel' attribute includes external
1434
1448
  const rel = (a.getAttribute('rel') || '').split(/\s+/);
1435
1449
 
1436
- if (a.hasAttribute('download') || rel.includes('external')) {
1450
+ if (
1451
+ a.hasAttribute('download') ||
1452
+ rel.includes('external') ||
1453
+ a.hasAttribute('sveltekit:reload')
1454
+ ) {
1437
1455
  return;
1438
1456
  }
1439
1457
 
@@ -1435,10 +1435,7 @@ function normalize(loaded) {
1435
1435
  const status = loaded.status;
1436
1436
 
1437
1437
  if (!loaded.error && has_error_status) {
1438
- return {
1439
- status: status || 500,
1440
- error: new Error()
1441
- };
1438
+ return { status: status || 500, error: new Error() };
1442
1439
  }
1443
1440
 
1444
1441
  const error = typeof loaded.error === 'string' ? new Error(loaded.error) : loaded.error;
@@ -1478,6 +1475,18 @@ function normalize(loaded) {
1478
1475
  }
1479
1476
  }
1480
1477
 
1478
+ if (loaded.dependencies) {
1479
+ if (
1480
+ !Array.isArray(loaded.dependencies) ||
1481
+ loaded.dependencies.some((dep) => typeof dep !== 'string')
1482
+ ) {
1483
+ return {
1484
+ status: 500,
1485
+ error: new Error('"dependencies" property returned from load() must be of type string[]')
1486
+ };
1487
+ }
1488
+ }
1489
+
1481
1490
  // TODO remove before 1.0
1482
1491
  if (/** @type {any} */ (loaded).context) {
1483
1492
  throw new Error(
@@ -1613,7 +1622,7 @@ async function load_node({
1613
1622
  redirect: shadow.redirect
1614
1623
  };
1615
1624
  } else if (module.load) {
1616
- /** @type {import('types').LoadInput | import('types').ErrorLoadInput} */
1625
+ /** @type {import('types').LoadInput} */
1617
1626
  const load_input = {
1618
1627
  url: state.prerender ? create_prerendering_url_proxy(event.url) : event.url,
1619
1628
  params: event.params,
@@ -1732,9 +1741,8 @@ async function load_node({
1732
1741
  new Request(new URL(requested, event.url).href, { ...opts, credentials: undefined }),
1733
1742
  options,
1734
1743
  {
1735
- getClientAddress: state.getClientAddress,
1736
- initiator: route,
1737
- prerender: state.prerender
1744
+ ...state,
1745
+ initiator: route
1738
1746
  }
1739
1747
  );
1740
1748
 
@@ -1848,7 +1856,9 @@ async function load_node({
1848
1856
 
1849
1857
  return proxy;
1850
1858
  },
1851
- stuff: { ...stuff }
1859
+ stuff: { ...stuff },
1860
+ status: is_error ? status ?? null : null,
1861
+ error: is_error ? error ?? null : null
1852
1862
  };
1853
1863
 
1854
1864
  if (options.dev) {
@@ -1860,11 +1870,6 @@ async function load_node({
1860
1870
  });
1861
1871
  }
1862
1872
 
1863
- if (is_error) {
1864
- /** @type {import('types').ErrorLoadInput} */ (load_input).status = status;
1865
- /** @type {import('types').ErrorLoadInput} */ (load_input).error = error;
1866
- }
1867
-
1868
1873
  loaded = await module.load.call(null, load_input);
1869
1874
 
1870
1875
  if (!loaded) {
@@ -778,6 +778,7 @@ function crawl(html) {
778
778
  }
779
779
 
780
780
  let href = '';
781
+ let rel = '';
781
782
 
782
783
  while (i < html.length) {
783
784
  const start = i;
@@ -839,6 +840,8 @@ function crawl(html) {
839
840
 
840
841
  if (name === 'href') {
841
842
  href = value;
843
+ } else if (name === 'rel') {
844
+ rel = value;
842
845
  } else if (name === 'src') {
843
846
  hrefs.push(value);
844
847
  } else if (name === 'srcset') {
@@ -869,7 +872,7 @@ function crawl(html) {
869
872
  i += 1;
870
873
  }
871
874
 
872
- if (href) {
875
+ if (href && !/\bexternal\b/i.test(rel)) {
873
876
  hrefs.push(href);
874
877
  }
875
878
  }
@@ -1004,6 +1007,10 @@ async function prerender({ config, entries, files, log }) {
1004
1007
  paths: []
1005
1008
  };
1006
1009
 
1010
+ if (!config.kit.prerender.enabled) {
1011
+ return prerendered;
1012
+ }
1013
+
1007
1014
  installFetch();
1008
1015
 
1009
1016
  const server_root = join(config.kit.outDir, 'output');
@@ -1020,23 +1027,6 @@ async function prerender({ config, entries, files, log }) {
1020
1027
 
1021
1028
  const server = new Server(manifest);
1022
1029
 
1023
- const rendered = await server.respond(new Request('http://sveltekit-prerender/[fallback]'), {
1024
- getClientAddress,
1025
- prerender: {
1026
- fallback: true,
1027
- default: false,
1028
- dependencies: new Map()
1029
- }
1030
- });
1031
-
1032
- const file = `${config.kit.outDir}/output/prerendered/fallback.html`;
1033
- mkdirp(dirname(file));
1034
- writeFileSync(file, await rendered.text());
1035
-
1036
- if (!config.kit.prerender.enabled) {
1037
- return prerendered;
1038
- }
1039
-
1040
1030
  const error = normalise_error_handler(log, config.kit.prerender.onError);
1041
1031
 
1042
1032
  const q = queue(config.kit.prerender.concurrency);
@@ -1228,6 +1218,19 @@ async function prerender({ config, entries, files, log }) {
1228
1218
  await q.done();
1229
1219
  }
1230
1220
 
1221
+ const rendered = await server.respond(new Request('http://sveltekit-prerender/[fallback]'), {
1222
+ getClientAddress,
1223
+ prerender: {
1224
+ fallback: true,
1225
+ default: false,
1226
+ dependencies: new Map()
1227
+ }
1228
+ });
1229
+
1230
+ const file = `${config.kit.outDir}/output/prerendered/fallback.html`;
1231
+ mkdirp(dirname(file));
1232
+ writeFileSync(file, await rendered.text());
1233
+
1231
1234
  return prerendered;
1232
1235
  }
1233
1236
 
package/dist/cli.js CHANGED
@@ -870,7 +870,7 @@ async function launch(port, https, base) {
870
870
  exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}${base}`);
871
871
  }
872
872
 
873
- const prog = sade('svelte-kit').version('1.0.0-next.310');
873
+ const prog = sade('svelte-kit').version('1.0.0-next.314');
874
874
 
875
875
  prog
876
876
  .command('dev')
@@ -1049,7 +1049,7 @@ async function check_port(port) {
1049
1049
  function welcome({ port, host, https, open, base, loose, allow, cwd }) {
1050
1050
  if (open) launch(port, https, base);
1051
1051
 
1052
- console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.310'}\n`));
1052
+ console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.314'}\n`));
1053
1053
 
1054
1054
  const protocol = https ? 'https:' : 'http:';
1055
1055
  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.310",
3
+ "version": "1.0.0-next.314",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -15,16 +15,16 @@
15
15
  "vite": "^2.9.0"
16
16
  },
17
17
  "devDependencies": {
18
- "@playwright/test": "^1.20.2",
18
+ "@playwright/test": "^1.21.0",
19
19
  "@rollup/plugin-replace": "^4.0.0",
20
20
  "@types/amphtml-validator": "^1.0.1",
21
- "@types/cookie": "^0.4.1",
21
+ "@types/cookie": "^0.5.0",
22
22
  "@types/marked": "^4.0.1",
23
23
  "@types/mime": "^2.0.3",
24
24
  "@types/node": "^16.11.11",
25
25
  "@types/sade": "^1.7.3",
26
26
  "amphtml-validator": "^1.0.35",
27
- "cookie": "^0.4.1",
27
+ "cookie": "^0.5.0",
28
28
  "cross-env": "^7.0.3",
29
29
  "devalue": "^2.0.1",
30
30
  "eslint": "^8.3.0",
@@ -38,7 +38,7 @@
38
38
  "selfsigned": "^2.0.0",
39
39
  "sirv": "^2.0.0",
40
40
  "svelte": "^3.44.2",
41
- "svelte-check": "^2.2.10",
41
+ "svelte-check": "^2.5.0",
42
42
  "svelte-preprocess": "^4.9.8",
43
43
  "svelte2tsx": "~0.5.0",
44
44
  "tiny-glob": "^0.2.9",
@@ -83,8 +83,8 @@
83
83
  "check:all": "tsc && pnpm run -r check --filter ./",
84
84
  "format": "npm run check-format -- --write",
85
85
  "check-format": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore",
86
- "test": "npm run test:unit && npm run test:typings && npm run test:packaging",
87
- "test:all": "pnpm run -r test --workspace-concurrency 1 --filter ./",
86
+ "test": "npm run test:unit && npm run test:typings && npm run test:packaging && npm run test:integration",
87
+ "test:integration": "pnpm run -r test --workspace-concurrency 1 --filter ./test",
88
88
  "test:unit": "uvu src \"(spec\\.js|test[\\\\/]index\\.js)\" -i packaging",
89
89
  "test:typings": "tsc --project test/typings",
90
90
  "test:packaging": "uvu src/packaging \"(spec\\.js|test[\\\\/]index\\.js)\"",
package/types/index.d.ts CHANGED
@@ -7,10 +7,7 @@ import { CompileOptions } from 'svelte/types/compiler/interfaces';
7
7
  import {
8
8
  AdapterEntry,
9
9
  CspDirectives,
10
- ErrorLoadInput,
11
10
  JSONValue,
12
- LoadInput,
13
- LoadOutput,
14
11
  Logger,
15
12
  MaybePromise,
16
13
  Prerendered,
@@ -157,13 +154,6 @@ export interface Config {
157
154
  preprocess?: any;
158
155
  }
159
156
 
160
- export interface ErrorLoad<
161
- Params extends Record<string, string> = Record<string, string>,
162
- Props extends Record<string, any> = Record<string, any>
163
- > {
164
- (input: ErrorLoadInput<Params>): MaybePromise<LoadOutput<Props>>;
165
- }
166
-
167
157
  export interface ExternalFetch {
168
158
  (req: Request): Promise<Response>;
169
159
  }
@@ -196,6 +186,31 @@ export interface Load<
196
186
  (input: LoadInput<Params, InputProps>): MaybePromise<LoadOutput<OutputProps>>;
197
187
  }
198
188
 
189
+ export interface LoadInput<
190
+ Params extends Record<string, string> = Record<string, string>,
191
+ Props extends Record<string, any> = Record<string, any>
192
+ > {
193
+ fetch(info: RequestInfo, init?: RequestInit): Promise<Response>;
194
+ params: Params;
195
+ props: Props;
196
+ routeId: string | null;
197
+ session: App.Session;
198
+ stuff: Partial<App.Stuff>;
199
+ url: URL;
200
+ status: number | null;
201
+ error: Error | null;
202
+ }
203
+
204
+ export interface LoadOutput<Props extends Record<string, any> = Record<string, any>> {
205
+ status?: number;
206
+ error?: string | Error;
207
+ redirect?: string;
208
+ props?: Props;
209
+ stuff?: Partial<App.Stuff>;
210
+ maxage?: number;
211
+ dependencies?: string[];
212
+ }
213
+
199
214
  export interface Navigation {
200
215
  from: URL;
201
216
  to: URL;
@@ -118,6 +118,7 @@ export type NormalizedLoadOutput = {
118
118
  props?: Record<string, any> | Promise<Record<string, any>>;
119
119
  stuff?: Record<string, any>;
120
120
  maxage?: number;
121
+ dependencies?: string[];
121
122
  };
122
123
 
123
124
  export interface PageData {
@@ -134,12 +134,6 @@ export interface CspDirectives {
134
134
  >;
135
135
  }
136
136
 
137
- export interface ErrorLoadInput<Params extends Record<string, string> = Record<string, string>>
138
- extends LoadInput<Params> {
139
- status?: number;
140
- error?: Error;
141
- }
142
-
143
137
  export type HttpMethod = 'get' | 'head' | 'post' | 'put' | 'delete' | 'patch';
144
138
 
145
139
  export interface JSONObject {
@@ -156,28 +150,6 @@ export type JSONValue =
156
150
  | JSONValue[]
157
151
  | JSONObject;
158
152
 
159
- export interface LoadInput<
160
- Params extends Record<string, string> = Record<string, string>,
161
- Props extends Record<string, any> = Record<string, any>
162
- > {
163
- fetch(info: RequestInfo, init?: RequestInit): Promise<Response>;
164
- params: Params;
165
- props: Props;
166
- routeId: string | null;
167
- session: App.Session;
168
- stuff: Partial<App.Stuff>;
169
- url: URL;
170
- }
171
-
172
- export interface LoadOutput<Props extends Record<string, any> = Record<string, any>> {
173
- status?: number;
174
- error?: string | Error;
175
- redirect?: string;
176
- props?: Props;
177
- stuff?: Partial<App.Stuff>;
178
- maxage?: number;
179
- }
180
-
181
153
  export interface Logger {
182
154
  (msg: string): void;
183
155
  success(msg: string): void;