@sveltejs/kit 1.0.0-next.352 → 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.
package/assets/app/env.js CHANGED
@@ -4,13 +4,25 @@ export { prerendering } from '../env.js';
4
4
  * @type {import('$app/env').browser}
5
5
  */
6
6
  const browser = !import.meta.env.SSR;
7
+
8
+ /**
9
+ * @type {import('$app/env').server}
10
+ */
11
+ const server = !!import.meta.env.SSR;
12
+
7
13
  /**
8
14
  * @type {import('$app/env').dev}
9
15
  */
10
16
  const dev = !!import.meta.env.DEV;
17
+
18
+ /**
19
+ * @type {import('$app/env').prod}
20
+ */
21
+ const prod = !import.meta.env.DEV;
22
+
11
23
  /**
12
24
  * @type {import('$app/env').mode}
13
25
  */
14
26
  const mode = import.meta.env.MODE;
15
27
 
16
- export { browser, dev, mode };
28
+ export { browser, dev, mode, prod, server };
@@ -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,