@sveltejs/kit 1.0.0-next.412 → 1.0.0-next.415

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.412",
3
+ "version": "1.0.0-next.415",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -1,3 +1,5 @@
1
1
  // in `vite dev` and `vite preview`, we use a fake asset path so that we can
2
2
  // serve local assets while verifying that requests are correctly prefixed
3
3
  export const SVELTE_KIT_ASSETS = '/_svelte_kit_assets';
4
+
5
+ export const GENERATED_COMMENT = '// this file is generated — do not edit it\n';
@@ -0,0 +1,91 @@
1
+ import { GENERATED_COMMENT } from './constants.js';
2
+
3
+ /**
4
+ * @param {string} id
5
+ * @param {Record<string, string>} env
6
+ * @returns {string}
7
+ */
8
+ export function create_module(id, env) {
9
+ /** @type {string[]} */
10
+ const declarations = [];
11
+
12
+ for (const key in env) {
13
+ if (!valid_identifier.test(key) || reserved.has(key)) {
14
+ continue;
15
+ }
16
+
17
+ const comment = `/** @type {import('${id}').${key}} */`;
18
+ const declaration = `export const ${key} = ${JSON.stringify(env[key])};`;
19
+
20
+ declarations.push(`${comment}\n${declaration}`);
21
+ }
22
+
23
+ return GENERATED_COMMENT + declarations.join('\n\n');
24
+ }
25
+
26
+ /**
27
+ * @param {string} id
28
+ * @param {Record<string, string>} env
29
+ * @returns {string}
30
+ */
31
+ export function create_types(id, env) {
32
+ const declarations = Object.keys(env)
33
+ .filter((k) => valid_identifier.test(k))
34
+ .map((k) => `\texport const ${k}: string;`)
35
+ .join('\n');
36
+
37
+ return `declare module '${id}' {\n${declarations}\n}`;
38
+ }
39
+
40
+ export const reserved = new Set([
41
+ 'do',
42
+ 'if',
43
+ 'in',
44
+ 'for',
45
+ 'let',
46
+ 'new',
47
+ 'try',
48
+ 'var',
49
+ 'case',
50
+ 'else',
51
+ 'enum',
52
+ 'eval',
53
+ 'null',
54
+ 'this',
55
+ 'true',
56
+ 'void',
57
+ 'with',
58
+ 'await',
59
+ 'break',
60
+ 'catch',
61
+ 'class',
62
+ 'const',
63
+ 'false',
64
+ 'super',
65
+ 'throw',
66
+ 'while',
67
+ 'yield',
68
+ 'delete',
69
+ 'export',
70
+ 'import',
71
+ 'public',
72
+ 'return',
73
+ 'static',
74
+ 'switch',
75
+ 'typeof',
76
+ 'default',
77
+ 'extends',
78
+ 'finally',
79
+ 'package',
80
+ 'private',
81
+ 'continue',
82
+ 'debugger',
83
+ 'function',
84
+ 'arguments',
85
+ 'interface',
86
+ 'protected',
87
+ 'implements',
88
+ 'instanceof'
89
+ ]);
90
+
91
+ export const valid_identifier = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
@@ -42,56 +42,3 @@ export function trim(str) {
42
42
  const pattern = new RegExp(`^${indentation}`, 'gm');
43
43
  return str.replace(pattern, '').trim();
44
44
  }
45
-
46
- export const reserved = new Set([
47
- 'do',
48
- 'if',
49
- 'in',
50
- 'for',
51
- 'let',
52
- 'new',
53
- 'try',
54
- 'var',
55
- 'case',
56
- 'else',
57
- 'enum',
58
- 'eval',
59
- 'null',
60
- 'this',
61
- 'true',
62
- 'void',
63
- 'with',
64
- 'await',
65
- 'break',
66
- 'catch',
67
- 'class',
68
- 'const',
69
- 'false',
70
- 'super',
71
- 'throw',
72
- 'while',
73
- 'yield',
74
- 'delete',
75
- 'export',
76
- 'import',
77
- 'public',
78
- 'return',
79
- 'static',
80
- 'switch',
81
- 'typeof',
82
- 'default',
83
- 'extends',
84
- 'finally',
85
- 'package',
86
- 'private',
87
- 'continue',
88
- 'debugger',
89
- 'function',
90
- 'arguments',
91
- 'interface',
92
- 'protected',
93
- 'implements',
94
- 'instanceof'
95
- ]);
96
-
97
- export const valid_identifier = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
@@ -1,9 +1,9 @@
1
1
  import path from 'path';
2
- import colors from 'kleur';
3
2
  import { get_env } from '../../vite/utils.js';
4
- import { write_if_changed, reserved, valid_identifier } from './utils.js';
3
+ import { GENERATED_COMMENT } from '../constants.js';
4
+ import { create_types } from '../env.js';
5
+ import { write_if_changed } from './utils.js';
5
6
 
6
- const autogen_comment = '// this file is generated — do not edit it\n';
7
7
  const types_reference = '/// <reference types="@sveltejs/kit" />\n\n';
8
8
 
9
9
  /**
@@ -16,72 +16,12 @@ const types_reference = '/// <reference types="@sveltejs/kit" />\n\n';
16
16
  export function write_ambient(config, mode) {
17
17
  const env = get_env(mode, config.env.publicPrefix);
18
18
 
19
- // TODO when testing src, `$app` points at `src/runtime/app`... will
20
- // probably need to fiddle with aliases
21
- write_if_changed(
22
- path.join(config.outDir, 'runtime/env/static/public.js'),
23
- create_env_module('$env/static/public', env.public)
24
- );
25
-
26
- write_if_changed(
27
- path.join(config.outDir, 'runtime/env/static/private.js'),
28
- create_env_module('$env/static/private', env.private)
29
- );
30
-
31
19
  write_if_changed(
32
20
  path.join(config.outDir, 'ambient.d.ts'),
33
- autogen_comment +
21
+ GENERATED_COMMENT +
34
22
  types_reference +
35
- create_env_types('$env/static/public', env.public) +
23
+ create_types('$env/static/public', env.public) +
36
24
  '\n\n' +
37
- create_env_types('$env/static/private', env.private)
25
+ create_types('$env/static/private', env.private)
38
26
  );
39
27
  }
40
-
41
- /**
42
- * @param {string} id
43
- * @param {Record<string, string>} env
44
- * @returns {string}
45
- */
46
- function create_env_module(id, env) {
47
- /** @type {string[]} */
48
- const declarations = [];
49
-
50
- for (const key in env) {
51
- const warning = !valid_identifier.test(key)
52
- ? 'not a valid identifier'
53
- : reserved.has(key)
54
- ? 'a reserved word'
55
- : null;
56
-
57
- if (warning) {
58
- console.error(
59
- colors
60
- .bold()
61
- .yellow(`Omitting environment variable "${key}" from ${id} as it is ${warning}`)
62
- );
63
- continue;
64
- }
65
-
66
- const comment = `/** @type {import('${id}').${key}} */`;
67
- const declaration = `export const ${key} = ${JSON.stringify(env[key])};`;
68
-
69
- declarations.push(`${comment}\n${declaration}`);
70
- }
71
-
72
- return autogen_comment + declarations.join('\n\n');
73
- }
74
-
75
- /**
76
- * @param {string} id
77
- * @param {Record<string, string>} env
78
- * @returns {string}
79
- */
80
- function create_env_types(id, env) {
81
- const declarations = Object.keys(env)
82
- .filter((k) => valid_identifier.test(k))
83
- .map((k) => `\texport const ${k}: string;`)
84
- .join('\n');
85
-
86
- return `declare module '${id}' {\n${declarations}\n}`;
87
- }
@@ -32,7 +32,10 @@ export const getStores = () => {
32
32
  subscribe: stores.navigating.subscribe
33
33
  };
34
34
  },
35
- session: stores.session,
35
+ get session() {
36
+ removed_session();
37
+ return {};
38
+ },
36
39
  updated: stores.updated
37
40
  };
38
41
  };
@@ -54,29 +57,17 @@ export const navigating = {
54
57
  }
55
58
  };
56
59
 
57
- /** @param {string} verb */
58
- const throw_error = (verb) => {
60
+ function removed_session() {
61
+ // TODO remove for 1.0
59
62
  throw new Error(
60
- browser
61
- ? `Cannot ${verb} session store before subscribing`
62
- : `Can only ${verb} session store in browser`
63
+ 'stores.session is no longer available. See https://github.com/sveltejs/kit/discussions/5883'
63
64
  );
64
- };
65
+ }
65
66
 
66
- /** @type {typeof import('$app/stores').session} */
67
67
  export const session = {
68
- subscribe(fn) {
69
- const store = getStores().session;
70
-
71
- if (browser) {
72
- session.set = store.set;
73
- session.update = store.update;
74
- }
75
-
76
- return store.subscribe(fn);
77
- },
78
- set: () => throw_error('set'),
79
- update: () => throw_error('update')
68
+ subscribe: removed_session,
69
+ set: removed_session,
70
+ update: removed_session
80
71
  };
81
72
 
82
73
  /** @type {typeof import('$app/stores').updated} */
@@ -90,5 +81,11 @@ export const updated = {
90
81
 
91
82
  return store.subscribe(fn);
92
83
  },
93
- check: () => throw_error('check')
84
+ check: () => {
85
+ throw new Error(
86
+ browser
87
+ ? `Cannot check updated store before subscribing`
88
+ : `Can only check updated store in browser`
89
+ );
90
+ }
94
91
  };
@@ -50,13 +50,12 @@ function update_scroll_positions(index) {
50
50
  /**
51
51
  * @param {{
52
52
  * target: Element;
53
- * session: App.Session;
54
53
  * base: string;
55
54
  * trailing_slash: import('types').TrailingSlash;
56
55
  * }} opts
57
56
  * @returns {import('./types').Client}
58
57
  */
59
- export function create_client({ target, session, base, trailing_slash }) {
58
+ export function create_client({ target, base, trailing_slash }) {
60
59
  /** @type {Array<((href: string) => boolean)>} */
61
60
  const invalidated = [];
62
61
 
@@ -64,7 +63,6 @@ export function create_client({ target, session, base, trailing_slash }) {
64
63
  url: notifiable_store({}),
65
64
  page: notifiable_store({}),
66
65
  navigating: writable(/** @type {import('types').Navigation | null} */ (null)),
67
- session: writable(session),
68
66
  updated: create_updated_store()
69
67
  };
70
68
 
@@ -102,23 +100,6 @@ export function create_client({ target, session, base, trailing_slash }) {
102
100
  /** @type {import('svelte').SvelteComponent} */
103
101
  let root;
104
102
 
105
- /** @type {App.Session} */
106
- let $session;
107
-
108
- let ready = false;
109
- stores.session.subscribe(async (value) => {
110
- $session = value;
111
-
112
- if (!ready) return;
113
- session_id += 1;
114
-
115
- const current_load_uses_session = current.branch.some((node) => node?.uses.session);
116
- if (!current_load_uses_session) return;
117
-
118
- update(new URL(location.href), []);
119
- });
120
- ready = true;
121
-
122
103
  let router_enabled = true;
123
104
 
124
105
  // keeping track of the history index in order to prevent popstate navigation events if needed
@@ -475,7 +456,6 @@ export function create_client({ target, session, base, trailing_slash }) {
475
456
  const uses = {
476
457
  params: new Set(),
477
458
  url: false,
478
- session: false,
479
459
  dependencies: new Set(),
480
460
  parent: false
481
461
  };
@@ -511,7 +491,6 @@ export function create_client({ target, session, base, trailing_slash }) {
511
491
  });
512
492
  }
513
493
 
514
- const session = $session;
515
494
  const load_url = new LoadURL(url);
516
495
 
517
496
  if (node.shared?.load) {
@@ -524,10 +503,6 @@ export function create_client({ target, session, base, trailing_slash }) {
524
503
  uses.url = true;
525
504
  return load_url;
526
505
  },
527
- get session() {
528
- uses.session = true;
529
- return session;
530
- },
531
506
  async fetch(resource, init) {
532
507
  let requested;
533
508
 
@@ -581,6 +556,12 @@ export function create_client({ target, session, base, trailing_slash }) {
581
556
  '@migration task: Replace `props` with `data` stuff https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292693'
582
557
  );
583
558
  },
559
+ get session() {
560
+ // TODO remove this for 1.0
561
+ throw new Error(
562
+ 'session is no longer available. See https://github.com/sveltejs/kit/discussions/5883'
563
+ );
564
+ },
584
565
  get stuff() {
585
566
  throw new Error(
586
567
  '@migration task: Remove stuff https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292693'
@@ -620,8 +601,7 @@ export function create_client({ target, session, base, trailing_slash }) {
620
601
 
621
602
  const changed = current.url && {
622
603
  url: id !== current.url.pathname + current.url.search,
623
- params: Object.keys(params).filter((key) => current.params[key] !== params[key]),
624
- session: session_id !== current.session_id
604
+ params: Object.keys(params).filter((key) => current.params[key] !== params[key])
625
605
  };
626
606
 
627
607
  // preload modules to avoid waterfall, but handle rejections
@@ -643,7 +623,6 @@ export function create_client({ target, session, base, trailing_slash }) {
643
623
  !previous ||
644
624
  (changed.url && previous.uses.url) ||
645
625
  changed.params.some((param) => previous.uses.params.has(param)) ||
646
- (changed.session && previous.uses.session) ||
647
626
  Array.from(previous.uses.dependencies).some((dep) => invalidated.some((fn) => fn(dep))) ||
648
627
  (previous.uses.parent && nodes_changed_since_last_render.includes(true));
649
628
  nodes_changed_since_last_render.push(changed_since_last_render);
@@ -753,7 +732,6 @@ export function create_client({ target, session, base, trailing_slash }) {
753
732
  uses: {
754
733
  params: new Set(),
755
734
  url: false,
756
- session: false,
757
735
  dependencies: new Set(),
758
736
  parent: false
759
737
  }
@@ -825,7 +803,6 @@ export function create_client({ target, session, base, trailing_slash }) {
825
803
  uses: {
826
804
  params: new Set(),
827
805
  url: false,
828
- session: false,
829
806
  dependencies: new Set(),
830
807
  parent: false
831
808
  }
@@ -11,7 +11,6 @@ export { set_public_env } from '../env-public.js';
11
11
  * base: string;
12
12
  * },
13
13
  * target: Element;
14
- * session: any;
15
14
  * route: boolean;
16
15
  * spa: boolean;
17
16
  * trailing_slash: import('types').TrailingSlash;
@@ -24,10 +23,9 @@ export { set_public_env } from '../env-public.js';
24
23
  * };
25
24
  * }} opts
26
25
  */
27
- export async function start({ paths, target, session, route, spa, trailing_slash, hydrate }) {
26
+ export async function start({ paths, target, route, spa, trailing_slash, hydrate }) {
28
27
  const client = create_client({
29
28
  target,
30
- session,
31
29
  base: paths.base,
32
30
  trailing_slash
33
31
  });
@@ -69,7 +69,6 @@ export type BranchNode = {
69
69
  uses: {
70
70
  params: Set<string>;
71
71
  url: boolean; // TODO make more granular?
72
- session: boolean;
73
72
  dependencies: Set<string>;
74
73
  parent: boolean;
75
74
  };
@@ -222,7 +222,6 @@ export async function respond(request, options, state) {
222
222
  event,
223
223
  options,
224
224
  state,
225
- $session: await options.hooks.getSession(event),
226
225
  page_config: { router: true, hydrate: true },
227
226
  status: 200,
228
227
  error: null,
@@ -250,7 +249,8 @@ export async function respond(request, options, state) {
250
249
  try {
251
250
  if (error) return;
252
251
 
253
- const node = n ? await options.manifest._.nodes[n]() : undefined;
252
+ // == because it could be undefined (in dev) or null (in build, because of JSON.stringify)
253
+ const node = n == undefined ? n : await options.manifest._.nodes[n]();
254
254
  return {
255
255
  // TODO return `uses`, so we can reuse server data effectively
256
256
  data: await load_server_data({
@@ -260,7 +260,11 @@ export async function respond(request, options, state) {
260
260
  /** @type {import('types').JSONObject} */
261
261
  const data = {};
262
262
  for (let j = 0; j < i; j += 1) {
263
- Object.assign(data, await promises[j]);
263
+ const parent = await promises[j];
264
+ if (!parent || parent instanceof HttpError || 'error' in parent) {
265
+ return data;
266
+ }
267
+ Object.assign(data, parent.data);
264
268
  }
265
269
  return data;
266
270
  }
@@ -360,12 +364,10 @@ export async function respond(request, options, state) {
360
364
  // if this request came direct from the user, rather than
361
365
  // via a `fetch` in a `load`, render a 404 page
362
366
  if (!state.initiator) {
363
- const $session = await options.hooks.getSession(event);
364
367
  return await respond_with_error({
365
368
  event,
366
369
  options,
367
370
  state,
368
- $session,
369
371
  status: 404,
370
372
  error: new Error(`Not found: ${event.url.pathname}`),
371
373
  resolve_opts
@@ -413,12 +415,10 @@ export async function respond(request, options, state) {
413
415
 
414
416
  // TODO is this necessary? should we just return a plain 500 at this point?
415
417
  try {
416
- const $session = await options.hooks.getSession(event);
417
418
  return await respond_with_error({
418
419
  event,
419
420
  options,
420
421
  state,
421
- $session,
422
422
  status: 500,
423
423
  error,
424
424
  resolve_opts
@@ -43,8 +43,6 @@ export async function render_page(event, route, options, state, resolve_opts) {
43
43
  }
44
44
  }
45
45
 
46
- const $session = await options.hooks.getSession(event);
47
-
48
46
  const { fetcher, fetched, cookies } = create_fetch({ event, options, state, route });
49
47
 
50
48
  try {
@@ -112,7 +110,6 @@ export async function render_page(event, route, options, state, resolve_opts) {
112
110
  event,
113
111
  options,
114
112
  state,
115
- $session,
116
113
  resolve_opts
117
114
  });
118
115
  }
@@ -180,11 +177,9 @@ export async function render_page(event, route, options, state, resolve_opts) {
180
177
  return Promise.resolve().then(async () => {
181
178
  try {
182
179
  return await load_data({
183
- $session,
184
180
  event,
185
181
  fetcher,
186
182
  node,
187
- options,
188
183
  parent: async () => {
189
184
  const data = {};
190
185
  for (let j = 0; j < i; j += 1) {
@@ -240,7 +235,6 @@ export async function render_page(event, route, options, state, resolve_opts) {
240
235
  event,
241
236
  options,
242
237
  state,
243
- $session,
244
238
  resolve_opts,
245
239
  page_config: { router: true, hydrate: true },
246
240
  status,
@@ -294,7 +288,6 @@ export async function render_page(event, route, options, state, resolve_opts) {
294
288
  event,
295
289
  options,
296
290
  state,
297
- $session,
298
291
  resolve_opts,
299
292
  page_config: get_page_config(leaf_node, options),
300
293
  status,
@@ -313,7 +306,6 @@ export async function render_page(event, route, options, state, resolve_opts) {
313
306
  event,
314
307
  options,
315
308
  state,
316
- $session,
317
309
  status: 500,
318
310
  error: /** @type {Error} */ (error),
319
311
  resolve_opts
@@ -33,26 +33,15 @@ export async function load_server_data({ event, node, parent }) {
33
33
  /**
34
34
  * Calls the user's `load` function.
35
35
  * @param {{
36
- * $session: Record<string, any>;
37
36
  * event: import('types').RequestEvent;
38
37
  * fetcher: typeof fetch;
39
38
  * node: import('types').SSRNode | undefined;
40
- * options: import('types').SSROptions;
41
39
  * parent: () => Promise<Record<string, any>>;
42
40
  * server_data_promise: Promise<import('types').JSONObject | null>;
43
41
  * state: import('types').SSRState;
44
42
  * }} opts
45
43
  */
46
- export async function load_data({
47
- $session,
48
- event,
49
- fetcher,
50
- node,
51
- options,
52
- parent,
53
- server_data_promise,
54
- state
55
- }) {
44
+ export async function load_data({ event, fetcher, node, parent, server_data_promise, state }) {
56
45
  const server_data = await server_data_promise;
57
46
 
58
47
  if (!node?.shared?.load) {
@@ -65,12 +54,10 @@ export async function load_data({
65
54
  data: server_data,
66
55
  routeId: event.routeId,
67
56
  get session() {
68
- if (node.shared.prerender ?? options.prerender.default) {
69
- throw Error(
70
- 'Attempted to access session from a prerendered page. Session would never be populated.'
71
- );
72
- }
73
- return $session;
57
+ // TODO remove for 1.0
58
+ throw new Error(
59
+ 'session is no longer available. See https://github.com/sveltejs/kit/discussions/5883'
60
+ );
74
61
  },
75
62
  fetch: fetcher,
76
63
  setHeaders: event.setHeaders,
@@ -1,7 +1,6 @@
1
1
  import devalue from 'devalue';
2
2
  import { readable, writable } from 'svelte/store';
3
3
  import * as cookie from 'cookie';
4
- import { coalesce_to_error } from '../../../utils/error.js';
5
4
  import { hash } from '../../hash.js';
6
5
  import { render_json_payload_script } from '../../../utils/escape.js';
7
6
  import { s } from '../../../utils/misc.js';
@@ -25,7 +24,6 @@ const updated = {
25
24
  * cookies: import('set-cookie-parser').Cookie[];
26
25
  * options: import('types').SSROptions;
27
26
  * state: import('types').SSRState;
28
- * $session: any;
29
27
  * page_config: { hydrate: boolean, router: boolean };
30
28
  * status: number;
31
29
  * error: HttpError | Error | null;
@@ -40,7 +38,6 @@ export async function render_response({
40
38
  cookies,
41
39
  options,
42
40
  state,
43
- $session,
44
41
  page_config,
45
42
  status,
46
43
  error = null,
@@ -79,14 +76,11 @@ export async function render_response({
79
76
  }
80
77
 
81
78
  if (resolve_opts.ssr) {
82
- const session = writable($session);
83
-
84
79
  /** @type {Record<string, any>} */
85
80
  const props = {
86
81
  stores: {
87
82
  page: writable(null),
88
83
  navigating: writable(null),
89
- session,
90
84
  updated
91
85
  },
92
86
  /** @type {import('types').Page} */
@@ -165,9 +159,6 @@ export async function render_response({
165
159
  start({
166
160
  target: document.querySelector('[data-sveltekit-hydrate="${target}"]').parentNode,
167
161
  paths: ${s(options.paths)},
168
- session: ${try_serialize($session, (error) => {
169
- throw new Error(`Failed to serialize session data: ${error.message}`);
170
- })},
171
162
  route: ${!!page_config.router},
172
163
  spa: ${!resolve_opts.ssr},
173
164
  trailing_slash: ${s(options.trailing_slash)},
@@ -348,16 +339,3 @@ export async function render_response({
348
339
  headers
349
340
  });
350
341
  }
351
-
352
- /**
353
- * @param {any} data
354
- * @param {(error: Error) => void} [fail]
355
- */
356
- function try_serialize(data, fail) {
357
- try {
358
- return devalue(data);
359
- } catch (err) {
360
- if (fail) fail(coalesce_to_error(err));
361
- return null;
362
- }
363
- }
@@ -15,21 +15,12 @@ import { create_fetch } from './fetch.js';
15
15
  * event: import('types').RequestEvent;
16
16
  * options: SSROptions;
17
17
  * state: SSRState;
18
- * $session: any;
19
18
  * status: number;
20
19
  * error: Error;
21
20
  * resolve_opts: import('types').RequiredResolveOptions;
22
21
  * }} opts
23
22
  */
24
- export async function respond_with_error({
25
- event,
26
- options,
27
- state,
28
- $session,
29
- status,
30
- error,
31
- resolve_opts
32
- }) {
23
+ export async function respond_with_error({ event, options, state, status, error, resolve_opts }) {
33
24
  const { fetcher, fetched, cookies } = create_fetch({
34
25
  event,
35
26
  options,
@@ -52,11 +43,9 @@ export async function respond_with_error({
52
43
  const server_data = await server_data_promise;
53
44
 
54
45
  const data = await load_data({
55
- $session,
56
46
  event,
57
47
  fetcher,
58
48
  node: default_layout,
59
- options,
60
49
  parent: async () => ({}),
61
50
  server_data_promise,
62
51
  state
@@ -79,7 +68,6 @@ export async function respond_with_error({
79
68
  return await render_response({
80
69
  options,
81
70
  state,
82
- $session,
83
71
  page_config: {
84
72
  hydrate: options.hydrate,
85
73
  router: options.router
@@ -110,7 +110,6 @@ export class Server {
110
110
  if (!this.options.hooks) {
111
111
  const module = await import(${s(hooks)});
112
112
  this.options.hooks = {
113
- getSession: module.getSession || (() => ({})),
114
113
  handle: module.handle || (({ event, resolve }) => resolve(event)),
115
114
  handleError: module.handleError || (({ error }) => console.error(error.stack)),
116
115
  externalFetch: module.externalFetch || fetch
@@ -343,7 +343,6 @@ export async function dev(vite, vite_config, svelte_config, illegal_imports) {
343
343
 
344
344
  /** @type {import('types').Hooks} */
345
345
  const hooks = {
346
- getSession: user_hooks.getSession || (() => ({})),
347
346
  handle,
348
347
  handleError:
349
348
  user_hooks.handleError ||
package/src/vite/index.js CHANGED
@@ -14,8 +14,9 @@ import { generate_manifest } from '../core/generate_manifest/index.js';
14
14
  import { runtime_directory, logger } from '../core/utils.js';
15
15
  import { find_deps, get_default_config as get_default_build_config } from './build/utils.js';
16
16
  import { preview } from './preview/index.js';
17
- import { get_aliases, resolve_entry, prevent_illegal_rollup_imports } from './utils.js';
17
+ import { get_aliases, resolve_entry, prevent_illegal_rollup_imports, get_env } from './utils.js';
18
18
  import { fileURLToPath } from 'node:url';
19
+ import { create_module } from '../core/env.js';
19
20
 
20
21
  const cwd = process.cwd();
21
22
 
@@ -107,6 +108,9 @@ function kit() {
107
108
  /** @type {string | undefined} */
108
109
  let deferred_warning;
109
110
 
111
+ /** @type {{ public: Record<string, string>; private: Record<string, string> }} */
112
+ let env;
113
+
110
114
  /**
111
115
  * @type {{
112
116
  * build_dir: string;
@@ -191,13 +195,13 @@ function kit() {
191
195
  * @see https://vitejs.dev/guide/api-plugin.html#config
192
196
  */
193
197
  async config(config, config_env) {
194
- // The config is created in build_server for SSR mode and passed inline
195
- if (config.build?.ssr) {
196
- return;
197
- }
198
-
199
198
  vite_config_env = config_env;
200
199
  svelte_config = await load_config();
200
+ env = get_env(vite_config_env.mode, svelte_config.kit.env.publicPrefix);
201
+
202
+ // The config is created in build_server for SSR mode and passed inline
203
+ if (config.build?.ssr) return;
204
+
201
205
  is_build = config_env.command === 'build';
202
206
 
203
207
  paths = {
@@ -269,6 +273,20 @@ function kit() {
269
273
  return result;
270
274
  },
271
275
 
276
+ async resolveId(id) {
277
+ // treat $env/static/[public|private] as virtual
278
+ if (id.startsWith('$env/static/')) return `\0${id}`;
279
+ },
280
+
281
+ async load(id) {
282
+ switch (id) {
283
+ case '\0$env/static/private':
284
+ return create_module('$env/static/private', env.private);
285
+ case '\0$env/static/public':
286
+ return create_module('$env/static/public', env.public);
287
+ }
288
+ },
289
+
272
290
  /**
273
291
  * Stores the final config.
274
292
  */
@@ -432,9 +450,10 @@ function kit() {
432
450
  await adapt(svelte_config, build_data, prerendered, { log });
433
451
  } else {
434
452
  console.log(colors.bold().yellow('\nNo adapter specified'));
435
- // prettier-ignore
453
+
454
+ const link = colors.bold().cyan('https://kit.svelte.dev/docs/adapters');
436
455
  console.log(
437
- `See ${colors.bold().cyan('https://kit.svelte.dev/docs/adapters')} to learn how to configure your app to run on the platform of your choosing`
456
+ `See ${link} to learn how to configure your app to run on the platform of your choosing`
438
457
  );
439
458
  }
440
459
 
package/src/vite/utils.js CHANGED
@@ -105,6 +105,8 @@ export function get_aliases(config) {
105
105
  const alias = [
106
106
  { find: '__GENERATED__', replacement: path.posix.join(config.outDir, 'generated') },
107
107
  { find: '$app', replacement: `${runtime_directory}/app` },
108
+ { find: '$env/dynamic/public', replacement: `${runtime_directory}/env/dynamic/public.js` },
109
+ { find: '$env/dynamic/private', replacement: `${runtime_directory}/env/dynamic/private.js` },
108
110
  // For now, we handle `$lib` specially here rather than make it a default value for
109
111
  // `config.kit.alias` since it has special meaning for packaging, etc.
110
112
  { find: '$lib', replacement: config.files.lib }
@@ -128,21 +130,6 @@ export function get_aliases(config) {
128
130
  }
129
131
  }
130
132
 
131
- alias.push(
132
- {
133
- find: '$env/static/public',
134
- replacement: path.posix.join(config.outDir, 'runtime/env/static/public.js')
135
- },
136
- {
137
- find: '$env/static/private',
138
- replacement: path.posix.join(config.outDir, 'runtime/env/static/private.js')
139
- },
140
- {
141
- find: '$env',
142
- replacement: `${runtime_directory}/env`
143
- }
144
- );
145
-
146
133
  return alias;
147
134
  }
148
135
 
@@ -12,12 +12,10 @@
12
12
  * interface PrivateEnv {}
13
13
  *
14
14
  * interface PublicEnv {}
15
- *
16
- * interface Session {}
17
15
  * }
18
16
  * ```
19
17
  *
20
- * By populating these interfaces, you will gain type safety when using `env`, `event.locals`, `event.platform`, `session` and `stuff`.
18
+ * By populating these interfaces, you will gain type safety when using `env`, `event.locals` and `event.platform`.
21
19
  *
22
20
  * Note that since it's an ambient declaration file, you have to be careful when using `import` statements. Once you add an `import`
23
21
  * at the top level, the declaration file is no longer considered ambient and you lose access to these typings in other files.
@@ -45,7 +43,7 @@
45
43
  */
46
44
  declare namespace App {
47
45
  /**
48
- * The interface that defines `event.locals`, which can be accessed in [hooks](https://kit.svelte.dev/docs/hooks) (`handle`, `handleError` and `getSession`) and [endpoints](https://kit.svelte.dev/docs/routing#endpoints).
46
+ * The interface that defines `event.locals`, which can be accessed in [hooks](https://kit.svelte.dev/docs/hooks) (`handle`, and `handleError`), server-only `load` functions, and `+server.js` files.
49
47
  */
50
48
  export interface Locals {}
51
49
 
@@ -63,11 +61,6 @@ declare namespace App {
63
61
  * The interface that defines the dynamic environment variables exported from `$env/dynamic/public`.
64
62
  */
65
63
  export interface PublicEnv extends Record<string, string> {}
66
-
67
- /**
68
- * The interface that defines `session`, both as an argument to [`load`](https://kit.svelte.dev/docs/load) functions and the value of the [session store](https://kit.svelte.dev/docs/modules#$app-stores).
69
- */
70
- export interface Session {}
71
64
  }
72
65
 
73
66
  /**
@@ -220,15 +213,15 @@ declare module '$app/paths' {
220
213
 
221
214
  /**
222
215
  * ```ts
223
- * import { getStores, navigating, page, session, updated } from '$app/stores';
216
+ * import { getStores, navigating, page, updated } from '$app/stores';
224
217
  * ```
225
218
  *
226
- * Stores are _contextual_ — they are added to the [context](https://svelte.dev/tutorial/context-api) of your root component. This means that `session` and `page` are unique to each request on the server, rather than shared between multiple requests handled by the same server simultaneously, which is what makes it safe to include user-specific data in `session`.
219
+ * Stores are _contextual_ — they are added to the [context](https://svelte.dev/tutorial/context-api) of your root component. This means that `page` is unique to each request on the server, rather than shared between multiple requests handled by the same server simultaneously.
227
220
  *
228
221
  * Because of that, you must subscribe to the stores during component initialization (which happens automatically if you reference the store value, e.g. as `$page`, in a component) before you can use them.
229
222
  */
230
223
  declare module '$app/stores' {
231
- import { Readable, Writable } from 'svelte/store';
224
+ import { Readable } from 'svelte/store';
232
225
  import { Navigation, Page } from '@sveltejs/kit';
233
226
 
234
227
  /**
@@ -238,7 +231,6 @@ declare module '$app/stores' {
238
231
  export function getStores(): {
239
232
  navigating: typeof navigating;
240
233
  page: typeof page;
241
- session: typeof session;
242
234
  updated: typeof updated;
243
235
  };
244
236
 
@@ -252,11 +244,6 @@ declare module '$app/stores' {
252
244
  * When navigating finishes, its value reverts to `null`.
253
245
  */
254
246
  export const navigating: Readable<Navigation | null>;
255
- /**
256
- * A writable store whose initial value is whatever was returned from [`getSession`](https://kit.svelte.dev/docs/hooks#getsession).
257
- * It can be written to, but this will not cause changes to persist on the server — this is something you must implement yourself.
258
- */
259
- export const session: Writable<App.Session>;
260
247
  /**
261
248
  * A readable store whose initial value is `false`. If [`version.pollInterval`](https://kit.svelte.dev/docs/configuration#version) is a non-zero value, SvelteKit will poll for new versions of the app and update the store value to `true` when it detects one. `updated.check()` will force an immediate check, regardless of polling.
262
249
  */
package/types/index.d.ts CHANGED
@@ -177,10 +177,6 @@ export interface ExternalFetch {
177
177
  (req: Request): Promise<Response>;
178
178
  }
179
179
 
180
- export interface GetSession {
181
- (event: RequestEvent): MaybePromise<App.Session>;
182
- }
183
-
184
180
  export interface Handle {
185
181
  (input: {
186
182
  event: RequestEvent;
@@ -214,7 +210,6 @@ export interface LoadEvent<
214
210
  params: Params;
215
211
  data: Data;
216
212
  routeId: string | null;
217
- session: App.Session;
218
213
  setHeaders: (headers: ResponseHeaders) => void;
219
214
  url: URL;
220
215
  parent: () => Promise<ParentData>;
@@ -5,7 +5,6 @@ import {
5
5
  Config,
6
6
  ExternalFetch,
7
7
  ServerLoad,
8
- GetSession,
9
8
  Handle,
10
9
  HandleError,
11
10
  KitConfig,
@@ -92,7 +91,6 @@ export type GetParams = (match: RegExpExecArray) => Record<string, string>;
92
91
 
93
92
  export interface Hooks {
94
93
  externalFetch: ExternalFetch;
95
- getSession: GetSession;
96
94
  handle: Handle;
97
95
  handleError: HandleError;
98
96
  }