@sveltejs/kit 1.0.0-next.354 → 1.0.0-next.355

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.
@@ -577,16 +577,18 @@ function create_client({ target, session, base, trailing_slash }) {
577
577
  let token;
578
578
 
579
579
  /**
580
- * @param {string} href
580
+ * @param {string | URL} url
581
581
  * @param {{ noscroll?: boolean; replaceState?: boolean; keepfocus?: boolean; state?: any }} opts
582
582
  * @param {string[]} redirect_chain
583
583
  */
584
584
  async function goto(
585
- href,
585
+ url,
586
586
  { noscroll = false, replaceState = false, keepfocus = false, state = {} },
587
587
  redirect_chain
588
588
  ) {
589
- const url = new URL(href, get_base_uri(document));
589
+ if (typeof url === 'string') {
590
+ url = new URL(url, get_base_uri(document));
591
+ }
590
592
 
591
593
  if (router_enabled) {
592
594
  return navigate({
@@ -630,18 +630,6 @@ function escape_html_attr(str) {
630
630
 
631
631
  const s = JSON.stringify;
632
632
 
633
- /** @param {URL} url */
634
- function create_prerendering_url_proxy(url) {
635
- return new Proxy(url, {
636
- get: (target, prop, receiver) => {
637
- if (prop === 'search' || prop === 'searchParams') {
638
- throw new Error(`Cannot access url.${prop} on a page with prerendering enabled`);
639
- }
640
- return Reflect.get(target, prop, receiver);
641
- }
642
- });
643
- }
644
-
645
633
  const encoder = new TextEncoder();
646
634
 
647
635
  /**
@@ -1069,6 +1057,82 @@ class Csp {
1069
1057
  }
1070
1058
  }
1071
1059
 
1060
+ const absolute = /^([a-z]+:)?\/?\//;
1061
+ const scheme = /^[a-z]+:/;
1062
+
1063
+ /**
1064
+ * @param {string} base
1065
+ * @param {string} path
1066
+ */
1067
+ function resolve(base, path) {
1068
+ if (scheme.test(path)) return path;
1069
+
1070
+ const base_match = absolute.exec(base);
1071
+ const path_match = absolute.exec(path);
1072
+
1073
+ if (!base_match) {
1074
+ throw new Error(`bad base path: "${base}"`);
1075
+ }
1076
+
1077
+ const baseparts = path_match ? [] : base.slice(base_match[0].length).split('/');
1078
+ const pathparts = path_match ? path.slice(path_match[0].length).split('/') : path.split('/');
1079
+
1080
+ baseparts.pop();
1081
+
1082
+ for (let i = 0; i < pathparts.length; i += 1) {
1083
+ const part = pathparts[i];
1084
+ if (part === '.') continue;
1085
+ else if (part === '..') baseparts.pop();
1086
+ else baseparts.push(part);
1087
+ }
1088
+
1089
+ const prefix = (path_match && path_match[0]) || (base_match && base_match[0]) || '';
1090
+
1091
+ return `${prefix}${baseparts.join('/')}`;
1092
+ }
1093
+
1094
+ /** @param {string} path */
1095
+ function is_root_relative(path) {
1096
+ return path[0] === '/' && path[1] !== '/';
1097
+ }
1098
+
1099
+ /**
1100
+ * @param {string} path
1101
+ * @param {import('types').TrailingSlash} trailing_slash
1102
+ */
1103
+ function normalize_path(path, trailing_slash) {
1104
+ if (path === '/' || trailing_slash === 'ignore') return path;
1105
+
1106
+ if (trailing_slash === 'never') {
1107
+ return path.endsWith('/') ? path.slice(0, -1) : path;
1108
+ } else if (trailing_slash === 'always' && !path.endsWith('/')) {
1109
+ return path + '/';
1110
+ }
1111
+
1112
+ return path;
1113
+ }
1114
+
1115
+ class LoadURL extends URL {
1116
+ /** @returns {string} */
1117
+ get hash() {
1118
+ throw new Error(
1119
+ 'url.hash is inaccessible from load. Consider accessing hash from the page store within the script tag of your component.'
1120
+ );
1121
+ }
1122
+ }
1123
+
1124
+ class PrerenderingURL extends URL {
1125
+ /** @returns {string} */
1126
+ get search() {
1127
+ throw new Error('Cannot access url.search on a page with prerendering enabled');
1128
+ }
1129
+
1130
+ /** @returns {URLSearchParams} */
1131
+ get searchParams() {
1132
+ throw new Error('Cannot access url.searchParams on a page with prerendering enabled');
1133
+ }
1134
+ }
1135
+
1072
1136
  // TODO rename this function/module
1073
1137
 
1074
1138
  const updated = {
@@ -1171,7 +1235,7 @@ async function render_response({
1171
1235
  routeId: event.routeId,
1172
1236
  status,
1173
1237
  stuff,
1174
- url: state.prerendering ? create_prerendering_url_proxy(event.url) : event.url
1238
+ url: state.prerendering ? new PrerenderingURL(event.url) : event.url
1175
1239
  },
1176
1240
  components: branch.map(({ node }) => node.module.default)
1177
1241
  };
@@ -1946,70 +2010,6 @@ function normalize(loaded) {
1946
2010
  return /** @type {import('types').NormalizedLoadOutput} */ (loaded);
1947
2011
  }
1948
2012
 
1949
- const absolute = /^([a-z]+:)?\/?\//;
1950
- const scheme = /^[a-z]+:/;
1951
-
1952
- /**
1953
- * @param {string} base
1954
- * @param {string} path
1955
- */
1956
- function resolve(base, path) {
1957
- if (scheme.test(path)) return path;
1958
-
1959
- const base_match = absolute.exec(base);
1960
- const path_match = absolute.exec(path);
1961
-
1962
- if (!base_match) {
1963
- throw new Error(`bad base path: "${base}"`);
1964
- }
1965
-
1966
- const baseparts = path_match ? [] : base.slice(base_match[0].length).split('/');
1967
- const pathparts = path_match ? path.slice(path_match[0].length).split('/') : path.split('/');
1968
-
1969
- baseparts.pop();
1970
-
1971
- for (let i = 0; i < pathparts.length; i += 1) {
1972
- const part = pathparts[i];
1973
- if (part === '.') continue;
1974
- else if (part === '..') baseparts.pop();
1975
- else baseparts.push(part);
1976
- }
1977
-
1978
- const prefix = (path_match && path_match[0]) || (base_match && base_match[0]) || '';
1979
-
1980
- return `${prefix}${baseparts.join('/')}`;
1981
- }
1982
-
1983
- /** @param {string} path */
1984
- function is_root_relative(path) {
1985
- return path[0] === '/' && path[1] !== '/';
1986
- }
1987
-
1988
- /**
1989
- * @param {string} path
1990
- * @param {import('types').TrailingSlash} trailing_slash
1991
- */
1992
- function normalize_path(path, trailing_slash) {
1993
- if (path === '/' || trailing_slash === 'ignore') return path;
1994
-
1995
- if (trailing_slash === 'never') {
1996
- return path.endsWith('/') ? path.slice(0, -1) : path;
1997
- } else if (trailing_slash === 'always' && !path.endsWith('/')) {
1998
- return path + '/';
1999
- }
2000
-
2001
- return path;
2002
- }
2003
-
2004
- class LoadURL extends URL {
2005
- /** @returns {string} */
2006
- get hash() {
2007
- throw new Error(
2008
- 'url.hash is inaccessible from load. Consider accessing hash from the page store within the script tag of your component.'
2009
- );
2010
- }
2011
- }
2012
-
2013
2013
  /**
2014
2014
  * @param {string} hostname
2015
2015
  * @param {string} [constraint]
@@ -2112,7 +2112,7 @@ async function load_node({
2112
2112
  } else if (module.load) {
2113
2113
  /** @type {import('types').LoadEvent} */
2114
2114
  const load_input = {
2115
- url: state.prerendering ? create_prerendering_url_proxy(event.url) : new LoadURL(event.url),
2115
+ url: state.prerendering ? new PrerenderingURL(event.url) : new LoadURL(event.url),
2116
2116
  params: event.params,
2117
2117
  props: shadow.body || {},
2118
2118
  routeId: event.routeId,
package/dist/cli.js CHANGED
@@ -5,7 +5,7 @@ import { l as load_config, $, c as coalesce_to_error } from './chunks/error.js';
5
5
  import sade from 'sade';
6
6
  import * as vite from 'vite';
7
7
  import { networkInterfaces, release } from 'os';
8
- import 'url';
8
+ import { pathToFileURL } from 'url';
9
9
 
10
10
  /** @param {unknown} e */
11
11
  function handle_error(e) {
@@ -41,7 +41,7 @@ async function launch(port, https, base) {
41
41
  exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}${base}`);
42
42
  }
43
43
 
44
- const prog = sade('svelte-kit').version('1.0.0-next.354');
44
+ const prog = sade('svelte-kit').version('1.0.0-next.355');
45
45
 
46
46
  prog
47
47
  .command('dev')
@@ -242,7 +242,7 @@ prog.parse(process.argv, { unknown: (arg) => `Unknown option: ${arg}` });
242
242
  function welcome({ port, host, https, open, base, loose, allow, cwd }) {
243
243
  if (open) launch(port, https, base);
244
244
 
245
- console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.354'}\n`));
245
+ console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.355'}\n`));
246
246
 
247
247
  const protocol = https ? 'https:' : 'http:';
248
248
  const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
@@ -288,7 +288,7 @@ async function get_vite_config(svelte_config) {
288
288
  for (const file of ['vite.config.js', 'vite.config.mjs', 'vite.config.cjs']) {
289
289
  if (fs__default.existsSync(file)) {
290
290
  // TODO warn here if config.kit.vite was specified
291
- const module = await import(path__default.resolve(file));
291
+ const module = await import(pathToFileURL(file).toString());
292
292
  return {
293
293
  ...module.default,
294
294
  configFile: false
package/dist/vite.js CHANGED
@@ -2725,11 +2725,13 @@ function kit() {
2725
2725
  /** @type {import('types').ManifestData} */
2726
2726
  let manifest_data;
2727
2727
 
2728
- /** @type {{
2728
+ /**
2729
+ * @type {{
2729
2730
  * build_dir: string;
2730
2731
  * output_dir: string;
2731
2732
  * client_out_dir: string;
2732
- * }} */
2733
+ * }}
2734
+ */
2733
2735
  let paths;
2734
2736
 
2735
2737
  return {
@@ -2798,7 +2800,7 @@ function kit() {
2798
2800
  }
2799
2801
  },
2800
2802
  preview: {
2801
- port: 3000,
2803
+ port: config.preview?.port ?? 3000,
2802
2804
  strictPort: true
2803
2805
  },
2804
2806
  resolve: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.354",
3
+ "version": "1.0.0-next.355",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -17,13 +17,29 @@
17
17
  *
18
18
  * By populating these interfaces, you will gain type safety when using `event.locals`, `event.platform`, `session` and `stuff`.
19
19
  *
20
- * Note that since it's an ambient declaration file, you can't use `import` statements instead, use the `import(...)` function:
20
+ * Note that since it's an ambient declaration file, you have to be careful when using `import` statements. Once you add an `import`
21
+ * at the top level, the declaration file is no longer considered ambient and you lose access to these typings in other files.
22
+ * To avoid this, either use the `import(...)` function:
21
23
  *
22
24
  * ```ts
23
25
  * interface Locals {
24
26
  * user: import('$lib/types').User;
25
27
  * }
26
28
  * ```
29
+ * Or wrap the namespace with `declare global`:
30
+ * ```ts
31
+ * import { User } from '$lib/types';
32
+ *
33
+ * declare global {
34
+ * namespace App {
35
+ * interface Locals {
36
+ * user: User;
37
+ * }
38
+ * // ...
39
+ * }
40
+ * }
41
+ * ```
42
+ *
27
43
  */
28
44
  declare namespace App {
29
45
  /**
@@ -106,16 +122,16 @@ declare module '$app/navigation' {
106
122
  */
107
123
  export function disableScrollHandling(): void;
108
124
  /**
109
- * Returns a Promise that resolves when SvelteKit navigates (or fails to navigate, in which case the promise rejects) to the specified `href`.
125
+ * Returns a Promise that resolves when SvelteKit navigates (or fails to navigate, in which case the promise rejects) to the specified `url`.
110
126
  *
111
- * @param href Where to navigate to
127
+ * @param url Where to navigate to
112
128
  * @param opts.replaceState If `true`, will replace the current `history` entry rather than creating a new one with `pushState`
113
129
  * @param opts.noscroll If `true`, the browser will maintain its scroll position rather than scrolling to the top of the page after navigation
114
130
  * @param opts.keepfocus If `true`, the currently focused element will retain focus after navigation. Otherwise, focus will be reset to the body
115
131
  * @param opts.state The state of the new/updated history entry
116
132
  */
117
133
  export function goto(
118
- href: string,
134
+ url: string | URL,
119
135
  opts?: { replaceState?: boolean; noscroll?: boolean; keepfocus?: boolean; state?: any }
120
136
  ): Promise<void>;
121
137
  /**
@@ -318,3 +334,12 @@ declare module '@sveltejs/kit/node' {
318
334
  ): Promise<Request>;
319
335
  export function setResponse(res: import('http').ServerResponse, response: Response): void;
320
336
  }
337
+
338
+ declare module '@sveltejs/kit/experimental/vite' {
339
+ import { Plugin } from 'vite';
340
+
341
+ /**
342
+ * Returns the SvelteKit Vite plugins.
343
+ */
344
+ export function sveltekit(): Plugin[];
345
+ }