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

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.
@@ -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_$';
@@ -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
  }
@@ -3087,7 +3097,12 @@ async function respond(request, options, state) {
3087
3097
  }
3088
3098
  }
3089
3099
 
3090
- let decoded = decodeURI(url.pathname);
3100
+ let decoded;
3101
+ try {
3102
+ decoded = decodeURI(url.pathname);
3103
+ } catch {
3104
+ return new Response('Malformed URI', { status: 400 });
3105
+ }
3091
3106
 
3092
3107
  /** @type {import('types').SSRRoute | null} */
3093
3108
  let route = null;
@@ -3097,7 +3112,7 @@ async function respond(request, options, state) {
3097
3112
 
3098
3113
  if (options.paths.base && !state.prerendering?.fallback) {
3099
3114
  if (!decoded.startsWith(options.paths.base)) {
3100
- return new Response(undefined, { status: 404 });
3115
+ return new Response('Not found', { status: 404 });
3101
3116
  }
3102
3117
  decoded = decoded.slice(options.paths.base.length) || '/';
3103
3118
  }
@@ -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 };
@@ -224,7 +224,10 @@ const options = object(
224
224
  })
225
225
  }),
226
226
 
227
- endpointExtensions: string_array(['.js', '.ts']),
227
+ // TODO: remove this for the 1.0 release
228
+ endpointExtensions: error(
229
+ (keypath) => `${keypath} has been renamed to config.kit.moduleExtensions`
230
+ ),
228
231
 
229
232
  files: object({
230
233
  assets: string('static'),
@@ -270,6 +273,8 @@ const options = object(
270
273
  })
271
274
  }),
272
275
 
276
+ moduleExtensions: string_array(['.js', '.ts']),
277
+
273
278
  outDir: string('.svelte-kit'),
274
279
 
275
280
  package: object({
@@ -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 = {
@@ -137,35 +137,6 @@ function logger({ verbose }) {
137
137
  return log;
138
138
  }
139
139
 
140
- /**
141
- * Given an entry point like [cwd]/src/hooks, returns a filename like [cwd]/src/hooks.js or [cwd]/src/hooks/index.js
142
- * @param {string} entry
143
- * @returns {string|null}
144
- */
145
- function resolve_entry(entry) {
146
- if (fs__default.existsSync(entry)) {
147
- const stats = fs__default.statSync(entry);
148
- if (stats.isDirectory()) {
149
- return resolve_entry(path__default.join(entry, 'index'));
150
- }
151
-
152
- return entry;
153
- } else {
154
- const dir = path__default.dirname(entry);
155
-
156
- if (fs__default.existsSync(dir)) {
157
- const base = path__default.basename(entry);
158
- const files = fs__default.readdirSync(dir);
159
-
160
- const found = files.find((file) => file.replace(/\.[^.]+$/, '') === base);
161
-
162
- if (found) return path__default.join(dir, found);
163
- }
164
- }
165
-
166
- return null;
167
- }
168
-
169
140
  /** @param {import('types').ManifestData} manifest_data */
170
141
  function get_mime_lookup(manifest_data) {
171
142
  /** @type {Record<string, string>} */
@@ -181,25 +152,6 @@ function get_mime_lookup(manifest_data) {
181
152
  return mime;
182
153
  }
183
154
 
184
- /** @param {import('types').ValidatedKitConfig} config */
185
- function get_aliases(config) {
186
- /** @type {Record<string, string>} */
187
- const alias = {
188
- __GENERATED__: path__default.posix.join(config.outDir, 'generated'),
189
- $app: `${get_runtime_path(config)}/app`,
190
-
191
- // For now, we handle `$lib` specially here rather than make it a default value for
192
- // `config.kit.alias` since it has special meaning for packaging, etc.
193
- $lib: config.files.lib
194
- };
195
-
196
- for (const [key, value] of Object.entries(config.alias)) {
197
- alias[key] = path__default.resolve(value);
198
- }
199
-
200
- return alias;
201
- }
202
-
203
155
  const param_pattern = /^(\.\.\.)?(\w+)(?:=(\w+))?$/;
204
156
 
205
157
  /** @param {string} id */
@@ -352,7 +304,7 @@ function create_manifest_data({
352
304
  });
353
305
 
354
306
  const routes_base = posixify(path__default.relative(cwd, config.kit.files.routes));
355
- const valid_extensions = [...config.extensions, ...config.kit.endpointExtensions];
307
+ const valid_extensions = [...config.extensions, ...config.kit.moduleExtensions];
356
308
 
357
309
  if (fs__default.existsSync(config.kit.files.routes)) {
358
310
  list_files(config.kit.files.routes).forEach((file) => {
@@ -537,6 +489,7 @@ function create_manifest_data({
537
489
  if (fs__default.existsSync(config.kit.files.params)) {
538
490
  for (const file of fs__default.readdirSync(config.kit.files.params)) {
539
491
  const ext = path__default.extname(file);
492
+ if (!config.kit.moduleExtensions.includes(ext)) continue;
540
493
  const type = file.slice(0, -ext.length);
541
494
 
542
495
  if (/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(type)) {
@@ -943,7 +896,7 @@ function write_types(config, manifest_data) {
943
896
 
944
897
  if (file) {
945
898
  const ext = /** @type {string} */ (
946
- config.kit.endpointExtensions.find((ext) => file.endsWith(ext))
899
+ config.kit.moduleExtensions.find((ext) => file.endsWith(ext))
947
900
  );
948
901
  const key = file.slice(0, -ext.length);
949
902
  shadow_types.set(key, {
@@ -1024,4 +977,4 @@ var sync = /*#__PURE__*/Object.freeze({
1024
977
  all: all
1025
978
  });
1026
979
 
1027
- export { get_runtime_path as a, get_mime_lookup as b, all as c, sync as d, get_aliases as g, init as i, logger as l, parse_route_id as p, resolve_entry as r, s, update as u };
980
+ export { get_mime_lookup as a, all as b, sync as c, get_runtime_path as g, init as i, logger as l, parse_route_id as p, s, update as u };
package/dist/cli.js CHANGED
@@ -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.355');
44
+ const prog = sade('svelte-kit').version('1.0.0-next.358');
45
45
 
46
46
  prog
47
47
  .command('dev')
@@ -218,7 +218,7 @@ prog
218
218
 
219
219
  try {
220
220
  const config = await load_config();
221
- const sync = await import('./chunks/sync.js').then(function (n) { return n.d; });
221
+ const sync = await import('./chunks/sync.js').then(function (n) { return n.c; });
222
222
  sync.all(config);
223
223
  } catch (error) {
224
224
  handle_error(error);
@@ -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.355'}\n`));
245
+ console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.358'}\n`));
246
246
 
247
247
  const protocol = https ? 'https:' : 'http:';
248
248
  const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';