@sveltejs/kit 1.0.0-next.312 → 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.
@@ -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
  }
@@ -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) {
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.312');
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.312'}\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.312",
3
+ "version": "1.0.0-next.314",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -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;