@sveltejs/kit 1.0.0-next.2 → 1.0.0-next.202

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 (65) hide show
  1. package/README.md +12 -9
  2. package/assets/components/error.svelte +19 -3
  3. package/assets/runtime/app/env.js +20 -0
  4. package/assets/runtime/app/navigation.js +42 -34
  5. package/assets/runtime/app/paths.js +1 -0
  6. package/assets/runtime/app/stores.js +15 -9
  7. package/assets/runtime/chunks/utils.js +13 -0
  8. package/assets/runtime/env.js +8 -0
  9. package/assets/runtime/internal/singletons.js +5 -6
  10. package/assets/runtime/internal/start.js +1020 -320
  11. package/assets/runtime/paths.js +13 -0
  12. package/dist/chunks/cert.js +29255 -0
  13. package/dist/chunks/constants.js +8 -0
  14. package/dist/chunks/error.js +21 -0
  15. package/dist/chunks/index.js +4746 -0
  16. package/dist/chunks/index2.js +797 -0
  17. package/dist/chunks/index3.js +1042 -0
  18. package/dist/chunks/index4.js +398 -0
  19. package/dist/chunks/index5.js +827 -0
  20. package/dist/chunks/index6.js +15575 -0
  21. package/dist/chunks/multipart-parser.js +449 -0
  22. package/dist/chunks/url.js +62 -0
  23. package/dist/cli.js +958 -59
  24. package/dist/hooks.js +28 -0
  25. package/dist/install-fetch.js +6514 -0
  26. package/dist/node.js +51 -0
  27. package/dist/ssr.js +1771 -0
  28. package/package.json +90 -52
  29. package/svelte-kit.js +2 -0
  30. package/types/ambient-modules.d.ts +173 -0
  31. package/types/app.d.ts +21 -0
  32. package/types/config.d.ts +96 -0
  33. package/types/endpoint.d.ts +18 -0
  34. package/types/helper.d.ts +41 -0
  35. package/types/hooks.d.ts +36 -0
  36. package/types/index.d.ts +17 -0
  37. package/types/internal.d.ts +219 -0
  38. package/types/page.d.ts +77 -0
  39. package/CHANGELOG.md +0 -159
  40. package/assets/renderer/index.js +0 -2492
  41. package/assets/renderer/index.js.map +0 -1
  42. package/assets/runtime/app/navigation.js.map +0 -1
  43. package/assets/runtime/app/stores.js.map +0 -1
  44. package/assets/runtime/internal/singletons.js.map +0 -1
  45. package/assets/runtime/internal/start.js.map +0 -1
  46. package/dist/api.js +0 -38
  47. package/dist/api.js.map +0 -1
  48. package/dist/cli.js.map +0 -1
  49. package/dist/create_app.js +0 -550
  50. package/dist/create_app.js.map +0 -1
  51. package/dist/index.js +0 -10708
  52. package/dist/index.js.map +0 -1
  53. package/dist/index2.js +0 -506
  54. package/dist/index2.js.map +0 -1
  55. package/dist/index3.js +0 -62
  56. package/dist/index3.js.map +0 -1
  57. package/dist/index4.js +0 -563
  58. package/dist/index4.js.map +0 -1
  59. package/dist/index5.js +0 -276
  60. package/dist/index5.js.map +0 -1
  61. package/dist/package.js +0 -235
  62. package/dist/package.js.map +0 -1
  63. package/dist/utils.js +0 -58
  64. package/dist/utils.js.map +0 -1
  65. package/svelte-kit +0 -3
package/README.md CHANGED
@@ -1,15 +1,18 @@
1
- # @sveltejs/kit
1
+ # The fastest way to build Svelte apps
2
2
 
3
- Here be dragons, etc etc.
3
+ This is the [SvelteKit](https://kit.svelte.dev) framework and CLI.
4
4
 
5
- This project aims to replicate Sapper's functionality in its entirety, minus building for deployment (which can be handled by 'adapters' that do various opinionated things with the output of `snowpack build`).
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
- It's currently missing a ton of stuff but I figured I'd throw it up on GitHub anyway partly for the sake of 'working in the open' but mostly because I need an issue tracker to organise my thoughts.
7
+ ```bash
8
+ npm init svelte@next my-app
9
+ cd my-app
10
+ npm install
11
+ npm run dev
12
+ ```
8
13
 
9
- There are no tests yet or anything like that. Some of the code has just been straight copied over from the existing Sapper repo, but a pleasing amount of it can safely be left behind.
14
+ See the [documentation](https://kit.svelte.dev/docs) to learn more.
10
15
 
11
- ## Trying it out
16
+ ## Changelog
12
17
 
13
- Clone this repo, `npm install`, and `npm link`. That will create a global link to the `svelte` bin. You can then either `npm run build` or `npm run dev`, if you intend to make changes and see them immediately reflected.
14
-
15
- Then, clone the corresponding [svelte-app-demo](https://github.com/sveltejs/svelte-app-demo) repo and follow the instructions therein.
18
+ [The Changelog for this package is available on GitHub](https://github.com/sveltejs/kit/blob/master/packages/kit/CHANGELOG.md).
@@ -1,13 +1,29 @@
1
+ <script context="module">
2
+ /** @type {import('@sveltejs/kit').ErrorLoad} */
3
+ export function load({ error, status }) {
4
+ return {
5
+ props: { error, status }
6
+ };
7
+ }
8
+ </script>
9
+
1
10
  <script>
11
+ /** @type {number} */
2
12
  export let status;
13
+
14
+ /** @type {Error & {frame?: string} & {loc?: object}} */
3
15
  export let error;
4
16
  </script>
5
17
 
6
18
  <h1>{status}</h1>
7
19
 
8
- <p>{error.message}</p>
20
+ <pre>{error.message}</pre>
9
21
 
10
- <!-- TODO figure out what to do with stacktraces in prod -->
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}
11
27
  {#if error.stack}
12
28
  <pre>{error.stack}</pre>
13
- {/if}
29
+ {/if}
@@ -0,0 +1,20 @@
1
+ export { prerendering } from '../env.js';
2
+
3
+ /**
4
+ * @type {import('$app/env').browser}
5
+ */
6
+ const browser = !import.meta.env.SSR;
7
+ /**
8
+ * @type {import('$app/env').dev}
9
+ */
10
+ const dev = !!import.meta.env.DEV;
11
+ /**
12
+ * @type {import('$app/env').mode}
13
+ */
14
+ const mode = import.meta.env.MODE;
15
+ /**
16
+ * @type {import('$app/env').amp}
17
+ */
18
+ const amp = !!import.meta.env.VITE_SVELTEKIT_AMP;
19
+
20
+ export { amp, browser, dev, mode };
@@ -1,47 +1,55 @@
1
- import { router, renderer } from '../internal/singletons.js';
2
-
3
- function get_base_uri(window_document) {
4
- let baseURI = window_document.baseURI;
5
-
6
- if (!baseURI) {
7
- const baseTags = window_document.getElementsByTagName('base');
8
- baseURI = baseTags.length ? baseTags[0].href : window_document.URL;
9
- }
10
-
11
- return baseURI;
1
+ import { router as router$1 } from '../internal/singletons.js';
2
+ import { g as get_base_uri } from '../chunks/utils.js';
3
+
4
+ const router = /** @type {import('../client/router').Router} */ (router$1);
5
+
6
+ /**
7
+ * @param {string} name
8
+ */
9
+ function guard(name) {
10
+ return () => {
11
+ throw new Error(`Cannot call ${name}(...) on the server`);
12
+ };
12
13
  }
13
14
 
14
- function goto(href, { noscroll = false, replaceState = false } = {}) {
15
- const url = new URL(href, get_base_uri(document));
16
- const page = router.select(url);
15
+ const goto = import.meta.env.SSR ? guard('goto') : goto_;
16
+ const invalidate = import.meta.env.SSR ? guard('invalidate') : invalidate_;
17
+ const prefetch = import.meta.env.SSR ? guard('prefetch') : prefetch_;
18
+ const prefetchRoutes = import.meta.env.SSR ? guard('prefetchRoutes') : prefetchRoutes_;
17
19
 
18
- if (page) {
19
- // TODO this logic probably belongs inside router? cid should be private
20
- history[replaceState ? 'replaceState' : 'pushState']({ id: router.cid }, '', href);
21
-
22
- // TODO shouldn't need to pass the hash here
23
- return router.navigate(page, null, noscroll, url.hash);
24
- }
20
+ /**
21
+ * @type {import('$app/navigation').goto}
22
+ */
23
+ async function goto_(href, opts) {
24
+ return router.goto(href, opts, []);
25
+ }
25
26
 
26
- location.href = href;
27
- return new Promise(() => {
28
- /* never resolves */
29
- });
27
+ /**
28
+ * @type {import('$app/navigation').invalidate}
29
+ */
30
+ async function invalidate_(resource) {
31
+ const { href } = new URL(resource, location.href);
32
+ return router.renderer.invalidate(href);
30
33
  }
31
34
 
32
- function prefetch(href) {
33
- return renderer.prefetch(new URL(href, get_base_uri(document)));
35
+ /**
36
+ * @type {import('$app/navigation').prefetch}
37
+ */
38
+ function prefetch_(href) {
39
+ return router.prefetch(new URL(href, get_base_uri(document)));
34
40
  }
35
41
 
36
- async function prefetchRoutes(pathnames) {
37
- const path_routes = pathnames
38
- ? router.pages.filter((page) => pathnames.some((pathname) => page.pattern.test(pathname)))
39
- : router.pages;
42
+ /**
43
+ * @type {import('$app/navigation').prefetchRoutes}
44
+ */
45
+ async function prefetchRoutes_(pathnames) {
46
+ const matching = pathnames
47
+ ? router.routes.filter((route) => pathnames.some((pathname) => route[0].test(pathname)))
48
+ : router.routes;
40
49
 
41
- const promises = path_routes.map((r) => Promise.all(r.parts.map((p) => p[0]())));
50
+ const promises = matching.map((r) => Promise.all(r[1].map((load) => load())));
42
51
 
43
52
  await Promise.all(promises);
44
53
  }
45
54
 
46
- export { goto, prefetch, prefetchRoutes };
47
- //# sourceMappingURL=navigation.js.map
55
+ export { goto, invalidate, prefetch, prefetchRoutes };
@@ -0,0 +1 @@
1
+ export { assets, base } from '../paths.js';
@@ -1,7 +1,8 @@
1
1
  import { getContext } from 'svelte';
2
+ import { browser } from './env.js';
3
+ import '../env.js';
2
4
 
3
- // const ssr = (import.meta as any).env.SSR;
4
- const ssr = typeof window === 'undefined'; // TODO why doesn't previous line work in build?
5
+ const ssr = !browser;
5
6
 
6
7
  // TODO remove this (for 1.0? after 1.0?)
7
8
  let warned = false;
@@ -13,6 +14,9 @@ function stores() {
13
14
  return getStores();
14
15
  }
15
16
 
17
+ /**
18
+ * @type {import('$app/stores').getStores}
19
+ */
16
20
  const getStores = () => {
17
21
  const stores = getContext('__svelte__');
18
22
 
@@ -23,6 +27,8 @@ const getStores = () => {
23
27
  navigating: {
24
28
  subscribe: stores.navigating.subscribe
25
29
  },
30
+ // TODO remove this (for 1.0? after 1.0?)
31
+ // @ts-expect-error - deprecated, not part of type definitions, but still callable
26
32
  get preloading() {
27
33
  console.error('stores.preloading is deprecated; use stores.navigating instead');
28
34
  return {
@@ -33,13 +39,16 @@ const getStores = () => {
33
39
  };
34
40
  };
35
41
 
42
+ /** @type {typeof import('$app/stores').page} */
36
43
  const page = {
44
+ /** @param {(value: any) => void} fn */
37
45
  subscribe(fn) {
38
46
  const store = getStores().page;
39
47
  return store.subscribe(fn);
40
48
  }
41
49
  };
42
50
 
51
+ /** @type {typeof import('$app/stores').navigating} */
43
52
  const navigating = {
44
53
  subscribe(fn) {
45
54
  const store = getStores().navigating;
@@ -47,6 +56,7 @@ const navigating = {
47
56
  }
48
57
  };
49
58
 
59
+ /** @param {string} verb */
50
60
  const error = (verb) => {
51
61
  throw new Error(
52
62
  ssr
@@ -55,6 +65,7 @@ const error = (verb) => {
55
65
  );
56
66
  };
57
67
 
68
+ /** @type {typeof import('$app/stores').session} */
58
69
  const session = {
59
70
  subscribe(fn) {
60
71
  const store = getStores().session;
@@ -66,13 +77,8 @@ const session = {
66
77
 
67
78
  return store.subscribe(fn);
68
79
  },
69
- set: (value) => {
70
- error('set');
71
- },
72
- update: (updater) => {
73
- error('update');
74
- }
80
+ set: () => error('set'),
81
+ update: () => error('update')
75
82
  };
76
83
 
77
84
  export { getStores, navigating, page, session, stores };
78
- //# sourceMappingURL=stores.js.map
@@ -0,0 +1,13 @@
1
+ /** @param {HTMLDocument} doc */
2
+ function get_base_uri(doc) {
3
+ let baseURI = doc.baseURI;
4
+
5
+ if (!baseURI) {
6
+ const baseTags = doc.getElementsByTagName('base');
7
+ baseURI = baseTags.length ? baseTags[0].href : doc.URL;
8
+ }
9
+
10
+ return baseURI;
11
+ }
12
+
13
+ export { get_base_uri as g };
@@ -0,0 +1,8 @@
1
+ let prerendering = false;
2
+
3
+ /** @param {boolean} value */
4
+ function set_prerendering(value) {
5
+ prerendering = value;
6
+ }
7
+
8
+ export { prerendering, set_prerendering };
@@ -1,10 +1,9 @@
1
+ /** @type {import('./router').Router?} */
1
2
  let router;
2
- let renderer;
3
3
 
4
- function init(opts) {
5
- router = opts.router;
6
- renderer = opts.renderer;
4
+ /** @param {import('./router').Router?} _ */
5
+ function init(_) {
6
+ router = _;
7
7
  }
8
8
 
9
- export { init, renderer, router };
10
- //# sourceMappingURL=singletons.js.map
9
+ export { init, router };