@sveltejs/kit 1.0.0-next.19 → 1.0.0-next.193

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 (77) 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 +45 -13
  5. package/assets/runtime/app/paths.js +1 -2
  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 -11
  10. package/assets/runtime/internal/start.js +954 -350
  11. package/assets/runtime/paths.js +13 -0
  12. package/dist/chunks/cert.js +29254 -0
  13. package/dist/chunks/constants.js +8 -0
  14. package/dist/chunks/error.js +21 -0
  15. package/dist/chunks/http.js +22 -0
  16. package/dist/chunks/index.js +4745 -0
  17. package/dist/chunks/index2.js +700 -0
  18. package/dist/chunks/index3.js +1065 -0
  19. package/dist/chunks/index4.js +393 -0
  20. package/dist/chunks/index5.js +413 -0
  21. package/dist/chunks/index6.js +15560 -0
  22. package/dist/{standard.js → chunks/standard.js} +16 -18
  23. package/dist/cli.js +936 -67
  24. package/dist/hooks.js +28 -0
  25. package/dist/install-fetch.js +6070 -0
  26. package/dist/node.js +51 -0
  27. package/dist/ssr.js +1791 -0
  28. package/package.json +89 -54
  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 -270
  40. package/assets/runtime/app/navigation.js.map +0 -1
  41. package/assets/runtime/app/paths.js.map +0 -1
  42. package/assets/runtime/app/stores.js.map +0 -1
  43. package/assets/runtime/internal/singletons.js.map +0 -1
  44. package/assets/runtime/internal/start.js.map +0 -1
  45. package/assets/runtime/utils-85ebcc60.js +0 -18
  46. package/assets/runtime/utils-85ebcc60.js.map +0 -1
  47. package/dist/api.js +0 -44
  48. package/dist/api.js.map +0 -1
  49. package/dist/build.js +0 -246
  50. package/dist/build.js.map +0 -1
  51. package/dist/cli.js.map +0 -1
  52. package/dist/colors.js +0 -37
  53. package/dist/colors.js.map +0 -1
  54. package/dist/create_app.js +0 -578
  55. package/dist/create_app.js.map +0 -1
  56. package/dist/index.js +0 -12009
  57. package/dist/index.js.map +0 -1
  58. package/dist/index2.js +0 -544
  59. package/dist/index2.js.map +0 -1
  60. package/dist/index3.js +0 -71
  61. package/dist/index3.js.map +0 -1
  62. package/dist/index4.js +0 -466
  63. package/dist/index4.js.map +0 -1
  64. package/dist/index5.js +0 -717
  65. package/dist/index5.js.map +0 -1
  66. package/dist/index6.js +0 -713
  67. package/dist/index6.js.map +0 -1
  68. package/dist/logging.js +0 -43
  69. package/dist/logging.js.map +0 -1
  70. package/dist/package.js +0 -406
  71. package/dist/package.js.map +0 -1
  72. package/dist/renderer.js +0 -2391
  73. package/dist/renderer.js.map +0 -1
  74. package/dist/standard.js.map +0 -1
  75. package/dist/utils.js +0 -54
  76. package/dist/utils.js.map +0 -1
  77. 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,23 +1,55 @@
1
- import { g as get_base_uri } from '../utils-85ebcc60.js';
2
- import { router, renderer } from '../internal/singletons.js';
1
+ import { router as router$1 } from '../internal/singletons.js';
2
+ import { g as get_base_uri } from '../chunks/utils.js';
3
3
 
4
- async function goto(href, opts) {
5
- return router.goto(href, opts);
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
+ };
13
+ }
14
+
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_;
19
+
20
+ /**
21
+ * @type {import('$app/navigation').goto}
22
+ */
23
+ async function goto_(href, opts) {
24
+ return router.goto(href, opts, []);
25
+ }
26
+
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);
6
33
  }
7
34
 
8
- function prefetch(href) {
9
- 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)));
10
40
  }
11
41
 
12
- async function prefetchRoutes(pathnames) {
13
- const path_routes = pathnames
14
- ? router.pages.filter((page) => pathnames.some((pathname) => page.pattern.test(pathname)))
15
- : 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;
16
49
 
17
- const promises = path_routes.map((r) => Promise.all(r.parts.map((load) => load())));
50
+ const promises = matching.map((r) => Promise.all(r[1].map((load) => load())));
18
51
 
19
52
  await Promise.all(promises);
20
53
  }
21
54
 
22
- export { goto, prefetch, prefetchRoutes };
23
- //# sourceMappingURL=navigation.js.map
55
+ export { goto, invalidate, prefetch, prefetchRoutes };
@@ -1,2 +1 @@
1
- export { assets, base } from '../internal/singletons.js';
2
- //# sourceMappingURL=paths.js.map
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,15 +1,9 @@
1
+ /** @type {import('./router').Router?} */
1
2
  let router;
2
- let renderer;
3
- let base;
4
- let assets;
5
3
 
6
- function init(opts) {
7
- ({ router, renderer } = opts);
4
+ /** @param {import('./router').Router?} _ */
5
+ function init(_) {
6
+ router = _;
8
7
  }
9
8
 
10
- function set_paths(paths) {
11
- ({ base, assets } = paths);
12
- }
13
-
14
- export { assets, base, init, renderer, router, set_paths };
15
- //# sourceMappingURL=singletons.js.map
9
+ export { init, router };