@sveltejs/kit 1.0.0-next.353 → 1.0.0-next.356

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({
@@ -77,13 +77,13 @@ function is_pojo(body) {
77
77
 
78
78
  if (body) {
79
79
  if (body instanceof Uint8Array) return false;
80
+ if (body instanceof ReadableStream) return false;
80
81
 
81
- // body could be a node Readable, but we don't want to import
82
- // node built-ins, so we use duck typing
83
- if (body._readableState && typeof body.pipe === 'function') return false;
84
-
85
- // similarly, it could be a web ReadableStream
86
- if (typeof ReadableStream !== 'undefined' && body instanceof ReadableStream) return false;
82
+ // if body is a node Readable, throw an error
83
+ // TODO remove this for 1.0
84
+ if (body._readableState && typeof body.pipe === 'function') {
85
+ throw new Error('Node streams are no longer supported — use a ReadableStream instead');
86
+ }
87
87
  }
88
88
 
89
89
  return true;
@@ -114,6 +114,8 @@ const text_types = new Set([
114
114
  'multipart/form-data'
115
115
  ]);
116
116
 
117
+ const bodyless_status_codes = new Set([101, 204, 205, 304]);
118
+
117
119
  /**
118
120
  * Decides how the body should be parsed based on its mime type
119
121
  *
@@ -217,10 +219,13 @@ async function render_endpoint(event, mod) {
217
219
  }
218
220
  }
219
221
 
220
- return new Response(method !== 'head' ? normalized_body : undefined, {
221
- status,
222
- headers
223
- });
222
+ return new Response(
223
+ method !== 'head' && !bodyless_status_codes.has(status) ? normalized_body : undefined,
224
+ {
225
+ status,
226
+ headers
227
+ }
228
+ );
224
229
  }
225
230
 
226
231
  var chars$1 = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$';
@@ -630,18 +635,6 @@ function escape_html_attr(str) {
630
635
 
631
636
  const s = JSON.stringify;
632
637
 
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
638
  const encoder = new TextEncoder();
646
639
 
647
640
  /**
@@ -1069,6 +1062,82 @@ class Csp {
1069
1062
  }
1070
1063
  }
1071
1064
 
1065
+ const absolute = /^([a-z]+:)?\/?\//;
1066
+ const scheme = /^[a-z]+:/;
1067
+
1068
+ /**
1069
+ * @param {string} base
1070
+ * @param {string} path
1071
+ */
1072
+ function resolve(base, path) {
1073
+ if (scheme.test(path)) return path;
1074
+
1075
+ const base_match = absolute.exec(base);
1076
+ const path_match = absolute.exec(path);
1077
+
1078
+ if (!base_match) {
1079
+ throw new Error(`bad base path: "${base}"`);
1080
+ }
1081
+
1082
+ const baseparts = path_match ? [] : base.slice(base_match[0].length).split('/');
1083
+ const pathparts = path_match ? path.slice(path_match[0].length).split('/') : path.split('/');
1084
+
1085
+ baseparts.pop();
1086
+
1087
+ for (let i = 0; i < pathparts.length; i += 1) {
1088
+ const part = pathparts[i];
1089
+ if (part === '.') continue;
1090
+ else if (part === '..') baseparts.pop();
1091
+ else baseparts.push(part);
1092
+ }
1093
+
1094
+ const prefix = (path_match && path_match[0]) || (base_match && base_match[0]) || '';
1095
+
1096
+ return `${prefix}${baseparts.join('/')}`;
1097
+ }
1098
+
1099
+ /** @param {string} path */
1100
+ function is_root_relative(path) {
1101
+ return path[0] === '/' && path[1] !== '/';
1102
+ }
1103
+
1104
+ /**
1105
+ * @param {string} path
1106
+ * @param {import('types').TrailingSlash} trailing_slash
1107
+ */
1108
+ function normalize_path(path, trailing_slash) {
1109
+ if (path === '/' || trailing_slash === 'ignore') return path;
1110
+
1111
+ if (trailing_slash === 'never') {
1112
+ return path.endsWith('/') ? path.slice(0, -1) : path;
1113
+ } else if (trailing_slash === 'always' && !path.endsWith('/')) {
1114
+ return path + '/';
1115
+ }
1116
+
1117
+ return path;
1118
+ }
1119
+
1120
+ class LoadURL extends URL {
1121
+ /** @returns {string} */
1122
+ get hash() {
1123
+ throw new Error(
1124
+ 'url.hash is inaccessible from load. Consider accessing hash from the page store within the script tag of your component.'
1125
+ );
1126
+ }
1127
+ }
1128
+
1129
+ class PrerenderingURL extends URL {
1130
+ /** @returns {string} */
1131
+ get search() {
1132
+ throw new Error('Cannot access url.search on a page with prerendering enabled');
1133
+ }
1134
+
1135
+ /** @returns {URLSearchParams} */
1136
+ get searchParams() {
1137
+ throw new Error('Cannot access url.searchParams on a page with prerendering enabled');
1138
+ }
1139
+ }
1140
+
1072
1141
  // TODO rename this function/module
1073
1142
 
1074
1143
  const updated = {
@@ -1171,7 +1240,7 @@ async function render_response({
1171
1240
  routeId: event.routeId,
1172
1241
  status,
1173
1242
  stuff,
1174
- url: state.prerendering ? create_prerendering_url_proxy(event.url) : event.url
1243
+ url: state.prerendering ? new PrerenderingURL(event.url) : event.url
1175
1244
  },
1176
1245
  components: branch.map(({ node }) => node.module.default)
1177
1246
  };
@@ -1946,70 +2015,6 @@ function normalize(loaded) {
1946
2015
  return /** @type {import('types').NormalizedLoadOutput} */ (loaded);
1947
2016
  }
1948
2017
 
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
2018
  /**
2014
2019
  * @param {string} hostname
2015
2020
  * @param {string} [constraint]
@@ -2112,7 +2117,7 @@ async function load_node({
2112
2117
  } else if (module.load) {
2113
2118
  /** @type {import('types').LoadEvent} */
2114
2119
  const load_input = {
2115
- url: state.prerendering ? create_prerendering_url_proxy(event.url) : new LoadURL(event.url),
2120
+ url: state.prerendering ? new PrerenderingURL(event.url) : new LoadURL(event.url),
2116
2121
  params: event.params,
2117
2122
  props: shadow.body || {},
2118
2123
  routeId: event.routeId,
@@ -2279,6 +2284,11 @@ async function load_node({
2279
2284
  if (cookie) opts.headers.set('cookie', cookie);
2280
2285
  }
2281
2286
 
2287
+ // we need to delete the connection header, as explained here:
2288
+ // https://github.com/nodejs/undici/issues/1470#issuecomment-1140798467
2289
+ // TODO this may be a case for being selective about which headers we let through
2290
+ opts.headers.delete('connection');
2291
+
2282
2292
  const external_request = new Request(requested, /** @type {RequestInit} */ (opts));
2283
2293
  response = await options.hooks.externalFetch.call(null, external_request);
2284
2294
  }
@@ -0,0 +1,3 @@
1
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
2
+
3
+ export { commonjsGlobal as c };
@@ -15255,9 +15255,9 @@ async function preprocess(source, preprocessor, options) {
15255
15255
  /**
15256
15256
  * Resolves the `$lib` alias.
15257
15257
  *
15258
- * TODO: make this more generic to also handle other aliases the user could have defined
15259
- * via `kit.vite.resolve.alias`. Also investigate how to do this in a more robust way
15260
- * (right now regex string replacement is used).
15258
+ * TODO: make this more generic to also handle other aliases the user could have defined via
15259
+ * `kit.alias`. Also investigate how to do this in a more robust way (right now regex string
15260
+ * replacement is used).
15261
15261
  * For more discussion see https://github.com/sveltejs/kit/pull/2453
15262
15262
  *
15263
15263
  * @param {string} file Relative to the lib root
@@ -8,20 +8,34 @@ import '@sveltejs/vite-plugin-svelte';
8
8
  import 'vite';
9
9
  import './sync.js';
10
10
  import '../node/polyfills.js';
11
+ import 'assert';
12
+ import 'net';
13
+ import 'http';
14
+ import 'stream';
15
+ import 'buffer';
16
+ import 'util';
17
+ import 'stream/web';
18
+ import 'perf_hooks';
19
+ import 'util/types';
20
+ import 'events';
21
+ import 'tls';
22
+ import './_commonjsHelpers.js';
23
+ import 'async_hooks';
24
+ import 'console';
25
+ import 'zlib';
26
+ import 'crypto';
27
+ import 'querystring';
28
+ import '../node.js';
11
29
  import 'node:http';
12
30
  import 'node:https';
13
31
  import 'node:zlib';
14
32
  import 'node:stream';
15
33
  import 'node:buffer';
16
- import 'node:util';
17
34
  import 'node:url';
35
+ import 'node:util';
18
36
  import 'node:net';
19
37
  import 'node:fs';
20
38
  import 'node:path';
21
- import 'crypto';
22
- import 'querystring';
23
- import '../node.js';
24
- import 'stream';
25
39
 
26
40
  /**
27
41
  * Creates the Builder which is passed to adapters for building the application.
@@ -1,15 +1,16 @@
1
1
  import 'node:fs';
2
2
  import 'node:path';
3
- import { F as FormData, a as File } from '../node/polyfills.js';
3
+ import { F as FormData, a as File } from '../node.js';
4
4
  import 'node:http';
5
5
  import 'node:https';
6
6
  import 'node:zlib';
7
7
  import 'node:stream';
8
8
  import 'node:buffer';
9
- import 'node:util';
10
9
  import 'node:url';
10
+ import 'node:util';
11
+ import './_commonjsHelpers.js';
11
12
  import 'node:net';
12
- import 'crypto';
13
+ import 'stream';
13
14
 
14
15
  let s = 0;
15
16
  const S = {
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.353');
44
+ const prog = sade('svelte-kit').version('1.0.0-next.356');
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.353'}\n`));
245
+ console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.356'}\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